KVM: x86: implement IOAPIC_REG_EOI for directed EOI support
PATCH 1/1 KVM: x86: implement IOAPIC_REG_EOI for directed EOI support
If the guest takes advantage of the directed EOI feature by setting APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.
Quoted 1 line
From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."
Commit fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part. IOAPIC_REG_EOI writes were handled only on IA64 and the code was later removed with the rest of IA64 support.
The bug has gone undetected for a long time because Linux writes to IOAPIC_REG_EOI only if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.
This commit re-adds IOAPIC_REG_EOI and implements it in terms of __kvm_ioapic_update_eoi.
--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)
arch/x86/kvm/ioapic.c +28 -18
@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);
@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock); - -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) { +/* +* We are dropping lock while calling ack notifiers because ack +* notifier callbacks for assigned devices call into IOAPIC +* recursively. Since remote_irr is cleared only after call +* to notifiers if the same vector will be delivered while lock +* is dropped it will be put into irr and will be delivered +* after ack notifier returns. +*/ +spin_unlock (&ioapic->lock); +kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); +spin_lock (&ioapic->lock); + +if (trigger_mode !=IOAPIC_LEVEL_TRIG || +kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +continue ; + }ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG ); ent->fields.remote_irr =0 ;
@@ -478,7 +481,7 @@ void kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode)struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;spin_lock (&ioapic->lock); -__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode); +__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode, false);spin_unlock (&ioapic->lock); }
@@ -540,6 +543,7 @@ static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr, int len, const void *val) { struct kvm_ioapic *ioapic = to_ioapic(this); +struct kvm_lapic *apic = vcpu->arch.apic;u32 data;if (!ioapic_in_range (ioapic, addr))return -EOPNOTSUPP ;
@@ -575,6 +579,12 @@ static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this,ioapic_write_indirect (ioapic, data);break ; +case IOAPIC_REG_EOI : +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +__kvm_ioapic_update_eoi (vcpu, ioapic, data, +IOAPIC_LEVEL_TRIG , true); +break ; +default :break ; }
arch/x86/kvm/ioapic.h +1 -0
@@ -20,6 +20,7 @@ struct kvm_vcpu;/* Direct registers. */ #define IOAPIC_REG_SELECT 0x00#define IOAPIC_REG_WINDOW 0x10 +#define IOAPIC_REG_EOI 0x40/* Indirect registers. */ #define IOAPIC_REG_APIC_ID 0x00/* x86 IOAPIC only */
Signature · 1 line
2.9.3
Quoted 9 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."
Quoted 8 lines
Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.
Hi, Ladi,
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version 0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.
I think the problem is why the guest setup APIC_SPIV_DIRECTED_EOI even if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.
Quoted 43 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-8@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 10 lines
arch/x86/kvm/ioapic.c +1
-9-* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock); - -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {
Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Thanks,
Quoted 64 lines
arch/x86/kvm/ioapic.c +24
-1+/* +* We are dropping lock while calling ack notifiers because ack +* notifier callbacks for assigned devices call into IOAPIC +* recursively. Since remote_irr is cleared only after call +* to notifiers if the same vector will be delivered while lock +* is dropped it will be put into irr and will be delivered +* after ack notifier returns. +*/ +spin_unlock (&ioapic->lock); +kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); +spin_lock (&ioapic->lock); + +if (trigger_mode !=IOAPIC_LEVEL_TRIG || +kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +continue ; + }ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG ); ent->fields.remote_irr =0 ;@@ -478,7 +481,7 @@ void kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode)struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;spin_lock (&ioapic->lock); -__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode); +__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode, false);spin_unlock (&ioapic->lock); }@@ -540,6 +543,7 @@ static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr, int len, const void *val) { struct kvm_ioapic *ioapic = to_ioapic(this); +struct kvm_lapic *apic = vcpu->arch.apic;u32 data;if (!ioapic_in_range (ioapic, addr))return -EOPNOTSUPP ;@@ -575,6 +579,12 @@ static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this,ioapic_write_indirect (ioapic, data);break ; +case IOAPIC_REG_EOI : +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +__kvm_ioapic_update_eoi (vcpu, ioapic, data, +IOAPIC_LEVEL_TRIG , true); +break ; +default :break ; }arch/x86/kvm/ioapic.h +1
-0@@ -20,6 +20,7 @@ struct kvm_vcpu;/* Direct registers. */ #define IOAPIC_REG_SELECT 0x00#define IOAPIC_REG_WINDOW 0x10 +#define IOAPIC_REG_EOI 0x40/* Indirect registers. */ #define IOAPIC_REG_APIC_ID 0x00/* x86 IOAPIC only */ Signature · 1 line
2.9.3
Signature · 1 line
Peter Xu
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.
Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.
Thanks, that makes perfect sense and explains why Linux behaves the way it does (__eoi_ioapic_pin in arch/x86/kernel/apic/io_apic.c).
This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >= 0x20 but I don't see that in the document either.
I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Quoted 3 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.
Yes, I think that the guest is to blame here. We might add that to the commit message.
Quoted 48 lines
Quoted 48 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);
Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Thanks!
Ladi
Quoted 69 lines
Thanks,
Quoted 62 lines
arch/x86/kvm/ioapic.c +24
-1+/* +* We are dropping lock while calling ack notifiers because ack +* notifier callbacks for assigned devices call into IOAPIC +* recursively. Since remote_irr is cleared only after call +* to notifiers if the same vector will be delivered while lock +* is dropped it will be put into irr and will be delivered +* after ack notifier returns. +*/ +spin_unlock (&ioapic->lock); +kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); +spin_lock (&ioapic->lock); + +if (trigger_mode !=IOAPIC_LEVEL_TRIG || +kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +continue ; + }ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG ); ent->fields.remote_irr =0 ;@@ -478,7 +481,7 @@ void kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode)struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;spin_lock (&ioapic->lock); -__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode); +__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode, false);spin_unlock (&ioapic->lock); }@@ -540,6 +543,7 @@ static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr, int len, const void *val) { struct kvm_ioapic *ioapic = to_ioapic(this); +struct kvm_lapic *apic = vcpu->arch.apic;u32 data;if (!ioapic_in_range (ioapic, addr))return -EOPNOTSUPP ;@@ -575,6 +579,12 @@ static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this,ioapic_write_indirect (ioapic, data);break ; +case IOAPIC_REG_EOI : +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +__kvm_ioapic_update_eoi (vcpu, ioapic, data, +IOAPIC_LEVEL_TRIG , true); +break ; +default :break ; }arch/x86/kvm/ioapic.h +1
-1@@ -20,6 +20,7 @@ struct kvm_vcpu;/* Direct registers. */ #define IOAPIC_REG_SELECT 0x00#define IOAPIC_REG_WINDOW 0x10 +#define IOAPIC_REG_EOI 0x40/* Indirect registers. */ #define IOAPIC_REG_APIC_ID 0x00/* x86 IOAPIC only */ --Quoted 2 lines
2.9.3
--
Peter Xu
Quoted 42 lines · Ladi Prosek
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdf
However I see nothing related to how the IOAPIC version is defined. In that sense, the comment above __eoi_ioapic_pin() seems to be better. :)
Quoted 7 lines
Quoted 4 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.Yes, I think that the guest is to blame here. We might add that to the commit message.
Agreed.
Quoted 62 lines
Quoted 49 lines
Quoted 49 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
Quoted 6 lines
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Instead of the "!directed" flag (which is imho duplicated with what APIC_SPIV_DIRECTED_EOI means), do you like below fix?
-----8<-----
arch/x86/kvm/ioapic.c +6 -2
@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );
@@ -473,10 +472,15 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, } } +/* This should only be triggered by APIC EOI broadcast */ void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) {struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; +/* If we'll be using direct EOI, skip broadcast */ +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +spin_lock (&ioapic->lock);__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode);spin_unlock (&ioapic->lock);
---->8----
This patch along will break kvm_notify_acked_irq() in some way I guess, but if with your patch (though will possibly need to boost IOAPIC version to 0x20 as well), it should work fine as long as guest remembers to send the direct EOI.
Thanks,
Signature · 1 line
Peter Xu
Quoted 160 lines · Peter Xu
Quoted 42 lines · Ladi Prosek
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Quoted 7 lines
Quoted 4 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.Yes, I think that the guest is to blame here. We might add that to the commit message.
Agreed.
Quoted 62 lines
Quoted 49 lines
Quoted 49 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
Quoted 6 lines
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Instead of the "!directed" flag (which is imho duplicated with what
APIC_SPIV_DIRECTED_EOImeans), do you like below fix?-----8<-----
arch/x86/kvm/ioapic.c +1
-2@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );@@ -473,10 +472,15 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, } }
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 483
Quoted 10 lines
arch/x86/kvm/ioapic.c +5
-0+/* This should only be triggered by APIC EOI broadcast */ void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) {struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; +/* If we'll be using direct EOI, skip broadcast */ +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +
I've only seen the direct EOI sent for level irqs so I'm afraid that __kvm_ioapic_update_eoi needs to run for edge-triggered even if the APIC_SPIV_DIRECTED_EOI flag is set.
Other than that it looks reasonable.
Quoted 9 lines
arch/x86/kvm/ioapic.c +0
-1spin_lock (&ioapic->lock);__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode);spin_unlock (&ioapic->lock); ---->8----This patch along will break
kvm_notify_acked_irq()in some way I guess, but if with your patch (though will possibly need to boost IOAPIC version to0x20as well), it should work fine as long as guest remembers to send the direct EOI.
Not sure about the version boost, especially since we don't have a good spec to define what the version means. Maybe only if it helps Linux performance. In theory __eoi_ioapic_pin should be causing fewer vmexits with version>=0x20.
Quoted 4 lines
Thanks,
--
Peter Xu
Quoted 176 lines · Ladi Prosek
Quoted 160 lines · Peter Xu
Quoted 42 lines · Ladi Prosek
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Quoted 7 lines
Quoted 4 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.Yes, I think that the guest is to blame here. We might add that to the commit message.
Agreed.
Quoted 62 lines
Quoted 49 lines
Quoted 49 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
Quoted 6 lines
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Instead of the "!directed" flag (which is imho duplicated with what
APIC_SPIV_DIRECTED_EOImeans), do you like below fix?-----8<-----
arch/x86/kvm/ioapic.c +1
-2@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );@@ -473,10 +472,15 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, } }arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 483
Quoted 10 lines
arch/x86/kvm/ioapic.c +5
-0+/* This should only be triggered by APIC EOI broadcast */ void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) {struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; +/* If we'll be using direct EOI, skip broadcast */ +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +I've only seen the direct EOI sent for level irqs so I'm afraid that
__kvm_ioapic_update_eoineeds to run for edge-triggered even if theAPIC_SPIV_DIRECTED_EOIflag is set.
Quoted 1 line
Other than that it looks reasonable.
Although, wait, what if the guest uses APIC_SPIV_DIRECTED_EOI to suppress the broadcast but then does EOI by writing to the IOAPIC routing entry? You kind of indicated that this would be a valid use of the feature. This is what __eoi_ioapic_pin does for version<0x20 and on the host side we reset the remote_irr in ioapic_write_indirect if I'm reading the code correctly. Wouldn't we want to deliver the notification via kvm_notify_acked_irq in this case also?
Thanks!
Quoted 19 lines
Quoted 9 lines
arch/x86/kvm/ioapic.c +0
-1spin_lock (&ioapic->lock);__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode);spin_unlock (&ioapic->lock); ---->8----This patch along will break
kvm_notify_acked_irq()in some way I guess, but if with your patch (though will possibly need to boost IOAPIC version to0x20as well), it should work fine as long as guest remembers to send the direct EOI.Not sure about the version boost, especially since we don't have a good spec to define what the version means. Maybe only if it helps Linux performance. In theory
__eoi_ioapic_pinshould be causing fewer vmexits with version>=0x20.Quoted 4 lines
Thanks,
--
Peter Xu
Quoted 168 lines · Ladi Prosek
Quoted 167 lines · Ladi Prosek
Quoted 166 lines · Peter Xu
Quoted 42 lines · Ladi Prosek
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Quoted 7 lines
Quoted 4 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.Yes, I think that the guest is to blame here. We might add that to the commit message.
Agreed.
Quoted 62 lines
Quoted 49 lines
Quoted 49 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
Quoted 6 lines
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Instead of the "!directed" flag (which is imho duplicated with what
APIC_SPIV_DIRECTED_EOImeans), do you like below fix?-----8<-----
arch/x86/kvm/ioapic.c +2
-2@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );@@ -473,10 +472,15 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, } } +/* This should only be triggered by APIC EOI broadcast */ void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) {struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
Quoted 8 lines
Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 483
Quoted 4 lines
arch/x86/kvm/ioapic.c +4
-0+/* If we'll be using direct EOI, skip broadcast */ +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +I've only seen the direct EOI sent for level irqs so I'm afraid that
__kvm_ioapic_update_eoineeds to run for edge-triggered even if theAPIC_SPIV_DIRECTED_EOIflag is set.
Yes, if without your patch, it is problematic. But if with your patch, __kvm_ioapic_update_eoi() will be called in ioapic mmio write then.
Quoted 7 lines
Quoted 2 lines
Other than that it looks reasonable.
Although, wait, what if the guest uses
APIC_SPIV_DIRECTED_EOIto suppress the broadcast but then does EOI by writing to the IOAPIC routing entry? You kind of indicated that this would be a valid use of the feature.
That's exactly how I understand it. :)
Quoted 4 lines
This is what
__eoi_ioapic_pindoes for version<0x20 and on the host side we reset theremote_irrinioapic_write_indirectif I'm reading the code correctly. Wouldn't we want to deliver the notification viakvm_notify_acked_irqin this case also?
I think in that case (EOI sent via "direct EOI" of ioapic mmio register) the remote_irr is not cleaned in ioapic_write_indirect(), but it's cleaned in __kvm_ioapic_update_eoi() as well. It has the line:
ent->fields.remote_irr = 0;
Right?
Quoted 17 lines
Thanks!
Quoted 14 lines
Quoted 9 lines
arch/x86/kvm/ioapic.c +0
-1spin_lock (&ioapic->lock);__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode);spin_unlock (&ioapic->lock); ---->8----This patch along will break
kvm_notify_acked_irq()in some way I guess, but if with your patch (though will possibly need to boost IOAPIC version to0x20as well), it should work fine as long as guest remembers to send the direct EOI.Not sure about the version boost, especially since we don't have a good spec to define what the version means. Maybe only if it helps Linux performance. In theory
__eoi_ioapic_pinshould be causing fewer vmexits with version>=0x20.
I think at least from the comment it means only ioapic version 0x20 has that EOI register, and that's how I understand it.
Btw, I would even optimize my above fix to the following, which I like it better:
---->8----
arch/x86/kvm/ioapic.c +1 -2
@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );
arch/x86/kvm/lapic.c +3 -0
@@ -1064,6 +1064,9 @@ static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)if (!kvm_ioapic_handles_vector (apic, vector))return ; +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +/* Request a KVM exit to inform the userspace IOAPIC. */ if (irqchip_split (apic->vcpu->kvm)) { apic->vcpu->arch.pending_ioapic_eoi = vector;
----8<----
Moving the APIC_SPIV_DIRECTED_EOI check into kvm_ioapic_send_eoi() will make sure kvm will not send this useless EOI broadcast even the ioapic is in userspace.
Thanks,
Signature · 1 line
Peter Xu
Quoted 178 lines · Peter Xu
Quoted 168 lines · Ladi Prosek
Quoted 167 lines · Ladi Prosek
Quoted 166 lines · Peter Xu
Quoted 42 lines · Ladi Prosek
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Quoted 7 lines
Quoted 4 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.Yes, I think that the guest is to blame here. We might add that to the commit message.
Agreed.
Quoted 62 lines
Quoted 49 lines
Quoted 49 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
Quoted 6 lines
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Instead of the "!directed" flag (which is imho duplicated with what
APIC_SPIV_DIRECTED_EOImeans), do you like below fix?-----8<-----
arch/x86/kvm/ioapic.c +2
-2@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );@@ -473,10 +472,15 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, } } +/* This should only be triggered by APIC EOI broadcast */ void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) {struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;Quoted 8 lines
Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 483
Quoted 4 lines
arch/x86/kvm/ioapic.c +4
-0+/* If we'll be using direct EOI, skip broadcast */ +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +I've only seen the direct EOI sent for level irqs so I'm afraid that
__kvm_ioapic_update_eoineeds to run for edge-triggered even if theAPIC_SPIV_DIRECTED_EOIflag is set.
Quoted 2 lines
Yes, if without your patch, it is problematic. But if with your patch,
__kvm_ioapic_update_eoi()will be called in ioapic mmio write then.
No, there's no ioapic mmio write for edge-triggered interrupts, at least Windows don't do any. Edge interrupts must still be handled on the lapic EOI path.
Quoted 15 lines
Quoted 7 lines
Quoted 2 lines
Other than that it looks reasonable.
Although, wait, what if the guest uses
APIC_SPIV_DIRECTED_EOIto suppress the broadcast but then does EOI by writing to the IOAPIC routing entry? You kind of indicated that this would be a valid use of the feature.That's exactly how I understand it. :)
Quoted 4 lines
This is what
__eoi_ioapic_pindoes for version<0x20 and on the host side we reset theremote_irrinioapic_write_indirectif I'm reading the code correctly. Wouldn't we want to deliver the notification viakvm_notify_acked_irqin this case also?
Quoted 8 lines
I think in that case (EOI sent via "direct EOI" of ioapic mmio register) the
remote_irris not cleaned inioapic_write_indirect(), but it's cleaned in__kvm_ioapic_update_eoi()as well. It has the line:ent->fields.remote_irr = 0;Right?
Right, but I meant the other case, a guest that sets APIC_SPIV_DIRECTED_EOI but doesn't write to IOAPIC_REG_EOI. With your patch there would be no kvm_notify_acked_irq and that doesn't look correct.
Quoted 63 lines
Quoted 17 lines
Thanks!
Quoted 14 lines
Quoted 9 lines
arch/x86/kvm/ioapic.c +0
-1spin_lock (&ioapic->lock);__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode);spin_unlock (&ioapic->lock); ---->8----This patch along will break
kvm_notify_acked_irq()in some way I guess, but if with your patch (though will possibly need to boost IOAPIC version to0x20as well), it should work fine as long as guest remembers to send the direct EOI.Not sure about the version boost, especially since we don't have a good spec to define what the version means. Maybe only if it helps Linux performance. In theory
__eoi_ioapic_pinshould be causing fewer vmexits with version>=0x20.I think at least from the comment it means only ioapic version
0x20has that EOI register, and that's how I understand it.Btw, I would even optimize my above fix to the following, which I like it better:
---->8----
arch/x86/kvm/ioapic.c +1
-2@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );arch/x86/kvm/lapic.c +3
-1@@ -1064,6 +1064,9 @@ static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)if (!kvm_ioapic_handles_vector (apic, vector))return ; +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +/* Request a KVM exit to inform the userspace IOAPIC. */ if (irqchip_split (apic->vcpu->kvm)) { apic->vcpu->arch.pending_ioapic_eoi = vector; ----8<----Moving the
APIC_SPIV_DIRECTED_EOIcheck intokvm_ioapic_send_eoi()will make sure kvm will not send this useless EOI broadcast even the ioapic is in userspace.Thanks,
--
Peter Xu
Quoted 179 lines · Ladi Prosek
Quoted 178 lines · Peter Xu
Quoted 176 lines · Ladi Prosek
Quoted 175 lines · Ladi Prosek
Quoted 160 lines · Peter Xu
Quoted 42 lines · Ladi Prosek
Quoted 15 lines · Peter Xu
Quoted 14 lines · Ladi Prosek
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Quoted 7 lines
Quoted 4 lines
I think the problem is why the guest setup
APIC_SPIV_DIRECTED_EOIeven if IOAPIC does not support direct EOI (the guest can know it by probing IOAPIC version). Please correct if I'm wrong.Yes, I think that the guest is to blame here. We might add that to the commit message.
Agreed.
Quoted 62 lines
Quoted 49 lines
Quoted 49 lines
This commit re-adds
IOAPIC_REG_EOIand implements it in terms of__kvm_ioapic_update_eoi.Fixes fc61b800f950 ("KVM: Add Directed EOI support to APIC emulation")Signed-off-by Ladi Prosek <[email protected]>--- arch/x86/kvm/ioapic.c | 46 ++++++++++++++++++++++++++++------------------ arch/x86/kvm/ioapic.h | 1 + 2 files changed, 29 insertions(+), 18 deletions(-)arch/x86/kvm/ioapic.c +3
-13@@ -415,14 +415,15 @@ static void kvm_ioapic_eoi_inject_work(struct work_struct *work)#define IOAPIC_SUCCESSIVE_IRQ_MAX_COUNT 10000static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, -struct kvm_ioapic *ioapic,int vector,int trigger_mode) +struct kvm_ioapic *ioapic,int vector,int trigger_mode, +bool directed) {struct dest_map *dest_map = &ioapic->rtc_status.dest_map;struct kvm_lapic *apic = vcpu->arch.apic;int i;/* RTC special handling */ -if (test_bit (vcpu->vcpu_id, dest_map->map) && +if (!directed &&test_bit (vcpu->vcpu_id, dest_map->map) && vector == dest_map->vectors[vcpu->vcpu_id])rtc_irq_eoi (ioapic, vcpu);@@ -432,21 +433,23 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; -/* -* We are dropping lock while calling ack notifiers because ack -* notifier callbacks for assigned devices call into IOAPIC -* recursively. Since remote_irr is cleared only after call -* to notifiers if the same vector will be delivered while lock -* is dropped it will be put into irr and will be delivered -* after ack notifier returns. -*/ -spin_unlock (&ioapic->lock); -kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i); -spin_lock (&ioapic->lock);Quoted 8 lines
arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 436
Quoted 5 lines
arch/x86/kvm/ioapic.c +1
-4- -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) -continue ; +if (!directed) {Could I ask why we need to skip this if the EOI is sent via direct EOI register of IOAPIC?
Because it's already been done as part of the local EOI. With directed EOI we hit this function twice, first time when doing the local EOI and then the newly added code path for IOAPIC EOI with directed=true.
Quoted 6 lines
I, again, followed the above mentioned document which explicitly dictates the sequence. And I mechanically split the function to the "local part' - what it had been doing up to the continue statement - and the "directed part" - what it had been skipping. I'll admit that my familiarity with this code is limited and there may be a better way to do this.
Instead of the "!directed" flag (which is imho duplicated with what
APIC_SPIV_DIRECTED_EOImeans), do you like below fix?-----8<-----
arch/x86/kvm/ioapic.c +1
-2@@ -444,8 +444,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );@@ -473,10 +472,15 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, } }arch/x86/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, · line 483
Quoted 10 lines
arch/x86/kvm/ioapic.c +5
-0+/* This should only be triggered by APIC EOI broadcast */ void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) {struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic; +/* If we'll be using direct EOI, skip broadcast */ +if (kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +return ; +I've only seen the direct EOI sent for level irqs so I'm afraid that
__kvm_ioapic_update_eoineeds to run for edge-triggered even if theAPIC_SPIV_DIRECTED_EOIflag is set.
Quoted 6 lines
Quoted 2 lines
Yes, if without your patch, it is problematic. But if with your patch,
__kvm_ioapic_update_eoi()will be called in ioapic mmio write then.No, there's no ioapic mmio write for edge-triggered interrupts, at least Windows don't do any. Edge interrupts must still be handled on the lapic EOI path.
I see. Yes it may break that. Though I don't know in what case someone would register to this IOAPIC eoi message if it's edge-triggered...
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 3 lines
Other than that it looks reasonable.
Although, wait, what if the guest uses
APIC_SPIV_DIRECTED_EOIto suppress the broadcast but then does EOI by writing to the IOAPIC routing entry? You kind of indicated that this would be a valid use of the feature.That's exactly how I understand it. :)
Quoted 4 lines
This is what
__eoi_ioapic_pindoes for version<0x20 and on the host side we reset theremote_irrinioapic_write_indirectif I'm reading the code correctly. Wouldn't we want to deliver the notification viakvm_notify_acked_irqin this case also?I think in that case (EOI sent via "direct EOI" of ioapic mmio register) the
remote_irris not cleaned inioapic_write_indirect(), but it's cleaned in__kvm_ioapic_update_eoi()as well. It has the line:
Quoted 8 lines
Quoted 3 lines
ent->fields.remote_irr = 0;Right?
Right, but I meant the other case, a guest that sets
APIC_SPIV_DIRECTED_EOIbut doesn't write toIOAPIC_REG_EOI. With your patch there would be nokvm_notify_acked_irqand that doesn't look correct.
For level triggered irq, if it sets APIC_SPIV_DIRECTED_EOI but doesn't write IOAPIC_REG_EOI, it should be a guest bug, right?
Thinking about the migration issue that Radim has mentioned, I agree maybe we can consider just revert the suppress eoi broadcast. Actually now I start to wonder why direct EOI is introduced. I think it should be for performance's sake on systems has lots of ioapics? But looks like that's normally not the case, at least for kvm and most general machines, which only has one ioapic.
Thanks,
Signature · 1 line
Peter Xu
2017-04-13 16:32+0800, Peter Xu:
Quoted 21 lines · Ladi Prosek
Quoted 20 lines · Peter Xu
Quoted 18 lines · Ladi Prosek
Quoted 6 lines · Ladi Prosek
Quoted 5 lines · Peter Xu
Quoted 4 lines
void
kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode){ struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;Quoted 8 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ /* If we'll be using direct EOI, skip broadcast */ + if (kvm_lapic_get_reg(apic, APIC_SPIV) & APIC_SPIV_DIRECTED_EOI) + return; +I've only seen the direct EOI sent for level irqs so I'm afraid that
__kvm_ioapic_update_eoineeds to run for edge-triggered even if theAPIC_SPIV_DIRECTED_EOIflag is set.Yes, if without your patch, it is problematic. But if with your patch,
__kvm_ioapic_update_eoi()will be called in ioapic mmio write then.
Quoted 6 lines
Quoted 3 lines
No, there's no ioapic mmio write for edge-triggered interrupts, at least Windows don't do any. Edge interrupts must still be handled on the lapic EOI path.
I see. Yes it may break that. Though I don't know in what case someone would register to this IOAPIC eoi message if it's edge-triggered...
I don't know of any sane case ...
KVM PIT (arch/x86/kvm/i8254.c) uses it to keep track of lost edge interrupts so it could re-inject them.
Windows needed it for reasonable timeflow, IIRC.
The userspace probably uses it for similar reasons.
We have to keep the edge notifier working. :(
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 4 lines
This is what
__eoi_ioapic_pindoes for version<0x20 and on the host side we reset theremote_irrinioapic_write_indirectif I'm reading the code correctly. Wouldn't we want to deliver the notification viakvm_notify_acked_irqin this case also?I think in that case (EOI sent via "direct EOI" of ioapic mmio register) the
remote_irris not cleaned inioapic_write_indirect(), but it's cleaned in__kvm_ioapic_update_eoi()as well. It has the line:ent->fields.remote_irr = 0;Right?
Quoted 7 lines
Quoted 4 lines
Right, but I meant the other case, a guest that sets
APIC_SPIV_DIRECTED_EOIbut doesn't write toIOAPIC_REG_EOI. With your patch there would be nokvm_notify_acked_irqand that doesn't look correct.For level triggered irq, if it sets
APIC_SPIV_DIRECTED_EOIbut doesn't writeIOAPIC_REG_EOI, it should be a guest bug, right?
Yes.
Quoted 6 lines
Thinking about the migration issue that Radim has mentioned, I agree maybe we can consider just revert the suppress eoi broadcast. Actually now I start to wonder why direct EOI is introduced. I think it should be for performance's sake on systems has lots of ioapics? But looks like that's normally not the case, at least for kvm and most general machines, which only has one ioapic.
That is what I thought as well.
I am wondering why Windows uses it -- maybe they remap vector numbers and therefore need to EOI a different vector?
The feature might have been introduced because some OS assumed presence of the feature if x2APIC was available ...
Right, reverting it is pretty safe, because it was broken before. :) (And we ignore the SPIV completely when forwarding EOI to userspace.)
Does Windows 2016 work with this patch?
---8<---
arch/x86/kvm/ioapic.c +1 -2
@@ -442,8 +442,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );
arch/x86/kvm/lapic.c +0 -4
@@ -319,8 +319,6 @@ void kvm_apic_set_version(struct kvm_vcpu *vcpu)return ; feat =kvm_find_cpuid_entry (apic->vcpu,0x1 ,0 ); -if (feat && (feat->ecx & (1 << (X86_FEATURE_X2APIC &31 )))) - v |=APIC_LVR_DIRECTED_EOI ;kvm_lapic_set_reg (apic,APIC_LVR , v); }
@@ -1636,8 +1634,6 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)case APIC_SPIV : {u32 mask =0x3ff ; -if (kvm_lapic_get_reg (apic,APIC_LVR ) &APIC_LVR_DIRECTED_EOI ) - mask |=APIC_SPIV_DIRECTED_EOI ;apic_set_spiv (apic, val & mask);if (!(val &APIC_SPIV_APIC_ENABLED )) {int i;
Quoted 70 lines · Radim Krcmar
2017-04-13 16:32+0800, Peter Xu:
Quoted 21 lines · Ladi Prosek
Quoted 20 lines · Peter Xu
Quoted 18 lines · Ladi Prosek
Quoted 6 lines · Ladi Prosek
Quoted 5 lines · Peter Xu
Quoted 4 lines
void
kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode){ struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;Quoted 8 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ /* If we'll be using direct EOI, skip broadcast */ + if (kvm_lapic_get_reg(apic, APIC_SPIV) & APIC_SPIV_DIRECTED_EOI) + return; +I've only seen the direct EOI sent for level irqs so I'm afraid that
__kvm_ioapic_update_eoineeds to run for edge-triggered even if theAPIC_SPIV_DIRECTED_EOIflag is set.Yes, if without your patch, it is problematic. But if with your patch,
__kvm_ioapic_update_eoi()will be called in ioapic mmio write then.Quoted 6 lines
Quoted 3 lines
No, there's no ioapic mmio write for edge-triggered interrupts, at least Windows don't do any. Edge interrupts must still be handled on the lapic EOI path.
I see. Yes it may break that. Though I don't know in what case someone would register to this IOAPIC eoi message if it's edge-triggered...
I don't know of any sane case ...
KVM PIT (
arch/x86/kvm/i8254.c) uses it to keep track of lost edge interrupts so it could re-inject them.
Windows needed it for reasonable timeflow, IIRC.The userspace probably uses it for similar reasons.
We have to keep the edge notifier working. :(
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 4 lines
This is what
__eoi_ioapic_pindoes for version<0x20 and on the host side we reset theremote_irrinioapic_write_indirectif I'm reading the code correctly. Wouldn't we want to deliver the notification viakvm_notify_acked_irqin this case also?I think in that case (EOI sent via "direct EOI" of ioapic mmio register) the
remote_irris not cleaned inioapic_write_indirect(), but it's cleaned in__kvm_ioapic_update_eoi()as well. It has the line:ent->fields.remote_irr = 0;Right?
Quoted 7 lines
Quoted 4 lines
Right, but I meant the other case, a guest that sets
APIC_SPIV_DIRECTED_EOIbut doesn't write toIOAPIC_REG_EOI. With your patch there would be nokvm_notify_acked_irqand that doesn't look correct.For level triggered irq, if it sets
APIC_SPIV_DIRECTED_EOIbut doesn't writeIOAPIC_REG_EOI, it should be a guest bug, right?Yes.
Quoted 6 lines
Thinking about the migration issue that Radim has mentioned, I agree maybe we can consider just revert the suppress eoi broadcast. Actually now I start to wonder why direct EOI is introduced. I think it should be for performance's sake on systems has lots of ioapics? But looks like that's normally not the case, at least for kvm and most general machines, which only has one ioapic.
Quoted 4 lines
That is what I thought as well.
I am wondering why Windows uses it -- maybe they remap vector numbers and therefore need to EOI a different vector?
Maybe it has something to do with how they assign devices to the root Hyper-V partition. I've seen the issue only with NICs, if it helps.
Quoted 6 lines
The feature might have been introduced because some OS assumed presence of the feature if x2APIC was available ...
Right, reverting it is pretty safe, because it was broken before. :) (And we ignore the SPIV completely when forwarding EOI to userspace.)Does Windows 2016 work with this patch?
Yes, this patch works.
Quoted 37 lines
---8<---
arch/x86/kvm/ioapic.c +1
-2@@ -442,8 +442,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,kvm_notify_acked_irq (ioapic->kvm,KVM_IRQCHIP_IOAPIC , i);spin_lock (&ioapic->lock); -if (trigger_mode !=IOAPIC_LEVEL_TRIG || -kvm_lapic_get_reg (apic,APIC_SPIV ) &APIC_SPIV_DIRECTED_EOI ) +if (trigger_mode !=IOAPIC_LEVEL_TRIG )continue ;ASSERT (ent->fields.trig_mode ==IOAPIC_LEVEL_TRIG );arch/x86/kvm/lapic.c +0
-4@@ -319,8 +319,6 @@ void kvm_apic_set_version(struct kvm_vcpu *vcpu)return ; feat =kvm_find_cpuid_entry (apic->vcpu,0x1 ,0 ); -if (feat && (feat->ecx & (1 << (X86_FEATURE_X2APIC &31 )))) - v |=APIC_LVR_DIRECTED_EOI ;kvm_lapic_set_reg (apic,APIC_LVR , v); }@@ -1636,8 +1634,6 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)case APIC_SPIV : {u32 mask =0x3ff ; -if (kvm_lapic_get_reg (apic,APIC_LVR ) &APIC_LVR_DIRECTED_EOI ) - mask |=APIC_SPIV_DIRECTED_EOI ;apic_set_spiv (apic, val & mask);if (!(val &APIC_SPIV_APIC_ENABLED )) {int i;
Paolo Bonzini
maintainerQuoted 3 lines · Radim Krcmar
KVM PIT (
arch/x86/kvm/i8254.c) uses it to keep track of lost edge interrupts so it could re-inject them.
Windows needed it for reasonable timeflow, IIRC.
This is for old Linux.
Windows needs the RTC tracking, which also uses the irq ack notifier.
Quoted 4 lines
The feature might have been introduced because some OS assumed presence of the feature if x2APIC was available ...
Right, reverting it is pretty safe, because it was broken before. (And we ignore the SPIV completely when forwarding EOI to userspace.)
Yeah, that's the important part. I'm a bit worried of the consequences for migration, but AIUI you think it's fine? (That is, too many EOIs are not a problem, only too few are).
Paolo
2017-04-12 17:06+0800, Peter Xu:
Quoted 51 lines · Ladi Prosek
Quoted 42 lines · Peter Xu
Quoted 15 lines · Ladi Prosek
Quoted 14 lines
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Quoted 8 lines
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)
Yeah, it is officially described in ICH9 datasheet as:
13.5.6 VER—Version Register (LPC I/F—D31:F0)
Default Value: 00170020h
The one we emulate in KVM is in 82093AA datasheet:
3.2.2. IOAPICVER—IOAPIC VERSION REGISTER
Default Value: 00170011h
The former has the EOI register, the latter doesn't.
---
I don't like the idea behind the patch, but it is acceptable and thinking about good solutions gets us into compatibility nightmares ... (We could remove support for directed EOI, because it is a detectable
feature and makes little sense in KVM, or we could implement the IOAPIC version 0x20, but both would be tricky to migrate.)
People should switch to userspace IOAPIC anyway. :)
Quoted 66 lines · Radim Krcmar
2017-04-12 17:06+0800, Peter Xu:
Quoted 51 lines · Ladi Prosek
Quoted 42 lines · Peter Xu
Quoted 15 lines · Ladi Prosek
Quoted 14 lines
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Quoted 8 lines
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Yeah, it is officially described in ICH9 datasheet as:
13.5.6 VER—Version Register (LPC I/F—D31:F0)
Default Value: 00170020h
Quoted 6 lines
The one we emulate in KVM is in 82093AA datasheet:
3.2.2. IOAPICVER—IOAPIC VERSION REGISTER
Default Value: 00170011hThe former has the EOI register, the latter doesn't.
Got it. Do you want me to resubmit with a different commit message and a comment blaming the guest OS instead of calling it a KVM bug? :) Or do you think it's worth exploring Peter's suggestion to make a more invasive fix?
Quoted 8 lines
---
I don't like the idea behind the patch, but it is acceptable and thinking about good solutions gets us into compatibility nightmares ... (We could remove support for directed EOI, because it is a detectable
feature and makes little sense in KVM, or we could implement the IOAPIC version0x20, but both would be tricky to migrate.)People should switch to userspace IOAPIC anyway. :)
For the record, QEMU with kernel-irqchip=split works fine as it emulates version 0x20 with the IOAPIC_EOI register by default. kernel-irqchip=off does not seem to work, I will look into it.
Thanks!
Ladi
2017-04-13 08:36+0200, Ladi Prosek:
Quoted 72 lines · Radim Krcmar
Quoted 71 lines
2017-04-12 17:06+0800, Peter Xu:
Quoted 51 lines · Ladi Prosek
Quoted 42 lines · Peter Xu
Quoted 15 lines · Ladi Prosek
Quoted 14 lines
If the guest takes advantage of the directed EOI feature by setting
APIC_SPIV_DIRECTED_EOI, it is expected to signal EOI by writing to the EOI register of the respective IOAPIC.From Intel's x2APIC Specification:
"following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register."Commit
fc61b800f950("KVM: Add Directed EOI support to APIC emulation") inhibited EOI on LAPIC EOI register write but didn't add the IOAPIC part.IOAPIC_REG_EOIwrites were handled only on IA64 and the code was later removed with the rest of IA64 support.Quoted 5 lines
Quoted 3 lines
The bug has gone undetected for a long time because Linux writes to
IOAPIC_REG_EOIonly if the IOAPIC version is >=0x20. Windows doesn't seem to perform such a check.Hi, Ladi,
Hi Peter,
Quoted 6 lines
Not sure I'm understanding it correctly... I see "direct EOI" is a feature for IOAPIC version
0x20, while "suppress EOI-broadcast" is another feature for APIC. They are not the same feature, so it may not be required to have them all together. IIUC current x86 kvm is just the case - it supports EOI broadcast suppression on APIC, but it does not support direct EOI on kernel IOAPIC.Thanks, that makes perfect sense and explains why Linux behaves the way it does (
__eoi_ioapic_pininarch/x86/kernel/apic/io_apic.c).This document makes it look like suppress EOI-broadcast always implies directed EOI, though:
http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
NB "The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. "
Quoted 7 lines
There is no mention of APIC version or any other detection mechanism for directed EOI. Maybe the chip being x2APIC implies version >=
0x20but I don't see that in the document either.I suspect that Microsoft implemented EOI by following this same spec. Level-triggered interrupts don't work right on Windows Server 2016 with Hyper-V enabled without this patch.
Quoted 8 lines
Yes, the documents for IOAPIC is always hard to find, at least for me...
There is some pages mentioned IOAPIC in ICH9 manual on chap 13.5 here:
http://www.intel.com/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdfHowever I see nothing related to how the IOAPIC version is defined. In that sense, the comment above
__eoi_ioapic_pin()seems to be better. :)Yeah, it is officially described in ICH9 datasheet as:
13.5.6 VER—Version Register (LPC I/F—D31:F0)
Default Value: 00170020hThe one we emulate in KVM is in 82093AA datasheet:
3.2.2. IOAPICVER—IOAPIC VERSION REGISTER
Default Value: 00170011h
Quoted 6 lines
Quoted 1 line
The former has the EOI register, the latter doesn't.
Got it. Do you want me to resubmit with a different commit message and a comment blaming the guest OS instead of calling it a KVM bug? :) Or do you think it's worth exploring Peter's suggestion to make a more invasive fix?
I would experiment with reverting the APIC suppress-EOI-broadcast first. It doesn't currently work well and is pointless in theory.
Quoted 11 lines
Quoted 8 lines
---
I don't like the idea behind the patch, but it is acceptable and thinking about good solutions gets us into compatibility nightmares ... (We could remove support for directed EOI, because it is a detectable
feature and makes little sense in KVM, or we could implement the IOAPIC version0x20, but both would be tricky to migrate.)People should switch to userspace IOAPIC anyway. :)
For the record, QEMU with kernel-irqchip=split works fine as it emulates version
0x20with theIOAPIC_EOIregister by default.
Great, thanks.
Quoted 1 line
kernel-irqchip=off does not seem to work, I will look into it.
Well, good luck. :)
Paolo Bonzini
maintainerQuoted 3 lines · Ladi Prosek
For the record, QEMU with kernel-irqchip=split works fine as it emulates version
0x20with theIOAPIC_EOIregister by default. kernel-irqchip=off does not seem to work, I will look into it.
There's a lot more breakage to kernel-irqchip=off, and it's more or less on life support. Don't waste your time on it.
Paolo