diff mbox series

[RFC,1/3] powerpc/32: Implement HAVE_CONTEXT_TRACKING_USER support

Message ID 20221004063306.511154-2-npiggin@gmail.com (mailing list archive)
State Superseded
Headers show
Series powerpc/32: nohz full support | expand

Commit Message

Nicholas Piggin Oct. 4, 2022, 6:33 a.m. UTC
Context tracking involves tracking user, kernel, guest switches. This
enables existing context tracking code for interrupt entry on 32-bit.
KVM and interrupt exit already has context tracking calls.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Kconfig                 |  2 +-
 arch/powerpc/include/asm/interrupt.h | 21 ++++++---------------
 2 files changed, 7 insertions(+), 16 deletions(-)

Comments

Christophe Leroy Oct. 4, 2022, 11:32 a.m. UTC | #1
Le 04/10/2022 à 08:33, Nicholas Piggin a écrit :
> Context tracking involves tracking user, kernel, guest switches. This
> enables existing context tracking code for interrupt entry on 32-bit.
> KVM and interrupt exit already has context tracking calls.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>   arch/powerpc/Kconfig                 |  2 +-
>   arch/powerpc/include/asm/interrupt.h | 21 ++++++---------------
>   2 files changed, 7 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 81c9f895d690..f667279ec74c 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -204,7 +204,7 @@ config PPC
>   	select HAVE_ARCH_SECCOMP_FILTER
>   	select HAVE_ARCH_TRACEHOOK
>   	select HAVE_ASM_MODVERSIONS
> -	select HAVE_CONTEXT_TRACKING_USER		if PPC64
> +	select HAVE_CONTEXT_TRACKING_USER
>   	select HAVE_C_RECORDMCOUNT
>   	select HAVE_DEBUG_KMEMLEAK
>   	select HAVE_DEBUG_STACKOVERFLOW
> diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h
> index 4745bb9998bd..8860a246d51a 100644
> --- a/arch/powerpc/include/asm/interrupt.h
> +++ b/arch/powerpc/include/asm/interrupt.h
> @@ -85,6 +85,8 @@ do {									\
>   	    (user_mode(regs) || (TRAP(regs) != INTERRUPT_PROGRAM)))	\
>   		BUG_ON(cond);						\
>   } while (0)
> +#else
> +#define INT_SOFT_MASK_BUG_ON(regs, cond)

Here you can just drop the ifdef CONFIG_PPC64 I guess instead of adding 
an additional empty macro.

>   #endif
>   
>   #ifdef CONFIG_PPC_BOOK3S_64
> @@ -152,19 +154,8 @@ static inline void booke_restore_dbcr0(void)
>   static inline void interrupt_enter_prepare(struct pt_regs *regs)
>   {
>   #ifdef CONFIG_PPC32
> -	if (!arch_irq_disabled_regs(regs))
> -		trace_hardirqs_off();
> -
> -	if (user_mode(regs))
> -		kuap_lock();
> -	else
> -		kuap_save_and_lock(regs);
> -
> -	if (user_mode(regs))
> -		account_cpu_user_entry();
> -#endif
> -
> -#ifdef CONFIG_PPC64
> +	bool trace_enable = !arch_irq_disabled_regs(regs);

nit: You could be put this as an #else to the existing #ifdef CONFIG_PPC64

> +#else
>   	bool trace_enable = false;
>   
>   	if (IS_ENABLED(CONFIG_TRACE_IRQFLAGS)) {
> @@ -188,8 +179,9 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs)
>   	} else {
>   		__hard_RI_enable();
>   	}
> +	/* Only call trace_hardirqs_off when RI=1, it can cause SLB faults */
> +#endif
>   
> -	/* Do this when RI=1 because it can cause SLB faults */
>   	if (trace_enable)
>   		trace_hardirqs_off();
>   
> @@ -215,7 +207,6 @@ static inline void interrupt_enter_prepare(struct pt_regs *regs)
>   	}
>   	INT_SOFT_MASK_BUG_ON(regs, !arch_irq_disabled_regs(regs) &&
>   				   !(regs->msr & MSR_EE));
> -#endif
>   
>   	booke_restore_dbcr0();
>   }
Nicholas Piggin Oct. 6, 2022, 8:22 a.m. UTC | #2
On Tue Oct 4, 2022 at 9:32 PM AEST, Christophe Leroy wrote:
>
>
> Le 04/10/2022 à 08:33, Nicholas Piggin a écrit :
> > Context tracking involves tracking user, kernel, guest switches. This
> > enables existing context tracking code for interrupt entry on 32-bit.
> > KVM and interrupt exit already has context tracking calls.
> > 
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > ---
> >   arch/powerpc/Kconfig                 |  2 +-
> >   arch/powerpc/include/asm/interrupt.h | 21 ++++++---------------
> >   2 files changed, 7 insertions(+), 16 deletions(-)
> > 
> > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> > index 81c9f895d690..f667279ec74c 100644
> > --- a/arch/powerpc/Kconfig
> > +++ b/arch/powerpc/Kconfig
> > @@ -204,7 +204,7 @@ config PPC
> >   	select HAVE_ARCH_SECCOMP_FILTER
> >   	select HAVE_ARCH_TRACEHOOK
> >   	select HAVE_ASM_MODVERSIONS
> > -	select HAVE_CONTEXT_TRACKING_USER		if PPC64
> > +	select HAVE_CONTEXT_TRACKING_USER
> >   	select HAVE_C_RECORDMCOUNT
> >   	select HAVE_DEBUG_KMEMLEAK
> >   	select HAVE_DEBUG_STACKOVERFLOW
> > diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h
> > index 4745bb9998bd..8860a246d51a 100644
> > --- a/arch/powerpc/include/asm/interrupt.h
> > +++ b/arch/powerpc/include/asm/interrupt.h
> > @@ -85,6 +85,8 @@ do {									\
> >   	    (user_mode(regs) || (TRAP(regs) != INTERRUPT_PROGRAM)))	\
> >   		BUG_ON(cond);						\
> >   } while (0)
> > +#else
> > +#define INT_SOFT_MASK_BUG_ON(regs, cond)
>
> Here you can just drop the ifdef CONFIG_PPC64 I guess instead of adding 
> an additional empty macro.

