* [PATCH MANUALSEL 5.17 1/3] KVM: x86: disable preemption while updating apicv inhibition
@ 2022-06-21 21:21 Sasha Levin
2022-06-21 21:21 ` [PATCH MANUALSEL 5.17 2/3] KVM: x86: disable preemption around the call to kvm_arch_vcpu_{un|}blocking Sasha Levin
2022-06-21 21:21 ` [PATCH MANUALSEL 5.17 3/3] KVM: selftests: Restrict test region to 48-bit physical addresses when using nested Sasha Levin
0 siblings, 2 replies; 3+ messages in thread
From: Sasha Levin @ 2022-06-21 21:21 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Maxim Levitsky, Paolo Bonzini, Sasha Levin, tglx, mingo, bp,
dave.hansen, x86, kvm
From: Maxim Levitsky <mlevitsk@redhat.com>
[ Upstream commit 66c768d30e64e1280520f34dbef83419f55f3459 ]
Currently nothing prevents preemption in kvm_vcpu_update_apicv.
On SVM, If the preemption happens after we update the
vcpu->arch.apicv_active, the preemption itself will
'update' the inhibition since the AVIC will be first disabled
on vCPU unload and then enabled, when the current task
is loaded again.
Then we will try to update it again, which will lead to a warning
in __avic_vcpu_load, that the AVIC is already enabled.
Fix this by disabling preemption in this code.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20220606180829.102503-6-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/x86/kvm/x86.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5204283da798..0e456c82a00b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9668,6 +9668,7 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu)
return;
down_read(&vcpu->kvm->arch.apicv_update_lock);
+ preempt_disable();
activate = kvm_apicv_activated(vcpu->kvm);
if (vcpu->arch.apicv_active == activate)
@@ -9687,6 +9688,7 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu)
kvm_make_request(KVM_REQ_EVENT, vcpu);
out:
+ preempt_enable();
up_read(&vcpu->kvm->arch.apicv_update_lock);
}
EXPORT_SYMBOL_GPL(kvm_vcpu_update_apicv);
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH MANUALSEL 5.17 2/3] KVM: x86: disable preemption around the call to kvm_arch_vcpu_{un|}blocking
2022-06-21 21:21 [PATCH MANUALSEL 5.17 1/3] KVM: x86: disable preemption while updating apicv inhibition Sasha Levin
@ 2022-06-21 21:21 ` Sasha Levin
2022-06-21 21:21 ` [PATCH MANUALSEL 5.17 3/3] KVM: selftests: Restrict test region to 48-bit physical addresses when using nested Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2022-06-21 21:21 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Maxim Levitsky, Paolo Bonzini, Sasha Levin, kvm
From: Maxim Levitsky <mlevitsk@redhat.com>
[ Upstream commit 18869f26df1a11ed11031dfb7392bc7d774062e8 ]
On SVM, if preemption happens right after the call to finish_rcuwait
but before call to kvm_arch_vcpu_unblocking on SVM/AVIC, it itself
will re-enable AVIC, and then we will try to re-enable it again
in kvm_arch_vcpu_unblocking which will lead to a warning
in __avic_vcpu_load.
The same problem can happen if the vCPU is preempted right after the call
to kvm_arch_vcpu_blocking but before the call to prepare_to_rcuwait
and in this case, we will end up with AVIC enabled during sleep -
Ooops.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20220606180829.102503-7-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
virt/kvm/kvm_main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 717ee1b2e058..8f88f168012e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3305,9 +3305,11 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu)
vcpu->stat.generic.blocking = 1;
+ preempt_disable();
kvm_arch_vcpu_blocking(vcpu);
-
prepare_to_rcuwait(wait);
+ preempt_enable();
+
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
@@ -3317,9 +3319,11 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu)
waited = true;
schedule();
}
- finish_rcuwait(wait);
+ preempt_disable();
+ finish_rcuwait(wait);
kvm_arch_vcpu_unblocking(vcpu);
+ preempt_enable();
vcpu->stat.generic.blocking = 0;
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH MANUALSEL 5.17 3/3] KVM: selftests: Restrict test region to 48-bit physical addresses when using nested
2022-06-21 21:21 [PATCH MANUALSEL 5.17 1/3] KVM: x86: disable preemption while updating apicv inhibition Sasha Levin
2022-06-21 21:21 ` [PATCH MANUALSEL 5.17 2/3] KVM: x86: disable preemption around the call to kvm_arch_vcpu_{un|}blocking Sasha Levin
@ 2022-06-21 21:21 ` Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2022-06-21 21:21 UTC (permalink / raw)
To: linux-kernel, stable
Cc: David Matlack, Sean Christopherson, Paolo Bonzini, Sasha Levin,
shuah, bgardon, kvm, linux-kselftest
From: David Matlack <dmatlack@google.com>
[ Upstream commit e0f3f46e42064a51573914766897b4ab95d943e3 ]
The selftests nested code only supports 4-level paging at the moment.
This means it cannot map nested guest physical addresses with more than
48 bits. Allow perf_test_util nested mode to work on hosts with more
than 48 physical addresses by restricting the guest test region to
48-bits.
While here, opportunistically fix an off-by-one error when dealing with
vm_get_max_gfn(). perf_test_util.c was treating this as the maximum
number of GFNs, rather than the maximum allowed GFN. This didn't result
in any correctness issues, but it did end up shifting the test region
down slightly when using huge pages.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
Message-Id: <20220520233249.3776001-12-dmatlack@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
.../testing/selftests/kvm/lib/perf_test_util.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 722df3a28791..ddd68ba0c99f 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -110,6 +110,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
struct kvm_vm *vm;
uint64_t guest_num_pages;
uint64_t backing_src_pagesz = get_backing_src_pagesz(backing_src);
+ uint64_t region_end_gfn;
int i;
pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
@@ -144,18 +145,29 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
pta->vm = vm;
+ /* Put the test region at the top guest physical memory. */
+ region_end_gfn = vm_get_max_gfn(vm) + 1;
+
+#ifdef __x86_64__
+ /*
+ * When running vCPUs in L2, restrict the test region to 48 bits to
+ * avoid needing 5-level page tables to identity map L2.
+ */
+ if (pta->nested)
+ region_end_gfn = min(region_end_gfn, (1UL << 48) / pta->guest_page_size);
+#endif
/*
* If there should be more memory in the guest test region than there
* can be pages in the guest, it will definitely cause problems.
*/
- TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
+ TEST_ASSERT(guest_num_pages < region_end_gfn,
"Requested more guest memory than address space allows.\n"
" guest pages: %" PRIx64 " max gfn: %" PRIx64
" vcpus: %d wss: %" PRIx64 "]\n",
- guest_num_pages, vm_get_max_gfn(vm), vcpus,
+ guest_num_pages, region_end_gfn - 1, vcpus,
vcpu_memory_bytes);
- pta->gpa = (vm_get_max_gfn(vm) - guest_num_pages) * pta->guest_page_size;
+ pta->gpa = (region_end_gfn - guest_num_pages) * pta->guest_page_size;
pta->gpa = align_down(pta->gpa, backing_src_pagesz);
#ifdef __s390x__
/* Align to 1M (segment size) */
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-21 21:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-21 21:21 [PATCH MANUALSEL 5.17 1/3] KVM: x86: disable preemption while updating apicv inhibition Sasha Levin
2022-06-21 21:21 ` [PATCH MANUALSEL 5.17 2/3] KVM: x86: disable preemption around the call to kvm_arch_vcpu_{un|}blocking Sasha Levin
2022-06-21 21:21 ` [PATCH MANUALSEL 5.17 3/3] KVM: selftests: Restrict test region to 48-bit physical addresses when using nested Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox