Message ID | 20220922031013.2150682-8-keescook@chromium.org (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Johannes Berg |
Headers | show |
Series | slab: Introduce kmalloc_size_roundup() | expand |
>-----Original Message----- >From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of >Kees Cook >Sent: Wednesday, September 21, 2022 11:10 PM >To: Vlastimil Babka <vbabka@suse.cz> >Cc: linux-wireless@vger.kernel.org; Jacob Shin <jacob.shin@amd.com>; >llvm@lists.linux.dev; dri-devel@lists.freedesktop.org; linux-mm@kvack.org; >Eric Dumazet <edumazet@google.com>; Nguyen, Anthony L ><anthony.l.nguyen@intel.com>; linux-hardening@vger.kernel.org; Sumit >Semwal <sumit.semwal@linaro.org>; dev@openvswitch.org; x86@kernel.org; >Brandeburg, Jesse <jesse.brandeburg@intel.com>; intel-wired- >lan@lists.osuosl.org; David Rientjes <rientjes@google.com>; Miguel Ojeda ><ojeda@kernel.org>; Yonghong Song <yhs@fb.com>; Paolo Abeni ><pabeni@redhat.com>; linux-media@vger.kernel.org; Marco Elver ><elver@google.com>; Kees Cook <keescook@chromium.org>; Josef Bacik ><josef@toxicpanda.com>; linaro-mm-sig@lists.linaro.org; Jakub Kicinski ><kuba@kernel.org>; David Sterba <dsterba@suse.com>; Joonsoo Kim ><iamjoonsoo.kim@lge.com>; Alex Elder <elder@kernel.org>; Greg Kroah- >Hartman <gregkh@linuxfoundation.org>; Nick Desaulniers ><ndesaulniers@google.com>; linux-kernel@vger.kernel.org; David S. Miller ><davem@davemloft.net>; Pekka Enberg <penberg@kernel.org>; Daniel >Micay <danielmicay@gmail.com>; netdev@vger.kernel.org; linux- >fsdevel@vger.kernel.org; Andrew Morton <akpm@linux-foundation.org>; >Christian König <christian.koenig@amd.com>; linux-btrfs@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@intel.com> >Cc: Tony Nguyen <anthony.l.nguyen@intel.com> >Cc: "David S. Miller" <davem@davemloft.net> >Cc: Eric Dumazet <edumazet@google.com> >Cc: Jakub Kicinski <kuba@kernel.org> >Cc: Paolo Abeni <pabeni@redhat.com> >Cc: intel-wired-lan@lists.osuosl.org >Cc: netdev@vger.kernel.org >Signed-off-by: Kees Cook <keescook@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
On Thu, Sep 22, 2022 at 03:56:54PM +0000, Ruhl, Michael J wrote: > >From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of Kees Cook > [...] > >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)); > > ? Sure! I though it might be more readable split up. I will change it. :)
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); /* allocate q_vector and rings */ q_vector = adapter->q_vector[v_idx];
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@intel.com> Cc: Tony Nguyen <anthony.l.nguyen@intel.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Paolo Abeni <pabeni@redhat.com> Cc: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> --- drivers/net/ethernet/intel/igb/igb_main.c | 1 + 1 file changed, 1 insertion(+)