linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
@ 2024-02-23 10:50 Oleg Nesterov
  2024-02-23 13:41 ` Wen Yang
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2024-02-23 10:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Eric W. Biederman, Christian Brauner, Wen Yang, linux-kernel

get_signal() uses signr or ksig->info.si_signo in a chaotic way, this
looks confusing. Change it to always use signr.

This allows us to simplify the SIGNAL_GROUP_EXIT/group_exec_task branch,
it no longer needs to touch ksig at all.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/signal.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index c9c57d053ce4..690982e6595e 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2727,12 +2727,15 @@ bool get_signal(struct ksignal *ksig)
 		/* Has this task already been marked for death? */
 		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
 		     signal->group_exec_task) {
-			clear_siginfo(&ksig->info);
-			ksig->info.si_signo = signr = SIGKILL;
+			signr = SIGKILL;
 			sigdelset(&current->pending.signal, SIGKILL);
 			trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
-				&sighand->action[SIGKILL - 1]);
+					     &sighand->action[SIGKILL - 1]);
 			recalc_sigpending();
+			/*
+			 * implies do_group_exit(), no need to initialize
+			 * ksig->info
+			 */
 			goto fatal;
 		}
 
@@ -2842,7 +2845,7 @@ bool get_signal(struct ksignal *ksig)
 				spin_lock_irq(&sighand->siglock);
 			}
 
-			if (likely(do_signal_stop(ksig->info.si_signo))) {
+			if (likely(do_signal_stop(signr))) {
 				/* It released the siglock.  */
 				goto relock;
 			}
@@ -2866,7 +2869,7 @@ bool get_signal(struct ksignal *ksig)
 
 		if (sig_kernel_coredump(signr)) {
 			if (print_fatal_signals)
-				print_fatal_signal(ksig->info.si_signo);
+				print_fatal_signal(signr);
 			proc_coredump_connector(current);
 			/*
 			 * If it was able to dump core, this kills all
@@ -2890,7 +2893,7 @@ bool get_signal(struct ksignal *ksig)
 		/*
 		 * Death signals, no core dump.
 		 */
-		do_group_exit(ksig->info.si_signo);
+		do_group_exit(signr);
 		/* NOTREACHED */
 	}
 	spin_unlock_irq(&sighand->siglock);
-- 
2.25.1.362.g51ebf55



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
  2024-02-23 10:50 [PATCH] get_signal: simplify/cleanup the the usage of ksig->info Oleg Nesterov
@ 2024-02-23 13:41 ` Wen Yang
  2024-02-23 14:19   ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: Wen Yang @ 2024-02-23 13:41 UTC (permalink / raw)
  To: Oleg Nesterov, Andrew Morton
  Cc: Eric W. Biederman, Christian Brauner, linux-kernel



On 2024/2/23 18:50, Oleg Nesterov wrote:
> get_signal() uses signr or ksig->info.si_signo in a chaotic way, this
> looks confusing. Change it to always use signr.
> 
> This allows us to simplify the SIGNAL_GROUP_EXIT/group_exec_task branch,
> it no longer needs to touch ksig at all.
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>   kernel/signal.c | 15 +++++++++------
>   1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/signal.c b/kernel/signal.c
> index c9c57d053ce4..690982e6595e 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -2727,12 +2727,15 @@ bool get_signal(struct ksignal *ksig)
>   		/* Has this task already been marked for death? */
>   		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
>   		     signal->group_exec_task) {
> -			clear_siginfo(&ksig->info);
> -			ksig->info.si_signo = signr = SIGKILL;
> +			signr = SIGKILL;
>   			sigdelset(&current->pending.signal, SIGKILL);
>   			trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
> -				&sighand->action[SIGKILL - 1]);
> +					     &sighand->action[SIGKILL - 1]);
>   			recalc_sigpending();
> +			/*
> +			 * implies do_group_exit(), no need to initialize
> +			 * ksig->info
> +			 */
>   			goto fatal;

There is little question:
If the this conditions is met:
    current->flags & PF_USER_WORKER
It may execute “goto out“ instead of do_group_exit().

--
Best wishes,
Wen


