The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
	Longlong Xia <xialonglong2025@163.com>
Cc: akpm@linux-foundation.org, xu.xin16@zte.com.cn,
	chengming.zhou@linux.dev, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, xialonglong@kylinos.cn
Subject: Re: [PATCH v2] mm/ksm: validate KSM rmap items before hwpoison kill
Date: Thu, 6 Aug 2026 10:35:56 +0200	[thread overview]
Message-ID: <1dd77152-bafa-4c4c-a85f-aba054065601@kernel.org> (raw)
In-Reply-To: <anNl1SSA3fidOrTy@lucifer>

>> @@ -3253,9 +3253,13 @@ void collect_procs_ksm(const struct folio *folio, const struct page *page,
>>  			{
> 
> OK so you're literally doing an anon rmap walk here, with the anon lock held.
> 
>>  				vma = vmac->vma;
>>  				if (vma->vm_mm == t->mm) {
>> -					addr = rmap_item->address & PAGE_MASK;
>> +					const unsigned long mapped_addr =
>> +						page_mapped_in_vma_at_address(page, vma, addr);
> 
> Now you're doing another anon rmap walk? Why on earth are you doing that? And
> won't this deadlock?

I think it's the same as with page_mapped_in_vma(): it expects the anon vma lock
to already haven been taken.

At least that's what I understand when looking at collect_procs_anon. :)

> 
> Why aren't you just checking the whether addr is contained in the range here?

Yeah, that should be much easier.

> 
> Like:
> 
> 	/* Make sure VMA wasn't split/remapped */
> 	if (!in_range(addr, vma->vm_start, vma_pages(vma)))
> 		continue;
> 
> Or something?
> 
>> +
>> +					if (mapped_addr == -EFAULT)
>> +						continue;
>>  					add_to_kill_ksm(t, page, vma, to_kill,
>> -							addr);
>> +							mapped_addr);
>>  				}
>>  			}
>>  		}
>> diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
>> index bac2eb5de63d..f7c5dc9248bc 100644
>> --- a/mm/page_vma_mapped.c
>> +++ b/mm/page_vma_mapped.c
>> @@ -336,6 +336,26 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
>>  }
>>
>>  #ifdef CONFIG_MEMORY_FAILURE
>> +unsigned long page_mapped_in_vma_at_address(const struct page *page,
>> +		struct vm_area_struct *vma, unsigned long addr)
>> +{
>> +	struct page_vma_mapped_walk pvmw = {
>> +		.pfn = page_to_pfn(page),
>> +		.nr_pages = 1,
>> +		.vma = vma,
>> +		.address = addr,
>> +		.flags = PVMW_SYNC,
>> +	};
>> +
>> +	if (addr < vma->vm_start || addr >= vma->vm_end)
>> +		return -EFAULT;
>> +	if (!page_vma_mapped_walk(&pvmw))
>> +		return -EFAULT;
>> +	page_vma_mapped_walk_done(&pvmw);
>> +
>> +	return pvmw.address;
>> +}
> 
> I hate this name I hate that it's CONFIG_MEMORY_FAILURE only.

Note that page_mapped_in_vma() is also KSM only.

But I am curious why the function differs from what I quickly hacked together.


-- 
Cheers,

David

      parent reply	other threads:[~2026-08-06  8:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 15:11 [PATCH 1/1] mm/ksm: validate KSM rmap items before hwpoison kill Longlong Xia
2026-08-05 12:19 ` David Hildenbrand (Arm)
2026-08-05 16:21   ` Longlong Xia
2026-08-05 16:27     ` Lorenzo Stoakes (ARM)
2026-08-05 16:29 ` [PATCH v2] " Longlong Xia
2026-08-05 16:47   ` Lorenzo Stoakes (ARM)
2026-08-06  7:48     ` Longlong Xia
2026-08-06  9:16       ` Lorenzo Stoakes (ARM)
2026-08-06  9:19         ` Longlong Xia
2026-08-06  8:35     ` David Hildenbrand (Arm) [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=1dd77152-bafa-4c4c-a85f-aba054065601@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=xialonglong2025@163.com \
    --cc=xialonglong@kylinos.cn \
    --cc=xu.xin16@zte.com.cn \
    /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