From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: intel-xe@lists.freedesktop.org, "Ingo Molnar" <mingo@redhat.com>,
"Will Deacon" <will@kernel.org>,
"Waiman Long" <longman@redhat.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Maarten Lankhorst" <maarten@lankhorst.se>,
"Christian König" <christian.koenig@amd.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] locking/ww_mutex: Adjust to lockdep nest_lock requirements
Date: Wed, 09 Oct 2024 15:43:29 +0200 [thread overview]
Message-ID: <c5e8899f4bcba24a787cd0f4c92c3fc4d7ef3130.camel@linux.intel.com> (raw)
In-Reply-To: <20241009131015.GP17263@noisy.programming.kicks-ass.net>
On Wed, 2024-10-09 at 15:10 +0200, Peter Zijlstra wrote:
> On Wed, Oct 09, 2024 at 11:20:31AM +0200, Thomas Hellström wrote:
> > When using mutex_acquire_nest() with a nest_lock, lockdep refcounts
> > the
> > number of acquired lockdep_maps of mutexes of the same class, and
> > also
> > keeps a pointer to the first acquired lockdep_map of a class. That
> > pointer
> > is then used for various comparison-, printing- and checking
> > purposes,
> > but there is no mechanism to actively ensure that lockdep_map stays
> > in
> > memory. Instead, a warning is printed if the lockdep_map is freed
> > and
> > there are still held locks of the same lock class, even if the
> > lockdep_map
> > itself has been released.
> >
> > In the context of WW/WD transactions that means that if a user
> > unlocks
> > and frees a ww_mutex from within an ongoing ww transaction, and
> > that
> > mutex happens to be the first ww_mutex grabbed in the transaction,
> > such a warning is printed and there might be a risk of a UAF.
> >
> > Note that this is only problem when lockdep is enabled and affects
> > only
> > dereferences of struct lockdep_map.
> >
> > Adjust to this by adding a fake lockdep_map to the acquired context
> > and
> > make sure it is the first acquired lockdep map of the associated
> > ww_mutex class. Then hold it for the duration of the WW/WD
> > transaction.
> >
> > This has the side effect that trying to lock a ww mutex *without* a
> > ww_acquire_context but where a such context has been acquire, we'd
> > see
> > a lockdep splat. The test-ww_mutex.c selftest attempts to do that,
> > so
> > modify that particular test to not acquire a ww_acquire_context if
> > it
> > is not going to be used.
> >
> > v2:
> > - Lower the number of locks in the test-ww_mutex
> > stress(STRESS_ALL) test to accommodate the dummy lock
> > introduced in this patch without overflowing lockdep held lock
> > references.
>
> Thanks, I rebased tip/locking/core, which should now have this patch.
Thanks.
It takes some time for that failing CI test to run, though so, and
since I can't repro the failure locally I'll keep a watch out.
/Thomas
next prev parent reply other threads:[~2024-10-09 13:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 9:20 Thomas Hellström
2024-10-09 13:10 ` Peter Zijlstra
2024-10-09 13:43 ` Thomas Hellström [this message]
2024-10-09 13:20 ` [tip: locking/core] " tip-bot2 for Thomas Hellström
2024-10-14 20:23 ` [PATCH v2] " Boqun Feng
2024-10-15 11:03 ` Thomas Hellström
2024-10-15 15:27 ` Thomas Hellström
2024-10-15 18:00 ` Boqun Feng
2024-10-16 6:17 ` Thomas Hellström
2024-10-16 17:12 ` Boqun Feng
2024-10-17 15:13 ` Thomas Hellström
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=c5e8899f4bcba24a787cd0f4c92c3fc4d7ef3130.camel@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=boqun.feng@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=maarten@lankhorst.se \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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
Powered by JetHome