From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
michal.orzel@amd.com, xenia.ragiadakou@amd.com,
ayan.kumar.halder@amd.com, consulting@bugseng.com,
andrew.cooper3@citrix.com, roger.pau@citrix.com,
Simone Ballarin <simone.ballarin@bugseng.com>,
Doug Goldstein <cardoe@cardoe.com>,
George Dunlap <george.dunlap@citrix.com>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
xen-devel@lists.xenproject.org
Subject: Re: [XEN PATCH][for-4.19 v4 1/8] xen/include: add macro ISOLATE_LOW_BIT
Date: Tue, 31 Oct 2023 13:07:01 +0100 [thread overview]
Message-ID: <f6c499316d9c619627cdbd72e02417b1@bugseng.com> (raw)
In-Reply-To: <1178b79c-d6a3-a46c-5556-3fb5964dc051@suse.com>
On 2023-10-31 11:20, Jan Beulich wrote:
> On 31.10.2023 11:03, Nicola Vetrini wrote:
>> On 2023-10-31 09:28, Nicola Vetrini wrote:
>>> On 2023-10-31 08:43, Jan Beulich wrote:
>>>> On 30.10.2023 23:44, Stefano Stabellini wrote:
>>>>> On Mon, 30 Oct 2023, Jan Beulich wrote:
>>>>>> On 27.10.2023 15:34, Nicola Vetrini wrote:
>>>>>>> --- a/xen/include/xen/macros.h
>>>>>>> +++ b/xen/include/xen/macros.h
>>>>>>> @@ -8,8 +8,14 @@
>>>>>>> #define DIV_ROUND(n, d) (((n) + (d) / 2) / (d))
>>>>>>> #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
>>>>>>>
>>>>>>> -#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
>>>>>>> -#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
>>>>>>> +/*
>>>>>>> + * Given an unsigned integer argument, expands to a mask where
>>>>>>> just the least
>>>>>>> + * significant nonzero bit of the argument is set, or 0 if no
>>>>>>> bits
>>>>>>> are set.
>>>>>>> + */
>>>>>>> +#define ISOLATE_LOW_BIT(x) ((x) & -(x))
>>>>>>
>>>>>> Not even considering future Misra changes (which aiui may require
>>>>>> that
>>>>>> anyway), this generalization of the macro imo demands that its
>>>>>> argument
>>>>>> now be evaluated only once.
>>>>>
>>>>> Fur sure that would be an improvement, but I don't see a trivial
>>>>> way
>>>>> to
>>>>> do it and this issue is also present today before the patch.
>>>>
>>>> This was an issue here for MASK_EXTR() and MASK_INSR(), yes, but the
>>>> new
>>>> macro has wider use, and there was no issue elsewhere so far.
>>>>
>>>>> I think it
>>>>> would be better to avoid scope-creeping this patch as we are
>>>>> already
>>>>> at
>>>>> v4 for something that was expected to be a trivial mechanical
>>>>> change.
>>>>> I
>>>>> would rather review the fix as a separate patch, maybe sent by you
>>>>> as
>>>>> you probably have a specific implementation in mind?
>>>>
>>>> #define ISOLATE_LOW_BIT(x) ({ \
>>>> typeof(x) x_ = (x); \
>>>> x_ & -x_; \
>>>> })
>>>>
>>>> Hard to see the scope creep here. What I would consider scope creep
>>>> I
>>>> specifically didn't even ask for: I'd like this macro to be
>>>> overridable
>>>> by an arch. Specifically (see my earlier naming hint) I'd like to
>>>> use
>>>> x86's BMI insn BLSI in the context of "x86: allow Kconfig control
>>>> over
>>>> psABI level", when ABI v2 or higher is in use.
>>>
>>> I appreciate you suggesting an implementation; I'll send a v5
>>> incorporating it.
>>
>> There's an issue with this approach, though: since the macro is used
>> indirectly
>> in expressions that are e.g. case labels or array sizes, the build
>> fails
>> (see [1] for instance).
>> Perhaps it's best to leave it as is?
>
> Hmm. I'm afraid it's not an option to "leave as is", not the least
> because
> - as said - I'm under the impression that another Misra rule requires
> macro arguments to be evaluated exactly once. Best I can think of right
> away is to have a macro for limited use (to address such build issues)
> plus an inline function (for general use). But yes, maybe that then
> indeed
> needs to be a 2nd step.
>
> Jan
>
>> [1]
>> https://gitlab.com/xen-project/people/bugseng/xen/-/jobs/5423693947
>>
There is no such MISRA Rule afaik: R23.7 is similar, but only for C11
generic selections.
--
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
next prev parent reply other threads:[~2023-10-31 12:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1698410970.git.nicola.vetrini@bugseng.com>
[not found] ` <dca236bf9199f596bafb35eb48d81adc280d8cca.1698410970.git.nicola.vetrini@bugseng.com>
2023-10-27 20:48 ` [XEN PATCH][for-4.19 v4 1/8] xen/include: add macro ISOLATE_LOW_BIT Stefano Stabellini
2023-10-30 15:40 ` Jan Beulich
2023-10-30 22:44 ` Stefano Stabellini
2023-10-31 7:43 ` Jan Beulich
2023-10-31 8:28 ` Nicola Vetrini
2023-10-31 10:03 ` Nicola Vetrini
2023-10-31 10:20 ` Jan Beulich
2023-10-31 12:07 ` Nicola Vetrini [this message]
2023-11-16 8:26 ` Jan Beulich
2023-11-16 10:02 ` Nicola Vetrini
2023-11-16 10:25 ` Jan Beulich
2023-11-17 0:43 ` Stefano Stabellini
2023-11-17 7:07 ` Jan Beulich
2023-11-17 9:55 ` Nicola Vetrini
2023-11-18 2:20 ` Stefano Stabellini
2023-11-09 7:18 ` Jan Beulich
2023-11-10 0:36 ` Stefano Stabellini
[not found] ` <6efab48e9340916f23c94baf5c189d1d1c6ab7e6.1698410970.git.nicola.vetrini@bugseng.com>
2023-10-27 20:50 ` [XEN PATCH][for-4.19 v4 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class Stefano Stabellini
2023-10-31 8:50 ` Nicola Vetrini
[not found] ` <8e56caec1dfa2ef9a528d58935f16c537adfdbea.1698410970.git.nicola.vetrini@bugseng.com>
2023-10-30 15:22 ` [XEN PATCH][for-4.19 v4 4/8] x86_64/mm: express macro CNT using ISOLATE_LOW_BIT Jan Beulich
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=f6c499316d9c619627cdbd72e02417b1@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayan.kumar.halder@amd.com \
--cc=cardoe@cardoe.com \
--cc=consulting@bugseng.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=simone.ballarin@bugseng.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.