From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>,
linux-kernel@vger.kernel.org,
Bart Van Assche <bvanassche@acm.org>
Subject: Re: [PATCH v5 6/7] locking/lockdep: Reuse freed chain_hlocks entries
Date: Tue, 4 Feb 2020 11:57:09 -0500 [thread overview]
Message-ID: <f7f4151d-6514-be7b-1915-37f19411ca96@redhat.com> (raw)
In-Reply-To: <16125cbf-09ee-919e-4b7a-33dabb123159@redhat.com>
On 2/4/20 11:26 AM, Waiman Long wrote:
> On 2/4/20 11:12 AM, Waiman Long wrote:
>> On 2/4/20 10:42 AM, Peter Zijlstra wrote:
>>> On Mon, Feb 03, 2020 at 11:41:46AM -0500, Waiman Long wrote:
>>>> + /*
>>>> + * We require a minimum of 2 (u16) entries to encode a freelist
>>>> + * 'pointer'.
>>>> + */
>>>> + req = max(req, 2);
>>> Would something simple like the below not avoid that whole 1 entry
>>> 'chain' nonsense?
>>>
>>> It boots and passes the selftests, so it must be perfect :-)
>>>
>>> --- a/kernel/locking/lockdep.c
>>> +++ b/kernel/locking/lockdep.c
>>> @@ -3163,7 +3163,7 @@ static int validate_chain(struct task_st
>>> * (If lookup_chain_cache_add() return with 1 it acquires
>>> * graph_lock for us)
>>> */
>>> - if (!hlock->trylock && hlock->check &&
>>> + if (!chain_head && !hlock->trylock && hlock->check &&
>>> lookup_chain_cache_add(curr, hlock, chain_key)) {
>>> /*
>>> * Check whether last held lock:
>>>
>> Well, I think that will eliminate the 1-entry chains for the process
>> context. However, we can still have 1-entry chain in the irq context, I
>> think, as long as there are process context locks in front of it.
>>
>> I think this fix is still worthwhile as it will eliminate some of the
>> 1-entry chains.
> Sorry, I think I mis-read the code. This patch will eliminate some
> cross-context check. How about something like
>
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index 32406ef0d6a2..d746897b638f 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -2931,7 +2931,7 @@ static int validate_chain(struct task_struct *curr,
> * (If lookup_chain_cache_add() return with 1 it acquires
> * graph_lock for us)
> */
> - if (!hlock->trylock && hlock->check &&
> + if ((chain_head != 1) && !hlock->trylock && hlock->check &&
> lookup_chain_cache_add(curr, hlock, chain_key)) {
> /*
> * Check whether last held lock:
> @@ -3937,7 +3937,7 @@ static int __lock_acquire(struct lockdep_map
> *lock, unsign
> hlock->prev_chain_key = chain_key;
> if (separate_irq_context(curr, hlock)) {
> chain_key = INITIAL_CHAIN_KEY;
> - chain_head = 1;
> + chain_head = 2; /* Head of irq context chain */
> }
> chain_key = iterate_chain_key(chain_key, class_idx);
Wait, it is possible that we can have deadlock like this:
cpu 0 cpu 1
----- -----
lock A lock B
<irq> <irq>
lock B lock A
If we eliminate 1-entry chain, will that impact our ability to detect this
kind of deadlock?
Thanks,
Longman
next prev parent reply other threads:[~2020-02-04 16:57 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-03 16:41 [PATCH v5 0/7] locking/lockdep: Reuse zapped chain_hlocks entries Waiman Long
2020-02-03 16:41 ` [PATCH v5 1/7] locking/lockdep: Decrement irq context counters when removing lock chain Waiman Long
2020-02-03 16:41 ` [PATCH v5 2/7] locking/lockdep: Display irq_context names in /proc/lockdep_chains Waiman Long
2020-02-03 16:41 ` [PATCH v5 3/7] locking/lockdep: Track number of zapped classes Waiman Long
2020-02-03 16:41 ` [PATCH v5 4/7] locking/lockdep: Throw away all lock chains with zapped class Waiman Long
2020-02-03 16:41 ` [PATCH v5 5/7] locking/lockdep: Track number of zapped lock chains Waiman Long
2020-02-03 16:41 ` [PATCH v5 6/7] locking/lockdep: Reuse freed chain_hlocks entries Waiman Long
2020-02-04 12:36 ` Peter Zijlstra
2020-02-04 14:54 ` Waiman Long
2020-02-04 16:45 ` Waiman Long
2020-02-05 9:41 ` Peter Zijlstra
2020-02-05 13:59 ` Waiman Long
2020-02-04 15:42 ` Peter Zijlstra
2020-02-04 16:12 ` Waiman Long
2020-02-04 16:26 ` Waiman Long
2020-02-04 16:57 ` Waiman Long [this message]
2020-02-05 9:48 ` Peter Zijlstra
2020-02-05 14:03 ` Waiman Long
2020-02-03 16:41 ` [PATCH v5 7/7] locking/lockdep: Add a fast path for chain_hlocks allocation Waiman Long
2020-02-04 12:47 ` Peter Zijlstra
2020-02-04 15:07 ` Waiman Long
2020-02-04 13:18 ` Peter Zijlstra
2020-02-04 13:44 ` Peter Zijlstra
2020-02-04 18:02 ` 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=f7f4151d-6514-be7b-1915-37f19411ca96@redhat.com \
--to=longman@redhat.com \
--cc=bvanassche@acm.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).