Skip to contentSkip to conversation

powerpc/interrupt: Use early_radix_enabled() in NMI real-mode guard

PATCH Superseded Venkat Rao Bagalkote 4 participants 6 messages Sep 7 – Sep 8 PowerPC

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/interrupt: Use early_radix_enabled() in NMI real-mode guard

radix_enabled() uses a jump label which is only valid after mmu_feature_keys_init() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.

Replace radix_enabled() with early_radix_enabled() which does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times, including before jump label initialization.

Add the missing #include <asm/mmu.h> since early_radix_enabled() is declared there.

---
 arch/powerpc/include/asm/interrupt.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +3 -2
index 1b45a49e9bed..36a654e780f7 100644
@@ -71,6 +71,7 @@
 
 #include <asm/kprobes.h>
 #include <asm/runlatch.h>
+#include <asm/mmu.h>
 
 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
 /*
@@ -290,7 +291,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
 		state = irqentry_nmi_enter(regs);			\
 	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
 		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
 		/* no nmi_entry for a pseries hash guest		\
 		 * taking a real mode exception */			\
 	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
@@ -307,7 +308,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
 		irqentry_nmi_exit(regs, state);				\
 	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
 		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
 		/* no nmi_exit for a pseries hash guest			\
 		 * taking a real mode exception */			\
 	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Venkat Rao Bagalkote

radix_enabled() uses a jump label which is only valid after mmu_feature_keys_init() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.

Replace radix_enabled() with early_radix_enabled() which does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times, including before jump label initialization.

Add the missing #include <asm/mmu.h> since early_radix_enabled() is declared there.

---
 arch/powerpc/include/asm/interrupt.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +0 -0
index 1b45a49e9bed..36a654e780f7 100644

arch/powerpc/include/asm/interrupt.h line 74

Quoted 4 lines
arch/powerpc/include/asm/interrupt.h +1 -0
@@ -71,6 +71,7 @@
 
 #include <asm/kprobes.h>
 #include <asm/runlatch.h>
+#include <asm/mmu.h>

I would prefer this to be in alphabetical order.

Quoted 24 lines
arch/powerpc/include/asm/interrupt.h +2 -2
 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
 /*
@@ -290,7 +291,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
 		state = irqentry_nmi_enter(regs);			\
 	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
 		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
 		/* no nmi_entry for a pseries hash guest		\
 		 * taking a real mode exception */			\
 	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
@@ -307,7 +308,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
 		irqentry_nmi_exit(regs, state);				\
 	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
 		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
 		/* no nmi_exit for a pseries hash guest			\
 		 * taking a real mode exception */			\
 	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
Signature · 1 line
2.45.2

Rest all looks good.

Regards,
Mukesh

#2 lore raw
In reply to Venkat Rao Bagalkote

Hello,

Quoted 9 lines · Venkat Rao Bagalkote

radix_enabled() uses a jump label which is only valid after mmu_feature_keys_init() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.

Replace radix_enabled() with early_radix_enabled() which does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times, including before jump label initialization.

Any Fixes: here?

Thanks

Michal

Quoted 43 lines

Add the missing #include <asm/mmu.h> since early_radix_enabled() is declared there.

---
 arch/powerpc/include/asm/interrupt.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +3 -2
index 1b45a49e9bed..36a654e780f7 100644
@@ -71,6 +71,7 @@
 
 #include <asm/kprobes.h>
 #include <asm/runlatch.h>
+#include <asm/mmu.h>
 
 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
 /*
@@ -290,7 +291,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
 		state = irqentry_nmi_enter(regs);			\
 	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
 		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
 		/* no nmi_entry for a pseries hash guest		\
 		 * taking a real mode exception */			\
 	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
@@ -307,7 +308,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
 		irqentry_nmi_exit(regs, state);				\
 	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
 		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
 		/* no nmi_exit for a pseries hash guest			\
 		 * taking a real mode exception */			\
 	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
Signature · 1 line
2.45.2
#3 lore raw
Quoted 9 lines · Michal Suchánek

Hello,

Quoted 6 lines · Venkat Rao Bagalkote

radix_enabled() uses a jump label which is only valid after mmu_feature_keys_init() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.

Quoted 4 lines
Quoted 3 lines

Replace radix_enabled() with early_radix_enabled() which does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times, including before jump label initialization.

Any Fixes: here?

Hello Michal,

Yes, this can have.

Fixes 118178e62e2e ("powerpc: move NMI entry/exit code into wrapper")

As commit 118178e62e2e originally introduced !radxi_enabled() check in NMI wrapper path.

Regards,

Venkat.

Quoted 47 lines

Thanks

Michal

Quoted 42 lines

Add the missing #include <asm/mmu.h> since early_radix_enabled() is declared there.

---
  arch/powerpc/include/asm/interrupt.h | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +3 -2
index 1b45a49e9bed..36a654e780f7 100644
@@ -71,6 +71,7 @@
 
  #include <asm/kprobes.h>
  #include <asm/runlatch.h>
+#include <asm/mmu.h>
 
  #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
  /*
@@ -290,7 +291,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
  		state = irqentry_nmi_enter(regs);			\
  	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
  		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
  		/* no nmi_entry for a pseries hash guest		\
  		 * taking a real mode exception */			\
  	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
@@ -307,7 +308,7 @@ interrupt_handler long func(struct pt_regs *regs)			\
  		irqentry_nmi_exit(regs, state);				\
  	} else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&			\
  		   firmware_has_feature(FW_FEATURE_LPAR) &&		\
