* [PATCH] KVM: x86: recalculate_apic_map after enabling apic
@ 2014-08-18 21:03 Nadav Amit
2014-08-19 10:35 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Nadav Amit @ 2014-08-18 21:03 UTC (permalink / raw)
To: gleb; +Cc: kvm, Nadav Amit
Currently, recalculate_apic_map ignores vcpus whose lapic is software disabled
through the spurious interrupt vector. However, once it is re-enabled, the map
is not recalculated. Therefore, if the guest OS configured DFR while lapic is
software-disabled, the map may be incorrect. This patch recalculates apic map
after software enabling the lapic.
Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
arch/x86/kvm/lapic.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 08e8a89..4a736199 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -112,17 +112,6 @@ static inline int __apic_test_and_clear_vector(int vec, void *bitmap)
struct static_key_deferred apic_hw_disabled __read_mostly;
struct static_key_deferred apic_sw_disabled __read_mostly;
-static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
-{
- if ((kvm_apic_get_reg(apic, APIC_SPIV) ^ val) & APIC_SPIV_APIC_ENABLED) {
- if (val & APIC_SPIV_APIC_ENABLED)
- static_key_slow_dec_deferred(&apic_sw_disabled);
- else
- static_key_slow_inc(&apic_sw_disabled.key);
- }
- apic_set_reg(apic, APIC_SPIV, val);
-}
-
static inline int apic_enabled(struct kvm_lapic *apic)
{
return kvm_apic_sw_enabled(apic) && kvm_apic_hw_enabled(apic);
@@ -210,6 +199,20 @@ out:
kvm_vcpu_request_scan_ioapic(kvm);
}
+static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
+{
+ u32 prev = kvm_apic_get_reg(apic, APIC_SPIV);
+
+ apic_set_reg(apic, APIC_SPIV, val);
+ if ((prev ^ val) & APIC_SPIV_APIC_ENABLED) {
+ if (val & APIC_SPIV_APIC_ENABLED) {
+ static_key_slow_dec_deferred(&apic_sw_disabled);
+ recalculate_apic_map(apic->vcpu->kvm);
+ } else
+ static_key_slow_inc(&apic_sw_disabled.key);
+ }
+}
+
static inline void kvm_apic_set_id(struct kvm_lapic *apic, u8 id)
{
apic_set_reg(apic, APIC_ID, id << 24);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] KVM: x86: recalculate_apic_map after enabling apic
2014-08-18 21:03 [PATCH] KVM: x86: recalculate_apic_map after enabling apic Nadav Amit
@ 2014-08-19 10:35 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2014-08-19 10:35 UTC (permalink / raw)
To: Nadav Amit, gleb; +Cc: kvm
Il 18/08/2014 23:03, Nadav Amit ha scritto:
> Currently, recalculate_apic_map ignores vcpus whose lapic is software disabled
> through the spurious interrupt vector. However, once it is re-enabled, the map
> is not recalculated. Therefore, if the guest OS configured DFR while lapic is
> software-disabled, the map may be incorrect. This patch recalculates apic map
> after software enabling the lapic.
>
> Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
> ---
> arch/x86/kvm/lapic.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index 08e8a89..4a736199 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -112,17 +112,6 @@ static inline int __apic_test_and_clear_vector(int vec, void *bitmap)
> struct static_key_deferred apic_hw_disabled __read_mostly;
> struct static_key_deferred apic_sw_disabled __read_mostly;
>
> -static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
> -{
> - if ((kvm_apic_get_reg(apic, APIC_SPIV) ^ val) & APIC_SPIV_APIC_ENABLED) {
> - if (val & APIC_SPIV_APIC_ENABLED)
> - static_key_slow_dec_deferred(&apic_sw_disabled);
> - else
> - static_key_slow_inc(&apic_sw_disabled.key);
> - }
> - apic_set_reg(apic, APIC_SPIV, val);
> -}
> -
> static inline int apic_enabled(struct kvm_lapic *apic)
> {
> return kvm_apic_sw_enabled(apic) && kvm_apic_hw_enabled(apic);
> @@ -210,6 +199,20 @@ out:
> kvm_vcpu_request_scan_ioapic(kvm);
> }
>
> +static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val)
> +{
> + u32 prev = kvm_apic_get_reg(apic, APIC_SPIV);
> +
> + apic_set_reg(apic, APIC_SPIV, val);
> + if ((prev ^ val) & APIC_SPIV_APIC_ENABLED) {
> + if (val & APIC_SPIV_APIC_ENABLED) {
> + static_key_slow_dec_deferred(&apic_sw_disabled);
> + recalculate_apic_map(apic->vcpu->kvm);
> + } else
> + static_key_slow_inc(&apic_sw_disabled.key);
> + }
> +}
> +
> static inline void kvm_apic_set_id(struct kvm_lapic *apic, u8 id)
> {
> apic_set_reg(apic, APIC_ID, id << 24);
>
Applied to kvm/queue, thanks.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-19 10:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-18 21:03 [PATCH] KVM: x86: recalculate_apic_map after enabling apic Nadav Amit
2014-08-19 10:35 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.