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

Re: [PATCH v6 10/12] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers


  • To: Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Oleksandr Tyshchenko <olekstysh@xxxxxxxxx>
  • From: Leonid Komarianskyi <Leonid_Komarianskyi@xxxxxxxx>
  • Date: Thu, 4 Sep 2025 05:52:52 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=nJEkX+ZN5YOwXfTmzsec36wkjEKtOCnkm3E0Knpu+NY=; b=L7PfTIeEuAkjJcyotAO4J8PZiWCBz7aeQtTH2eE5ZrG7JCvKzGoJtemvFme3+O4DSZ1pjnCRJ7IW/vXJugKZJpDusii0WSOJNxMiGcX4MjD13HD/rjb8vpY1OKt8/dQwlhmh2GyA0s3SYIIw3TYs8HD567HN1FK/z8wE41umfkqUrUaptRrIxLADhXFsvPT2x6NkNEkuIQo7SlXUvwTUKzZltw9IXz/ly4/rNICcjl9vuV7aPgBbi3oXcnFJoc2xAHZlXrB//0BziIRuC/uXCA7+h4+dp7Wp4SzLrLVR1vQfcgaXfYXnRRl04ivDzutZKnoKvsr+IIw3yT7TWMPXTw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BHkqujKG+YNIvdqUJX98mMBROvb9Qh2rb4LntMkF9pLNz42shmd71OMbuSyz28fEKJTagzvvWSG8z4Q2b0GRgDQ7F95hG/gBKleS8FobU3YxB3GosX8d+XpwtjSF96NkNivtI8t0elPfwQ1k7e3PaL91fwCgDYi9A8S0ejrLnSZgZtFVbWIHpKFtoXnsXYFKRyDu79Ko+BxWmf394whOBvCAqYn85hAV+OsKVx/G/OsC+JPu1nn4MMwR4WXYA7vwZRStj22q6MnDRJjuVSZ9iAIjF5lqMW0B/gOtfckh7+vbzIg0TZlOv+lIELm0DXwpQVdEPdM2iWfjHIJ3lNsVHg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Thu, 04 Sep 2025 05:53:13 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcHN9FrhwGrEUPyUu8gbPtoBO0RbSCFF2AgAByMgA=
  • Thread-topic: [PATCH v6 10/12] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers

Hi Julien, Volodymyr and Oleksandr,

Thank you for your comments.

On 04.09.25 02:04, Julien Grall wrote:
> Hi,
> 
> On 03/09/2025 22:37, Volodymyr Babchuk wrote:
>> Hi Oleksandr,
>>
>> Oleksandr Tyshchenko <olekstysh@xxxxxxxxx> writes:
>>
>>
>> [...]
>>
>>>> +static inline uint32_t vgic_get_reg_offset(uint32_t reg, uint32_t 
>>>> spi_base,
>>>> +                                           uint32_t espi_base)
>>>> +{
>>>> +    if ( reg < espi_base )
>>>> +        return reg - spi_base;
>>>> +    else
>>>> +        return reg - espi_base;
>>>> +}
>>>
>>> I am wondering (I do not request a change) whether
>>> vgic_get_reg_offset() is really helpfull,
>>> e.g. is
>>>   offset = vgic_get_reg_offset(reg, GICD_IPRIORITYR, GICD_IPRIORITYRnE);
>>> much better than:
>>>   offset = reg < GICD_IPRIORITYRnE ? reg - GICD_IPRIORITYR : reg -
>>>   GICD_IPRIORITYRnE;
>  >>>
>> IMO, it is easy to make a mistake, because you need to write register
>> name 3 times. Can cause errors during copy-pasting.
> 
> +1.
> 
>   But I saw clever
>> trick by Mykola Kvach, something like this:
>>
>> #define vgic_get_reg_offset(addr, reg_name) ( addr < reg_name##nE ? \
>>   addr - reg_name : addr - reg_name##nE )
>>
>> And then you can just use this as
>>
>> offset = vgic_get_reg_offset(reg, GICD_IPRIORITYR)
>>
>> I don't know what maintainers think about this type of preprocessor
>> trickery, but in my opinion it is justified in this case, because it
>> leaves less room for a mistake.
> 
> I don't have a strong opinion between the macro version or the static 
> inline helper. However:
>    * for the macro version, you want to store 'addr' in a local variable 
> to ensure it is only evaluated once.
>    * for both case, I would prefer if we assert (for the static inline 
> helper) or use BUILD_BUG_ON() to confirm that spi_base < espi_base
> 
> Cheers,
> 

I was considering introducing this kind of macro, but I think it may 
lead to issues in the future because it requires us to always maintain 
the pattern reg_name/reg_name##nE for all registers. I understand that 
the names of the defines are unlikely to change, but I would prefer to 
use an inline function along with the suggested ASSERT(), as it seems 
more versatile to me.

Best regards,
Leonid

 


Rackspace

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