Skip to content

Commit a313c8e

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Paolo Bonzini: "PPC: - Fix a bug where we try to do an ultracall on a system without an ultravisor KVM: - Fix uninitialised sysreg accessor - Fix handling of demand-paged device mappings - Stop spamming the console on IMPDEF sysregs - Relax mappings of writable memslots - Assorted cleanups MIPS: - Now orphan, James Hogan is stepping down x86: - MAINTAINERS change, so long Radim and thanks for all the fish - supported CPUID fixes for AMD machines without SPEC_CTRL" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: MAINTAINERS: remove Radim from KVM maintainers MAINTAINERS: Orphan KVM for MIPS kvm: x86: Host feature SSBD doesn't imply guest feature AMD_SSBD kvm: x86: Host feature SSBD doesn't imply guest feature SPEC_CTRL_SSBD KVM: PPC: Book3S HV: Don't do ultravisor calls on systems without ultravisor KVM: arm/arm64: Properly handle faulting of device mappings KVM: arm64: Ensure 'params' is initialised when looking up sys register KVM: arm/arm64: Remove excessive permission check in kvm_arch_prepare_memory_region KVM: arm64: Don't log IMP DEF sysreg traps KVM: arm64: Sanely ratelimit sysreg messages KVM: arm/arm64: vgic: Use wrapper function to lock/unlock all vcpus in kvm_vgic_create() KVM: arm/arm64: vgic: Fix potential double free dist->spis in __kvm_vgic_destroy() KVM: arm/arm64: Get rid of unused arg in cpu_init_hyp_mode()
2 parents 7214618 + d68321d commit a313c8e

File tree

8 files changed

+65
-46
lines changed

8 files changed

+65
-46
lines changed

MAINTAINERS

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9041,7 +9041,6 @@ F: include/linux/umh.h
90419041

90429042
KERNEL VIRTUAL MACHINE (KVM)
90439043
M: Paolo Bonzini <[email protected]>
9044-
M: Radim Krčmář <[email protected]>
90459044
90469045
W: http://www.linux-kvm.org
90479046
T: git git://git.kernel.org/pub/scm/virt/kvm/kvm.git
@@ -9076,9 +9075,9 @@ F: virt/kvm/arm/
90769075
F: include/kvm/arm_*
90779076

90789077
KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips)
9079-
M: James Hogan <[email protected]>
90809078
9081-
S: Supported
9079+
9080+
S: Orphan
90829081
F: arch/mips/include/uapi/asm/kvm*
90839082
F: arch/mips/include/asm/kvm*
90849083
F: arch/mips/kvm/
@@ -9113,7 +9112,6 @@ F: tools/testing/selftests/kvm/*/s390x/
91139112

91149113
KERNEL VIRTUAL MACHINE FOR X86 (KVM/x86)
91159114
M: Paolo Bonzini <[email protected]>
9116-
M: Radim Krčmář <[email protected]>
91179115
R: Sean Christopherson <[email protected]>
91189116
R: Vitaly Kuznetsov <[email protected]>
91199117
R: Wanpeng Li <[email protected]>

arch/arm64/kvm/sys_regs.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,9 +2098,9 @@ static void unhandled_cp_access(struct kvm_vcpu *vcpu,
20982098
WARN_ON(1);
20992099
}
21002100

2101-
kvm_err("Unsupported guest CP%d access at: %08lx [%08lx]\n",
2102-
cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
2103-
print_sys_reg_instr(params);
2101+
print_sys_reg_msg(params,
2102+
"Unsupported guest CP%d access at: %08lx [%08lx]\n",
2103+
cp, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
21042104
kvm_inject_undefined(vcpu);
21052105
}
21062106

@@ -2233,6 +2233,12 @@ int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run)
22332233
NULL, 0);
22342234
}
22352235

2236+
static bool is_imp_def_sys_reg(struct sys_reg_params *params)
2237+
{
2238+
// See ARM DDI 0487E.a, section D12.3.2
2239+
return params->Op0 == 3 && (params->CRn & 0b1011) == 0b1011;
2240+
}
2241+
22362242
static int emulate_sys_reg(struct kvm_vcpu *vcpu,
22372243
struct sys_reg_params *params)
22382244
{
@@ -2248,10 +2254,12 @@ static int emulate_sys_reg(struct kvm_vcpu *vcpu,
22482254

22492255
if (likely(r)) {
22502256
perform_access(vcpu, params, r);
2257+
} else if (is_imp_def_sys_reg(params)) {
2258+
kvm_inject_undefined(vcpu);
22512259
} else {
2252-
kvm_err("Unsupported guest sys_reg access at: %lx [%08lx]\n",
2253-
*vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
2254-
print_sys_reg_instr(params);
2260+
print_sys_reg_msg(params,
2261+
"Unsupported guest sys_reg access at: %lx [%08lx]\n",
2262+
*vcpu_pc(vcpu), *vcpu_cpsr(vcpu));
22552263
kvm_inject_undefined(vcpu);
22562264
}
22572265
return 1;
@@ -2360,8 +2368,11 @@ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
23602368
if ((id & KVM_REG_ARM_COPROC_MASK) != KVM_REG_ARM64_SYSREG)
23612369
return NULL;
23622370

2371+
if (!index_to_params(id, &params))
2372+
return NULL;
2373+
23632374
table = get_target_table(vcpu->arch.target, true, &num);
2364-
r = find_reg_by_id(id, &params, table, num);
2375+
r = find_reg(&params, table, num);
23652376
if (!r)
23662377
r = find_reg(&params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
23672378

arch/arm64/kvm/sys_regs.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,24 @@ struct sys_reg_desc {
6262
#define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */
6363
#define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */
6464

