Re: [PATCH v2 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03.06.24 16:43, Matthew Wilcox wrote:
On Mon, Jun 03, 2024 at 10:07:45PM +0800, Lance Yang wrote:
+++ b/mm/mlock.c
@@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
  static inline unsigned int folio_mlock_step(struct folio *folio,
  		pte_t *pte, unsigned long addr, unsigned long end)
  {
-	unsigned int count, i, nr = folio_nr_pages(folio);
-	unsigned long pfn = folio_pfn(folio);
+	const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
+	unsigned int count = (end - addr) >> PAGE_SHIFT;

This is a pre-existing bug, but ... what happens if you're on a 64-bit
system and you mlock() a range that is exactly 2^44 bytes?  Seems to me
that count becomes 0.  Why not use an unsigned long here and avoid the
problem entirely?

folio_pte_batch() also needs to take an unsigned long max_nr in that
case, because you aren't restricting it to folio_nr_pages().

Yeah, likely we should also take a look at other folio_pte_batch() users like copy_present_ptes() that pass the count as an int. Nothing should really be broken, but we might not batch as much as we could, which is unfortunate.

--
Cheers,

David / dhildenb





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux