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

Re: [PATCH 2/2] xen/arm: gnttab: modify macros to evaluate all arguments and only once


  • To: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 5 May 2022 13:55:51 +0200
  • 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=0Ip9NLDbIkinEk8L3v7zxIbR5eNjq31A39HEQEZfsmA=; b=n6Yamit5blYAEGNIuAGrMqJalTCYDZIMB0JRGsN936dt0/F9dqrsiRFgwv3mf3JKfrRRW05YQ6F0MX9//1k2yvL89TfoPhrXMXUhEsRoA8crGnqcYPvokt2o+23q0yPOvb3gHnRG9z8SyCsXrjQ75eY+ZTOoZX7Vxp4TDcETP2nhM5pqAdW2rxjUiYFyQ83DSAPsHL0fH5NhkM+i7tXyrRLOOAhVfXCa0Cqn2xIHT1BEqEt5xl0CxaH6FO1aobUJUOkWDqD2AkGsY5qB6YRcC+N7QLhI2nlSHBJsicIjuknEbtOyr9egt9beSaK12MC6GOcBWig5LaI9INAXIs+Y8A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B31V0Fw5uzWM/PQeOgp6v8uNJezWqvCSWr8GEFDTJ+0cHmHxFjXn6nmckA8c9KBNEKlXbG7DGDQoqNgGvszfj8RkqtPU/mvLiE81dPEm2AtLXTJabY+SF9OtdGaDYf5YDtXFsYQYlILflDtJaBsHsih9C04J3x/5jNU0M4/7h26g75JGAq+VE7qG/dT2W4YTES/zWOM6GEMlN2a5NSH8j7Q08hqLMnXbwH/pKuOmvanCQySlFWyd0kEEuEVvJN0MMqr29y5RvulXvbUCfY+7+pys+w8x6cpPR6729sQ2sL3x1Wm7Q5NUpFHOjvPbvEdjA/3HU4nvO5Y5NY1mchBRbw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 05 May 2022 11:56:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.05.2022 13:25, Michal Orzel wrote:
> On 05.05.2022 13:20, Jan Beulich wrote:
>> On 05.05.2022 12:36, Michal Orzel wrote:
>>> Modify macros to evaluate all the arguments and make sure the arguments
>>> are evaluated only once. While doing so, use typeof for basic types
>>> and use const qualifier when applicable.
>>
>> Why only for basic types? To take an example, passing void * into
>> gnttab_need_iommu_mapping() would imo also better not work.
>>
> Just by looking at the majority of macros in Xen, typeof is used mostly for 
> basic data types.
> Also I think it is better to explictly use a struct type for better 
> readability.
> Otherwise one need to search in other files, to what type does typeof 
> evaluates.
> 
>>> @@ -98,13 +104,36 @@ int replace_grant_host_mapping(unsigned long gpaddr, 
>>> mfn_t mfn,
>>>  })
>>>  
>>>  #define gnttab_shared_gfn(d, t, i)                                       \
>>> -    (((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i])
>>> +    ({                                                                   \
>>> +        const struct domain *d_ = (d);                                   \
>>> +        const struct grant_table *t_ = (t);                              \
>>> +        const typeof(i) i_ = (i);                                        \
>>> +                                                                         \
>>> +        if ( d_ != NULL )                                                \
>>> +            ASSERT(d_->grant_table == t_);                               \
>>
>> I'm puzzled by this NULL check (and the similar instance further down):
>> Are you suggesting NULL can legitimately come into here? If not, maybe
>> better ASSERT(d_ && d_->grant_table == t_)?
>>
> Example:
> NULL is coming explictly from macro gnttab_get_frame_gfn right above 
> gnttab_shared_gfn.

Hmm, that's pretty odd (and Arm specific). Just like with the other remark
above, it'll be the Arm maintainers to judge, but here I think the NULLs
would better be done away with, by introducing intermediate macros, e.g.

#define gnttab_shared_gfn_(t, i) ...

#define gnttab_shared_gfn(d, t, i) ({                                  \
    const typeof(t) t_ = (t);                                          \
    ASSERT((d)->grant_table == t_);                                    \
    gnttab_shared_gfn_(t_, i);                                         \
})

#define gnttab_get_frame_gfn(gt, st, idx) ({                           \
   (st) ? gnttab_status_gfn_(gt, idx)                                  \
        : gnttab_shared_gfn_(gt, idx);                                 \
})

Jan




 


Rackspace

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