65-
static inline void print_sys_reg_instr(const struct sys_reg_params *p)
65+
static __printf(2, 3)
66+
inline void print_sys_reg_msg(const struct sys_reg_params *p,
67+
char *fmt, ...)
6668
{
69+
va_list va;
70+
71+
va_start(va, fmt);
6772
/* Look, we even formatted it for you to paste into the table! */
68-
kvm_pr_unimpl(" { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
73+
kvm_pr_unimpl("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
74+
&(struct va_format){ fmt, &va },
6975
p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
76+
va_end(va);
77+
}
78+
79+
static inline void print_sys_reg_instr(const struct sys_reg_params *p)
80+
{
81+
/* GCC warns on an empty format string */
82+
print_sys_reg_msg(p, "%s", "");
7083
}
7184

7285
static inline bool ignore_write(struct kvm_vcpu *vcpu,

arch/powerpc/kvm/book3s_hv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4983,7 +4983,8 @@ static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)
49834983
if (nesting_enabled(kvm))
49844984
kvmhv_release_all_nested(kvm);
49854985
kvm->arch.process_table = 0;
4986-
uv_svm_terminate(kvm->arch.lpid);
4986+
if (kvm->arch.secure_guest)
4987+
uv_svm_terminate(kvm->arch.lpid);
49874988
kvmhv_set_ptbl_entry(kvm->arch.lpid, 0, 0);
49884989
}
49894990

arch/x86/kvm/cpuid.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)
402402
entry->edx |= F(SPEC_CTRL);
403403
if (boot_cpu_has(X86_FEATURE_STIBP))
404404
entry->edx |= F(INTEL_STIBP);
405-
if (boot_cpu_has(X86_FEATURE_SSBD))
405+
if (boot_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
406+
boot_cpu_has(X86_FEATURE_AMD_SSBD))
406407
entry->edx |= F(SPEC_CTRL_SSBD);
407408
/*
408409
* We emulate ARCH_CAPABILITIES in software even
@@ -759,7 +760,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
759760
entry->ebx |= F(AMD_IBRS);
760761
if (boot_cpu_has(X86_FEATURE_STIBP))
761762
entry->ebx |= F(AMD_STIBP);
762-
if (boot_cpu_has(X86_FEATURE_SSBD))
763+
if (boot_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
764+
boot_cpu_has(X86_FEATURE_AMD_SSBD))
763765
entry->ebx |= F(AMD_SSBD);
764766
if (!boot_cpu_has_bug(X86_BUG_SPEC_STORE_BYPASS))
765767
entry->ebx |= F(AMD_SSB_NO);

virt/kvm/arm/arm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ long kvm_arch_vm_ioctl(struct file *filp,
13521352
}
13531353
}
13541354

1355-
static void cpu_init_hyp_mode(void *dummy)
1355+
static void cpu_init_hyp_mode(void)
13561356
{
13571357
phys_addr_t pgd_ptr;
13581358
unsigned long hyp_stack_ptr;
@@ -1386,7 +1386,7 @@ static void cpu_hyp_reinit(void)
13861386
if (is_kernel_in_hyp_mode())
13871387
kvm_timer_init_vhe();
13881388
else
1389-
cpu_init_hyp_mode(NULL);
1389+
cpu_init_hyp_mode();
13901390

13911391
kvm_arm_init_debug();
13921392

virt/kvm/arm/mmu.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ static unsigned long io_map_base;
3838
#define KVM_S2PTE_FLAG_IS_IOMAP (1UL << 0)
3939
#define KVM_S2_FLAG_LOGGING_ACTIVE (1UL << 1)
4040

41+
static bool is_iomap(unsigned long flags)
42+
{
43+
return flags & KVM_S2PTE_FLAG_IS_IOMAP;
44+
}
45+
4146
static bool memslot_is_logging(struct kvm_memory_slot *memslot)
4247
{
4348
return memslot->dirty_bitmap && !(memslot->flags & KVM_MEM_READONLY);
@@ -1698,6 +1703,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
16981703

16991704
vma_pagesize = vma_kernel_pagesize(vma);
17001705
if (logging_active ||
1706+
(vma->vm_flags & VM_PFNMAP) ||
17011707
!fault_supports_stage2_huge_mapping(memslot, hva, vma_pagesize)) {
17021708
force_pte = true;
17031709
vma_pagesize = PAGE_SIZE;
@@ -1760,6 +1766,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
17601766
writable = false;
17611767
}
17621768

1769+
if (exec_fault && is_iomap(flags))
1770+
return -ENOEXEC;
1771+
17631772
spin_lock(&kvm->mmu_lock);
17641773
if (mmu_notifier_retry(kvm, mmu_seq))
17651774
goto out_unlock;
@@ -1781,7 +1790,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
17811790
if (writable)
17821791
kvm_set_pfn_dirty(pfn);
17831792

1784-
if (fault_status != FSC_PERM)
1793+
if (fault_status != FSC_PERM && !is_iomap(flags))
17851794
clean_dcache_guest_page(pfn, vma_pagesize);
17861795

17871796
if (exec_fault)
@@ -1948,9 +1957,8 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
19481957
if (kvm_is_error_hva(hva) || (write_fault && !writable)) {
19491958
if (is_iabt) {
19501959
/* Prefetch Abort on I/O address */
1951-
kvm_inject_pabt(vcpu, kvm_vcpu_get_hfar(vcpu));
1952-
ret = 1;
1953-
goto out_unlock;
1960+
ret = -ENOEXEC;
1961+
goto out;
19541962
}
19551963

