From: Joe Damato <jdamato@fastly•com>
To: Christian Brauner <brauner@kernel•org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation•org>,
linux-kernel@vger•kernel.org, netdev@vger•kernel.org,
chuck.lever@oracle•com, jlayton@kernel•org,
linux-api@vger•kernel.org, edumazet@google•com,
davem@davemloft•net, alexander.duyck@gmail•com,
sridhar.samudrala@intel•com, kuba@kernel•org,
willemdebruijn.kernel@gmail•com, weiwan@google•com,
Jonathan Corbet <corbet@lwn•net>,
Alexander Viro <viro@zeniv•linux.org.uk>, Jan Kara <jack@suse•cz>,
Michael Ellerman <mpe@ellerman•id.au>,
Nathan Lynch <nathanl@linux•ibm.com>,
Steve French <stfrench@microsoft•com>,
Thomas Zimmermann <tzimmermann@suse•de>,
Jiri Slaby <jirislaby@kernel•org>,
Julien Panis <jpanis@baylibre•com>, Arnd Bergmann <arnd@arndb•de>,
Andrew Waterman <waterman@eecs•berkeley.edu>,
Thomas Huth <thuth@redhat•com>,
Palmer Dabbelt <palmer@dabbelt•com>,
"open list:DOCUMENTATION" <linux-doc@vger•kernel.org>,
"open list:FILESYSTEMS (VFS and infrastructure)"
<linux-fsdevel@vger•kernel.org>
Subject: Re: [PATCH net-next v3 3/3] eventpoll: Add epoll ioctl for epoll_params
Date: Fri, 26 Jan 2024 08:52:18 -0800 [thread overview]
Message-ID: <20240126165217.GA1463@fastly.com> (raw)
In-Reply-To: <20240126-kribbeln-sonnabend-35dcb3d1fc48@brauner>
On Fri, Jan 26, 2024 at 11:07:36AM +0100, Christian Brauner wrote:
> On Thu, Jan 25, 2024 at 06:36:30PM -0800, Joe Damato wrote:
> > On Thu, Jan 25, 2024 at 04:23:58PM -0800, Greg Kroah-Hartman wrote:
> > > On Thu, Jan 25, 2024 at 04:11:28PM -0800, Joe Damato wrote:
> > > > On Thu, Jan 25, 2024 at 03:21:46PM -0800, Greg Kroah-Hartman wrote:
> > > > > On Thu, Jan 25, 2024 at 10:56:59PM +0000, Joe Damato wrote:
> > > > > > +struct epoll_params {
> > > > > > + u64 busy_poll_usecs;
> > > > > > + u16 busy_poll_budget;
> > > > > > +
> > > > > > + /* for future fields */
> > > > > > + u8 data[118];
> > > > > > +} EPOLL_PACKED;
> > > > >
> > > > > variables that cross the user/kernel boundry need to be __u64, __u16,
> > > > > and __u8 here.
> > > >
> > > > I'll make that change for the next version, thank you.
> > > >
> > > > > And why 118?
> > > >
> > > > I chose this arbitrarily. I figured that a 128 byte struct would support 16
> > > > u64s in the event that other fields needed to be added in the future. 118
> > > > is what was left after the existing fields. There's almost certainly a
> > > > better way to do this - or perhaps it is unnecessary as per your other
> > > > message.
> > > >
> > > > I am not sure if leaving extra space in the struct is a recommended
> > > > practice for ioctls or not - I thought I noticed some code that did and
> > > > some that didn't in the kernel so I err'd on the side of leaving the space
> > > > and probably did it in the worst way possible.
> > >
> > > It's not really a good idea unless you know exactly what you are going
> > > to do with it. Why not just have a new ioctl if you need new
> > > information in the future? That's simpler, right?
> >
> > Sure, that makes sense to me. I'll remove it in the v4 alongside the other
> > changes you've requested.
>
> Fwiw, we do support extensible ioctls since they encode the size. Take a
> look at kernel/seccomp.c. It's a clean extensible interface built on top
> of the copy_struct_from_user() pattern we added for system calls
> (openat(), clone3() etc.):
>
> static long seccomp_notify_ioctl(struct file *file, unsigned int cmd,
> unsigned long arg)
> {
> struct seccomp_filter *filter = file->private_data;
> void __user *buf = (void __user *)arg;
>
> /* Fixed-size ioctls */
> switch (cmd) {
> case SECCOMP_IOCTL_NOTIF_RECV:
> return seccomp_notify_recv(filter, buf);
> case SECCOMP_IOCTL_NOTIF_SEND:
> return seccomp_notify_send(filter, buf);
> case SECCOMP_IOCTL_NOTIF_ID_VALID_WRONG_DIR:
> case SECCOMP_IOCTL_NOTIF_ID_VALID:
> return seccomp_notify_id_valid(filter, buf);
> case SECCOMP_IOCTL_NOTIF_SET_FLAGS:
> return seccomp_notify_set_flags(filter, arg);
> }
>
> /* Extensible Argument ioctls */
> #define EA_IOCTL(cmd) ((cmd) & ~(IOC_INOUT | IOCSIZE_MASK))
> switch (EA_IOCTL(cmd)) {
> case EA_IOCTL(SECCOMP_IOCTL_NOTIF_ADDFD):
> return seccomp_notify_addfd(filter, buf, _IOC_SIZE(cmd));
> default:
> return -EINVAL;
> }
> }
>
> static long seccomp_notify_addfd(struct seccomp_filter *filter,
> struct seccomp_notif_addfd __user *uaddfd,
> unsigned int size)
> {
> struct seccomp_notif_addfd addfd;
> struct seccomp_knotif *knotif;
> struct seccomp_kaddfd kaddfd;
> int ret;
>
> BUILD_BUG_ON(sizeof(addfd) < SECCOMP_NOTIFY_ADDFD_SIZE_VER0);
> BUILD_BUG_ON(sizeof(addfd) != SECCOMP_NOTIFY_ADDFD_SIZE_LATEST);
>
> if (size < SECCOMP_NOTIFY_ADDFD_SIZE_VER0 || size >= PAGE_SIZE)
> return -EINVAL;
>
> ret = copy_struct_from_user(&addfd, sizeof(addfd), uaddfd, size);
> if (ret)
> return ret;
Thanks; that's a really helpful note and example.
I'm inclined to believe that new fields probably won't be needed for a
while, but if they are: an extensible ioctl could be added in the future
to deal with that problem at that point.
Thanks,
Joe
next prev parent reply other threads:[~2024-01-26 16:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 22:56 [PATCH net-next v3 0/3] Per epoll context busy poll support Joe Damato
2024-01-25 22:56 ` [PATCH net-next v3 1/3] eventpoll: support busy poll per epoll instance Joe Damato
2024-01-25 22:56 ` [PATCH net-next v3 2/3] eventpoll: Add per-epoll busy poll packet budget Joe Damato
2024-01-25 22:56 ` [PATCH net-next v3 3/3] eventpoll: Add epoll ioctl for epoll_params Joe Damato
2024-01-25 23:20 ` Greg Kroah-Hartman
2024-01-26 0:04 ` Joe Damato
2024-01-25 23:21 ` Greg Kroah-Hartman
2024-01-26 0:11 ` Joe Damato
2024-01-26 0:23 ` Greg Kroah-Hartman
2024-01-26 2:36 ` Joe Damato
2024-01-26 6:16 ` Arnd Bergmann
2024-01-27 14:51 ` David Laight
2024-01-26 10:07 ` Christian Brauner
2024-01-26 16:52 ` Joe Damato [this message]
2024-01-25 23:22 ` Greg Kroah-Hartman
2024-01-26 0:07 ` Joe Damato
2024-01-28 11:24 ` kernel test robot
2024-01-27 16:20 ` [PATCH net-next v3 0/3] Per epoll context busy poll support Willem de Bruijn
2024-01-29 19:09 ` Joe Damato
2024-01-30 20:33 ` Willem de Bruijn
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=20240126165217.GA1463@fastly.com \
--to=jdamato@fastly$(echo .)com \
--cc=alexander.duyck@gmail$(echo .)com \
--cc=arnd@arndb$(echo .)de \
--cc=brauner@kernel$(echo .)org \
--cc=chuck.lever@oracle$(echo .)com \
--cc=corbet@lwn$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=edumazet@google$(echo .)com \
--cc=gregkh@linuxfoundation$(echo .)org \
--cc=jack@suse$(echo .)cz \
--cc=jirislaby@kernel$(echo .)org \
--cc=jlayton@kernel$(echo .)org \
--cc=jpanis@baylibre$(echo .)com \
--cc=kuba@kernel$(echo .)org \
--cc=linux-api@vger$(echo .)kernel.org \
--cc=linux-doc@vger$(echo .)kernel.org \
--cc=linux-fsdevel@vger$(echo .)kernel.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=mpe@ellerman$(echo .)id.au \
--cc=nathanl@linux$(echo .)ibm.com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=palmer@dabbelt$(echo .)com \
--cc=sridhar.samudrala@intel$(echo .)com \
--cc=stfrench@microsoft$(echo .)com \
--cc=thuth@redhat$(echo .)com \
--cc=tzimmermann@suse$(echo .)de \
--cc=viro@zeniv$(echo .)linux.org.uk \
--cc=waterman@eecs$(echo .)berkeley.edu \
--cc=weiwan@google$(echo .)com \
--cc=willemdebruijn.kernel@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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