From patchwork Tue May 28 17:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 91032 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E9DA3845140 for ; Tue, 28 May 2024 17:37:51 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 59391385F018 for ; Tue, 28 May 2024 17:37:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59391385F018 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fastly.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 59391385F018 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716917846; cv=none; b=MJ4pvG0GJ0VKsVjZJjB0jE2Stuyfwnd+RG0P7pdUjmMX0tLkaizLEwCn2+9ifCY1Dt3s6Rzypkg/2SN4+Wjbf/jvTvXZnW1PMeemY5QhMuBQ2B2j9zOg7kTkbpZlidGNy/oKYTUqmBltNaBD5ImpfdPv1Z1tDkbU4LJP8ZoAT1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716917846; c=relaxed/simple; bh=4pxHkW7xqMFu18KSb9ZSWOdfAgHMCCAuMXIy9dVYQeA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=kXsr0QjiMiRFilfCZvRj4leoBV2GddfZ/S1CTur1a+f1wLxtN2h/FZGluVZBXSphz6R41MlkHex9BOl1AQoB4G+vlnPrQaWJ1BKCJ1odQiONBKYTM64FS7J6PkVvLWDd5n5okUFv3V8PkNBiYgN78i6BWLHbUiYkCmb41D1IegY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1f480624d10so9000535ad.1 for ; Tue, 28 May 2024 10:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1716917841; x=1717522641; darn=sourceware.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=d/ntYE/ebCMFFAJNVbfKgNLgc8fTUxBBYyO9UpA2wGw=; b=X1fjUFSj17ls7esLCmLxYRPV9XAW/tcG5YF5JSawKcYUIvB0tQyI+FHFG7kAheOttM 370TmlNO1BJbQvylbgz4DnSupzNmaL6qxDGhEOAWUaBYNifCdjEUI4SsIFv9wFF8N7CL Q/JKsYQnlQSIuCgsGnifBNlUGAir4Uu5zA6J0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716917841; x=1717522641; 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=d/ntYE/ebCMFFAJNVbfKgNLgc8fTUxBBYyO9UpA2wGw=; b=rUdP8aBCW63B3Cnu3N6PkomWPlHnluxG255uTYzU7A45NyjUl+pNwUnANKgfuI0pYI U80GE7C7BWErz50uiLPGCpdsfghgrtx29cWv7xROfJyhw5RqMb6otTvn3ErUrvrIl4mQ OS5v4AhJxy914Z2dkIJN3Vu5Qg1Uh+BhQZOX9fLdqfyS8avOQEegA0GRoEBHvI2HMHcE 23KmB5HEgGNiZCe/R45cx4qFuZXhSaMfD7A8U0VO8s5YUTKyrwB5dYFNogyL2XZIdyBt FHzZf0E0amXkzFEqfiKYIJvNB7DO9W2jgHoSGgClPdVUk2bDyacvyREVLRrMBXYdmxX+ HUOQ== X-Gm-Message-State: AOJu0YzCXhbmPCjNQEgr4kcPPAl+GRo0hRGbUIcu/m1SzXCJ9S+az5ao CPNkI51SaHT2KoElCHA94rROkkmbQfmcDowL4yfc3DJMKt6rbPTUcvnljabA2Yd9T4c0aNkTxso 3i3tby8gsTBOzu4zAjOIcIsbyIXO+Iaw5exkLby7CHz+9LpoJGumeQqsxnO6g0fLXEW/T+3h7QB Z7mArHFrGCE4IGMha0nwa/cAB5MN7jut3elEQL5bo= X-Google-Smtp-Source: AGHT+IHW1nhdNCwYBctrYkL2bfnUy2fuSKRZQT988ngUS49W5sqmi8j4trJMs2LugKRdbufjR9Ol9g== X-Received: by 2002:a17:902:c403:b0:1f2:f5a3:9c98 with SMTP id d9443c01a7336-1f4486b5de1mr155646775ad.1.1716917840736; Tue, 28 May 2024 10:37:20 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c9a8db7sm83101935ad.222.2024.05.28.10.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 10:37:20 -0700 (PDT) From: Joe Damato To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org, Joe Damato Subject: [PATCH v2 1/1] Linux: Add epoll ioctls Date: Tue, 28 May 2024 17:37:06 +0000 Message-Id: <20240528173706.511391-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240528173706.511391-1-jdamato@fastly.com> References: <20240528173706.511391-1-jdamato@fastly.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org As of Linux kernel 6.9, some ioctls and a parameters structure have been introduced which allow user programs to control whether a particular epoll context will busy poll. Update the headers to include these for the convenience of user apps. The ioctls were added in Linux kernel 6.9 commit 18e2bf0edf4dd ("eventpoll: Add epoll ioctl for epoll_params") [1] to include/uapi/linux/eventpoll.h. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/?h=v6.9&id=18e2bf0edf4dd Signed-off-by: Joe Damato Reviewed-by: Adhemerval Zanella --- NEWS | 3 + sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/sys/epoll.h | 14 ++++ sysdeps/unix/sysv/linux/tst-epoll-ioctls.c | 92 ++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/tst-epoll-ioctls.c diff --git a/NEWS b/NEWS index 84efa46df3..20e263f581 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,9 @@ Major new features: more extensive verification tests for AT_SECURE programs and not meant to be a security feature. +* On Linux, update epoll header to include epoll ioctl definitions and + related structure added in Linux kernel 6.9. + Deprecated and removed features, and other changes affecting compatibility: * Architectures which use a 32-bit seconds-since-epoch field in struct diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 415aa1f14d..ae66590e91 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -200,6 +200,7 @@ tests += \ tst-clone2 \ tst-clone3 \ tst-epoll \ + tst-epoll-ioctls \ tst-fanotify \ tst-fdopendir-o_path \ tst-getauxval \ diff --git a/sysdeps/unix/sysv/linux/sys/epoll.h b/sysdeps/unix/sysv/linux/sys/epoll.h index fc8dce45c8..45e546fa44 100644 --- a/sysdeps/unix/sysv/linux/sys/epoll.h +++ b/sysdeps/unix/sysv/linux/sys/epoll.h @@ -19,6 +19,7 @@ #define _SYS_EPOLL_H 1 #include +#include #include #include @@ -87,6 +88,19 @@ struct epoll_event epoll_data_t data; /* User data variable */ } __EPOLL_PACKED; +struct epoll_params +{ + uint32_t busy_poll_usecs; + uint16_t busy_poll_budget; + uint8_t prefer_busy_poll; + + /* pad the struct to a multiple of 64bits */ + uint8_t __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) __BEGIN_DECLS diff --git a/sysdeps/unix/sysv/linux/tst-epoll-ioctls.c b/sysdeps/unix/sysv/linux/tst-epoll-ioctls.c new file mode 100644 index 0000000000..618ecc4e86 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-epoll-ioctls.c @@ -0,0 +1,92 @@ +/* Basic tests for Linux epoll ioctls. + Copyright (C) 2022-2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void +test_epoll_ioctl (void) +{ + int efd = epoll_create1 (0); + TEST_VERIFY_EXIT (efd != -1); + + struct epoll_params params; + + TEST_COMPARE (ioctl (efd, EPIOCGPARAMS, ¶ms), 0); + + /* parameters are all 0 by default */ + TEST_COMPARE (params.busy_poll_usecs, 0); + TEST_COMPARE (params.busy_poll_budget, 0); + TEST_COMPARE (params.prefer_busy_poll, 0); + TEST_COMPARE (params.__pad, 0); + + /* set custom parameters */ + params.busy_poll_usecs = 40; + params.busy_poll_budget = 8; + params.prefer_busy_poll = 1; + params.__pad = 0; + + TEST_COMPARE (ioctl (efd, EPIOCSPARAMS, ¶ms), 0); + + memset (¶ms, 0, sizeof (params)); + + TEST_COMPARE (ioctl (efd, EPIOCGPARAMS, ¶ms), 0); + + /* check custom values were retrieved after being set */ + TEST_COMPARE (params.busy_poll_usecs, 40); + TEST_COMPARE (params.busy_poll_budget, 8); + TEST_COMPARE (params.prefer_busy_poll, 1); + TEST_COMPARE (params.__pad, 0); + + xclose (efd); +} + +static bool +ioctl_supported (void) +{ + int efd = epoll_create1 (0); + TEST_VERIFY_EXIT (efd != -1); + + struct epoll_params params; + int r = ioctl (efd, EPIOCGPARAMS, ¶ms); + xclose (efd); + + return (r == 0); +} + +static int +do_test (void) +{ + if (ioctl_supported ()) + test_epoll_ioctl (); + else + return EXIT_UNSUPPORTED; + + return 0; +} + +#include