All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: Barry Song <21cnbao@gmail.com>
Cc: akpm@linux-foundation.org, david@redhat.com,
	baolin.wang@linux.alibaba.com, chrisl@kernel.org,
	kasong@tencent.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-riscv@lists.infradead.org, lorenzo.stoakes@oracle.com,
	ryan.roberts@arm.com, v-songbaohua@oppo.com, x86@kernel.org,
	huang.ying.caritas@gmail.com, zhengtangquan@oppo.com,
	riel@surriel.com, Liam.Howlett@oracle.com, vbabka@suse.cz,
	harry.yoo@oracle.com, mingzhe.yang@ly.com,
	Lance Yang <ioworker0@gmail.com>
Subject: Re: [PATCH 1/1] mm/rmap: make folio unmap batching safe and support partial batches
Date: Fri, 27 Jun 2025 14:14:32 +0800	[thread overview]
Message-ID: <e33bbf93-ed78-4cbd-9ed7-1e36453549c0@linux.dev> (raw)
In-Reply-To: <CAGsJ_4yjvHzeUTDoALafLddTCTOSzYiFQNvAmSQORLJV1HPhPQ@mail.gmail.com>



On 2025/6/27 13:02, Barry Song wrote:
> On Fri, Jun 27, 2025 at 2:53 PM Lance Yang <ioworker0@gmail.com> wrote:
>>
>> From: Lance Yang <lance.yang@linux.dev>
>>
>> As pointed out by David[1], the batched unmap logic in try_to_unmap_one()
>> can read past the end of a PTE table if a large folio is mapped starting at
>> the last entry of that table.
>>
>> So let's fix the out-of-bounds read by refactoring the logic into a new
>> helper, folio_unmap_pte_batch().
>>
>> The new helper now correctly calculates the safe number of pages to scan by
>> limiting the operation to the boundaries of the current VMA and the PTE
>> table.
>>
>> In addition, the "all-or-nothing" batching restriction is removed to
>> support partial batches. The reference counting is also cleaned up to use
>> folio_put_refs().
>>
>> [1] https://lore.kernel.org/linux-mm/a694398c-9f03-4737-81b9-7e49c857fcbe@redhat.com
>>
>> Fixes: 354dffd29575 ("mm: support batched unmap for lazyfree large folios during reclamation")
>> Suggested-by: David Hildenbrand <david@redhat.com>
>> Suggested-by: Barry Song <baohua@kernel.org>
>> Signed-off-by: Lance Yang <lance.yang@linux.dev>
> 
> I'd prefer changing the subject to something like
> "Fix potential out-of-bounds page table access during batched unmap"

Yep, that's much better.

> 
> Supporting partial batching is a cleanup-related benefit of this fix.
> It's worth mentioning that the affected cases are quite rare,
> since MADV_FREE typically performs split_folio().

Yeah, it would be quite rare in practice ;)

> 
> Also, we need to Cc stable.

Thanks! Will do.



WARNING: multiple messages have this Message-ID (diff)
From: Lance Yang <lance.yang@linux.dev>
To: Barry Song <21cnbao@gmail.com>
Cc: akpm@linux-foundation.org, david@redhat.com,
	baolin.wang@linux.alibaba.com, chrisl@kernel.org,
	kasong@tencent.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-riscv@lists.infradead.org, lorenzo.stoakes@oracle.com,
	ryan.roberts@arm.com, v-songbaohua@oppo.com, x86@kernel.org,
	huang.ying.caritas@gmail.com, zhengtangquan@oppo.com,
	riel@surriel.com, Liam.Howlett@oracle.com, vbabka@suse.cz,
	harry.yoo@oracle.com, mingzhe.yang@ly.com,
	Lance Yang <ioworker0@gmail.com>
Subject: Re: [PATCH 1/1] mm/rmap: make folio unmap batching safe and support partial batches
Date: Fri, 27 Jun 2025 14:14:32 +0800	[thread overview]
Message-ID: <e33bbf93-ed78-4cbd-9ed7-1e36453549c0@linux.dev> (raw)
In-Reply-To: <CAGsJ_4yjvHzeUTDoALafLddTCTOSzYiFQNvAmSQORLJV1HPhPQ@mail.gmail.com>



On 2025/6/27 13:02, Barry Song wrote:
> On Fri, Jun 27, 2025 at 2:53 PM Lance Yang <ioworker0@gmail.com> wrote:
>>
>> From: Lance Yang <lance.yang@linux.dev>
>>
>> As pointed out by David[1], the batched unmap logic in try_to_unmap_one()
>> can read past the end of a PTE table if a large folio is mapped starting at
>> the last entry of that table.
>>
>> So let's fix the out-of-bounds read by refactoring the logic into a new
>> helper, folio_unmap_pte_batch().
>>
>> The new helper now correctly calculates the safe number of pages to scan by
>> limiting the operation to the boundaries of the current VMA and the PTE
>> table.
>>
>> In addition, the "all-or-nothing" batching restriction is removed to
>> support partial batches. The reference counting is also cleaned up to use
>> folio_put_refs().
>>
>> [1] https://lore.kernel.org/linux-mm/a694398c-9f03-4737-81b9-7e49c857fcbe@redhat.com
>>
>> Fixes: 354dffd29575 ("mm: support batched unmap for lazyfree large folios during reclamation")
>> Suggested-by: David Hildenbrand <david@redhat.com>
>> Suggested-by: Barry Song <baohua@kernel.org>
>> Signed-off-by: Lance Yang <lance.yang@linux.dev>
> 
> I'd prefer changing the subject to something like
> "Fix potential out-of-bounds page table access during batched unmap"

Yep, that's much better.

> 
> Supporting partial batching is a cleanup-related benefit of this fix.
> It's worth mentioning that the affected cases are quite rare,
> since MADV_FREE typically performs split_folio().

Yeah, it would be quite rare in practice ;)

> 
> Also, we need to Cc stable.

Thanks! Will do.


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-06-27  6:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27  2:52 [PATCH 1/1] mm/rmap: make folio unmap batching safe and support partial batches Lance Yang
2025-06-27  2:52 ` Lance Yang
2025-06-27  5:02 ` Barry Song
2025-06-27  5:02   ` Barry Song
2025-06-27  6:14   ` Lance Yang [this message]
2025-06-27  6:14     ` Lance Yang
2025-07-16 15:21 ` patchwork-bot+linux-riscv
2025-07-16 15:21   ` patchwork-bot+linux-riscv

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=e33bbf93-ed78-4cbd-9ed7-1e36453549c0@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=21cnbao@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=harry.yoo@oracle.com \
    --cc=huang.ying.caritas@gmail.com \
    --cc=ioworker0@gmail.com \
    --cc=kasong@tencent.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mingzhe.yang@ly.com \
    --cc=riel@surriel.com \
    --cc=ryan.roberts@arm.com \
    --cc=v-songbaohua@oppo.com \
    --cc=vbabka@suse.cz \
    --cc=x86@kernel.org \
    --cc=zhengtangquan@oppo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.