From: ebiederm@xmission.com (Eric W. Biederman)
To: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Oleg Nesterov <oleg@redhat.com>, Andrei Vagin <avagin@gmail.com>,
Adrian Reber <areber@redhat.com>,
Pavel Emelyanov <ovzxemul@gmail.com>,
Jann Horn <jannh@google.com>,
Dmitry Safonov <0x7f454c46@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org, Mike Rapoport <rppt@linux.ibm.com>,
Radostin Stoyanov <rstoyanov1@gmail.com>
Subject: Re: [PATCH v10 1/2] fork: extend clone3() to support setting a PID
Date: Sat, 16 Nov 2019 16:55:59 -0600 [thread overview]
Message-ID: <87wobz5t34.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <20191115130800.zntefr5ptabdngph@wittgenstein> (Christian Brauner's message of "Fri, 15 Nov 2019 14:08:01 +0100")
Christian Brauner <christian.brauner@ubuntu.com> writes:
> On Fri, Nov 15, 2019 at 11:49:10AM +0100, Oleg Nesterov wrote:
>> On 11/15, Christian Brauner wrote:
>> >
>> > +static int set_tid_next(pid_t *set_tid, size_t *size, int idx)
>> > +{
>> > + int tid = 0;
>> > +
>> > + if (*size) {
>> > + tid = set_tid[idx];
>> > + if (tid < 1 || tid >= pid_max)
>> > + return -EINVAL;
>> > +
>> > + /*
>> > + * Also fail if a PID != 1 is requested and
>> > + * no PID 1 exists.
>> > + */
>> > + if (tid != 1 && !tmp->child_reaper)
>> > + return -EINVAL;
>> > +
>> > + if (!ns_capable(tmp->user_ns, CAP_SYS_ADMIN))
>> > + return -EPERM;
>> > +
>> > + (*size)--;
>> > + }
>>
>> this needs more args, struct pid_namespace *tmp + pid_t pid_max
>> if (set_tid_size) {
>> tid = set_tid[ns->level - i];
>>
>> retval = -EINVAL;
>> if (tid < 1 || tid >= pid_max)
>> goto out_free;
>
> I'm not a fan of this pattern of _not_ setting error codes in the actual
> error path t but I won't object.
If you can show a compiler that actually manages to reliably perform
that code motion it is worth discussing making it go away. Last I
checked gcc will emit an extra basic block just to handle setting
the error code before jumping to the out_free. That extra basic block
because of the extra jump tends to be costly.
Not a huge cost but in these days when branches are getting increasingly
expensive and Moore's law wrapping up I prefer code patterns that
generate cood code.
Eric
prev parent reply other threads:[~2019-11-16 22:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-14 14:27 [PATCH v10 1/2] fork: extend clone3() to support setting a PID Adrian Reber
2019-11-14 14:27 ` [PATCH v10 2/2] selftests: add tests for clone3() with *set_tid Adrian Reber
2019-11-14 14:49 ` Christian Brauner
2019-11-14 18:34 ` Andrei Vagin
2019-11-15 15:14 ` Adrian Reber
2019-11-15 18:39 ` Andrei Vagin
2019-11-14 19:05 ` Andrei Vagin
2019-11-14 15:50 ` [PATCH v10 1/2] fork: extend clone3() to support setting a PID Oleg Nesterov
2019-11-14 16:40 ` Christian Brauner
2019-11-14 19:15 ` Andrei Vagin
2019-11-15 9:34 ` Oleg Nesterov
2019-11-15 9:58 ` Christian Brauner
2019-11-15 10:49 ` Oleg Nesterov
2019-11-15 13:08 ` Christian Brauner
2019-11-16 22:55 ` Eric W. Biederman [this message]
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=87wobz5t34.fsf@x220.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=0x7f454c46@gmail.com \
--cc=areber@redhat.com \
--cc=avagin@gmail.com \
--cc=christian.brauner@ubuntu.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=oleg@redhat.com \
--cc=ovzxemul@gmail.com \
--cc=rppt@linux.ibm.com \
--cc=rstoyanov1@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).