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

Re: [XEN PATCH][for-4.19 v4 1/8] xen/include: add macro ISOLATE_LOW_BIT


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 31 Oct 2023 11:20:48 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=S5glKg/6Malbpd9Q1r5x3CQww802ehDsgVCSD+2P/KA=; b=eEhf4WLFb9jTGkzbN1kvPfs2jCKamBwWe0GnJxdAyw470NMOBoxOnDRoHM46of5jxqnHRkgfvSF735J3fIkahGwQ+1sZ/fR/A7LK3y8Iun+kgjSydi2LlWQTtWdonkoyhVJAxCqH0i8zZCwmwuIuZPlvmM1MSW8VJaGrLOqjqkgBtDXgzpXdcYC4xEAbg22sL/tMgcaREsfPVsbR5o4EECkeH7KBJ69/yRjMZKFLg8seVG8BHZhZZBUNSTYo/kPtZdgtlfbJiZwpAtocoAlw6lXrPGhJdw9sxLfy/AYgVI2Zzc4ec1gPZP6ZNf2UUeDT0jdBPkjyH4tBCzRBAfNNEg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NdO6c5KmrJsdEyhkKsZJsnUSV/DyhxldzHSdJEoRV6zhRkX/Hk9fFKHyDyBcAFsUgr+ah9zopq2/3mqdc38K4jneF/9xWTqawMmwWR/tt7ERhJKIiCj0iqVJWuFPb/Vs/UcX4Y1Q1vYiqftPN02qcZ7Gz8FtfQky/6jyIZdqGN1X+6kL0q+4zMrqsejjo5fiWTsx64lm0BPNJIf3P1zK5Ln2mWgPMr3TuVOp0RBSP01S6TTnQHcylClFQyN42iPJlhb4Oa1jyP/hisDF/Aec7K79RKik48oSgzHqCZXVUytf29W2jehkfxtnVCbQullDO+YrSJSz0ETWl9NvSlV1DA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, michal.orzel@xxxxxxx, xenia.ragiadakou@xxxxxxx, ayan.kumar.halder@xxxxxxx, consulting@xxxxxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger.pau@xxxxxxxxxx, Simone Ballarin <simone.ballarin@xxxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 31 Oct 2023 10:21:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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
> 




 


Rackspace

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