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

Re: [PATCH v7 01/12] vpci: introduce per-domain lock to protect vpci structure


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 20 Jun 2023 16:17:28 -0400
  • 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
  • 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=zx181DDKOS+YXOh++MInpvRp7CSA8JPETz6niB+9IjU=; b=XgPPwF6VAFE646d8FBV3O/V0uyUzF+ROowyPu//kjVojhRp/gv6UuQNaxTzKwpudVq+iSy1k2IhZNA0pOnhm4HtX8WLkgyYygq0imJCJH5JISYUUaw9k2Gij5EUdtuxnTY7glMPkb2A6eBBEAEXVILVkNF0B6aLDUAGj0YNC6et/d52T1US0Kq7dp/9fBdsdrsYuGCWxwkaTGIb56czCo31ESQe+6a5jh4JjBKoJFYeofFdHRhUowIAL7+S4gKu+YnZBdtFn3/2YdnyUCzYEAZLmdst+F0DwlVy+lBPUkO89hrqEAtgR8EzIJBGuiPrTUwrm9pIN+7OmvwApRwzFSw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KY2suoiTEWEfS4+3IwEU0Au1axJMhxwOjotXBsrwnXdJlmtQOtCC6Q+IFdgqhLwjOE0yrDVADgyp2hJV/5Ifu9Eu2XVZrbaHt6/LCxj1nCvBLojR5SUNbZiX2nYui1WVokKb9zg8cpjK4+oqMzJPOe6vwrlgyWJSWkFpSt8am5IFfaqQCW02mYIDP42ZoQFyBCq5WpRmGBFQcBjQLw5c9Afmkaw3IH5ElY28gPybq2hNoN9i7sOf3PSYVn3su3YhrgFmbV/6QSXA9On3POJz0wmbUwDgQ+jjLshI3ytmscKj7FHnqu1GjmQwy1nFFbaIhVPjL4NSgJfyj5rDKYEeWQ==
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, 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>, Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Tue, 20 Jun 2023 20:18:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 6/13/23 06:32, Volodymyr Babchuk wrote:

...

> diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
> index 652807a4a4..1270174e78 100644
> --- a/xen/drivers/vpci/vpci.c
> +++ b/xen/drivers/vpci/vpci.c
> @@ -38,20 +38,32 @@ extern vpci_register_init_t *const __end_vpci_array[];
> 
>  void vpci_remove_device(struct pci_dev *pdev)
>  {
> -    if ( !has_vpci(pdev->domain) || !pdev->vpci )
> +    struct vpci *vpci;
> +
> +    if ( !has_vpci(pdev->domain) )
>          return;
> 
> -    spin_lock(&pdev->vpci->lock);
> +    write_lock(&pdev->domain->vpci_rwlock);
> +    if ( !pdev->vpci )
> +    {
> +        write_unlock(&pdev->domain->vpci_rwlock);
> +        return;
> +    }
> +
> +    vpci = pdev->vpci;
> +    pdev->vpci = NULL;

Here we set pdev->vpci to NULL, yet there are still a few uses remaining after 
this in vpci_remove_device. I suspect they were missed during a 
s/pdev->vpci/vpci/ search and replace.

> +    write_unlock(&pdev->domain->vpci_rwlock);
> +
>      while ( !list_empty(&pdev->vpci->handlers) )

pdev->vpci dereferenced here

>      {
> -        struct vpci_register *r = list_first_entry(&pdev->vpci->handlers,
> +        struct vpci_register *r = list_first_entry(&vpci->handlers,
>                                                     struct vpci_register,
>                                                     node);
> 
>          list_del(&r->node);
>          xfree(r);
>      }
> -    spin_unlock(&pdev->vpci->lock);
> +
>      if ( pdev->vpci->msix )

pdev->vpci dereferenced here

>      {
>          unsigned int i;
> @@ -61,29 +73,33 @@ void vpci_remove_device(struct pci_dev *pdev)
>              if ( pdev->vpci->msix->table[i] )

pdev->vpci dereferenced here, and two more above not shown in the diff context

>                  iounmap(pdev->vpci->msix->table[i]);

pdev->vpci dereferenced here

>      }
> -    xfree(pdev->vpci->msix);
> -    xfree(pdev->vpci->msi);
> -    xfree(pdev->vpci);
> -    pdev->vpci = NULL;
> +    xfree(vpci->msix);
> +    xfree(vpci->msi);
> +    xfree(vpci);
>  }



 


Rackspace

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