Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1194353rdb; Fri, 9 Feb 2024 13:22:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWlbVCJ3yRMpXUkqUKySr4B57yTi2KFxnlLIC0TKIYfNbRAUQKfMmjp5aEQ+CYcXBfFC2oenSUHKtsLtieTHPKKEHmBt9AFrmhbqPl3jg== X-Google-Smtp-Source: AGHT+IHwvmnDi0V/+HZGhxkiS+XMEqDcqVq7su7M9bbIqvM9cZ65EJCO03yX9kZeICgyfo8la0o+ X-Received: by 2002:a17:906:4c56:b0:a38:1e9c:8268 with SMTP id d22-20020a1709064c5600b00a381e9c8268mr231415ejw.32.1707513762051; Fri, 09 Feb 2024 13:22:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707513762; cv=pass; d=google.com; s=arc-20160816; b=0CO3ZkbsMDK3TZISyTQz9QVdK1/JVO3B5MNzNCBouURuhl45fZxX+dulySKNrKyIZ0 HfEzBJutSYSroqGGSx/3Wv7bo76UWIzpkAcaNfCUdqTb5hO5v4n32338Xa4o1GsFp5jR tyrWRqwvkRa0hog5ajWcAMpGG51wnvcC2SWw8gSXBPHHFSPO2JBBkWu5oZBeJWcZ9HxK 7uMLzsTirT+WNSvDlBnB6eqbpCtryrjNhyVCzCjXjg0VW5lssJHr92hMXk17r/5JJNKd v7kFdiQ1u7ejLA3om1is128Ykz9d1g3MDyE67OdtSBAbbjb590EjwZo2hUOr6Igx01PQ AbIw== 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=8T72+tfYxIVMKkrQX69I/sG/Ln/429Cv0P7tqGCS/cM=; fh=8d8zFdzCzx8vlWdwE6ZxnkomcM6tAFkLDmtrkoybQkM=; b=R1A/2rETt0/WzD/repUUamglI4wA7jLQZ69Z5k2KQ4cMAUsrc/kkLfWjSVlf0BsAXD JGsLTyazZ++0jn/zt7tdGyfiNO+Pw5Rd8A7UKuTSLmC0ZqaEIkTsCTA279svHvfgLr+W VRz868qU/eqXvl89IodlYu0EfpUIFM9Rqh6G4DJ11Mg7tBpKUvybbsU2CRE3ILyDlZVY LDfd+yaljgw6ykTZojOd5nvA8dvygCMpKgAuAOxatCvp/hwSyvmh6lK5kIj/VyixZnfG JLo9WsiIDBSCZeoZzT/wCEkQl8n4aYe43ReOl4PO1mmTxA8Lclq6LdHWOVgMo13ZS3n9 riwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=wLoX768r; 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-60022-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60022-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com X-Forwarded-Encrypted: i=2; AJvYcCVBXxxO4kbVfhYq+VvV+08fCNl3l0Pcy7S0ADJy07yK837tfDWCvFrXOSQk4cpk6DBhgsCcyZl1LBQ0ZYgXceMUketTSmGyGhnK93OoRQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y7-20020a17090668c700b00a3599b5e76csi1287952ejr.692.2024.02.09.13.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:22:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60022-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=wLoX768r; 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-60022-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60022-linux.lists.archive=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 6C2901F21FCA for ; Fri, 9 Feb 2024 21:22:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5451C3BB51; Fri, 9 Feb 2024 21:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="wLoX768r" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 C7B063BB25 for ; Fri, 9 Feb 2024 21:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707513359; cv=none; b=qlH2qgJ5fHddsbGpE5tsDgJy9GWlxkH7s30OtO5GUfiPin6rb+EwwyVHivTUKXrHBznYxbvwMj9a1jD9FBQBoo3xywmxuLGDOfmqo0uQG3tQf6PIZv+j6drgmQ0N6z1tDMpzHJpHHONDf4K61X2YTqe/xe/hhdir1XUD8Gt1tAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707513359; c=relaxed/simple; bh=bU1lRcpmwwquP/3WT3NzDHAkVOQAiLuggZfIHJAVD+s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E4NwwezXNGc7He6DwWFIrK00tQduhbTzojlDeVWYCPxpoqXkX7fMqLacflLkSn8agSGbljMeFnXG8Tj64sKXAtPYF2KvazVBieJ9CJZLIxeGYjTo3biBrTdzoHg23k3DkkwEuJtJezASPxYj7U7IYvqd+Qw+j80Gn4wG3t12Gac= 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=wLoX768r; arc=none smtp.client-ip=209.85.210.180 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-pf1-f180.google.com with SMTP id d2e1a72fcca58-6da6b0eb2d4so1279253b3a.1 for ; Fri, 09 Feb 2024 13:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1707513356; x=1708118156; 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=8T72+tfYxIVMKkrQX69I/sG/Ln/429Cv0P7tqGCS/cM=; b=wLoX768rhfA6KiMLsxoXieDDIgiLiuhFmxIyhI6YSIG+EK1zztLADr3sCzO3Ug0ajd InGT2QhFIXO0/IBTPq+qbKMx3k0ba1LnfNqpKknZ5Y8YDVf0sJmpF3N0X1+4b4LQtGKQ /6PXRPFTtWM1DH8u//n8KiSrtV7cVTAGB7drU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707513356; x=1708118156; 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=8T72+tfYxIVMKkrQX69I/sG/Ln/429Cv0P7tqGCS/cM=; b=q1/KzVG04JRYVAVqbiiexlsCkoWCs5e7jvS/rOeWq7owQcgYklOM72luZkVgdqzLH2 XFRN4J9ZqGwX80nj0H7WRlj8Vq9fU42tOELpSJ6RDP44OD0nIAFSk8/wmtcvPKpQ6Upx 0nXHSJsnqm1BCLlpTskIEG9kF0lJRb1qJBH91gx6UAkXJY1MqNw93pZ7IPeDfEjesish UDi2ODEVobOa7BVqQy2fcJWnYlH16KM0g1DHN7487KyMPEplIs+WQtCYEVwKA+She1bK gG0HWjwjNOCFMPJqvPy7f963KVrtLaWrSji7LWOswkV9+BqIkt+I4xF5KLuvGV7siRUg xb5w== X-Gm-Message-State: AOJu0Yxo+YoOnvkHhm+WjB6Iiphlc476U+3DhkD3yxDt/h0ogxJi84i3 1wjUDRhP8g5ACzhqn9VgPkBUeGvytBQmpmqxD73km4WPz7n+v+ehJwKDtwD5jKAZf1mpLXl5WgH gpNkpyy/5CsVIRJiHc1Tlr7R+O4qICpl4aCcUMYPwDfTJpKH6DKRW2Ah8KMkDarPeX9ylUg9B8Y dgSWbKDDaGQ+ThvmT7xExQFgY7S7f9hHG+1nIcKfhlE6t4VQ== X-Received: by 2002:a05:6a20:43ab:b0:19e:97ee:af55 with SMTP id i43-20020a056a2043ab00b0019e97eeaf55mr416941pzl.1.1707513356321; Fri, 09 Feb 2024 13:15:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVJj4LR8eeRuam1BjuM1EtiGu4vRjwhKwhCP2VDo1jULvf+oH9l/0VIv52J3i3gAldtueQNp1HaQlSWVqUAOltAJbLlwiAvsey9QvL1B7bO02YsgDNJopPwshTnQ3tyFQ6D5kt8M3NjEpwPS6FLo2uH+M+2v0a/RdTTzAQMW2Wu/fkW2IxjaJRXRaCPKig0A7c+szKH2aD5loF5hu1ERoEbVmJPJxxXdkT/Vt0PKlnyYneCEtS7ltvzrsljk8C3Bpg+W3KkH9i4zF7se9Mg7h2ixJKrXbXUfB1SPt3wfJNyvDnaj3Ske0SQb3UB66GJk2kpsCuTlpKGzysTVLj+0RNmpNSkFGflrBDALZ8AHclwtbHrFS46Qk4vju1eWXlcXIBFaO4B4M+QJBI3TStBkygryk8choXmBnwFue451x0uWFjJ/hyUtYHRnl06YSLsOdi3sq93YtBuSxTZTNm9dO0nB9E6hPNoFgQg7TjU/KepJumiDHhPjJRqkhepXJ5Rr0gucnslzFbw8Vt8wGJsMuP+fLBrI5uQMlx1h9mMGYoJsNFKMlsh/rX9ssjr5PWAD1Pe8L4cPxjWGwdpeTPzN6lFYbsHnTGqTBZ5Di6PHpnyv3VSDX2xhwCPnwEV9nbI9Nb0MIS3t+QdYy2jHaEyiWwsB3MwHluQ5zsHDIv2nfbSanPshj/sbNHgLmrqsc0bdMD/Zzr8YqNOwI9PyrBc6ntkp7F+p9jl4i2svMK7kg+UZztPA4V5jfaqDTHVD4BRKLWaoaRI/F9Vas3w1UwNh9r1dc0VeTJBmuvQ317k9SaD1ICDR2/yT5Dut0Qp54NyDdhHTFSeCMLiSy9u4SMwngtb4Hifi+a71p9k1vZLWaUxxbA0TdxSCaPzXni33Ur8qjXbknmy6anUxmQ1COpjI4kmgzhjw9T8U6GhwFufx6XZF5IaHrynioWVsudVbIGracylX7 a02wPNR2PPU0KDXcJqz/4oACS54pay537goYpUUFa77oBslUA1Ow== Received: from localhost.localdomain ([2620:11a:c018:0:ea8:be91:8d1:f59b]) by smtp.gmail.com with ESMTPSA id x23-20020aa79197000000b006e05c801748sm969629pfa.199.2024.02.09.13.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 13:15:55 -0800 (PST) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@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, willemdebruijn.kernel@gmail.com, weiwan@google.com, David.Laight@ACULAB.COM, arnd@arndb.de, sdf@google.com, amritha.nambiar@intel.com, Joe Damato , Jiri Slaby , Jonathan Corbet , Alexander Viro , Jan Kara , Michael Ellerman , Nathan Lynch , Greg Kroah-Hartman , Maik Broemme , Steve French , Thomas Zimmermann , Julien Panis , Thomas Huth , Albert Ou , Palmer Dabbelt , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)) Subject: [PATCH net-next v7 4/4] eventpoll: Add epoll ioctl for epoll_params Date: Fri, 9 Feb 2024 21:15:24 +0000 Message-Id: <20240209211528.51234-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240209211528.51234-1-jdamato@fastly.com> References: <20240209211528.51234-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Acked-by: Stanislav Fomichev Reviewed-by: Jiri Slaby --- .../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 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 #include #include +#include #include /* @@ -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; + 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; + 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; + } +} + #else static inline bool ep_busy_loop(struct eventpoll *ep, int nonblock) @@ -505,6 +549,12 @@ static inline void ep_set_busy_poll_napi_id(struct epitem *epi) { } +static long ep_eventpoll_bp_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + return -EOPNOTSUPP; +} + #endif /* CONFIG_NET_RX_BUSY_POLL */ /* @@ -864,6 +914,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; @@ -970,6 +1040,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..4f4b948ef381 100644 --- a/include/uapi/linux/eventpoll.h +++ b/include/uapi/linux/eventpoll.h @@ -85,4 +85,17 @@ struct epoll_event { __u64 data; } EPOLL_PACKED; +struct epoll_params { + __u32 busy_poll_usecs; + __u16 busy_poll_budget; + __u8 prefer_busy_poll; + + /* pad the struct to a multiple of 64bits */ + __u8 __pad; +}; + +#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