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

Re: [PATCH v3 07/11] vpci: Hide extended capability when it fails to initialize


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Date: Wed, 7 May 2025 07:26:21 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.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=6zzPfcQAlF0IvpQv5qBLJEQD5SOS7tHGLQU9VaBR2xo=; b=S6SHHM4iBcS2tTHTuN++inJxFfzgj7rgcsMQcjKDYeVffiSyklIiyTBy30rV5Qzt/KzIlYy4XfhsjefuLHubvEEkF20VJWvM2kn73wByjDrstJbBtjxx/u2c0rCvj+mbT5Y8jU/Oi4cdZsYyUWwJcIvZZxIFjWtI9kMi2YVAxBDBKJN5OHbqGrHPsZG9xNcTA03oPKufAG5gGe2lrEs84tlgYrWGLH1rZUPQ49AiqF1hk7AtGtWAp+fmbvLnSGkWoweLPDIBZ4TO2c2TezoarMludt1FB7J2mDAA8BvveairGNDu/FhSFw9AR6yXpxpox2SCyP5v2+eB3YS4xkKQoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vchyJjtoWWRTcFCuKij7AyJMRP7NrkuDMyqOQOzXKr0IwpjA4Xnu632e81Qyp+dLivWaYm5wGJXe+/rm3M8G71htcdfORUQ9HaAxol/pPceBCbhrqYBhYLZWSPtrMOYmrRnoQ9/M3xrNbhGnbnTA6S/X0kJxiY+iG48rIMj+tnBlClxIZNuPXZpkN2OLK2P4TLFO2tiUfx+m5x3BCDRzNwhQ5J6/jw5LpKIsxmP6xF93CutTrtOYUzOYMP64VvQLjldTwBsvW/HWTnmFQ6jSHTPGO5ijA0w5f5EGfZFFGI6UTPcgxHuD+QrLek/RUbMCr/VIG+gKVYaE0PkuCXEaWQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Huang, Ray" <Ray.Huang@xxxxxxx>, "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Delivery-date: Wed, 07 May 2025 07:26:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHbsoVd9OkTHNIeNk69huFsDqzHMLPF4NaAgAGCYAA=
  • Thread-topic: [PATCH v3 07/11] vpci: Hide extended capability when it fails to initialize

On 2025/5/7 00:21, Roger Pau Monné wrote:
> On Mon, Apr 21, 2025 at 02:18:59PM +0800, Jiqian Chen wrote:
>> When vpci fails to initialize a extended capability of device for dom0,
>> it just return error instead of catching and processing exception. That
>> makes the entire device unusable.
>>
>> So, add new a function to hide extended capability when initialization
>> fails. And remove the failed extended capability handler from vpci
>> extended capability list.
>>
>> Signed-off-by: Jiqian Chen <Jiqian.Chen@xxxxxxx>
>> ---
>> cc: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
>> ---
>> v2->v3 changes:
>> * Separated from the last version patch "vpci: Hide capability when it fails 
>> to initialize".
>> * Whole implementation changed because last version is wrong.
>>   This version gets target handler and previous handler from vpci->handlers, 
>> then remove the target.
>> * Note: a case in function vpci_ext_capability_mask() needs to be discussed,
>>   because it may change the offset of next capability when the offset of 
>> target
>>   capability is 0x100U(the first extended capability), my implementation is 
>> just to
>>   ignore and let hardware to handle the target capability.
>>
>> v1->v2 changes:
>> * Removed the "priorities" of initializing capabilities since it isn't used 
>> anymore.
>> * Added new function vpci_capability_mask() and vpci_ext_capability_mask() to
>>   remove failed capability from list.
>> * Called vpci_make_msix_hole() in the end of init_msix().
>>
>> Best regards,
>> Jiqian Chen.
>> ---
>>  xen/drivers/vpci/vpci.c    | 79 ++++++++++++++++++++++++++++++++++++++
>>  xen/include/xen/pci_regs.h |  1 +
>>  2 files changed, 80 insertions(+)
>>
>> diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
>> index f97c7cc460a0..8ff5169bdd18 100644
>> --- a/xen/drivers/vpci/vpci.c
>> +++ b/xen/drivers/vpci/vpci.c
>> @@ -183,6 +183,83 @@ static void vpci_capability_mask(struct pci_dev *pdev,
>>      xfree(next_r);
>>  }
>>  
>> +static struct vpci_register *vpci_get_previous_ext_cap_register
>> +                (struct vpci *vpci, const unsigned int offset)
>> +{
>> +    uint32_t header;
>> +    unsigned int pos = PCI_CFG_SPACE_SIZE;
>> +    struct vpci_register *r;
>> +
>> +    if ( offset <= PCI_CFG_SPACE_SIZE )
>> +        return NULL;
>> +
>> +    r = vpci_get_register(vpci, pos, 4);
>> +    ASSERT(r);
>> +
>> +    header = (uint32_t)(uintptr_t)r->private;
>> +    pos = PCI_EXT_CAP_NEXT(header);
>> +    while ( pos > PCI_CFG_SPACE_SIZE && pos != offset )
>> +    {
>> +        r = vpci_get_register(vpci, pos, 4);
>> +        ASSERT(r);
>> +        header = (uint32_t)(uintptr_t)r->private;
>> +        pos = PCI_EXT_CAP_NEXT(header);
>> +    }
>> +
>> +    if ( pos <= PCI_CFG_SPACE_SIZE )
>> +        return NULL;
>> +
>> +    return r;
>> +}
>> +
>> +static void vpci_ext_capability_mask(struct pci_dev *pdev,
>> +                                     const unsigned int cap)
>> +{
>> +    const unsigned int offset = pci_find_ext_capability(pdev->sbdf, cap);
>> +    struct vpci_register *rm, *prev_r;
>> +    struct vpci *vpci = pdev->vpci;
>> +    uint32_t header, pre_header;
> 
> Maybe sanity check that offset is correct?
What do you mean sanity check?
Do I need to add something?

> 
>> +    spin_lock(&vpci->lock);
>> +    rm = vpci_get_register(vpci, offset, 4);
>> +    if ( !rm )
>> +    {
>> +        spin_unlock(&vpci->lock);
>> +        return;
>> +    }
>> +
>> +    header = (uint32_t)(uintptr_t)rm->private;
>> +    if ( offset == PCI_CFG_SPACE_SIZE )
>> +    {
>> +        if ( PCI_EXT_CAP_NEXT(header) <= PCI_CFG_SPACE_SIZE )
>> +            rm->private = (void *)(uintptr_t)0;
>> +        else
>> +            /*
>> +             * Else case needs to remove the capability in position 0x100U 
>> and
>> +             * moves the next capability to be in position 0x100U, that 
>> would
>> +             * cause the offset of next capability in vpci different from 
>> the
>> +             * hardware, then cause error accesses, so just ignore it here 
>> and
>> +             * hope hardware would handle the capability well.
>> +            */
>> +            printk(XENLOG_ERR "%pd %pp: ext cap %u is first cap, can't mask 
>> it\n",
>> +                   pdev->domain, &pdev->sbdf, cap);
> 
> In this case, could you maybe replace just the capability ID part of
> the header to return 0?  That will likely cause the OS to continue
> scanning the list, while ID 0 won't match which any known
> capability.
OK, will do in next version.

> 
> Thanks, Roger.

-- 
Best regards,
Jiqian Chen.

 


Rackspace

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