6. Let $m>1$ be an integer. The sequence $a_{1}, a_{2}, \cdots$ is defined as follows:
$$
\begin{array}{l}
a_{1}=a_{2}=1, a_{3}=4, \\
a_{n}=m\left(a_{n-1}+a_{n-2}\right)-a_{n-3}(n \geqslant 4) .
\end{array}
$$

Determine all integers $m$ such that every term of the sequence is a perfect square.
6. $m=2,10$.

Consider the integer $m>1$, such that the sequence defined as described in the problem contains only perfect squares.
First, prove that $m-1$ is a power of 3.
Assume $m-1$ is even, then $a_{4}=5 m-1$ should be divisible by 4. Hence $m \equiv 1(\bmod 4)$.

But $a_{5}=5 m^{2}+3 m-1 \equiv 3(\bmod 4)$ cannot be a perfect square, a contradiction.
Thus, $m-1$ is odd.
Assume an odd prime $p \neq 3$ divides $m-1$.
Notice that, $a_{n}-a_{n-1} \equiv a_{n-2}-a_{n-3}(\bmod p)$.
Therefore, the sequence modulo $p$ takes the form 1, $1,4,4,7,7,10,10, \cdots$
In fact, by induction, it can be shown:
$a_{2 k} \equiv a_{2 k-1} \equiv 3 k-2(\bmod p)(k \geqslant 1)$.
Since $\operatorname{gcd}(p, 3)=1$, the sequence $a_{n}(\bmod p)$ contains all residues modulo $p$, which contradicts the fact that there are only $\frac{p+1}{2}$ quadratic residues modulo $p$.
This indicates that $m-1$ is a power of 3.
Let $h$ and $k$ be integers, satisfying:
$m=3^{k}+1, a_{4}=h^{2}$.
Then $5 \times 3^{k}=(h-2)(h+2)$.
Since $\operatorname{gcd}(h-2, h+2)=1$, we have
$$
\left\{\begin{array}{l}
h-2=1,3^{k}, 5, \\
h+2=5 \times 3^{k}, 5,3^{k} .
\end{array}\right.
$$

In the first two cases, we get $k=0$, and in the last case, we get $k=2$.
Thus, $m=2$ or 10.
Now, verify the converse.
Assume $m=2$ or 10, let $t=1$ or 3 such that
$$
m=t^{2}+1 \text {. }
$$

The integer sequence $b_{1}, b_{2}, \cdots$ is defined as follows:
$b_{1}=1, b_{2}=1, b_{3}=2$,
$b_{n}=t b_{n-1}+b_{n-2}(n \geqslant 4)$.
Clearly, for $n=1,2,3$, we have $a_{n}=b_{n}^{2}$.
Notice that, if $m=2$, then $a_{4}=9$ and $b_{4}=3$;
if $m=10$, then $a_{4}=49$ and $b_{4}=7$.
In both cases, we have $a_{4}=b_{4}^{2}$.
If $n \geqslant 5$, then
$b_{n}^{2}+b_{n-3}^{2}$
$=\left(t b_{n-1}+b_{n-2}\right)^{2}+\left(b_{n-1}-t b_{n-2}\right)^{2}$
$=\left(t^{2}+1\right)\left(b_{n-1}^{2}+b_{n-2}^{2}\right)$
$=m\left(b_{n-1}^{2}+b_{n-2}^{2}\right)$.
Therefore, by induction, it can be proven that for all $n \geqslant 1$, we have $a_{n}=b_{n}^{2}$.
Hence, the proposition is proven.