Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2534206pxt; Mon, 9 Aug 2021 02:54:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkz0BsyIM5L9HjZin5onfgbuCBszI2RZPsN80gWY2ldoGDbPrIQKZApNM2Gn0+XxMMF9ps X-Received: by 2002:a05:6402:1719:: with SMTP id y25mr29076040edu.331.1628502891716; Mon, 09 Aug 2021 02:54:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628502891; cv=none; d=google.com; s=arc-20160816; b=npEZICbO+9s/RfsIzclEsq42TKY1KbZ6JOHRPotA29aU/J5F4TYV+kai8AT4tk6C28 A9sWLE4RbmGgXupyMOh6fSM+w56Zv0P26rXPyQmGGg+4ugG8jkeKtk1Hz3a3knJye778 uTItvh/HfjkDqz+nwPptfvN3FZF+VJNDrzm+GsKsd+/YiPFYA8h/EUNBBg1HA1rX2tFH +WnvMWTuIhNGpxyrvSgG6l67SLp/Gs04HCIEsISVbwCuiJh09eIaiJ6d+G1WfYCmLZfc FSOwlHVLKXJugdUFMQ0WMThPOEw+aC9TVLFxZemo+B/8oeYFPzU0XLAnFRiW5rS1VEm8 HsvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=zlMdws6cyohkcKoE6LS+JeHUqOT6wr3OqaNW970zyGs=; b=vSq+d6wPh+l6iwaCpIpbDDGwyspyw/mL/vNil7TJzFn+ahM9ZaczaWvXzVTnSvW2hZ m/UbSKmfH56cuw/z+phr6oBuMYwN8DKRxYZcLDY2D8y40gvaG3fYm40NH1MwUca8fYan yxHj74Yh+sL/pOadJIRH+2NplbjV/J4w6KPC0I3WdfyB9LgN4BPHbmaYp0uKyv7tqQpk PZfRYQrtoa9AXDlYhDC55fLIdN3AkH2HoEH20I8igKXZtz/8A8pSHFG2Mw70Dw0m22P5 SknERdGVaF1G7K+o1kpEBy6JRpBSmcZ64RBbou+eX2aEjt76rxkJPfla9vbN+dEX4d5l kxgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lzL1EENg; dkim=neutral (no key) header.i=@linutronix.de header.b=vWImuFQk; 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 h17si17085592edb.607.2021.08.09.02.54.28; Mon, 09 Aug 2021 02:54:51 -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=lzL1EENg; dkim=neutral (no key) header.i=@linutronix.de header.b=vWImuFQk; 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 S233878AbhHIISo (ORCPT + 99 others); Mon, 9 Aug 2021 04:18:44 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:34864 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233588AbhHIISn (ORCPT ); Mon, 9 Aug 2021 04:18:43 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628497102; 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: in-reply-to:in-reply-to:references:references; bh=zlMdws6cyohkcKoE6LS+JeHUqOT6wr3OqaNW970zyGs=; b=lzL1EENgaymAqIl1jCW9hxawXEhOeoNQ2NqfUecla0ivj7gtrpx37WtJKhx09FPfM26XWK F78/CNMq06WuOrQjHsVgl5BBw65hl1EGFu0lgpFEh6I4nU0bEzZ7A5Ax7bvR5K7+QmByeL sw7oG8wz+FC6J39tRwT0phXcI9OnUqE6HQHJGJyDQdJgjWLAM+az8YQ30ULFhut53ve8FT nOKqvLGEpcn2J0S67oJq/35X2RSstOv687FhYEw82OmpFslpyR1tUZ+bGKCBUoO3jY2WG9 fG4W3L6UbHaYmKbcDxuMceL1MJCy0KeL7QALH+BsQV6L7MUdAyrqo2MFoWrYQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628497102; 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: in-reply-to:in-reply-to:references:references; bh=zlMdws6cyohkcKoE6LS+JeHUqOT6wr3OqaNW970zyGs=; b=vWImuFQkcz+k7EjHGJ33+34dzM/uf9L53hfMpbqU2PsmULZlQWKK/kgmbJIv3dLPA3GUJG ntuiCZc0ItqafOBw== To: Davidlohr Bueso Cc: LKML , Peter Zijlstra , Ingo Molnar , Juri Lelli , Steven Rostedt , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , Sebastian Andrzej Siewior , Mike Galbraith Subject: Re: [patch V3 56/64] futex: Correct the number of requeued waiters for PI In-Reply-To: <20210808170535.kotqd5t677tijh4o@offworld> References: <20210805151300.330412127@linutronix.de> <20210805153956.051961951@linutronix.de> <20210808170535.kotqd5t677tijh4o@offworld> Date: Mon, 09 Aug 2021 10:18:22 +0200 Message-ID: <87o8a7t4j5.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 08 2021 at 10:05, Davidlohr Bueso wrote: > On Thu, 05 Aug 2021, Thomas Gleixner wrote: > >>From: Thomas Gleixner >> >>The accounting is wrong when either the PI sanity check or the >>requeue PI operation fails. Adjust it in the failure path. > > Ok fortunately these accounting errors are benign considering they > are in error paths. This also made me wonder about the requeue PI > top-waiter wakeup from futex_proxy_trylock_atomic(), which is always > required with nr_wakers == 1. We account for it on the successful > case we acquired the lock on it's behalf (and thus requeue_pi_wake_futex > was called), but if the corresponding lookup_pi_state fails, we'll retry. > So, shouldn't the task_count++ only be considered when we know the > requeueing is next (a successful top_waiter acquiring the lock+pi state)? > > @@ -2260,7 +2260,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags, > */ > if (ret > 0) { > WARN_ON(pi_state); > - task_count++; > /* > * If we acquired the lock, then the user space value > * of uaddr2 should be vpid. It cannot be changed by > @@ -2275,6 +2274,8 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags, > */ > ret = lookup_pi_state(uaddr2, ret, hb2, &key2, > &pi_state, &exiting); > + if (!ret) > + task_count++; > } Yes, but if futex_proxy_trylock_atomic() succeeds and lookup_pi_state() fails then the user space futex value is already the VPID of the top waiter and a retry will then fail the futex_proxy_trylock_atomic(). > switch (ret) { > > Also, looking at the code, I think we can use the goto retry_private > optimization for private futexes upon futex_proxy_trylock_atomic > lookup_pi_state errors: > > @@ -2290,8 +2290,11 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags, > double_unlock_hb(hb1, hb2); > hb_waiters_dec(hb2); > ret = fault_in_user_writeable(uaddr2); > - if (!ret) > + if (!ret) { > + if (!(flags & FLAGS_SHARED)) > + goto retry_private; > goto retry; > + } Yes, we can, but let me stare at that code some more. Thanks, tglx