Skip to content

Commit fe37fe2

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "ARM: - Fix dangling references to a redistributor region if the vgic was prematurely destroyed. - Properly mark FFA buffers as released, ensuring that both parties can make forward progress. x86: - Allow getting/setting MSRs for SEV-ES guests, if they're using the pre-6.9 KVM_SEV_ES_INIT API. - Always sync pending posted interrupts to the IRR prior to IOAPIC route updates, so that EOIs are intercepted properly if the old routing table requested that. Generic: - Avoid __fls(0) - Fix reference leak on hwpoisoned page - Fix a race in kvm_vcpu_on_spin() by ensuring loads and stores are atomic. - Fix bug in __kvm_handle_hva_range() where KVM calls a function pointer that was intended to be a marker only (nothing bad happens but kind of a mine and also technically undefined behavior) - Do not bother accounting allocations that are small and freed before getting back to userspace. Selftests: - Fix compilation for RISC-V. - Fix a "shift too big" goof in the KVM_SEV_INIT2 selftest. - Compute the max mappable gfn for KVM selftests on x86 using GuestMaxPhyAddr from KVM's supported CPUID (if it's available)" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: SEV-ES: Fix svm_get_msr()/svm_set_msr() for KVM_SEV_ES_INIT guests KVM: Discard zero mask with function kvm_dirty_ring_reset virt: guest_memfd: fix reference leak on hwpoisoned page kvm: do not account temporary allocations to kmem MAINTAINERS: Drop Wanpeng Li as a Reviewer for KVM Paravirt support KVM: x86: Always sync PIR to IRR prior to scanning I/O APIC routes KVM: Stop processing *all* memslots when "null" mmu_notifier handler is found KVM: arm64: FFA: Release hyp rx buffer KVM: selftests: Fix RISC-V compilation KVM: arm64: Disassociate vcpus from redistributor region on teardown KVM: Fix a data race on last_boosted_vcpu in kvm_vcpu_on_spin() KVM: selftests: x86: Prioritize getting max_gfn from GuestPhysBits KVM: selftests: Fix shift of 32 bit unsigned int more than 32 bits
2 parents 35bb670 + e159d63 commit fe37fe2

File tree

16 files changed

+68
-27
lines changed

16 files changed

+68
-27
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12382,7 +12382,6 @@ F: drivers/video/backlight/ktz8866.c
1238212382

1238312383
KVM PARAVIRT (KVM/paravirt)
1238412384
M: Paolo Bonzini <pbonzini@redhat.com>
12385-
R: Wanpeng Li <wanpengli@tencent.com>
1238612385
R: Vitaly Kuznetsov <vkuznets@redhat.com>
1238712386
L: kvm@vger.kernel.org
1238812387
S: Supported

arch/arm64/kvm/hyp/nvhe/ffa.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ static void ffa_retrieve_req(struct arm_smccc_res *res, u32 len)
177177
res);
178178
}
179179

180+
static void ffa_rx_release(struct arm_smccc_res *res)
181+
{
182+
arm_smccc_1_1_smc(FFA_RX_RELEASE,
183+
0, 0,
184+
0, 0, 0, 0, 0,
185+
res);
186+
}
187+
180188
static void do_ffa_rxtx_map(struct arm_smccc_res *res,
181189
struct kvm_cpu_context *ctxt)
182190
{
@@ -543,16 +551,19 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *res,
543551
if (WARN_ON(offset > len ||
544552
fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE)) {
545553
ret = FFA_RET_ABORTED;
554+
ffa_rx_release(res);
546555
goto out_unlock;
547556
}
548557

549558
if (len > ffa_desc_buf.len) {
550559
ret = FFA_RET_NO_MEMORY;
560+
ffa_rx_release(res);
551561
goto out_unlock;
552562
}
553563

554564
buf = ffa_desc_buf.buf;
555565
memcpy(buf, hyp_buffers.rx, fraglen);
566+
ffa_rx_release(res);
556567

557568
for (fragoff = fraglen; fragoff < len; fragoff += fraglen) {
558569
ffa_mem_frag_rx(res, handle_lo, handle_hi, fragoff);
@@ -563,6 +574,7 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *res,
563574

564575
fraglen = res->a3;
565576
memcpy((void *)buf + fragoff, hyp_buffers.rx, fraglen);
577+
ffa_rx_release(res);
566578
}
567579

568580
ffa_mem_reclaim(res, handle_lo, handle_hi, flags);

arch/arm64/kvm/vgic/vgic-init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static void kvm_vgic_dist_destroy(struct kvm *kvm)
391391

392392
if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
393393
list_for_each_entry_safe(rdreg, next, &dist->rd_regions, list)
394-
vgic_v3_free_redist_region(rdreg);
394+
vgic_v3_free_redist_region(kvm, rdreg);
395395
INIT_LIST_HEAD(&dist->rd_regions);
396396
} else {
397397
dist->vgic_cpu_base = VGIC_ADDR_UNDEF;

arch/arm64/kvm/vgic/vgic-mmio-v3.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,19 @@ static int vgic_v3_alloc_redist_region(struct kvm *kvm, uint32_t index,
919919
return ret;
920920
}
921921

922-
void vgic_v3_free_redist_region(struct vgic_redist_region *rdreg)
922+
void vgic_v3_free_redist_region(struct kvm *kvm, struct vgic_redist_region *rdreg)
923923
{
924+
struct kvm_vcpu *vcpu;
925+
unsigned long c;
926+
927+
lockdep_assert_held(&kvm->arch.config_lock);
928+
929+
/* Garbage collect the region */
930+
kvm_for_each_vcpu(c, vcpu, kvm) {
931+
if (vcpu->arch.vgic_cpu.rdreg == rdreg)
932+
vcpu->arch.vgic_cpu.rdreg = NULL;
933+
}
934+
924935
list_del(&rdreg->list);
925936
kfree(rdreg);
926937
}
@@ -945,7 +956,7 @@ int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count)
945956

