From nobody Wed Apr 8 17:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88FE7C38A02 for ; Fri, 28 Oct 2022 09:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229973AbiJ1J6N (ORCPT ); Fri, 28 Oct 2022 05:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230388AbiJ1J5o (ORCPT ); Fri, 28 Oct 2022 05:57:44 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81AF21CBA99 for ; Fri, 28 Oct 2022 02:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666951017; x=1698487017; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cCBe/q5YolyqbHnPs4c9IauGtcofM9sooHtix6H+SW0=; b=lIWCqFwqEsP9jbB6DHK0hQ8ZG9kNq9f5m1kgoNjk1eAIEOru6VEk6pc3 OL65SV3CS2hF1IvKxSBocn1+jHy58EAK6uFabaSN8klZdht532YOKnYrY F0eHODM97lANgxk2FhfMwMBBdoX1tnC5H2AO9Vq+v7/9rsp5YaU20+giX u1iFCTu1IqkIf/Vwx3x/ZT5vTHlDXgf74jpeO0I0ys1kXSKuFtgI+kPGx 78laN4dtV3syBMtL58WAXPvdCl7w8PUx1iVgITyTF9h7ajbkJSW1PlYzu INAYyu+QAyV4uz5kGlavNsQ8siTn+Cu1Wxk5+V7PueNoWD0H3lAhKo5O3 g==; X-IronPort-AV: E=Sophos;i="5.95,220,1661788800"; d="scan'208";a="214962167" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2022 17:56:56 +0800 IronPort-SDR: TGBftajlAQB1RTVRseCc8dyKzc/dfvmxjyWgtFQr90W+ZffjRI9fULnXRlj1fGutFb/kos9K6P tlm+qWYWDDVowSthRxW72WMUuUZO0ViFXReooVBwZ0rDN9CGip4oGpxKK0SfjLXowHOELKhSf5 VEBKlFzKFIWOFZwY176PsM1pBa+GeexfigQUnndyUTG9l0Y1QrmwnjBILqtms5vepEzK+Klu7p Px4ITc52O+VQr811AlnG3bbDBALSUnfMsS+hpwTT3PXN8RQCyqBpMcLuJ00U2O+s+uNu/R2vxn Sl4w0gmF3QEZ+b+sK6MdNRUP Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:16:16 -0700 IronPort-SDR: SP8zhc46vgRZU0EtI+e0VVQN7piHlDoH45Hv1qj35VvWNwEArbQ37vAJL8FWKjNUr/NOxOTsm8 ROD8kQAAAX3gI6o5uaLgFviGnpocZzqwgCUFU9LpL+8V3vMiGDTWE/PhNi2f5a626numjRQV7D +kCZMM2JrnvS02j8eHd+PdiTUTGms2bbKkhZs4fQtYdEVOTP7xXf+q4BOLg0Z/CGb+mbU8SMVw P2q1cM8xGQiM8/qnlS/wHsKnzNvhlnvQJHnru4wkvriomv6Nq0THpbGcvh3g+SoTEZxp01yDII bpw= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:56:57 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MzHyJ1CsLz1RwqL for ; Fri, 28 Oct 2022 02:56:56 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666951014; x=1669543015; bh=cCBe/q5YolyqbHnPs4 c9IauGtcofM9sooHtix6H+SW0=; b=OAa1FYOtOr8Yv6LLPxBxxoNFUhQW1PLMnJ KFEd1oT/7vn16T4Ox7LgvGBdS+hqd6gPwOQD+nIAb+mY8pOgCRmEUosR2o/YvVo7 wpOApZYhSgJk5YFexLdrCigBcPzlYSH1qa+qFwQ6OpEDnM78Seta0h3nrh40sQme m6PJx/hKkzXwqplYVSPZZP6jZpEbq6RStVjLuI+4SJNkY8C/uphHH0wg2GWucedb K7fTkvTVRg6JfbnLrdL1GltYKVNnAI5+AYitDl/Pdw2Vvy69WKH6rB4ynzmNbF3H kXvPWTYZsbt5AnqAlvR2HFSepDgUBQm5t2SDARtsEN5IOPa9eCSw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 0QtzsX-_Dr1I for ; Fri, 28 Oct 2022 02:56:54 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.50]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MzHy76NpKz1Rwt8; Fri, 28 Oct 2022 02:56:47 -0700 (PDT) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, dave@stgolabs.net, alexander.shishkin@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, acme@redhat.com, dvhart@infradead.org, mark.rutland@arm.com, peterz@infradead.org, arnd@arndb.de, alistair23@gmail.com, linux-riscv@lists.infradead.org, mingo@redhat.com, alistair.francis@wdc.com, atish.patra@wdc.com Subject: [PATCH 1/6] perf bench futex: Add support for 32-bit systems with 64-bit time_t Date: Fri, 28 Oct 2022 19:56:27 +1000 Message-Id: <20221028095632.1081262-2-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> References: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alistair Francis Some 32-bit architectures (such are 32-bit RISC-V) only have a 64-bit time_t and as such don't have the SYS_futex syscall. This patch will allow us to use the SYS_futex_time64 syscall on those platforms. This also converts the futex calls to be y2038 safe (when built for a 5.1+ kernel). This is a revert of commit ba4026b09d83acf56c040b6933eac7916c27e728 "Revert "perf bench futex: Add support for 32-bit systems with 64-bit time_= t"". The original commit was reverted as including linux/time_types.h would fail to compile on older kernels. This commit doesn't include linux/time_types.h to avoid this issue. Signed-off-by: Alistair Francis Cc: Alexander Shishkin Cc: Alistair Francis Cc: Atish Patra Cc: Darren Hart Cc: Davidlohr Bueso Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-riscv@lists.infradead.org Cc: Arnaldo Carvalho de Melo Reviewed-by: Arnd Bergmann Message-Id: <20211209235857.423773-1-alistair.francis@opensource.wdc.com> --- tools/perf/bench/futex.h | 52 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h index ebdc2b032afc..385d2bdfaa9f 100644 --- a/tools/perf/bench/futex.h +++ b/tools/perf/bench/futex.h @@ -8,6 +8,7 @@ #ifndef _FUTEX_H #define _FUTEX_H =20 +#include #include #include #include @@ -28,7 +29,17 @@ struct bench_futex_parameters { }; =20 /** - * futex_syscall() - SYS_futex syscall wrapper + * This is copied from linux/time_types.h. + * We copy this here to avoid compilation failures when running + * on systems that don't ship with linux/time_types.h. + */ +struct __kernel_old_timespec { + __kernel_old_time_t tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ +}; + +/** + * futex_syscall() - __NR_futex syscall wrapper * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op @@ -49,14 +60,49 @@ static inline int futex_syscall(volatile u_int32_t *uaddr, int op, u_int32_t val, struct tim= espec *timeout, volatile u_int32_t *uaddr2, int val3, int opflags) { - return syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3= ); +#if defined(__NR_futex_time64) + if (sizeof(*timeout) !=3D sizeof(struct __kernel_old_timespec)) { + int ret =3D syscall(__NR_futex_time64, uaddr, op | opflags, val, timeout, + uaddr2, val3); + if (ret =3D=3D 0 || errno !=3D ENOSYS) + return ret; + } +#endif + +#if defined(__NR_futex) + if (sizeof(*timeout) =3D=3D sizeof(struct __kernel_old_timespec)) + return syscall(__NR_futex, uaddr, op | opflags, val, timeout, uaddr2, va= l3); + + if (timeout && timeout->tv_sec =3D=3D (long)timeout->tv_sec) { + struct __kernel_old_timespec ts32; + + ts32.tv_sec =3D (__kernel_long_t) timeout->tv_sec; + ts32.tv_nsec =3D (__kernel_long_t) timeout->tv_nsec; + + return syscall(__NR_futex, uaddr, op | opflags, val, ts32, uaddr2, val3); + } else if (!timeout) { + return syscall(__NR_futex, uaddr, op | opflags, val, NULL, uaddr2, val3); + } +#endif + + errno =3D ENOSYS; + return -1; } =20 static inline int futex_syscall_nr_requeue(volatile u_int32_t *uaddr, int op, u_int32_t val,= int nr_requeue, volatile u_int32_t *uaddr2, int val3, int opflags) { - return syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, v= al3); +#if defined(__NR_futex_time64) + int ret =3D syscall(__NR_futex_time64, uaddr, op | opflags, val, nr_requ= eue, + uaddr2, val3); + if (ret =3D=3D 0 || errno !=3D ENOSYS) + return ret; +#endif + +#if defined(__NR_futex) + return syscall(__NR_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, = val3); +#endif } =20 /** --=20 2.37.3 From nobody Wed Apr 8 17:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90EF0FA3741 for ; Fri, 28 Oct 2022 09:58:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbiJ1J62 (ORCPT ); Fri, 28 Oct 2022 05:58:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230362AbiJ1J5w (ORCPT ); Fri, 28 Oct 2022 05:57:52 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCE6B78BF9 for ; Fri, 28 Oct 2022 02:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666951027; x=1698487027; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HDOW4KvVqZm7M+oRwyLLXnE8cnS2CkUYQNAOKUB1qEA=; b=MryUVIOxX5idiKMr1s9eTK0X6QPeDaz/soHe+0Zd73tuen9z+6Ok+/IX llEzY4UfkL9+b/iQ4CQmI9BBSbdzphjJnkoag8YE4BWbn7jkHRfqisT3M FDO++5zOtfgD3hWtl0Qjsvc7yypQk1bH8Iux+Lr70EbppARdhrgbodvfO CAQqZDs5apx9XKX17ukEP+2shDRz95cK4PafIDP0Ok8bno35NjbIzXFRQ GCGGtoFTvFHpDs1NbmHvs/UuSZEYwhWPOsfj9JF2WR68Z3xmiDC/gK6gr PRX+bJ7QyJpEXc9anonNbR1e0c3bk9XdGAuX1jX13eQ5wTSGKzsPlrkYl w==; X-IronPort-AV: E=Sophos;i="5.95,220,1661788800"; d="scan'208";a="214962182" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2022 17:57:06 +0800 IronPort-SDR: LBpz6MBox9ISVsLvntTKLeeLVan0qiu7RRwb+g2a33sTew4zKHc0b/n71TbykJSBcdsDlx8HfM fIo0YtXlH61zjj//a4X7km73jgTKSyYdiBGNBBazIdY3F77E6VEdmIzlj6YOLV87LEk4p4l0ir 84klRH4xtCQA84vKTNWjv3l7lxm2WG4KRPzQz0PB8scTu8fpWobcayQTHXEV9GuTToisuhc5fc Qyu6vO9CcC28VZ2Gq8qBAbvsouthRSRlLBt9A51GGZ+Dd7Ehhej3VBO1S+DGm9bTpHJAZ49vjX 93oAv9rR5+oWjiZXydGEChG0 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:10:43 -0700 IronPort-SDR: Cav5Y8AqmC8okMtSDSjHTGImmia9jmTzGbvovhVNqWFMGf4W5IT4yviJCuh+GJo/P7ouKJhg19 N1sCL+nR3XGPFfYkKEQ+httw6AH1s5F0fCkhhQyphoZFysxKt15FkBebHwSciOUisclPSEnid2 3zlR3mfHqx7PRwlVLk3ldVuHEAQpDg9hOtWtr5f34G6HgDBNgtUUZp3VQDQk4nxQXaChYHUCfQ maPOO7kiBZ8RTmrJfZosLdavKYB+X5VdCw4FZdSAWQavpWV3S8g+SvNyc4tRMd6LpWNCClLiWc O7g= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:57:06 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MzHyT2KYCz1SHkX for ; Fri, 28 Oct 2022 02:57:05 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666951023; x=1669543024; bh=HDOW4KvVqZm7M+oRwy LLXnE8cnS2CkUYQNAOKUB1qEA=; b=sAi49Kz2aJYOKZLKyiB/WlLqbdA/IvI1xK OBN3BMUWU/e1IBbG+n6Ac+ZZqv+G5mMc1Js/804PxVD4y7APryBjKkSh849VHIcc nG0PZChp3RVA8YGzYh0X1Ha/1dDleUur6uepq87pxLK13mEGdf6JAZ9jaNdTnE0i NFUaD83Rux/jF5LDGkHT8Lc1SafrYsu3KuGFpuFooVooLgnLcxnK6S4j7V2l6FFX kAPK8IsQ/ENXLpif3vkLWEudo6NV1JaLzzENYnjyxnnxeQ3cni0F3GER8FPdqS41 NT3LgJcWBh2BCp1vKPVeDaSZgJ+IK92VwpME44nP1sYKxpqe/+MA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id meVjp_qOu_uk for ; Fri, 28 Oct 2022 02:57:03 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.50]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MzHyH5rjnz1RvLy; Fri, 28 Oct 2022 02:56:55 -0700 (PDT) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, dave@stgolabs.net, alexander.shishkin@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, acme@redhat.com, dvhart@infradead.org, mark.rutland@arm.com, peterz@infradead.org, arnd@arndb.de, alistair23@gmail.com, linux-riscv@lists.infradead.org, mingo@redhat.com, alistair.francis@wdc.com, atish.patra@wdc.com Subject: [PATCH 2/6] selftests: futex: Call the futex syscall from a function Date: Fri, 28 Oct 2022 19:56:28 +1000 Message-Id: <20221028095632.1081262-3-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> References: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alistair Francis Call the futex syscall from a function In preparation for a more complex futex() function let's convert the current macro into two functions. We need two functions to avoid compiler failures as the macro is overloaded. This will allow us to include pre-processor conditionals in the futex syscall functions. Signed-off-by: Alistair Francis Message-Id: <20211209235857.423773-2-alistair.francis@opensource.wdc.com> --- .../selftests/futex/include/futextest.h | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/test= ing/selftests/futex/include/futextest.h index ddbcfc9b7bac..c786fffecb8a 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -48,7 +48,7 @@ typedef volatile u_int32_t futex_t; #endif =20 /** - * futex() - SYS_futex syscall wrapper + * futex_syscall() - SYS_futex syscall wrapper * @uaddr: address of first futex * @op: futex op code * @val: typically expected value of uaddr, but varies by op @@ -58,17 +58,26 @@ typedef volatile u_int32_t futex_t; * @val3: varies by op * @opflags: flags to be bitwise OR'd with op, such as FUTEX_PRIVATE_FLAG * - * futex() is used by all the following futex op wrappers. It can also be + * futex_syscall() is used by all the following futex op wrappers. It can = also be * used for misuse and abuse testing. Generally, the specific op wrappers - * should be used instead. It is a macro instead of an static inline funct= ion as - * some of the types over overloaded (timeout is used for nr_requeue for - * example). + * should be used instead. * * These argument descriptions are the defaults for all * like-named arguments in the following wrappers except where noted below. */ -#define futex(uaddr, op, val, timeout, uaddr2, val3, opflags) \ - syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3) +static inline int +futex_syscall(volatile u_int32_t *uaddr, int op, u_int32_t val, struct tim= espec *timeout, + volatile u_int32_t *uaddr2, int val3, int opflags) +{ + return syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3= ); +} + +static inline int +futex_syscall_nr_requeue(volatile u_int32_t *uaddr, int op, u_int32_t val,= int nr_requeue, + volatile u_int32_t *uaddr2, int val3, int opflags) +{ + return syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, v= al3); +} =20 /** * futex_wait() - block on uaddr with optional timeout @@ -77,7 +86,7 @@ typedef volatile u_int32_t futex_t; static inline int futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opfl= ags) { - return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); } =20 /** @@ -87,7 +96,7 @@ futex_wait(futex_t *uaddr, futex_t val, struct timespec *= timeout, int opflags) static inline int futex_wake(futex_t *uaddr, int nr_wake, int opflags) { - return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags); } =20 /** @@ -98,8 +107,8 @@ static inline int futex_wait_bitset(futex_t *uaddr, futex_t val, struct timespec *timeout, u_int32_t bitset, int opflags) { - return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, - opflags); + return futex_syscall(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset, + opflags); } =20 /** @@ -109,8 +118,8 @@ futex_wait_bitset(futex_t *uaddr, futex_t val, struct t= imespec *timeout, static inline int futex_wake_bitset(futex_t *uaddr, int nr_wake, u_int32_t bitset, int opfla= gs) { - return futex(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset, - opflags); + return futex_syscall(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitse= t, + opflags); } =20 /** @@ -121,7 +130,7 @@ static inline int futex_lock_pi(futex_t *uaddr, struct timespec *timeout, int detect, int opflags) { - return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opfl= ags); } =20 /** @@ -130,7 +139,7 @@ futex_lock_pi(futex_t *uaddr, struct timespec *timeout,= int detect, static inline int futex_unlock_pi(futex_t *uaddr, int opflags) { - return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags); + return futex_syscall(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags); } =20 /** @@ -140,8 +149,8 @@ static inline int futex_wake_op(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_wake2, int wake_op, int opflags) { - return futex(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op, - opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, = uaddr2, wake_op, + opflags); } =20 /** @@ -156,8 +165,8 @@ static inline int futex_requeue(futex_t *uaddr, futex_t *uaddr2, int nr_wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0, - opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue= , uaddr2, 0, + opflags); } =20 /** @@ -169,8 +178,8 @@ static inline int futex_cmp_requeue(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wak= e, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_req= ueue, uaddr2, + val, opflags); } =20 /** @@ -185,8 +194,8 @@ static inline int futex_wait_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, struct timespec *timeout, int opflags) { - return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0, - opflags); + return futex_syscall(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, = 0, + opflags); } =20 /** @@ -200,8 +209,8 @@ static inline int futex_cmp_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_= wake, int nr_requeue, int opflags) { - return futex(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2, - val, opflags); + return futex_syscall_nr_requeue(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_= requeue, uaddr2, + val, opflags); } =20 /** --=20 2.37.3 From nobody Wed Apr 8 17:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A25BC38A02 for ; Fri, 28 Oct 2022 09:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbiJ1J6f (ORCPT ); Fri, 28 Oct 2022 05:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230341AbiJ1J5y (ORCPT ); Fri, 28 Oct 2022 05:57:54 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8A60A1B2 for ; Fri, 28 Oct 2022 02:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666951037; x=1698487037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ukg2qTmNSbfxQotuwWTieHEmVg4/tjCtE5mHopxUMgk=; b=Bh4HYT0OFrNKkLXSJ5IUXPjpJeh6oECb0XWZEHhsdQZMd34Ix/LDW0rF GqaSkheDbDtpldT+ctIOOOhuVxaOaaBrBjAaM/AQKFZrnQmDaEsZx0i8/ ehreWu/jShMBNW0AV3rOwMGro/KTix9r2i6NdbqN9OZHGPUZYXHsK7gZw OUaxKHCFGxxEwmN8lGjVAUn1FPXmqmp2tWCWG4fItww5VZb2mlkXc4rHE TxkD3MZLLFhWXReYP8EXFFXjxMA6l3wmNDpQxGcEln/6yRUZnwN3S6stH FvBIUtuymU+2PFTaQDETohvfeBQIX0zK/kUOqnwCEmqFYiOvEJl0oFXYV g==; X-IronPort-AV: E=Sophos;i="5.95,220,1661788800"; d="scan'208";a="220111900" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2022 17:57:17 +0800 IronPort-SDR: mwKR/BYshG7tOCfAN0iBQ3SHvMMXY19zr3r6YqzCNxFsbUmBzcn4FaO8n+zoZZabudYJbTV8an 2QJZ18gE1CDyxUZRnUgLWvLTyuaGdQ7EJAWwvVu+zifACYLvabXQ7kWoVXOH9VInZnO9iLd2c7 pKhw72YKcs42e1zOMV7vz3gsD+wXN2E7/QStXA3k/Z5Eu7yaFt1gYCcAbOjx7RyzuqWg3bNZ3J mbh5JD0F8puVl0A/xPguLWlK6YvoGwDbtIOoKVGDAbnEeiRSANvK00yGdm+oXqMfLA4qSrx13P N7Dr2wkyE9LIy7HP7VlJYWhg Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:16:36 -0700 IronPort-SDR: 1BEZjGNfBcBpOk3JuX4jrv+RtACB8lwxOamt6m7C40VkIpxnglq47O2fgzHmCDcOD7xBFhjND9 sgsQqHPdynWf5M9y9umzMBF6aZSYeCBYvqQUKHWowmyWdqSu2g21hoVSlzS1vo79NtBKy8K4lp Ef2uGgnIWYRgN8GqNGFXXHOqoZLOhUOoXddwh8hSZZPRCQBmUtN2R/686g9tWEgW14a8CfBXn8 WyahYzcbrpnCfoK6v6D3aa6ADOKtegrkbuFA8Wroq0aLQwxm8a4JVAMACf3xNwQ9uWUe+9lIft FnU= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:57:14 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MzHyd2S7Tz1SHkX for ; Fri, 28 Oct 2022 02:57:13 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666951031; x=1669543032; bh=Ukg2qTmNSbfxQotuwW TieHEmVg4/tjCtE5mHopxUMgk=; b=XoCXBRwRjUVW20Iyiw7Ncz9qA6Y7jOuo8m w/G8osTW19FFlzpKM22INyC6m+ZqsW/n1Ch9ryyHlArDTWw5GB0zrU+ZQfljy2oX c9kEp9TUbpGba2sWPxxEeX04baDMcX8URqB8BANKiB3LEOlMACM6C+z8GOgLLVIa /V6DhcV2n/hnsi6JusbOgc3btLu+n4nNjIEykuu50qKj159tB4KpJoa3tfqyAm3D DqQeycQan6SOtNMyUmwhPpoAp6kasc30qw80a32RT+WEeDcCrXkj2xlvU+VWpoeK inkUSTGoxo1PxL6eKckIQhzvoCrVaSXMkHLfOi24JRTGYzJ3FhXg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1FXjg0k1JJTW for ; Fri, 28 Oct 2022 02:57:11 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.50]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MzHyS2SsTz1RvTp; Fri, 28 Oct 2022 02:57:03 -0700 (PDT) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, dave@stgolabs.net, alexander.shishkin@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, acme@redhat.com, dvhart@infradead.org, mark.rutland@arm.com, peterz@infradead.org, arnd@arndb.de, alistair23@gmail.com, linux-riscv@lists.infradead.org, mingo@redhat.com, alistair.francis@wdc.com, atish.patra@wdc.com Subject: [PATCH 3/6] uapi: futex: Add a futex syscall Date: Fri, 28 Oct 2022 19:56:29 +1000 Message-Id: <20221028095632.1081262-4-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> References: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alistair Francis This commit adds two futex syscall wrappers that are exposed to userspace. Neither the kernel or glibc currently expose a futex wrapper, so userspace is left performing raw syscalls. This has mostly been because the overloading of one of the arguments makes it impossible to provide a single type safe function. Until recently the single syscall has worked fine. With the introduction of a 64-bit time_t futex call on 32-bit architectures, this has become more complex. The logic of handling the two possible futex syscalls is complex and often implemented incorrectly. This patch adds two futex syscall functions that correctly handle the time_t complexity for userspace. This idea is based on previous discussions: https://lore.kernel.org/lkml/CAK8P3a3x_EyCiPDpMK54y=3DRtm-Wb08ym2TNiuAZgXhY= rThcWTw@mail.gmail.com/ Signed-off-by: Alistair Francis Message-Id: <20211209235857.423773-3-alistair.francis@opensource.wdc.com> --- include/uapi/linux/futex_syscall.h | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 include/uapi/linux/futex_syscall.h diff --git a/include/uapi/linux/futex_syscall.h b/include/uapi/linux/futex_= syscall.h new file mode 100644 index 000000000000..bac621eb319c --- /dev/null +++ b/include/uapi/linux/futex_syscall.h @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Futex syscall helper functions + * + * Copyright (C) 2021 Western Digital. All Rights Reserved. + * + * Author: Alistair Francis + */ +#ifndef _UAPI_LINUX_FUTEX_SYSCALL_H +#define _UAPI_LINUX_FUTEX_SYSCALL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * __kernel_futex_syscall_timeout() - __NR_futex/__NR_futex_time64 syscall= wrapper + * @uaddr: address of first futex + * @op: futex op code + * @val: typically expected value of uaddr, but varies by op + * @timeout: an absolute struct timespec + * @uaddr2: address of second futex for some ops + * @val3: varies by op + */ +static inline int +__kernel_futex_syscall_timeout(volatile uint32_t *uaddr, int op, uint32_t = val, + struct timespec *timeout, volatile uint32_t *uaddr2, int val3) +{ +#if defined(__NR_futex_time64) + if (sizeof(*timeout) !=3D sizeof(struct __kernel_old_timespec)) { + int ret =3D syscall(__NR_futex_time64, uaddr, op, val, timeout, uaddr2, = val3); + + if (ret =3D=3D 0 || errno !=3D ENOSYS) + return ret; + } +#endif + +#if defined(__NR_futex) + if (sizeof(*timeout) =3D=3D sizeof(struct __kernel_old_timespec)) + return syscall(__NR_futex, uaddr, op, val, timeout, uaddr2, val3); + + if (timeout && timeout->tv_sec =3D=3D (long)timeout->tv_sec) { + struct __kernel_old_timespec ts_old; + + ts_old.tv_sec =3D (__kernel_long_t) timeout->tv_sec; + ts_old.tv_nsec =3D (__kernel_long_t) timeout->tv_nsec; + + return syscall(__NR_futex, uaddr, op, val, &ts_old, uaddr2, val3); + } else if (!timeout) { + return syscall(__NR_futex, uaddr, op, val, NULL, uaddr2, val3); + } +#endif + + errno =3D ENOSYS; + return -1; +} + +/** + * __kernel_futex_syscall_nr_requeue() - __NR_futex/__NR_futex_time64 sysc= all wrapper + * @uaddr: address of first futex + * @op: futex op code + * @val: typically expected value of uaddr, but varies by op + * @nr_requeue: an op specific meaning + * @uaddr2: address of second futex for some ops + * @val3: varies by op + */ +static inline int +__kernel_futex_syscall_nr_requeue(volatile uint32_t *uaddr, int op, uint32= _t val, + uint32_t nr_requeue, volatile uint32_t *uaddr2, int val3) +{ +#if defined(__NR_futex_time64) + int ret =3D syscall(__NR_futex_time64, uaddr, op, val, nr_requeue, uaddr= 2, val3); + + if (ret =3D=3D 0 || errno !=3D ENOSYS) + return ret; +#endif + +#if defined(__NR_futex) + return syscall(__NR_futex, uaddr, op, val, nr_requeue, uaddr2, val3); +#endif + + errno =3D ENOSYS; + return -1; +} + +#endif /* _UAPI_LINUX_FUTEX_SYSCALL_H */ --=20 2.37.3 From nobody Wed Apr 8 17:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D14F3ECAAA1 for ; Fri, 28 Oct 2022 09:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbiJ1J6d (ORCPT ); Fri, 28 Oct 2022 05:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbiJ1J5z (ORCPT ); Fri, 28 Oct 2022 05:57:55 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9186B5A827 for ; Fri, 28 Oct 2022 02:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666951042; x=1698487042; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r/Wt8wTrrxLwn/R3qKGQRI/nbpEUQa2isveXNykvGmo=; b=D70giHajM4Owq1IwKDR7pbSjdFwyqMvIkpVbizjof3Sp5Xg4sQlr/FaE MwwyX8CeEYZySeq5VbHMAppG7Ncsgrydd2JiahEjxko1H3hg1IP5yft9H 2OFPSKLW8pgrEp9E9H2ZVEiey7Wl8PUL0jLBUJAABXb1OEzahwWCxypIc MxWN3BGIkpIQ0daQnIGyDYCB5/lT+gpWBTJoL+2eGeWj4bv4vCpH7Vk7q 5j6wZZv7wy8+GxKp/pJDFA7R/h7d1KxKjuMFJne5H51eu4Lz6oqtHQsCQ k6+Kp/Nx8/Ir5Ku8rHPe+Lcc5i+EIRxyLLh6mFKgoFQzahkSb+ftJX63Y w==; X-IronPort-AV: E=Sophos;i="5.95,220,1661788800"; d="scan'208";a="327068497" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2022 17:57:21 +0800 IronPort-SDR: U+qZsvGaWMfcwF4H6obUyXcSpY9JF5saundO8oftyR6Xbgxu6oG5i/TplnS9Kbm7qccDmDwwmg YtTbqQEbbsdROLqisET1H3fM4hjG/5TN/uQMkaPuw0rqKpBYEioU30K+4/4/HAKi+PZZluA7T+ zU3T6RmZCV80MaIBWfj/vCIAOb+HIO2Ukg0B6Bqb7f/UuRBKJ1OmcafexhZKHqSrfb1/+4V/1W s91gvbGfb5Uj2KVNvQ131b8L2xrRifNq1vj+B0mvd7zzTKvgdUrCVFVwSjhxWfmN0trkqT+3Yk dNwh4ZEGTi1pRrz22OdoNkMI Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:16:41 -0700 IronPort-SDR: M8kz8t4jbCtprmaG5BDc51msI0JF5TZOfvfJJbEbJ447jrHir47xUu5YO0cSUHiJuWV3mBPDhc gPuLdJCfl75CWcLVoWkehFPxlT9wcyumlBYvDHXNK/ZMx3F6o4/0jtMYqiHB4y7TVqfq1Q1Yr7 iLUQ+zcCjG+foHeOKpl0gzVfLWSCuJNyRv6wpSI1c+TXaXB72qXOTlgOrqNi2SFQc4mGV+ehtH sIFm6iAcbt/FRf4oHNWQx+YeuM+/DErv3++ww/1eye69QAmWXskAqqkQHMHsap72ec02AGk2Ty Bk8= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:57:22 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MzHyn2WZ2z1RWy3 for ; Fri, 28 Oct 2022 02:57:21 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666951040; x=1669543041; bh=r/Wt8wTrrxLwn/R3qK GQRI/nbpEUQa2isveXNykvGmo=; b=J/XB7nV3s8VIP3A2o68BCRLdofvNTcUQoQ WBFb7oiY2q3ZtHUgU/oyAMv/aTGdkNAeTg4zioNsvN7N0Hvi8camt+2Vqc4Qmkma qD0h9f2TouksOrzl9VGkBu3QSVWJZF96fMvqslYzl6fx0nuuG0EApS6wBlbZT/Ju ylvGiB/zfeLKclZ6F9BQzXJ3tz8BueH6n7jBLDHqU0xCaJBqIduYTbdnPuq9nUUV Ys2p0lfJmr7fykFMktiyg2cVClc1P5j8dlG3k/YHZfjvLL0WFRrE/yew1NptDn2O JaS6AJcDVjHiv/l5rwKPGC4g9b+fPyNrNQTpGA3BdKyqPUbB63JA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id O-6iK4hps_tj for ; Fri, 28 Oct 2022 02:57:20 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.50]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MzHyc2BBbz1RvLy; Fri, 28 Oct 2022 02:57:11 -0700 (PDT) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, dave@stgolabs.net, alexander.shishkin@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, acme@redhat.com, dvhart@infradead.org, mark.rutland@arm.com, peterz@infradead.org, arnd@arndb.de, alistair23@gmail.com, linux-riscv@lists.infradead.org, mingo@redhat.com, alistair.francis@wdc.com, atish.patra@wdc.com Subject: [PATCH 4/6] selftests: futex: Add support for 32-bit systems with 64-bit time_t Date: Fri, 28 Oct 2022 19:56:30 +1000 Message-Id: <20221028095632.1081262-5-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> References: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alistair Francis Using the new __kernel_futex_syscall*() functions let's add support for 32-bit systems with a 64-bit time_t. We can just direclty call the publically exposed __kernel_futex_syscall_timeout() and __kernel_futex_syscall_nr_requeue() functions to do this. Signed-off-by: Alistair Francis Message-Id: <20211209235857.423773-4-alistair.francis@opensource.wdc.com> --- tools/testing/selftests/futex/functional/futex_requeue_pi.c | 2 +- tools/testing/selftests/futex/include/futextest.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/= tools/testing/selftests/futex/functional/futex_requeue_pi.c index 1ee5518ee6b7..556bf3e74755 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c @@ -294,7 +294,7 @@ int unit_test(int broadcast, long lock, int third_party= _owner, long timeout_ns) secs =3D (ts.tv_nsec + timeout_ns) / 1000000000; ts.tv_nsec =3D ((int64_t)ts.tv_nsec + timeout_ns) % 1000000000; ts.tv_sec +=3D secs; - info("ts.tv_sec =3D %ld\n", ts.tv_sec); + info("ts.tv_sec =3D %lld\n", (long long) ts.tv_sec); info("ts.tv_nsec =3D %ld\n", ts.tv_nsec); tsp =3D &ts; } diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/test= ing/selftests/futex/include/futextest.h index c786fffecb8a..1686f94667b1 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -21,6 +21,7 @@ #include #include #include +#include =20 typedef volatile u_int32_t futex_t; #define FUTEX_INITIALIZER 0 @@ -69,14 +70,14 @@ static inline int futex_syscall(volatile u_int32_t *uaddr, int op, u_int32_t val, struct tim= espec *timeout, volatile u_int32_t *uaddr2, int val3, int opflags) { - return syscall(SYS_futex, uaddr, op | opflags, val, timeout, uaddr2, val3= ); + return __kernel_futex_syscall_timeout(uaddr, op | opflags, val, timeout, = uaddr2, val3); } =20 static inline int futex_syscall_nr_requeue(volatile u_int32_t *uaddr, int op, u_int32_t val,= int nr_requeue, volatile u_int32_t *uaddr2, int val3, int opflags) { - return syscall(SYS_futex, uaddr, op | opflags, val, nr_requeue, uaddr2, v= al3); + return __kernel_futex_syscall_nr_requeue(uaddr, op | opflags, val, nr_req= ueue, uaddr2, val3); } =20 /** --=20 2.37.3 From nobody Wed Apr 8 17:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DCBEECAAA1 for ; Fri, 28 Oct 2022 09:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbiJ1J6p (ORCPT ); Fri, 28 Oct 2022 05:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbiJ1J5z (ORCPT ); Fri, 28 Oct 2022 05:57:55 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A828248A3B for ; Fri, 28 Oct 2022 02:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666951051; x=1698487051; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5sXdRpXoL8fKMHadmBmTH5z4Y4mbuNPDkZAxHvAj8lU=; b=j5FwVFpkYrZ3n9vmSI6ZCdaC3au/JB4T5DYCcF/mjSxonGVbkxTxK1c/ 4bHPAxswHfqRPHxswSrdejVU8QfFH/Fc2utKFAihRgN32tG/++klULaIa W+UBYKQruBP6xGT7T5+pu3i/SnG2q3Yk9q6ih/p6VfyEh/1f9Uhm9pFb0 0+cDLbDd0Bx7pILg6nuXhOoMu+iCOtsIeEhDD9v85UXgO1En/lutePvIG p9NONOVo7YamnlxY93gDFfa4NzaYLt8bO4KGZVZ9zrBV1fB8jYXRrjl1M 64qs8N0/6Qmpab6nRansrOwCAgl+/EDreKfVcQv0U71okhtl4l0d/6Om/ w==; X-IronPort-AV: E=Sophos;i="5.95,220,1661788800"; d="scan'208";a="214962251" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2022 17:57:31 +0800 IronPort-SDR: vGXVRuET5nPJyJHBCJmoE8wC+jFCqoIxLRpxW+FJRQqrB5j6rhJPCB5eUvFx07yz36MXJSIJOi jJSoMEHbd6ZULQErOmZ84XOugzLzArAr1217sZbT6MxFMDfdihVzSPYsRtuG//a5MmvoDUT35t NNOjm3VacT36wfcuxrh1xUsXkWEiNUqJrnjes8tV8CMB2875w8ryhQc8UuBwSt/0DZ500CT++L ha9SXdhXYFnBF2MSkY9IgQjq4jWu0uwrp6Tk2485i0KLg2fGVRw1I/Kj5LseaCbWbOogvzBg4+ gCui2bO5/jaBns39ScFF7137 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:16:51 -0700 IronPort-SDR: 4a3jm/dhZFn5wMyUMAV1EyWsRjIEQNh/O2JDnqxF1dSwlcDKfQ7acN52XC+JsA2ujbA3HUxm5p oTLwlYwUaa6kIOBG6bnnLoOdMPznduPSOSUlwjQE5PefwnogLZM0j6ANBtPiT3IfNSKyXPOciy giQ9LLykY9cCp24zJkYFL7AF/cYAhMXl7sr5Z+caC8Z+LN93kHoKr0txHA17X237Cn1icogO8S I9ZRcLzDEj2BxJOlVzG+HE5gj+EUzEkrMTYQV11vTi8QjuLb825JbApiZ53i9O/A78iFs0c/RH XFQ= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:57:32 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MzHyz05fxz1Rx15 for ; Fri, 28 Oct 2022 02:57:30 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666951049; x=1669543050; bh=5sXdRpXoL8fKMHadmB mTH5z4Y4mbuNPDkZAxHvAj8lU=; b=i4/10uIu5RyP75V/f5ENBFGxGBQsJdPxTT e+kzdLy8o7BJq2hv9WGbJcPNne4tQPPnn2Acj2woZm2Xyp4Jhw3LAI8A/HAIFFwl NNiTQBR4Zf4diFyhwtRhDQRyV4eUz8AhcYUH6bk+kk/ew6Ih3Lw2hZlN3MeFCtWq yg8I5LQk6DPR8peBUxhVIrW2l/B00G4BReNrsIqnEJFmkQSIk0ZyB2BKx8Y9ZjZH HMMi3VYWfIYEbXeJU5BkIuewRNqpBMfAqUzDKolPa5HPPj05XT48eQ9Y3LRbuUoe 1dKOqJ/YCh/NfdcW9YftXy/87Oq4Y/lmphJilXOocMvsDc8RgHXw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yVrgylNbT07p for ; Fri, 28 Oct 2022 02:57:29 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.50]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MzHyn26b8z1RwtC; Fri, 28 Oct 2022 02:57:20 -0700 (PDT) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, dave@stgolabs.net, alexander.shishkin@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, acme@redhat.com, dvhart@infradead.org, mark.rutland@arm.com, peterz@infradead.org, arnd@arndb.de, alistair23@gmail.com, linux-riscv@lists.infradead.org, mingo@redhat.com, alistair.francis@wdc.com, atish.patra@wdc.com Subject: [PATCH 5/6] uapi: futex: Add a futex waitv syscall Date: Fri, 28 Oct 2022 19:56:31 +1000 Message-Id: <20221028095632.1081262-6-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> References: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alistair Francis This commit adds a futex waitv syscall wrapper that is exposed to userspace. Neither the kernel or glibc currently expose a futex wrapper, so userspace is left performing raw syscalls. As the futex_waitv syscall always expects a 64-bit time_t this can be tricky for 32-bit systems to get correct. In order to avoid userspace incorrectly passing the wrong timeouts let's expose a public helper function that ensures the kernel is passed the correct timeout struct. Signed-off-by: Alistair Francis Reviewed-by: Arnd Bergmann Message-Id: <20211209235857.423773-5-alistair.francis@opensource.wdc.com> --- include/uapi/linux/futex_syscall.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/uapi/linux/futex_syscall.h b/include/uapi/linux/futex_= syscall.h index bac621eb319c..f637f05a3be0 100644 --- a/include/uapi/linux/futex_syscall.h +++ b/include/uapi/linux/futex_syscall.h @@ -89,4 +89,31 @@ __kernel_futex_syscall_nr_requeue(volatile uint32_t *uad= dr, int op, uint32_t val return -1; } =20 +/** + * __kernel_futex_syscall_waitv - Wait at multiple futexes, wake on any + * @waiters: Array of waiters + * @nr_waiters: Length of waiters array + * @flags: Operation flags + * @timo: Optional timeout for operation + */ +static inline int +__kernel_futex_syscall_waitv(volatile struct futex_waitv *waiters, unsigne= d long nr_waiters, + unsigned long flags, struct timespec *timo, clockid_t clockid) +{ + /* futex_waitv expects a 64-bit time_t */ + if (sizeof(*timo) =3D=3D sizeof(struct __kernel_timespec)) + return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clock= id); + + /* If the caller supplied a 32-bit time_t, convert it to 64-bit */ + if (timo) { + struct __kernel_timespec ts_new; + + ts_new.tv_sec =3D timo->tv_sec; + ts_new.tv_nsec =3D timo->tv_nsec; + + return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, &ts_new, cl= ockid); + } else + return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, NULL, clock= id); +} + #endif /* _UAPI_LINUX_FUTEX_SYSCALL_H */ --=20 2.37.3 From nobody Wed Apr 8 17:19:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFA66C38A02 for ; Fri, 28 Oct 2022 09:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbiJ1J6l (ORCPT ); Fri, 28 Oct 2022 05:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbiJ1J5z (ORCPT ); Fri, 28 Oct 2022 05:57:55 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B936B4BA65 for ; Fri, 28 Oct 2022 02:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1666951058; x=1698487058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JydiMbJm91qt7Dzdbzqgf9FuIhgVG9u78TP21lC8mbE=; b=KcqwFCXt6O6YYo0VqzY0Me9E/fyCCDsQ5pS6d+uchlsR6pfAYcE38KaH zL3Nyd6VCNkwgENEYAkiYiRYf5L4+YWCLZ//qUgVFZcBkqtTgeR7KZ9im M/LbwmdZOXbQARep2jIoOIFyzyqNQuoubb+9Aaql0hyGJF9jTP7sY4PBv B+Y7TmIxwg9NunNhk4knfd+8Y3FY/WTV7WX2nOIaMURQg5NwbM10PYy+U KYL44YTXUCoVez0Q7+oe+6ssLd/FHqir3gsvO3bet5bC4GPnCpXJxFTkm cbwshbucx7Y00TvIfuVlD5LMhU097Mc47QyQsI+ulhh7du69UdgPkK2kP Q==; X-IronPort-AV: E=Sophos;i="5.95,220,1661788800"; d="scan'208";a="327068528" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Oct 2022 17:57:37 +0800 IronPort-SDR: aVnYPSrmKr4bWmI4qyDuy+K3i84Aflr90WQnTX6VLCTC1wMv/NdL+iqYo4LT4774+2zoJ5n/1p B7dGqFRgMfepGdqmyBIQUwa/25/iJjJkm0fZtUfQKiTMIUolM6GiseJK2ZLf9ZAxxnbNQZOPUL hgpk1g83tnPFYipT1EWiS0kVUMSQKtxTvMN2akXrA0eAC0LmqPvZzsAn0OxIj1LBTySbHq0LN3 IK/gVJ9xS1Sor5sicwDYmkpUrb/Om5velLX7b+wCf7QFJ9ZjWQyz4ipbjiadQodCOG4DRQ+MRe d8MCESJeKCKanq3jcP2iduRs Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:11:14 -0700 IronPort-SDR: OkxcFIkieMD7AV5nA6FtG9LqsBVlqL6u4VB+xMqHYZnXllmjW/gLasypTY2jm6kg7sFyjMYQs/ YW339jqmZLO63PumM/azGNhmw3apMMCZGqFq326JSoHfOJt9m/sJkGDBu2aMVjympnQz6OQxu1 GwxVpsHqbiyoQ7O+a7zwuuSvr29Bz2S6OJcTf8E5ms0Ap1GoSh+Wyryo++/LUOrq1usxOdDqjG BrSxDm3fY75qsYkcBKFRVoRBDmV3hI//yiRNhQvZDWTOhh9667d4xB8j7YsFNfIhYEP1KOiRYp SRM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Oct 2022 02:57:38 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4MzHz45yL5z1SHkN for ; Fri, 28 Oct 2022 02:57:36 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1666951055; x=1669543056; bh=JydiMbJm91qt7Dzdbz qgf9FuIhgVG9u78TP21lC8mbE=; b=j4RPkeDxD2OMqX5Kxa/3L32kWsZVpnmHr6 BX+yIlhNHMvGj8A/k3T1hWRpUdDmrQWD7bum2uaSPmy7PgQtfwWQh9jsrpx9aLai twJ3Qb4KRS3qMqAY5VyHySyh/tP8wknTEYHCs061Qq7tKyih2RzCagzYSo+nsAQH dvvF8wU4J247DKqVq+cPiysOHuqw5sByri8/ct5ZjmjXPD6smYx/xm7TL4i5AZvh i539ZC1YkSepuErIJctkmpHBUR4i5HAeJgJKBBDQ/doWP8SbVzFX+EErBI3DA9hF vGgkNwGT29RTkowIHP/Zy/Wu4zNaPL+MlyFdv2ud1IqiEU2U1i/g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 8d7oQvq_s8MR for ; Fri, 28 Oct 2022 02:57:35 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.167.50]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4MzHyy43gyz1RvLy; Fri, 28 Oct 2022 02:57:30 -0700 (PDT) From: Alistair Francis To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, dave@stgolabs.net, alexander.shishkin@linux.intel.com, tglx@linutronix.de, namhyung@kernel.org, jolsa@redhat.com, linux-perf-users@vger.kernel.org, acme@redhat.com, dvhart@infradead.org, mark.rutland@arm.com, peterz@infradead.org, arnd@arndb.de, alistair23@gmail.com, linux-riscv@lists.infradead.org, mingo@redhat.com, alistair.francis@wdc.com, atish.patra@wdc.com Subject: [PATCH 6/6] selftests: futex: Use futex_waitv helper function Date: Fri, 28 Oct 2022 19:56:32 +1000 Message-Id: <20221028095632.1081262-7-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> References: <20221028095632.1081262-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alistair Francis Use the publically exposed __kernel_futex_syscall_waitv() helper function for the futex_waitv tests. Signed-off-by: Alistair Francis Message-Id: <20211209235857.423773-6-alistair.francis@opensource.wdc.com> --- tools/testing/selftests/futex/include/futex2test.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/futex/include/futex2test.h b/tools/tes= ting/selftests/futex/include/futex2test.h index 9d305520e849..fdc0a0a270cd 100644 --- a/tools/testing/selftests/futex/include/futex2test.h +++ b/tools/testing/selftests/futex/include/futex2test.h @@ -5,6 +5,7 @@ * Copyright 2021 Collabora Ltd. */ #include +#include =20 #define u64_to_ptr(x) ((void *)(uintptr_t)(x)) =20 @@ -18,5 +19,5 @@ static inline int futex_waitv(volatile struct futex_waitv *waiters, unsign= ed long nr_waiters, unsigned long flags, struct timespec *timo, clockid_t clockid) { - return syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clocki= d); + return __kernel_futex_syscall_waitv(waiters, nr_waiters, flags, timo, clo= ckid); } --=20 2.37.3