Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2819386imm; Mon, 10 Sep 2018 07:00:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbccbw0749mpAFSXKrNDr6+tBsKYEqVomiIG872xwsbUACV5LJVF8y3ZmrQpqKfNcYidPvF X-Received: by 2002:a17:902:bd44:: with SMTP id b4-v6mr22111561plx.144.1536588038385; Mon, 10 Sep 2018 07:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536588038; cv=none; d=google.com; s=arc-20160816; b=z8TAyhaNMajDnoHM84WyNpFGXKuaN5/uL01g41HxbXXobeFtDMChqNMLbwhNi4Rcnj 2i7cblrjQ3U1+KNkHaUeBxeXjZy36jkXNUCFI4UX2ozWHN/RjiVNFPcjaimvwM23Maal eL0KitRLBUthY7HbtH8KTGdvelHF6/ibjy8BNZ3I4qIU3Q+yxKKOKnBB+6fOkECvSv0q 5y8HXiCe2ialiCo78tdFLyNeqRev/PI9dR22lBNPtzSltD5UQSJ4BK1xzVGhFmuVCzxl XlVKRnazioX3+sPJdClk3rBTsEPlr9qefNsUCyEZyf2ovKh4DfIzRL8Ifv/oMgDG6gUV 2bLA== 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=EUbYCfEDCsJGsk9vZGqMRilQSFrjcI3at2vjd9xn8mM=; b=udVNzfiUhC0/uNKJ3hrtplF2JU5mRXT3PtPVsC0vKgtRsf310Tr3nElqcWjVJogMxM L2J7yJ/l8XA7qoit850hnQFksHS2ySLS/DVx8KpNnOqXtkG2pJXGYqVyxz/wblDH2zKy fZJGCTv3JC6tphWl5joPsaeJMEwj2h94tPThWnxLggEPfist4YeVzl/oS1sbIOIYiG7M UO7tRSU0fQRCJHmVecvQmv3zl827lf9IcBot4NtSm3jPTppCEA904j++iqswz+RxM9FE MaW3vgP0F+H7U1v/HbBA8F5lYeoK3idQbNXmNGg5SomJ3DxcDOkNLoijOfp1P/jzjYgm seog== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="mjKkxC/A"; 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 l7-v6si17610997pgi.261.2018.09.10.07.00.21; Mon, 10 Sep 2018 07:00:38 -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=bombadil.20170209 header.b="mjKkxC/A"; 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 S1728848AbeIJSuy (ORCPT + 99 others); Mon, 10 Sep 2018 14:50:54 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:34256 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeIJSuy (ORCPT ); Mon, 10 Sep 2018 14:50:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=EUbYCfEDCsJGsk9vZGqMRilQSFrjcI3at2vjd9xn8mM=; b=mjKkxC/APFY0vVUMBI2NZdmdW /xGnghsHWPPtiwEz2hxoCZIQP/gnsUtG/FtwvYsACPhQUJ+lSgLNNA17DYxEMCsnW4fIXCJ+7QZEu X53vic0H6XaWCEV53HisdDkMgmylymWa3+IZ+kqMxMeXr4fTXWpy6V/JlivJ0UGkZBjXjZL+mm6nP NVDcDS0QtXKBSPZF0Zw+8zSa2DdrLm9P8b98cm3VDSe784lYASQVT4ZvIRZJ73fHoX/16ZkQH62cn hAaxc5Fj5oQR+up7u1weGGpzL/U0qqmkcKlkjU2kALAe4EsBrYF6Ed7VKHYI5O69/IfZrMqK8QIrW RAZc230XQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fzMg2-0000MD-QP; Mon, 10 Sep 2018 13:56:31 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B3C25202C1A02; Mon, 10 Sep 2018 15:56:27 +0200 (CEST) Date: Mon, 10 Sep 2018 15:56:27 +0200 From: Peter Zijlstra To: Jia-Ju Bai Cc: mingo@redhat.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, Thomas Gleixner , Steven Rostedt Subject: Re: [PATCH V2] kernel: locking: rtmutex: Fix a possible sleep-in-atomic-context bug in rt_mutex_handle_deadlock() Message-ID: <20180910135627.GL24106@hirez.programming.kicks-ass.net> References: <20180811030037.14885-1-baijiaju1990@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180811030037.14885-1-baijiaju1990@gmail.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 11, 2018 at 11:00:37AM +0800, Jia-Ju Bai wrote: You forgot to Cc the person who wrote this code... > kernel/locking/rtmutex.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c > index 2823d4163a37..8f25a289abe8 100644 > --- a/kernel/locking/rtmutex.c > +++ b/kernel/locking/rtmutex.c > @@ -1205,7 +1205,7 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state, > } > > static void rt_mutex_handle_deadlock(int res, int detect_deadlock, > - struct rt_mutex_waiter *w) > + struct rt_mutex_waiter *w, struct rt_mutex *lock) > { > /* > * If the result is not -EDEADLOCK or the caller requested > @@ -1218,6 +1218,8 @@ static void rt_mutex_handle_deadlock(int res, int detect_deadlock, > * Yell lowdly and stop the task right here. > */ > rt_mutex_print_deadlock(w); > + /* We're not going anywhere, release the wait_lock */ > + raw_spin_unlock_irq(&lock->wait_lock); > while (1) { > set_current_state(TASK_INTERRUPTIBLE); > schedule(); > @@ -1269,7 +1271,7 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state, > if (unlikely(ret)) { > __set_current_state(TASK_RUNNING); > remove_waiter(lock, &waiter); > - rt_mutex_handle_deadlock(ret, chwalk, &waiter); > + rt_mutex_handle_deadlock(ret, chwalk, &waiter, lock); > } The patch is correct; but I can't find myself liking it very much. This dinly little single use function is growing a lot of arguments. The alternative is something like the below; not sure myself though. Thomas? diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 2823d4163a37..a44d4034e232 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1204,18 +1204,10 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state, return ret; } -static void rt_mutex_handle_deadlock(int res, int detect_deadlock, - struct rt_mutex_waiter *w) +static void rt_mutex_handle_deadlock(struct rt_mutex_waiter *w) { /* - * If the result is not -EDEADLOCK or the caller requested - * deadlock detection, nothing to do here. - */ - if (res != -EDEADLOCK || detect_deadlock) - return; - - /* - * Yell lowdly and stop the task right here. + * Yell loudly and stop the task right here. */ rt_mutex_print_deadlock(w); while (1) { @@ -1269,7 +1261,10 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state, if (unlikely(ret)) { __set_current_state(TASK_RUNNING); remove_waiter(lock, &waiter); - rt_mutex_handle_deadlock(ret, chwalk, &waiter); + if (chwalk == RT_MUTEX_MIN_CHAINWALK && ret == -EDEADLOCK) { + raw_spin_unlock_irqrestore(&lock->wait_lock, flags); + rt_mutex_handle_deadlock(&waiter); + } } /*