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

From: Ruhl, Michael J
Date: Thu Sep 22 2022 - 11:57:29 EST



>-----Original Message-----
>From: dri-devel <dri-devel-bounces@xxxxxxxxxxxxxxxxxxxxx> On Behalf Of
>Kees Cook
>Sent: Wednesday, September 21, 2022 11:10 PM
>To: Vlastimil Babka <vbabka@xxxxxxx>
>Cc: linux-wireless@xxxxxxxxxxxxxxx; Jacob Shin <jacob.shin@xxxxxxx>;
>llvm@xxxxxxxxxxxxxxx; dri-devel@xxxxxxxxxxxxxxxxxxxxx; linux-mm@xxxxxxxxx;
>Eric Dumazet <edumazet@xxxxxxxxxx>; Nguyen, Anthony L
><anthony.l.nguyen@xxxxxxxxx>; linux-hardening@xxxxxxxxxxxxxxx; Sumit
>Semwal <sumit.semwal@xxxxxxxxxx>; dev@xxxxxxxxxxxxxxx; x86@xxxxxxxxxx;
>Brandeburg, Jesse <jesse.brandeburg@xxxxxxxxx>; intel-wired-
>lan@xxxxxxxxxxxxxxxx; David Rientjes <rientjes@xxxxxxxxxx>; Miguel Ojeda
><ojeda@xxxxxxxxxx>; Yonghong Song <yhs@xxxxxx>; Paolo Abeni
><pabeni@xxxxxxxxxx>; linux-media@xxxxxxxxxxxxxxx; Marco Elver
><elver@xxxxxxxxxx>; Kees Cook <keescook@xxxxxxxxxxxx>; Josef Bacik
><josef@xxxxxxxxxxxxxx>; linaro-mm-sig@xxxxxxxxxxxxxxxx; Jakub Kicinski
><kuba@xxxxxxxxxx>; David Sterba <dsterba@xxxxxxxx>; Joonsoo Kim
><iamjoonsoo.kim@xxxxxxx>; Alex Elder <elder@xxxxxxxxxx>; Greg Kroah-
>Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; Nick Desaulniers
><ndesaulniers@xxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx; David S. Miller
><davem@xxxxxxxxxxxxx>; Pekka Enberg <penberg@xxxxxxxxxx>; Daniel
>Micay <danielmicay@xxxxxxxxx>; netdev@xxxxxxxxxxxxxxx; linux-
>fsdevel@xxxxxxxxxxxxxxx; Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>;
>Christian König <christian.koenig@xxxxxxx>; linux-btrfs@xxxxxxxxxxxxxxx
>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@xxxxxxxxx>
>Cc: Tony Nguyen <anthony.l.nguyen@xxxxxxxxx>
>Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
>Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
>Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
>Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
>Cc: intel-wired-lan@xxxxxxxxxxxxxxxx
>Cc: netdev@xxxxxxxxxxxxxxx
>Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
>---
> 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