[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] x86/gen-cpuid: Avoid violations of Misra rule 1.3


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 2 Aug 2023 14:31:20 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • 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=2TbtnL/m8prfhEqUqlTW4I8qNZGxszTAgBNOj+2dmDg=; b=Q0AXBDxnHqiY4NUeEwp2WuYCdRUZaXJocnuM69RupY5gGZha1yYv51UoK6xHxQwuXHAUSKClfHuvHOTCKBm/8L+ZFWsfSUyiR0AjspsZRjGf/vhEJR08FhwSASCiwSKvKkXeUr1zd9hlnZsG3WA5muLV+IPg7Ss7V9swOrF0AS5cS4+YqBoNnCQIUZ+vVggwSfdj8wBK/v84eZKpwrmKfj11tKnC5nNhASe8eLji+IU9oj+FVJQyj9Yl//cvOO43OV8svScSKE/XOcNEeRPxbwoxdQGH9HhvnbmAzqJuwmS4/8vNIKYMsJlX4IRIAL1vYODQnCN0zYduXAE2oqaSdA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oJMijDyyu/ZOEaWeIyh4d3OEaHhja83ko2FAYAZWOyK4OVg6npDkBcOR+CaKDGNHiUOJ3/FdSW33twh9AVp6VJoQtRnwBZVBmfHotPt8/fxLA0ksLG70g2NniVcsLsZ6bNxC2mFoECUN5LxjCYnm5QLU74xf9p5deVd9u97W/Wps0uSjvlc4xhKluRx8WTU4pMlLHAs/NJTapfeMzdO6o5KpVWcngvERQ27Ljb3nUrvf9BGbqqKii3HzJMufiup7R/xuEUay3FF3yzPhsDKm1sfaOl0rIsEMCBc3TS+9lmKF/qhGIsIMl5sUiXnJAf5iWbwJtmD2sRoujuI/D/XspA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 02 Aug 2023 13:31:43 +0000
  • Ironport-data: A9a23:rLbff6KhUMdV1lfcFE+REJQlxSXFcZb7ZxGr2PjKsXjdYENS0mFUx zcZDz2CPq6NYmv2fYx+Poy09kwF7ZGBnYViQFNlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHvykU7Ss1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpKrfrawP9TlK6q4mhA7gRkPakjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5pKF4Vy +UnLgoxNDKB3sWk642YVNJF05FLwMnDZOvzu1lG5BSAVbMMZ8+GRK/Ho9hFwD03m8ZCW+7EY NYUYiZuaxKGZABTPlAQC9Q1m+LAanvXKmUE7g7K4/VvpTGLl2Sd05C0WDbRUvWMSd9YgQCzo WXe8n6iKhobKMae2XyO9XfEaurnxHqrAtxDSu3knhJsqEaXw3AuLSYGbgK2+9W3p3CfdfkCe mVBr0LCqoB3riRHVOLVXRe1vXqFtR40QMdLHqsx7wTl4rXQyxaUAC4DVDEpQNonv8gyTHo02 0OTntXoLTZyv6aYT33b/bCRxRuiNC5QIWIcaCssSQoe/8KlsIw1lgjITNtoDOiylNKdJN3r6 zWDrSx7jbNMi8cOjv2/5Qqe22nqoYXVRAko4AmRRnii8g5yeI+iYcqv9ETf6vFDao2eSzFto UQ5piRX18hWZbnlqcBHaLxl8G2BjxpdDADhvA==
  • Ironport-hdrordr: A9a23:aA43sqhtgF/DCgR6Hqbz9CJHE3BQXgYji2hC6mlwRA09TyX4rb HUoB1/73TJYVkqNk3I9ersBEDCewK5yXcN2+gs1O6ZPDUO21HYTr2Kj7GSuwEIcheWnoRgPM FbAs1D4bbLYmSS4/yX3OD2KadG/DArytHPuc7Oi11WZUVBbaV46gdwDQyWVndxWBJNCfMCZf mhD4581kOdRUg=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 02/08/2023 2:22 pm, Jan Beulich wrote:
> On 02.08.2023 15:10, Andrew Cooper wrote:
>> Add the script to the X86 section in ./MAINTAINERS.
>>
>> Structures or unions without any named members aren't liked by Misra
>> (nor the C standard). Avoid emitting such for leaves without any known
>> bits.
>>
>> The placeholders are affected similarly, but are only visible to MISRA in the
>> middle of a patch series adding a new leaf.  The absence of a name was
>> intentional as these defines need to not duplicate names.
>>
>> As that's not deemed acceptable any more, move placeholder processing into 
>> the
>> main loop and append the the word number to generate unique names.
>>
>>   $ diff cpuid-autogen-{before,after}.h
>>   @@ -1034,7 +1034,7 @@
>>        bool intel_psfd:1, ipred_ctrl:1, rrsba_ctrl:1, ddp_ctrl:1,     ...
>>
>>    #define CPUID_BITFIELD_14 \
>>   -    bool :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1,   ...
>>   +    uint32_t _placeholder_14
>>
>>    #define CPUID_BITFIELD_15 \
>>        bool :1, :1, :1, :1, avx_vnni_int8:1, avx_ne_convert:1, :1,    ...
>>   @@ -1043,19 +1043,19 @@
>>        bool rdcl_no:1, eibrs:1, rsba:1, skip_l1dfl:1, intel_ssb_no:1, ...
>>
>>    #define CPUID_BITFIELD_17 \
>>   -    bool :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1,   ...
>>   +    uint32_t _placeholder_17
>>
>>    #define CPUID_BITFIELD_18 \
>>   -    uint32_t :32 /* placeholder */
>>   +    uint32_t _placeholder_18
>>
>>    #define CPUID_BITFIELD_19 \
>>   -    uint32_t :32 /* placeholder */
>>   +    uint32_t _placeholder_19
>>
>>    #define CPUID_BITFIELD_20 \
>>   -    uint32_t :32 /* placeholder */
>>   +    uint32_t _placeholder_20
>>
>>    #define CPUID_BITFIELD_21 \
>>   -    uint32_t :32 /* placeholder */
>>   +    uint32_t _placeholder_21
>>
>>    #endif /* __XEN_X86__FEATURESET_DATA__ */
>>
>> No functional change.
>>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Thanks.

> with one question below.
>
>> v2:
>>  * Write it more pythonically.
> Yeah, you know I don't speak Python very well. I was glad I got it to
> work without overly much hassle.

Generally speaking, if you've got bool-like variables around loops,
there's a neater way of expressing it.

This one relies on truthy/falsy values where "" is treated as false. 
(Same too with None, 0, (,), {} and [] for the other primitive datatypes).

>
>> @@ -382,7 +382,10 @@ def crunch_numbers(state):
>>  
>>              names.append(name.lower())
>>  
>> -        state.bitfields.append("bool " + ":1, ".join(names) + ":1")
>> +        if any(names):
>> +            state.bitfields.append("bool " + ":1, ".join(names) + ":1")
>> +        else:
>> +            state.bitfields.append("uint32_t _placeholder_%s" % (word, ))
> I thought % could be used here, but then I wouldn't have known to use
> %s (elsewhere we use %u), nor to add an empty argument (which I see
> is done in a few other places as well, but not uniformly when %s is
> used). I assume there's a reason for the specific way you've done it
> here?

Hmm.  That was taken from your version.

In python, %s means "call str() on whatever you have".  Similarly, %r
means repr().  str() on an integer behaves as %d.

But yes, %u would be better here, and consistent with the rest of the
script.

Happy to fix on commit.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.