From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Julien Grall <julien@xen.org>
Cc: xen-devel@lists.xenproject.org, sstabellini@kernel.org,
michal.orzel@amd.com, xenia.ragiadakou@amd.com,
ayan.kumar.halder@amd.com, consulting@bugseng.com,
jbeulich@suse.com, andrew.cooper3@citrix.com,
roger.pau@citrix.com, Paul Durrant <paul@xen.org>,
George Dunlap <george.dunlap@citrix.com>, Wei Liu <wl@xen.org>
Subject: Re: [XEN PATCH][for-4.19 8/9] xen/types: address Rule 10.1 for DECLARE_BITMAP use
Date: Mon, 09 Oct 2023 09:44:59 +0200 [thread overview]
Message-ID: <f8ce739932699bb44900570c262acbc8@bugseng.com> (raw)
In-Reply-To: <354c6138-509e-4106-9a27-3c75c85b85e5@xen.org>
On 06/10/2023 16:47, Julien Grall wrote:
> Hi Nicola,
>
> On 06/10/2023 11:10, Nicola Vetrini wrote:
>> On 06/10/2023 11:34, Julien Grall wrote:
>>> Hi Nicola,
>>>
>>> On 06/10/2023 09:26, Nicola Vetrini wrote:
>>>> Given its use in the declaration
>>>> 'DECLARE_BITMAP(features, IOMMU_FEAT_count)' the argument
>>>> 'bits' has essential type 'enum iommu_feature', which is not
>>>> allowed by the Rule as an operand to the addition operator
>>>> in macro 'BITS_TO_LONGS'.
>>>>
>>>> A comment in BITS_TO_LONGS is added to make it clear that
>>>> values passed are meant to be positive.
>>>
>>> I am confused. If the value is meant to be positive. Then...
>>>
>>>>
>>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>>> ---
>>>> xen/include/xen/iommu.h | 2 +-
>>>> xen/include/xen/types.h | 1 +
>>>> 2 files changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
>>>> index 0e747b0bbc1c..34aa0b9b5b81 100644
>>>> --- a/xen/include/xen/iommu.h
>>>> +++ b/xen/include/xen/iommu.h
>>>> @@ -360,7 +360,7 @@ struct domain_iommu {
>>>> #endif
>>>> /* Features supported by the IOMMU */
>>>> - DECLARE_BITMAP(features, IOMMU_FEAT_count);
>>>> + DECLARE_BITMAP(features, (int)IOMMU_FEAT_count);
>>>
>>> ... why do we cast to (int) rather than (unsigned int)? Also, I think
>>> this cast deserve a comment on top because this is not a very obvious
>>> one.
>>>
>>>> /* Does the guest share HAP mapping with the IOMMU? */
>>>> bool hap_pt_share;
>>>> diff --git a/xen/include/xen/types.h b/xen/include/xen/types.h
>>>> index aea259db1ef2..936e83d333a0 100644
>>>> --- a/xen/include/xen/types.h
>>>> +++ b/xen/include/xen/types.h
>>>> @@ -22,6 +22,7 @@ typedef signed long ssize_t;
>>>> typedef __PTRDIFF_TYPE__ ptrdiff_t;
>>>> +/* Users of this macro are expected to pass a positive value */
>>>> #define BITS_TO_LONGS(bits) \
>>>> (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
>>>> #define DECLARE_BITMAP(name,bits) \
>>>
>>> Cheers,
>>
>> See [1] for the reason why I did so. I should have mentioned that in
>> the commit notes, sorry.
>> In short, making BITS_TO_LONGS essentially unsigned would cause a
>> cascade of build errors and
>> possibly other essential type violations.
> Can you share some of the errors?
>
I don't have that build log at hand, but you can reproduce them by
defining
#define BYTES_PER_LONG (_AC(1,U) << LONG_BYTEORDER)
#define BITS_PER_LONG (BYTES_PER_LONG << 3)
#define BITS_TO_LONGS(bits) \
(((bits)+BITS_PER_LONG-1U)/BITS_PER_LONG)
and then fiddle a bit with the signedness of the constants in
xen/arch/x86/include/asm/page-bits.h.
They are essentially pointer comparison errors in the instances of 'min'
and 'max'
that involve those macros or macros derived from those, which make the
build fail because
they (rightfully) trigger a warning from gcc.
>> If this is to be fixed that way, the effort required
>> is far greater. Either way, a comment on top of can be added, along
>> the lines of:
>>
>> Leaving this as an enum would violate MISRA C:2012 Rule 10.1
>
> I read this as you are simply trying to silence your tool. I think
> this the wrong approach as you are now making the code confusing for
> the reader (you pass a signed int to a function that is supposed to
> take a positive number).
>
> I appreciate that this will result to more violations at the
> beginning. But the whole point of MISRA is to make the code better.
>
> If this is too complex to solve now, then a possible option is to
> deviate for the time being.
>
> Cheers,
>
You have a point in that is sort of hides a deeper issue that is
constituted by the
signedness of the macro, but I'd suggest adding to this patch a comment
explaining what
needs to be done, rather than a deviation comment that hides the
violations. The reason
is that in the former case, if you put an unsigned argument too big to
fit in an integer
it will generate a new report, while if a negative argument is used,
there is a warning
comment on the macro definition (not an ideal countermeasure, though).
>>
>> [1]
>> https://lore.kernel.org/xen-devel/6495ba58bda01eae1f4baa46096424eb@bugseng.com/
>>
--
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
next prev parent reply other threads:[~2023-10-09 7:45 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-06 8:26 [XEN PATCH 0/9] address violations of MISRA C:2012 Rule 10.1 Nicola Vetrini
2023-10-06 8:26 ` [XEN PATCH][for-4.19 1/9] xen/include: add macro LOWEST_POW2 Nicola Vetrini
2023-10-06 9:29 ` Julien Grall
2023-10-06 10:02 ` Nicola Vetrini
2023-10-06 10:22 ` Julien Grall
2023-10-06 10:34 ` Nicola Vetrini
2023-10-06 14:35 ` Julien Grall
2023-10-06 15:36 ` Nicola Vetrini
2023-10-07 0:05 ` Stefano Stabellini
2023-10-07 0:29 ` Stefano Stabellini
2023-10-09 8:23 ` Nicola Vetrini
2023-10-06 16:35 ` andrew.cooper3
2023-10-09 7:08 ` Nicola Vetrini
2023-10-06 8:26 ` [XEN PATCH][for-4.19 2/9] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 Nicola Vetrini
2023-10-10 0:45 ` Stefano Stabellini
2023-10-06 8:26 ` [XEN PATCH][for-4.19 3/9] xen/pdx: amend definition of PDX_GROUP_COUNT Nicola Vetrini
2023-10-06 8:26 ` [XEN PATCH 4/9] x86_64/mm: express macro CNT using LOWEST_POW2 Nicola Vetrini
2023-10-06 8:26 ` [XEN PATCH 5/9] x86/cpu-policy: address violations of MISRA C Rule 10.1 Nicola Vetrini
2023-10-06 17:57 ` Andrew Cooper
2023-10-09 7:13 ` Nicola Vetrini
2023-10-06 8:26 ` [XEN PATCH 6/9] x86/io_apic: address violation of MISRA C:2012 " Nicola Vetrini
2023-10-10 0:48 ` Stefano Stabellini
2023-10-06 8:26 ` [XEN PATCH 7/9] x86/mce: Move MC_NCLASSES into the enum mctelem_class Nicola Vetrini
2023-10-06 19:11 ` andrew.cooper3
2023-10-09 7:15 ` Nicola Vetrini
2023-10-06 8:26 ` [XEN PATCH][for-4.19 8/9] xen/types: address Rule 10.1 for DECLARE_BITMAP use Nicola Vetrini
2023-10-06 9:34 ` Julien Grall
2023-10-06 10:10 ` Nicola Vetrini
2023-10-06 14:47 ` Julien Grall
2023-10-07 1:04 ` Stefano Stabellini
2023-10-09 7:48 ` Nicola Vetrini
2023-10-09 9:09 ` Julien Grall
2023-10-10 1:09 ` Stefano Stabellini
2023-10-10 10:53 ` Julien Grall
2023-10-10 12:07 ` Nicola Vetrini
2023-10-10 12:13 ` Julien Grall
2023-10-10 12:15 ` Julien Grall
2023-10-10 12:55 ` Nicola Vetrini
2023-10-10 14:20 ` Nicola Vetrini
2023-10-09 7:44 ` Nicola Vetrini [this message]
2023-10-06 8:26 ` [XEN PATCH 9/9] xen/compat: address Rule 10.1 for macros CHECK_SIZE Nicola Vetrini
2023-10-10 1:02 ` Stefano Stabellini
2023-10-10 16:00 ` Andrew Cooper
2023-10-10 16:06 ` Nicola Vetrini
2023-10-10 16:19 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f8ce739932699bb44900570c262acbc8@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayan.kumar.halder@amd.com \
--cc=consulting@bugseng.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=paul@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
--cc=xenia.ragiadakou@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.