From: Peter Zijlstra <peterz@infradead.org>
To: Imre Deak <imre.deak@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
"Ingo Molnar" <mingo@redhat.com>,
"Will Deacon" <will.deacon@arm.com>
Subject: Re: [PATCH v2 2/2] lockdep: Fix merging of hlocks with non-zero references
Date: Mon, 27 May 2019 18:06:18 +0200 [thread overview]
Message-ID: <20190527160618.GT2650@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190527151438.GF2623@hirez.programming.kicks-ass.net>
On Mon, May 27, 2019 at 05:14:38PM +0200, Peter Zijlstra wrote:
> On Fri, May 24, 2019 at 11:15:09PM +0300, Imre Deak wrote:
> > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> > index 967352d32af1..9e2a4ab6c731 100644
> > --- a/kernel/locking/lockdep.c
> > +++ b/kernel/locking/lockdep.c
> > @@ -3637,6 +3637,11 @@ print_lock_nested_lock_not_held(struct task_struct *curr,
> >
> > static int __lock_is_held(const struct lockdep_map *lock, int read);
> >
> > +static int hlock_reference(int reference)
> > +{
> > + return reference ? : 1;
> > +}
> > +
> > /*
> > * This gets called for every mutex_lock*()/spin_lock*() operation.
> > * We maintain the dependency maps and validate the locking attempt:
> > @@ -3702,17 +3707,15 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
> > if (depth) {
> > hlock = curr->held_locks + depth - 1;
> > if (hlock->class_idx == class_idx && nest_lock) {
> > - if (hlock->references) {
> > - /*
> > - * Check: unsigned int references overflow.
> > - */
> > - if (DEBUG_LOCKS_WARN_ON(hlock->references == UINT_MAX))
>
> What tree is this against? Afaict this is still 12 bits ?!
>
> > - return 0;
> > + /*
> > + * Check: unsigned int references overflow.
> > + */
> > + if (DEBUG_LOCKS_WARN_ON(hlock_reference(hlock->references) >
> > + UINT_MAX - hlock_reference(references)))
>
> Idem. Also very weird overflow check..
>
> > + return 0;
> >
> > - hlock->references++;
> > - } else {
> > - hlock->references = 2;
> > - }
> > + hlock->references = hlock_reference(hlock->references) +
> > + hlock_reference(references);
> >
> > return 2;
> > }
I think you wanted something like this: ?
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -3731,6 +3731,11 @@ print_lock_nested_lock_not_held(struct t
static int __lock_is_held(const struct lockdep_map *lock, int read);
+static inline int hlock_references(struct held_lock *hlock)
+{
+ return hlock->references ? : 1;
+}
+
/*
* This gets called for every mutex_lock*()/spin_lock*() operation.
* We maintain the dependency maps and validate the locking attempt:
@@ -3796,17 +3801,14 @@ static int __lock_acquire(struct lockdep
if (depth) {
hlock = curr->held_locks + depth - 1;
if (hlock->class_idx == class_idx && nest_lock) {
- if (hlock->references) {
- /*
- * Check: unsigned int references:12, overflow.
- */
- if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1))
- return 0;
-
- hlock->references++;
- } else {
- hlock->references = 2;
- }
+ if (!references)
+ references++;
+
+ hlock->references = hlock_references(hlock) + references;
+
+ /* Overflow */
+ if (DEBUG_LOCKS_WARN_ON(hlock->references < references))
+ return 0;
return 2;
}
next prev parent reply other threads:[~2019-05-27 16:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 20:15 [PATCH v2 1/2] lockdep: Fix OOO unlock when hlocks need merging Imre Deak
2019-05-24 20:15 ` [PATCH v2 2/2] lockdep: Fix merging of hlocks with non-zero references Imre Deak
2019-05-27 15:14 ` Peter Zijlstra
2019-05-27 15:44 ` Imre Deak
2019-05-27 16:10 ` Peter Zijlstra
2019-05-27 16:06 ` Peter Zijlstra [this message]
2019-05-27 16:21 ` Imre Deak
2019-06-03 13:32 ` [tip:locking/core] locking/lockdep: " tip-bot for Imre Deak
2019-05-27 15:02 ` [PATCH v2 1/2] lockdep: Fix OOO unlock when hlocks need merging Peter Zijlstra
2019-05-27 15:21 ` Imre Deak
2019-06-03 13:31 ` [tip:locking/core] locking/lockdep: " tip-bot for Imre Deak
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=20190527160618.GT2650@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=imre.deak@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=ville.syrjala@linux.intel.com \
--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
all inboxes | Powered by JetHome®