From: Herbert Xu <herbert@gondor.apana.org.au>
To: david.laight.linux@gmail.com
Cc: linux-kernel@vger.kernel.org,
"Alan Stern" <stern@rowland.harvard.edu>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Alexei Starovoitov" <ast@kernel.org>,
"Andi Shyti" <andi.shyti@kernel.org>,
"Andreas Dilger" <adilger.kernel@dilger.ca>,
"Andrew Lunn" <andrew@lunn.ch>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Arnaldo Carvalho de Melo" <acme@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Borislav Petkov" <bp@alien8.de>,
"Christian Brauner" <brauner@kernel.org>,
"Christian König" <christian.koenig@amd.com>,
"Christoph Hellwig" <hch@lst.de>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Dan Williams" <dan.j.williams@intel.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Dave Jiang" <dave.jiang@intel.com>,
"David Ahern" <dsahern@kernel.org>,
"David Hildenbrand" <david@redhat.com>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"David S. Miller" <davem@davemloft.net>,
"Dennis Zhou" <dennis@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Jakub Sitnicki" <jakub@cloudflare.com>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
"Jarkko Sakkinen" <jarkko@kernel.org>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
"Jens Axboe" <axboe@kernel.dk>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"John Allen" <john.allen@amd.com>,
"Jonathan Cameron" <jonathan.cameron@huawei.com>,
"Juergen Gross" <jgross@suse.com>, "Kees Cook" <kees@kernel.org>,
"KP Singh" <kpsingh@kernel.org>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Mika Westerberg" <westeri@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Miklos Szeredi" <miklos@szeredi.hu>,
"Namhyung Kim" <namhyung@kernel.org>,
"Neal Cardwell" <ncardwell@google.com>,
nic_swsd@realtek.com,
"OGAWA Hirofumi" <hirofumi@mail.parknet.co.jp>,
"Olivia Mackall" <olivia@selenic.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Huewe" <peterhuewe@gmx.de>,
"Peter Zijlstra" <peterz@infradead.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Sean Christopherson" <seanjc@google.com>,
"Srinivas Kandagatla" <srini@kernel.org>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Tejun Heo" <tj@kernel.org>, "Theodore Ts'o" <tytso@mit.edu>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Tom Lendacky" <thomas.lendacky@amd.com>,
"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
x86@kernel.org, "Yury Norov" <yury.norov@gmail.com>,
amd-gfx@lists.freedesktop.org, bpf@vger.kernel.org,
cgroups@vger.kernel.org, dri-devel@lists.freedesktop.org,
io-uring@vger.kernel.org, kvm@vger.kernel.org,
linux-acpi@vger.kernel.org, linux-block@vger.kernel.org,
linux-crypto@vger.kernel.org, linux-cxl@vger.kernel.org,
linux-efi@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-integrity@vger.kernel.org,
linux-mm@kvack.org, linux-nvme@lists.infradead.org,
linux-pci@vger.kernel.org, linux-perf-users@vger.kernel.org,
linux-scsi@vger.kernel.org, linux-serial@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
mptcp@lists.linux.dev, netdev@vger.kernel.org,
usb-storage@lists.one-eyed-alien.net
Subject: Re: [PATCH 00/44] Change a lot of min_t() that might mask high bits
Date: Mon, 24 Nov 2025 17:49:51 +0800 [thread overview]
Message-ID: <aSQqP6nlqGYOGqcJ@gondor.apana.org.au> (raw)
In-Reply-To: <20251119224140.8616-1-david.laight.linux@gmail.com>
On Wed, Nov 19, 2025 at 10:40:56PM +0000, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
>
> It in not uncommon for code to use min_t(uint, a, b) when one of a or b
> is 64bit and can have a value that is larger than 2^32;
> This is particularly prevelant with:
> uint_var = min_t(uint, uint_var, uint64_expression);
>
> Casts to u8 and u16 are very likely to discard significant bits.
>
> These can be detected at compile time by changing min_t(), for example:
> #define CHECK_SIZE(fn, type, val) \
> BUILD_BUG_ON_MSG(sizeof (val) > sizeof (type) && \
> !statically_true(((val) >> 8 * (sizeof (type) - 1)) < 256), \
> fn "() significant bits of '" #val "' may be discarded")
>
> #define min_t(type, x, y) ({ \
> CHECK_SIZE("min_t", type, x); \
> CHECK_SIZE("min_t", type, y); \
> __cmp_once(min, type, x, y); })
>
> (and similar changes to max_t() and clamp_t().)
>
> This shows up some real bugs, some unlikely bugs and some false positives.
> In most cases both arguments are unsigned type (just different ones)
> and min_t() can just be replaced by min().
>
> The patches are all independant and are most of the ones needed to
> get the x86-64 kernel I build to compile.
> I've not tried building an allyesconfig or allmodconfig kernel.
> I've also not included the patch to minmax.h itself.
>
> I've tried to put the patches that actually fix things first.
> The last one is 0009.
>
> I gave up on fixing sched/fair.c - it is too broken for a single patch!
> The patch for net/ipv4/tcp.c is also absent because do_tcp_getsockopt()
> needs multiple/larger changes to make it 'sane'.
>
> I've had to trim the 124 maintainers/lists that get_maintainer.pl finds
> from 124 to under 100 to be able to send the cover letter.
> The individual patches only go to the addresses found for the associated files.
> That reduces the number of emails to a less unsane number.
>
> David Laight (44):
> x86/asm/bitops: Change the return type of variable__ffs() to unsigned
> int
> ext4: Fix saturation of 64bit inode times for old filesystems
> perf: Fix branch stack callchain limit
> io_uring/net: Change some dubious min_t()
> ipc/msg: Fix saturation of percpu counts in msgctl_info()
> bpf: Verifier, remove some unusual uses of min_t() and max_t()
> net/core/flow_dissector: Fix cap of __skb_flow_dissect() return value.
> net: ethtool: Use min3() instead of nested min_t(u16,...)
> ipv6: __ip6_append_data() don't abuse max_t() casts
> x86/crypto: ctr_crypt() use min() instead of min_t()
> arch/x96/kvm: use min() instead of min_t()
> block: use min() instead of min_t()
> drivers/acpi: use min() instead of min_t()
> drivers/char/hw_random: use min3() instead of nested min_t()
> drivers/char/tpm: use min() instead of min_t()
> drivers/crypto/ccp: use min() instead of min_t()
> drivers/cxl: use min() instead of min_t()
> drivers/gpio: use min() instead of min_t()
> drivers/gpu/drm/amd: use min() instead of min_t()
> drivers/i2c/busses: use min() instead of min_t()
> drivers/net/ethernet/realtek: use min() instead of min_t()
> drivers/nvme: use min() instead of min_t()
> arch/x86/mm: use min() instead of min_t()
> drivers/nvmem: use min() instead of min_t()
> drivers/pci: use min() instead of min_t()
> drivers/scsi: use min() instead of min_t()
> drivers/tty/vt: use umin() instead of min_t(u16, ...) for row/col
> limits
> drivers/usb/storage: use min() instead of min_t()
> drivers/xen: use min() instead of min_t()
> fs: use min() or umin() instead of min_t()
> block: bvec.h: use min() instead of min_t()
> nodemask: use min() instead of min_t()
> ipc: use min() instead of min_t()
> bpf: use min() instead of min_t()
> bpf_trace: use min() instead of min_t()
> lib/bucket_locks: use min() instead of min_t()
> lib/crypto/mpi: use min() instead of min_t()
> lib/dynamic_queue_limits: use max() instead of max_t()
> mm: use min() instead of min_t()
> net: Don't pass bitfields to max_t()
> net/core: Change loop conditions so min() can be used
> net: use min() instead of min_t()
> net/netlink: Use umin() to avoid min_t(int, ...) discarding high bits
> net/mptcp: Change some dubious min_t(int, ...) to min()
>
> arch/x86/crypto/aesni-intel_glue.c | 3 +-
> arch/x86/include/asm/bitops.h | 18 +++++-------
> arch/x86/kvm/emulate.c | 3 +-
> arch/x86/kvm/lapic.c | 2 +-
> arch/x86/kvm/mmu/mmu.c | 2 +-
> arch/x86/mm/pat/set_memory.c | 12 ++++----
> block/blk-iocost.c | 6 ++--
> block/blk-settings.c | 2 +-
> block/partitions/efi.c | 3 +-
> drivers/acpi/property.c | 2 +-
> drivers/char/hw_random/core.c | 2 +-
> drivers/char/tpm/tpm1-cmd.c | 2 +-
> drivers/char/tpm/tpm_tis_core.c | 4 +--
> drivers/crypto/ccp/ccp-dev.c | 2 +-
> drivers/cxl/core/mbox.c | 2 +-
> drivers/gpio/gpiolib-acpi-core.c | 2 +-
> .../gpu/drm/amd/amdgpu/amdgpu_doorbell_mgr.c | 4 +--
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
> .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
> drivers/i2c/busses/i2c-designware-master.c | 2 +-
> drivers/net/ethernet/realtek/r8169_main.c | 3 +-
> drivers/nvme/host/pci.c | 3 +-
> drivers/nvme/host/zns.c | 3 +-
> drivers/nvmem/core.c | 2 +-
> drivers/pci/probe.c | 3 +-
> drivers/scsi/hosts.c | 2 +-
> drivers/tty/vt/selection.c | 9 +++---
> drivers/usb/storage/protocol.c | 3 +-
> drivers/xen/grant-table.c | 2 +-
> fs/buffer.c | 2 +-
> fs/exec.c | 2 +-
> fs/ext4/ext4.h | 2 +-
> fs/ext4/mballoc.c | 3 +-
> fs/ext4/resize.c | 2 +-
> fs/ext4/super.c | 2 +-
> fs/fat/dir.c | 4 +--
> fs/fat/file.c | 3 +-
> fs/fuse/dev.c | 2 +-
> fs/fuse/file.c | 8 ++---
> fs/splice.c | 2 +-
> include/linux/bvec.h | 3 +-
> include/linux/nodemask.h | 9 +++---
> include/linux/perf_event.h | 2 +-
> include/net/tcp_ecn.h | 5 ++--
> io_uring/net.c | 6 ++--
> ipc/mqueue.c | 4 +--
> ipc/msg.c | 6 ++--
> kernel/bpf/core.c | 4 +--
> kernel/bpf/log.c | 2 +-
> kernel/bpf/verifier.c | 29 +++++++------------
> kernel/trace/bpf_trace.c | 2 +-
> lib/bucket_locks.c | 2 +-
> lib/crypto/mpi/mpicoder.c | 2 +-
> lib/dynamic_queue_limits.c | 2 +-
> mm/gup.c | 4 +--
> mm/memblock.c | 2 +-
> mm/memory.c | 2 +-
> mm/percpu.c | 2 +-
> mm/truncate.c | 3 +-
> mm/vmscan.c | 2 +-
> net/core/datagram.c | 6 ++--
> net/core/flow_dissector.c | 7 ++---
> net/core/net-sysfs.c | 3 +-
> net/core/skmsg.c | 4 +--
> net/ethtool/cmis_cdb.c | 7 ++---
> net/ipv4/fib_trie.c | 2 +-
> net/ipv4/tcp_input.c | 4 +--
> net/ipv4/tcp_output.c | 5 ++--
> net/ipv4/tcp_timer.c | 4 +--
> net/ipv6/addrconf.c | 8 ++---
> net/ipv6/ip6_output.c | 7 +++--
> net/ipv6/ndisc.c | 5 ++--
> net/mptcp/protocol.c | 8 ++---
> net/netlink/genetlink.c | 9 +++---
> net/packet/af_packet.c | 2 +-
> net/unix/af_unix.c | 4 +--
> 76 files changed, 141 insertions(+), 176 deletions(-)
Patches 10,14,16,37 applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
prev parent reply other threads:[~2025-11-24 9:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 22:40 david.laight.linux
2025-11-19 22:41 ` [PATCH 30/44] fs: use min() or umin() instead of min_t() david.laight.linux
2025-11-25 9:06 ` Christian Brauner
2025-11-19 22:41 ` [PATCH 39/44] mm: use min() " david.laight.linux
2025-11-20 9:20 ` David Hildenbrand (Red Hat)
2025-11-20 9:59 ` David Laight
2025-11-20 23:45 ` Eric Biggers
2025-11-21 8:27 ` David Hildenbrand (Red Hat)
2025-11-21 9:15 ` David Laight
2025-11-20 10:36 ` Lorenzo Stoakes
2025-11-20 12:09 ` Lorenzo Stoakes
2025-11-20 12:55 ` David Laight
2025-11-20 13:42 ` David Hildenbrand (Red Hat)
2025-11-20 15:44 ` David Laight
2025-11-21 8:24 ` David Hildenbrand (Red Hat)
2025-11-20 1:47 ` [PATCH 00/44] Change a lot of min_t() that might mask high bits Jakub Kicinski
2025-11-20 9:38 ` Lorenzo Stoakes
2025-11-20 14:52 ` (subset) " Jens Axboe
2025-11-24 9:49 ` Herbert Xu [this message]
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=aSQqP6nlqGYOGqcJ@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=James.Bottomley@hansenpartnership.com \
--cc=Jason@zx2c4.com \
--cc=acme@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andi.shyti@kernel.org \
--cc=andrew@lunn.ch \
--cc=andrii@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ardb@kernel.org \
--cc=ast@kernel.org \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=christian.koenig@amd.com \
--cc=dan.j.williams@intel.com \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=david@redhat.com \
--cc=dennis@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=hch@lst.de \
--cc=hirofumi@mail.parknet.co.jp \
--cc=io-uring@vger.kernel.org \
--cc=jakub@cloudflare.com \
--cc=jarkko@kernel.org \
--cc=jgross@suse.com \
--cc=jirislaby@kernel.org \
--cc=john.allen@amd.com \
--cc=jonathan.cameron@huawei.com \
--cc=kees@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=miklos@szeredi.hu \
--cc=mingo@redhat.com \
--cc=mptcp@lists.linux.dev \
--cc=namhyung@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.com \
--cc=olivia@selenic.com \
--cc=pabeni@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterhuewe@gmx.de \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=seanjc@google.com \
--cc=srini@kernel.org \
--cc=sstabellini@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=tj@kernel.org \
--cc=tytso@mit.edu \
--cc=usb-storage@lists.one-eyed-alien.net \
--cc=viro@zeniv.linux.org.uk \
--cc=westeri@kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
--cc=willy@infradead.org \
--cc=x86@kernel.org \
--cc=yury.norov@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox