Message ID | 20240105060456.15331-1-xuewen.yan@unisoc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-17498-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6046999dyb; Thu, 4 Jan 2024 22:06:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRqInped6vEbm3QRbTbCgeZhACEAsH0Yr4Dho+Qll2oUG97/mX3d8UML+QpFZuIxw/cmFk X-Received: by 2002:a17:906:ef0a:b0:a28:67a9:eec8 with SMTP id f10-20020a170906ef0a00b00a2867a9eec8mr976746ejs.93.1704434802786; Thu, 04 Jan 2024 22:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704434802; cv=none; d=google.com; s=arc-20160816; b=J0FzrwtXICfHYW296RLrZOgHwT9A3w2BEtrSzLMwrI/Cp9i8h53exlK+bdTwZFGGQg 5Ko8s6x29seCu6VMQFZmEd5KA9PRg6YW+/IsbBkaGY3wCKipVA2nq943iitDcIYTAa8D PmTSmftlX2ZAG2GQyUAK0ryQB2rRRiJ9xmt1E5PsmkNPcd/PC1jEK3X873JpdOGDUA9M Ft+obHJKOVXwtC/g1AO9SwOyovb2GoxoJSkZHVSqC+HRa4F7Uj0J632TmnclmORtNO6Y XFOF844l9Bc3DzMGZ8F7iTEGGbMGb9Oz+vMYgrnGcx8UVtXN4aq3WYMpo7uJPFc1xwuS A2Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=WdkFKCRbyK0g3vjxPFtUnW8TRCKNxZu/fajrS3Vsaq8=; fh=6TEuBn3xHBmm9CO09z8Oulz2ZYn5AJtkDIzfzYoQFK0=; b=MeLWyLlZciSmJIFH/6JyaWbzyN4yQy4iiwSbb6NcodrFSbaBleUEw7uL13BJlEK2rX LcmD30miENrfrPqFs5EVZq/afWxYblE+S2sFoTczQ0YYHahJ2kkidHwkNuqKj0ML4UWR pjMR/rvmzRwi2ne3GQ09ihxr400gj8FIpJyO0xEq3AUm9DJLfcjKEvj0W+vTClH8CJXS 8WVQ+f80hcqRODX5TfuRtoVR3g4uRnn3pRq+KOUo0Fm58Nsti3NJKbZUqe+WvdCow8rh B4bojfg/9YOJOoobtd5EsqRiN1WKViXXBo9HALDWXy0AENx75M+GmGbg6ihJ2p9VkDUI LW2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17498-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17498-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gh38-20020a1709073c2600b00a2934eecdcesi247157ejc.425.2024.01.04.22.06.42 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 22:06:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17498-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17498-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17498-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 675B71F22E32 for <ouuuleilei@gmail.com>; Fri, 5 Jan 2024 06:06:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F198FC8C6; Fri, 5 Jan 2024 06:06:23 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09D775662 for <linux-kernel@vger.kernel.org>; Fri, 5 Jan 2024 06:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 40565A0p056912; Fri, 5 Jan 2024 14:05:10 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4T5t6m0M9xz2NZjcg; Fri, 5 Jan 2024 13:58:24 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.73) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 5 Jan 2024 14:05:07 +0800 From: Xuewen Yan <xuewen.yan@unisoc.com> To: <peterz@infradead.org>, <mingo@redhat.com>, <will@kernel.org>, <boqun.feng@gmail.com> CC: <longman@redhat.com>, <zhiguo.niu@unisoc.com>, <ke.wang@unisoc.com>, <linux-kernel@vger.kernel.org> Subject: [PATCH v2] lockdep: Add missing graph_unlock in check_prev_add Date: Fri, 5 Jan 2024 14:04:56 +0800 Message-ID: <20240105060456.15331-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 40565A0p056912 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787229427891399327 X-GMAIL-MSGID: 1787229427891399327 |
Series |
[v2] lockdep: Add missing graph_unlock in check_prev_add
|
|
Commit Message
Xuewen Yan
Jan. 5, 2024, 6:04 a.m. UTC
The check_prev_add() is held graph_lock, and it should unlock the graph_lock before return 0. But there is one condition where it will return 0 without unlock, that is: /* <prev> is not found in <next>::locks_before */ return 0; So add graph_unlock before return 0. Fixes: 3454a36d6a39 ("lockdep: Introduce lock_list::dep") Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> --- Change in V2: -move the graph_unlock to check_prev_add from validate_chain(Boqun) -Add fix tag --- --- kernel/locking/lockdep.c | 1 + 1 file changed, 1 insertion(+)
Comments
On 1/5/24 01:04, Xuewen Yan wrote: > The check_prev_add() is held graph_lock, and it should unlock > the graph_lock before return 0. > But there is one condition where it will return 0 without unlock, > that is: > > /* <prev> is not found in <next>::locks_before */ > return 0; > > So add graph_unlock before return 0. > > Fixes: 3454a36d6a39 ("lockdep: Introduce lock_list::dep") > Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com> > Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> > --- > Change in V2: > -move the graph_unlock to check_prev_add from validate_chain(Boqun) > -Add fix tag > --- > --- > kernel/locking/lockdep.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index 151bd3de5936..c8602a251bec 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -3178,6 +3178,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, > } > > /* <prev> is not found in <next>::locks_before */ > + graph_unlock(); > return 0; > } > } There are multiple places in check_prev_add() that will return 0. It will be odd to have just one of them has a graph_unlock(). It makes the code hard to understand. You should insert graph_unlock() in a place that matches the other places where graph_unlock() will be called. My suggestion is as follows: diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 151bd3de5936..d9f2df36332c 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3252,7 +3252,7 @@ check_prevs_add(struct task_struct *curr, struct held_loc> if (hlock->check) { int ret = check_prev_add(curr, hlock, next, distance, &> if (!ret) - return 0; + goto out_bug; /* * Stop after the first non-trylock entry, It looks like this bug was first introduced by commit 910b1b2e6d ("[PATCH] lockdep: internal locking fixes"). So you may also add a fixes tag. Cheers, Longman
Hi Waiman On Tue, Jan 9, 2024 at 11:51 AM Waiman Long <longman@redhat.com> wrote: > > On 1/5/24 01:04, Xuewen Yan wrote: > > The check_prev_add() is held graph_lock, and it should unlock > > the graph_lock before return 0. > > But there is one condition where it will return 0 without unlock, > > that is: > > > > /* <prev> is not found in <next>::locks_before */ > > return 0; > > > > So add graph_unlock before return 0. > > > > Fixes: 3454a36d6a39 ("lockdep: Introduce lock_list::dep") > > Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com> > > Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> > > --- > > Change in V2: > > -move the graph_unlock to check_prev_add from validate_chain(Boqun) > > -Add fix tag > > --- > > --- > > kernel/locking/lockdep.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > > index 151bd3de5936..c8602a251bec 100644 > > --- a/kernel/locking/lockdep.c > > +++ b/kernel/locking/lockdep.c > > @@ -3178,6 +3178,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, > > } > > > > /* <prev> is not found in <next>::locks_before */ > > + graph_unlock(); > > return 0; > > } > > } > > There are multiple places in check_prev_add() that will return 0. It > will be odd to have just one of them has a graph_unlock(). It makes the > code hard to understand. You should insert graph_unlock() in a place > that matches the other places where graph_unlock() will be called. My > suggestion is as follows: > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index 151bd3de5936..d9f2df36332c 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -3252,7 +3252,7 @@ check_prevs_add(struct task_struct *curr, struct > held_loc> > if (hlock->check) { > int ret = check_prev_add(curr, hlock, next, > distance, &> > if (!ret) > - return 0; > + goto out_bug; > > /* > * Stop after the first non-trylock entry, > As you say, there are multiple places in check_prev_add() that will return 0, and some cases had unlocked the lock, if all goto the out_bug, would it cause double unlock? Maybe as follows? --- diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 151bd3de5936..8b665ba90ad0 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3178,7 +3178,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, } /* <prev> is not found in <next>::locks_before */ - return 0; + goto list_err; } } @@ -3215,6 +3215,11 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, return 0; return 2; + +list_err: + /* still get graph_lock, unlock it before return*/ + graph_unlock(); + return 0; } Thanks! --- BRs xuewen > It looks like this bug was first introduced by commit 910b1b2e6d > ("[PATCH] lockdep: internal locking fixes"). So you may also add a fixes > tag. > > Cheers, > Longman > >
On 1/9/24 00:11, Xuewen Yan wrote: > Hi Waiman > > > On Tue, Jan 9, 2024 at 11:51 AM Waiman Long <longman@redhat.com> wrote: >> On 1/5/24 01:04, Xuewen Yan wrote: >>> The check_prev_add() is held graph_lock, and it should unlock >>> the graph_lock before return 0. >>> But there is one condition where it will return 0 without unlock, >>> that is: >>> >>> /* <prev> is not found in <next>::locks_before */ >>> return 0; >>> >>> So add graph_unlock before return 0. >>> >>> Fixes: 3454a36d6a39 ("lockdep: Introduce lock_list::dep") >>> Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com> >>> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> >>> --- >>> Change in V2: >>> -move the graph_unlock to check_prev_add from validate_chain(Boqun) >>> -Add fix tag >>> --- >>> --- >>> kernel/locking/lockdep.c | 1 + >>> 1 file changed, 1 insertion(+) >>> >>> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c >>> index 151bd3de5936..c8602a251bec 100644 >>> --- a/kernel/locking/lockdep.c >>> +++ b/kernel/locking/lockdep.c >>> @@ -3178,6 +3178,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, >>> } >>> >>> /* <prev> is not found in <next>::locks_before */ >>> + graph_unlock(); >>> return 0; >>> } >>> } >> There are multiple places in check_prev_add() that will return 0. It >> will be odd to have just one of them has a graph_unlock(). It makes the >> code hard to understand. You should insert graph_unlock() in a place >> that matches the other places where graph_unlock() will be called. My >> suggestion is as follows: >> >> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c >> index 151bd3de5936..d9f2df36332c 100644 >> --- a/kernel/locking/lockdep.c >> +++ b/kernel/locking/lockdep.c >> @@ -3252,7 +3252,7 @@ check_prevs_add(struct task_struct *curr, struct >> held_loc> >> if (hlock->check) { >> int ret = check_prev_add(curr, hlock, next, >> distance, &> >> if (!ret) >> - return 0; >> + goto out_bug; >> >> /* >> * Stop after the first non-trylock entry, >> > As you say, there are multiple places in check_prev_add() that will > return 0, and some cases had unlocked the lock, if all goto the > out_bug, would it cause double unlock? > Maybe as follows? > --- > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index 151bd3de5936..8b665ba90ad0 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -3178,7 +3178,7 @@ check_prev_add(struct task_struct *curr, struct > held_lock *prev, > } > > /* <prev> is not found in <next>::locks_before */ > - return 0; > + goto list_err; > } > } > > @@ -3215,6 +3215,11 @@ check_prev_add(struct task_struct *curr, struct > held_lock *prev, > return 0; > > return 2; > + > +list_err: > + /* still get graph_lock, unlock it before return*/ > + graph_unlock(); > + return 0; > } I see. the graph_unlock() is called before any error message is printed. I understand the reason why this is done this way, but it does make it easy to re-introduce this kind of error when the lockdep code is changed. We need a better system to track the state of the graph_lock and do an unlock if necessary. Cheers, Longman
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 151bd3de5936..c8602a251bec 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3178,6 +3178,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, } /* <prev> is not found in <next>::locks_before */ + graph_unlock(); return 0; } }