6. Let $m \neq 0$ be an integer. Find all real-coefficient polynomials $P(x)$ such that for any real number $x$, we have
$$
\begin{array}{l}
\left(x^{3}-m x^{2}+1\right) P(x+1)+\left(x^{3}+m x^{2}+1\right) P(x-1) \\
=2\left(x^{3}-m x+1\right) P(x) .
\end{array}
$$
6. Let $P(x)=a_{n} x^{n}+\cdots+a_{1} x+a_{0}\left(a_{n} \neq 0\right)$.

Comparing the coefficients of $x^{n+1}$ on both sides of equation (1), we get
$a_{n}(n-2 m)(n-1)=0$.
Thus, $n=1$ or $2 m$.
If $n=1$, it is easy to see that $P(x)=x$ is a solution to equation (1), and $P(x)=1$ is not a solution to equation (1).
Since $P$ is linear, the linear solution to equation (1) is
$P(x)=t x(t \in \mathbf{R})$.
If $n=2 m$, then the polynomial
$$
x P(x+1)-(x+1) P(x)=(n-1) a_{n} x^{n}+\cdots
$$

has degree $n$.
Therefore, there is at least one root $r$ (possibly complex).
If $r \notin\{0,-1\}$, define
$k=\frac{P(r)}{r}=\frac{P(r+1)}{r+1}$;
if $r=0$, set $k=P(1)$;
if $r=-1$, set $k=-P(-1)$.
Now consider the polynomial $S(x)=P(x)-k x$.
Since $P(x)$ and $k x$ both satisfy equation (1), $S(x)$ also satisfies equation (1), and $r, r+1$ are its roots.
Let $A(x)=x^{3}-m x^{2}+1, B(x)=x^{3}+m x^{2}+1$.
Substituting $x=s$ into equation (1), we have the following conclusions.
(1) If $s-1, s$ are roots of $S$, and $s$ is not a root of $A$, then $s+1$ is a root of $S$;
(2) If $s, s+1$ are roots of $S$, and $s$ is not a root of $B$, then $s-1$ is a root of $S$.
Let integers $a \geqslant 0, b \geqslant 1$, such that
$$
r-a, r-a+1, \cdots, r, r+1, \cdots, r+b-1, r+b
$$

are roots of $S$, and $r-a-1, r+b+1$ are not roots of $S$. Then $r-a$ is a root of $B$, and $r+b$ is a root of $A$.

Since $r-a$ is a root of $B(x)$, and also a root of $A(x+a+b)$, it is also a root of the greatest common divisor $C(x)$ of $B(x)$ and $A(x+a+b)$ with integer coefficients.

If $C(x)$ is a non-trivial factor of $B(x)$, then $B$ has a rational root $\alpha$.

Since the leading and constant coefficients of $B$ are both 1, $\alpha$ can only be 1 or -1.

But $B(-1)=m>0, B(1)=m+2>0$ (since $n=2 m$). This is a contradiction.
Therefore, $B(x)=A(x+a+b)$.
Let $c=a+b \geqslant 1$. Then
$0=A(x+c)-B(x)$
$=(3 c-2 m) x^{2}+c(3 c-2 m) x+c^{2}(c-m)$.
Thus, $3 c-2 m=c-m=0$.
Hence, $m=0$, which is a contradiction.
In conclusion, $P(x)=t x(t \in \mathbf{R})$ is the solution to equation (1).