Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4216896ybg; Fri, 25 Oct 2019 15:15:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVqDHDjC2Etaid5suPoENcDxDaYwVjB+TSKmy2/svcu5op26PnYFJq7NMsd9rASt1h24XH X-Received: by 2002:aa7:cd43:: with SMTP id v3mr6453707edw.235.1572041759725; Fri, 25 Oct 2019 15:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572041759; cv=none; d=google.com; s=arc-20160816; b=BRU2tWxptusiH7YxLQJpti26w3XojtAQPYvh1VLihLuM2QrDa/UsJ9GM8LGm8hVTUu bYih/7S6Uv/1UUz8ndSALonTVCqBo4aoCqVU6lgfQ+dlNFDR734iWze4pR3vfGIE02IV ox6M0786IG4XQHs5X+kjknivRzj/8YzqV0NeO6M4IWOwL1y1KuM3ZTIeA9uJQ41Rlqf2 sqVwxx4HpUXVOxozmVZvcg0lrOLJpPRNn85xdjlrU7tCEtnTqn0XPRL+U94Wlvvp6VYH 50Qy+JlYhKxebjYmzjxUWlkVSe8mFx/tqhHOJP7NAQ2ihurFUo+i9xLYuBM0h9AhQoC6 v4lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8Sc47oM8963qpiXK5I7HTH3chzXQNmOfoNk1YmTZRUA=; b=sGJLfRrx+cocSyBobT8i5R4y9WfmVX20O3LWt786uNPok8cn7GB0ufgoEBrkjBdMhe I4+pE1XpZL2BOp2PMz8lXpX7MLG1ABPiTvUPtzWDvEW73ejDHZNt3HekkvthBcxOuDaT Kmze+gP2MFgefw6kIBG37Cgl35bRiGuM54HuDh7aQQNsqK5vuKNgaKid/StZiLqHtCKN lGKSuTG3xjxFuKwCbyiYTy79X+DPl74R45hRLl5jwiu7tXLt2gJSkYzlAUzM2petLWMM YIVUbs40GlZyalsrZ1MywtXuYxFI6qvpfHh/RL+/E9/8qp7b+EPC64aL1M3jpmDxE20O 0J9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=DNkB25Zd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s58si2311202edm.45.2019.10.25.15.15.35; Fri, 25 Oct 2019 15:15:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=DNkB25Zd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437814AbfJYIKp (ORCPT + 99 others); Fri, 25 Oct 2019 04:10:45 -0400 Received: from merlin.infradead.org ([205.233.59.134]:35634 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437404AbfJYIKo (ORCPT ); Fri, 25 Oct 2019 04:10:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8Sc47oM8963qpiXK5I7HTH3chzXQNmOfoNk1YmTZRUA=; b=DNkB25ZdI237ISuoSpzbiyMJX kzgXrCVKjcOAlRuqiwHbmyEQYY3gQ1wGpVApWN15N06kEQnRnnAD7g8uIkmB17+VAD8HnM0n107S8 Lp0fGAfUpK4blN+BJM3WfT/d64+hKo4NmaRE5kDGTwcN+lDKFBV+ITTWCw3xVrxhzZhSS5c6GxAB/ U7hG8wi23LfzwNnudOfHNzqWsRXVyBCXOBueGJw6TzsoL3mT39Kx5eEHkn+B62XHAHlYlSKNobmoX 67RCA2wo+oWKu+6I7YTrvIY9Qxw8Wu1vwkc0uBbUc3SLaek6piFS7PoHIUPuo1ZxoTBjNGXYf4asE BCajCheyw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iNugB-0001Ql-R4; Fri, 25 Oct 2019 08:10:40 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 404503006E3; Fri, 25 Oct 2019 10:09:38 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 178B5201A6624; Fri, 25 Oct 2019 10:10:37 +0200 (CEST) Date: Fri, 25 Oct 2019 10:10:37 +0200 From: Peter Zijlstra To: Davidlohr Bueso Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH -tip] locking/mutex: Complain upon api misuse wrt interrupt context Message-ID: <20191025081037.GF4131@hirez.programming.kicks-ass.net> References: <20191025033634.3330-1-dave@stgolabs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191025033634.3330-1-dave@stgolabs.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 24, 2019 at 08:36:34PM -0700, Davidlohr Bueso wrote: > Sprinkle warning checks, under CONFIG_DEBUG_MUTEXES. While the mutex > rules and semantics are explicitly documented, this allows to expose > any abusers and robustifies the whole thing. While trylock and unlock > are non-blocking, calling from irq context is still forbidden (lock > must be within the same context as unlock). > > Signed-off-by: Davidlohr Bueso > --- > kernel/locking/mutex.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c > index 468a9b8422e3..7e9c316c646c 100644 > --- a/kernel/locking/mutex.c > +++ b/kernel/locking/mutex.c > @@ -733,6 +733,9 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne > */ > void __sched mutex_unlock(struct mutex *lock) > { > +#ifdef CONFIG_DEBUG_MUTEXES > + WARN_ON(in_interrupt()); > +#endif > #ifndef CONFIG_DEBUG_LOCK_ALLOC > if (__mutex_unlock_fast(lock)) > return; > @@ -1413,6 +1416,7 @@ int __sched mutex_trylock(struct mutex *lock) > > #ifdef CONFIG_DEBUG_MUTEXES > DEBUG_LOCKS_WARN_ON(lock->magic != lock); > + WARN_ON(in_interrupt()); > #endif > > locked = __mutex_trylock(lock); No real objection, but should not lockdep already complain about this? __mutex_unlock_slowpath() takes ->wait_lock irq-unsafe, so then using it from an IRQ should generate an insta IRQ inversion report.