19561964
/*
@@ -1992,6 +2000,11 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
19922000
ret = user_mem_abort(vcpu, fault_ipa, memslot, hva, fault_status);
19932001
if (ret == 0)
19942002
ret = 1;
2003+
out:
2004+
if (ret == -ENOEXEC) {
2005+
kvm_inject_pabt(vcpu, kvm_vcpu_get_hfar(vcpu));
2006+
ret = 1;
2007+
}
19952008
out_unlock:
19962009
srcu_read_unlock(&vcpu->kvm->srcu, idx);
19972010
return ret;
@@ -2301,15 +2314,6 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
23012314
if (!vma || vma->vm_start >= reg_end)
23022315
break;
23032316

2304-
/*
2305-
* Mapping a read-only VMA is only allowed if the
2306-
* memory region is configured as read-only.
2307-
*/
2308-
if (writable && !(vma->vm_flags & VM_WRITE)) {
2309-
ret = -EPERM;
2310-
break;
2311-
}
2312-
23132317
/*
23142318
* Take the intersection of this VMA with the memory region
23152319
*/

virt/kvm/arm/vgic/vgic-init.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
7070
*/
7171
int kvm_vgic_create(struct kvm *kvm, u32 type)
7272
{
73-
int i, vcpu_lock_idx = -1, ret;
73+
int i, ret;
7474
struct kvm_vcpu *vcpu;
7575

7676
if (irqchip_in_kernel(kvm))
@@ -86,17 +86,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
8686
!kvm_vgic_global_state.can_emulate_gicv2)
8787
return -ENODEV;
8888

89-
/*
90-
* Any time a vcpu is run, vcpu_load is called which tries to grab the
91-
* vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
92-
* that no other VCPUs are run while we create the vgic.
93-
*/
9489
ret = -EBUSY;
95-
kvm_for_each_vcpu(i, vcpu, kvm) {
96-
if (!mutex_trylock(&vcpu->mutex))
97-
goto out_unlock;
98-
vcpu_lock_idx = i;
99-
}
90+
if (!lock_all_vcpus(kvm))
91+
return ret;
10092

10193
kvm_for_each_vcpu(i, vcpu, kvm) {
10294
if (vcpu->arch.has_run_once)
@@ -125,10 +117,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
125117
INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions);
126118

127119
out_unlock:
128-
for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
129-
vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
130-
mutex_unlock(&vcpu->mutex);
131-
}
120+
unlock_all_vcpus(kvm);
132121
return ret;
133122
}
134123

@@ -177,6 +166,7 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis)
177166
break;
178167
default:
179168
kfree(dist->spis);
169+
dist->spis = NULL;
180170
return -EINVAL;
181171
}
182172
}

0 commit comments

Comments
 (0)