linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: Kiryl Shutsemau <kirill@shutemov.name>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	akpm@linux-foundation.org, david@redhat.com,
	lorenzo.stoakes@oracle.com, ziy@nvidia.com,
	baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com,
	npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com,
	baohua@kernel.org, lance.yang@linux.dev, xu.xin16@zte.com.cn,
	chengming.zhou@linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH] mm/mm_slot: make sure slot is the first element of its wrapper structure
Date: Mon, 15 Sep 2025 13:37:18 +0000	[thread overview]
Message-ID: <20250915133718.tiw4i2kpbowaqbtf@master> (raw)
In-Reply-To: <ncyl7ryvmvzz5ndycb322nxknyruyouzxgemzgqroopp6nkuho@dugqpe3ij4ad>

On Mon, Sep 15, 2025 at 10:39:28AM +0100, Kiryl Shutsemau wrote:
>On Sun, Sep 14, 2025 at 12:00:26AM +0000, 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.
>> 
>> Current code works since mm_slot is the first element, but make sure it
>> won't be disturbed.
>
>Seems excessive for this kind of problem.
>
>Why not check slot in mm_slot_entry?
>
>diff --git a/mm/mm_slot.h b/mm/mm_slot.h
>index 83f18ed1c4bd..0de24c490b62 100644
>--- a/mm/mm_slot.h
>+++ b/mm/mm_slot.h
>@@ -19,7 +19,7 @@ struct mm_slot {
> };
>
> #define mm_slot_entry(ptr, type, member) \
>-	container_of(ptr, type, member)
>+	(ptr ? container_of(ptr, type, member) : NULL)
>

Hmm... I  have thought about this. But not choose this one without some strong
reason.

I am fine with this too...

> static inline void *mm_slot_alloc(struct kmem_cache *cache)
> {
>-- 
>  Kiryl Shutsemau / Kirill A. Shutemov

-- 
Wei Yang
Help you, Help me


      reply	other threads:[~2025-09-15 13:37 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
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 [this message]

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=20250915133718.tiw4i2kpbowaqbtf@master \
    --to=richard.weiyang@gmail.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=dev.jain@arm.com \
    --cc=kirill@shutemov.name \
    --cc=lance.yang@linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.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