Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2747217rwb; Fri, 16 Dec 2022 06:07:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7viTs5XjYw2UgIWiGCYS0nFuT+DADN+BKUJybVbOP2eCN+D+cuKfKt3PqSXxFQZ6csB3nu X-Received: by 2002:a05:6402:2986:b0:463:c2f9:8a0a with SMTP id eq6-20020a056402298600b00463c2f98a0amr26250460edb.33.1671199665779; Fri, 16 Dec 2022 06:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671199665; cv=none; d=google.com; s=arc-20160816; b=lgaO5QZv+WTo0lQHN20rK/NEjQIgudRkOU8gKYthxT1LShZDMMLD79KK1zVzO8BZ6D Banz6Pnb7qBpzs4S8uq66U4KWOUDPTh26WtpjiGLV7mYR2Lpx0FTJbE5Y26o67MWLsZ8 n6wDRfBCzs/2yY0QAlMeMYv0iwYLEoFnPI5AXdl9qCHGnX72/AZCOm3rI7qz6MVM4Gev 3E1y5JXlvpUBBC8Di2YWH6u1H7tusujdQvTAq7weiZBGmGG8J47jNdjcc0uahfxrYgdV WAMypElOVMBaYgQuF2ZbLG7P3ycnVq1J/qJ9P2uNNpqFbVl2fNf+HW4d10NPogCOclPK xxvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=c968LIkPtRAcAWr7KW3RR1IEeTWZ/jbDsawIYan75rg=; b=ruEW9fiTOJcm9wd53cXSWWxZ4x+YLoDvCRgueUzF7G9Awq2Yz6x4rtd7dWu/POLIVI x5V1MHn2uTDNmCn83qqfH6dU1dW4yZZrTc9tOwmV0kp2xOSlv492PAe9zxhYv58U3/Ni sYArxwTW2piV1kSE1pzSFu8Fy6uE6meZfCDV/YumuTXfUxWa2ILhkpmUzW9k/4XV8BZM gSGwrLKssBnbwNLdeYILZvjzN4C5zI27MLXlD7Qf9+l6OR+JPGUKQj8l4Uii2PbA197s ylOs3Uoi9LaPvVFh64JG2/6MDVcPGZEmflrpVktrP3khYpYJ0rSRRX/vgRWAs1qNgVBP J9Xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020aa7dac1000000b0046bef95b2e6si2108276eds.492.2022.12.16.06.07.28; Fri, 16 Dec 2022 06:07:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbiLPNz7 (ORCPT + 68 others); Fri, 16 Dec 2022 08:55:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiLPNz5 (ORCPT ); Fri, 16 Dec 2022 08:55:57 -0500 Received: from outbound-smtp10.blacknight.com (outbound-smtp10.blacknight.com [46.22.139.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AC491145B for ; Fri, 16 Dec 2022 05:55:54 -0800 (PST) Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp10.blacknight.com (Postfix) with ESMTPS id 4E9921C3C1E for ; Fri, 16 Dec 2022 13:55:53 +0000 (GMT) Received: (qmail 25094 invoked from network); 16 Dec 2022 13:55:53 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 16 Dec 2022 13:55:52 -0000 Date: Fri, 16 Dec 2022 13:55:48 +0000 From: Mel Gorman To: Will Deacon Cc: Sebastian Andrzej Siewior , Peter Zijlstra , Jan Kara , Thomas Gleixner , Ingo Molnar , Waiman Long , Boqun Feng , Pierre Gondois , Steven Rostedt , Catalin Marinas , Davidlohr Bueso , LKML , Linux-RT Subject: Re: [PATCH] rtmutex: Add acquire semantics for rtmutex lock acquisition Message-ID: <20221216135548.itw2xrqbvuldk35y@techsingularity.net> References: <20221202100223.6mevpbl7i6x5udfd@techsingularity.net> <20221202150158.xzgovoy7wuic6vvk@techsingularity.net> <20221216111412.GA8666@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20221216111412.GA8666@willie-the-truck> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 16, 2022 at 11:14:12AM +0000, Will Deacon wrote: > > diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c > > index 35212f260148..af0dbe4d5e97 100644 > > --- a/kernel/locking/rtmutex.c > > +++ b/kernel/locking/rtmutex.c > > @@ -238,6 +238,13 @@ static __always_inline void mark_rt_mutex_waiters(struct rt_mutex_base *lock) > > owner = *p; > > } while (cmpxchg_relaxed(p, owner, > > owner | RT_MUTEX_HAS_WAITERS) != owner); > > + > > + /* > > + * The cmpxchg loop above is relaxed to avoid back-to-back ACQUIRE > > + * operations in the event of contention. Ensure the successful > > + * cmpxchg is visible. > > + */ > > + smp_mb__after_atomic(); > > Could we use smp_acquire__after_ctrl_dep() instead? > It's might be sufficient but it's not as obviously correct. It lacks an obvious pairing that is definitely correct but the control dependency combined with the smp_acquire__after_ctrl_dep *should* be sufficient against the lock fast path based on the available documentation. However, I was unable to convince myself that this is definitely correct on all CPUs. Given that arm64 was trivial to crash on PREEMPT_RT before the patch (hackbench pipes also triggers the same problem), I'm reluctant to try and be too clever particularly as I didn't have a reproducer for a problem in this specific path. If someone can demonstrate a reasonable case where smp_mb__after_atomic() is too heavy and document that it can be safely relaxed then great. At least if that relaxing is wrong, there will be a bisection point between the fix and the reintroduction of damage. -- Mel Gorman SUSE Labs