Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3149400pxb; Sat, 9 Oct 2021 03:10:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNDl08nGqcIweXSg58YHjCIvvVYE4V6s4EbbTLPL2CqHsIc9DD4e72d0+Y3bDppRni15J8 X-Received: by 2002:a17:906:1fc1:: with SMTP id e1mr10461824ejt.515.1633774252237; Sat, 09 Oct 2021 03:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633774252; cv=none; d=google.com; s=arc-20160816; b=BVUOFTq5bQFjBA2qjgHxn7HyHNKTdGti/h1wVcILYl0UMYyVGSX5SZzNsBJ39GjpBk W1YbhUJlbcSc/Y7992D2nc5Api2eG3dJro6/ClfBAjFZjMvCryjvM3Pjo68zbLJ7a6W9 LAP9sfuzoMlZUxWVKnzr4kA5PMj0DsJvAOtRtTE3+2szK9fHue3Rw6SC1dDbM4S7xYRm EniztRIYmfdU93I/XxMpC9WYKw9nO7MZ9h8lBzeviXoXORJ+DRUbG0nJEr5C7v408NDh NsT2VoZRn6ncFRLYAsjiGGYI8YRq0cBRIes8OwmQeP8ZramHsmuWhwbhJt0dx0fksStA tyLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=KAVJicna/b7C2WGjjGSmvD9XEwNO08BcYAxnu1bhB4A=; b=i+XqCJsSwmUNs4JHSSxMwDgQ0z1itgGmacl02dW/WPS8D5yy+O8nEy11IZMhdcmeuF aOo5Cmcc3YDy/syVk8j7pXOUIw5czIa6PdjfDyvRqWU0HaUy5ddcfNa+azOrrMMP4r9y kkZrd/dBgqdGQegElSzvLT0yvx92tm4ZzbzL8Mz85TT+QCMZMP2uLgpdMBtJohWkRQBI HCqvlkzJ744oul6Pr2Os6CjYJFQEmk+pz/y7IgCJUcBC3xByprnFy2xZfEyGaG4HvOoK cbyH9v2e9je0VgulbJ1VVJXQ+k9VzSKCuRgsgZ+KG8IaS6iRKHlMxmFZZn+lukSz0uKo z1UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qNXbMDhO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=s98zpnWn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si2673071ejr.434.2021.10.09.03.10.29; Sat, 09 Oct 2021 03:10:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qNXbMDhO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=s98zpnWn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244523AbhJIKJG (ORCPT + 99 others); Sat, 9 Oct 2021 06:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244411AbhJIKJB (ORCPT ); Sat, 9 Oct 2021 06:09:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8B24C061570; Sat, 9 Oct 2021 03:07:04 -0700 (PDT) Date: Sat, 09 Oct 2021 10:06:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1633774020; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KAVJicna/b7C2WGjjGSmvD9XEwNO08BcYAxnu1bhB4A=; b=qNXbMDhOLyCTcLxugNHuU6pEj4b2sAb+xWlhudLDd7QYcTMmT/7J+upyKxNnnXtkJLOKcI 1A5Aez39IAN5wQs0D6LEGqHqYN+pt5/rlnrPlWVknJds1gXmLO0ibMbAQCTqAkghxviPvH 6Y8G6/6iKnTGRND7vdKJXySqPsYRa8WoxGeWmySUpn6o42iEyvpDxA5U1kSelxH21LVaxi oWPrGjbJUBvaWGKzhdpEKpfYDYFiOpDw+ssSD3xq5So1zN7Z4AJ/R7JkcrpnS4sU4+QZtl pGZN1KA42MEZYa40OuGVOtY56zm6HqejksgISu+/RDr5Y257ib/uk/DrHvsyHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1633774020; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KAVJicna/b7C2WGjjGSmvD9XEwNO08BcYAxnu1bhB4A=; b=s98zpnWn3qR5S7R+BqWrxdMlfUBZShn3PPh24yqqKuyTARsPlgzBht8FiXqs4oC+a8m0WT YSSmLxFyfLwtPqBA== From: tip-bot2 for =?utf-8?q?Andr=C3=A9?= Almeida Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] futex2: Documentation: Document sys_futex_waitv() uAPI Cc: andrealmeid@collabora.com, "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210923171111.300673-23-andrealmeid@collabora.com> References: <20210923171111.300673-23-andrealmeid@collabora.com> MIME-Version: 1.0 Message-ID: <163377401910.25758.10428842079103776202.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: dd0aa2cd2e9e3e49b8c3b43924dc1a1d4e22b4d1 Gitweb: https://git.kernel.org/tip/dd0aa2cd2e9e3e49b8c3b43924dc1a1d4e2= 2b4d1 Author: Andr=C3=A9 Almeida AuthorDate: Thu, 23 Sep 2021 14:11:11 -03:00 Committer: Peter Zijlstra CommitterDate: Thu, 07 Oct 2021 13:51:13 +02:00 futex2: Documentation: Document sys_futex_waitv() uAPI Create userspace documentation for futex_waitv() syscall, detailing how the arguments are used. Signed-off-by: Andr=C3=A9 Almeida Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20210923171111.300673-23-andrealmeid@collabor= a.com --- Documentation/userspace-api/futex2.rst | 86 +++++++++++++++++++++++++- Documentation/userspace-api/index.rst | 1 +- 2 files changed, 87 insertions(+) create mode 100644 Documentation/userspace-api/futex2.rst diff --git a/Documentation/userspace-api/futex2.rst b/Documentation/userspace= -api/futex2.rst new file mode 100644 index 0000000..9693f47 --- /dev/null +++ b/Documentation/userspace-api/futex2.rst @@ -0,0 +1,86 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D +futex2 +=3D=3D=3D=3D=3D=3D + +:Author: Andr=C3=A9 Almeida + +futex, or fast user mutex, is a set of syscalls to allow userspace to create +performant synchronization mechanisms, such as mutexes, semaphores and +conditional variables in userspace. C standard libraries, like glibc, uses it +as a means to implement more high level interfaces like pthreads. + +futex2 is a followup version of the initial futex syscall, designed to overc= ome +limitations of the original interface. + +User API +=3D=3D=3D=3D=3D=3D=3D=3D + +``futex_waitv()`` +----------------- + +Wait on an array of futexes, wake on any:: + + futex_waitv(struct futex_waitv *waiters, unsigned int nr_futexes, + unsigned int flags, struct timespec *timeout, clockid_t clocki= d) + + struct futex_waitv { + __u64 val; + __u64 uaddr; + __u32 flags; + __u32 __reserved; + }; + +Userspace sets an array of struct futex_waitv (up to a max of 128 entries), +using ``uaddr`` for the address to wait for, ``val`` for the expected value +and ``flags`` to specify the type (e.g. private) and size of futex. +``__reserved`` needs to be 0, but it can be used for future extension. The +pointer for the first item of the array is passed as ``waiters``. An invalid +address for ``waiters`` or for any ``uaddr`` returns ``-EFAULT``. + +If userspace has 32-bit pointers, it should do a explicit cast to make sure +the upper bits are zeroed. ``uintptr_t`` does the tricky and it works for +both 32/64-bit pointers. + +``nr_futexes`` specifies the size of the array. Numbers out of [1, 128] +interval will make the syscall return ``-EINVAL``. + +The ``flags`` argument of the syscall needs to be 0, but it can be used for +future extension. + +For each entry in ``waiters`` array, the current value at ``uaddr`` is compa= red +to ``val``. If it's different, the syscall undo all the work done so far and +return ``-EAGAIN``. If all tests and verifications succeeds, syscall waits u= ntil +one of the following happens: + +- The timeout expires, returning ``-ETIMEOUT``. +- A signal was sent to the sleeping task, returning ``-ERESTARTSYS``. +- Some futex at the list was woken, returning the index of some waked futex. + +An example of how to use the interface can be found at ``tools/testing/selft= ests/futex/functional/futex_waitv.c``. + +Timeout +------- + +``struct timespec *timeout`` argument is an optional argument that points to= an +absolute timeout. You need to specify the type of clock being used at +``clockid`` argument. ``CLOCK_MONOTONIC`` and ``CLOCK_REALTIME`` are support= ed. +This syscall accepts only 64bit timespec structs. + +Types of futex +-------------- + +A futex can be either private or shared. Private is used for processes that +shares the same memory space and the virtual address of the futex will be the +same for all processes. This allows for optimizations in the kernel. To use +private futexes, it's necessary to specify ``FUTEX_PRIVATE_FLAG`` in the fut= ex +flag. For processes that doesn't share the same memory space and therefore c= an +have different virtual addresses for the same futex (using, for instance, a +file-backed shared memory) requires different internal mechanisms to be get +properly enqueued. This is the default behavior, and it works with both priv= ate +and shared futexes. + +Futexes can be of different sizes: 8, 16, 32 or 64 bits. Currently, the only +supported one is 32 bit sized futex, and it need to be specified using +``FUTEX_32`` flag. diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-= api/index.rst index c432be0..a61eac0 100644 --- a/Documentation/userspace-api/index.rst +++ b/Documentation/userspace-api/index.rst @@ -28,6 +28,7 @@ place where this information is gathered. media/index sysfs-platform_profile vduse + futex2 =20 .. only:: subproject and html =20