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

Re: [RFC XEN PATCH v4 1/5] xen/vpci: Clear all vpci status of device


  • To: "Hildebrand, Stewart" <Stewart.Hildebrand@xxxxxxx>
  • From: "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Date: Thu, 11 Jan 2024 02:36:23 +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=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=TAm2y2f9mxG1L6fJRCLllKwedFmPKAjJe+UAACa/sCg=; b=lYVu0t6Sdx+YbkYH5oMEQxW4G1OB+u7VxzQ0WF66WfsLNIxzT4Wb0tbW5jw2UjpsKnUq2KuSbZsyREPWb2CNJI9D3e4dPavGsyCePWx2RwKLLOrcejm0rRZ4IqFaJxJhrqhkufICU7sgZFgHozW1Ctgcu19NCQi8aRx2jJAjkI/GaJojmZY2ll48W1In8m1CwoaRz5n1+30v9Wdeqr166StQJ/Va4/hXWJTGJXr9kmTMKThOcX3sXaqmFHrs3cQxRgvxcGBo2bZvFkhltwwEP1vtWT1XYf0LJ+bQwn0LcIt21iU7cgtULICgUvKOPOH7fB3yqiezsMjxIcMSdeuzaQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RLesn8eaebvzwhJQnRy2t5xSphHWBxp7z0lt+aI22QTcXkDL6Hh0TTaIj+/xVLinHvChTsAnmNTZ7WI53W95+rk5ixyVHe112cgj4InSK9k0WTjUwHIlKTd8alB8Kq2fnp22UiQO0E5LW8HgfiFuaiI9GyQeKRcTXWTrjKPzFwPQwAOWc5VF82u7RmsCggtlTmzbwdGxcf8Fj4MLi9UpiY7dJeBuDtpy3DrCpnheJ3lapzOk37fDDWJT7ltQz9+1O0SIsrV+P3mKrmo7eEbJyT8qHyuKZM403zibd9PDDjv5plqqY74TdH1SV10yWQgY8a91ICLvL7IOsiOEa4q3Fg==
  • 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>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, "Huang, Ray" <Ray.Huang@xxxxxxx>, "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Delivery-date: Thu, 11 Jan 2024 02:36:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHaP6YrwTeuO8u85U6eXqUvf5Gm3LDRoHaAgAF/ZoD///38AIABVnwA
  • Thread-topic: [RFC XEN PATCH v4 1/5] xen/vpci: Clear all vpci status of device

On 2024/1/10 22:09, Stewart Hildebrand wrote:
> On 1/10/24 01:24, Chen, Jiqian wrote:
>> On 2024/1/9 23:24, Stewart Hildebrand wrote:
>>> On 1/5/24 02:09, Jiqian Chen wrote:
>>>> diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c
>>>> index 42db3e6d133c..552ccbf747cb 100644
>>>> --- a/xen/drivers/pci/physdev.c
>>>> +++ b/xen/drivers/pci/physdev.c
>>>> @@ -67,6 +68,39 @@ ret_t pci_physdev_op(int cmd, 
>>>> XEN_GUEST_HANDLE_PARAM(void) arg)
>>>>          break;
>>>>      }
>>>>  
>>>> +    case PHYSDEVOP_pci_device_state_reset: {
>>>> +        struct physdev_pci_device dev;
>>>> +        struct pci_dev *pdev;
>>>> +        pci_sbdf_t sbdf;
>>>> +
>>>> +        if ( !is_pci_passthrough_enabled() )
>>>> +            return -EOPNOTSUPP;
>>>> +
>>>> +        ret = -EFAULT;
>>>> +        if ( copy_from_guest(&dev, arg, 1) != 0 )
>>>> +            break;
>>>> +        sbdf = PCI_SBDF(dev.seg, dev.bus, dev.devfn);
>>>> +
>>>> +        ret = xsm_resource_setup_pci(XSM_PRIV, sbdf.sbdf);
>>>> +        if ( ret )
>>>> +            break;
>>>> +
>>>> +        pcidevs_lock();
>>>> +        pdev = pci_get_pdev(NULL, sbdf);
>>>> +        if ( !pdev )
>>>> +        {
>>>> +            pcidevs_unlock();
>>>> +            ret = -ENODEV;
>>>> +            break;
>>>> +        }
>>>> +
>>>
>>>         write_lock(&pdev->domain->pci_lock);
>>>
>>>> +        ret = vpci_reset_device_state(pdev);
>>>
>>>         write_unlock(&pdev->domain->pci_lock);
>> vpci_reset_device_state only reset the vpci state of pdev without deleting 
>> pdev from domain, and here has held pcidevs_lock, it has no need to lock 
>> pci_lock?
> 
> Strictly speaking, it is not enforced yet. However, an upcoming change [1] 
> will expand the scope of d->pci_lock to include protecting the pdev->vpci 
> structure to an extent, so it will be required once that change is committed. 
> In my opinion there is no harm in adding the additional lock now. If you 
> prefer to wait I would not object, but in this case I would at least ask for 
> a TODO comment to help remind us to address it later.
> 
> [1] https://lists.xenproject.org/archives/html/xen-devel/2024-01/msg00446.html
> 
Ok, I see. I will add pci_lock in next version, thank you for reminding me.

>>
>>>
>>>> +        pcidevs_unlock();
>>>> +        if ( ret )
>>>> +            printk(XENLOG_ERR "%pp: failed to reset PCI device state\n", 
>>>> &sbdf);
>>>> +        break;
>>>> +    }
>>>> +
>>>>      default:
>>>>          ret = -ENOSYS;
>>>>          break;
>>>> diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
>>>> index 72ef277c4f8e..3c64cb10ccbb 100644
>>>> --- a/xen/drivers/vpci/vpci.c
>>>> +++ b/xen/drivers/vpci/vpci.c
>>>> @@ -107,6 +107,15 @@ int vpci_add_handlers(struct pci_dev *pdev)
>>>>  
>>>>      return rc;
>>>>  }
>>>> +
>>>> +int vpci_reset_device_state(struct pci_dev *pdev)
>>>> +{
>>>> +    ASSERT(pcidevs_locked());
>>>
>>>     ASSERT(rw_is_write_locked(&pdev->domain->pci_lock));
>>>
>>>> +
>>>> +    vpci_remove_device(pdev);
>>>> +    return vpci_add_handlers(pdev);
>>>> +}
>>>> +
>>>>  #endif /* __XEN__ */
>>>>  
>>>>  static int vpci_register_cmp(const struct vpci_register *r1,
>>

-- 
Best regards,
Jiqian Chen.

 


Rackspace

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