2021-09-13 15:59:18

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [PATCH RESEND v3 6/6] powerpc/signal: Use unsafe_copy_siginfo_to_user()

Christophe Leroy <[email protected]> writes:

> Use unsafe_copy_siginfo_to_user() in order to do the copy
> within the user access block.
>
> On an mpc 8321 (book3s/32) the improvment is about 5% on a process
> sending a signal to itself.
>
> Signed-off-by: Christophe Leroy <[email protected]>
> ---
> v3: Don't leave compat aside, use the new unsafe_copy_siginfo_to_user32()
> ---
> arch/powerpc/kernel/signal_32.c | 8 +++-----
> arch/powerpc/kernel/signal_64.c | 5 +----
> 2 files changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
> index ff101e2b3bab..3a2db8af2d65 100644
> --- a/arch/powerpc/kernel/signal_32.c
> +++ b/arch/powerpc/kernel/signal_32.c
> @@ -710,9 +710,9 @@ static long restore_tm_user_regs(struct pt_regs *regs, struct mcontext __user *s
> }
> #endif
>
> -#ifdef CONFIG_PPC64
> +#ifndef CONFIG_PPC64
>
> -#define copy_siginfo_to_user copy_siginfo_to_user32
> +#define unsafe_copy_siginfo_to_user32 unsafe_copy_siginfo_to_user
>
> #endif /* CONFIG_PPC64 */

Any particular reason to reverse the sense of this #ifdef?

Otherwise this change looks much cleaner.

Eric


>
> @@ -779,15 +779,13 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
> asm("dcbst %y0; sync; icbi %y0; sync" :: "Z" (mctx->mc_pad[0]));
> }
> unsafe_put_sigset_t(&frame->uc.uc_sigmask, oldset, failed);
> + unsafe_copy_siginfo_to_user32(&frame->info, &ksig->info, failed);
>
> /* create a stack frame for the caller of the handler */
> unsafe_put_user(regs->gpr[1], newsp, failed);
>
> user_access_end();
>
> - if (copy_siginfo_to_user(&frame->info, &ksig->info))
> - goto badframe;
> -
> regs->link = tramp;
>
> #ifdef CONFIG_PPC_FPU_REGS
> diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
> index d80ff83cacb9..56c0c74aa28c 100644
> --- a/arch/powerpc/kernel/signal_64.c
> +++ b/arch/powerpc/kernel/signal_64.c
> @@ -901,15 +901,12 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,
> }
>
> unsafe_copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set), badframe_block);
> + unsafe_copy_siginfo_to_user(&frame->info, &ksig->info, badframe_block);
> /* Allocate a dummy caller frame for the signal handler. */
> unsafe_put_user(regs->gpr[1], newsp, badframe_block);
>
> user_write_access_end();
>
> - /* Save the siginfo outside of the unsafe block. */
> - if (copy_siginfo_to_user(&frame->info, &ksig->info))
> - goto badframe;
> -
> /* Make sure signal handler doesn't get spurious FP exceptions */
> tsk->thread.fp_state.fpscr = 0;


2021-09-13 17:18:37

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH RESEND v3 6/6] powerpc/signal: Use unsafe_copy_siginfo_to_user()



