Skip to contentSkip to conversation

arch: ARM64: add isb before enable pan

RFC PATCH In review Huangzhaoyang 4 participants 10 messages Oct 8, 2021 – Oct 11, 2021 arm64

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 arch: ARM64: add isb before enable pan

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

---
 arch/arm64/kernel/cpufeature.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/cpufeature.c +1 -0
index efed283..3c0de0d 100644
@@ -1663,6 +1663,7 @@ static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
 	WARN_ON_ONCE(in_interrupt());
 
 	sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);
+	isb();
 	set_pstate_pan(1);
 }
 #endif /* CONFIG_ARM64_PAN */
Signature · 1 line
1.9.1
maintainer
#1 lore raw

Hi,

Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Quoted 10 lines
---
 arch/arm64/kernel/cpufeature.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/cpufeature.c +0 -0
index efed283..3c0de0d 100644

arch/arm64/kernel/cpufeature.c static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) · line 1667

Quoted 5 lines
arch/arm64/kernel/cpufeature.c +1 -0
@@ -1663,6 +1663,7 @@ static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
 	WARN_ON_ONCE(in_interrupt());
 
 	sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);
+	isb();
 	set_pstate_pan(1);

SCTLR_EL1.SPAN only affects the PAN behaviour on taking an exception, which is itself a context-synchronizing event, so I can't see why the ISB makes any difference here (at least, for the purposes of PAN).

Thanks,

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
Quoted 14 lines · Will Deacon

Hi,

Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic and can NOT be captured by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

[1]

[    0.348000]  [0:    migration/0:   11] Synchronous External Abort:
level 1 (translation table walk) (0x96000055) at 0xffffffc000e06004
[    0.352000]  [0:    migration/0:   11] Internal error: : 96000055
[#1] PREEMPT SMP
[    0.352000]  [0:    migration/0:   11] Modules linked in:
[    0.352000]  [0:    migration/0:   11] Process migration/0 (pid:
11, stack limit = 0x        (ptrval))
[    0.352000]  [0:    migration/0:   11] CPU: 0 PID: 11 Comm:
migration/0 Tainted: G S
4.14.199-22631304-abA035FXXU0AUJ4_T4 #2
[    0.352000]  [0:    migration/0:   11] Hardware name: Spreadtrum
UMS9230 1H10 SoC (DT)
[    0.352000]  [0:    migration/0:   11] task:         (ptrval)
task.stack:         (ptrval)
[    0.352000]  [0:    migration/0:   11] pc : patch_alternative+0x68/0x27c
[    0.352000]  [0:    migration/0:   11] lr :

__apply_alternatives.llvm.7450387295891320208+0x60/0x160

[2]
__apply_alternatives
for()
patch_alternative <----panic here in the 2nd round of loop
after invoking flush_icache_range
flush_icache_range

[3]
sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE
+ tst \tmp1, #0xffff80000000 // check ttbr1_el1 valid
+ b.le .
msr ttbr1_el1, \tmp1 // set reserved ASID

Quoted 24 lines
Quoted 11 lines
---
 arch/arm64/kernel/cpufeature.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/cpufeature.c +0 -0
index efed283..3c0de0d 100644

arch/arm64/kernel/cpufeature.c static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) · line 1667

Quoted 5 lines
arch/arm64/kernel/cpufeature.c +1 -0
@@ -1663,6 +1663,7 @@ static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
      WARN_ON_ONCE(in_interrupt());
 
      sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);
+     isb();
      set_pstate_pan(1);

SCTLR_EL1.SPAN only affects the PAN behaviour on taking an exception, which is itself a context-synchronizing event, so I can't see why the ISB makes any difference here (at least, for the purposes of PAN).

Thanks,

Will

maintainer
#3 lore raw
Quoted 18 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Quoted 7 lines

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic and can NOT be captured by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

Can you please change the ARM64_HAS_PAN type to ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE? I wonder whether system_uses_ttbr0_pan() changes its output when all CPUs had been brought up and system_uses_hw_pan() returns true.

Signature · 1 line
Catalin
#4 lore raw
Quoted 28 lines · Catalin Marinas
Quoted 18 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Quoted 7 lines

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic and can NOT be captured by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

Quoted 4 lines

