From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8312C4338F for ; Sun, 8 Aug 2021 17:05:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF2D860EE7 for ; Sun, 8 Aug 2021 17:05:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbhHHRGD (ORCPT ); Sun, 8 Aug 2021 13:06:03 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:37856 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbhHHRGC (ORCPT ); Sun, 8 Aug 2021 13:06:02 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4C7261FFE9; Sun, 8 Aug 2021 17:05:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6BC1B13398; Sun, 8 Aug 2021 17:05:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IT3FB+MOEGH8DQAAMHmgww (envelope-from ); Sun, 08 Aug 2021 17:05:39 +0000 Date: Sun, 8 Aug 2021 10:05:35 -0700 From: Davidlohr Bueso To: Thomas Gleixner 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 Message-ID: <20210808170535.kotqd5t677tijh4o@offworld> References: <20210805151300.330412127@linutronix.de> <20210805153956.051961951@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210805153956.051961951@linutronix.de> User-Agent: NeoMutt/20201120 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++; } 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; + } return ret; case -EBUSY: case -EAGAIN: Thanks, Davidlohr