[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e06666bf-6d19-4ed7-a870-012dff1fe077@kernel.org>
Date: Thu, 20 Nov 2025 14:42:24 +0100
From: "David Hildenbrand (Red Hat)" <david@...nel.org>
To: David Laight <david.laight.linux@...il.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
Axel Rasmussen <axelrasmussen@...gle.com>, Christoph Lameter
<cl@...two.org>, Dennis Zhou <dennis@...nel.org>,
Johannes Weiner <hannes@...xchg.org>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
Mike Rapoport <rppt@...nel.org>, Tejun Heo <tj@...nel.org>,
Yuanchu Xie <yuanchu@...gle.com>
Subject: Re: [PATCH 39/44] mm: use min() instead of min_t()
>>
>>>
>>> Signed-off-by: David Laight <david.laight.linux@...il.com>
>>> ---
>>> mm/gup.c | 4 ++--
>>> mm/memblock.c | 2 +-
>>> mm/memory.c | 2 +-
>>> mm/percpu.c | 2 +-
>>> mm/truncate.c | 3 +--
>>> mm/vmscan.c | 2 +-
>>> 6 files changed, 7 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/mm/gup.c b/mm/gup.c
>>> index a8ba5112e4d0..55435b90dcc3 100644
>>> --- a/mm/gup.c
>>> +++ b/mm/gup.c
>>> @@ -237,8 +237,8 @@ static inline struct folio *gup_folio_range_next(struct page *start,
>>> unsigned int nr = 1;
>>>
>>> if (folio_test_large(folio))
>>> - nr = min_t(unsigned int, npages - i,
>>> - folio_nr_pages(folio) - folio_page_idx(folio, next));
>>> + nr = min(npages - i,
>>> + folio_nr_pages(folio) - folio_page_idx(folio, next));
>>
>> There's no cases where any of these would discard significant bits. But we
>> ultimately cast to unisnged int anyway (nr) so not sure this achieves anything.
>
> The (implicit) cast to unsigned int is irrelevant - that happens after the min().
> The issue is that 'npages' is 'unsigned long' so can (in theory) be larger than 4G.
> Ok that would be a 16TB buffer, but someone must have decided that npages might
> not fit in 32 bits otherwise they wouldn't have used 'unsigned long'.
See commit fa17bcd5f65e ("mm: make folio page count functions return
unsigned") why that function used to return "long" instead of "unsigned
int" and how we changed it to "unsigned long".
Until that function actually returns something that large might take a
while, so no need to worry about that right now.
--
Cheers
David
Powered by blists - more mailing lists