From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FA681B4138 for ; Thu, 20 Nov 2025 15:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763653451; cv=none; b=ELCGqjAvqryakOP/E16wOy09hbs73FJ+8jrW6lyIaGcK6HuUltb5WkkCp4VDLwixCp+JRsLg16I40k/5haAF0hKQZwcReMN6g1qJ2ns/veq1JCVGGIcbH8awVZqaN8WhRYWtHxhrJlqrR0SvTshyC2h9FovN3IqFl7ZXV2FkgRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763653451; c=relaxed/simple; bh=5SJdDsNIzpAiSSWDtnGIqvp7M7NjjLQ9tdPcSngvhOM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bRB43yjjYnE+KkxqlQgIjyKIYrP9eLkdZtGoBXJVBO6UwA/DK6/XJF6lzmczsgA1eFNnhGCG4Oz5DQF66FwI/zoP5F2Wa4uGw0bUD/7ouv9e9TYrVuJjwh+W0OiuBBi540g1mpMtlRQXL3zgAsQAiOQOnGhZvnKFIGSeebZ5lsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MQeYuG1G; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MQeYuG1G" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-477a1c28778so12646405e9.3 for ; Thu, 20 Nov 2025 07:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763653448; x=1764258248; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=V/ugw1qh5Js/ttrR8EDVGlYrGkAdfYtHHIqpSwNHbFo=; b=MQeYuG1GDX9e3y6vgFW0eeN2eqphzE0xb/h3CH8Q5oNQhsSzdC7+x8wt8xmQ3/QbgH Wft7rTbPSsJIz0K7fwhm+dZyF+xoo4fjyp1FH9BNU21NGF3fhevaBQzK0VGM/LHGNP8c 2Nn5JAjIa9ME+zfKmSPPDqWzVwDpto/2go6a4++gXqGnI+L1EUiCjiJAbHQi9nK0d8Zx dHpxzHnxCDlw74ZDYPgXXz0rPbWWNHDGmKhY1aA+jzZ2CMy/fBAMUmDhkMXsJmZyH2ut rs6jVIZ6HPewK4EaR/wop1l5UC02yU/c7DPaN/Q60awNQVrA7McDU8/rETJ1o+FUtphT t1LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763653448; x=1764258248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=V/ugw1qh5Js/ttrR8EDVGlYrGkAdfYtHHIqpSwNHbFo=; b=WFoRtqCxmscQZgu+q9ISgtW/PVCoO6RpzyH8iyINF7WWa7+/0aR8Z8qg8a+kXSbIBV 8BnDsNeY7ltyATp1219Q+Sj1okSetLWDa1UDfRVQdsKeaavQnCN812dPjNifAR0HqgeF DtlTO+I7Yam5nSYNNlmxqDHCErH17zrgxuNU4Ah8wySAPoO93RDycRPCKghmY/OTlx4j 0Pl6SqHiSH1CG6pNaeCuz3ChWN56ebkLEIcNAR+FY2PRESXK59ztjMSCI35VOMdatr6m 7fskAo+GqIuWD6wZbDF1q481sTeE6fRrttiHyWdVaCb4OSvBoMSXTijRiF19Gb8LE7MJ RbMw== X-Forwarded-Encrypted: i=1; AJvYcCUEiE9m07hmPbvIo3HTvtm2LpIBjgBkRkXZqe86Olh9db0UfdGdUSnDSe1gvoy07dlFAowCILVI2H7YkV0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxcndy74LIEp+7EFyyizNt0Pcelrp4lBW2KVEP4dbEXPyyxPfDS EuIAWNIporRInyiTl9he7nkx93UnU8H+2UjpMIq3vaQ8w+Set7iJlWzc X-Gm-Gg: ASbGnct8jQQflz3PnBdtZeJ5GdwpwEkORP/fqMBUU1zp9MY21bnNjodX8whs0K4s77n PhGOWcXCeF+yGwqz+xaHfQhEv/q3WQ+D7DOAQRffZOeXkFwPeeySUbla2PmPnGxQ1COhec03HGa xAMvKWCr96Eksih8q5Dhi0WH1XkwhBp/fer2ld6i6q0VIj1L5Jh9RZ9wFpMeor/4vFdvpjdbmil SvqmKM14r+Oy6+jGG2F9gypdfO0/aVBO3DAsCuEl8jEFS8/S10NijLsJl1lAVBBimF4Fq6nliAg Aq/BdRtJgSc5n3AcQuOXaTUrBFnZ/p/vEy9jFwf3PQLeGAX4LQFVs6YpW6P9HNYqNolp0cFwvwO 32clS6RUZ9JMFXb7RJ1njqDjcuyCPJUtmaJKM7P5pGo8p6rjwI2tN8ESIm8XDrVXp+nEGuLzsgH iQKrMVzDQbTMwK3fwd5YSKd+AI8crMnG97U33/h1TiGxOBq6uhIzbq X-Google-Smtp-Source: AGHT+IHZscOyGXLMcLEwSzXG79SY8Qx2G6gT/YROcc1hUDKG1pZJxcFyYdrYEnvMt+Oi8xS02ts8rg== X-Received: by 2002:a05:600c:450f:b0:475:e067:f23d with SMTP id 5b1f17b1804b1-477b8a98d52mr31212975e9.25.1763653447408; Thu, 20 Nov 2025 07:44:07 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fba20esm5977502f8f.37.2025.11.20.07.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 07:44:07 -0800 (PST) Date: Thu, 20 Nov 2025 15:44:05 +0000 From: David Laight To: "David Hildenbrand (Red Hat)" Cc: Lorenzo Stoakes , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Axel Rasmussen , Christoph Lameter , Dennis Zhou , Johannes Weiner , "Matthew Wilcox (Oracle)" , Mike Rapoport , Tejun Heo , Yuanchu Xie Subject: Re: [PATCH 39/44] mm: use min() instead of min_t() Message-ID: <20251120154405.7bcf9a6e@pumpkin> In-Reply-To: References: <20251119224140.8616-1-david.laight.linux@gmail.com> <20251119224140.8616-40-david.laight.linux@gmail.com> <0c264126-b7ff-4509-93a6-582d928769ea@lucifer.local> <20251120125505.7ec8dfc6@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 20 Nov 2025 14:42:24 +0100 "David Hildenbrand (Red Hat)" wrote: > >> > >>> > >>> Signed-off-by: David Laight > >>> --- > >>> 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. Except that it gives a false positive on a compile-time test that finds a few real bugs. I've been (slowly) fixing 'allmodconfig' and found 'goodies' like: min_t(u32, MAX_UINT, expr) and min_t(u8, expr, 255) Pretty much all the min_t(unsigned xxx) that compile when changed to min() are safe changes and might fix an obscure bug. Probably 99% make no difference. So I'd like to get rid of the ones that make no difference. David