Le 13/09/2021 à 17:57, Eric W. Biederman a écrit :
> Christophe Leroy <[email protected]> writes:
>
>> Use unsafe_copy_siginfo_to_user() in order to do the copy
>> within the user access block.
>>
>> On an mpc 8321 (book3s/32) the improvment is about 5% on a process
>> sending a signal to itself.
>>
>> Signed-off-by: Christophe Leroy <[email protected]>
>> ---
>> v3: Don't leave compat aside, use the new unsafe_copy_siginfo_to_user32()
>> ---
>> arch/powerpc/kernel/signal_32.c | 8 +++-----
>> arch/powerpc/kernel/signal_64.c | 5 +----
>> 2 files changed, 4 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
>> index ff101e2b3bab..3a2db8af2d65 100644
>> --- a/arch/powerpc/kernel/signal_32.c
>> +++ b/arch/powerpc/kernel/signal_32.c
>> @@ -710,9 +710,9 @@ static long restore_tm_user_regs(struct pt_regs *regs, struct mcontext __user *s
>> }
>> #endif
>>
>> -#ifdef CONFIG_PPC64
>> +#ifndef CONFIG_PPC64
>>
>> -#define copy_siginfo_to_user copy_siginfo_to_user32
>> +#define unsafe_copy_siginfo_to_user32 unsafe_copy_siginfo_to_user
>>
>> #endif /* CONFIG_PPC64 */
>
> Any particular reason to reverse the sense of this #ifdef?

Yes I had double definition of unsafe_copy_siginfo_to_user(), I could
have ifdefed out unsafe_copy_siginfo_to_user() in signal.h, but I
prefered to ifdef out copy_siginfo_to_user32() in compat.h

>
> Otherwise this change looks much cleaner.

Thanks
Christophe

2021-09-14 00:42:10

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [PATCH RESEND v3 6/6] powerpc/signal: Use unsafe_copy_siginfo_to_user()

[email protected] (Eric W. Biederman) writes:

> Christophe Leroy <[email protected]> writes:
>
>> Use unsafe_copy_siginfo_to_user() in order to do the copy
>> within the user access block.
>>
>> On an mpc 8321 (book3s/32) the improvment is about 5% on a process
>> sending a signal to itself.

If you can't make function calls from an unsafe macro there is another
way to handle this that doesn't require everything to be inline.

From a safety perspective it is probably even a better approach.

Eric

diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 0608581967f0..1b30bb78b863 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -205,6 +205,12 @@ struct sigframe {
int abigap[56];
};

+#ifdef CONFIG_PPC64
+# define user_siginfo_t compat_siginfo_t
+#else
+# define user_siginfo_t siginfo_t
+#endif
+
/*
* When we have rt signals to deliver, we set up on the
* user stack, going down from the original stack pointer:
@@ -217,11 +223,7 @@ struct sigframe {
*
*/
struct rt_sigframe {
-#ifdef CONFIG_PPC64
- compat_siginfo_t info;
-#else
- struct siginfo info;
-#endif
+ user_siginfo_t info;
struct ucontext uc;
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
struct ucontext uc_transact;
@@ -712,7 +714,7 @@ static long restore_tm_user_regs(struct pt_regs *regs, struct mcontext __user *s

#ifdef CONFIG_PPC64

-#define copy_siginfo_to_user copy_siginfo_to_user32
+#define copy_siginfo_to_external copy_siginfo_to_external32

#endif /* CONFIG_PPC64 */

@@ -731,6 +733,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
struct pt_regs *regs = tsk->thread.regs;
/* Save the thread's msr before get_tm_stackpointer() changes it */
unsigned long msr = regs->msr;
+ user_siginfo_t uinfo;

/* Set up Signal Frame */
frame = get_sigframe(ksig, tsk, sizeof(*frame), 1);
@@ -743,6 +746,8 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
else
prepare_save_user_regs(1);

+ copy_siginfo_to_external(&uinfo, &ksig->info);
+
if (!user_access_begin(frame, sizeof(*frame)))
goto badframe;

@@ -778,12 +783,10 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
asm("dcbst %y0; sync; icbi %y0; sync" :: "Z" (mctx->mc_pad[0]));
}
unsafe_put_sigset_t(&frame->uc.uc_sigmask, oldset, failed);
+ unsafe_copy_to_user(&frame->info, &uinfo, failed);

user_access_end();

- if (copy_siginfo_to_user(&frame->info, &ksig->info))
- goto badframe;
-
regs->link = tramp;

#ifdef CONFIG_PPC_FPU_REGS

Eric