Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp277674rdb; Thu, 25 Jan 2024 15:23:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSaGDsY8X5T9xq60J1q70Tol7nwTddvQysWuRMbJec9cbH/tI/5K+0JG57L4FBpsG1QfrU X-Received: by 2002:a17:902:f552:b0:1d4:6429:4e1c with SMTP id h18-20020a170902f55200b001d464294e1cmr473458plf.4.1706225007243; Thu, 25 Jan 2024 15:23:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706225007; cv=pass; d=google.com; s=arc-20160816; b=1C6FgSo/RfWJQKghXkk6+nnznLfGu5m35hpC0wL5rnmlXjeK+ZcnwqNEftXcLG8Zk3 EVED4VG7u/4MoUCGg/8SM6Fz3QVEXoMfbNyG2u5I5BlPB9l0L9XCYB0JO+43eiDTVbWK nALws8i64QF1Mr9207S0QpzD+el+IWosMLCUOJ72XQyB/HLyG/Uh1luTa+bMtk0avmyl EqLX9alSLdTUJlkFTYfObZdm5Qfe9OhHxGv2VDIXeZAH930dyeGUdvx97nE6b/JXIeRM wU01uCPeFV4P3ZV9wmcBqdz4n0ZIOfb0lUikDA/KAf+FkpVtYY4z0oHCSy8aXiAQ2rxp 4+NA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rLx5+QasJFO1odf7ddKrCPDJsvCUIFtE7xwairnlLa8=; fh=/KzSCYo0ATKYQ8eqkLNwiYH9CmT2qaa1DaO1/JhgZ+Y=; b=c7MbXuXePZTTqIcP5DeQZ7oayNQ6Qkzpl3qeNfALhJ/6i+jiQnYQ3CYAFwpWHqvooS GoEeNbvTov8vHyZqm8GgJFVlKXylqEVzoihdACEN/LOEqQ7M6WNr6NPd8OK46+TNap+Y RGh24N67BBSxt/1+yBJVTttRxCB2cXV+G62V94Djb2yemGh44qM9Red5dsS3SE9W3zVa RoAygENSznuTGPubI60slklen0RsZHedYGgV9tWv9TVsCO6URqvuXNz8Wi7QZjQdf35s eV4s52QQz1yC+z0DSKvvZDWZ50cfm6B17opuveBfvdZ18h+5DLR2o69PZy6zzLFWwBzZ Lf5A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="G/U+Uh7x"; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-39411-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39411-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z20-20020a170903409400b001d7105e7ff2si36297plc.623.2024.01.25.15.23.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 15:23:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39411-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="G/U+Uh7x"; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-39411-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39411-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F4B1294526 for ; Thu, 25 Jan 2024 23:22:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 991FE134D7; Thu, 25 Jan 2024 23:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="G/U+Uh7x" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FC3412E4E; Thu, 25 Jan 2024 23:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706224956; cv=none; b=QLfnUnU+qhjET+cZUDhpxFfZgUno1M0MVLgXdX2uONqZpAvb/4m02gHrnfIjrpX18wBLmvKu1dQ2Zhzd57lh7PdWMCA632z+8BzaVI+2/KcTSQB8F91Zmnu9qfyR+pt5A7LNl2vdEXdwi3/PW78H3err2u2rBC5qvVE5/xpcp/4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706224956; c=relaxed/simple; bh=587/YeORTOjV4+4rZmCxNEau5T3CAeS60+mA4rS7qv0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jUkzn1AZdvHa40UHL7T2JgbqYAlJP29uob7mdEhl7J9gW6JF0h6cItAwHCIfOCjPy614j4TAKP4ODtazNykbmArrTglsWevz7cmTrZpQK9ANZA4yuM4a8wpGTsPQPk89VCwCsSy1L3K2bRumk+1dikg6F6VZi73NStqXP1mFOqQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=G/U+Uh7x; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1471C433F1; Thu, 25 Jan 2024 23:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706224956; bh=587/YeORTOjV4+4rZmCxNEau5T3CAeS60+mA4rS7qv0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G/U+Uh7xSlHZmssoQ6TdqtZIO6/P8sce/TuhJLXQfa15z5QJa4CejQ4Y+tqrGECzP p3mCGeahqF71sPfCIBBDlc5fWrvczb5IQ5wMqJub3eHrM/aJKUZeQ18I+a1VySgRz8 OZGYj+umd8CQIOdCRaL1CSHJDCDePSXzzg8b4aNM= Date: Thu, 25 Jan 2024 15:22:34 -0800 From: Greg Kroah-Hartman To: Joe Damato Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, linux-api@vger.kernel.org, brauner@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 , Alexander Viro , Jan Kara , Michael Ellerman , Nathan Lynch , Steve French , Thomas Zimmermann , Jiri Slaby , Julien Panis , Arnd Bergmann , Andrew Waterman , Thomas Huth , Palmer Dabbelt , "open list:DOCUMENTATION" , "open list:FILESYSTEMS (VFS and infrastructure)" Subject: Re: [PATCH net-next v3 3/3] eventpoll: Add epoll ioctl for epoll_params Message-ID: <2024012558-coasting-unlatch-9315@gregkh> References: <20240125225704.12781-1-jdamato@fastly.com> <20240125225704.12781-4-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240125225704.12781-4-jdamato@fastly.com> On Thu, Jan 25, 2024 at 10:56:59PM +0000, Joe Damato 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 or packet budget > params for a specific epoll context. > > Signed-off-by: Joe Damato > --- > .../userspace-api/ioctl/ioctl-number.rst | 1 + > fs/eventpoll.c | 64 +++++++++++++++++++ > include/uapi/linux/eventpoll.h | 12 ++++ > 3 files changed, 77 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 > > diff --git a/fs/eventpoll.c b/fs/eventpoll.c > index 40bd97477b91..73ae886efb8a 100644 > --- a/fs/eventpoll.c > +++ b/fs/eventpoll.c > @@ -6,6 +6,8 @@ > * Davide Libenzi > */ > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > + > #include > #include > #include > @@ -37,6 +39,7 @@ > #include > #include > #include > +#include > #include > > /* > @@ -495,6 +498,39 @@ 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; > + struct epoll_params epoll_params; > + void __user *uarg = (void __user *) arg; > + > + ep = file->private_data; > + > + switch (cmd) { > + case EPIOCSPARAMS: > + if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params))) > + return -EFAULT; > + > + if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT && > + !capable(CAP_NET_ADMIN)) > + return -EPERM; > + > + ep->busy_poll_usecs = epoll_params.busy_poll_usecs; > + ep->busy_poll_budget = epoll_params.busy_poll_budget; > + return 0; > + case EPIOCGPARAMS: > + memset(&epoll_params, 0, sizeof(epoll_params)); > + epoll_params.busy_poll_usecs = ep->busy_poll_usecs; > + epoll_params.busy_poll_budget = ep->busy_poll_budget; > + if (copy_to_user(uarg, &epoll_params, sizeof(epoll_params))) > + return -EFAULT; > + return 0; > + default: > + return -ENOIOCTLCMD; > + } > +} > + > #else > > static inline bool ep_busy_loop(struct eventpoll *ep, int nonblock) > @@ -510,6 +546,12 @@ static inline bool ep_busy_loop_on(struct eventpoll *ep) > { > return false; > } > + > +static long ep_eventpoll_bp_ioctl(struct file *file, unsigned int cmd, > + unsigned long arg) > +{ > + return -EOPNOTSUPP; > +} > #endif /* CONFIG_NET_RX_BUSY_POLL */ > > /* > @@ -869,6 +911,26 @@ static void ep_clear_and_put(struct eventpoll *ep) > ep_free(ep); > } > > +static long ep_eventpoll_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > +{ > + int ret; > + > + if (!is_file_epoll(file)) > + return -EINVAL; > + > + switch (cmd) { > + case EPIOCSPARAMS: > + case EPIOCGPARAMS: > + ret = ep_eventpoll_bp_ioctl(file, cmd, arg); > + break; > + default: > + ret = -EINVAL; > + break; > + } > + > + return ret; > +} > + > static int ep_eventpoll_release(struct inode *inode, struct file *file) > { > struct eventpoll *ep = file->private_data; > @@ -975,6 +1037,8 @@ static const struct file_operations eventpoll_fops = { > .release = ep_eventpoll_release, > .poll = ep_eventpoll_poll, > .llseek = noop_llseek, > + .unlocked_ioctl = ep_eventpoll_ioctl, > + .compat_ioctl = compat_ptr_ioctl, > }; > > /* > diff --git a/include/uapi/linux/eventpoll.h b/include/uapi/linux/eventpoll.h > index cfbcc4cc49ac..8eb0fdbce995 100644 > --- a/include/uapi/linux/eventpoll.h > +++ b/include/uapi/linux/eventpoll.h > @@ -85,4 +85,16 @@ struct epoll_event { > __u64 data; > } EPOLL_PACKED; > > +struct epoll_params { > + u64 busy_poll_usecs; > + u16 busy_poll_budget; > + > + /* for future fields */ > + u8 data[118]; You forgot to validate that "data" is set to 0, which means that this would be useless. Why have this at all? thanks, greg k-h