Can you please change the ARM64_HAS_PAN type to ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE? I wonder whether system_uses_ttbr0_pan() changes its output when all CPUs had been brought up and system_uses_hw_pan() returns true.

ok, thanks. We will try. Is it a workaround for known defect?

Quoted 3 lines

--
Catalin

maintainer
#5 lore raw
Quoted 28 lines · Zhaoyang Huang
Quoted 27 lines · Catalin Marinas
Quoted 25 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic and can NOT be captured by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

Quoted 6 lines
Quoted 4 lines

Can you please change the ARM64_HAS_PAN type to ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE? I wonder whether system_uses_ttbr0_pan() changes its output when all CPUs had been brought up and system_uses_hw_pan() returns true.

ok, thanks. We will try. Is it a workaround for known defect?

No, other than the potential kernel bug you reported.

Signature · 1 line
Catalin
#6 lore raw
Quoted 30 lines · Catalin Marinas
Quoted 28 lines · Zhaoyang Huang
Quoted 27 lines · Catalin Marinas
Quoted 25 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic and can NOT be captured by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Can you please change the ARM64_HAS_PAN type to ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE? I wonder whether system_uses_ttbr0_pan() changes its output when all CPUs had been brought up and system_uses_hw_pan() returns true.

ok, thanks. We will try. Is it a workaround for known defect?

No, other than the potential kernel bug you reported.

Changing the type to ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE doesn't work for this issue.

Quoted 3 lines

--
Catalin

reviewer
#7 lore raw
In reply to Zhaoyang Huang

Hi,

Quoted 12 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 8 lines
Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic

Just to check, how do you know the value of TTBR1_EL1 was 0x34000000? That isn't in the log sample below -- was that from the output of show_pte(), an external debugger, or something else?

I'm assuming from the "(ptrval)" bits below that can't have been from show_pte().

Quoted 16 lines

and can NOT be captured
by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

[1]

[    0.348000]  [0:    migration/0:   11] Synchronous External Abort:
level 1 (translation table walk) (0x96000055) at 0xffffffc000e06004
[    0.352000]  [0:    migration/0:   11] Internal error: : 96000055
[#1] PREEMPT SMP
[    0.352000]  [0:    migration/0:   11] Modules linked in:
[    0.352000]  [0:    migration/0:   11] Process migration/0 (pid:
11, stack limit = 0x        (ptrval))
[    0.352000]  [0:    migration/0:   11] CPU: 0 PID: 11 Comm:
Quoted 1 line

migration/0 Tainted: G S

Assuming I've read the taint_flags table correctly, that 'S' is TAINT_CPU_OUT_OF_SPEC, for which we should dump warnings for at boot time. The 'G' indicates the absence of proprietary modules.

Can you provide a full dmesg for a failed boot, please?

Have you made any changes to arch/arm64/kernel/cpufeature.c?

Are you able to test with a mainline kernel?

Quoted 17 lines

4.14.199-22631304-abA035FXXU0AUJ4_T4 #2

[    0.352000]  [0:    migration/0:   11] Hardware name: Spreadtrum
UMS9230 1H10 SoC (DT)
[    0.352000]  [0:    migration/0:   11] task:         (ptrval)
task.stack:         (ptrval)
[    0.352000]  [0:    migration/0:   11] pc : patch_alternative+0x68/0x27c
[    0.352000]  [0:    migration/0:   11] lr :

__apply_alternatives.llvm.7450387295891320208+0x60/0x160

[2]
__apply_alternatives
for()
patch_alternative <----panic here in the 2nd round of loop
after invoking flush_icache_range
flush_icache_range

Quoted 4 lines

[3]
sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE
+ tst \tmp1, #0xffff80000000 // check ttbr1_el1 valid
+ b.le .

What are you trying to detect for here? This is testing both the ASID and BADDR[47] bits, so I don;t understand the rationale.

Thanks,
Mark.

Quoted 26 lines

msr ttbr1_el1, \tmp1 // set reserved ASID

Quoted 24 lines
Quoted 11 lines
---
 arch/arm64/kernel/cpufeature.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/cpufeature.c +0 -0
index efed283..3c0de0d 100644

arch/arm64/kernel/cpufeature.c static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) · line 1667

Quoted 5 lines
arch/arm64/kernel/cpufeature.c +1 -0
@@ -1663,6 +1663,7 @@ static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
      WARN_ON_ONCE(in_interrupt());
 
      sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);
