Message ID | 20221018085911.never.761-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1850890wrs; Tue, 18 Oct 2022 02:06:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gvPy8onmb2rs1oZxrMsVb15hdBR79LIb1xCLmZkySUy97ZC9DKaKaX2APgAoY45GLO05l X-Received: by 2002:a17:907:6d27:b0:78d:46f6:c59e with SMTP id sa39-20020a1709076d2700b0078d46f6c59emr1580807ejc.30.1666084008842; Tue, 18 Oct 2022 02:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666084008; cv=none; d=google.com; s=arc-20160816; b=NgxsAFGZs1xQhw+Gtdfoa8SGJAkqcBN7jPHjDgn/MoaX40YAq2t8q/csoSMWFIM8i6 /gnbl9Z6N1pPXLeYOXi4EPtgoYWqbHNwrn86VcY+iv0zmWTYSXMb6E8NisuwbqQAeLtF /6y4EQsLaL28mFew8e6vI/B3hHk/4gdkC7+anJEQA9Ur8FWit5XrXLRdA6+x2m9Vh359 uHJyg6GSdNBD+GiKMqNYy8BGFjaHXtzWWzAfm2hiuXLpNoiSOxDpfpV1LaKfCFMAuBEK U5BojcVqvXLxGmt2HWFo/ucBLVLcebYUoPMPcWp5nZIxokR4nzD1Q0THp1Q3SUePIiIp mroA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SyYgnWapL79xSGbWpqYMsssi6Z5UWEMZCCJiBQWYB4E=; b=r9J9tgiJpeGpz87EihH27zbDOn9VDjdRNyrIJi8338YhumEd9+FnBQt5RmKVmshmaR uHNHEcz7HKXVzdcJy4RIXZxAIYYKAe/OOSmnIxlD0PgQRAHhNugCLxU29uc1JL5qM77i vIt00uRYomcqr0aYUXKnKkYANdb5YHhadwg3XFQePqOF4UG8h1g5nop8Y6kzMebqPu4b b4ubz/CpDLgA2twSs6WvGBK4EHMpqnDAAr5wppJ/VipXLlJ6Jr/xv+LxI9gsbfK9D+pT 8auKdW+fto+t1ycZJLyXWVzwA1gvb3NLjl21jPM8Cr1ifOPiV/qyUaGEe/i3PQgw6e8m s3Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HESG1GP8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a170906724a00b007808f3f4cbcsi9627034ejk.239.2022.10.18.02.06.23; Tue, 18 Oct 2022 02:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HESG1GP8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231213AbiJRJAM (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Tue, 18 Oct 2022 05:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbiJRI7x (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 18 Oct 2022 04:59:53 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B84271C11E for <linux-kernel@vger.kernel.org>; Tue, 18 Oct 2022 01:59:32 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id g8-20020a17090a128800b0020c79f987ceso16692356pja.5 for <linux-kernel@vger.kernel.org>; Tue, 18 Oct 2022 01:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SyYgnWapL79xSGbWpqYMsssi6Z5UWEMZCCJiBQWYB4E=; b=HESG1GP8bzrjSt/N/3biOxlPGGIiOnjZz7pL+YQNIzKoN6I+tjDC2Pp/uhHC2z4Vs5 aGzRvgHCUubVN8NGAjkTNHZ87zzBdFYkpHDd3e4o8LjWLUqMjpqz3WlVjyqFQs2gPvwO j+TfsLtFgE7q5r2dDeTn1JsFxJEDhZiBVK/VY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SyYgnWapL79xSGbWpqYMsssi6Z5UWEMZCCJiBQWYB4E=; b=cHhLpbPK/iEIOx+4KUmREZV4hPe/jY2Tr2rnNBWMnw3NR59+ox0lerCvsZiH3k9LuW TNdVbm0PHMZoimsF0bt1Y4EvYc7Kkm4WakXgpgi7/th7D9nDdwh5Dkho5rUkQuJb3t6C 0XljTSl9mxi1KU9cRGRELCtRQx7/Ji48SdUmBm7K1QqqPBNPduQAMn3OF39EPLxatjg3 eCbI6B5kXPBDkjOfgcrJbz3mzP4HTi629uZTDfZqx5d93Dkxr6sn/UA4N8z06a0zZp6g Dm3RQVUmh1EzG12jdTfYeO7IBtV43yLxlUx4xQ03vtB8ZEqyKdD0PhL4JzSsi6uE6zW2 Ce5Q== X-Gm-Message-State: ACrzQf1Gpqx9t0MtDCOy+ytYPz2i1i04caL2r1tAqM5P14CMC4vr/l4k 0Wq1rPV/Z0d7ARoomPvZ6yY1gQ== X-Received: by 2002:a17:903:2410:b0:17a:b32:dbec with SMTP id e16-20020a170903241000b0017a0b32dbecmr1919815plo.163.1666083571999; Tue, 18 Oct 2022 01:59:31 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d25-20020aa797b9000000b00561f8fdba8esm8997458pfq.12.2022.10.18.01.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 01:59:31 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Rasesh Mody <rmody@marvell.com> Cc: Kees Cook <keescook@chromium.org>, GR-Linux-NIC-Dev@marvell.com, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] bnx2: Pass allocation size to build_skb() Date: Tue, 18 Oct 2022 01:59:29 -0700 Message-Id: <20221018085911.never.761-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1102; h=from:subject:message-id; bh=0iHouSVWi0PwtUaYPQkq5H19VoFAe1X0ZNyWzn5SCiM=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjTmrxhlbZceUvuakDoLe7hd916D4/myuLK08nIiua YaUGddiJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY05q8QAKCRCJcvTf3G3AJpR4EA CSTtT9LieM6D3o4tx5ZJ7a+zK3I/9WqHD2KIdka3We7XaR1IpSrnbypJUI70xheIXyARK5Zn80tsLE k7/i2X/PNQNJv9jzpb026t0x2BXhHogl/tlXrP4PrLQlYvBAL7XEn23/bri3WzBRbhgSsoPkeNfhlQ QKGVsgMLCItyteG6u/d5pTfNIh98Tm1hf9jG/GL6WAe/7+D8BF8BZGBwAOjiOv3Q8GbrSEHX0U/6pH /hg88vrHL6GJT8mTrn9dc6pgNB3fsn5fhIYs4/MLZ1Ahq2x81aqlRYfa5EaeSkAUEt9OQpm8TmjWQ2 nXpSqNi259io2cnMCSNpiSYSTPQ5ZhMQdDJnuwo4XCFN34OCPo3OZZu3Oyc3ZwTwmZmjrqElELGdY4 SfwSJAr3fuDULYYC3lL12WtPpGPRvJDVaODhLTcD7GLTOPDSCQx+twqsxNCH95pVm8YlHIpQ0yTSbZ bvjv9wViG6B0yqtZE+W1buh4DWWGIDVAJN1U0jCul+euwN0z8+hhYTtUDmDucD8JJyY2VEAQsqFdlZ D1xiDdO0FrU6GNtxtlAA85AfBfkUJlSKZSTDQjldvi8L//k34b7eK6Mok96/EqRa2qGd0TYnFnd1P+ ShmDVyS57kEFJJnIC/Y6S0Hp0E+cSRlSXShV8nJUBGoJsvYcz0yiQ1KeHnPA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747015705420323663?= X-GMAIL-MSGID: =?utf-8?q?1747015705420323663?= |
Series |
bnx2: Pass allocation size to build_skb()
|
|
Commit Message
Kees Cook
Oct. 18, 2022, 8:59 a.m. UTC
In preparation for requiring that build_skb() have a non-zero size
argument, pass the actual data allocation size explicitly into
build_skb().
Cc: Rasesh Mody <rmody@marvell.com>
Cc: GR-Linux-NIC-Dev@marvell.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: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/net/ethernet/broadcom/bnx2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Tue, 18 Oct 2022 01:59:29 -0700 Kees Cook wrote: > In preparation for requiring that build_skb() have a non-zero size > argument, pass the actual data allocation size explicitly into > build_skb(). build_skb(, 0) has the special meaning of "head buf has been kmalloc'd", rather than alloc_page(). Was this changed and I missed it?
On Wed, Oct 19, 2022 at 05:02:55PM -0700, Jakub Kicinski wrote: > On Tue, 18 Oct 2022 01:59:29 -0700 Kees Cook wrote: > > In preparation for requiring that build_skb() have a non-zero size > > argument, pass the actual data allocation size explicitly into > > build_skb(). > > build_skb(, 0) has the special meaning of "head buf has been kmalloc'd", > rather than alloc_page(). Was this changed and I missed it? Hm, I'm not clear on it. I see ksize() being called, but I guess that works for alloc_page() allocations too? build_skb __build_skb: __build_skb_around: unsigned int size = frag_size ? : ksize(data); So I guess in this case, this patch is wrong, and should instead be this to match the ksize() used in build_skb(): diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index fec57f1982c8..dbe310144780 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c @@ -5415,8 +5415,9 @@ bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size) bp->rx_buf_use_size = rx_size; /* hw alignment + build_skb() overhead*/ - bp->rx_buf_size = SKB_DATA_ALIGN(bp->rx_buf_use_size + BNX2_RX_ALIGN) + - NET_SKB_PAD + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + bp->rx_buf_size = kmalloc_size_roundup( + SKB_DATA_ALIGN(bp->rx_buf_use_size + BNX2_RX_ALIGN) + + NET_SKB_PAD + SKB_DATA_ALIGN(sizeof(struct skb_shared_info))); bp->rx_jumbo_thresh = rx_size - BNX2_RX_OFFSET; bp->rx_ring_size = size; bp->rx_max_ring = bnx2_find_max_ring(size, BNX2_MAX_RX_RINGS);
On Fri, 21 Oct 2022 19:06:26 -0700 Kees Cook wrote: > On Wed, Oct 19, 2022 at 05:02:55PM -0700, Jakub Kicinski wrote: > > On Tue, 18 Oct 2022 01:59:29 -0700 Kees Cook wrote: > > > In preparation for requiring that build_skb() have a non-zero size > > > argument, pass the actual data allocation size explicitly into > > > build_skb(). > > > > build_skb(, 0) has the special meaning of "head buf has been kmalloc'd", > > rather than alloc_page(). Was this changed and I missed it? > > Hm, I'm not clear on it. I see ksize() being called, but I guess that > works for alloc_page() allocations too? > > build_skb > __build_skb: > __build_skb_around: > unsigned int size = frag_size ? : ksize(data); Hm, what I'm saying is the definition of the frag_size is - the size of the frag if page-backed, or 0 if kmalloc-backed. So the ternary op above applies ksize only in the kmalloc case. > So I guess in this case, this patch is wrong, and should instead be this > to match the ksize() used in build_skb(): > > diff --git a/drivers/net/ethernet/broadcom/bnx2.c > b/drivers/net/ethernet/broadcom/bnx2.c > index fec57f1982c8..dbe310144780 100644 > --- a/drivers/net/ethernet/broadcom/bnx2.c > +++ b/drivers/net/ethernet/broadcom/bnx2.c > @@ -5415,8 +5415,9 @@ bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size) > > bp->rx_buf_use_size = rx_size; > /* hw alignment + build_skb() overhead*/ > - bp->rx_buf_size = SKB_DATA_ALIGN(bp->rx_buf_use_size + BNX2_RX_ALIGN) + > - NET_SKB_PAD + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); > + bp->rx_buf_size = kmalloc_size_roundup( > + SKB_DATA_ALIGN(bp->rx_buf_use_size + BNX2_RX_ALIGN) + > + NET_SKB_PAD + SKB_DATA_ALIGN(sizeof(struct skb_shared_info))); > bp->rx_jumbo_thresh = rx_size - BNX2_RX_OFFSET; > bp->rx_ring_size = size; > bp->rx_max_ring = bnx2_find_max_ring(size, BNX2_MAX_RX_RINGS); IIUC you want the size of the allocation to match exactly to the result of ksize()? In that case - yup, the above looks good. FWIW the kmalloc backed heads are actually a performance bottleneck so we'd be doing everyone a favor if we just converted the two drivers which do this to use pages and killed the "feature". But the roundup works well enough.
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c index fec57f1982c8..0b2d4972343a 100644 --- a/drivers/net/ethernet/broadcom/bnx2.c +++ b/drivers/net/ethernet/broadcom/bnx2.c @@ -3045,7 +3045,8 @@ bnx2_rx_skb(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u8 *data, dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size, DMA_FROM_DEVICE); - skb = build_skb(data, 0); + + skb = build_skb(data, bp->rx_buf_size); if (!skb) { kfree(data); goto error;