[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] xen/arm: Fix MISRA regression on R1.1, flexible array member not at the end
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
- Date: Thu, 2 May 2024 08:13:46 +0000
- Accept-language: en-GB, en-US
- Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BAUECygnRCTvIC2GrB7oVlQdHqf7g+0FQEkkv0kuxuU=; b=EXTzPtkjXI3kEuMXovBwDD8CvLQKdllPdy4Bu8pbgw3DbkdA8vTTJ0zFR601FemeCVUnt1cI1el8llsRQ/v8f/5/KxAHFiT+RIAcA2kzJaxnuFRm4xg9Xp56DjBICD3uk8iH1325OeEl59LmT6NZyG0a+2RwnqZbVdOq7a5BtrE8AosO/KcK2sx69FV8gYrp8aZ0xfWoOsm36nuyebsoCnVl0b0tGMI9iNbpbGFoZmoTRSThOZun3F39S79lqDlRTbFmErVfNpo0OgiM5LjiyUefA3dqRQpdG5hpt4vRE+Eg6gn8ASV58+UrUJ5EoViyf9ixelXgYkmnr+2SCe0i/g==
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BAUECygnRCTvIC2GrB7oVlQdHqf7g+0FQEkkv0kuxuU=; b=c+myNK9NQpRZ4UwreT5KlSYy7z6/fj6suwBYdA8kovsIf0eIJ4mkgsvqhO115UXKtuyUeLoDxwWI8wVdridYjIGu8ZisZBkR9F37zX0SMkSePTXkH5dlErd2tTSvZq65xmf1ZwdpxaLLg6GDpkNOU37/PMwuuUF4VnHYFJ+Kj4GYmd1fz8d0XBjtXg+92u1OkY50lP0qZB5/XewYRNy2oYdAZci92xIWPFnxS5evOumz1d7HSnbKSjc5npmys9WxBUbGyVma7x/NZY8L9lpU90wAhJXlg44SF5PqCl/cZuhWzJB0vwgiV5ag+YVBTYPWXQarJKikvARBBIqf7UfCiA==
- Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=RPbx0lNRbqCgn6scOdjUhrH4opZ7S5FDa+0st5LjEQbUke4hLE30zRT/+NXiE66MtouJ1DKqttoj8S1LKCsdqZ80x8elDqnFC+tJzlfw98RQg6+Z3uyD9xvkcUIhaXSejR8nXOHWQ5QkfZRCIg25CK0ZuXTIor+WaYuN9GIqDNOGdpx3/hTu1HFPx4Wvpn6SSxarj1M0ygTxA/2uOUqWtJF8DduzM10DrhCOxb6XeEdV39MuSISkQv1fmNI4mF9olAFW4lm1SSLmk3vm3GnB1PNG4egFhLgTOXBeIup5uqLrwG5eWBDPdv1DS5tsAiOpKCqNCUXglM+dPKP/6TlHtg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dgmemJqaOA3YdFbaPnAbcXOYHrY/fq7PLevpALvqgzIQCUGAMekR63F8xBP3pG3vuPr2xtAK3MTPZVY9HAtGatMHk16nPrIMD1dJ363n68/IUWZ066EGKw1OJii6i/XxUfbOs6gbXlhDBc8L794tl51+cP38oOhcDCGOyXwYUIgTGg0/YOOEXXUSgWWdiMkyxAEnKpaxqG029BpXT94YfqeDWeSBuoBdewWRLUEJNiogT5YbIzgr4Quie2N8t3EBoSqKgG9neMurOqhcuXdw7jEPuBNCz8ZRAvRp4Ycms29XKRvCpsS5SAqt5ubNjk7Asa59VfTy6mokkhm0tFII2g==
- Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Cc: "consulting @ bugseng . com" <consulting@xxxxxxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Thu, 02 May 2024 08:14:15 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Nodisclaimer: true
- Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Thread-index: AQHamu72Eq1RpEGs60mNp9DIfY8mn7GAr6+AgAFEGQCAAYYzgIAABVAAgAACyoCAABlOgA==
- Thread-topic: [PATCH 2/2] xen/arm: Fix MISRA regression on R1.1, flexible array member not at the end
> On 2 May 2024, at 07:43, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>
> On 02.05.2024 08:33, Luca Fancellu wrote:
>>
>>
>>> On 2 May 2024, at 07:14, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>>>
>>> On 01.05.2024 08:57, Luca Fancellu wrote:
>>>> Hi Jan,
>>>>
>>>>> On 30 Apr 2024, at 12:37, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>>>>>
>>>>> On 30.04.2024 13:09, Luca Fancellu wrote:
>>>>>> --- a/xen/arch/arm/include/asm/setup.h
>>>>>> +++ b/xen/arch/arm/include/asm/setup.h
>>>>>> @@ -64,18 +64,20 @@ struct membank {
>>>>>> };
>>>>>>
>>>>>> struct membanks {
>>>>>> - unsigned int nr_banks;
>>>>>> - unsigned int max_banks;
>>>>>> + __struct_group(membanks_hdr, common, ,
>>>>>> + unsigned int nr_banks;
>>>>>> + unsigned int max_banks;
>>>>>> + );
>>>>>> struct membank bank[];
>>>>>> };
>>>>>
>>>>> I'm afraid I can't spot why __struct_group() is needed here. Why would
>>>>> just
>>>>> one of the two more straightforward
>>>>>
>>>>> struct membanks {
>>>>> struct membanks_hdr {
>>>>> unsigned int nr_banks;
>>>>> unsigned int max_banks;
>>>>> );
>>>>> struct membank bank[];
>>>>> };
>>>>>
>>>>
>>>> At the first sight I thought this solution could have worked, however GCC
>>>> brought me back down to earth
>>>> remembering me that flexible array members can’t be left alone in an empty
>>>> structure:
>>>>
>>>> /data_sdc/lucfan01/gitlab_mickledore_xen/xen/xen/arch/arm/include/asm/setup.h:70:6:
>>>> error: declaration does not declare anything [-Werror]
>>>> 70 | };
>>>> | ^
>>>> /data_sdc/lucfan01/gitlab_mickledore_xen/xen/xen/arch/arm/include/asm/setup.h:71:20:
>>>> error: flexible array member in a struct with no named members
>>>> 71 | struct membank bank[];
>>>> | ^~~~
>>>> [...]
>>>
>>> Since for patch 1 you looked at Linux'es uapi/linux/stddef.h, the solution
>>> to this lies there, in __DECLARE_FLEX_ARRAY(). Alongside or instead of
>>> borrowing __struct_group(), we could consider borrowing this as well. Or
>>> open-code it just here, for the time being (perhaps my preference). Yet
>>> it's not clear to me that doing so will actually be enough to make things
>>> work for you.
>>
>> I looked also into __DECLARE_FLEX_ARRAY(), but then decided __struct_group()
>> was enough for my purpose, can I ask the technical reasons why it would be
>> your
>> preference? Is there something in that construct that is a concern for you?
>
> I don't like either construct very much, but of the two __DECLARE_FLEX_ARRAY()
> looks slightly more "natural" for what is wanted and how it's done.
> __struct_group() introducing twice the (effectively) same structure feels
> pretty odd, for now at least. It's not even entirely clear to me whether there
> aren't pitfalls, seeing that the C spec differentiates named and unnamed
> struct fields in a few cases. For __DECLARE_FLEX_ARRAY(), otoh, I can't
> presently see any reason to suspect possible corner cases.
>
> Yet as said before - I'm not sure __DECLARE_FLEX_ARRAY() alone would be enough
> for what you want to achieve.
Mmm yes, I think I would still have problems because container_of wants a named
member,
so __DECLARE_FLEX_ARRAY() doesn’t help much alone, if I’m not missing something
obvious.
If you believe however that importing __struct_group() only for this instance
is not enough to justify
its presence in the codebase, I could open-code it, provided that maintainers
are ok with that.
In any case it would be used soon also for other architectures using bootinfo.
|