946957
mutex_lock(&kvm->arch.config_lock);
947958
rdreg = vgic_v3_rdist_region_from_index(kvm, index);
948-
vgic_v3_free_redist_region(rdreg);
959+
vgic_v3_free_redist_region(kvm, rdreg);
949960
mutex_unlock(&kvm->arch.config_lock);
950961
return ret;
951962
}

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ vgic_v3_rd_region_size(struct kvm *kvm, struct vgic_redist_region *rdreg)
316316

317317
struct vgic_redist_region *vgic_v3_rdist_region_from_index(struct kvm *kvm,
318318
u32 index);
319-
void vgic_v3_free_redist_region(struct vgic_redist_region *rdreg);
319+
void vgic_v3_free_redist_region(struct kvm *kvm, struct vgic_redist_region *rdreg);
320320

321321
bool vgic_v3_rdist_overlap(struct kvm *kvm, gpa_t base, size_t size);
322322

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
28432843

28442844
if (sev_es_prevent_msr_access(vcpu, msr_info)) {
28452845
msr_info->data = 0;
2846-
return -EINVAL;
2846+
return vcpu->kvm->arch.has_protected_state ? -EINVAL : 0;
28472847
}
28482848

28492849
switch (msr_info->index) {
@@ -2998,7 +2998,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
29982998
u64 data = msr->data;
29992999

30003000
if (sev_es_prevent_msr_access(vcpu, msr))
3001-
return -EINVAL;
3001+
return vcpu->kvm->arch.has_protected_state ? -EINVAL : 0;
30023002

30033003
switch (ecx) {
30043004
case MSR_AMD64_TSC_RATIO:

arch/x86/kvm/x86.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10718,13 +10718,12 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
1071810718

1071910719
bitmap_zero(vcpu->arch.ioapic_handled_vectors, 256);
1072010720

10721+
static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu);
10722+
1072110723
if (irqchip_split(vcpu->kvm))
1072210724
kvm_scan_ioapic_routes(vcpu, vcpu->arch.ioapic_handled_vectors);
10723-
else {
10724-
static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu);
10725-
if (ioapic_in_kernel(vcpu->kvm))
10726-
kvm_ioapic_scan_entry(vcpu, vcpu->arch.ioapic_handled_vectors);
10727-
}
10725+
else if (ioapic_in_kernel(vcpu->kvm))
10726+
kvm_ioapic_scan_entry(vcpu, vcpu->arch.ioapic_handled_vectors);
1072810727

1072910728
if (is_guest_mode(vcpu))
1073010729
vcpu->arch.load_eoi_exitmap_pending = true;

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ struct kvm_x86_cpu_property {
277277
#define X86_PROPERTY_MAX_EXT_LEAF KVM_X86_CPU_PROPERTY(0x80000000, 0, EAX, 0, 31)
278278
#define X86_PROPERTY_MAX_PHY_ADDR KVM_X86_CPU_PROPERTY(0x80000008, 0, EAX, 0, 7)
279279
#define X86_PROPERTY_MAX_VIRT_ADDR KVM_X86_CPU_PROPERTY(0x80000008, 0, EAX, 8, 15)
280+
#define X86_PROPERTY_GUEST_MAX_PHY_ADDR KVM_X86_CPU_PROPERTY(0x80000008, 0, EAX, 16, 23)
280281
#define X86_PROPERTY_SEV_C_BIT KVM_X86_CPU_PROPERTY(0x8000001F, 0, EBX, 0, 5)
281282
#define X86_PROPERTY_PHYS_ADDR_REDUCTION KVM_X86_CPU_PROPERTY(0x8000001F, 0, EBX, 6, 11)
282283

tools/testing/selftests/kvm/lib/riscv/ucall.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "kvm_util.h"
1111
#include "processor.h"
12+
#include "sbi.h"
1213

1314
void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu)
1415
{

tools/testing/selftests/kvm/lib/x86_64/processor.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,9 +1247,20 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm)
12471247
{
12481248
const unsigned long num_ht_pages = 12 << (30 - vm->page_shift); /* 12 GiB */
12491249
unsigned long ht_gfn, max_gfn, max_pfn;
1250-
uint8_t maxphyaddr;
1250+
uint8_t maxphyaddr, guest_maxphyaddr;
12511251

1252-
max_gfn = (1ULL << (vm->pa_bits - vm->page_shift)) - 1;
1252+
/*
1253+
* Use "guest MAXPHYADDR" from KVM if it's available. Guest MAXPHYADDR
1254+
* enumerates the max _mappable_ GPA, which can be less than the raw
1255+
* MAXPHYADDR, e.g. if MAXPHYADDR=52, KVM is using TDP, and the CPU
1256+
* doesn't support 5-level TDP.
1257+
*/
1258+
guest_maxphyaddr = kvm_cpu_property(X86_PROPERTY_GUEST_MAX_PHY_ADDR);
1259+
guest_maxphyaddr = guest_maxphyaddr ?: vm->pa_bits;
1260+
TEST_ASSERT(guest_maxphyaddr <= vm->pa_bits,
1261+
"Guest MAXPHYADDR should never be greater than raw MAXPHYADDR");
1262+
1263+
max_gfn = (1ULL << (guest_maxphyaddr - vm->page_shift)) - 1;
12531264

12541265
/* Avoid reserved HyperTransport region on AMD processors. */
12551266
if (!host_cpu_is_amd)

0 commit comments

Comments
 (0)