[PATCH 07/12] igb: Proactively round up to kmalloc bucket size

Ruhl, Michael J michael.j.ruhl at intel.com
Thu Sep 22 15:56:54 UTC 2022


>-----Original Message-----
>From: dri-devel <dri-devel-bounces at lists.freedesktop.org> On Behalf Of
>Kees Cook
>Sent: Wednesday, September 21, 2022 11:10 PM
>To: Vlastimil Babka <vbabka at suse.cz>
>Cc: linux-wireless at vger.kernel.org; Jacob Shin <jacob.shin at amd.com>;
>llvm at lists.linux.dev; dri-devel at lists.freedesktop.org; linux-mm at kvack.org;
>Eric Dumazet <edumazet at google.com>; Nguyen, Anthony L
><anthony.l.nguyen at intel.com>; linux-hardening at vger.kernel.org; Sumit
>Semwal <sumit.semwal at linaro.org>; dev at openvswitch.org; x86 at kernel.org;
>Brandeburg, Jesse <jesse.brandeburg at intel.com>; intel-wired-
>lan at lists.osuosl.org; David Rientjes <rientjes at google.com>; Miguel Ojeda
><ojeda at kernel.org>; Yonghong Song <yhs at fb.com>; Paolo Abeni
><pabeni at redhat.com>; linux-media at vger.kernel.org; Marco Elver
><elver at google.com>; Kees Cook <keescook at chromium.org>; Josef Bacik
><josef at toxicpanda.com>; linaro-mm-sig at lists.linaro.org; Jakub Kicinski
><kuba at kernel.org>; David Sterba <dsterba at suse.com>; Joonsoo Kim
><iamjoonsoo.kim at lge.com>; Alex Elder <elder at kernel.org>; Greg Kroah-
>Hartman <gregkh at linuxfoundation.org>; Nick Desaulniers
><ndesaulniers at google.com>; linux-kernel at vger.kernel.org; David S. Miller
><davem at davemloft.net>; Pekka Enberg <penberg at kernel.org>; Daniel
>Micay <danielmicay at gmail.com>; netdev at vger.kernel.org; linux-
>fsdevel at vger.kernel.org; Andrew Morton <akpm at linux-foundation.org>;
>Christian König <christian.koenig at amd.com>; linux-btrfs at vger.kernel.org
>Subject: [PATCH 07/12] igb: Proactively round up to kmalloc bucket size
>
>Instead of having a mismatch between the requested allocation size and
>the actual kmalloc bucket size, which is examined later via ksize(),
>round up proactively so the allocation is explicitly made for the full
>size, allowing the compiler to correctly reason about the resulting size
>of the buffer through the existing __alloc_size() hint.
>
>Cc: Jesse Brandeburg <jesse.brandeburg at intel.com>
>Cc: Tony Nguyen <anthony.l.nguyen at intel.com>
>Cc: "David S. Miller" <davem at davemloft.net>
>Cc: Eric Dumazet <edumazet at google.com>
>Cc: Jakub Kicinski <kuba at kernel.org>
>Cc: Paolo Abeni <pabeni at redhat.com>
>Cc: intel-wired-lan at lists.osuosl.org
>Cc: netdev at vger.kernel.org
>Signed-off-by: Kees Cook <keescook at chromium.org>
>---
> drivers/net/ethernet/intel/igb/igb_main.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c
>b/drivers/net/ethernet/intel/igb/igb_main.c
>index 2796e81d2726..4d70ee5b0f79 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -1196,6 +1196,7 @@ static int igb_alloc_q_vector(struct igb_adapter
>*adapter,
>
> 	ring_count = txr_count + rxr_count;
> 	size = struct_size(q_vector, ring, ring_count);
>+	size = kmalloc_size_roundup(size);

why not:

	size = kmalloc_size_roundup(struct_size(q_vector, ring, ring_count));

?

m
> 	/* allocate q_vector and rings */
> 	q_vector = adapter->q_vector[v_idx];
>--
>2.34.1



More information about the dri-devel mailing list