[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANn89iKB=_C4kZ1SFF18DXXaOdL4hXcLAZLWMT3w=-nHyWPaoA@mail.gmail.com>
Date: Sun, 11 Feb 2024 10:40:45 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Joe Damato <jdamato@...tly.com>
Cc: linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
chuck.lever@...cle.com, jlayton@...nel.org, linux-api@...r.kernel.org,
brauner@...nel.org, davem@...emloft.net, alexander.duyck@...il.com,
sridhar.samudrala@...el.com, kuba@...nel.org, willemdebruijn.kernel@...il.com,
weiwan@...gle.com, David.Laight@...lab.com, arnd@...db.de, sdf@...gle.com,
amritha.nambiar@...el.com, Jiri Slaby <jirislaby@...nel.org>,
Jonathan Corbet <corbet@....net>, Alexander Viro <viro@...iv.linux.org.uk>, Jan Kara <jack@...e.cz>,
Michael Ellerman <mpe@...erman.id.au>, Nathan Lynch <nathanl@...ux.ibm.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Maik Broemme <mbroemme@...mpq.org>,
Steve French <stfrench@...rosoft.com>, Thomas Zimmermann <tzimmermann@...e.de>,
Julien Panis <jpanis@...libre.com>, Thomas Huth <thuth@...hat.com>,
Albert Ou <aou@...s.berkeley.edu>, Palmer Dabbelt <palmer@...belt.com>,
"open list:DOCUMENTATION" <linux-doc@...r.kernel.org>,
"open list:FILESYSTEMS (VFS and infrastructure)" <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH net-next v7 4/4] eventpoll: Add epoll ioctl for epoll_params
On Fri, Feb 9, 2024 at 10:15 PM Joe Damato <jdamato@...tly.com> wrote:
>
> Add an ioctl for getting and setting epoll_params. User programs can use
> this ioctl to get and set the busy poll usec time, packet budget, and
> prefer busy poll params for a specific epoll context.
>
> Parameters are limited:
> - busy_poll_usecs is limited to <= s32_max
> - busy_poll_budget is limited to <= NAPI_POLL_WEIGHT by unprivileged
> users (!capable(CAP_NET_ADMIN))
> - prefer_busy_poll must be 0 or 1
> - __pad must be 0
>
> Signed-off-by: Joe Damato <jdamato@...tly.com>
> Acked-by: Stanislav Fomichev <sdf@...gle.com>
> Reviewed-by: Jiri Slaby <jirislaby@...nel.org>
> ---
> .../userspace-api/ioctl/ioctl-number.rst | 1 +
> fs/eventpoll.c | 72 +++++++++++++++++++
> include/uapi/linux/eventpoll.h | 13 ++++
> 3 files changed, 86 insertions(+)
>
> diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
> index 457e16f06e04..b33918232f78 100644
> --- a/Documentation/userspace-api/ioctl/ioctl-number.rst
> +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
> @@ -309,6 +309,7 @@ Code Seq# Include File Comments
> 0x89 0B-DF linux/sockios.h
> 0x89 E0-EF linux/sockios.h SIOCPROTOPRIVATE range
> 0x89 F0-FF linux/sockios.h SIOCDEVPRIVATE range
> +0x8A 00-1F linux/eventpoll.h
> 0x8B all linux/wireless.h
> 0x8C 00-3F WiNRADiO driver
> <http://www.winradio.com.au/>
> diff --git a/fs/eventpoll.c b/fs/eventpoll.c
> index 1b8d01af0c2c..aa58d42737e6 100644
> --- a/fs/eventpoll.c
> +++ b/fs/eventpoll.c
> @@ -37,6 +37,7 @@
> #include <linux/seq_file.h>
> #include <linux/compat.h>
> #include <linux/rculist.h>
> +#include <linux/capability.h>
> #include <net/busy_poll.h>
>
> /*
> @@ -494,6 +495,49 @@ static inline void ep_set_busy_poll_napi_id(struct epitem *epi)
> ep->napi_id = napi_id;
> }
>
> +static long ep_eventpoll_bp_ioctl(struct file *file, unsigned int cmd,
> + unsigned long arg)
> +{
> + struct eventpoll *ep = file->private_data;
> + void __user *uarg = (void __user *)arg;
> + struct epoll_params epoll_params;
> +
> + switch (cmd) {
> + case EPIOCSPARAMS:
> + if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params)))
> + return -EFAULT;
> +
> + /* pad byte must be zero */
> + if (epoll_params.__pad)
> + return -EINVAL;
> +
> + if (epoll_params.busy_poll_usecs > S32_MAX)
> + return -EINVAL;
> +
> + if (epoll_params.prefer_busy_poll > 1)
> + return -EINVAL;
> +
> + if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT &&
> + !capable(CAP_NET_ADMIN))
> + return -EPERM;
> +
> + ep->busy_poll_usecs = epoll_params.busy_poll_usecs;
You need WRITE_ONCE(ep->XXX, val); for all these settings.
> + ep->busy_poll_budget = epoll_params.busy_poll_budget;
> + ep->prefer_busy_poll = epoll_params.prefer_busy_poll;
> + return 0;
> + case EPIOCGPARAMS:
> + memset(&epoll_params, 0, sizeof(epoll_params));
> + epoll_params.busy_poll_usecs = ep->busy_poll_usecs;
You need to use READ_ONCE(ep->XXXXX) for the three reads.
> + epoll_params.busy_poll_budget = ep->busy_poll_budget;
> + epoll_params.prefer_busy_poll = ep->prefer_busy_poll;
> + if (copy_to_user(uarg, &epoll_params, sizeof(epoll_params)))
> + return -EFAULT;
> + return 0;
> + default:
> + return -ENOIOCTLCMD;
> + }
> +}
>
Powered by blists - more mailing lists