I couldn't because some of the statements use some PPC64-only variables.
It ends up looking a bit better this way.

> >   #endif
> >   
> >   #ifdef CONFIG_PPC_BOOK3S_64
> > @@ -152,19 +154,8 @@ static inline void booke_restore_dbcr0(void)
> >   static inline void interrupt_enter_prepare(struct pt_regs *regs)
> >   {
> >   #ifdef CONFIG_PPC32
> > -	if (!arch_irq_disabled_regs(regs))
> > -		trace_hardirqs_off();
> > -
> > -	if (user_mode(regs))
> > -		kuap_lock();
> > -	else
> > -		kuap_save_and_lock(regs);
> > -
> > -	if (user_mode(regs))
> > -		account_cpu_user_entry();
> > -#endif
> > -
> > -#ifdef CONFIG_PPC64
> > +	bool trace_enable = !arch_irq_disabled_regs(regs);
>
> nit: You could be put this as an #else to the existing #ifdef CONFIG_PPC64

Yep, I was able to clean it up even a bit better actually.

Thanks,
Nick
diff mbox series

Patch

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 81c9f895d690..f667279ec74c 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -204,7 +204,7 @@  config PPC
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_ASM_MODVERSIONS
-	select HAVE_CONTEXT_TRACKING_USER		if PPC64
+	select HAVE_CONTEXT_TRACKING_USER
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DEBUG_STACKOVERFLOW
diff --git a/arch/powerpc/include/asm/interrupt.h b/arch/powerpc/include/asm/interrupt.h
index 4745bb9998bd..8860a246d51a 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -85,6 +85,8 @@  do {									\
 	    (user_mode(regs) || (TRAP(regs) != INTERRUPT_PROGRAM)))	\
 		BUG_ON(cond);						\
 } while (0)
+#else
+#define INT_SOFT_MASK_BUG_ON(regs, cond)
 #endif
 
 #ifdef CONFIG_PPC_BOOK3S_64
@@ -152,19 +154,8 @@  static inline void booke_restore_dbcr0(void)
 static inline void interrupt_enter_prepare(struct pt_regs *regs)
 {
 #ifdef CONFIG_PPC32
-	if (!arch_irq_disabled_regs(regs))
-		trace_hardirqs_off();
-
-	if (user_mode(regs))
-		kuap_lock();
-	else
-		kuap_save_and_lock(regs);
-
-	if (user_mode(regs))
-		account_cpu_user_entry();
-#endif
-
-#ifdef CONFIG_PPC64
+	bool trace_enable = !arch_irq_disabled_regs(regs);
+#else
 	bool trace_enable = false;
 
 	if (IS_ENABLED(CONFIG_TRACE_IRQFLAGS)) {
@@ -188,8 +179,9 @@  static inline void interrupt_enter_prepare(struct pt_regs *regs)
 	} else {
 		__hard_RI_enable();
 	}
+	/* Only call trace_hardirqs_off when RI=1, it can cause SLB faults */
+#endif
 
-	/* Do this when RI=1 because it can cause SLB faults */
 	if (trace_enable)
 		trace_hardirqs_off();
 
@@ -215,7 +207,6 @@  static inline void interrupt_enter_prepare(struct pt_regs *regs)
 	}
 	INT_SOFT_MASK_BUG_ON(regs, !arch_irq_disabled_regs(regs) &&
 				   !(regs->msr & MSR_EE));
-#endif
 
 	booke_restore_dbcr0();
 }