All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	matthewb@google.com, Jesse Barnes <jsbarnes@google.com>,
	vapier@google.com, Christian Brauner <christian@brauner.io>,
	vpillai <vpillai@digitalocean.com>,
	vineethrp@gmail.com, Peter Zijlstra <peterz@infradead.org>,
	stable <stable@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] sched/headers: Fix sched_setattr userspace compilation breakage
Date: Thu, 28 May 2020 19:08:59 -0400	[thread overview]
Message-ID: <20200528230859.GB225299@google.com> (raw)
In-Reply-To: <CAHk-=wjgtD6drydXP5h_r90v0sCSQe7BMk7AiYADhJ-x9HGgkg@mail.gmail.com>

Hi Linus,

On Thu, May 28, 2020 at 03:21:56PM -0700, Linus Torvalds wrote:
> On Thu, May 28, 2020 at 6:55 AM Joel Fernandes (Google)
> <joel@joelfernandes.org> wrote:
> >
> > On a modern Linux distro, compiling the following program fails:
> >  #include<stdlib.h>
> >  #include<stdint.h>
> >  #include<pthread.h>
> >  #include<linux/sched/types.h>
> 
> You shouldn't include kernel headers in user space - that's the job of
> glibc and friends.

Ah, my bad. Sorry I read the docs now and looks like I got it all backwards.

> 
> > --- a/include/uapi/linux/sched/types.h
> > +++ b/include/uapi/linux/sched/types.h
> > @@ -4,9 +4,11 @@
> >
> >  #include <linux/types.h>
> >
> > +#if defined(__KERNEL__)
> >  struct sched_param {
> >         int sched_priority;
> >  };
> > +#endif
> 
> This makes no sense.
> 
> The point of a 'uapi' header is to export things to user space. Yes,
> they sometimes mix kernel-internal thngs in there (because of how they
> were created by just moving kernel headers to the uapi directory), but
> that ' struct sched_param' is very much part of the very interface
> definition that that file is all about exporting.
> 
> So no, this patch is fundamentally wrong. It negates the whole point
> of having a uapi header at all.

Sorry, I naively assumed that headers in 'include/uapi/' are safe to include
from userspace. I feel terrible.

> The glibc-provided "<sched.h>" should have been where you got all
> these declarations and #defines from, and the point of the uapi file
> was always to help glibc (and other library implementations) get them
> from the kernel.

The problem is <sched.h> still does not get us 'struct sched_attr' even
though the manpage of sched_setattr(2) says including <sched.h> is all that's
needed.

> 
> So why are you including kernel header files and mixing them with
> system-provided stuff?

The include of <sched.h> does not result in availability of the sched_attr
header.

Also, even if glibc included 'include/uapi/linux/sched/types.h' to get struct
sched_attr's definition, we would run into the same issue I reported right?
The 'struct sched_param' is already defined by glibc, and this header
redefines it.

Sorry that this patch is wrong, I'll try to fix it the right way. Thanks for
your help.

thanks,

 - Joel


  reply	other threads:[~2020-05-28 23:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 13:55 [PATCH] sched/headers: Fix sched_setattr userspace compilation breakage Joel Fernandes (Google)
2020-05-28 22:21 ` Linus Torvalds
2020-05-28 23:08   ` Joel Fernandes [this message]
2020-05-28 23:23     ` Linus Torvalds
2020-05-29  1:45       ` Joel Fernandes
2020-05-29  2:17         ` Linus Torvalds
2020-05-29 16:17           ` Joel Fernandes

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=20200528230859.GB225299@google.com \
    --to=joel@joelfernandes.org \
    --cc=christian@brauner.io \
    --cc=gregkh@linuxfoundation.org \
    --cc=jsbarnes@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthewb@google.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vapier@google.com \
    --cc=vineethrp@gmail.com \
    --cc=vpillai@digitalocean.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.