Message ID | ZG1d51tGG4c97qqb@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 b10csp2513100vqo; Tue, 23 May 2023 17:51:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FtZQ+ATEbzqFWq3Ow5Xfcq9YJa0d5ydKs3rBpOlkrkzStrX874IF8ejQv9+tHHfGiWQjy X-Received: by 2002:a17:90a:b902:b0:24e:201e:dcbd with SMTP id p2-20020a17090ab90200b0024e201edcbdmr16405303pjr.21.1684889485630; Tue, 23 May 2023 17:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684889485; cv=none; d=google.com; s=arc-20160816; b=1J/FmBNkrHpxsOthAUP3Vp11EMz6DAYgPAPbsm5UEwh8IdVDhfOomJo09zAqnV1uoZ L9wghj536dzVmPC/DwwqHcO2RMjbTWyL/y8UlYir52QKz5V5SuCsNPxh4r22Te26RB2+ yMfpVFyyoIwvIVZ0USdFfMIpp1b1GHa4nDXHZeKyzqXPdK0U1IkAN5nDjwsmO0uzL/sn yONcGE7xsdvmwaSrXwTaPQmhvFANaj5+BzJEBhmla0Apxm1QZ3g00v6diq4R9XuymX6I 8jmWZLUANURZS9YrTKpR4tLhzBiV6H6QSBB7oRmpSroSb2f4q5q6owQibC+vmrNdEacB /sDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=pImi1hrj0NR+3M7BvxtIvn3K3YOOp28EyhvyhlhZ27s=; b=VnDHr0r81ZMdSCM3J0ymAVZSYjGomdQu+39NgEl9ekawtqpj0UdIxOt3R9O8NYntjS qd0kOB8Zhy98qZyNxJ/n80eRjC9ouw1DFrKWwYsbf21J2yvhtKKcjiB0i8fdD0azhb0P dUD6F30aD1Nt2WDB2KwjyaXrAz8RQF/aV3IW6viQiCvEs7aBnZCDPqP9lGpyBZL9JMnR cl/bfoZ1P5gDpKrw6L59JfUtoGgRZ/euXOjZ6nvoO4QbCUXWNM/H9IALWLcu0/7v3GUq brsEW/0KOSP3vsAooAd20D5Dm5PN+l8fyqTbj0/NfaUL4VCSkHYlYipewI6hSbrFWgcl HdFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f93Pabb7; 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 mv21-20020a17090b199500b0025027e0ad3dsi310389pjb.81.2023.05.23.17.51.03; Tue, 23 May 2023 17:51:25 -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=f93Pabb7; 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 S238570AbjEXAnf (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Tue, 23 May 2023 20:43:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233155AbjEXAne (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 23 May 2023 20:43:34 -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 C030EB5; Tue, 23 May 2023 17:43:31 -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 548C861B8C; Wed, 24 May 2023 00:43:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1A78C433D2; Wed, 24 May 2023 00:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684889010; bh=XqBRM7wMx7bhj22GlxezAhF4kwnXTfLHZNjhx8i29XE=; h=Date:From:To:Cc:Subject:From; b=f93Pabb7KcuqabWadPFXOC3R2rz9S0T3KbI+qvoqRkbAunayJIvMEs8EsZZFS++ys qAl0KX2/JhMe+2GGL32tEDHx8TL6795oLn4S5lAsxJ8takKfd/LqscgyCYuTPHYzdO XgFyn4OFB44MqzfOFj+s5GH/j/jY33s2Cq39S4+79w6Pc9/GS3BKsEfuVTBEFQa39M FKLJ+Hz7tQ47ebQefuIvv6AumkfczhVQhoEOiO3esr+CULGVvyftidR1/a+3DAnNib 8QuEXqLFMxFnMOLF6dbuYWiL2KIOUaGoYnzxL55FOgxR4iV8O6ZbQdlCD0dfsYn6J3 nQSZtWGLvIgZQ== Date: Tue, 23 May 2023 18:44:23 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org> Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] nfsd: Replace one-element array with flexible-array member Message-ID: <ZG1d51tGG4c97qqb@work> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 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?1766734677414693700?= X-GMAIL-MSGID: =?utf-8?q?1766734677414693700?= |
Series |
[next] nfsd: Replace one-element array with flexible-array member
|
|
Commit Message
Gustavo A. R. Silva
May 24, 2023, 12:44 a.m. UTC
One-element arrays are deprecated, and we are replacing them with
flexible array members instead. So, replace a one-element array
with a flexible-arrayº member in struct vbi_anc_data and refactor
the rest of the code, accordingly.
This results in no differences in binary output.
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/298
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
fs/nfsd/nfs4callback.c | 2 +-
fs/nfsd/xdr4.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On Tue, May 23, 2023 at 06:44:23PM -0600, Gustavo A. R. Silva wrote: > One-element arrays are deprecated, and we are replacing them with > flexible array members instead. So, replace a one-element array > with a flexible-arrayº member in struct vbi_anc_data and refactor I don't know what "struct vbi_anc_data" is. Is the patch description correct? > the rest of the code, accordingly. > > This results in no differences in binary output. > > Link: https://github.com/KSPP/linux/issues/79 > Link: https://github.com/KSPP/linux/issues/298 > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > fs/nfsd/nfs4callback.c | 2 +- > fs/nfsd/xdr4.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c > index 4039ffcf90ba..2c688d51135d 100644 > --- a/fs/nfsd/nfs4callback.c > +++ b/fs/nfsd/nfs4callback.c > @@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, > { > encode_nfs_cb_opnum4(xdr, OP_CB_RECALL_ANY); > encode_uint32(xdr, ra->ra_keep); > - encode_bitmap4(xdr, ra->ra_bmval, ARRAY_SIZE(ra->ra_bmval)); > + encode_bitmap4(xdr, ra->ra_bmval, 1); I find the new code less self-documenting. > hdr->nops++; > } > > diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h > index 510978e602da..68072170eac8 100644 > --- a/fs/nfsd/xdr4.h > +++ b/fs/nfsd/xdr4.h > @@ -899,7 +899,7 @@ struct nfsd4_operation { > struct nfsd4_cb_recall_any { > struct nfsd4_callback ra_cb; > u32 ra_keep; > - u32 ra_bmval[1]; > + u32 ra_bmval[]; This is not a placeholder for "1 or more elements". We actually want just a single u32 element in this array. Doesn't this change the sizeof(struct nfsd4_cb_recall_any) ? > }; > > #endif > -- > 2.34.1 >
On 5/23/23 19:01, Chuck Lever wrote: > On Tue, May 23, 2023 at 06:44:23PM -0600, Gustavo A. R. Silva wrote: >> One-element arrays are deprecated, and we are replacing them with >> flexible array members instead. So, replace a one-element array >> with a flexible-arrayº member in struct vbi_anc_data and refactor > > I don't know what "struct vbi_anc_data" is. Is the patch description > correct? Oops, copy/paste error. I'll fix it up. :) > > >> the rest of the code, accordingly. >> >> This results in no differences in binary output. >> >> Link: https://github.com/KSPP/linux/issues/79 >> Link: https://github.com/KSPP/linux/issues/298 >> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > >> --- >> fs/nfsd/nfs4callback.c | 2 +- >> fs/nfsd/xdr4.h | 2 +- >> 2 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c >> index 4039ffcf90ba..2c688d51135d 100644 >> --- a/fs/nfsd/nfs4callback.c >> +++ b/fs/nfsd/nfs4callback.c >> @@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, >> { >> encode_nfs_cb_opnum4(xdr, OP_CB_RECALL_ANY); >> encode_uint32(xdr, ra->ra_keep); >> - encode_bitmap4(xdr, ra->ra_bmval, ARRAY_SIZE(ra->ra_bmval)); >> + encode_bitmap4(xdr, ra->ra_bmval, 1); > > I find the new code less self-documenting. > > >> hdr->nops++; >> } >> >> diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h >> index 510978e602da..68072170eac8 100644 >> --- a/fs/nfsd/xdr4.h >> +++ b/fs/nfsd/xdr4.h >> @@ -899,7 +899,7 @@ struct nfsd4_operation { >> struct nfsd4_cb_recall_any { >> struct nfsd4_callback ra_cb; >> u32 ra_keep; >> - u32 ra_bmval[1]; >> + u32 ra_bmval[]; > > This is not a placeholder for "1 or more elements". We actually want > just a single u32 element in this array. Doesn't this change the > sizeof(struct nfsd4_cb_recall_any) ? I see. Yes, it does change the size. Can we replace it with a simple object of type u32? or do you actually need this to stay an array? Thanks -- Gustav > > >> }; >> >> #endif >> -- >> 2.34.1 >>
On Tue, May 23, 2023 at 07:11:37PM -0600, Gustavo A. R. Silva wrote: > > On 5/23/23 19:01, Chuck Lever wrote: > > On Tue, May 23, 2023 at 06:44:23PM -0600, Gustavo A. R. Silva wrote: > > > One-element arrays are deprecated, and we are replacing them with > > > flexible array members instead. So, replace a one-element array > > > with a flexible-arrayº member in struct vbi_anc_data and refactor > > > > I don't know what "struct vbi_anc_data" is. Is the patch description > > correct? > > Oops, copy/paste error. I'll fix it up. :) > > > > > > > > the rest of the code, accordingly. > > > > > > This results in no differences in binary output. > > > > > > Link: https://github.com/KSPP/linux/issues/79 > > > Link: https://github.com/KSPP/linux/issues/298 > > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > > > > --- > > > fs/nfsd/nfs4callback.c | 2 +- > > > fs/nfsd/xdr4.h | 2 +- > > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c > > > index 4039ffcf90ba..2c688d51135d 100644 > > > --- a/fs/nfsd/nfs4callback.c > > > +++ b/fs/nfsd/nfs4callback.c > > > @@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, > > > { > > > encode_nfs_cb_opnum4(xdr, OP_CB_RECALL_ANY); > > > encode_uint32(xdr, ra->ra_keep); > > > - encode_bitmap4(xdr, ra->ra_bmval, ARRAY_SIZE(ra->ra_bmval)); > > > + encode_bitmap4(xdr, ra->ra_bmval, 1); > > > > I find the new code less self-documenting. > > > > > > > hdr->nops++; > > > } > > > diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h > > > index 510978e602da..68072170eac8 100644 > > > --- a/fs/nfsd/xdr4.h > > > +++ b/fs/nfsd/xdr4.h > > > @@ -899,7 +899,7 @@ struct nfsd4_operation { > > > struct nfsd4_cb_recall_any { > > > struct nfsd4_callback ra_cb; > > > u32 ra_keep; > > > - u32 ra_bmval[1]; > > > + u32 ra_bmval[]; > > > > This is not a placeholder for "1 or more elements". We actually want > > just a single u32 element in this array. Doesn't this change the > > sizeof(struct nfsd4_cb_recall_any) ? > > I see. Yes, it does change the size. Can we replace it with a simple > object of type u32? or do you actually need this to stay an array? It's not impossible to make it a scalar u32, however... In this area of code, *_bmval is always a bitmap -- an array of u32s. Helpers like encode_bitmap4() assume an array. I think it would be less confusing overall to human readers if it remained an array. In this case, it is a single element array because CB_RECALL_ANY doesn't happen to use bits above the first 32-bit word of the bitmap. We could make it a 2-element array, I think, without harm. Send a patch for that, and Dai can test it to make sure there are no unexpected interoperability consequences. I hope that would avoid suspicious-looking array definitions. > > > }; > > > #endif > > > -- > > > 2.34.1 > > >
On 5/23/23 19:31, Chuck Lever wrote: > On Tue, May 23, 2023 at 07:11:37PM -0600, Gustavo A. R. Silva wrote: >> >> On 5/23/23 19:01, Chuck Lever wrote: >>> On Tue, May 23, 2023 at 06:44:23PM -0600, Gustavo A. R. Silva wrote: >>>> One-element arrays are deprecated, and we are replacing them with >>>> flexible array members instead. So, replace a one-element array >>>> with a flexible-arrayº member in struct vbi_anc_data and refactor >>> >>> I don't know what "struct vbi_anc_data" is. Is the patch description >>> correct? >> >> Oops, copy/paste error. I'll fix it up. :) >> >>> >>> >>>> the rest of the code, accordingly. >>>> >>>> This results in no differences in binary output. >>>> >>>> Link: https://github.com/KSPP/linux/issues/79 >>>> Link: https://github.com/KSPP/linux/issues/298 >>>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> >>> >>>> --- >>>> fs/nfsd/nfs4callback.c | 2 +- >>>> fs/nfsd/xdr4.h | 2 +- >>>> 2 files changed, 2 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c >>>> index 4039ffcf90ba..2c688d51135d 100644 >>>> --- a/fs/nfsd/nfs4callback.c >>>> +++ b/fs/nfsd/nfs4callback.c >>>> @@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, >>>> { >>>> encode_nfs_cb_opnum4(xdr, OP_CB_RECALL_ANY); >>>> encode_uint32(xdr, ra->ra_keep); >>>> - encode_bitmap4(xdr, ra->ra_bmval, ARRAY_SIZE(ra->ra_bmval)); >>>> + encode_bitmap4(xdr, ra->ra_bmval, 1); >>> >>> I find the new code less self-documenting. >>> >>> >>>> hdr->nops++; >>>> } >>>> diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h >>>> index 510978e602da..68072170eac8 100644 >>>> --- a/fs/nfsd/xdr4.h >>>> +++ b/fs/nfsd/xdr4.h >>>> @@ -899,7 +899,7 @@ struct nfsd4_operation { >>>> struct nfsd4_cb_recall_any { >>>> struct nfsd4_callback ra_cb; >>>> u32 ra_keep; >>>> - u32 ra_bmval[1]; >>>> + u32 ra_bmval[]; >>> >>> This is not a placeholder for "1 or more elements". We actually want >>> just a single u32 element in this array. Doesn't this change the >>> sizeof(struct nfsd4_cb_recall_any) ? >> >> I see. Yes, it does change the size. Can we replace it with a simple >> object of type u32? or do you actually need this to stay an array? > > It's not impossible to make it a scalar u32, however... > > In this area of code, *_bmval is always a bitmap -- an array of u32s. > Helpers like encode_bitmap4() assume an array. I think it would be > less confusing overall to human readers if it remained an array. > > In this case, it is a single element array because CB_RECALL_ANY > doesn't happen to use bits above the first 32-bit word of the > bitmap. I see. If this is never going to be treated as a flexible array, then it can stay as is. -fstrict-flex-arrays=3 should not warn about this because the array will never ever be tried to be accessed beyond element 1. :) Thanks for the feedback! -- Gustavo > > We could make it a 2-element array, I think, without harm. Send a > patch for that, and Dai can test it to make sure there are no > unexpected interoperability consequences. > > I hope that would avoid suspicious-looking array definitions. > > >>>> }; >>>> #endif >>>> -- >>>> 2.34.1 >>>>
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 4039ffcf90ba..2c688d51135d 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, { encode_nfs_cb_opnum4(xdr, OP_CB_RECALL_ANY); encode_uint32(xdr, ra->ra_keep); - encode_bitmap4(xdr, ra->ra_bmval, ARRAY_SIZE(ra->ra_bmval)); + encode_bitmap4(xdr, ra->ra_bmval, 1); hdr->nops++; } diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 510978e602da..68072170eac8 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -899,7 +899,7 @@ struct nfsd4_operation { struct nfsd4_cb_recall_any { struct nfsd4_callback ra_cb; u32 ra_keep; - u32 ra_bmval[1]; + u32 ra_bmval[]; }; #endif