Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp247875pxb; Mon, 13 Sep 2021 18:17:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKFDTQF0ZfQcumhpZUx1YUZnCvua5E27yCybpfaYTPJweOBLRBgUJyCAYnuXVG4v4HS0xP X-Received: by 2002:aa7:c3cb:: with SMTP id l11mr16430539edr.310.1631582264551; Mon, 13 Sep 2021 18:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631582264; cv=none; d=google.com; s=arc-20160816; b=qRp0w0LjPGFgTdEt7cFrLGnZC8F514yJQvKtnJN/xo2fYMr7jomb0Trrw1Jb//ff4r /fGqLCCfE34iAB5A5KVitYejuhCzSS/7rtppuyyQ/XWP9/lySp1jTzR5OXLs1XXiXvjk mrq5DFe+WKOAgW0Dro/4nY4yNPviLhihvXoz70cXti+LGmLaS5gVijXWapQYSWIcp7Qr /VfKmzyzdDwvCgLihcJ6KFXemo5545nY54o0wKmEDOtW2gU0Cn169/iuM8qI1RplWUdR LKHfsr16impjvWFXVDhfleUOrI3cQyVUPkH7PXkOfRHtEOVCVUldN4UJKvMzn7RJt6Ds zclg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=UIFUULZXQDg7+U+CZahOjC36byrqbcllUTVbW2ndRTI=; b=flUqY/L08u4m9pt+fFc5mVOY+RDqfyN4b/jQieMe559yFk8FNaucFd/cqK7bcFkMeH g9PHwIFQHb+xMwbChMaAvVWUX8iOkZZsEbiWf1Oyns1l6EKApSo7QMgZ0J6rqkJQOgLF jqMiNKyOQSHx1lOYuMTkQZhvmw2XojH1QuDYtLusFToBrC//q33FkS8RJW5Xp6k978zf FqikUUBCZHXGzHjlI+pCSPzg7Se26tK1i+TpX5nlSNzR1YHiz29jgzMlf8O6lX2lyjlc 0wGv78e+U9UtvPTIAbk6cU0dl7jmRvuN8XGA4cmgN1Ob0Ga5DULH4orawctCn7tv4YMq elww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oobnOPnv; dkim=neutral (no key) header.i=@linutronix.de header.b=QmsCXBvq; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s23si8094485ejj.684.2021.09.13.18.17.21; Mon, 13 Sep 2021 18:17:44 -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=@linutronix.de header.s=2020 header.b=oobnOPnv; dkim=neutral (no key) header.i=@linutronix.de header.b=QmsCXBvq; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244184AbhIMWJt (ORCPT + 99 others); Mon, 13 Sep 2021 18:09:49 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:57176 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235948AbhIMWJs (ORCPT ); Mon, 13 Sep 2021 18:09:48 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1631570911; 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=UIFUULZXQDg7+U+CZahOjC36byrqbcllUTVbW2ndRTI=; b=oobnOPnv/ggcqFhOGebZ9ySpZq+NIwxYkAiXEFvvJdj7DfcY5kccC7NrbYxg5lMTx1LkSU 5l+86n9pmRp9MzWFh7kCXymBuCDafS89r5Lx+9k/YH8MUEcZIQ09fd/CKJUzpRAkiLNdKZ IUgXcPDc15T40ygrnkbVCNyu3LjOAeKST8PtOgw06tAlNmITuEWza02cX6OzTN8dqhM4PT 2hNSLvebcAcZFsjjgjlZYjoeuvQasqGxa/hmCSWpm33ubukH00Xb9civpoaC8i7hbueUBZ a0FqELq6ZY/5kT7Jm2+pHusWsWlxaC4uy9WR4aQtn93yygzvtexEJMyBOLGt7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1631570911; 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=UIFUULZXQDg7+U+CZahOjC36byrqbcllUTVbW2ndRTI=; b=QmsCXBvqYyPbrTlY/BjmSoIMCMv/ifqWhO3if8hnHHMFXy91oJaqHeVQFBAf1QFdzhzLmg qSNxJs7/1M+mVPBw== To: Peter Zijlstra , boqun.feng@gmail.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, Ingo Molnar , Juri Lelli , Steven Rostedt , Davidlohr Bueso , Will Deacon , 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() In-Reply-To: <20210909110203.767330253@infradead.org> References: <20210909105915.757320973@infradead.org> <20210909110203.767330253@infradead.org> Date: Tue, 14 Sep 2021 00:08:30 +0200 Message-ID: <871r5sf7s1.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 09 2021 at 12:59, 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). I don't think so because both the state store and the wakeup are serialized via tsk->pi_lock. > While there, make them consistent with the IRQ usage in > set_special_state(). > > Fixes: 5f220be21418 ("sched/wakeup: Prepare for RT sleeping spin/rwlocks") > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/sched.h | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) > > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -245,7 +245,8 @@ struct task_group; > * if (try_lock()) > * break; > * raw_spin_unlock_irq(&lock->wait_lock); > - * schedule_rtlock(); > + * if (!cond) > + * schedule_rtlock(); cond is not really relevant here. > * raw_spin_lock_irq(&lock->wait_lock); > * set_current_state(TASK_RTLOCK_WAIT); > * } > @@ -253,22 +254,24 @@ struct task_group; > */ > #define current_save_and_set_rtlock_wait_state() \ > do { \ > - lockdep_assert_irqs_disabled(); \ > - raw_spin_lock(¤t->pi_lock); \ > + unsigned long flags; /* may shadow */ \ > + \ > + raw_spin_lock_irqsave(¤t->pi_lock, flags); \ Why? This is solely for the rtlock use case which invokes this with interrupts disabled. So why do we need that irqsave() overhead here? > current->saved_state = current->__state; \ > debug_rtlock_wait_set_state(); \ > - WRITE_ONCE(current->__state, TASK_RTLOCK_WAIT); \ > - raw_spin_unlock(¤t->pi_lock); \ > + smp_store_mb(current->__state, TASK_RTLOCK_WAIT); \ The try_lock() does not matter at all here, really. All what matters is that the unlocker cannot observe the wrong state and that's fully serialized via tsk::pi_lock. Thanks, tglx