+     isb();
      set_pstate_pan(1);

SCTLR_EL1.SPAN only affects the PAN behaviour on taking an exception, which is itself a context-synchronizing event, so I can't see why the ISB makes any difference here (at least, for the purposes of PAN).

Thanks,

Will

#8 lore raw
Quoted 82 lines · Mark Rutland

Hi,

Quoted 12 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 8 lines
Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic

Just to check, how do you know the value of TTBR1_EL1 was 0x34000000? That isn't in the log sample below -- was that from the output of show_pte(), an external debugger, or something else?

I'm assuming from the "(ptrval)" bits below that can't have been from show_pte().

Quoted 16 lines

and can NOT be captured
by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

[1]

[    0.348000]  [0:    migration/0:   11] Synchronous External Abort:
level 1 (translation table walk) (0x96000055) at 0xffffffc000e06004
[    0.352000]  [0:    migration/0:   11] Internal error: : 96000055
[#1] PREEMPT SMP
[    0.352000]  [0:    migration/0:   11] Modules linked in:
[    0.352000]  [0:    migration/0:   11] Process migration/0 (pid:
11, stack limit = 0x        (ptrval))
[    0.352000]  [0:    migration/0:   11] CPU: 0 PID: 11 Comm:
Quoted 1 line

migration/0 Tainted: G S

Assuming I've read the taint_flags table correctly, that 'S' is TAINT_CPU_OUT_OF_SPEC, for which we should dump warnings for at boot time. The 'G' indicates the absence of proprietary modules.

Can you provide a full dmesg for a failed boot, please?

Have you made any changes to arch/arm64/kernel/cpufeature.c?

Are you able to test with a mainline kernel?

Quoted 17 lines

4.14.199-22631304-abA035FXXU0AUJ4_T4 #2

[    0.352000]  [0:    migration/0:   11] Hardware name: Spreadtrum
UMS9230 1H10 SoC (DT)
[    0.352000]  [0:    migration/0:   11] task:         (ptrval)
task.stack:         (ptrval)
[    0.352000]  [0:    migration/0:   11] pc : patch_alternative+0x68/0x27c
[    0.352000]  [0:    migration/0:   11] lr :

__apply_alternatives.llvm.7450387295891320208+0x60/0x160

[2]
__apply_alternatives
for()
patch_alternative <----panic here in the 2nd round of loop
after invoking flush_icache_range
flush_icache_range

Quoted 4 lines

[3]
sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE
+ tst \tmp1, #0xffff80000000 // check ttbr1_el1 valid
+ b.le .

Quoted 5 lines

What are you trying to detect for here? This is testing both the ASID and BADDR[47] bits, so I don;t understand the rationale.

Thanks,
Mark.

this issue is fixed by the patch 'arm64: Avoid flush_icache_range() in alternatives patching code(429388682dc266e7a693f9c27e3aabd341d55343)'. thanks

Quoted 27 lines
Quoted 27 lines

msr ttbr1_el1, \tmp1 // set reserved ASID

Quoted 24 lines
Quoted 11 lines
---
 arch/arm64/kernel/cpufeature.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/cpufeature.c +0 -0
index efed283..3c0de0d 100644

arch/arm64/kernel/cpufeature.c static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) · line 1667

Quoted 5 lines
arch/arm64/kernel/cpufeature.c +1 -0
@@ -1663,6 +1663,7 @@ static void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused)
      WARN_ON_ONCE(in_interrupt());
 
      sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0);
+     isb();
      set_pstate_pan(1);

SCTLR_EL1.SPAN only affects the PAN behaviour on taking an exception, which is itself a context-synchronizing event, so I can't see why the ISB makes any difference here (at least, for the purposes of PAN).

Thanks,

Will

reviewer
#9 lore raw
Quoted 80 lines · Zhaoyang Huang
Quoted 79 lines · Mark Rutland
Quoted 12 lines · Zhaoyang Huang
Quoted 11 lines · Will Deacon
Quoted 9 lines · Huangzhaoyang

From: Zhaoyang Huang <[email protected]>

set_pstate_pan failure is observed in an ARM64 system occasionaly on a reboot test, which can be work around by a msleep on the sw context. We assume suspicious on disorder of previous instr of disabling SW_PAN and add an isb here.

