Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7302406rwb; Tue, 6 Dec 2022 04:08:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf59d8OcVERkhvzVJ77YmlKuEhMFUNVlm+Mo1EdabYOlimbaP1d3/BM2P5GRyFaKtlKAK4Gh X-Received: by 2002:a05:6402:5308:b0:460:19c3:2992 with SMTP id eo8-20020a056402530800b0046019c32992mr3600345edb.1.1670328488688; Tue, 06 Dec 2022 04:08:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670328488; cv=none; d=google.com; s=arc-20160816; b=FCcGZk01fVuKXsdJeWRaRuK2Ku7lVvEXKO8/SF31+mAXwAizCqqFlucyxRr52VSQCM rfdtIS/YvKWCWs0EVOGE3cXKwy7IzFCbN64qm2/mGX4wPqYyowdPaV/aKn9z5GqjBg+1 OEc7Xy6i2KZkARhtpkkidnuLLowKz2w6+j3+HaoBxAqWe4qpdGbPCAU2wbZFwNX05mro ggrUSSPH7dSbO4OMDLYyn9n2AaDRAeL6DX8XZF+clP2x/7bB77cxbochbJs3NLlWxkZR dXANxBH+xldfG09qUkOI9CK5zPKDxEzShwSDsaMaUWsOX3SDT+XmFweHjQACYXA6oRLu gpcg== 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:dkim-signature :dkim-signature:date; bh=dP3T+S+aLmRfAy6FLnk9bCE+dI1DE5HTxIK16+BuHp0=; b=tENxff1EkwZqdmsBcljV1d35Di9DP5uahooj8GIXkaSOice7BiOiOCdqNriV6Knvay iM5dOR7+DD/30+oDUu+5o5N1FgFgshyX/NYN4A8BMqyOhsG+WjuhTh9feoCGBuWFMMBc q15GCdZf/X/fxbmKwzyZRlDRr8kS5PWpVKmVAytf5iA/Anmd5DzOhDLL+jp6VANDcia+ /6rJ93Z1b7ep1ZfOsrDA9Zg8OKzQOp2tDGi/QoGmrH52QyNBpkRXPbE+5LtLhKypSncI gzt1DiumHTqOVVRRz9zpHsgPfYYe431V7m+ur3RQHKuPAEYBkSoUgMd+dReoxRynTGV9 Rn8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KO6aodTS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=NuBk0oK6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa37-20020a17090786a500b007839bfdaa33si14842897ejc.358.2022.12.06.04.07.46; Tue, 06 Dec 2022 04:08:08 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KO6aodTS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=NuBk0oK6; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233661AbiLFLoA (ORCPT + 79 others); Tue, 6 Dec 2022 06:44:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233558AbiLFLn5 (ORCPT ); Tue, 6 Dec 2022 06:43:57 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C83B31A059; Tue, 6 Dec 2022 03:43:55 -0800 (PST) Date: Tue, 6 Dec 2022 12:43:51 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1670327033; 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=dP3T+S+aLmRfAy6FLnk9bCE+dI1DE5HTxIK16+BuHp0=; b=KO6aodTSgzOwrYYtTO48XmeW2iNKdfmTYbr1ZTrG2imhbkW8yPwvMjA21vskt6kPpF3M4b WUzAbcQDU5IET7jdvNvcSGdV7D2X0Yoa589vcm7OUOsX/avotCPcdALxbaW9FVUrYAi0Z9 6ADDkNMuvfFzAK1YJ5Au7neac2AZJhIMw86y51QtZhzyV9scd3UJO3E+cn7QaHzQKd+iTf FX6nK61LWXVMCUsb/LrqjluyIgW3HteMCVS1lqxTuUHDQ7GTS/gfQxIX2aiaKEoHN+fjET TjOCpE7TMTDNNQMGS5Ir4qNCFv8KcWN10J48Dr9paPON7uWivsMMoxUUH6bwVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1670327033; 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=dP3T+S+aLmRfAy6FLnk9bCE+dI1DE5HTxIK16+BuHp0=; b=NuBk0oK6E6MphaE5QCnN+ImHu3blbgMg/uf4RsDV8/pkJRWFRPfNgS2UAbAW14XMIl+vAG PTMeY1t/2E+p6SAg== From: Sebastian Andrzej Siewior To: Mel Gorman 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: References: <20221202100223.6mevpbl7i6x5udfd@techsingularity.net> <20221202150158.xzgovoy7wuic6vvk@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221202150158.xzgovoy7wuic6vvk@techsingularity.net> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 2022-12-02 15:01:58 [+0000], Mel Gorman wrote: > > 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. It looks like it had a strong cmpxchg which was relaxed. But I might be wrong ;) Either way we need stable tag so that this gets back ported. The commit in question is since v4.4 and stable trees are maintained down to 4.9 (but only until JAN so we should hurry ;)). > > 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. but in general, it should succeed on the first iteration. It can only fail (and retry) if the owner was able to unlock it first. A second locker will spin on the wait_lock so. > 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(); > } Sebastian