Skip to content

Commit 6693075

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fixes from Paolo Bonzini: "Bugfixes for x86 and s390" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs KVM: x86: Initializing all kvm_lapic_irq fields in ioapic_write_indirect KVM: VMX: Condition ENCLS-exiting enabling on CPU support for SGX1 KVM: s390: Also reset registers in sync regs for initial cpu reset KVM: fix Kconfig menu text for -Werror KVM: x86: remove stale comment from struct x86_emulate_ctxt KVM: x86: clear stale x86_emulate_ctxt->intercept value KVM: SVM: Fix the svm vmexit code for WRMSR KVM: X86: Fix dereference null cpufreq policy
2 parents 69a4d0b + 018cabb commit 6693075

File tree

9 files changed

+48
-13
lines changed

9 files changed

+48
-13
lines changed

arch/s390/kvm/kvm-s390.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,10 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
32683268
/* Initial reset is a superset of the normal reset */
32693269
kvm_arch_vcpu_ioctl_normal_reset(vcpu);
32703270

3271-
/* this equals initial cpu reset in pop, but we don't switch to ESA */
3271+
/*
3272+
* This equals initial cpu reset in pop, but we don't switch to ESA.
3273+
* We do not only reset the internal data, but also ...
3274+
*/
32723275
vcpu->arch.sie_block->gpsw.mask = 0;
32733276
vcpu->arch.sie_block->gpsw.addr = 0;
32743277
kvm_s390_set_prefix(vcpu, 0);
@@ -3278,6 +3281,19 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
32783281
memset(vcpu->arch.sie_block->gcr, 0, sizeof(vcpu->arch.sie_block->gcr));
32793282
vcpu->arch.sie_block->gcr[0] = CR0_INITIAL_MASK;
32803283
vcpu->arch.sie_block->gcr[14] = CR14_INITIAL_MASK;
3284+
3285+
/* ... the data in sync regs */
3286+
memset(vcpu->run->s.regs.crs, 0, sizeof(vcpu->run->s.regs.crs));
3287+
vcpu->run->s.regs.ckc = 0;
3288+
vcpu->run->s.regs.crs[0] = CR0_INITIAL_MASK;
3289+
vcpu->run->s.regs.crs[14] = CR14_INITIAL_MASK;
3290+
vcpu->run->psw_addr = 0;
3291+
vcpu->run->psw_mask = 0;
3292+
vcpu->run->s.regs.todpr = 0;
3293+
vcpu->run->s.regs.cputm = 0;
3294+
vcpu->run->s.regs.ckc = 0;
3295+
vcpu->run->s.regs.pp = 0;
3296+
vcpu->run->s.regs.gbea = 1;
32813297
vcpu->run->s.regs.fpc = 0;
32823298
vcpu->arch.sie_block->gbea = 1;
32833299
vcpu->arch.sie_block->pp = 0;

arch/x86/include/asm/kvm_emulate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ struct x86_emulate_ctxt {
360360
u64 d;
361361
unsigned long _eip;
362362
struct operand memop;
363-
/* Fields above regs are cleared together. */
364363
unsigned long _regs[NR_VCPU_REGS];
365364
struct operand *memopp;
366365
struct fetch_cache fetch;

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ config KVM_WERROR
6868
depends on (X86_64 && !KASAN) || !COMPILE_TEST
6969
depends on EXPERT
7070
help
71-
Add -Werror to the build flags for (and only for) i915.ko.
71+
Add -Werror to the build flags for KVM.
7272

7373
If in doubt, say "N".
7474

arch/x86/kvm/emulate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5173,6 +5173,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len)
51735173
ctxt->fetch.ptr = ctxt->fetch.data;
51745174
ctxt->fetch.end = ctxt->fetch.data + insn_len;
51755175
ctxt->opcode_len = 1;
5176+
ctxt->intercept = x86_intercept_none;
51765177
if (insn_len > 0)
51775178
memcpy(ctxt->fetch.data, insn, insn_len);
51785179
else {

arch/x86/kvm/ioapic.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,15 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
378378
if (e->fields.delivery_mode == APIC_DM_FIXED) {
379379
struct kvm_lapic_irq irq;
380380

381-
irq.shorthand = APIC_DEST_NOSHORT;
382381
irq.vector = e->fields.vector;
383382
irq.delivery_mode = e->fields.delivery_mode << 8;
384-
irq.dest_id = e->fields.dest_id;
385383
irq.dest_mode =
386384
kvm_lapic_irq_dest_mode(!!e->fields.dest_mode);
385+
irq.level = false;
386+
irq.trig_mode = e->fields.trig_mode;
387+
irq.shorthand = APIC_DEST_NOSHORT;
388+
irq.dest_id = e->fields.dest_id;
389+
irq.msi_redir_hint = false;
387390
bitmap_zero(&vcpu_bitmap, 16);
388391
kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq,
389392
&vcpu_bitmap);

arch/x86/kvm/svm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6312,7 +6312,8 @@ static void svm_handle_exit_irqoff(struct kvm_vcpu *vcpu,
63126312
enum exit_fastpath_completion *exit_fastpath)
63136313
{
63146314
if (!is_guest_mode(vcpu) &&
6315-
to_svm(vcpu)->vmcb->control.exit_code == EXIT_REASON_MSR_WRITE)
6315+
to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
6316+
to_svm(vcpu)->vmcb->control.exit_info_1)
63166317
*exit_fastpath = handle_fastpath_set_msr_irqoff(vcpu);
63176318
}
63186319