>   		}
>   
> @@ -2842,7 +2845,7 @@ bool get_signal(struct ksignal *ksig)
>   				spin_lock_irq(&sighand->siglock);
>   			}
>   
> -			if (likely(do_signal_stop(ksig->info.si_signo))) {
> +			if (likely(do_signal_stop(signr))) {
>   				/* It released the siglock.  */
>   				goto relock;
>   			}
> @@ -2866,7 +2869,7 @@ bool get_signal(struct ksignal *ksig)
>   
>   		if (sig_kernel_coredump(signr)) {
>   			if (print_fatal_signals)
> -				print_fatal_signal(ksig->info.si_signo);
> +				print_fatal_signal(signr);
>   			proc_coredump_connector(current);
>   			/*
>   			 * If it was able to dump core, this kills all
> @@ -2890,7 +2893,7 @@ bool get_signal(struct ksignal *ksig)
>   		/*
>   		 * Death signals, no core dump.
>   		 */
> -		do_group_exit(ksig->info.si_signo);
> +		do_group_exit(signr);
>   		/* NOTREACHED */
>   	}
>   	spin_unlock_irq(&sighand->siglock);


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
  2024-02-23 13:41 ` Wen Yang
@ 2024-02-23 14:19   ` Oleg Nesterov
  2024-02-23 14:31     ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2024-02-23 14:19 UTC (permalink / raw)
  To: Wen Yang
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, linux-kernel

On 02/23, Wen Yang wrote:
>
>
> On 2024/2/23 18:50, Oleg Nesterov wrote:
> >get_signal() uses signr or ksig->info.si_signo in a chaotic way, this
> >looks confusing. Change it to always use signr.
> >
> >This allows us to simplify the SIGNAL_GROUP_EXIT/group_exec_task branch,
> >it no longer needs to touch ksig at all.
> >
> >Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> >---
> >  kernel/signal.c | 15 +++++++++------
> >  1 file changed, 9 insertions(+), 6 deletions(-)
> >
> >diff --git a/kernel/signal.c b/kernel/signal.c
> >index c9c57d053ce4..690982e6595e 100644
> >--- a/kernel/signal.c
> >+++ b/kernel/signal.c
> >@@ -2727,12 +2727,15 @@ bool get_signal(struct ksignal *ksig)
> >  		/* Has this task already been marked for death? */
> >  		if ((signal->flags & SIGNAL_GROUP_EXIT) ||
> >  		     signal->group_exec_task) {
> >-			clear_siginfo(&ksig->info);
> >-			ksig->info.si_signo = signr = SIGKILL;
> >+			signr = SIGKILL;
> >  			sigdelset(&current->pending.signal, SIGKILL);
> >  			trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
> >-				&sighand->action[SIGKILL - 1]);
> >+					     &sighand->action[SIGKILL - 1]);
> >  			recalc_sigpending();
> >+			/*
> >+			 * implies do_group_exit(), no need to initialize
> >+			 * ksig->info
> >+			 */
> >  			goto fatal;
>
> There is little question:
> If the this conditions is met:
>    current->flags & PF_USER_WORKER
> It may execute “goto out“ instead of do_group_exit().

Yes, but vhost/io workers do not use ksig at all.

Oleg.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
  2024-02-23 14:19   ` Oleg Nesterov
@ 2024-02-23 14:31     ` Oleg Nesterov
  2024-02-23 14:44       ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2024-02-23 14:31 UTC (permalink / raw)
  To: Wen Yang
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, linux-kernel

On 02/23, Oleg Nesterov wrote:
>
> On 02/23, Wen Yang wrote:
> >
> >
> > On 2024/2/23 18:50, Oleg Nesterov wrote:
> > >+			/*
> > >+			 * implies do_group_exit(), no need to initialize
> > >+			 * ksig->info
> > >+			 */
> > >  			goto fatal;
> >
> > There is little question:
> > If the this conditions is met:
> >    current->flags & PF_USER_WORKER
> > It may execute “goto out“ instead of do_group_exit().
>
> Yes, but vhost/io workers do not use ksig at all.

Ah, wait...

I forgot about the ->sa_flags check before hide_si_addr_tag_bits().

OK, thanks... I'll send V2.

Oleg.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
  2024-02-23 14:31     ` Oleg Nesterov
@ 2024-02-23 14:44       ` Oleg Nesterov
  2024-02-26  9:52         ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2024-02-23 14:44 UTC (permalink / raw)
  To: Wen Yang
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, linux-kernel

On 02/23, Oleg Nesterov wrote:
>
> On 02/23, Oleg Nesterov wrote:
> >
> > On 02/23, Wen Yang wrote:
> > >
> > >
> > > On 2024/2/23 18:50, Oleg Nesterov wrote:
> > > >+			/*
> > > >+			 * implies do_group_exit(), no need to initialize
> > > >+			 * ksig->info
> > > >+			 */
> > > >  			goto fatal;
> > >
> > > There is little question:
> > > If the this conditions is met:
> > >    current->flags & PF_USER_WORKER
> > > It may execute “goto out“ instead of do_group_exit().
> >
> > Yes, but vhost/io workers do not use ksig at all.
>
> Ah, wait...
>
> I forgot about the ->sa_flags check before hide_si_addr_tag_bits().
>
> OK, thanks... I'll send V2.

Tomorrow.

I'll recheck, but I think we need the patch below as 1/2 regadless of
this change

Oleg.
---

--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2897,13 +2897,13 @@ bool get_signal(struct ksignal *ksig)
 		/* NOTREACHED */
 	}
 	spin_unlock_irq(&sighand->siglock);
-out:
+
 	ksig->sig = signr;
 
 	if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
 		hide_si_addr_tag_bits(ksig);
