fix some spinlock issues in vmsi
RFC PATCH 1/1 fix some spinlock issues in vmsi
Hi,
This patch fixes some spinlock issues related to changeset:
19246:9bc5799566be "passthrough MSI-X mask bit acceleration" 19263:9c5b4efc934d "hvm: passthrough MSI-X: fix ia64 link and MSI-X clean up"
Without this patch, I got:
(XEN) Assertion '_spin_is_locked(&pcidevs_lock)' failed at vmsi.c:389 or
(XEN) Xen BUG at spinlock.c:25
I'm not sure this fix is right. Please review it.
- d->arch.hvm_domain.msixtbl_list_lock is redundant. irq_desc->lock covers it, thus remove the spinlock.
- ASSERT(spin_is_locked(&pcidevs_lock)) is not needed. At first, I intended to add the enclosure of pcidevs_lock. But this assertion seems pointless. pcidevs_lock is for alldevs_list and msixtbl_pt_xxx functions never refer it.
- In "debug=y" environment, xmalloc must not be called from both irq_enable and irq_disable state. Otherwise,
the assertion failure occurs in check_lock().
So, in msixtbl_pt_register, xmalloc is called beforehand. I thinks this is ugly, though.
Thanks,
Kouya
xen/arch/x86/hvm/hvm.c +0 -1
@@ -309,7 +309,6 @@ int hvm_domain_initialise(struct domainspin_lock_init (&d->arch.hvm_domain.uc_lock);INIT_LIST_HEAD (&d->arch.hvm_domain.msixtbl_list); -spin_lock_init (&d->arch.hvm_domain.msixtbl_list_lock);hvm_init_guest_time (d);
xen/arch/x86/hvm/vmsi.c +24 -34
133 lines not on this page · raw message
xen/include/asm-x86/hvm/domain.h +0 -1
@@ -77,7 +77,6 @@ struct hvm_domain {/* hypervisor intercepted msix table */ struct list_head msixtbl_list; -spinlock_t msixtbl_list_lock;struct viridian_domain viridian;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 12 lines · Kouya Shimura
Hi,
This patch fixes some spinlock issues related to changeset:
19246:9bc5799566be "passthrough MSI-X mask bit acceleration" 19263:9c5b4efc934d "hvm: passthrough MSI-X: fix ia64 link and MSI-X clean up"Without this patch, I got:
(XEN) Assertion '_spin_is_locked(&pcidevs_lock)' failed at vmsi.c:389 or
(XEN) Xen BUG at spinlock.c:25
Quoted 4 lines
I'm not sure this fix is right. Please review it.
-
d->arch.hvm_domain.msixtbl_list_lockis redundant.irq_desc->lockcovers it, thus remove the spinlock.
No, it's not redundant. msixtbl_list_lock is to protect msixtbl_list, which may contain entries for multiple irqs, consider if two pt_bind_irq are called simultaneously, irq_desc->lock wouldn't be enough to protect the list.
Quoted 5 lines
- ASSERT(spin_is_locked(&pcidevs_lock)) is not needed. At first, I intended to add the enclosure of
pcidevs_lock. But this assertion seems pointless.pcidevs_lockis foralldevs_listandmsixtbl_pt_xxxfunctions never refer it.
I was thinking that pcidevs_lock is already held for msixtbl_pt_xxx, but obviously I was wrong:-) However, it's not that pointless, msixtbl_pt_xxx refers to the content of pci_dev, the use of pcidevs_lock is intended to protect it against destructive modification, like an improper PHYDEVOP_manage_pci_remove. It may not be neccessary for a well-written device model, but that's something we can't rely on.
A similar problem also exists in msixtbl_write/msixtbl_read. Currently, these functions access the mapped msix table using the pointer stored in pci_dev, and when pci_dev is removed without the knowledge of the guest, pci_dev alongside the fixmaps will be removed and this definitely will frustrate these functions. Unfortunately, adding spinlocks to msixtbl_{read,write} seems quite expensive, especially for multiple guest threads, that's why RCU based lock is used here. For a completely secure handling of this, maybe we need a less brute, asynchronous pci_remove hypercall or something.
Quoted 6 lines
- In "debug=y" environment, xmalloc must not be called from both
irq_enableandirq_disablestate. Otherwise,
the assertion failure occurs incheck_lock().
So, inmsixtbl_pt_register, xmalloc is called beforehand. I thinks this is ugly, though.
This is fine to me, thank you for pointing out this.
Thanks,
Qing
Quoted 7 lines
Thanks,
KouyaSigned-off-by Kouya Shimura <[email protected]>
Hi Qing,
Thank you for review and elaboration.
Quoted 7 lines · Qing He
Quoted 2 lines
-
d->arch.hvm_domain.msixtbl_list_lockis redundant.irq_desc->lockcovers it, thus remove the spinlock.No, it's not redundant.
msixtbl_list_lockis to protectmsixtbl_list, which may contain entries for multiple irqs, consider if twopt_bind_irqare called simultaneously,irq_desc->lockwouldn't be enough to protect the list.
I see. Although two pt_bind_irq are hardly called simultaneously.
Quoted 11 lines
Quoted 4 lines
- ASSERT(spin_is_locked(&pcidevs_lock)) is not needed. At first, I intended to add the enclosure of
pcidevs_lock. But this assertion seems pointless.pcidevs_lockis foralldevs_listandmsixtbl_pt_xxxfunctions never refer it.I was thinking that
pcidevs_lockis already held formsixtbl_pt_xxx, but obviously I was wrong:-) However, it's not that pointless,msixtbl_pt_xxxrefers to the content ofpci_dev, the use ofpcidevs_lockis intended to protect it against destructive modification, like an improperPHYDEVOP_manage_pci_remove. It may not be neccessary for a well-written device model, but that's something we can't rely on.
Okay, one more question.
If ASSERT(spin_is_locked(&pcidevs_lock)) is needed, msixtbl_list_lock becomes redundant?
(i.e. pcidevs_lock must covers it)
Any way, msixtbl_list_lock would better be remained for the future...
Thanks,
Kouya
Quoted 7 lines · Kouya Shimura
Quoted 4 lines · Qing He
No, it's not redundant.
msixtbl_list_lockis to protectmsixtbl_list, which may contain entries for multiple irqs, consider if twopt_bind_irqare called simultaneously,irq_desc->lockwouldn't be enough to protect the list.I see. Although two
pt_bind_irqare hardly called simultaneously.
The problem here and in many other place is whether we can safely assume that dom0 operations are completely within expectation
Quoted 13 lines
Quoted 6 lines
Quoted 5 lines
- ASSERT(spin_is_locked(&pcidevs_lock)) is not needed. At first, I intended to add the enclosure of
pcidevs_lock. But this assertion seems pointless.pcidevs_lockis foralldevs_listandmsixtbl_pt_xxxfunctions never refer it.Quoted 6 lines
I was thinking that
pcidevs_lockis already held formsixtbl_pt_xxx, but obviously I was wrong:-) However, it's not that pointless,msixtbl_pt_xxxrefers to the content ofpci_dev, the use ofpcidevs_lockis intended to protect it against destructive modification, like an improperPHYDEVOP_manage_pci_remove. It may not be neccessary for a well-written device model, but that's something we can't rely on.
Quoted 5 lines
Okay, one more question.
If ASSERT(spin_is_locked(&pcidevs_lock)) is needed,msixtbl_list_lockbecomes redundant?
(i.e.pcidevs_lockmust covers it)
Any way,msixtbl_list_lockwould better be remained for the future...
I'm OK with that, though I think msixtbl_list_lock is more closer to the list. Are you going to use something named like this?
Thanks,
Qing
Quoted 9 lines · Qing He
A similar problem also exists in msixtbl_write/msixtbl_read. Currently, these functions access the mapped msix table using the pointer stored in
pci_dev, and whenpci_devis removed without the knowledge of the guest,pci_devalongside the fixmaps will be removed and this definitely will frustrate these functions. Unfortunately, adding spinlocks to msixtbl_{read,write} seems quite expensive, especially for multiple guest threads, that's why RCU based lock is used here. For a completely secure handling of this, maybe we need a less brute, asynchronouspci_removehypercall or something.
Add the locks, making it correct. Then optimise later as necessary, using RCU or (perhaps easier) just smaller locks: Per MSI-X or per-pci-dev or whatever. Throwing in racey code condemns us to subtle races forever more.
-- Keir
Quoted 12 lines · Keir Fraser
Quoted 9 lines · Qing He
A similar problem also exists in msixtbl_write/msixtbl_read. Currently, these functions access the mapped msix table using the pointer stored in
pci_dev, and whenpci_devis removed without the knowledge of the guest,pci_devalongside the fixmaps will be removed and this definitely will frustrate these functions. Unfortunately, adding spinlocks to msixtbl_{read,write} seems quite expensive, especially for multiple guest threads, that's why RCU based lock is used here. For a completely secure handling of this, maybe we need a less brute, asynchronouspci_removehypercall or something.
Quoted 3 lines
Add the locks, making it correct. Then optimise later as necessary, using RCU or (perhaps easier) just smaller locks: Per MSI-X or per-pci-dev or whatever. Throwing in racey code condemns us to subtle races forever more.
Ok, I'll make a patch to use the locks.
Do you think it's ok to assume that guest has already free the device when calling remove_pci_device on hotplugging?
Thanks,
Qing
Quoted 4 lines
-- Keir
Quoted 8 lines · Qing He
Quoted 3 lines
Add the locks, making it correct. Then optimise later as necessary, using RCU or (perhaps easier) just smaller locks: Per MSI-X or per-pci-dev or whatever. Throwing in racey code condemns us to subtle races forever more.
Ok, I'll make a patch to use the locks.
Do you think it's ok to assume that guest has already free the device when calling
remove_pci_deviceon hotplugging?
Do you mean deinitialised and unloaded the device driver?
-- Keir
Quoted 6 lines · Keir Fraser
Quoted 4 lines · Qing He
Quoted 3 lines
Add the locks, making it correct. Then optimise later as necessary, using RCU or (perhaps easier) just smaller locks: Per MSI-X or per-pci-dev or whatever. Throwing in racey code condemns us to subtle races forever more.
Quoted 6 lines
Quoted 4 lines
Ok, I'll make a patch to use the locks.
Do you think it's ok to assume that guest has already free the device when calling
remove_pci_deviceon hotplugging?Do you mean deinitialised and unloaded the device driver?
Yes, the racey condition we just talked happens here. Consider the following case, when remove_pci_device is called, the device data structure is removed by the hypervisor. But there is no guarauntee in the hypervisor that guest already has knowledge, for example the guest may continue to access the device resources. It's in this case msixtbl_{read,write} has a little racey condition.
I don't think this scenario is desirable, but does it happen in the current logic?
Thanks,
Qing
Quoted 11 lines · Qing He
Quoted 1 line
Do you mean deinitialised and unloaded the device driver?
Yes, the racey condition we just talked happens here. Consider the following case, when
remove_pci_deviceis called, the device data structure is removed by the hypervisor. But there is no guarauntee in the hypervisor that guest already has knowledge, for example the guest may continue to access the device resources. It's in this case msixtbl_{read,write} has a little racey condition.I don't think this scenario is desirable, but does it happen in the current logic?
Uh, well since dom0 is in fact mostly in charge of PCI access, there's not much we can do in Xen to enforce this. At that level we kind of have to assume that dom0 has sequenced hotplug/hotunplug sensibly.
-- Keir
I was confused by this also when I try to working on the pci_dev lock.
Current implementation did't assume the device is not owned by guest, that means the IOMMU/MSI are both maybe enabled for a guest when dom0 try to invoke the PHYSDEVOP_manage_pci_remove hypercall. This cause a lot of race condition issue and makes the pci pass-through very complex.
Maybe we can simplify through two step:
a) Instead of let Xen HV to handle the situation that the device is still owned by other guest, we can have pciback to do that before this hypercall is invoked. For PV driver domain it will be simple since dom0's kernel should invoke PCIback's remove() function. For HVM domain, I think it should be ok for stubdomain environment. This will make HV simpler and robust and didn't make thing worse.
b) Find some mechanism so that dom0 can cause virtual hotplug to guest, then hotplug in host side will not cause trouble to guest. There are virtual hotplug for PV guest but it is async method, not sure if that can be integrated with dom0's hotplug event handling.
Not sure if this is feasible.
CC Esp and Winston also.
Thanks
Yunhong Jiang
Quoted 27 lines · [email protected] <> wrote:
Quoted 11 lines · Qing He
Quoted 1 line
Do you mean deinitialised and unloaded the device driver?
Yes, the racey condition we just talked happens here. Consider the following case, when
remove_pci_deviceis called, the device data structure is removed by the hypervisor. But there is no guarauntee in the hypervisor that guest already has knowledge, for example the guest may continue to access the device resources. It's in this case msixtbl_{read,write} has a little racey condition.I don't think this scenario is desirable, but does it happen in the current logic?
Uh, well since dom0 is in fact mostly in charge of PCI access, there's not
much we can do in Xen to enforce this. At that level we kind of have to assume that dom0 has sequenced hotplug/hotunplug sensibly.-- Keir
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel