ipq806x: enable Linksys EA8500 eth1 interface
[openwrt/staging/stintel.git] / target / linux / generic / pending-5.4 / 350-MIPS-Add-missing-EHB-in-mtc0-mfc0-sequence-for-DSPen.patch
1 From db4603e30effd74d4adb6bcdf73072b2c06fafcd Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Fri, 3 Jul 2020 00:07:15 +0200
4 Subject: [PATCH] MIPS: Add missing EHB in mtc0 -> mfc0 sequence for DSPen
5
6 This resolves the hazard between the mtc0 in the change_c0_status() and
7 the mfc0 in configure_exception_vector(). Without resolving this hazard
8 configure_exception_vector() could read an old value and would restore
9 this old value again. This would revert the changes change_c0_status()
10 did. I checked this by printing out the read_c0_status() at the end of
11 per_cpu_trap_init() and the ST0_MX is not set without this patch.
12
13 The hazard is documented in the MIPS Architecture Reference Manual Vol.
14 III: MIPS32/microMIPS32 Privileged Resource Architecture (MD00088), rev
15 6.03 table 8.1 which includes:
16
17 Producer | Consumer | Hazard
18 ----------|----------|----------------------------
19 mtc0 | mfc0 | any coprocessor 0 register
20
21 I saw this hazard on an Atheros AR9344 rev 2 SoC with a MIPS 74Kc CPU.
22 There the change_c0_status() function would activate the DSPen by
23 setting ST0_MX in the c0_status register. This was reverted and then the
24 system got a DSP exception when the DSP registers were saved in
25 save_dsp() in the first process switch. The crash looks like this:
26
27 [ 0.089999] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
28 [ 0.097796] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
29 [ 0.107070] Kernel panic - not syncing: Unexpected DSP exception
30 [ 0.113470] Rebooting in 1 seconds..
31
32 We saw this problem in OpenWrt only on the MIPS 74Kc based Atheros SoCs,
33 not on the 24Kc based SoCs. We only saw it with kernel 5.4 not with
34 kernel 4.19, in addition we had to use GCC 8.4 or 9.X, with GCC 8.3 it
35 did not happen.
36
37 In the kernel I bisected this problem to commit 9012d011660e ("compiler:
38 allow all arches to enable CONFIG_OPTIMIZE_INLINING"), but when this was
39 reverted it also happened after commit 172dcd935c34b ("MIPS: Always
40 allocate exception vector for MIPSr2+").
41
42 Commit 0b24cae4d535 ("MIPS: Add missing EHB in mtc0 -> mfc0 sequence.")
43 does similar changes to a different file. I am not sure if there are
44 more places affected by this problem.
45
46 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
47 Cc: <stable@vger.kernel.org>
48 ---
49 arch/mips/kernel/traps.c | 1 +
50 1 file changed, 1 insertion(+)
51
52 --- a/arch/mips/kernel/traps.c
53 +++ b/arch/mips/kernel/traps.c
54 @@ -2126,6 +2126,7 @@ static void configure_status(void)
55
56 change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
57 status_set);
58 + back_to_back_c0_hazard();
59 }
60
61 unsigned int hwrena;