Re: [PATCH] signals: check_kill_permission: don't check creds ifsame_thread_group()

From: Oleg Nesterov
Date: Tue May 18 2010 - 10:11:30 EST


On 05/18, David Howells wrote:
>
> Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> > Yes, but both current_cred() and same_thread_group(current, t) call
> > get_current(), and gcc doesn't cache the result because we call
> > audit_signal_info() in between.
>
> Sorry, yes. I was reading get_current() as current_cred() for some reason.
>
> However, you are _still_ calling get_current() twice... So that bit of your
> changelog isn't really correct.

If I read kernel/signal.s correctly - no.

Well, yes, get_current() is still called twice inside check_kill_permission().
But this is because we have audit_signal_info()->audit_dummy_context() which
uses current too.

But "cred = current_cred()" and same_thread_group(current, t) read
gs:current_task only once, so this change really helps (although the
optimization is very minor, of course).

> In fact, get_current() should be __attribute_const__ since it can't change
> whilst you're looking at it, except within switch_to(), probably in a piece of
> assembly code, so gcc should be free to cache it as long as it likes.

Agreed! I thought about this many times.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/