[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: Jiqian Chen <Jiqian.Chen@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 9 Jan 2024 10:24:05 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org 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=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=u+HMJXyXGN7Yzen/DWfjQa/KINyran/Sq/l+V+dwkPA=; b=ijfKQCBoMqPW4SrWO6roZoZn2eM+CQOkp989S4J3yGE2J9XhC/QjuJKqBeaAQMuIus36BvQlYPHBRSIlNpcwinIzhPGarGXhS66UlnaTubROBHfxmDlMaFDmRCL3Kkyiclym1M+x7DJQI339rmVQO82mVz10gKPjNZjjqdSFNjY+cCpD/5F9Q78kiBKM4lLdMRYmZNpQcl8/7YZ3mPUcPRWzROPSXKWzshG+LnlaNrrRpLeHqC18i3puAiJHoWHE6fRjWROzkBK8Riwcuii/CDvHpus7h+JIqzTdu8JAvo6ullXOgUjHKpm3QRVY7xP0hW45ieZ0FLZuoGU6OW4Qww==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HxxFuNEBkHDBaLE6eA+Ndxqe7neuvfTsPUGDgL7vx0H0HKPJTY/HvaUPTSEcRdDPGA8+r7nqBqOtrhx55tPYwzD3ZN13Fso3gPB5wNaaSPuF8yWnLgmeHwKZBp73R21/d9+n0eVcAxeDGbDS4drYBfiNAYdEAYsZNxa3HtNj0REZiV02lHrIzppXpwjZHVmLGImjK7qaPPfEsM8IRyqXAhpoT08LwNhz8CSPWNJDvOeoN3NhIVLmwqVkUin37yMZzgLjSYMVjHXLl3OpaFLst9ozOxUfcM49BkJGJ1lPhPy8Y1bhVtn6J2VfBaX//xS5SulHAjmWdu9WmYDUioKNlg==
  • Cc: 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 Rui <Ray.Huang@xxxxxxx>
  • Delivery-date: Tue, 09 Jan 2024 15:24:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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);

> +        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,



 


Rackspace

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