mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <llong@redhat.com>
To: yunhui cui <cuiyunhui@bytedance.com>,
	peterz@infradead.org, mingo@redhat.com, will@kernel.org,
	boqun.feng@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] locking/mutex: add MUTEX_WARN_ON() into fast path
Date: Thu, 20 Feb 2025 09:03:03 -0500	[thread overview]
Message-ID: <fdc09769-0595-4d45-9d6c-18ce7e98535d@redhat.com> (raw)
In-Reply-To: <CAEEQ3wmk5jBOPqD-5GUZ+463mcG919uuKVnBJrWedKLssVDBaA@mail.gmail.com>

On 2/20/25 7:49 AM, yunhui cui wrote:
> Hi All,
>
> Gentle ping. Any comments on this patch?
>
> On Sun, Jan 26, 2025 at 11:32 AM Yunhui Cui <cuiyunhui@bytedance.com> wrote:
>> Scenario: In platform_device_register, the driver misuses struct
>> device as platform_data, making kmemdup duplicate a device. Accessing
>> the duplicate may cause list corruption due to its mutex magic or list
>> holding old content.
>> It recurs randomly as the first mutex - getting process skips the slow
>> path and mutex check. Adding MUTEX_WARN_ON(lock->magic!= lock) in
>> __mutex_trylock_fast() makes it always happen.
>>
>> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>> ---
>>   kernel/locking/mutex.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
>> index b36f23de48f1..19b636f60a24 100644
>> --- a/kernel/locking/mutex.c
>> +++ b/kernel/locking/mutex.c
>> @@ -143,6 +143,8 @@ static __always_inline bool __mutex_trylock_fast(struct mutex *lock)
>>          unsigned long curr = (unsigned long)current;
>>          unsigned long zero = 0UL;
>>
>> +       MUTEX_WARN_ON(lock->magic != lock);
>> +
>>          if (atomic_long_try_cmpxchg_acquire(&lock->owner, &zero, curr))
>>                  return true;
>>
>> --
>> 2.39.2
>>
LGTM

Acked-by: Waiman Long <longman@redhat.com>


  reply	other threads:[~2025-02-20 14:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-26  3:32 Yunhui Cui
2025-02-20 12:49 ` yunhui cui
2025-02-20 14:03   ` Waiman Long [this message]
2025-02-21 19:28 ` [tip: locking/core] locking/mutex: Add " tip-bot2 for Yunhui Cui

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=fdc09769-0595-4d45-9d6c-18ce7e98535d@redhat.com \
    --to=llong@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®