public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <christian@brauner.io>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
	mingo@kernel.org, james.morris@microsoft.com,
	keescook@chromium.org, peterz@infradead.org, sds@tycho.nsa.gov,
	viro@zeniv.linux.org.uk, akpm@linux-foundation.org,
	oleg@redhat.com
Subject: Re: [PATCH v1 04/20] signal: add copy_pending() helper
Date: Tue, 29 May 2018 14:41:59 +0200	[thread overview]
Message-ID: <20180529124159.GB11221@mailbox.org> (raw)
In-Reply-To: <87r2lusl8l.fsf@xmission.com>

On Tue, May 29, 2018 at 07:24:26AM -0500, Eric W. Biederman wrote:
> Christian Brauner <christian@brauner.io> writes:
> 
> > Instead of using a goto for this let's add a simple helper copy_pending()
> > which can be called in both places.
> 
> Ick no.  As far as I can see this just confuses the logic of the
> collect_signal function.
> 
> Instead of having two cases with an optional
> "sigdelset(&list->signal, sig)" if the signal is no longer in the queue,
> you are moving the core work of collect_signal into another function.
> 
> At the very least this is going to make maintenance more difficult
> as now the work of this function is split into two functions.

I do disagree here tbh. The goto jump into it the if part of an if-else
seems pretty nasty.
I also don't know why this should be confusing the logic. There's a
single function that is called in two places and it is declared directly
atop it's only caller. Additionally, recognizing a single name of a
function as being the same in two places is way easier then recognizing
that a multi-line pattern is the same in two places.

Christian

> 
> It most definitely would have made the bug fix to add resched_timer more
> difficult.
> 
> Eric
> 
> > Signed-off-by: Christian Brauner <christian@brauner.io>
> > ---
> > v0->v1:
> > * patch unchanged
> > ---
> >  kernel/signal.c | 54 +++++++++++++++++++++++++++----------------------
> >  1 file changed, 30 insertions(+), 24 deletions(-)
> >
> > diff --git a/kernel/signal.c b/kernel/signal.c
> > index bc750fb4ddcc..baae137455eb 100644
> > --- a/kernel/signal.c
> > +++ b/kernel/signal.c
> > @@ -515,6 +515,19 @@ int unhandled_signal(struct task_struct *tsk, int sig)
> >  	return !tsk->ptrace;
> >  }
> >  
> > +static void copy_pending(siginfo_t *info, struct sigqueue *first,
> > +			 bool *resched_timer)
> > +{
> > +	list_del_init(&first->list);
> > +	copy_siginfo(info, &first->info);
> > +
> > +	*resched_timer = (first->flags & SIGQUEUE_PREALLOC) &&
> > +			 (info->si_code == SI_TIMER) &&
> > +			 (info->si_sys_private);
> > +
> > +	__sigqueue_free(first);
> > +}
> > +
> >  static void collect_signal(int sig, struct sigpending *list, siginfo_t *info,
> >  			   bool *resched_timer)
> >  {
> > @@ -526,8 +539,10 @@ static void collect_signal(int sig, struct sigpending *list, siginfo_t *info,
> >  	*/
> >  	list_for_each_entry(q, &list->list, list) {
> >  		if (q->info.si_signo == sig) {
> > -			if (first)
> > -				goto still_pending;
> > +			if (first) {
> > +				copy_pending(info, first, resched_timer);
> > +				return;
> > +			}
> >  			first = q;
> >  		}
> >  	}
> > @@ -535,29 +550,20 @@ static void collect_signal(int sig, struct sigpending *list, siginfo_t *info,
> >  	sigdelset(&list->signal, sig);
> >  
> >  	if (first) {
> > -still_pending:
> > -		list_del_init(&first->list);
> > -		copy_siginfo(info, &first->info);
> > -
> > -		*resched_timer =
> > -			(first->flags & SIGQUEUE_PREALLOC) &&
> > -			(info->si_code == SI_TIMER) &&
> > -			(info->si_sys_private);
> > -
> > -		__sigqueue_free(first);
> > -	} else {
> > -		/*
> > -		 * Ok, it wasn't in the queue.  This must be
> > -		 * a fast-pathed signal or we must have been
> > -		 * out of queue space.  So zero out the info.
> > -		 */
> > -		clear_siginfo(info);
> > -		info->si_signo = sig;
> > -		info->si_errno = 0;
> > -		info->si_code = SI_USER;
> > -		info->si_pid = 0;
> > -		info->si_uid = 0;
> > +		copy_pending(info, first, resched_timer);
> > +		return;
> >  	}
> > +
> > +	/*
> > +	 * Ok, it wasn't in the queue. This must be a fast-pathed signal or we
> > +	 * must have been out of queue space. So zero out the info.
> > +	 */
> > +	clear_siginfo(info);
> > +	info->si_signo = sig;
> > +	info->si_errno = 0;
> > +	info->si_code = SI_USER;
> > +	info->si_pid = 0;
> > +	info->si_uid = 0;
> >  }
> >  
> >  static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,

  reply	other threads:[~2018-05-29 12:42 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28 21:53 [PATCH v1 00/20] signal: refactor some functions Christian Brauner
2018-05-28 21:53 ` [PATCH v1 01/20] signal: make force_sigsegv() void Christian Brauner
2018-05-28 21:53 ` [PATCH v1 02/20] signal: make kill_as_cred_perm() return bool Christian Brauner
2018-05-28 21:53 ` [PATCH v1 03/20] signal: make may_ptrace_stop() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 04/20] signal: add copy_pending() helper Christian Brauner
2018-05-29 12:24   ` Eric W. Biederman
2018-05-29 12:41     ` Christian Brauner [this message]
2018-05-29 13:44       ` Eric W. Biederman
2018-05-29 13:55         ` Christian Brauner
2018-05-28 21:53 ` [PATCH v1 05/20] signal: flatten do_send_sig_info() Christian Brauner
2018-05-29 12:28   ` Eric W. Biederman
2018-05-29 12:38     ` Christian Brauner
2018-05-30 20:31       ` Eric W. Biederman
2018-05-28 21:53 ` [PATCH v1 06/20] signal: drop else branch in do_signal_stop() Christian Brauner
2018-05-29 14:30   ` Oleg Nesterov
2018-05-29 15:06     ` Christian Brauner
2018-05-28 21:53 ` [PATCH v1 07/20] signal: make do_sigpending() void Christian Brauner
2018-05-28 21:53 ` [PATCH v1 08/20] signal: simplify rt_sigaction() Christian Brauner
2018-05-28 21:53 ` [PATCH v1 09/20] signal: make kill_ok_by_cred() return bool Christian Brauner
2018-05-28 21:53 ` [PATCH v1 10/20] signal: make sig_handler_ignored() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 11/20] signal: make sig_task_ignored() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 12/20] signal: make sig_ignored() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 13/20] signal: make has_pending_signals() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 14/20] signal: make recalc_sigpending_tsk() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 15/20] signal: make unhandled_signal() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 16/20] signal: make flush_sigqueue_mask() void Christian Brauner
2018-05-28 21:53 ` [PATCH v1 17/20] signal: make wants_signal() return bool Christian Brauner
2018-05-28 21:53 ` [PATCH v1 18/20] signal: make legacy_queue() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 19/20] signal: make security_task_kill() " Christian Brauner
2018-05-28 21:53 ` [PATCH v1 20/20] signal: make get_signal() " Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180529124159.GB11221@mailbox.org \
    --to=christian@brauner.io \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.morris@microsoft.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sds@tycho.nsa.gov \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox