From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 B883A2D7DEE for ; Fri, 19 Dec 2025 09:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766135227; cv=none; b=BIGdE2+MwzaVlRRBYzSW8jZkJh9KAKAlptkMkYNmMcP7bYir6+pouINUeVWYJKSslHVM2bQwxhYxjpDpJt6hV9ruM3CoIXKEeHXsl5fxGzJOJVAdxc91qowVUPK+a+To2DIT18FrLXLKsM7jNjHXvqggXQQwfasHwEqk5bPLcl4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766135227; c=relaxed/simple; bh=IvXHjwzY77XaX7X/U9dF0cDnVYHe1YX3RN/SMu0a+j0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=td7gt9tKaE85IsQiuLoHbRsfR4AN1aQfjJi1zbxX12PwE+0UylOP81ALP29MnZ/PXyEkwX0W1DUN6zX7aZ0uRUh/9NjBTLfR2gKYpgvEDDumUsGV7lu5O9RecCFgVBvseKrPn/RWSZHT85WVvtruL1UFRAPlIU/yh8MafBCYoMg= 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=jp9qeAux; arc=none smtp.client-ip=209.85.128.43 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="jp9qeAux" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-47a8195e515so11837675e9.0 for ; Fri, 19 Dec 2025 01:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766135224; x=1766740024; 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=YBS6/GkvOknyT7Zpvi8ZpC9HmfcmPlYKsO2XlNLAgug=; b=jp9qeAuxAD8Q2HE2+ijX5VzUIL4RQI5rrfccVcWgbBx8bKkIcvb6euKgGm2DPGAb7a d2p0z8wuj4gLtl+a4IWXtiRA9GnWgAMS55C1DEOLHdsxrWsn/GEFq1K2a1BYXU1G+VCt 4qvNMCZtsWSOA/bdb0r+9h9z05dvl71RF22UWdDVSv9Gg8FMXLrzJGN+qV4tXY6hJ/wH Bx0tZZO8mwdSptw6Bj8IB0+GnSTkm6DiMFVByoyY+l8wC0YKn9R1I34hGi387/1IceQc /Z4NYOYcdTornnkb5o3TdkrQzwNMdAmpj7D6IM6atlrgtel1ugsItyBmwrWlqHwgUNJf JANQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766135224; x=1766740024; 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=YBS6/GkvOknyT7Zpvi8ZpC9HmfcmPlYKsO2XlNLAgug=; b=hliVXPYVxUsid3jtiGQhn82oRJfWA88Mln9LBGNzOLF/sMFspgn2PeQcoMIlw6R5S9 9SJD67r8vToj67TdU35n4TxZSYl9NX4U/fr1Sx3WuBfZaklBnc/i/qDkVGRFYS6vniu7 4CT5TRnM5vY0dtZzG3DtCSwDuGT//LQAJb20+4uIGIlYb51guNHJGDENF/MaQhQCsV6V ZYF/BK+6MEjdzh1xl9wAe6W51owV8aIN5/u/FNorOmGUcCaQlPP2zRg5bSnLOSPguSaD 3r4Kb5peaW0g4kE2tatIdaJuoNthJyRgjfKKvYkh87Zmw1HZjJVGtK4gQieGmfY76zN1 EMHg== X-Forwarded-Encrypted: i=1; AJvYcCWoHOcI28oJTPM/XSq87eJr/m5BrvcAFQSzAqDRUJBgr/W45CRWwHpl4U/vEBN1VDBfRhgA5kc3lxjLlIg=@vger.kernel.org X-Gm-Message-State: AOJu0YwXlsPKON8w5L6LvR15zO23V6LAnSGeieZrfYQjiRbD0jmaRDKB H7DVSDUXwjoJBfdi9lYitolbbyszrAppYwIwgTHIL5tKKRtoFvJEt0pV X-Gm-Gg: AY/fxX52MWSPFd5O5fSvVb7Djhf8e3t7IRTUPKlfLJyNMkkEH4SmUUCgyyE+IMuuhCs NCNARg2nrTT56kjH01r3g+DV9WhhSf4b6bNluYvBYd1Dt9IubspV00lg8IiOjg4w1ksOWGQK2M0 WP0TqoeXUyJqF/HgH/Z8EIi0io+UDZzCvEhft+DN7apdtwrLgn2T9IbMZ5Ay4td6VDngCSRNQfI ycpdVeT4i9gr52/YfLp2jqx6udnA/sgym7MsbF2CdLxyRegetR+J9A4wqB5Pq73fCfxzkiKI6tt 3aNKrWR+u+8VtIbMGI4vC13M9a+qIzJih56v86pbOW5EEyVp5DFbSCIGx0mzWf9Beyuv+HaeT/Q D0VBL9vf43FdJM0aqoXBi2E0RdKqi/XXHDgBVScEUhIxh1LZemvmP15/Ydxxgfm7nb2Wg3pAQR/ zkAzqBoZ4VKj9QoahJ1vzFtW0s7SKdkNQF+1U3KrsZZ53xWvShcsaZ X-Google-Smtp-Source: AGHT+IFLmds42d8vq8VOO1M1o+9hrFfg92pPA/nYyB7zACk7trqZpvV3gBxa+GxMMxXj4A+KGeNviw== X-Received: by 2002:a05:600c:8b0c:b0:475:dcbb:7903 with SMTP id 5b1f17b1804b1-47d19555796mr16725745e9.9.1766135223727; Fri, 19 Dec 2025 01:07:03 -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 5b1f17b1804b1-47be3a49315sm33171175e9.2.2025.12.19.01.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 01:07:03 -0800 (PST) Date: Fri, 19 Dec 2025 09:07:01 +0000 From: David Laight To: Joanne Koong Cc: Bernd Schubert , Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel test robot Subject: Re: [PATCH] fuse: change fuse_wr_pages() to avoid signedness error from min() Message-ID: <20251219090701.58d8141b@pumpkin> In-Reply-To: References: <20251216141647.13911-1-david.laight.linux@gmail.com> 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, 19 Dec 2025 11:24:23 +0800 Joanne Koong wrote: > On Wed, Dec 17, 2025 at 12:22=E2=80=AFAM w= rote: > > > > From: David Laight > > > > On 32bit builds the 'number of pages required' calculation is signed > > and min() complains because max_pages is unsigned. > > Change the calcualtion that determines the number of pages by adding the > > 'offset in page' to 'len' rather than subtracting the end and start pag= es. > > Although the 64bit value is still signed, the compiler knows it isn't > > negative so min() doesn't complain. > > The generated code is also slightly better. > > > > Forcing the calculation to 32 bits (eg len + (size_t)(pos & ...)) > > generates much better code and is probably safe because len should > > be limited to 'INT_MAX - PAGE_SIZE). > > > > Fixes: 0f5bb0cfb0b4 ("fs: use min() or umin() instead of min_t()") > > Reported-by: kernel test robot > > Closes: https://lore.kernel.org/oe-kbuild-all/202512160948.O7QqxHj2-lkp= @intel.com/ > > Signed-off-by: David Laight > > --- > > fs/fuse/file.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/fuse/file.c b/fs/fuse/file.c > > index 4f71eb5a9bac..98edb6a2255d 100644 > > --- a/fs/fuse/file.c > > +++ b/fs/fuse/file.c > > @@ -1323,7 +1323,7 @@ static ssize_t fuse_fill_write_pages(struct fuse_= io_args *ia, > > static inline unsigned int fuse_wr_pages(loff_t pos, size_t len, > > unsigned int max_pages) > > { > > - return min(((pos + len - 1) >> PAGE_SHIFT) - (pos >> PAGE_SHIFT= ) + 1, > > + return min(((len + (pos & (PAGE_SIZE - 1)) - 1) >> PAGE_SHIFT) = + 1, > > max_pages); =20 >=20 > I find this logic a bit confusing to read still, what about something lik= e: >=20 > unsigned int nr_pages =3D DIV_ROUND_UP(offset_in_page(pos) + len, PAGE_SI= ZE); > return min(nr_pages, max_pages); You can just do: return min(DIV_ROUND_UP(offset_in_page(pos) + len, PAGE_SIZE), max_pages); or splitting the long line: len +=3D offset_in_page(pos); return min(DIV_ROUND_UP(len, PAGE_SIZE), max_pages); Using offset_in_page() and DIV_ROUND_UP adds the 'hidden' requirement that 'len <=3D MAX_ULONG - 2 * PAGE_SIZE'. (Should be true - read/write (etc) are bounded to MAX_INT - PAGE_SIZE.) > instead? I think the compiler will automatically optimize the > DIV_ROUND_UP to use a bit shift. Provided it is an unsigned divide - and the LHS is unsigned. DIV_ROUNDUP(a, b) is '(a + b - 1)/b' which can overflow for large 'a'. The other option is '(a - 1)/b + 1' which is valid for non-zero 'a'. David >=20 > Thanks, > Joanne > > } > > > > -- > > 2.39.5 > > > > =20