-
-	return ksig->sig > 0;
+out:
+	return signr > 0;
 }
 
 /**


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
  2024-02-23 14:44       ` Oleg Nesterov
@ 2024-02-26  9:52         ` Oleg Nesterov
  2024-02-26 15:06           ` Wen Yang
  0 siblings, 1 reply; 7+ messages in thread
From: Oleg Nesterov @ 2024-02-26  9:52 UTC (permalink / raw)
  To: Wen Yang
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, linux-kernel

OK, lets forget about "no need to initialize ksig->info" part for now.

Yes, PF_USER_WORKER's never dereference ksig, but I agree this doesn't
look clean without other cleanups. I'll probably return to this later
when other pending problems with PF_USER_WORKER are fixed.

Wen, thanks again for your review.

Oleg.

On 02/23, Oleg Nesterov wrote:
>
> On 02/23, Oleg Nesterov wrote:
> >
> > On 02/23, Oleg Nesterov wrote:
> > >
> > > On 02/23, Wen Yang wrote:
> > > >
> > > >
> > > > On 2024/2/23 18:50, Oleg Nesterov wrote:
> > > > >+			/*
> > > > >+			 * implies do_group_exit(), no need to initialize
> > > > >+			 * ksig->info
> > > > >+			 */
> > > > >  			goto fatal;
> > > >
> > > > There is little question:
> > > > If the this conditions is met:
> > > >    current->flags & PF_USER_WORKER
> > > > It may execute “goto out“ instead of do_group_exit().
> > >
> > > Yes, but vhost/io workers do not use ksig at all.
> >
> > Ah, wait...
> >
> > I forgot about the ->sa_flags check before hide_si_addr_tag_bits().
> >
> > OK, thanks... I'll send V2.
>
> Tomorrow.
>
> I'll recheck, but I think we need the patch below as 1/2 regadless of
> this change
>
> Oleg.
> ---
>
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -2897,13 +2897,13 @@ bool get_signal(struct ksignal *ksig)
>  		/* NOTREACHED */
>  	}
>  	spin_unlock_irq(&sighand->siglock);
> -out:
> +
>  	ksig->sig = signr;
>
>  	if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
>  		hide_si_addr_tag_bits(ksig);
> -
> -	return ksig->sig > 0;
> +out:
> +	return signr > 0;
>  }
>
>  /**


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] get_signal: simplify/cleanup the the usage of ksig->info
  2024-02-26  9:52         ` Oleg Nesterov
@ 2024-02-26 15:06           ` Wen Yang
  0 siblings, 0 replies; 7+ messages in thread
From: Wen Yang @ 2024-02-26 15:06 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, linux-kernel



On 2024/2/26 17:52, Oleg Nesterov wrote:
> OK, lets forget about "no need to initialize ksig->info" part for now.
> 
> Yes, PF_USER_WORKER's never dereference ksig, but I agree this doesn't
> look clean without other cleanups. I'll probably return to this later
> when other pending problems with PF_USER_WORKER are fixed.
> 
> Wen, thanks again for your review.
> 
> Oleg.
> 


Thank you very much, Oleg,

We greatly appreciate your comments and the discussion has given us a 
precious opportunity to understand the linux signal.

--
Best wishes,
Wen


> On 02/23, Oleg Nesterov wrote:
>>
>> On 02/23, Oleg Nesterov wrote:
>>>
>>> On 02/23, Oleg Nesterov wrote:
>>>>
>>>> On 02/23, Wen Yang wrote:
>>>>>
>>>>>
>>>>> On 2024/2/23 18:50, Oleg Nesterov wrote:
>>>>>> +			/*
>>>>>> +			 * implies do_group_exit(), no need to initialize
>>>>>> +			 * ksig->info
>>>>>> +			 */
>>>>>>   			goto fatal;
>>>>>
>>>>> There is little question:
>>>>> If the this conditions is met:
>>>>>     current->flags & PF_USER_WORKER
>>>>> It may execute “goto out“ instead of do_group_exit().
>>>>
>>>> Yes, but vhost/io workers do not use ksig at all.
>>>
>>> Ah, wait...
>>>
>>> I forgot about the ->sa_flags check before hide_si_addr_tag_bits().
>>>
>>> OK, thanks... I'll send V2.
>>
>> Tomorrow.
>>
>> I'll recheck, but I think we need the patch below as 1/2 regadless of
>> this change
>>
>> Oleg.
>> ---
>>
>> --- a/kernel/signal.c
>> +++ b/kernel/signal.c
>> @@ -2897,13 +2897,13 @@ bool get_signal(struct ksignal *ksig)
>>   		/* NOTREACHED */
>>   	}
>>   	spin_unlock_irq(&sighand->siglock);
>> -out:
>> +
>>   	ksig->sig = signr;
>>
>>   	if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
>>   		hide_si_addr_tag_bits(ksig);
>> -
>> -	return ksig->sig > 0;
>> +out:
>> +	return signr > 0;
>>   }
>>
>>   /**
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-26 15:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 10:50 [PATCH] get_signal: simplify/cleanup the the usage of ksig->info Oleg Nesterov
2024-02-23 13:41 ` Wen Yang
2024-02-23 14:19   ` Oleg Nesterov
2024-02-23 14:31     ` Oleg Nesterov
2024-02-23 14:44       ` Oleg Nesterov
2024-02-26  9:52         ` Oleg Nesterov
2024-02-26 15:06           ` Wen Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).