-		   !radix_enabled()) {					\
+		   !early_radix_enabled()) {				\
  		/* no nmi_exit for a pseries hash guest			\
  		 * taking a real mode exception */			\
  	} else if (IS_ENABLED(CONFIG_KASAN)) {				\
Signature · 1 line
2.45.2
#4 lore raw
Quoted 17 lines · Venkat Rao Bagalkote
Quoted 9 lines · Michal Suchánek

Hello,

Quoted 6 lines · Venkat Rao Bagalkote

radix_enabled() uses a jump label which is only valid after mmu_feature_keys_init() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.

Quoted 4 lines
Quoted 3 lines

Replace radix_enabled() with early_radix_enabled() which does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times, including before jump label initialization.

Any Fixes: here?

Quoted 9 lines

Hello Michal,

Yes, this can have.

Fixes 118178e62e2e ("powerpc: move NMI entry/exit code into wrapper")

As commit 118178e62e2e originally introduced !radxi_enabled() check in NMI wrapper path.

looks like it did movement of code, rather than introducing.

Quoted 49 lines

Regards,

Venkat.

Quoted 45 lines

Thanks

Michal

Quoted 40 lines

Add the missing #include <asm/mmu.h> since early_radix_enabled() is declared there.

---
  arch/powerpc/include/asm/interrupt.h | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +3 -2
index 1b45a49e9bed..36a654e780f7 100644
@@ -71,6 +71,7 @@
   #include <asm/kprobes.h>
   #include <asm/runlatch.h>
+#include <asm/mmu.h>
   #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
   /*
@@ -290,7 +291,7 @@ interrupt_handler long func(struct pt_regs *regs)            \
           state = irqentry_nmi_enter(regs);            \
       } else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&            \
              firmware_has_feature(FW_FEATURE_LPAR) &&        \
-           !radix_enabled()) {                    \
+           !early_radix_enabled()) {                \
           /* no nmi_entry for a pseries hash guest        \
            * taking a real mode exception */            \
       } else if (IS_ENABLED(CONFIG_KASAN)) {                \
@@ -307,7 +308,7 @@ interrupt_handler long func(struct pt_regs *regs)            \
           irqentry_nmi_exit(regs, state);                \
       } else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&            \
              firmware_has_feature(FW_FEATURE_LPAR) &&        \
-           !radix_enabled()) {                    \
+           !early_radix_enabled()) {                \
           /* no nmi_exit for a pseries hash guest            \
            * taking a real mode exception */            \
       } else if (IS_ENABLED(CONFIG_KASAN)) {                \
Signature · 1 line
2.45.2
#5 lore raw
Quoted 24 lines · Shrikanth Hegde
Quoted 21 lines · Venkat Rao Bagalkote
Quoted 9 lines · Michal Suchánek

Hello,

Quoted 6 lines · Venkat Rao Bagalkote

radix_enabled() uses a jump label which is only valid after mmu_feature_keys_init() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.

Quoted 4 lines
Quoted 3 lines

Replace radix_enabled() with early_radix_enabled() which does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times, including before jump label initialization.

Any Fixes: here?

Hello Michal,

Yes, this can have.

Quoted 8 lines
Quoted 5 lines
Fixes 118178e62e2e ("powerpc: move NMI entry/exit code into wrapper")

As commit  originally introduced !radxi_enabled() check in NMI wrapper path.

looks like it did movement of code, rather than introducing.

Hello Shrikanth,

Yes, you are right. commit 118178e62e2e, just consolidated NMI wrapper logic from arch/powerpc/kernel/mce.c into interrupt.h.

Tracing it further back, radix_enabled() check for pseries hash guest in real-mode NMI was originally introduced in

commit: 8d0e21012743 ("powerpc/mce: Avoid nmi_enter/exit in real mode on pseries hash")

I can add Fixes: 8d0e21012743, and send V2, if that works.

Regards,

Venkat.

Quoted 53 lines
Quoted 51 lines

Regards,

Venkat.

Quoted 47 lines

Thanks

Michal

Quoted 42 lines

Add the missing #include <asm/mmu.h> since early_radix_enabled() is declared there.

---
  arch/powerpc/include/asm/interrupt.h | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +2 -1
index 1b45a49e9bed..36a654e780f7 100644
@@ -71,6 +71,7 @@
   #include <asm/kprobes.h>
   #include <asm/runlatch.h>
+#include <asm/mmu.h>
   #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
   /*
@@ -290,7 +291,7 @@ interrupt_handler long func(struct pt_regs 
 *regs)            \
           state = irqentry_nmi_enter(regs);            \
       } else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&            \
              firmware_has_feature(FW_FEATURE_LPAR) &&        \
-           !radix_enabled()) {                    \
+           !early_radix_enabled()) {                \
           /* no nmi_entry for a pseries hash guest        \
            * taking a real mode exception */            \

      } else if (IS_ENABLED(CONFIG_KASAN)) { \

arch/powerpc/include/asm/interrupt.h +1 -1
@@ -307,7 +308,7 @@ interrupt_handler long func(struct pt_regs 
 *regs)            \
           irqentry_nmi_exit(regs, state);                \
       } else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) &&            \
              firmware_has_feature(FW_FEATURE_LPAR) &&        \
-           !radix_enabled()) {                    \
+           !early_radix_enabled()) {                \
           /* no nmi_exit for a pseries hash guest \
            * taking a real mode exception */            \

      } else if (IS_ENABLED(CONFIG_KASAN)) { \

Signature · 1 line
2.45.2