Skip to content

Commit 3cd7cd8

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "Two larger x86 series: - Redo incorrect fix for SEV/SMAP erratum - Windows 11 Hyper-V workaround Other x86 changes: - Various x86 cleanups - Re-enable access_tracking_perf_test - Fix for #GP handling on SVM - Fix for CPUID leaf 0Dh in KVM_GET_SUPPORTED_CPUID - Fix for ICEBP in interrupt shadow - Avoid false-positive RCU splat - Enable Enlightened MSR-Bitmap support for real ARM: - Correctly update the shadow register on exception injection when running in nVHE mode - Correctly use the mm_ops indirection when performing cache invalidation from the page-table walker - Restrict the vgic-v3 workaround for SEIS to the two known broken implementations Generic code changes: - Dead code cleanup" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (43 commits) KVM: eventfd: Fix false positive RCU usage warning KVM: nVMX: Allow VMREAD when Enlightened VMCS is in use KVM: nVMX: Implement evmcs_field_offset() suitable for handle_vmread() KVM: nVMX: Rename vmcs_to_field_offset{,_table} KVM: nVMX: eVMCS: Filter out VM_EXIT_SAVE_VMX_PREEMPTION_TIMER KVM: nVMX: Also filter MSR_IA32_VMX_TRUE_PINBASED_CTLS when eVMCS selftests: kvm: check dynamic bits against KVM_X86_XCOMP_GUEST_SUPP KVM: x86: add system attribute to retrieve full set of supported xsave states KVM: x86: Add a helper to retrieve userspace address from kvm_device_attr selftests: kvm: move vm_xsave_req_perm call to amx_test KVM: x86: Sync the states size with the XCR0/IA32_XSS at, any time KVM: x86: Update vCPU's runtime CPUID on write to MSR_IA32_XSS KVM: x86: Keep MSR_IA32_XSS unchanged for INIT KVM: x86: Free kvm_cpuid_entry2 array on post-KVM_RUN KVM_SET_CPUID{,2} KVM: nVMX: WARN on any attempt to allocate shadow VMCS for vmcs02 KVM: selftests: Don't skip L2's VMCALL in SMM test for SVM guest KVM: x86: Check .flags in kvm_cpuid_check_equal() too KVM: x86: Forcibly leave nested virt when SMM state is toggled KVM: SVM: drop unnecessary code in svm_hv_vmcb_dirty_nested_enlightenments() KVM: SVM: hyper-v: Enable Enlightened MSR-Bitmap support for real ...
2 parents e015270 + 17179d0 commit 3cd7cd8

File tree

35 files changed

+490
-228
lines changed

35 files changed

+490
-228
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3268,6 +3268,7 @@ number.
32683268

32693269
:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
32703270
KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3271+
KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device (no set)
32713272
:Type: device ioctl, vm ioctl, vcpu ioctl
32723273
:Parameters: struct kvm_device_attr
32733274
:Returns: 0 on success, -1 on error
@@ -3302,7 +3303,8 @@ transferred is defined by the particular attribute.
33023303
------------------------
33033304

33043305
:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3305-
KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3306+
KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3307+
KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device
33063308
:Type: device ioctl, vm ioctl, vcpu ioctl
33073309
:Parameters: struct kvm_device_attr
33083310
:Returns: 0 on success, -1 on error

arch/arm64/kvm/hyp/exception.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ static inline void __vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg)
3838

3939
static void __vcpu_write_spsr(struct kvm_vcpu *vcpu, u64 val)
4040
{
41-
write_sysreg_el1(val, SYS_SPSR);
41+
if (has_vhe())
42+
write_sysreg_el1(val, SYS_SPSR);
43+
else
44+
__vcpu_sys_reg(vcpu, SPSR_EL1) = val;
4245
}
4346

4447
static void __vcpu_write_spsr_abt(struct kvm_vcpu *vcpu, u64 val)

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -983,13 +983,9 @@ static int stage2_unmap_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
983983
*/
984984
stage2_put_pte(ptep, mmu, addr, level, mm_ops);
985985

986-
if (need_flush) {
987-
kvm_pte_t *pte_follow = kvm_pte_follow(pte, mm_ops);
988-
989-
dcache_clean_inval_poc((unsigned long)pte_follow,
990-
(unsigned long)pte_follow +
991-
kvm_granule_size(level));
992-
}
986+
if (need_flush && mm_ops->dcache_clean_inval_poc)
987+
mm_ops->dcache_clean_inval_poc(kvm_pte_follow(pte, mm_ops),
988+
kvm_granule_size(level));
993989

994990
if (childp)
995991
mm_ops->put_page(childp);
@@ -1151,15 +1147,13 @@ static int stage2_flush_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,
11511147
struct kvm_pgtable *pgt = arg;
11521148
struct kvm_pgtable_mm_ops *mm_ops = pgt->mm_ops;
11531149
kvm_pte_t pte = *ptep;
1154-
kvm_pte_t *pte_follow;
11551150

11561151
if (!kvm_pte_valid(pte) || !stage2_pte_cacheable(pgt, pte))
11571152
return 0;
11581153

1159-
pte_follow = kvm_pte_follow(pte, mm_ops);
1160-
dcache_clean_inval_poc((unsigned long)pte_follow,
1161-
(unsigned long)pte_follow +
1162-
kvm_granule_size(level));
1154+
if (mm_ops->dcache_clean_inval_poc)
1155+
mm_ops->dcache_clean_inval_poc(kvm_pte_follow(pte, mm_ops),
1156+
kvm_granule_size(level));
11631157
return 0;
11641158
}
11651159

arch/arm64/kvm/hyp/vgic-v3-sr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,9 @@ static void __vgic_v3_read_ctlr(struct kvm_vcpu *vcpu, u32 vmcr, int rt)
983983
val = ((vtr >> 29) & 7) << ICC_CTLR_EL1_PRI_BITS_SHIFT;
984984
/* IDbits */
985985
val |= ((vtr >> 23) & 7) << ICC_CTLR_EL1_ID_BITS_SHIFT;
986+
/* SEIS */
987+
if (kvm_vgic_global_state.ich_vtr_el2 & ICH_VTR_SEIS_MASK)
988+
val |= BIT(ICC_CTLR_EL1_SEIS_SHIFT);
986989
/* A3V */
987990
val |= ((vtr >> 21) & 1) << ICC_CTLR_EL1_A3V_SHIFT;
988991
/* EOImode */

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,18 @@ static int __init early_gicv4_enable(char *buf)
609609
}
610610
early_param("kvm-arm.vgic_v4_enable", early_gicv4_enable);
611611

612+
static const struct midr_range broken_seis[] = {
613+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_ICESTORM),
614+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_FIRESTORM),
615+
{},
616+
};
617+
618+
static bool vgic_v3_broken_seis(void)
619+
{
620+
return ((kvm_vgic_global_state.ich_vtr_el2 & ICH_VTR_SEIS_MASK) &&
621+
is_midr_in_range_list(read_cpuid_id(), broken_seis));
622+
}
623+
612624
/**
613625
* vgic_v3_probe - probe for a VGICv3 compatible interrupt controller
614626
* @info: pointer to the GIC description
@@ -676,9 +688,10 @@ int vgic_v3_probe(const struct gic_kvm_info *info)
676688
group1_trap = true;
677689
}
678690

679-
if (kvm_vgic_global_state.ich_vtr_el2 & ICH_VTR_SEIS_MASK) {
680-
kvm_info("GICv3 with locally generated SEI\n");
691+
if (vgic_v3_broken_seis()) {
692+
kvm_info("GICv3 with broken locally generated SEI\n");
681693

694+
kvm_vgic_global_state.ich_vtr_el2 &= ~ICH_VTR_SEIS_MASK;
682695
group0_trap = true;
683696
group1_trap = true;
684697
if (ich_vtr_el2 & ICH_VTR_TDS_MASK)

arch/x86/include/asm/kvm_host.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,8 @@ struct kvm_x86_ops {
14831483

14841484
int (*get_msr_feature)(struct kvm_msr_entry *entry);
14851485

1486-
bool (*can_emulate_instruction)(struct kvm_vcpu *vcpu, void *insn, int insn_len);
1486+
bool (*can_emulate_instruction)(struct kvm_vcpu *vcpu, int emul_type,
1487+
void *insn, int insn_len);
14871488

14881489
bool (*apic_init_signal_blocked)(struct kvm_vcpu *vcpu);
14891490
int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu);
@@ -1496,6 +1497,7 @@ struct kvm_x86_ops {
14961497
};
14971498

14981499
struct kvm_x86_nested_ops {
1500+
void (*leave_nested)(struct kvm_vcpu *vcpu);
14991501
int (*check_events)(struct kvm_vcpu *vcpu);
15001502
bool (*hv_timer_pending)(struct kvm_vcpu *vcpu);
15011503
void (*triple_fault)(struct kvm_vcpu *vcpu);
@@ -1861,7 +1863,6 @@ int kvm_cpu_has_extint(struct kvm_vcpu *v);
18611863
int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
18621864
int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
18631865
void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event);
1864-
void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu);
18651866

18661867
int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
18671868
unsigned long ipi_bitmap_high, u32 min,

arch/x86/include/uapi/asm/kvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ struct kvm_sync_regs {
452452

453453
#define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001
454454

455+
/* attributes for system fd (group 0) */
456+
#define KVM_X86_XCOMP_GUEST_SUPP 0
457+
455458
struct kvm_vmx_nested_state_data {
456459
__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
457460
__u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];

arch/x86/kvm/cpuid.c

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
133133
orig = &vcpu->arch.cpuid_entries[i];
134134
if (e2[i].function != orig->function ||
135135
e2[i].index != orig->index ||
136+
e2[i].flags != orig->flags ||
136137
e2[i].eax != orig->eax || e2[i].ebx != orig->ebx ||
137138
e2[i].ecx != orig->ecx || e2[i].edx != orig->edx)
138139
return -EINVAL;
@@ -196,10 +197,26 @@ void kvm_update_pv_runtime(struct kvm_vcpu *vcpu)
196197
vcpu->arch.pv_cpuid.features = best->eax;
197198
}
198199

200+
/*
201+
* Calculate guest's supported XCR0 taking into account guest CPUID data and
202+
* supported_xcr0 (comprised of host configuration and KVM_SUPPORTED_XCR0).
203+
*/
204+
static u64 cpuid_get_supported_xcr0(struct kvm_cpuid_entry2 *entries, int nent)
205+
{
206+
struct kvm_cpuid_entry2 *best;
207+
208+
best = cpuid_entry2_find(entries, nent, 0xd, 0);
209+
if (!best)
210+
return 0;
211+
212+
return (best->eax | ((u64)best->edx << 32)) & supported_xcr0;
213+
}
214+
199215
static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *entries,
200216
int nent)
201217
{
202218
struct kvm_cpuid_entry2 *best;
219+
u64 guest_supported_xcr0 = cpuid_get_supported_xcr0(entries, nent);
203220

204221
best = cpuid_entry2_find(entries, nent, 1, 0);
205222
if (best) {
@@ -238,6 +255,21 @@ static void __kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu, struct kvm_cpuid_e
238255
vcpu->arch.ia32_misc_enable_msr &
239256
MSR_IA32_MISC_ENABLE_MWAIT);
240257
}
258+
259+
/*
260+
* Bits 127:0 of the allowed SECS.ATTRIBUTES (CPUID.0x12.0x1) enumerate
261+
* the supported XSAVE Feature Request Mask (XFRM), i.e. the enclave's
262+
* requested XCR0 value. The enclave's XFRM must be a subset of XCRO
263+
* at the time of EENTER, thus adjust the allowed XFRM by the guest's
264+
* supported XCR0. Similar to XCR0 handling, FP and SSE are forced to
265+
* '1' even on CPUs that don't support XSAVE.
266+
*/
267+
best = cpuid_entry2_find(entries, nent, 0x12, 0x1);
268+
if (best) {
269+
best->ecx &= guest_supported_xcr0 & 0xffffffff;
270+
best->edx &= guest_supported_xcr0 >> 32;
271+
best->ecx |= XFEATURE_MASK_FPSSE;
272+
}
241273
}
242274

243275
void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
@@ -261,27 +293,8 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
261293
kvm_apic_set_version(vcpu);
262294
}
263295

264-
best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
265-
if (!best)
266-
vcpu->arch.guest_supported_xcr0 = 0;
267-
else
268-
vcpu->arch.guest_supported_xcr0 =
269-
(best->eax | ((u64)best->edx << 32)) & supported_xcr0;
270-
271-
/*
272-
* Bits 127:0 of the allowed SECS.ATTRIBUTES (CPUID.0x12.0x1) enumerate
273-
* the supported XSAVE Feature Request Mask (XFRM), i.e. the enclave's
274-
* requested XCR0 value. The enclave's XFRM must be a subset of XCRO
275-
* at the time of EENTER, thus adjust the allowed XFRM by the guest's
276-
* supported XCR0. Similar to XCR0 handling, FP and SSE are forced to
277-
* '1' even on CPUs that don't support XSAVE.
278-
*/
279-
best = kvm_find_cpuid_entry(vcpu, 0x12, 0x1);
280-
if (best) {
281-
best->ecx &= vcpu->arch.guest_supported_xcr0 & 0xffffffff;
282-
best->edx &= vcpu->arch.guest_supported_xcr0 >> 32;
283-
best->ecx |= XFEATURE_MASK_FPSSE;
284-
}
296+
vcpu->arch.guest_supported_xcr0 =
297+
cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
285298

286299
kvm_update_pv_runtime(vcpu);
287300

@@ -346,8 +359,14 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
346359
* KVM_SET_CPUID{,2} again. To support this legacy behavior, check
347360
* whether the supplied CPUID data is equal to what's already set.
348361
*/
349-
if (vcpu->arch.last_vmentry_cpu != -1)
350-
return kvm_cpuid_check_equal(vcpu, e2, nent);
362+
if (vcpu->arch.last_vmentry_cpu != -1) {
363+
r = kvm_cpuid_check_equal(vcpu, e2, nent);
364+
if (r)
365+
return r;
366+
367+
kvfree(e2);
368+
return 0;
369+
}
351370

352371
r = kvm_check_cpuid(vcpu, e2, nent);
353372
if (r)
@@ -887,13 +906,14 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
887906
}
888907
break;
889908
case 0xd: {
890-
u64 guest_perm = xstate_get_guest_group_perm();
909+
u64 permitted_xcr0 = supported_xcr0 & xstate_get_guest_group_perm();
910+
u64 permitted_xss = supported_xss;
891911

892-
entry->eax &= supported_xcr0 & guest_perm;
893-
entry->ebx = xstate_required_size(supported_xcr0, false);
912+
entry->eax &= permitted_xcr0;
913+
entry->ebx = xstate_required_size(permitted_xcr0, false);
894914
entry->ecx = entry->ebx;
895-
entry->edx &= (supported_xcr0 & guest_perm) >> 32;
896-
if (!supported_xcr0)
915+
entry->edx &= permitted_xcr0 >> 32;
916+
if (!permitted_xcr0)
897917
break;
898918

899919
entry = do_host_cpuid(array, function, 1);
@@ -902,20 +922,20 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
902922

903923
cpuid_entry_override(entry, CPUID_D_1_EAX);
904924
if (entry->eax & (F(XSAVES)|F(XSAVEC)))
905-
entry->ebx = xstate_required_size(supported_xcr0 | supported_xss,
925+
entry->ebx = xstate_required_size(permitted_xcr0 | permitted_xss,
906926
true);
907927
else {
908-
WARN_ON_ONCE(supported_xss != 0);
928+
WARN_ON_ONCE(permitted_xss != 0);
909929
entry->ebx = 0;
910930
}
911-
entry->ecx &= supported_xss;
912-
entry->edx &= supported_xss >> 32;
931+
entry->ecx &= permitted_xss;
932+
entry->edx &= permitted_xss >> 32;
913933

914934
for (i = 2; i < 64; ++i) {
915935
bool s_state;
916-
if (supported_xcr0 & BIT_ULL(i))
936+
if (permitted_xcr0 & BIT_ULL(i))
917937
s_state = false;
918-
else if (supported_xss & BIT_ULL(i))
938+
else if (permitted_xss & BIT_ULL(i))
919939
s_state = true;
920940
else
921941
continue;
@@ -929,7 +949,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
929949
* invalid sub-leafs. Only valid sub-leafs should
930950
* reach this point, and they should have a non-zero
931951
* save state size. Furthermore, check whether the
932-
* processor agrees with supported_xcr0/supported_xss
952+
* processor agrees with permitted_xcr0/permitted_xss
933953
* on whether this is an XCR0- or IA32_XSS-managed area.
934954
*/
935955
if (WARN_ON_ONCE(!entry->eax || (entry->ecx & 0x1) != s_state)) {

arch/x86/kvm/lapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,7 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s)
26292629
kvm_apic_set_version(vcpu);
26302630

26312631
apic_update_ppr(apic);
2632-
hrtimer_cancel(&apic->lapic_timer.timer);
2632+
cancel_apic_timer(apic);
26332633
apic->lapic_timer.expired_tscdeadline = 0;
26342634
apic_update_lvtt(apic);
26352635
apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0));

arch/x86/kvm/svm/nested.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,9 @@ void svm_free_nested(struct vcpu_svm *svm)
983983
/*
984984
* Forcibly leave nested mode in order to be able to reset the VCPU later on.
985985
*/
986-
void svm_leave_nested(struct vcpu_svm *svm)
986+
void svm_leave_nested(struct kvm_vcpu *vcpu)
987987
{
988-
struct kvm_vcpu *vcpu = &svm->vcpu;
988+
struct vcpu_svm *svm = to_svm(vcpu);
989989

990990
if (is_guest_mode(vcpu)) {
991991
svm->nested.nested_run_pending = 0;
@@ -1411,7 +1411,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
14111411
return -EINVAL;
14121412

14131413
if (!(kvm_state->flags & KVM_STATE_NESTED_GUEST_MODE)) {
1414-
svm_leave_nested(svm);
1414+
svm_leave_nested(vcpu);
14151415
svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET));
14161416
return 0;
14171417
}
@@ -1478,7 +1478,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
14781478
*/
14791479

14801480
if (is_guest_mode(vcpu))
1481-
svm_leave_nested(svm);
1481+
svm_leave_nested(vcpu);
14821482
else
14831483
svm->nested.vmcb02.ptr->save = svm->vmcb01.ptr->save;
14841484

@@ -1532,6 +1532,7 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)
15321532
}
15331533

15341534
struct kvm_x86_nested_ops svm_nested_ops = {
1535+
.leave_nested = svm_leave_nested,
15351536
.check_events = svm_check_nested_events,
15361537
.triple_fault = nested_svm_triple_fault,
15371538
.get_nested_state_pages = svm_get_nested_state_pages,

0 commit comments

Comments
 (0)