Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2276985rwb; Fri, 2 Dec 2022 07:43:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7NosEcPWI6YE287a9ZdJy0H0Ob9COcbMWTk5obdGtNZIlMzqcQVGPhY+lS7iPx5lFXI7Hz X-Received: by 2002:a05:6402:2949:b0:468:fb6b:3a79 with SMTP id ed9-20020a056402294900b00468fb6b3a79mr6753211edb.63.1669995825799; Fri, 02 Dec 2022 07:43:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669995825; cv=none; d=google.com; s=arc-20160816; b=kE+ocDN2ikBXyebLQMEIumrcPI5SXdQSi85FK59PCfGsbAW1Kob9NDjnKeYCwC4eK5 7SEv8OQFydkSjnalnfm/uNsFr2PyA8IgIo2a5vIuPjLXtFquc6b9K8dnNVyugxkdlNVM gzkjMxc1J3ZQ8kVoGmLvRTMtmVCSmFCe1LO+jPa3mM9QkGoncwXzMd7Updjf3HoOUAKZ nJ8qSnyrgxK6PXpT56nZfa92gIQTvuKo9Jl7Jxn71WexFrPt8kSSvuCKw7ZdCPjIYokj ru3HBG2F4jK0NMnCRl/uMeZmYu0bSDNsgIaVXtWOofYpKML3wvc3NTSarmF4lzsB9dQj 2k2Q== 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=Nu6CiQRYcUS9dMMYsVOl3DQO/ppN3CBtOjKgdn0f3pg=; b=yBs39rYE/kMxjdYHdhXbKKbzlCpV5pPCySpLcTHJdmZi3lB1WnjLL1nwJiziUpPiGV nQ1n2B79JHOD4/bOyeQFHtBFHNh0KdjEngLEPOHgOiEwH6k0hgcgvrDzH37r2+OKjXRB X0kV0mpdWv7sAH3wLBl9sRnQlQ6oBMb7S/rE1H6JtXA9DgkdsXPYSTvRrdA0P1Iy0o5e G/Dc6UrLk2i6mw7g9wwedIX4IAa5wTsNoMS9F14XsOkdfEbGgpQO2TUUHV2lO5yK/xFe AeS4Nwr2LRLnWXbbWgarXJfBTTsCXX7Lm4rA1dgpXQP33eD+BUqPNW1e25sOPKC6Cual Y6eQ== 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 b10-20020a056402084a00b0046b1f708941si6763443edz.556.2022.12.02.07.43.25; Fri, 02 Dec 2022 07:43: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 S232741AbiLBPC1 (ORCPT + 82 others); Fri, 2 Dec 2022 10:02:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiLBPCZ (ORCPT ); Fri, 2 Dec 2022 10:02:25 -0500 Received: from outbound-smtp15.blacknight.com (outbound-smtp15.blacknight.com [46.22.139.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0910BE2543 for ; Fri, 2 Dec 2022 07:02:22 -0800 (PST) Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp15.blacknight.com (Postfix) with ESMTPS id A700E1C4395 for ; Fri, 2 Dec 2022 15:02:20 +0000 (GMT) Received: (qmail 20000 invoked from network); 2 Dec 2022 15:02:20 -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); 2 Dec 2022 15:02:20 -0000 Date: Fri, 2 Dec 2022 15:01:58 +0000 From: Mel Gorman To: Sebastian Andrzej Siewior Cc: Peter Zijlstra , Jan Kara , Thomas Gleixner , Ingo Molnar , Will Deacon , 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: <20221202150158.xzgovoy7wuic6vvk@techsingularity.net> References: <20221202100223.6mevpbl7i6x5udfd@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: 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 02, 2022 at 12:21:06PM +0100, Sebastian Andrzej Siewior wrote: > On 2022-12-02 10:02:23 [+0000], Mel Gorman wrote: > > The lock owner is updated with an IRQ-safe raw spinlock held but the > > spin_unlock does not provide acquire semantics which are needed when > > acquiring a mutex. This patch adds the necessary acquire semantics for a > > lock operation when the lock owner is updated. It successfully completed > > 10 iterations of the dbench workload while the vanilla kernel fails on > > the first iteration. > > I *think* it is > > Fixes: 700318d1d7b38 ("locking/rtmutex: Use acquire/release semantics") > Adding Davidlohr to cc. It might have made the problem worse but even then rt_mutex_set_owner was just a plain assignment and while I didn't check carefully, at a glance try_to_take_rt_mutex didn't look like it guaranteed ACQUIRE semantics. > Before that, it did cmpxchg() which should be fine. > > Regarding mark_rt_mutex_waiters(). Isn't acquire semantic required in > order for the lock-owner not perform the fastpath but go to the slowpath > instead? > Good spot, it does. While the most straight-forward solution is to use cmpxchg_acquire, I think it is overkill because it could incur back-to-back ACQUIRE operations in the event of contention. There could be a smp_wmb after the cmpxchg_relaxed but that impacts all arches and a non-paired smp_wmb is generally frowned upon. I'm thinking this on top of the patch should be sufficient even though it's a heavier operation than is necesary for ACQUIRE as well as being "not typical" according to Documentation/atomic_t.txt. Will, as this affects ARM primarily do you have any preference? 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(); } /*