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

Re: [PATCH v8 02/13] vpci: use per-domain PCI lock to protect vpci structure


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 28 Jul 2023 15:55:04 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=WTbxb09MAK35wf0lo93bbnMh5YL/QO7+u3Rh8gTfu5U=; b=JyD1QyAHpSPTAOoqu5GXIYyYrkO/+X8AY7kzIEifcpxXRbnDKjO7AzUS7efbtBQ7+W5vgG9EBBznvGtWmsqabLmADPksNxcFgnebksgcKCJR+af9NKwcSGKzIb2cek01+zOmma3TXp4yPCl31G13LAqFHfoucMe4gnCiPEs/anzketsl68M2FrwfDZDfeFQtYv0Bj/KAXfA6IFPYWdF1q9HLf3f01J3RC7rp7PE/5aV9i+WGlEZ6QBz7xnc1IjaSFH4NNUYmwZbYGM3GNt7gzqLRb7YK/nyvtSvfmfiSfg4dhSeP34e7PI6ROismGKPf1om2VvXtOopCl/C6Z3FSYA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CnRwVhyOfeFH9GicmeDa/WRyTrVZEWhMYMQ3Wv/07aHwgjHGDDwpS2RS0o9F2WEQTSsTeghH+simg+HfLt+d4bm125CLAc5qKqJa1UNfs50Z0OOdEfOLWue3qZgFskkb94CU9JS3qNEFmVGDHQL3blKOHiajMjCzIKIyv+Wm+JK2As3FBf3VBPWqdxA0aUzvKfK31qay15Q0S4pry105A1QVJOkgn1CM8bmhw90GVXItnwBVYuRfkh752uRSuArP5Ts6cNeubrUY5syMwJHS5oADEeZt4zxcWAp9JY985WLDahIGMCg2ceIOldtpvUyIoq642Gx/EH6uiVtnE6yjzw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • Delivery-date: Fri, 28 Jul 2023 13:55:45 +0000
  • Ironport-data: A9a23:Jy/tY6nEh9g1xDPcSDZCl3vo5gxQJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIdC2+BaK3bZWCjc9xyaIu/9U5UvMDRzYNgSVZlrSFkEyMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE0p5K2aVA8w5ARkPqgU5g+GzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 ewhAiIDQD6nvv270bWCR8JPge4jCeC+aevzulk4pd3YJdAPZMiZBo/svJpf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVU3jOCF3Nn9I7RmQe1PmUmVv CTe9nnRCRAGLt2PjzGC9xpAg8eWxHyjB9pJSOLQGvhC2kSR4mgvKDkvd1qrmKmEqk6EcJFlJ BlBksYphe1onKCxdfHDWBm/rG+BrwQrcdNaGO0n6ymA0qPRpQ2eAwAsXjNHLdArqsIybTgrz UOS2cPkAyR1t7+YQm7b8a2bxRuVPSUWNmYEaTUzZA0J+cT4oIozgxTMSf5uCKewyNbyHFnYw TqHsSw/jLU7ltMQ2uOw+lWvvt63jp3ATwpw7AOOWGugtll9fNT9O9Tu7kXH5/FdKorfVkOGo HUPh8mZ6qYJEI2JkyuOBu4KGdlF+sq4DdEVunY3d7FJythn0yXLkVx4iN2mGHpUDw==
  • Ironport-hdrordr: A9a23:NW1DLq9JHV5whTFfnoluk+D+I+orL9Y04lQ7vn2ZHyYlCPBws/ re5cjzsiWE7gr5OUtQ/uxoXZPrfZqyz+8X3WB8B9eftWrdyQ+VxeNZnOnfKmbbalXDH4dmvM 8KT0EUMqyUMbEVt6fHyTj9O8o8xsKK6aW57N2utEuFjjsHV0ij1WpE48qgfXGejTMpOaYE
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, Jul 28, 2023 at 12:21:54AM +0000, Volodymyr Babchuk wrote:
> 
> Hi Roger,
> 
> Roger Pau Monné <roger.pau@xxxxxxxxxx> writes:
> 
> > On Thu, Jul 27, 2023 at 12:56:54AM +0000, Volodymyr Babchuk wrote:
> >> Hi Roger,
> >> 
> >> Roger Pau Monné <roger.pau@xxxxxxxxxx> writes:
> >> 
> >> > On Wed, Jul 26, 2023 at 01:17:58AM +0000, Volodymyr Babchuk wrote:
> >> >> 
> >> >> Hi Roger,
> >> >> 
> >> >> Roger Pau Monné <roger.pau@xxxxxxxxxx> writes:
> >> >> 
> >> >> > On Thu, Jul 20, 2023 at 12:32:31AM +0000, Volodymyr Babchuk wrote:
> >> >> >> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
> >> >> >> @@ -498,6 +537,7 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int 
> >> >> >> reg, unsigned int size,
> >> >> >>          ASSERT(data_offset < size);
> >> >> >>      }
> >> >> >>      spin_unlock(&pdev->vpci->lock);
> >> >> >> +    unlock_locks(d);
> >> >> >
> >> >> > There's one issue here, some handlers will cal pcidevs_lock(), which
> >> >> > will result in a lock over inversion, as in the previous patch we
> >> >> > agreed that the locking order was pcidevs_lock first, d->pci_lock
> >> >> > after.
> >> >> >
> >> >> > For example the MSI control_write() handler will call
> >> >> > vpci_msi_arch_enable() which takes the pcidevs lock.  I think I will
> >> >> > have to look into using a dedicated lock for MSI related handling, as
> >> >> > that's the only place where I think we have this pattern of taking the
> >> >> > pcidevs_lock after the d->pci_lock.
> >> >> 
> >> >> I'll mention this in the commit message. Is there something else that I
> >> >> should do right now?
> >> >
> >> > Well, I don't think we want to commit this as-is with a known lock
> >> > inversion.
> >> >
> >> > The functions that require the pcidevs lock are:
> >> >
> >> > pt_irq_{create,destroy}_bind()
> >> > unmap_domain_pirq()
> >> >
> >> > AFAICT those functions require the lock in order to assert that the
> >> > underlying device doesn't go away, as they do also use d->event_lock
> >> > in order to get exclusive access to the data fields.  Please double
> >> > check that I'm not mistaken.
> >> 
> >> You are right, all three function does not access any of PCI state
> >> directly. However...
> >> 
> >> > If that's accurate you will have to check the call tree that spawns
> >> > from those functions in order to modify the asserts to check for
> >> > either the pcidevs or the per-domain pci_list lock being taken.
> >> 
> >> ... I checked calls for PT_IRQ_TYPE_MSI case, there is only call that
> >> bothers me: hvm_pi_update_irte(), which calls IO-MMU code via
> >> vmx_pi_update_irte():
> >> 
> >> amd_iommu_msi_msg_update_ire() or msi_msg_write_remap_rte().
> >
> > That path is only for VT-d, so strictly speaking you only need to worry
> > about msi_msg_write_remap_rte().
> >
> > msi_msg_write_remap_rte() does take the IOMMU intremap lock.
> >
> > There are also existing callers of iommu_update_ire_from_msi() that
> > call the functions without the pcidevs locked.  See
> > hpet_msi_set_affinity() for example.
> 
> Thank you for clarifying this.
> 
> I have found another call path which causes troubles:
> __pci_enable_msi[x] is called from pci_enable_msi() via vMSI, via
> physdev_map_irq and also directly from ns16550 driver.

Both vPCI and physdev_map_irq() use the same path: map_domain_pirq()
which gets called with d->event_lock taken in exclusive mode, that
should be enough as a device cannot be assigned to multiple guests.

ns16550_init_postirq() is an init function, which means it won't be
executed after Xen has booted, so I think this is all fine, as
concurrent accesses from ns16550_init_postirq() and map_domain_pirq()
are impossible.

Thanks, Roger.



 


Rackspace

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