arch/x86/kvm/vmx/nested.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu)
224224
return;
225225

226226
kvm_vcpu_unmap(vcpu, &vmx->nested.hv_evmcs_map, true);
227-
vmx->nested.hv_evmcs_vmptr = -1ull;
227+
vmx->nested.hv_evmcs_vmptr = 0;
228228
vmx->nested.hv_evmcs = NULL;
229229
}
230230

@@ -1923,7 +1923,8 @@ static int nested_vmx_handle_enlightened_vmptrld(struct kvm_vcpu *vcpu,
19231923
if (!nested_enlightened_vmentry(vcpu, &evmcs_gpa))
19241924
return 1;
19251925

1926-
if (unlikely(evmcs_gpa != vmx->nested.hv_evmcs_vmptr)) {
1926+
if (unlikely(!vmx->nested.hv_evmcs ||
1927+
evmcs_gpa != vmx->nested.hv_evmcs_vmptr)) {
19271928
if (!vmx->nested.hv_evmcs)
19281929
vmx->nested.current_vmptr = -1ull;
19291930

arch/x86/kvm/vmx/vmx.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,6 +2338,17 @@ static void hardware_disable(void)
23382338
kvm_cpu_vmxoff();
23392339
}
23402340

2341+
/*
2342+
* There is no X86_FEATURE for SGX yet, but anyway we need to query CPUID
2343+
* directly instead of going through cpu_has(), to ensure KVM is trapping
2344+
* ENCLS whenever it's supported in hardware. It does not matter whether
2345+
* the host OS supports or has enabled SGX.
2346+
*/
2347+
static bool cpu_has_sgx(void)
2348+
{
2349+
return cpuid_eax(0) >= 0x12 && (cpuid_eax(0x12) & BIT(0));
2350+
}
2351+
23412352
static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt,
23422353
u32 msr, u32 *result)
23432354
{
@@ -2418,8 +2429,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,
24182429
SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE |
24192430
SECONDARY_EXEC_PT_USE_GPA |
24202431
SECONDARY_EXEC_PT_CONCEAL_VMX |
2421-
SECONDARY_EXEC_ENABLE_VMFUNC |
2422-
SECONDARY_EXEC_ENCLS_EXITING;
2432+
SECONDARY_EXEC_ENABLE_VMFUNC;
2433+
if (cpu_has_sgx())
2434+
opt2 |= SECONDARY_EXEC_ENCLS_EXITING;
24232435
if (adjust_vmx_controls(min2, opt2,
24242436
MSR_IA32_VMX_PROCBASED_CTLS2,
24252437
&_cpu_based_2nd_exec_control) < 0)

arch/x86/kvm/x86.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7195,10 +7195,12 @@ static void kvm_timer_init(void)
71957195

71967196
cpu = get_cpu();
71977197
policy = cpufreq_cpu_get(cpu);
7198-
if (policy && policy->cpuinfo.max_freq)
7199-
max_tsc_khz = policy->cpuinfo.max_freq;
7198+
if (policy) {
7199+
if (policy->cpuinfo.max_freq)
7200+
max_tsc_khz = policy->cpuinfo.max_freq;
7201+
cpufreq_cpu_put(policy);
7202+
}
72007203
put_cpu();
7201-
cpufreq_cpu_put(policy);
72027204
#endif
72037205
cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block,
72047206
CPUFREQ_TRANSITION_NOTIFIER);

0 commit comments

Comments
 (0)