Message ID | ZGLR3H1OTgJfOdFP@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp82606vqo; Mon, 15 May 2023 17:55:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ497VAFEtfBmNZYwczS/OjQVNi/yK/c3X1ZSH3bcZ9ClqVGI40sXPehf7dw4wIBO77TED/g X-Received: by 2002:a05:6a00:1741:b0:646:421f:500b with SMTP id j1-20020a056a00174100b00646421f500bmr42602603pfc.10.1684198526188; Mon, 15 May 2023 17:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684198526; cv=none; d=google.com; s=arc-20160816; b=r+0k4EZMCH9m6/dAAiP/qv42OAewrucpqzwuz43d/hkK93E3MAhv9XQ8TQYcd3ZA5b YnvRikz4rCLMq1pAPkgCjGvd0snXK7h9WBm/1h7hbHXywn/cfl9fPQjVetfC9LvcLh3x 6fIBhwMqlbqUU9sOLm3nETV2a6+wbz2VP3x9xtIHPc0gkfwboiJaDU/7V1c/KDUNFJTD sdnNploxbPCqRhgZIfeC/jLNBPN3gsN44YSPu+69Bw/JK0aslc1q9nWdcJAVFl2b1FVn lSrCu2lkOgi7XaLzBv3VMAhxK0JHk5CsJ92YExeekEnhMFzO7FbMW01imvMmi6FZsjwP qK8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=sUyab1KeClx4Mr67jrQkpbMEZH48rSb860QH+IytggM=; b=sqysy1YoBX24zb8MaRBlzl7AMgYh74XPXs+a+MLZeOQ1ha6YFPY4BQpg7WIOgRtnMG jnRs/QQLcBYV8uAqNg7qr67mDHWG1kWYB8ZgoL1OI2aslqK/gpxoMHJ/CmXVrH6tQ8Yh sjqvrIDWJI3iPf6S6XWp003Dia33mWIh4ByPTVxiRsOAUiDNZoOBh9oiuRj+LfPRKdvI mjoj7bKixqmPK4WxSpO91Br5aSF5GL/GvwpLbexSMzDRBFMsfw1ZopSwntiKR1DGgS5b /JqJD38iDn7PHxWL0TkEmxcoAIcfQvKw+Xxb6Cd+GnfG7KtetIrBZXXh5zUY2ckMCBux qyMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DtiDA03q; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k16-20020a628410000000b0063d2130eadasi18702996pfd.256.2023.05.15.17.55.11; Mon, 15 May 2023 17:55:26 -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=@kernel.org header.s=k20201202 header.b=DtiDA03q; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245573AbjEPAn1 (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Mon, 15 May 2023 20:43:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231675AbjEPAn0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 15 May 2023 20:43:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 864BE30FD; Mon, 15 May 2023 17:43:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1B2BE614EF; Tue, 16 May 2023 00:43:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D9EC433EF; Tue, 16 May 2023 00:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684197804; bh=EZ/VEL9nOrJvXWP6Eakz2K4BqbU29ceO9yaOi8MzFko=; h=Date:From:To:Cc:Subject:From; b=DtiDA03qB8WUjEC0lxHy7XUBo+JRvMljs14RzZ5Iwbj3u1sMKB3DRd6/PJBOfHyrj xnjHhlVHg/BvwHuSK1gpstKc7I/nwQ5kXyw1CJvPyNDyFIsgiotCakhag/yr5tmAII ForlwY0e2dYmTNED0G6UT0NLKAr6Q7vm9VvJgUU1YEVZOMKaxOkVomqTMlTgat7piY 1lpUj0OqDAK+Ys0ZZTnFGK5D6/VVkzo46q0D65W+zMqGViHsLmex2bJI/6dDXYG2qY hoHlMwVXY9hoO8De3n3pqvAIfU6Do8KWI02Bf971ijhvINxtar994EA+bXVeDy1qnY 0M+aJ0gcSKVlw== Date: Mon, 15 May 2023 18:44:12 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Jesse Brandeburg <jesse.brandeburg@intel.com>, Tony Nguyen <anthony.l.nguyen@intel.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] iavf: Replace one-element array with flexible-array member Message-ID: <ZGLR3H1OTgJfOdFP@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1766010153988757304?= X-GMAIL-MSGID: =?utf-8?q?1766010153988757304?= |
Series |
[next] iavf: Replace one-element array with flexible-array member
|
|
Commit Message
Gustavo A. R. Silva
May 16, 2023, 12:44 a.m. UTC
One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct iavf_qvlist_info, and refactor the rest of the code,
accordingly.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [1].
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/289
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +-
drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On Mon, May 15, 2023 at 06:44:12PM -0600, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element array with flexible-array > member in struct iavf_qvlist_info, and refactor the rest of the code, > accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/289 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Simon Horman <simon.horman@corigine.com>
On Mon, May 15, 2023 at 06:44:12PM -0600, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element array with flexible-array > member in struct iavf_qvlist_info, and refactor the rest of the code, > accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/289 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org>
On 5/15/2023 5:44 PM, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with flexible > array members instead. So, replace one-element array with flexible-array > member in struct iavf_qvlist_info, and refactor the rest of the code, > accordingly. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/289 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- > drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.c b/drivers/net/ethernet/intel/iavf/iavf_client.c > index 93c903c02c64..782384b3aa38 100644 > --- a/drivers/net/ethernet/intel/iavf/iavf_client.c > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.c > @@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, > > v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; > msg_size = struct_size(v_qvlist_info, qv_info, > - v_qvlist_info->num_vectors - 1); > + v_qvlist_info->num_vectors); The problem is this mirrors the virtchnl struct (virtchnl_rdma_qvlist_info) so that structure needs to change as well... However, this goes back to the interface that virtchnl provides between PF and VF [1]. I think removing the iavf structure and directly using the virtchnl one would make sense. We'd need to adjust virtchnl and follow Kees' suggestion [2]. > adapter->client_pending |= BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP); > err = iavf_aq_send_msg_to_pf(&adapter->hw, > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.h b/drivers/net/ethernet/intel/iavf/iavf_client.h > index c5d51d7dc7cc..500269bc0f5b 100644 > --- a/drivers/net/ethernet/intel/iavf/iavf_client.h > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.h > @@ -53,7 +53,7 @@ struct iavf_qv_info { > > struct iavf_qvlist_info { > u32 num_vectors; > - struct iavf_qv_info qv_info[1]; > + struct iavf_qv_info qv_info[]; > }; > > #define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF [1] https://lore.kernel.org/intel-wired-lan/f3674339c0390ced22b365101f2d3e3a2bf26845.camel@intel.com/ [2] https://lore.kernel.org/intel-wired-lan/202106091424.37E833794@keescook/
On Tue, May 23, 2023 at 11:19:00AM -0700, Tony Nguyen wrote: > On 5/15/2023 5:44 PM, Gustavo A. R. Silva wrote: > > One-element arrays are deprecated, and we are replacing them with flexible > > array members instead. So, replace one-element array with flexible-array > > member in struct iavf_qvlist_info, and refactor the rest of the code, > > accordingly. > > > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > > routines on memcpy() and help us make progress towards globally > > enabling -fstrict-flex-arrays=3 [1]. > > > > Link: https://github.com/KSPP/linux/issues/79 > > Link: https://github.com/KSPP/linux/issues/289 > > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > --- > > drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- > > drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.c b/drivers/net/ethernet/intel/iavf/iavf_client.c > > index 93c903c02c64..782384b3aa38 100644 > > --- a/drivers/net/ethernet/intel/iavf/iavf_client.c > > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.c > > @@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, > > v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; > > msg_size = struct_size(v_qvlist_info, qv_info, > > - v_qvlist_info->num_vectors - 1); > > + v_qvlist_info->num_vectors); > > The problem is this mirrors the virtchnl struct (virtchnl_rdma_qvlist_info) > so that structure needs to change as well... However, this goes back to the > interface that virtchnl provides between PF and VF [1]. > > I think removing the iavf structure and directly using the virtchnl one > would make sense. We'd need to adjust virtchnl and follow Kees' suggestion > [2]. Note that at the time I suggested "[0]", but it should have been "[]". But, yes, Keeping the "over allocation" is fine since it's a hardware ABI. Alternatively, it could be defined with a union to keep all the sizes the same: struct iavf_qvlist_info { u32 num_vectors; - struct iavf_qv_info qv_info[1]; + union { + struct iavf_qv_info single_qv_info; + DECLARE_FLEX_ARRAY(struct iavf_qv_info, qv_info) + }; }; -Kees > > > adapter->client_pending |= BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP); > > err = iavf_aq_send_msg_to_pf(&adapter->hw, > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.h b/drivers/net/ethernet/intel/iavf/iavf_client.h > > index c5d51d7dc7cc..500269bc0f5b 100644 > > --- a/drivers/net/ethernet/intel/iavf/iavf_client.h > > +++ b/drivers/net/ethernet/intel/iavf/iavf_client.h > > @@ -53,7 +53,7 @@ struct iavf_qv_info { > > struct iavf_qvlist_info { > > u32 num_vectors; > > - struct iavf_qv_info qv_info[1]; > > + struct iavf_qv_info qv_info[]; > > }; > > #define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF > > [1] https://lore.kernel.org/intel-wired-lan/f3674339c0390ced22b365101f2d3e3a2bf26845.camel@intel.com/ > [2] https://lore.kernel.org/intel-wired-lan/202106091424.37E833794@keescook/
diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.c b/drivers/net/ethernet/intel/iavf/iavf_client.c index 93c903c02c64..782384b3aa38 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_client.c +++ b/drivers/net/ethernet/intel/iavf/iavf_client.c @@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; msg_size = struct_size(v_qvlist_info, qv_info, - v_qvlist_info->num_vectors - 1); + v_qvlist_info->num_vectors); adapter->client_pending |= BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP); err = iavf_aq_send_msg_to_pf(&adapter->hw, diff --git a/drivers/net/ethernet/intel/iavf/iavf_client.h b/drivers/net/ethernet/intel/iavf/iavf_client.h index c5d51d7dc7cc..500269bc0f5b 100644 --- a/drivers/net/ethernet/intel/iavf/iavf_client.h +++ b/drivers/net/ethernet/intel/iavf/iavf_client.h @@ -53,7 +53,7 @@ struct iavf_qv_info { struct iavf_qvlist_info { u32 num_vectors; - struct iavf_qv_info qv_info[1]; + struct iavf_qv_info qv_info[]; }; #define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF