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

Re: [PATCH v3 3/4] xen/arm: vgic: free eSPIs using the bitmap index


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Mykola Kvach <Mykola_Kvach@xxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Mon, 14 Sep 2026 17:55:29 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=epam.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=vIcYhh7rNGzaEgLlSvJR9moaf3b6CekunNJoxLa5bQ0=; b=J9SAzCsIBslyDDe59NUvXhl3PWl2828C+2sLdUo0EplcLdlYUz395h+OhdQU9A3NJjspv4uWHdniZkn6RTBycaWFMX2e/SMCgyggjL1myFfOhodgV8NIbDp2gX6sWmrGbDujUdhLBphG9uJk647TXcuL8g+cTgENzA0aG9pLmfBBXh/V4XE1McbtjbWhVkg2i/0BNSZNAyMU1DAO2L3QqEKNvPng0XR+SIZ901Fq58QqRLQmji8U4gxP83rOeqSGutqxaicY1bd5IlODE2Iqtfm1ciUzT0j+NKLcUcjAAnHtx108E3OP6fMSDpGH973rLYdazPJTFGVOPmvu7Lzrvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kWPO3yW3SDDeNCwG33G8h1ivc2XFSbdYez1Lfz92MRmdTiQ/kOCZlI9ZlJnB8ktNWVmGtdW74nJOCzlFWTsiBiE8s3WOApnJXu/Grz4p+RHZpUeIGpdb3Z4cgLzAVNnnZv5FB2pydg0xVpyiy4ALfxCypXmbhFTcYslw4hbDaCaj3rFS1zh8wjBcQNQrkMGn8b5jWJam4ST9TcJddDBLmBC+uZk51mIEUhMF4f4w386YoYITHKNZ6VCjjbYCf7u5bfBPkdkUthcR9F0YPMWrHiAFE/FQZ051O2NOUrIWineZKoQ5fT5Ce0pXsGuUoAUXLJ3HqBusOR948tYvTQXVLg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Mon, 14 Sep 2026 15:55:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 25-Aug-26 02:35, Volodymyr Babchuk wrote:
> Hi,
> 
> 
> I have only one small question to this patch. Please see below.
> 
> Mykola Kvach <mykola_kvach@xxxxxxxx> writes:
> 
>> The allocated_irqs bitmap in the existing vGIC implementation stores eSPI
>> allocation bits immediately after the regular vIRQ bits.
>> vgic_reserve_virq() converts an eSPI INTID to this compressed bitmap index,
>> but vgic_free_virq() used the raw INTID.
>>
>> Freeing INTID 4096 therefore clears bit 4096 instead of the first eSPI bit.
>> This writes beyond allocated_irqs and leaves the intended eSPI bit set.
>> Valid eSPIs reach this path during DOMCTL bind failure cleanup and unbind,
>> and during vPL011 teardown.
>>
>> Add virq_to_idx(), the inverse of idx_to_virq(), and use it when reserving
>> and freeing vIRQs. Validate a vIRQ before clearing its allocation bit.
>>
>> Fixes: bdde400c6e1b ("xen/arm: vgic: add resource management for extended 
>> SPIs")
>> Signed-off-by: Mykola Kvach <mykola_kvach@xxxxxxxx>
>> ---
>> Changes in v3:
>> - Adapt virq_to_idx() to the configuration-neutral is_espi() helper.
>>
>> Changes in v2:
>> - Call is_espi() without a configuration guard.
>> ---
>>  xen/arch/arm/vgic.c | 27 ++++++++++++++++-----------
>>  1 file changed, 16 insertions(+), 11 deletions(-)
>>
>> diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
>> index e14123a30a..e541348a5c 100644
>> --- a/xen/arch/arm/vgic.c
>> +++ b/xen/arch/arm/vgic.c
>> @@ -33,6 +33,16 @@ static inline unsigned int idx_to_virq(struct domain *d, 
>> unsigned int idx)
>>      return idx;
>>  }
>>  
>> +static inline unsigned int virq_to_idx(struct domain *d, unsigned int virq)
Please add a comment at the top of the function about the layout these two
helpers encode to prevent such problems in the future.

>> +{
>> +    ASSERT(IS_ENABLED(CONFIG_GICV3_ESPI) || !is_espi(virq));
>> +
>> +    if ( IS_ENABLED(CONFIG_GICV3_ESPI) && is_espi(virq) )
>> +        return espi_intid_to_idx(virq) + vgic_num_irqs(d);
>> +
>> +    return virq;
>> +}
>> +
>>  bool vgic_is_valid_line(struct domain *d, unsigned int virq)
>>  {
>>  #ifdef CONFIG_GICV3_ESPI
>> @@ -849,19 +859,11 @@ bool vgic_emulate(struct cpu_user_regs *regs, union 
>> hsr hsr)
>>  
>>  bool vgic_reserve_virq(struct domain *d, unsigned int virq)
>>  {
>> -    unsigned int idx = virq;
>> -
>>      if ( !vgic_is_valid_line(d, virq) )
>>          return false;
>>  
>> -    if ( is_espi(virq) )
>> -    {
>> -        unsigned int num_regular_irqs = vgic_num_irqs(d);
>> -
>> -        idx = espi_intid_to_idx(virq) + num_regular_irqs;
>> -    }
>> -
>> -    return !test_and_set_bit(idx, d->arch.vgic.allocated_irqs);
>> +    return !test_and_set_bit(virq_to_idx(d, virq),
>> +                             d->arch.vgic.allocated_irqs);
>>  }
>>  
>>  int vgic_allocate_virq(struct domain *d, bool spi)
>> @@ -898,7 +900,10 @@ int vgic_allocate_virq(struct domain *d, bool spi)
>>  
>>  void vgic_free_virq(struct domain *d, unsigned int virq)
>>  {
>> -    clear_bit(virq, d->arch.vgic.allocated_irqs);
>> +    if ( !vgic_is_valid_line(d, virq) )
> 
> Is this really can happen during normal runtime?
Yes, it can. A dom0less domU with direct-map, vpl011 and an explicit
nr_spis.

With the comment added:
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

~Michal




 


Rackspace

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