PS:
The bootup test failed with a invalid TTBR1_EL1 that equals 0x34000000, which is alike racing between on chip PAN and SW_PAN.

Quoted 8 lines
Quoted 6 lines

Sorry, but I'm struggling to understand the problem here. Please could you explain it in more detail?

- Why does a TTBR1_EL1 value of 0x34000000 indicate a race?
- Can you explain the race that you think might be occurring?
- Why does an ISB prevent the race?

Please find panic logs[1], related codes[2], sample of debug patch[3] below. TTBR1_EL1 equals 0x34000000 when panic

Just to check, how do you know the value of TTBR1_EL1 was 0x34000000? That isn't in the log sample below -- was that from the output of show_pte(), an external debugger, or something else?

I'm assuming from the "(ptrval)" bits below that can't have been from show_pte().

Quoted 16 lines

and can NOT be captured
by the debug patch during retest (all entrances that msr ttbr1_el1 are under watch) which should work. Adding ISB here to prevent race on TTBR1 from previous access of sysregs which can affect the msr result(the test is still ongoing). Could the race be ARM64_HAS_PAN(automated by core) and SW_PAN.

[1]

[    0.348000]  [0:    migration/0:   11] Synchronous External Abort:
level 1 (translation table walk) (0x96000055) at 0xffffffc000e06004
[    0.352000]  [0:    migration/0:   11] Internal error: : 96000055
[#1] PREEMPT SMP
[    0.352000]  [0:    migration/0:   11] Modules linked in:
[    0.352000]  [0:    migration/0:   11] Process migration/0 (pid:
11, stack limit = 0x        (ptrval))
[    0.352000]  [0:    migration/0:   11] CPU: 0 PID: 11 Comm:
Quoted 1 line

migration/0 Tainted: G S

Assuming I've read the taint_flags table correctly, that 'S' is TAINT_CPU_OUT_OF_SPEC, for which we should dump warnings for at boot time. The 'G' indicates the absence of proprietary modules.

Can you provide a full dmesg for a failed boot, please?

Have you made any changes to arch/arm64/kernel/cpufeature.c?

Are you able to test with a mainline kernel?

Quoted 21 lines

4.14.199-22631304-abA035FXXU0AUJ4_T4 #2

[    0.352000]  [0:    migration/0:   11] Hardware name: Spreadtrum
UMS9230 1H10 SoC (DT)
[    0.352000]  [0:    migration/0:   11] task:         (ptrval)
task.stack:         (ptrval)
[    0.352000]  [0:    migration/0:   11] pc : patch_alternative+0x68/0x27c
[    0.352000]  [0:    migration/0:   11] lr :

__apply_alternatives.llvm.7450387295891320208+0x60/0x160

[2]
__apply_alternatives
for()
patch_alternative <----panic here in the 2nd round of loop
after invoking flush_icache_range
flush_icache_range

[3]
sub \tmp1, \tmp1, #SWAPPER_DIR_SIZE
+ tst \tmp1, #0xffff80000000 // check ttbr1_el1 valid
+ b.le .

Quoted 8 lines
Quoted 5 lines

What are you trying to detect for here? This is testing both the ASID and BADDR[47] bits, so I don;t understand the rationale.

Thanks,
Mark.

this issue is fixed by the patch 'arm64: Avoid flush_icache_range() in alternatives patching code(429388682dc266e7a693f9c27e3aabd341d55343)'. thanks

Ah, thanks for this.

So this is because in arch/arm64/mm/cache.S we do (abbreviated):

| ENTRY(flush_icache_range)
| 	/* FALLTHROUGH */
| ENTRY(__flush_cache_user_range)
| 	uaccess_ttbr0_enable x2, x3, x4
| 
| 	...
| 
| 	uaccess_ttbr0_disable x1, x2
| 	ret
| ENDPROC(flush_icache_range)

... and even if I-caches are coherent and we don't execute junk for something we've patched but not invalidated, since we patch each alternative site in turn we can end up with unbalanced calls to enable/disable across a number of patches.

It looks like 429388682dc266e7a693f9c27e3aabd341d55343 isn't in the current linux-4.14.y, so we should post a backported version. From local testing, that applies trivially.

Who wants to post that to stable? I can do if people want.

Thanks,
Mark.