Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp544350pxb; Thu, 9 Sep 2021 06:49:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOq2vtQmBHJlmBpAhn8gjcOqxg8zaHqyrdJ9S3LY8/9nlV5dpDe5jSoXtdTkmUPT6bLan0 X-Received: by 2002:a05:6e02:1d88:: with SMTP id h8mr2364836ila.258.1631195392711; Thu, 09 Sep 2021 06:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631195392; cv=none; d=google.com; s=arc-20160816; b=J97jkx58kGuNZW8DuEBGuG12uXO9JVKBzeVACSZ1wtX/YYOtG30hPqhk1yG8Jh2hkm Kfem0r/NpmLHxNQADhMjSj628t5pqd9g5T8613CDRyPd8ne2B8rMvWxBAnUBzjTDW3gk u6XAyI03TMxfrghwQiXQNKrquZ2NFIdfeL18+l7Pl1f8rDoHWlNLHB/+wBnOfsbtP6mz CAmOHr0CR2rOCM/04TrrHKf7cuQ28dxJp5Zza4U03j9cOkcGTuZL5IPIT103578c6PfG +npeFwiYOqxZMFhBilDRxLn7kKMfDTuwIB3ZdsYAHZx+4cf5POIkzEqYkYjwtbqv9I2o oKpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=r/2pGUVyq++7NhMYrtNDR+rm/QTpABrdNOr1CKqfQxg=; b=PxCvNsgAj11krm9XzLj5dqGUt8JPp1/cP2wi3//I47cgJ6O5TlD+OcFDIHQo4XkA+E CtLHrQ64C2RMwKFjR1ZD3jeYS4vbLEvMJRDSO2M1XJeipCSu/rifQIVCibOUd69/tQY3 pQqne81pa+as1cI+5m4FLb4q9YBea4DS1tLc8r7uvGkCAyc0dL5YNQsFmAL+uMF0mYPS V1a+e2lrA/2w2Sm2LzcvsmrGB58moUJ3wAsTEusGXpkI1OixGPAWmPH6T23MYWHUJYQJ i2T8nr06D5ikEH/otLt2XeMnNJ4R5As5p3ue7Ih1bj1XwZtssc4C8TwhRlcnccLy+tqf 12sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kKOuhJJU; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si1892122jat.11.2021.09.09.06.49.39; Thu, 09 Sep 2021 06:49:52 -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=@kernel.org header.s=k20201202 header.b=kKOuhJJU; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357599AbhIINsq (ORCPT + 99 others); Thu, 9 Sep 2021 09:48:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:60526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358095AbhIINqj (ORCPT ); Thu, 9 Sep 2021 09:46:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 18BAB6120E; Thu, 9 Sep 2021 13:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631195130; bh=Pzye3sEvQsiMMe8AQ4zppyqO9pYnFlQgLwp86cyCJJY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kKOuhJJUCW0KfdmlP3stdZxZge+g95zJfm++qFLvKTwZINw3q5hi3jn1rkKPbveeI iAsQEXgYfUrxCFJlVi+3He1LditPPNT2HoZWH8KGpFSujPPv0DbJPb9z6wY9drtw+w S8qz8vLnuxI99Siy1ltpfDV1J8W81duYq92ljIxgarfGu02aQh1GRH6mVgeK9qsx3X yPphuSlcNdPffYKPB8Jov9XJR7wsUa0GpFwHeh5rMjlGPkmZpcHGDjmugcp7JwbpDm 8QAIKSzIToW0FWf8EPQZr2nxm6DWTSsg6Y/+E5i3xjrGDyWFBU2/0ne50bmcl98VGu oknCAtKD6Mk0w== Date: Thu, 9 Sep 2021 14:45:24 +0100 From: Will Deacon To: Peter Zijlstra Cc: tglx@linutronix.de, boqun.feng@gmail.com, linux-kernel@vger.kernel.org, Ingo Molnar , Juri Lelli , Steven Rostedt , Davidlohr Bueso , Waiman Long , Sebastian Andrzej Siewior , Mike Galbraith , Daniel Bristot de Oliveira Subject: Re: [PATCH 1/4] sched/wakeup: Strengthen current_save_and_set_rtlock_wait_state() Message-ID: <20210909134524.GB9722@willie-the-truck> References: <20210909105915.757320973@infradead.org> <20210909110203.767330253@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210909110203.767330253@infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 09, 2021 at 12:59:16PM +0200, Peter Zijlstra wrote: > While looking at current_save_and_set_rtlock_wait_state() I'm thinking > it really ought to use smp_store_mb(), because something like: > > current_save_and_set_rtlock_wait_state(); > for (;;) { > if (try_lock()) > break; > > raw_spin_unlock_irq(&lock->wait_lock); > schedule(); > raw_spin_lock_irq(&lock->wait_lock); > > set_current_state(TASK_RTLOCK_WAIT); > } > current_restore_rtlock_saved_state(); > > which is the advertised usage in the comment, is actually broken, > since trylock() will only need a load-acquire in general and that > could be re-ordered against the state store, which could lead to a > missed wakeup -> BAD (tm). Why doesn't the UNLOCK of pi_lock in current_save_and_set_rtlock_wait_state() order the state change before the successful try_lock? I'm just struggling to envisage how this actually goes wrong. Will