From: Dev Jain <dev.jain@arm.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: Lance Yang <lance.yang@linux.dev>,
linux-mm@kvack.org, lorenzo.stoakes@oracle.com,
akpm@linux-foundation.org, chengming.zhou@linux.dev,
npache@redhat.com, ryan.roberts@arm.com, xu.xin16@zte.com.cn,
baohua@kernel.org, Liam.Howlett@oracle.com, david@redhat.com,
ziy@nvidia.com, baolin.wang@linux.alibaba.com
Subject: Re: [PATCH] mm/mm_slot: make sure slot is the first element of its wrapper structure
Date: Mon, 15 Sep 2025 09:19:55 +0530 [thread overview]
Message-ID: <daead4f9-aa50-41bc-901a-8dfbdbd896c5@arm.com> (raw)
In-Reply-To: <20250915015722.z4w23d6ralc2y7mk@master>
On 15/09/25 7:27 am, Wei Yang wrote:
> On Sun, Sep 14, 2025 at 12:59:33PM +0530, Dev Jain wrote:
>> On 14/09/25 12:33 pm, Lance Yang wrote:
>>>
>>> On 2025/9/14 14:21, Dev Jain wrote:
>>>> On 14/09/25 5:30 am, Wei Yang wrote:
>>>>> When using mm_slot in ksm/khugepaged, there is code snip like:
>>>>>
>>>>> slot = mm_slot_lookup(mm_slots_hash, mm);
>>>>> mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
>>>>> if (mm_slot && ..) {
>>>>> }
>>>>>
>>>>> This is only valid when mm_slot is the first element of its wrapper
>>>>> structure, otherwise a NULL slot would converted to a mm_slot with
>>>>> negative value. And current code thinks it is valid and continue.
>>>> Shouldn't you fix the code for the case when you can't find the slot
>>>> in the hashtable, i.e slot == NULL? Like, if (!slot) return.
>>> Right. For khugepaged specifically, the slot == NULL case in
>>> __khugepaged_exit() (only user of mm_slot_lookup) should probably
>>> be treated as a kernel BUG for new.
>>>
>>> But I'm not sure if the same logic applies to KSM ;)
>> I haven't seen the KSM analogue, but restricting the position of an element
>>
>> in a struct to make the code work should imply that the code is wrong in
>>
>> the first place :)
>>
> Ok, if so, I think this should be a patch with Fixes tag and cc stable? And it
> supposed to be two patches, since it fixes two different commit. Am I right?
I don't think this is a fix which needs to be backported, the current code works.
What we need is a VM_BUG_ON() or a WARN_ON_ONCE() when slot == NULL, because that
just shouldn't happen, and then safely exit.
>
> Originally, I though we don't want that bother :-)
>
> And now we decide to fix this, I am wondering why we wrap mm_slot with
> khugepaged_mm_slot. I don't think it is necessary to create a new data
> structure to just wrap another. And this is why the problem comes.
>
> commit b26e27015e mm: thp: convert to common struct mm_slot
Yeah I always wondered why we had that wrapper, makes things unnecessarily
complicated.
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
next prev parent reply other threads:[~2025-09-15 3:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-14 0:00 Wei Yang
2025-09-14 5:05 ` Lance Yang
2025-09-15 1:47 ` Wei Yang
2025-09-15 7:32 ` David Hildenbrand
2025-09-15 7:42 ` Wei Yang
2025-09-15 7:48 ` David Hildenbrand
2025-09-15 7:52 ` Wei Yang
2025-09-14 6:21 ` Dev Jain
2025-09-14 7:03 ` Lance Yang
2025-09-14 7:29 ` Dev Jain
2025-09-14 7:39 ` Lance Yang
2025-09-14 14:16 ` xu.xin16
2025-09-15 1:57 ` Wei Yang
2025-09-15 3:49 ` Dev Jain [this message]
2025-09-15 4:05 ` Dev Jain
2025-09-15 7:46 ` Wei Yang
2025-09-15 7:57 ` David Hildenbrand
2025-09-15 7:56 ` David Hildenbrand
2025-09-15 8:08 ` Lance Yang
2025-09-15 8:26 ` David Hildenbrand
2025-09-15 8:11 ` Dev Jain
2025-09-15 8:25 ` David Hildenbrand
2025-09-15 9:07 ` Wei Yang
2025-09-15 9:15 ` Wei Yang
2025-09-15 9:39 ` Kiryl Shutsemau
2025-09-15 13:37 ` Wei Yang
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=daead4f9-aa50-41bc-901a-8dfbdbd896c5@arm.com \
--to=dev.jain@arm.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=lance.yang@linux.dev \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=npache@redhat.com \
--cc=richard.weiyang@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=xu.xin16@zte.com.cn \
--cc=ziy@nvidia.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