* [PATCH 01/11] KVM: s390: do store status after handling STOP_ON_STOP bit
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 02/11] KVM: s390: Sanitize fpc registers for KVM_SET_FPU Avi Kivity
` (11 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Jens Freimann <jfrei@linux.vnet.ibm.com>
In handle_stop() handle the stop bit before doing the store status as
described for "Stop and Store Status" in the Principles of Operation.
We have to give up the local_int.lock before calling kvm store status
since it calls gmap_fault() which might sleep. Since local_int.lock
only protects local_int.* and not guest memory we can give up the lock.
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 9e0d5473e2f0ba2d2fe9dab9408edef3060b710e)
---
arch/s390/kvm/intercept.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index 0243454..a5f6eff 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -133,13 +133,6 @@ static int handle_stop(struct kvm_vcpu *vcpu)
vcpu->stat.exit_stop_request++;
spin_lock_bh(&vcpu->arch.local_int.lock);
- if (vcpu->arch.local_int.action_bits & ACTION_STORE_ON_STOP) {
- vcpu->arch.local_int.action_bits &= ~ACTION_STORE_ON_STOP;
- rc = kvm_s390_vcpu_store_status(vcpu,
- KVM_S390_STORE_STATUS_NOADDR);
- if (rc >= 0)
- rc = -EOPNOTSUPP;
- }
if (vcpu->arch.local_int.action_bits & ACTION_RELOADVCPU_ON_STOP) {
vcpu->arch.local_int.action_bits &= ~ACTION_RELOADVCPU_ON_STOP;
@@ -155,7 +148,18 @@ static int handle_stop(struct kvm_vcpu *vcpu)
rc = -EOPNOTSUPP;
}
- spin_unlock_bh(&vcpu->arch.local_int.lock);
+ if (vcpu->arch.local_int.action_bits & ACTION_STORE_ON_STOP) {
+ vcpu->arch.local_int.action_bits &= ~ACTION_STORE_ON_STOP;
+ /* store status must be called unlocked. Since local_int.lock
+ * only protects local_int.* and not guest memory we can give
+ * up the lock here */
+ spin_unlock_bh(&vcpu->arch.local_int.lock);
+ rc = kvm_s390_vcpu_store_status(vcpu,
+ KVM_S390_STORE_STATUS_NOADDR);
+ if (rc >= 0)
+ rc = -EOPNOTSUPP;
+ } else
+ spin_unlock_bh(&vcpu->arch.local_int.lock);
return rc;
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 02/11] KVM: s390: Sanitize fpc registers for KVM_SET_FPU
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
2012-05-09 13:10 ` [PATCH 01/11] KVM: s390: do store status after handling STOP_ON_STOP bit Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 03/11] KVM: Fix write protection race during dirty logging Avi Kivity
` (10 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Christian Borntraeger <borntraeger@de.ibm.com>
commit 7eef87dc99e419b1cc051e4417c37e4744d7b661 (KVM: s390: fix
register setting) added a load of the floating point control register
to the KVM_SET_FPU path. Lets make sure that the fpc is valid.
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 851755871c1f3184f4124c466e85881f17fa3226)
---
arch/s390/kvm/kvm-s390.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index d1c44573..d3cb86c 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -418,7 +418,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
{
memcpy(&vcpu->arch.guest_fpregs.fprs, &fpu->fprs, sizeof(fpu->fprs));
- vcpu->arch.guest_fpregs.fpc = fpu->fpc;
+ vcpu->arch.guest_fpregs.fpc = fpu->fpc & FPC_VALID_MASK;
restore_fp_regs(&vcpu->arch.guest_fpregs);
return 0;
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 03/11] KVM: Fix write protection race during dirty logging
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
2012-05-09 13:10 ` [PATCH 01/11] KVM: s390: do store status after handling STOP_ON_STOP bit Avi Kivity
2012-05-09 13:10 ` [PATCH 02/11] KVM: s390: Sanitize fpc registers for KVM_SET_FPU Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 04/11] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock Avi Kivity
` (9 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
This patch fixes a race introduced by:
commit 95d4c16ce78cb6b7549a09159c409d52ddd18dae
KVM: Optimize dirty logging by rmap_write_protect()
During protecting pages for dirty logging, other threads may also try
to protect a page in mmu_sync_children() or kvm_mmu_get_page().
In such a case, because get_dirty_log releases mmu_lock before flushing
TLB's, the following race condition can happen:
A (get_dirty_log) B (another thread)
lock(mmu_lock)
clear pte.w
unlock(mmu_lock)
lock(mmu_lock)
pte.w is already cleared
unlock(mmu_lock)
skip TLB flush
return
...
TLB flush
Though thread B assumes the page has already been protected when it
returns, the remaining TLB entry will break that assumption.
This patch fixes this problem by making get_dirty_log hold the mmu_lock
until it flushes the TLB's.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 6dbf79e7164e9a86c1e466062c48498142ae6128)
---
arch/x86/kvm/x86.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9cbfc06..410b6b0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2997,6 +2997,8 @@ static void write_protect_slot(struct kvm *kvm,
unsigned long *dirty_bitmap,
unsigned long nr_dirty_pages)
{
+ spin_lock(&kvm->mmu_lock);
+
/* Not many dirty pages compared to # of shadow pages. */
if (nr_dirty_pages < kvm->arch.n_used_mmu_pages) {
unsigned long gfn_offset;
@@ -3004,16 +3006,13 @@ static void write_protect_slot(struct kvm *kvm,
for_each_set_bit(gfn_offset, dirty_bitmap, memslot->npages) {
unsigned long gfn = memslot->base_gfn + gfn_offset;
- spin_lock(&kvm->mmu_lock);
kvm_mmu_rmap_write_protect(kvm, gfn, memslot);
- spin_unlock(&kvm->mmu_lock);
}
kvm_flush_remote_tlbs(kvm);
- } else {
- spin_lock(&kvm->mmu_lock);
+ } else
kvm_mmu_slot_remove_write_access(kvm, memslot->id);
- spin_unlock(&kvm->mmu_lock);
- }
+
+ spin_unlock(&kvm->mmu_lock);
}
/*
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 04/11] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (2 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 03/11] KVM: Fix write protection race during dirty logging Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 05/11] KVM: x86 emulator: correctly mask pmc index bits in RDPMC instruction emulation Avi Kivity
` (8 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Other threads may process the same page in that small window and skip
TLB flush and then return before these functions do flush.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 565f3be2174611f364405bbea2d86e153c2e7e78)
---
virt/kvm/kvm_main.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c4ac57e..4c68c1e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -289,15 +289,15 @@ static void kvm_mmu_notifier_invalidate_page(struct mmu_notifier *mn,
*/
idx = srcu_read_lock(&kvm->srcu);
spin_lock(&kvm->mmu_lock);
+
kvm->mmu_notifier_seq++;
need_tlb_flush = kvm_unmap_hva(kvm, address) | kvm->tlbs_dirty;
- spin_unlock(&kvm->mmu_lock);
- srcu_read_unlock(&kvm->srcu, idx);
-
/* we've to flush the tlb before the pages can be freed */
if (need_tlb_flush)
kvm_flush_remote_tlbs(kvm);
+ spin_unlock(&kvm->mmu_lock);
+ srcu_read_unlock(&kvm->srcu, idx);
}
static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn,
@@ -335,12 +335,12 @@ static void kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
for (; start < end; start += PAGE_SIZE)
need_tlb_flush |= kvm_unmap_hva(kvm, start);
need_tlb_flush |= kvm->tlbs_dirty;
- spin_unlock(&kvm->mmu_lock);
- srcu_read_unlock(&kvm->srcu, idx);
-
/* we've to flush the tlb before the pages can be freed */
if (need_tlb_flush)
kvm_flush_remote_tlbs(kvm);
+
+ spin_unlock(&kvm->mmu_lock);
+ srcu_read_unlock(&kvm->srcu, idx);
}
static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
@@ -378,13 +378,14 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
idx = srcu_read_lock(&kvm->srcu);
spin_lock(&kvm->mmu_lock);
- young = kvm_age_hva(kvm, address);
- spin_unlock(&kvm->mmu_lock);
- srcu_read_unlock(&kvm->srcu, idx);
+ young = kvm_age_hva(kvm, address);
if (young)
kvm_flush_remote_tlbs(kvm);
+ spin_unlock(&kvm->mmu_lock);
+ srcu_read_unlock(&kvm->srcu, idx);
+
return young;
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 05/11] KVM: x86 emulator: correctly mask pmc index bits in RDPMC instruction emulation
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (3 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 04/11] KVM: mmu_notifier: Flush TLBs before releasing mmu_lock Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 06/11] KVM: Ensure all vcpus are consistent with in-kernel irqchip settings Avi Kivity
` (7 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 270c6c79f4e15e599f47174ecedad932463af7a2)
---
arch/x86/kvm/pmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 7aad544..3e48c1d 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -413,7 +413,7 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data)
struct kvm_pmc *counters;
u64 ctr;
- pmc &= (3u << 30) - 1;
+ pmc &= ~(3u << 30);
if (!fixed && pmc >= pmu->nr_arch_gp_counters)
return 1;
if (fixed && pmc >= pmu->nr_arch_fixed_counters)
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 06/11] KVM: Ensure all vcpus are consistent with in-kernel irqchip settings
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (4 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 05/11] KVM: x86 emulator: correctly mask pmc index bits in RDPMC instruction emulation Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 07/11] KVM: VMX: Fix delayed load of shared MSRs Avi Kivity
` (6 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
If some vcpus are created before KVM_CREATE_IRQCHIP, then
irqchip_in_kernel() and vcpu->arch.apic will be inconsistent, leading
to potential NULL pointer dereferences.
Fix by:
- ensuring that no vcpus are installed when KVM_CREATE_IRQCHIP is called
- ensuring that a vcpu has an apic if it is installed after KVM_CREATE_IRQCHIP
This is somewhat long winded because vcpu->arch.apic is created without
kvm->lock held.
Based on earlier patch by Michael Ellerman.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 3e515705a1f46beb1c942bb8043c16f8ac7b1e9e)
---
arch/ia64/kvm/kvm-ia64.c | 5 +++++
arch/x86/kvm/x86.c | 8 ++++++++
include/linux/kvm_host.h | 7 +++++++
virt/kvm/kvm_main.c | 4 ++++
4 files changed, 24 insertions(+)
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index 4050520..8c25855 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -1169,6 +1169,11 @@ static enum hrtimer_restart hlt_timer_fn(struct hrtimer *data)
#define PALE_RESET_ENTRY 0x80000000ffffffb0UL
+bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu)
+{
+ return irqchip_in_kernel(vcpu->kcm) == (vcpu->arch.apic != NULL);
+}
+
int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
{
struct kvm_vcpu *v;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 410b6b0..8d1c6c6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3131,6 +3131,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
r = -EEXIST;
if (kvm->arch.vpic)
goto create_irqchip_unlock;
+ r = -EINVAL;
+ if (atomic_read(&kvm->online_vcpus))
+ goto create_irqchip_unlock;
r = -ENOMEM;
vpic = kvm_create_pic(kvm);
if (vpic) {
@@ -5956,6 +5959,11 @@ void kvm_arch_check_processor_compat(void *rtn)
kvm_x86_ops->check_processor_compatibility(rtn);
}
+bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu)
+{
+ return irqchip_in_kernel(vcpu->kvm) == (vcpu->arch.apic != NULL);
+}
+
int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
{
struct page *page;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index bc21720..4c4e83d 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -775,6 +775,13 @@ static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
{
return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
}
+
+bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
+
+#else
+
+static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
+
#endif
#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4c68c1e..7858228 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1720,6 +1720,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
goto vcpu_destroy;
mutex_lock(&kvm->lock);
+ if (!kvm_vcpu_compatible(vcpu)) {
+ r = -EINVAL;
+ goto unlock_vcpu_destroy;
+ }
if (atomic_read(&kvm->online_vcpus) == KVM_MAX_VCPUS) {
r = -EINVAL;
goto unlock_vcpu_destroy;
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 07/11] KVM: VMX: Fix delayed load of shared MSRs
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (5 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 06/11] KVM: Ensure all vcpus are consistent with in-kernel irqchip settings Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 08/11] KVM: nVMX: Fix erroneous exception bitmap check Avi Kivity
` (5 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
Shared MSRs (MSR_*STAR and related) are stored in both vmx->guest_msrs
and in the CPU registers, but vmx_set_msr() only updated memory. Prior
to 46199f33c2953, this didn't matter, since we called vmx_load_host_state(),
which scheduled a vmx_save_host_state(), which re-synchronized the CPU
state, but now we don't, so the CPU state will not be synchronized until
the next exit to host userspace. This mostly affects nested vmx workloads,
which play with these MSRs a lot.
Fix by loading the MSR eagerly.
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 9ee73970c03edb68146ceb1ba2a7033c99a5e017)
---
arch/x86/kvm/vmx.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 3b4c8d8..fafb325 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2219,6 +2219,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
msr = find_msr_entry(vmx, msr_index);
if (msr) {
msr->data = data;
+ if (msr - vmx->guest_msrs < vmx->save_nmsrs)
+ kvm_set_shared_msr(msr->index, msr->data,
+ msr->mask);
break;
}
ret = kvm_set_msr_common(vcpu, msr_index, data);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 08/11] KVM: nVMX: Fix erroneous exception bitmap check
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (6 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 07/11] KVM: VMX: Fix delayed load of shared MSRs Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 09/11] KVM: VMX: vmx_set_cr0 expects kvm->srcu locked Avi Kivity
` (4 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Nadav Har'El <nyh@math.technion.ac.il>
The code which checks whether to inject a pagefault to L1 or L2 (in
nested VMX) was wrong, incorrect in how it checked the PF_VECTOR bit.
Thanks to Dan Carpenter for spotting this.
Signed-off-by: Nadav Har'El <nyh@il.ibm.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 9587190107d0c0cbaccbf7bf6b0245d29095a9ae)
---
arch/x86/kvm/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index fafb325..5d1b0c7 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1678,7 +1678,7 @@ static int nested_pf_handled(struct kvm_vcpu *vcpu)
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
/* TODO: also check PFEC_MATCH/MASK, not just EB.PF. */
- if (!(vmcs12->exception_bitmap & PF_VECTOR))
+ if (!(vmcs12->exception_bitmap & (1u << PF_VECTOR)))
return 0;
nested_vmx_vmexit(vcpu);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 09/11] KVM: VMX: vmx_set_cr0 expects kvm->srcu locked
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (7 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 08/11] KVM: nVMX: Fix erroneous exception bitmap check Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 10/11] KVM: VMX: Fix kvm_set_shared_msr() called in preemptible context Avi Kivity
` (3 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Marcelo Tosatti <mtosatti@redhat.com>
vmx_set_cr0 is called from vcpu run context, therefore it expects
kvm->srcu to be held (for setting up the real-mode TSS).
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
(cherry picked from commit 7a4f5ad051e02139a9f1c0f7f4b1acb88915852b)
---
arch/x86/kvm/vmx.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 5d1b0c7..7f33e33 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3918,7 +3918,9 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
vmx->vcpu.arch.cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET;
+ vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
vmx_set_cr0(&vmx->vcpu, kvm_read_cr0(vcpu)); /* enter rmode */
+ srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
vmx_set_cr4(&vmx->vcpu, 0);
vmx_set_efer(&vmx->vcpu, 0);
vmx_fpu_activate(&vmx->vcpu);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 10/11] KVM: VMX: Fix kvm_set_shared_msr() called in preemptible context
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (8 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 09/11] KVM: VMX: vmx_set_cr0 expects kvm->srcu locked Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-09 13:10 ` [PATCH 11/11] KVM: lock slots_lock around device assignment Avi Kivity
` (2 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
kvm_set_shared_msr() may not be called in preemptible context,
but vmx_set_msr() does so:
BUG: using smp_processor_id() in preemptible [00000000] code: qemu-kvm/22713
caller is kvm_set_shared_msr+0x32/0xa0 [kvm]
Pid: 22713, comm: qemu-kvm Not tainted 3.4.0-rc3+ #39
Call Trace:
[<ffffffff8131fa82>] debug_smp_processor_id+0xe2/0x100
[<ffffffffa0328ae2>] kvm_set_shared_msr+0x32/0xa0 [kvm]
[<ffffffffa03a103b>] vmx_set_msr+0x28b/0x2d0 [kvm_intel]
...
Making kvm_set_shared_msr() work in preemptible is cleaner, but
it's used in the fast path. Making two variants is overkill, so
this patch just disables preemption around the call.
Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
(cherry picked from commit 2225fd56049643c1a7d645c0ce9d499d43c7974e)
---
arch/x86/kvm/vmx.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 7f33e33..a7a6f60 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2219,9 +2219,12 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
msr = find_msr_entry(vmx, msr_index);
if (msr) {
msr->data = data;
- if (msr - vmx->guest_msrs < vmx->save_nmsrs)
+ if (msr - vmx->guest_msrs < vmx->save_nmsrs) {
+ preempt_disable();
kvm_set_shared_msr(msr->index, msr->data,
msr->mask);
+ preempt_enable();
+ }
break;
}
ret = kvm_set_msr_common(vcpu, msr_index, data);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 11/11] KVM: lock slots_lock around device assignment
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (9 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 10/11] KVM: VMX: Fix kvm_set_shared_msr() called in preemptible context Avi Kivity
@ 2012-05-09 13:10 ` Avi Kivity
2012-05-10 16:28 ` [PATCH 00/11] KVM fixes for 3.3.5 Greg KH
2012-05-12 0:35 ` Ben Hutchings
12 siblings, 0 replies; 16+ messages in thread
From: Avi Kivity @ 2012-05-09 13:10 UTC (permalink / raw)
To: stable; +Cc: Marcelo Tosatti, kvm
From: Alex Williamson <alex.williamson@redhat.com>
As pointed out by Jason Baron, when assigning a device to a guest
we first set the iommu domain pointer, which enables mapping
and unmapping of memory slots to the iommu. This leaves a window
where this path is enabled, but we haven't synchronized the iommu
mappings to the existing memory slots. Thus a slot being removed
at that point could send us down unexpected code paths removing
non-existent pinnings and iommu mappings. Take the slots_lock
around creating the iommu domain and initial mappings as well as
around iommu teardown to avoid this race.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
(cherry picked from commit 21a1416a1c945c5aeaeaf791b63c64926018eb77)
---
virt/kvm/iommu.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index fec1723..e9fff98 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -240,9 +240,13 @@ int kvm_iommu_map_guest(struct kvm *kvm)
return -ENODEV;
}
+ mutex_lock(&kvm->slots_lock);
+
kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type);
- if (!kvm->arch.iommu_domain)
- return -ENOMEM;
+ if (!kvm->arch.iommu_domain) {
+ r = -ENOMEM;
+ goto out_unlock;
+ }
if (!allow_unsafe_assigned_interrupts &&
!iommu_domain_has_cap(kvm->arch.iommu_domain,
@@ -253,17 +257,16 @@ int kvm_iommu_map_guest(struct kvm *kvm)
" module option.\n", __func__);
iommu_domain_free(kvm->arch.iommu_domain);
kvm->arch.iommu_domain = NULL;
- return -EPERM;
+ r = -EPERM;
+ goto out_unlock;
}
r = kvm_iommu_map_memslots(kvm);
if (r)
- goto out_unmap;
-
- return 0;
+ kvm_iommu_unmap_memslots(kvm);
-out_unmap:
- kvm_iommu_unmap_memslots(kvm);
+out_unlock:
+ mutex_unlock(&kvm->slots_lock);
return r;
}
@@ -340,7 +343,11 @@ int kvm_iommu_unmap_guest(struct kvm *kvm)
if (!domain)
return 0;
+ mutex_lock(&kvm->slots_lock);
kvm_iommu_unmap_memslots(kvm);
+ kvm->arch.iommu_domain = NULL;
+ mutex_unlock(&kvm->slots_lock);
+
iommu_domain_free(domain);
return 0;
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 00/11] KVM fixes for 3.3.5
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (10 preceding siblings ...)
2012-05-09 13:10 ` [PATCH 11/11] KVM: lock slots_lock around device assignment Avi Kivity
@ 2012-05-10 16:28 ` Greg KH
2012-05-12 0:35 ` Ben Hutchings
12 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2012-05-10 16:28 UTC (permalink / raw)
To: Avi Kivity; +Cc: stable, Marcelo Tosatti, kvm
On Wed, May 09, 2012 at 04:10:36PM +0300, Avi Kivity wrote:
> After a long hiatus, here are a bunch of very delayed fixes for 3.3.5.
All applied, thanks.
greg k-h
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/11] KVM fixes for 3.3.5
2012-05-09 13:10 [PATCH 00/11] KVM fixes for 3.3.5 Avi Kivity
` (11 preceding siblings ...)
2012-05-10 16:28 ` [PATCH 00/11] KVM fixes for 3.3.5 Greg KH
@ 2012-05-12 0:35 ` Ben Hutchings
2012-05-13 9:23 ` Avi Kivity
12 siblings, 1 reply; 16+ messages in thread
From: Ben Hutchings @ 2012-05-12 0:35 UTC (permalink / raw)
To: Avi Kivity; +Cc: stable, Marcelo Tosatti, kvm
[-- Attachment #1: Type: text/plain, Size: 2029 bytes --]
On Wed, 2012-05-09 at 16:10 +0300, Avi Kivity wrote:
> After a long hiatus, here are a bunch of very delayed fixes for 3.3.5.
Are any of these also applicable to 3.2.y?
Also, would you consider these two fixes from 3.3 important enough for
3.2.y?
d6185f20a0efbf175e12831d0de330e4f21725aa KVM: nVMX: Add KVM_REQ_IMMEDIATE_EXIT
51cfe38ea50aa631f58ed8c340ed6f0143c325a8 KVM: nVMX: Fix warning-causing idt-vectoring-info behavior
Ben.
> Alex Williamson (1):
> KVM: lock slots_lock around device assignment
>
> Avi Kivity (3):
> KVM: Ensure all vcpus are consistent with in-kernel irqchip settings
> KVM: VMX: Fix delayed load of shared MSRs
> KVM: VMX: Fix kvm_set_shared_msr() called in preemptible context
>
> Christian Borntraeger (1):
> KVM: s390: Sanitize fpc registers for KVM_SET_FPU
>
> Gleb Natapov (1):
> KVM: x86 emulator: correctly mask pmc index bits in RDPMC instruction
> emulation
>
> Jens Freimann (1):
> KVM: s390: do store status after handling STOP_ON_STOP bit
>
> Marcelo Tosatti (1):
> KVM: VMX: vmx_set_cr0 expects kvm->srcu locked
>
> Nadav Har'El (1):
> KVM: nVMX: Fix erroneous exception bitmap check
>
> Takuya Yoshikawa (2):
> KVM: Fix write protection race during dirty logging
> KVM: mmu_notifier: Flush TLBs before releasing mmu_lock
>
> arch/ia64/kvm/kvm-ia64.c | 5 +++++
> arch/s390/kvm/intercept.c | 20 ++++++++++++--------
> arch/s390/kvm/kvm-s390.c | 2 +-
> arch/x86/kvm/pmu.c | 2 +-
> arch/x86/kvm/vmx.c | 10 +++++++++-
> arch/x86/kvm/x86.c | 19 +++++++++++++------
> include/linux/kvm_host.h | 7 +++++++
> virt/kvm/iommu.c | 23 +++++++++++++++--------
> virt/kvm/kvm_main.c | 23 ++++++++++++++---------
> 9 files changed, 77 insertions(+), 34 deletions(-)
>
--
Ben Hutchings
Experience is directly proportional to the value of equipment destroyed.
- Carolyn Scheppner
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/11] KVM fixes for 3.3.5
2012-05-12 0:35 ` Ben Hutchings
@ 2012-05-13 9:23 ` Avi Kivity
2012-05-13 10:19 ` Ben Hutchings
0 siblings, 1 reply; 16+ messages in thread
From: Avi Kivity @ 2012-05-13 9:23 UTC (permalink / raw)
To: Ben Hutchings; +Cc: stable, Marcelo Tosatti, kvm
On 05/12/2012 03:35 AM, Ben Hutchings wrote:
> On Wed, 2012-05-09 at 16:10 +0300, Avi Kivity wrote:
> > After a long hiatus, here are a bunch of very delayed fixes for 3.3.5.
>
> Are any of these also applicable to 3.2.y?
Yes, and more. We'll prepare a patchset for 3.2.
> Also, would you consider these two fixes from 3.3 important enough for
> 3.2.y?
>
> d6185f20a0efbf175e12831d0de330e4f21725aa KVM: nVMX: Add KVM_REQ_IMMEDIATE_EXIT
> 51cfe38ea50aa631f58ed8c340ed6f0143c325a8 KVM: nVMX: Fix warning-causing idt-vectoring-info behavior
No.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 00/11] KVM fixes for 3.3.5
2012-05-13 9:23 ` Avi Kivity
@ 2012-05-13 10:19 ` Ben Hutchings
0 siblings, 0 replies; 16+ messages in thread
From: Ben Hutchings @ 2012-05-13 10:19 UTC (permalink / raw)
To: Avi Kivity; +Cc: stable, Marcelo Tosatti, kvm
[-- Attachment #1: Type: text/plain, Size: 760 bytes --]
On Sun, 2012-05-13 at 12:23 +0300, Avi Kivity wrote:
> On 05/12/2012 03:35 AM, Ben Hutchings wrote:
> > On Wed, 2012-05-09 at 16:10 +0300, Avi Kivity wrote:
> > > After a long hiatus, here are a bunch of very delayed fixes for 3.3.5.
> >
> > Are any of these also applicable to 3.2.y?
>
> Yes, and more. We'll prepare a patchset for 3.2.
Thanks.
Ben.
> > Also, would you consider these two fixes from 3.3 important enough for
> > 3.2.y?
> >
> > d6185f20a0efbf175e12831d0de330e4f21725aa KVM: nVMX: Add KVM_REQ_IMMEDIATE_EXIT
> > 51cfe38ea50aa631f58ed8c340ed6f0143c325a8 KVM: nVMX: Fix warning-causing idt-vectoring-info behavior
>
> No.
>
--
Ben Hutchings
The two most common things in the universe are hydrogen and stupidity.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread