vmd: Fix infinite loop executing irq's
PATCH 1/2 vmd: Fix infinite loop executing irq's
We can't initialize the list head on deletion as this causes the node to point to itself, looping infinitely if the vmd IRQ handler happens to be servicing that node.
The list initialization supposed to fix a bug from multiple calls to disable the same IRQ. We can fix this instead just checking if the previous pointer indicates it was already deleted.
--- arch/x86/pci/vmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/pci/vmd.c +2 -2
@@ -136,8 +136,8 @@ static void vmd_irq_disable(struct irq_data *data) data->chip->irq_mask (data);raw_spin_lock_irqsave (&list_lock, flags); -list_del_rcu (&vmdirq->node); -INIT_LIST_HEAD_RCU (&vmdirq->node); +if (vmdirq->node.prev !=LIST_POISON2 ) +list_del_rcu (&vmdirq->node);raw_spin_unlock_irqrestore (&list_lock, flags); }
Signature · 1 line
2.7.2
PATCH 2/2 vmd: Synchronize with RCU freeing msi irq descs
This patch fixes a potential race when disabling MSI/MSI-x on a VMD domain device. If the vmd interrupt service is running, it may see a disabled irq. We can synchronize rcu just before freeing the msi descriptor. This is safe since the irq_desc lock isn't held, and the descriptor is valid even though it is disabled. After vmd_msi_free, though, the handler is reinitialiazed to handle_bad_irq, so we can't let the vmd isr's list iteration see the disabled irq after this.
--- arch/x86/pci/vmd.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/pci/vmd.c +2 -0
@@ -213,6 +213,8 @@ static void vmd_msi_free(struct irq_domain *domain,struct vmd_irq *vmdirq =irq_get_chip_data (virq);unsigned long flags; +synchronize_rcu (); +/* XXX: Potential optimization to rebalance */ raw_spin_lock_irqsave (&list_lock, flags); vmdirq->irq->count--;
Signature · 1 line
2.7.2
Re: [PATCH 2/2] vmd: Synchronize with RCU freeing msi irq descs
This one's fine
Acked-by Jon Derrick: <[email protected]>
Quoted 29 lines · Keith Busch
This patch fixes a potential race when disabling MSI/MSI-x on a VMD domain device. If the vmd interrupt service is running, it may see a disabled irq. We can synchronize rcu just before freeing the msi descriptor. This is safe since the
irq_desclock isn't held, and the descriptor is valid even though it is disabled. Aftervmd_msi_free, though, the handler is reinitialiazed tohandle_bad_irq, so we can't let the vmd isr's list iteration see the disabled irq after this.Signed-off-by Keith Busch <[email protected]>--- arch/x86/pci/vmd.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/pci/vmd.c +2
-0@@ -213,6 +213,8 @@ static void vmd_msi_free(struct irq_domain *domain,struct vmd_irq *vmdirq =irq_get_chip_data (virq);unsigned long flags; +synchronize_rcu (); +/* XXX: Potential optimization to rebalance */ raw_spin_lock_irqsave (&list_lock, flags); vmdirq->irq->count--;Signature · 1 line
2.7.2
Re: [PATCH 2/2] vmd: Synchronize with RCU freeing msi irq descs
Hi Bjorn,
Any chance of pulling this one in?
Thanks,
Jon
Quoted 39 lines · Jon Derrick
This one's fine
Acked-by Jon Derrick: <[email protected]>
Quoted 29 lines · Keith Busch
This patch fixes a potential race when disabling MSI/MSI-x on a VMD domain device. If the vmd interrupt service is running, it may see a disabled irq. We can synchronize rcu just before freeing the msi descriptor. This is safe since the
irq_desclock isn't held, and the descriptor is valid even though it is disabled. Aftervmd_msi_free, though, the handler is reinitialiazed tohandle_bad_irq, so we can't let the vmd isr's list iteration see the disabled irq after this.Signed-off-by Keith Busch <[email protected]>--- arch/x86/pci/vmd.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/pci/vmd.c +2
-0@@ -213,6 +213,8 @@ static void vmd_msi_free(struct irq_domain *domain,struct vmd_irq *vmdirq =irq_get_chip_data (virq);unsigned long flags; +synchronize_rcu (); +/* XXX: Potential optimization to rebalance */ raw_spin_lock_irqsave (&list_lock, flags); vmdirq->irq->count--;Signature · 1 line
2.7.2--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] vmd: Synchronize with RCU freeing msi irq descs
In reply to Keith BuschQuoted 9 lines · Keith Busch
This patch fixes a potential race when disabling MSI/MSI-x on a VMD domain device. If the vmd interrupt service is running, it may see a disabled irq. We can synchronize rcu just before freeing the msi descriptor. This is safe since the
irq_desclock isn't held, and the descriptor is valid even though it is disabled. Aftervmd_msi_free, though, the handler is reinitialiazed tohandle_bad_irq, so we can't let the vmd isr's list iteration see the disabled irq after this.Signed-off-by Keith Busch <[email protected]>
Applied with Jon's ack to pci/host-vmd for v4.9, thanks!
If anybody else reads this, this patch got lost for a while because it was posted as the second patch of a series. I had some comments on the first patch that led to a little rework. When that happens, I mark the *entire* series as "Changes requested" or "Superseded" because I'm expecting a complete repost with the rework.
It's too much work for me to track individual patches within a series. So if you update one patch in a series, please just repost the entire series, including other patches that may be unmodified.
Bjorn
Quoted 24 lines
--- arch/x86/pci/vmd.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/pci/vmd.c +2
-0@@ -213,6 +213,8 @@ static void vmd_msi_free(struct irq_domain *domain,struct vmd_irq *vmdirq =irq_get_chip_data (virq);unsigned long flags; +synchronize_rcu (); +/* XXX: Potential optimization to rebalance */ raw_spin_lock_irqsave (&list_lock, flags); vmdirq->irq->count--;Signature · 6 lines
2.7.2 -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Keith Busch
We can't initialize the list head on deletion as this causes the node to point to itself, looping infinitely if the vmd IRQ handler happens to be servicing that node.
The list initialization supposed to fix a bug from multiple calls to disable the same IRQ. We can fix this instead just checking if the previous pointer indicates it was already deleted.
Should this have one or possibly more"fixes" lines here?
???Fixes: 97e9230 ("x86/PCI: VMD: Initialize list item in IRQ disable")???
Quoted 27 lines
Signed-off-by Keith Busch <[email protected]>--- arch/x86/pci/vmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/pci/vmd.c +2
-3@@ -136,8 +136,8 @@ static void vmd_irq_disable(struct irq_data *data) data->chip->irq_mask (data);raw_spin_lock_irqsave (&list_lock, flags); -list_del_rcu (&vmdirq->node); -INIT_LIST_HEAD_RCU (&vmdirq->node); +if (vmdirq->node.prev !=LIST_POISON2 ) +list_del_rcu (&vmdirq->node);raw_spin_unlock_irqrestore (&list_lock, flags); } --2.7.2
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
WWVzIHRoYXQncyB0aGUgb25lIGl0IGZpeGVzDQoNCi0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0t DQpGcm9tOiBNeXJvbiBTdG93ZSBbbWFpbHRvOm15cm9uLnN0b3dlQGdtYWlsLmNvbV0gDQpTZW50 OiBUaHVyc2RheSwgQXVndXN0IDQsIDIwMTYgNDo0OCBQTQ0KVG86IEJ1c2NoLCBLZWl0aCA8a2Vp dGguYnVzY2hAaW50ZWwuY29tPg0KQ2M6IGxpbnV4LXBjaSA8bGludXgtcGNpQHZnZXIua2VybmVs Lm9yZz47IEJqb3JuIEhlbGdhYXMgPGJoZWxnYWFzQGdvb2dsZS5jb20+OyBEZXJyaWNrLCBKb25h dGhhbiA8am9uYXRoYW4uZGVycmlja0BpbnRlbC5jb20+DQpTdWJqZWN0OiBSZTogW1BBVENIIDEv Ml0gdm1kOiBGaXggaW5maW5pdGUgbG9vcCBleGVjdXRpbmcgaXJxJ3MNCg0KT24gVGh1LCBBdWcg NCwgMjAxNiBhdCA0OjA5IFBNLCBLZWl0aCBCdXNjaCA8a2VpdGguYnVzY2hAaW50ZWwuY29tPiB3 cm90ZToNCj4gV2UgY2FuJ3QgaW5pdGlhbGl6ZSB0aGUgbGlzdCBoZWFkIG9uIGRlbGV0aW9uIGFz IHRoaXMgY2F1c2VzIHRoZSBub2RlIA0KPiB0byBwb2ludCB0byBpdHNlbGYsIGxvb3BpbmcgaW5m aW5pdGVseSBpZiB0aGUgdm1kIElSUSBoYW5kbGVyIGhhcHBlbnMgDQo+IHRvIGJlIHNlcnZpY2lu ZyB0aGF0IG5vZGUuDQo+DQo+IFRoZSBsaXN0IGluaXRpYWxpemF0aW9uIH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gICAgbGlzdF9kZWxfcmN1KCZ2bWRpcnEtPm5v ZGUpOw0KPiAtICAgICAgIElOSVRfTElTVF9IRUFEX1JDVSgmdm1kaXJxLT5ub2RlKTsNCj4gKyAg ICAgICBpZiAodm1kaXJxLT5ub2RlLnByZXYgIT0gTElTVF9QT0lTT04yKQ0KPiArICAgICAgICAg ICAgICAgbGlzdF9kZWxfcmN1KCZ2bWRpcnEtPm5vZGUpOw0KPiAgICAgICAgIHJhd19zcGluX3Vu bG9ja19pcnFyZXN0b3JlKCZsaXN0X2xvY2ssIGZsYWdzKTsgIH0NCj4NCj4gLS0NCj4gMi43LjIN Cj4NCj4gLS0NCj4gVG8gdW5zdWJzY3JpYmUgZnJvbSB0aGlzIGxpc3Q6IHNlbmQgdGhlIGxpbmUg InVuc3Vic2NyaWJlIGxpbnV4LXBjaSIgDQo+IGluIHRoZSBib2R5IG9mIGEgbWVzc2FnZSB0byBt YWpvcmRvbW9Admdlci5rZXJuZWwub3JnIE1vcmUgbWFqb3Jkb21vIA0KPiBpbmZvIGF0ICBodHRw Oi8vdmdlci5rZXJuZWwub3JnL21ham9yZG9tby1pbmZvLmh0bWwNCg==
Hi Keith,
Quoted 18 lines · Keith Busch
We can't initialize the list head on deletion as this causes the node to point to itself, looping infinitely if the vmd IRQ handler happens to be servicing that node.
The list initialization supposed to fix a bug from multiple calls to disable the same IRQ. We can fix this instead just checking if the previous pointer indicates it was already deleted.
Signed-off-by Keith Busch <[email protected]>--- arch/x86/pci/vmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/pci/vmd.c +0
-0
arch/x86/pci/vmd.c static void vmd_irq_disable(struct irq_data *data) · line 140
Quoted 7 lines
arch/x86/pci/vmd.c +2
-2@@ -136,8 +136,8 @@ static void vmd_irq_disable(struct irq_data *data) data->chip->irq_mask (data);raw_spin_lock_irqsave (&list_lock, flags); -list_del_rcu (&vmdirq->node); -INIT_LIST_HEAD_RCU (&vmdirq->node); +if (vmdirq->node.prev !=LIST_POISON2 ) +list_del_rcu (&vmdirq->node);
It doesn't seem quite right to test for LIST_POISON2. It seems like a little too much knowledge of list internals. There are no other similar tests in the kernel. Surely this isn't the only case where we need to remove from a list that another thread might be traversing. I would look for other similar situations and copy the way they handle it.
I think I saw a Fixes: tag later, so I assume you'll pick that up for v2. Should this also be tagged for stable? Are there any bug reports we should reference?
Quoted 3 lines
arch/x86/pci/vmd.c +0
-0raw_spin_unlock_irqrestore (&list_lock, flags); }
Quoted 6 lines · Bjorn Helgaas
It doesn't seem quite right to test for
LIST_POISON2. It seems like a little too much knowledge of list internals. There are no other similar tests in the kernel. Surely this isn't the only case where we need to remove from a list that another thread might be traversing. I would look for other similar situations and copy the way they handle it.
Yeah, I agree that's abusing internal knowledge of the API. We can track this state another way. Will fix and resend.
Quoted 3 lines
I think I saw a Fixes: tag later, so I assume you'll pick that up for v2. Should this also be tagged for stable? Are there any bug reports we should reference?
I'll add the fixes in the v2. This bug was reported only on internal Intel bug tracking, but I can still add a "Reported-by" and "Tested-by" tags. And no need for a stable since the bug was introduced in 4.8 merge window.