mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Xuewen Yan <xuewen.yan@unisoc.com>,
	peterz@infradead.org, mingo@redhat.com, will@kernel.org,
	boqun.feng@gmail.com
Cc: zhiguo.niu@unisoc.com, ke.wang@unisoc.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] lockdep: Add missing graph_unlock in check_prev_add
Date: Mon, 8 Jan 2024 22:49:30 -0500	[thread overview]
Message-ID: <a8023072-0900-4be9-bb34-02850276404b@redhat.com> (raw)
In-Reply-To: <20240105060456.15331-1-xuewen.yan@unisoc.com>

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


  reply	other threads:[~2024-01-09  3:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-05  6:04 Xuewen Yan
2024-01-09  3:49 ` Waiman Long [this message]
2024-01-09  5:11   ` Xuewen Yan
2024-01-09 15:40     ` Waiman Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8023072-0900-4be9-bb34-02850276404b@redhat.com \
    --to=longman@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=ke.wang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    --cc=xuewen.yan@unisoc.com \
    --cc=zhiguo.niu@unisoc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®