Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp929916pxt; Thu, 5 Aug 2021 15:35:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzha+bTD9uj+pjNqF6aYVKQ0oi2ZAxvq0ii6IZTAgTdoFoUBG37clxTD4epQnxZyrd5GCgU X-Received: by 2002:a92:cacd:: with SMTP id m13mr1538605ilq.256.1628202934286; Thu, 05 Aug 2021 15:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628202934; cv=none; d=google.com; s=arc-20160816; b=KHGVe+MZ7Ch81bW4UlXdDzYjog+sRH7KjDHQ6eAVnr6LPgRvvQERpgXqNZLFOj+30U Qt0gZc6Avr7SUJ9ppEDD4Bs6jP+sxnJxIZhXodJJKfkIh4JJYGRvS1P/eSYoPUbl4/kL TFG+FJkJVIotnWyu7toea8w1Txxo5hg8euTc7hGwwASqSsFmfnHjgaimfG6bfRsUSOlj lPaUjLeOVRq3cWttcMdsCw0FLQhHzs1ABygCFsJeGUO83ozUs/8BnDyrIgDu6qc12np4 dGmRwVPu4a/ZOMx3uFwmQ2a51qJRex3o/zrLwdeBtU4nEP3F0KYlgR9/+1PmP5O84O6/ c1Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:subject:cc:to:from:date:dkim-signature:dkim-signature :message-id; bh=zDbJOU97IQurUO8kF4WxZNgLkAG7qo6kSYRC7UzhOBU=; b=U0G3AHetune0Od9rr8c4HT+VHWuneq462Cti99yWfvnT637J1Z6QMk36t1gVhgG0/P ID/1V2KH5sQX4bxiU0kny1pdwcCyXeTPGB8U1spv+F6AiDKYRoukuLT62b/7C88C0nGr pu+hjGYdAtslup/nMCGhFv3Qb+xNgNGx0eNGAJXQt174VoeztpiKoe7j3a9GjR5DrSM7 gwdvdxKUGRzD6xYBZa35/Xzi+yB6pK8cLeS+oOnKvpFF48TOB034aNZRlo7YlY2VlSGJ YC3NGhNkzgZQeiqQoAzwRUtqaBp3Ye5/RDoKjk9v0F3eTGj9MfMSM+R0rGaam2pmGxr/ mfcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3K5SQ6OB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=7biyHmoC; 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 i16si6918453jan.31.2021.08.05.15.35.21; Thu, 05 Aug 2021 15:35:34 -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=3K5SQ6OB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=7biyHmoC; 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 S242861AbhHEPqG (ORCPT + 99 others); Thu, 5 Aug 2021 11:46:06 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:43924 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242336AbhHEPmt (ORCPT ); Thu, 5 Aug 2021 11:42:49 -0400 Message-ID: <20210805153956.161214930@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628178154; h=from:from: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: references:references; bh=zDbJOU97IQurUO8kF4WxZNgLkAG7qo6kSYRC7UzhOBU=; b=3K5SQ6OBW7s/GYacjIblXhGTF14wAFmTw9fDHIs9izMr5w39evDYOgwjCC+28vjoXDNqTb NxdEfTUdGGIUL+OXmgunFeaxXiWFOMAh8NDonBK5DS57vo3X7lMJo4cKt2ojJvvkQ98yBh 5dvhozn3eHXhJdLl0pyx67W7CuASgTc743/KeF10ebtWIRO76F1F9KQYIC3LPnIrgYmubL /xqvb7Mvfo7FdUUuPyTrBBdXr7pK2GCX5WboXMDJriR6u5CJb/yDq1ZPwXUmFx3LzXQ4Hw OjyyIYGdDfFm58f5C5fqbVyv0D8idozoEEHeNXLh25Mn0prs9Xav3LlB9gTHEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628178154; h=from:from: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: references:references; bh=zDbJOU97IQurUO8kF4WxZNgLkAG7qo6kSYRC7UzhOBU=; b=7biyHmoCIKs+jPx3DaWwhKteUxNTRY3QMYQTjyCbEvN77YVP1gy3V8hDclaNgxqezSkiBd lQs7lHR2rPkHM4CA== Date: Thu, 05 Aug 2021 17:13:58 +0200 From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Steven Rostedt , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , Sebastian Andrzej Siewior , Davidlohr Bueso , Mike Galbraith Subject: [patch V3 58/64] futex: Clarify comment in futex_requeue() References: <20210805151300.330412127@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner The comment about the restriction of the number of waiters to wake for the REQUEUE_PI case is confusing at best. Rewrite it. Signed-off-by: Thomas Gleixner --- kernel/futex.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) --- --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1960,15 +1960,27 @@ static int futex_requeue(u32 __user *uad */ if (refill_pi_state_cache()) return -ENOMEM; + /* - * requeue_pi must wake as many tasks as it can, up to nr_wake - * + nr_requeue, since it acquires the rt_mutex prior to - * returning to userspace, so as to not leave the rt_mutex with - * waiters and no owner. However, second and third wake-ups - * cannot be predicted as they involve race conditions with the - * first wake and a fault while looking up the pi_state. Both - * pthread_cond_signal() and pthread_cond_broadcast() should - * use nr_wake=1. + * futex_requeue() allows the caller to define the number + * of waiters to wake up via the @nr_wake argument. With + * REQUEUE_PI waking up more than one waiter is creating + * more problems than it solves. Waking up a waiter makes + * only sense if the PI futex @uaddr2 is uncontended as + * this allows the requeue code to acquire the futex + * @uaddr2 before waking the waiter. The waiter can then + * return to user space without further action. A secondary + * wakeup would just make the futex_wait_requeue_pi() + * handling more complex because that code would have to + * look up pi_state and do more or less all the handling + * which the requeue code has to do for the to be requeued + * waiters. So restrict the number of waiters to wake to + * one and only wake it up when the PI futex is + * uncontended. Otherwise requeue it and let the unlock of + * the PI futex handle the wakeup. + * + * All REQUEUE_PI users, e.g. pthread_cond_signal() and + * pthread_cond_broadcast() must use nr_wake=1. */ if (nr_wake != 1) return -EINVAL;