From patchwork Wed Jan 24 02:53:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13528456 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (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 C936B17593 for ; Wed, 24 Jan 2024 02:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064872; cv=none; b=P0yf3ZWwj6G/N/9QSQyr2oLYt1y9mUG2kJGzmS7hy/M7yThniC3AZ+LyYzrRcBCVTGgNqwlhZmTVIa9Ic2ya6KcPLoL/8MasIgtJRQtaqChECQHKMNKOeq2nXB4Pc3I90fNaQO5HwKVhJS2kKLcifJtA2bQX77xzL4RJhrwsx84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064872; c=relaxed/simple; bh=jEpGsvLii/mVQkq2gxlG8k/giShd2XXjSIODjknHbrE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NrtPcX5nBzbtR4moAsMTK5403tNO9Se1r05GyAasZ79my5LSWt7LeEvX4Ye5DBueh48VZJzCP+glzEtNtsD+OChPye3MMXZJyXi9tleS4A87xkNiA8enYWjZAx7jeU8cgWzUq1od2x7v4GsZENa0aG07LKCi7fZ1qauuaqO85sU= 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=RxqyEH6O; arc=none smtp.client-ip=209.85.167.172 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="RxqyEH6O" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3bd5c4cffefso4946398b6e.1 for ; Tue, 23 Jan 2024 18:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1706064869; x=1706669669; 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=vDDvozY18VzUKM9utNCLkKJpAjjBedBawVpo6PogSYE=; b=RxqyEH6OU/Dc7j7G6TLwlM6PZR/QaiwtH4HVR1DnCmRJe/4X1w2Bnc9H4NUsebsm+G RJVqLhphdsHx3sLt+FkjQ8KIqONYPkdSbic+l2OoFYB7tNH0IkLdTEBF7VX9fTDQrHR0 aevov3B87YxPeJ+AVArv6QjT6f2Ej5LDqxnxc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706064869; x=1706669669; 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=vDDvozY18VzUKM9utNCLkKJpAjjBedBawVpo6PogSYE=; b=L4rpGJI84MRBUNM4c9VF8oL02LV8Beeim3BlhFfn08hbqhJ1oY9AfiTwYtAUMAQZuW J1C3da0P66bBBYkMbGEKw5J+uP6rn7WUPvZLBqpJ7F5ISkJVsaLPHTJ37PaNmbkj4TCM kPslNNl1bQtXtsD+G2cLJSA2H3loUFP0DH+6/bm04SIDzDPtOIFMDTU3Jx39qH2vXDH8 JLCchIN62slccE4xFKPZjp+vpHfts/vmDFKlU33KkVhUCXm0NwYY7htiDV/+tQ5OoVMw U8aJuCUBI2Zf2jrmTotzr99DV6TDeyxviUciQuzksuNNN1F8VrGyGilnteePs1hDqX7n Lc2A== X-Gm-Message-State: AOJu0YwYKCFmddWao3t6vRFP/cSVmQ088jY9qvRAc7nTbswoJNKv7k6O rpK3Jp/Ugc2sbzrOG1K/ldg8KV/IZaUchUGL5ySd2oICcffGkOQplXG2XTJM9IzQzC3ij9NHpuj t5DpvYvoFh828/rs7sPOoy2Y4lAmHH9zIgdlobFu+3VLlcF/XSPL85rsiH7gzKJTK2PIt8MwLKU QPUZ1WdsYAGG5gMKTfanbkQzB14XCD1D8WrOI= X-Google-Smtp-Source: AGHT+IGaSc3GGnCsV9Ic5d+SfutWw9JoOp4upfNTYerkdduW5gB+8NRRZRhFAbcoNuFnhBV46rI2cA== X-Received: by 2002:a05:6808:1916:b0:3bd:bf4a:686c with SMTP id bf22-20020a056808191600b003bdbf4a686cmr1015263oib.18.1706064869015; Tue, 23 Jan 2024 18:54:29 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c018:0:ea8:be91:8d1:f59b]) by smtp.gmail.com with ESMTPSA id z14-20020a62d10e000000b006d9b38f2e75sm12974229pfg.32.2024.01.23.18.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 18:54:28 -0800 (PST) From: Joe Damato 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, Joe Damato Subject: [net-next 3/3] eventpoll: Add epoll ioctl for epoll_params Date: Wed, 24 Jan 2024 02:53:59 +0000 Message-Id: <20240124025359.11419-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240124025359.11419-1-jdamato@fastly.com> References: <20240124025359.11419-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 | 41 +++++++++++++++++++ include/uapi/linux/eventpoll.h | 12 ++++++ 3 files changed, 54 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..d973147c015c 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -869,6 +869,45 @@ 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; + + 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 +1014,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..9211103779c4 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 */ + uint8_t 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 */