Message ID | 20240125003014.43103-4-jdamato@fastly.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-37822-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1335637dyi; Wed, 24 Jan 2024 16:32:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFK8s1cBRVt5sxPSbCzSnj0p7Mf79CEhMj4697wePJP6Lnc+xzSeXvBjMx5E3Ugnj9Y+/bT X-Received: by 2002:a17:906:3b47:b0:a29:32bf:9c8 with SMTP id h7-20020a1709063b4700b00a2932bf09c8mr159380ejf.39.1706142725448; Wed, 24 Jan 2024 16:32:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706142725; cv=pass; d=google.com; s=arc-20160816; b=XZh6nz9e0jvxcur/lARopxuGTI+UD9XpkRcbZFWAWePzi0U+Yh0voNEpMS1eeCLZQg aGZic8gFyWfKivPBIZI6cR+vxdJ1eN8TUXrw/glNfHPqE3aGKLfRfUUlNX3+5VQ0IqBD RIbZteweaVHpc+sNm9hYH50oJWGA5R8F+H9tQUX4fHC1wJPejrvaXLFfYxXg9/V7lyhP cMiQRQumWeSP13lwSCrnbvvxrwbTLyE8JQSiAQmznGpAfwGqrlHB7iaPZHKnJYSSokGL 7D/PT4d2KyLlV5VUtYWXLExdU5tA9XNxWas4+Sn0T4lW4dYrtxH+Ix/fURLdoEHnYicd 75mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mfXKcx732lyegT0JnbCBFxum6PCwYsIbQ8eg5Ffi0GI=; fh=kBROcZlHw+mm7Fiz6uTzYndHaf6u4Vl5PFw7bDv5jto=; b=YE8fsAfV3ea71VDgzIAQJRa5c2lTS/WsPrHQJaFfhzIBwXtw101bpAh6CFDpMaPMEe jxoDp2S5IAubBvf5dm7n8Bap2PofBG4y+cH4yInFfZYNNe4T4Oc+pAR1rkSoO4jEg6NG OTxu3oTcC1RmTal5VXm5eLn1TkTas1vuts/vneRF8phoixKFJjTNSo6HIPrS5gEPR3RI 6IC1txlZD55v5wgSFyl+gfp9k4GWmgHrlf1bGmYp4BFRKIXyH0rEIzC0Q2zeSeterQtx c4azK2Bo2Ja06FuY9LygoPCMNVCoIf5FXZCYTlqAvoU0Ssu4ajZZcXWve/VivIGdd5rJ Lzgg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=Q4QliVc8; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-37822-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37822-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y20-20020a170906471400b00a30f936a555si379179ejq.665.2024.01.24.16.32.05 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 16:32:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37822-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=Q4QliVc8; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-37822-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37822-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id E22C31F2212B for <ouuuleilei@gmail.com>; Thu, 25 Jan 2024 00:32:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFCB1F507; Thu, 25 Jan 2024 00:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="Q4QliVc8" Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07DC267C45 for <linux-kernel@vger.kernel.org>; Thu, 25 Jan 2024 00:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706142627; cv=none; b=u+SIN0/FLBSzaqQXfbGh1JtYXrsD73lILJWpbULpBrTeyokxP2jUcrZPFZ4la/DMiqXK46CHEMtAvr+7qNSDkhekYu7kJSF+RyCxaE2KovDAPqbs6m0qg8i0SVUfv6ByUXcuxF8OjsBMlQ/jXcks3on2ykBh3ffg6ie73KFLmVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706142627; c=relaxed/simple; bh=WtXmg5IZU3NCkx951uq8x5TaAckhdrLYZZQD0cemNCU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ky6j8psij8np0a6Qqa4k0xnO8YBC+Odejlja8Ygbg2ECPP+Blz53OAP1wnCkH4vVLQh3EKKwTBoGyJR4riR8KrmKRv97LFZIR3bWx8Y2YJXaQ8L9WXAH7heXdIvGpCE1b7NslM0iwJgFKvro8Ce7VMEIbnUaCTlI4mXsJiQGcT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=Q4QliVc8; arc=none smtp.client-ip=209.85.160.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-21433afcc53so2536924fac.3 for <linux-kernel@vger.kernel.org>; Wed, 24 Jan 2024 16:30:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1706142625; x=1706747425; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mfXKcx732lyegT0JnbCBFxum6PCwYsIbQ8eg5Ffi0GI=; b=Q4QliVc8V5fIHZX0bf1XoosmwpMW41Gj409Sbv/gkf84IutJJTxOSzp9D4rFZmps3c JIhAvzZMlQqXfzrB+hRycD2WqbPyMVWBnI5VZIk/sY+z9VOATkB73oiaeiMwv3wbgX+6 TPb12iW5ju/yoII31ld99vsa7Y1Od43ZxJmc4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706142625; x=1706747425; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mfXKcx732lyegT0JnbCBFxum6PCwYsIbQ8eg5Ffi0GI=; b=GdPLpeMoxET2+roPfWXZ1Bad81HM5RyshkKfQxY5dyPgXjXe0lrCPkTR936lYxSgdi gmLt+61Pyow2CAsbwPLjO/qsVbAzNFb+Nk4WZvchQf/4KgTnVyK5u1Hk6Rvi7TBzR7Ci WeNywIIf+qFW0mp36aVEomMfr/5Q5SI5b/7OVrTFf4bYlMMtoz1zcy7bolx4U42bjQy1 jNwVeiV4I0mQkI5U3HtIP8KLMfvZwTPCfEamuj+8IAwUjZJSlwGwID7wIVppOi45ww/K J6r4CI6nWXl1EIpEOBjWouSru8GRiD1XFT1tRzYyZnSmv1K6QeyHnC+5g4z7fzqlAjij 2vOA== X-Gm-Message-State: AOJu0YzOEeR4Ytm3oVyj5NmAYhxpsgLGOT20vgsVCEexq/pnm8pk7aAS WQ1Sg9HxsCugSdE5OK/DXFyUmEYgPnWH3lsQ3t4K273Wl+rCXE6NFAXdkxWyBT0= X-Received: by 2002:a05:6871:8191:b0:205:9fe9:67de with SMTP id so17-20020a056871819100b002059fe967demr134665oab.39.1706142625168; Wed, 24 Jan 2024 16:30:25 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c018:0:ea8:be91:8d1:f59b]) by smtp.gmail.com with ESMTPSA id w10-20020a63d74a000000b005cd945c0399sm12550486pgi.80.2024.01.24.16.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 16:30:24 -0800 (PST) From: Joe Damato <jdamato@fastly.com> To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: 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, weiwan@google.com, Joe Damato <jdamato@fastly.com> Subject: [net-next v2 3/4] eventpoll: Add epoll ioctl for epoll_params Date: Thu, 25 Jan 2024 00:30:13 +0000 Message-Id: <20240125003014.43103-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240125003014.43103-1-jdamato@fastly.com> References: <20240125003014.43103-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789020314152405608 X-GMAIL-MSGID: 1789020314152405608 |
Series |
Per epoll context busy poll support
|
|
Commit Message
Joe Damato
Jan. 25, 2024, 12:30 a.m. UTC
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 <jdamato@fastly.com>
---
.../userspace-api/ioctl/ioctl-number.rst | 1 +
fs/eventpoll.c | 47 +++++++++++++++++++
include/uapi/linux/eventpoll.h | 12 +++++
3 files changed, 60 insertions(+)
Comments
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 <jdamato@fastly.com> Please be sure to include the lists and people suggested by `get_maintainer.pl -f fs/eventpoll.c`. Adding ioctls is generally discouraged. As this affects the behavior of epoll_wait, should this just be a flag to (a new variant of) epoll_wait? Speaking from some experience with adding epoll_pwait2. I initially there added a stateful change that would affect wait behavior. The sensible feedback as the time was to just change the behavior of the syscall it affected. Even if that requires a syscall (which is not that different from an ioctl, if better defined). The discussion in that thread may be informative to decide on API: https://lwn.net/ml/linux-kernel/20201116161001.1606608-1-willemdebruijn.kernel@gmail.com/ Agreed on the overall principle that it is preferable to be able to enable busypolling selectively. We already do for SO_BUSY_POLL and sysctl busy_read. > --- > .../userspace-api/ioctl/ioctl-number.rst | 1 + > fs/eventpoll.c | 47 +++++++++++++++++++ > include/uapi/linux/eventpoll.h | 12 +++++ > 3 files changed, 60 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 40bd97477b91..c1ee0fe01da1 100644 > --- a/fs/eventpoll.c > +++ b/fs/eventpoll.c > @@ -6,6 +6,8 @@ > * Davide Libenzi <davidel@xmailserver.org> > */ > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > + > #include <linux/init.h> > #include <linux/kernel.h> > #include <linux/sched/signal.h> > @@ -869,6 +871,49 @@ 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; > + struct eventpoll *ep; > + struct epoll_params epoll_params; > + void __user *uarg = (void __user *) arg; > + > + if (!is_file_epoll(file)) > + return -EINVAL; > + > + ep = file->private_data; > + > + switch (cmd) { > +#ifdef CONFIG_NET_RX_BUSY_POLL > + case EPIOCSPARAMS: > + if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params))) > + return -EFAULT; > + > + if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT) > + pr_err("busy poll budget %u exceeds suggested maximum %u\n", > + epoll_params.busy_poll_budget, NAPI_POLL_WEIGHT); > + > + 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; > +#endif > + 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 +1020,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]; > +} EPOLL_PACKED; > + > +#define EPOLL_IOC_TYPE 0x8A > +#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params) > +#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params) > + > #endif /* _UAPI_LINUX_EVENTPOLL_H */ > -- > 2.25.1 >
On Wed, Jan 24, 2024 at 09:46:23PM -0500, Willem de Bruijn wrote: > 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 <jdamato@fastly.com> > > Please be sure to include the lists and people suggested by > `get_maintainer.pl -f fs/eventpoll.c`. Thanks - I must have done something wrong when trying to get the maintainer list. Should I resend this v2? Not sure what the appropriate thing to do is in this case. My apologies. > Adding ioctls is generally discouraged. > > As this affects the behavior of epoll_wait, should this just be a > flag to (a new variant of) epoll_wait? I have no strong preference either way. It seems to me that adding a new system call is a fairly significant change vs adding an ioctl, but I am open to whatever is preferred by the maintainers. I have no idea who would need to weigh-in to make this decision. > Speaking from some experience with adding epoll_pwait2. I initially > there added a stateful change that would affect wait behavior. The > sensible feedback as the time was to just change the behavior of the > syscall it affected. Even if that requires a syscall (which is not > that different from an ioctl, if better defined). > > The discussion in that thread may be informative to decide on API: > https://lwn.net/ml/linux-kernel/20201116161001.1606608-1-willemdebruijn.kernel@gmail.com/ Interesting thread, thanks for sending. > Agreed on the overall principle that it is preferable to be able to > enable busypolling selectively. We already do for SO_BUSY_POLL and > sysctl busy_read. Thanks for taking a look and providing feedback. > > > --- > > .../userspace-api/ioctl/ioctl-number.rst | 1 + > > fs/eventpoll.c | 47 +++++++++++++++++++ > > include/uapi/linux/eventpoll.h | 12 +++++ > > 3 files changed, 60 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 40bd97477b91..c1ee0fe01da1 100644 > > --- a/fs/eventpoll.c > > +++ b/fs/eventpoll.c > > @@ -6,6 +6,8 @@ > > * Davide Libenzi <davidel@xmailserver.org> > > */ > > > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > + > > #include <linux/init.h> > > #include <linux/kernel.h> > > #include <linux/sched/signal.h> > > @@ -869,6 +871,49 @@ 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; > > + struct eventpoll *ep; > > + struct epoll_params epoll_params; > > + void __user *uarg = (void __user *) arg; > > + > > + if (!is_file_epoll(file)) > > + return -EINVAL; > > + > > + ep = file->private_data; > > + > > + switch (cmd) { > > +#ifdef CONFIG_NET_RX_BUSY_POLL > > + case EPIOCSPARAMS: > > + if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params))) > > + return -EFAULT; > > + > > + if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT) > > + pr_err("busy poll budget %u exceeds suggested maximum %u\n", > > + epoll_params.busy_poll_budget, NAPI_POLL_WEIGHT); > > + > > + 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; > > +#endif > > + 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 +1020,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]; > > +} EPOLL_PACKED; > > + > > +#define EPOLL_IOC_TYPE 0x8A > > +#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params) > > +#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params) > > + > > #endif /* _UAPI_LINUX_EVENTPOLL_H */ > > -- > > 2.25.1 > > > >
Hi Joe, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/eventpoll-support-busy-poll-per-epoll-instance/20240125-083418 base: net-next/main patch link: https://lore.kernel.org/r/20240125003014.43103-4-jdamato%40fastly.com patch subject: [net-next v2 3/4] eventpoll: Add epoll ioctl for epoll_params config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20240125/202401252141.eUlgsF08-lkp@intel.com/config) compiler: or1k-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240125/202401252141.eUlgsF08-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202401252141.eUlgsF08-lkp@intel.com/ All warnings (new ones prefixed by >>): fs/eventpoll.c: In function 'ep_eventpoll_ioctl': >> fs/eventpoll.c:879:22: warning: unused variable 'uarg' [-Wunused-variable] 879 | void __user *uarg = (void __user *) arg; | ^~~~ >> fs/eventpoll.c:878:29: warning: unused variable 'epoll_params' [-Wunused-variable] 878 | struct epoll_params epoll_params; | ^~~~~~~~~~~~ fs/eventpoll.c:877:27: warning: variable 'ep' set but not used [-Wunused-but-set-variable] 877 | struct eventpoll *ep; | ^~ vim +/uarg +879 fs/eventpoll.c 873 874 static long ep_eventpoll_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 875 { 876 int ret; 877 struct eventpoll *ep; > 878 struct epoll_params epoll_params; > 879 void __user *uarg = (void __user *) arg; 880 881 if (!is_file_epoll(file)) 882 return -EINVAL; 883 884 ep = file->private_data; 885 886 switch (cmd) { 887 #ifdef CONFIG_NET_RX_BUSY_POLL 888 case EPIOCSPARAMS: 889 if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params))) 890 return -EFAULT; 891 892 if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT) 893 pr_err("busy poll budget %u exceeds suggested maximum %u\n", 894 epoll_params.busy_poll_budget, NAPI_POLL_WEIGHT); 895 896 ep->busy_poll_usecs = epoll_params.busy_poll_usecs; 897 ep->busy_poll_budget = epoll_params.busy_poll_budget; 898 return 0; 899 900 case EPIOCGPARAMS: 901 memset(&epoll_params, 0, sizeof(epoll_params)); 902 epoll_params.busy_poll_usecs = ep->busy_poll_usecs; 903 epoll_params.busy_poll_budget = ep->busy_poll_budget; 904 if (copy_to_user(uarg, &epoll_params, sizeof(epoll_params))) 905 return -EFAULT; 906 907 return 0; 908 #endif 909 default: 910 ret = -EINVAL; 911 break; 912 } 913 914 return ret; 915 } 916
Joe Damato wrote: > On Wed, Jan 24, 2024 at 09:46:23PM -0500, Willem de Bruijn wrote: > > 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 <jdamato@fastly.com> > > > > Please be sure to include the lists and people suggested by > > `get_maintainer.pl -f fs/eventpoll.c`. > > Thanks - I must have done something wrong when trying to get the maintainer > list. > > Should I resend this v2? Not sure what the appropriate thing to do is in > this case. My apologies. If you don't get additional feedback in a few days and still prefer this option that might be an approach. After reading the below thread, compare the different possible APIs and either revise the code or perhaps add a small paragraph why you think this is the preferred path. > > Adding ioctls is generally discouraged. > > > > As this affects the behavior of epoll_wait, should this just be a > > flag to (a new variant of) epoll_wait? > > I have no strong preference either way. It seems to me that adding a new > system call is a fairly significant change vs adding an ioctl, but I am > open to whatever is preferred by the maintainers. > > I have no idea who would need to weigh-in to make this decision. > > > Speaking from some experience with adding epoll_pwait2. I initially > > there added a stateful change that would affect wait behavior. The > > sensible feedback as the time was to just change the behavior of the > > syscall it affected. Even if that requires a syscall (which is not > > that different from an ioctl, if better defined). > > > > The discussion in that thread may be informative to decide on API: > > https://lwn.net/ml/linux-kernel/20201116161001.1606608-1-willemdebruijn.kernel@gmail.com/ > > Interesting thread, thanks for sending. > > > Agreed on the overall principle that it is preferable to be able to > > enable busypolling selectively. We already do for SO_BUSY_POLL and > > sysctl busy_read. > > Thanks for taking a look and providing feedback. > > > > > > --- > > > .../userspace-api/ioctl/ioctl-number.rst | 1 + > > > fs/eventpoll.c | 47 +++++++++++++++++++ > > > include/uapi/linux/eventpoll.h | 12 +++++ > > > 3 files changed, 60 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 40bd97477b91..c1ee0fe01da1 100644 > > > --- a/fs/eventpoll.c > > > +++ b/fs/eventpoll.c > > > @@ -6,6 +6,8 @@ > > > * Davide Libenzi <davidel@xmailserver.org> > > > */ > > > > > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > > + > > > #include <linux/init.h> > > > #include <linux/kernel.h> > > > #include <linux/sched/signal.h> > > > @@ -869,6 +871,49 @@ 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; > > > + struct eventpoll *ep; > > > + struct epoll_params epoll_params; > > > + void __user *uarg = (void __user *) arg; > > > + > > > + if (!is_file_epoll(file)) > > > + return -EINVAL; > > > + > > > + ep = file->private_data; > > > + > > > + switch (cmd) { > > > +#ifdef CONFIG_NET_RX_BUSY_POLL > > > + case EPIOCSPARAMS: > > > + if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params))) > > > + return -EFAULT; > > > + > > > + if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT) > > > + pr_err("busy poll budget %u exceeds suggested maximum %u\n", > > > + epoll_params.busy_poll_budget, NAPI_POLL_WEIGHT); > > > + > > > + 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; > > > +#endif > > > + 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 +1020,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]; > > > +} EPOLL_PACKED; > > > + > > > +#define EPOLL_IOC_TYPE 0x8A > > > +#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params) > > > +#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params) > > > + > > > #endif /* _UAPI_LINUX_EVENTPOLL_H */ > > > -- > > > 2.25.1 > > > > > > >
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 40bd97477b91..c1ee0fe01da1 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -6,6 +6,8 @@ * Davide Libenzi <davidel@xmailserver.org> */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include <linux/init.h> #include <linux/kernel.h> #include <linux/sched/signal.h> @@ -869,6 +871,49 @@ 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; + struct eventpoll *ep; + struct epoll_params epoll_params; + void __user *uarg = (void __user *) arg; + + if (!is_file_epoll(file)) + return -EINVAL; + + ep = file->private_data; + + switch (cmd) { +#ifdef CONFIG_NET_RX_BUSY_POLL + case EPIOCSPARAMS: + if (copy_from_user(&epoll_params, uarg, sizeof(epoll_params))) + return -EFAULT; + + if (epoll_params.busy_poll_budget > NAPI_POLL_WEIGHT) + pr_err("busy poll budget %u exceeds suggested maximum %u\n", + epoll_params.busy_poll_budget, NAPI_POLL_WEIGHT); + + 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; +#endif + 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 +1020,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]; +} EPOLL_PACKED; + +#define EPOLL_IOC_TYPE 0x8A +#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params) +#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params) + #endif /* _UAPI_LINUX_EVENTPOLL_H */