Skip to content

Commit 407ab57

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 compilation error when PMD and PUD are folded - fix regression in reads-as-zero behaviour of ID_AA64ZFR0_EL1 - add aarch64 get-reg-list test x86: - fix semantic conflict between two series merged for 5.10 - fix (and test) enforcement of paravirtual cpuid features selftests: - various cleanups to memory management selftests - new selftests testcase for performance of dirty logging" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (30 commits) KVM: selftests: allow two iterations of dirty_log_perf_test KVM: selftests: Introduce the dirty log perf test KVM: selftests: Make the number of vcpus global KVM: selftests: Make the per vcpu memory size global KVM: selftests: Drop pointless vm_create wrapper KVM: selftests: Add wrfract to common guest code KVM: selftests: Simplify demand_paging_test with timespec_diff_now KVM: selftests: Remove address rounding in guest code KVM: selftests: Factor code out of demand_paging_test KVM: selftests: Use a single binary for dirty/clear log test KVM: selftests: Always clear dirty bitmap after iteration KVM: selftests: Add blessed SVE registers to get-reg-list KVM: selftests: Add aarch64 get-reg-list test selftests: kvm: test enforcement of paravirtual cpuid features selftests: kvm: Add exception handling to selftests selftests: kvm: Clear uc so UCALL_NONE is being properly reported selftests: kvm: Fix the segment descriptor layout to match the actual layout KVM: x86: handle MSR_IA32_DEBUGCTLMSR with report_ignored_msrs kvm: x86: request masterclock update any time guest uses different msr kvm: x86: ensure pv_cpuid.features is initialized when enabling cap ...
2 parents 3552c37 + 6d6a18f commit 407ab57

32 files changed

Lines changed: 2383 additions & 393 deletions

Documentation/virt/kvm/api.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6367,7 +6367,7 @@ accesses that would usually trigger a #GP by KVM into the guest will
63676367
instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
63686368
KVM_EXIT_X86_WRMSR exit notifications.
63696369

6370-
8.25 KVM_X86_SET_MSR_FILTER
6370+
8.27 KVM_X86_SET_MSR_FILTER
63716371
---------------------------
63726372

63736373
:Architectures: x86
@@ -6381,8 +6381,7 @@ In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
63816381
trap and emulate MSRs that are outside of the scope of KVM as well as
63826382
limit the attack surface on KVM's MSR emulation code.
63836383

6384-
6385-
8.26 KVM_CAP_ENFORCE_PV_CPUID
6384+
8.28 KVM_CAP_ENFORCE_PV_CPUID
63866385
-----------------------------
63876386

63886387
Architectures: x86

arch/arm64/kvm/mmu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
788788
}
789789

790790
switch (vma_shift) {
791+
#ifndef __PAGETABLE_PMD_FOLDED
791792
case PUD_SHIFT:
792793
if (fault_supports_stage2_huge_mapping(memslot, hva, PUD_SIZE))
793794
break;
794795
fallthrough;
796+
#endif
795797
case CONT_PMD_SHIFT:
796798
vma_shift = PMD_SHIFT;
797799
fallthrough;

arch/arm64/kvm/sys_regs.c

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ static bool trap_ptrauth(struct kvm_vcpu *vcpu,
10691069
static unsigned int ptrauth_visibility(const struct kvm_vcpu *vcpu,
10701070
const struct sys_reg_desc *rd)
10711071
{
1072-
return vcpu_has_ptrauth(vcpu) ? 0 : REG_HIDDEN_USER | REG_HIDDEN_GUEST;
1072+
return vcpu_has_ptrauth(vcpu) ? 0 : REG_HIDDEN;
10731073
}
10741074

10751075
#define __PTRAUTH_KEY(k) \
@@ -1153,6 +1153,22 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
11531153
return val;
11541154
}
11551155

1156+
static unsigned int id_visibility(const struct kvm_vcpu *vcpu,
1157+
const struct sys_reg_desc *r)
1158+
{
1159+
u32 id = sys_reg((u32)r->Op0, (u32)r->Op1,
1160+
(u32)r->CRn, (u32)r->CRm, (u32)r->Op2);
1161+
1162+
switch (id) {
1163+
case SYS_ID_AA64ZFR0_EL1:
1164+
if (!vcpu_has_sve(vcpu))
1165+
return REG_RAZ;
1166+
break;
1167+
}
1168+
1169+
return 0;
1170+
}
1171+
11561172
/* cpufeature ID register access trap handlers */
11571173

11581174
static bool __access_id_reg(struct kvm_vcpu *vcpu,
@@ -1171,7 +1187,9 @@ static bool access_id_reg(struct kvm_vcpu *vcpu,
11711187
struct sys_reg_params *p,
11721188
const struct sys_reg_desc *r)
11731189
{
1174-
return __access_id_reg(vcpu, p, r, false);
1190+
bool raz = sysreg_visible_as_raz(vcpu, r);
1191+
1192+
return __access_id_reg(vcpu, p, r, raz);
11751193
}
11761194

11771195
static bool access_raz_id_reg(struct kvm_vcpu *vcpu,
@@ -1192,72 +1210,7 @@ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu,
11921210
if (vcpu_has_sve(vcpu))
11931211
return 0;
11941212

1195-
return REG_HIDDEN_USER | REG_HIDDEN_GUEST;
1196-
}
1197-
1198-
/* Visibility overrides for SVE-specific ID registers */
1199-
static unsigned int sve_id_visibility(const struct kvm_vcpu *vcpu,
1200-
const struct sys_reg_desc *rd)
1201-
{
1202-
if (vcpu_has_sve(vcpu))
1203-
return 0;
1204-
1205-
return REG_HIDDEN_USER;
1206-
}
1207-
1208-
/* Generate the emulated ID_AA64ZFR0_EL1 value exposed to the guest */
1209-
static u64 guest_id_aa64zfr0_el1(const struct kvm_vcpu *vcpu)
1210-
{
1211-
if (!vcpu_has_sve(vcpu))
1212-
return 0;
1213-
1214-
return read_sanitised_ftr_reg(SYS_ID_AA64ZFR0_EL1);
1215-
}
1216-
1217-
static bool access_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
1218-
struct sys_reg_params *p,
1219-
const struct sys_reg_desc *rd)
1220-
{
1221-
if (p->is_write)
1222-
return write_to_read_only(vcpu, p, rd);
1223-
1224-
p->regval = guest_id_aa64zfr0_el1(vcpu);
1225-
return true;
1226-
}
1227-
1228-
static int get_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
1229-
const struct sys_reg_desc *rd,
1230-
const struct kvm_one_reg *reg, void __user *uaddr)
1231-
{
1232-
u64 val;
1233-
1234-
if (WARN_ON(!vcpu_has_sve(vcpu)))
1235-
return -ENOENT;
1236-
1237-
val = guest_id_aa64zfr0_el1(vcpu);
1238-
return reg_to_user(uaddr, &val, reg->id);
1239-
}
1240-
1241-
static int set_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,
1242-
const struct sys_reg_desc *rd,
1243-
const struct kvm_one_reg *reg, void __user *uaddr)
1244-
{
1245-
const u64 id = sys_reg_to_index(rd);
1246-
int err;
1247-
u64 val;
1248-
1249-
if (WARN_ON(!vcpu_has_sve(vcpu)))
1250-
return -ENOENT;
1251-
1252-
err = reg_from_user(&val, uaddr, id);
1253-
if (err)
1254-
return err;
1255-
1256-
/* This is what we mean by invariant: you can't change it. */
1257-
if (val != guest_id_aa64zfr0_el1(vcpu))
1258-
return -EINVAL;
1259-
1260-
return 0;
1213+
return REG_HIDDEN;
12611214
}
12621215

12631216
/*
@@ -1299,13 +1252,17 @@ static int __set_id_reg(const struct kvm_vcpu *vcpu,
12991252
static int get_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
13001253
const struct kvm_one_reg *reg, void __user *uaddr)
13011254
{
1302-
return __get_id_reg(vcpu, rd, uaddr, false);
1255+
bool raz = sysreg_visible_as_raz(vcpu, rd);
1256+
1257+
return __get_id_reg(vcpu, rd, uaddr, raz);
13031258
}
13041259

13051260
static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
13061261
const struct kvm_one_reg *reg, void __user *uaddr)
13071262
{
1308-
return __set_id_reg(vcpu, rd, uaddr, false);
1263+
bool raz = sysreg_visible_as_raz(vcpu, rd);
1264+
1265+
return __set_id_reg(vcpu, rd, uaddr, raz);
13091266
}
13101267

13111268
static int get_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
@@ -1397,6 +1354,7 @@ static bool access_mte_regs(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
13971354
.access = access_id_reg, \
13981355
.get_user = get_id_reg, \
13991356
.set_user = set_id_reg, \
1357+
.visibility = id_visibility, \
14001358
}
14011359

14021360
/*
@@ -1518,7 +1476,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
15181476
ID_SANITISED(ID_AA64PFR1_EL1),
15191477
ID_UNALLOCATED(4,2),
15201478
ID_UNALLOCATED(4,3),
1521-
{ SYS_DESC(SYS_ID_AA64ZFR0_EL1), access_id_aa64zfr0_el1, .get_user = get_id_aa64zfr0_el1, .set_user = set_id_aa64zfr0_el1, .visibility = sve_id_visibility },
1479+
ID_SANITISED(ID_AA64ZFR0_EL1),
15221480
ID_UNALLOCATED(4,5),
15231481
ID_UNALLOCATED(4,6),
15241482
ID_UNALLOCATED(4,7),
@@ -2185,7 +2143,7 @@ static void perform_access(struct kvm_vcpu *vcpu,
21852143
trace_kvm_sys_access(*vcpu_pc(vcpu), params, r);
21862144

21872145
/* Check for regs disabled by runtime config */
2188-
if (sysreg_hidden_from_guest(vcpu, r)) {
2146+
if (sysreg_hidden(vcpu, r)) {
21892147
kvm_inject_undefined(vcpu);
21902148
return;
21912149
}
@@ -2684,7 +2642,7 @@ int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg
26842642
return get_invariant_sys_reg(reg->id, uaddr);
26852643

26862644
/* Check for regs disabled by runtime config */
2687-
if (sysreg_hidden_from_user(vcpu, r))
2645+
if (sysreg_hidden(vcpu, r))
26882646
return -ENOENT;
26892647

26902648
if (r->get_user)
@@ -2709,7 +2667,7 @@ int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg
27092667
return set_invariant_sys_reg(reg->id, uaddr);
27102668

27112669
/* Check for regs disabled by runtime config */
2712-
if (sysreg_hidden_from_user(vcpu, r))
2670+
if (sysreg_hidden(vcpu, r))
27132671
return -ENOENT;
27142672

27152673
if (r->set_user)
@@ -2780,7 +2738,7 @@ static int walk_one_sys_reg(const struct kvm_vcpu *vcpu,
27802738
if (!(rd->reg || rd->get_user))
27812739
return 0;
27822740

2783-
if (sysreg_hidden_from_user(vcpu, rd))
2741+
if (sysreg_hidden(vcpu, rd))
27842742
return 0;
27852743

27862744
if (!copy_reg_to_user(rd, uind))

arch/arm64/kvm/sys_regs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ struct sys_reg_desc {
5959
const struct sys_reg_desc *rd);
6060
};
6161

62-
#define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */
63-
#define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */
62+
#define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */
63+
#define REG_RAZ (1 << 1) /* RAZ from userspace and guest */
6464

6565
static __printf(2, 3)
6666
inline void print_sys_reg_msg(const struct sys_reg_params *p,
@@ -111,22 +111,22 @@ static inline void reset_val(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r
111111
__vcpu_sys_reg(vcpu, r->reg) = r->val;
112112
}
113113

114-
static inline bool sysreg_hidden_from_guest(const struct kvm_vcpu *vcpu,
115-
const struct sys_reg_desc *r)
114+
static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,
115+
const struct sys_reg_desc *r)
116116
{
117117
if (likely(!r->visibility))
118118
return false;
119119

120-
return r->visibility(vcpu, r) & REG_HIDDEN_GUEST;
120+
return r->visibility(vcpu, r) & REG_HIDDEN;
121121
}
122122

123-
static inline bool sysreg_hidden_from_user(const struct kvm_vcpu *vcpu,
124-
const struct sys_reg_desc *r)
123+
static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
124+
const struct sys_reg_desc *r)
125125
{
126126
if (likely(!r->visibility))
127127
return false;
128128

129-
return r->visibility(vcpu, r) & REG_HIDDEN_USER;
129+
return r->visibility(vcpu, r) & REG_RAZ;
130130
}
131131

132132
static inline int cmp_sys_reg(const struct sys_reg_desc *i1,

arch/x86/kvm/cpuid.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ static int kvm_check_cpuid(struct kvm_cpuid_entry2 *entries, int nent)
9090
return 0;
9191
}
9292

93+
void kvm_update_pv_runtime(struct kvm_vcpu *vcpu)
94+
{
95+
struct kvm_cpuid_entry2 *best;
96+
97+
best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0);
98+
99+
/*
100+
* save the feature bitmap to avoid cpuid lookup for every PV
101+
* operation
102+
*/
103+
if (best)
104+
vcpu->arch.pv_cpuid.features = best->eax;
105+
}
106+
93107
void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
94108
{
95109
struct kvm_cpuid_entry2 *best;
@@ -124,13 +138,6 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu)
124138
(best->eax & (1 << KVM_FEATURE_PV_UNHALT)))
125139
best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT);
126140

127-
/*
128-
* save the feature bitmap to avoid cpuid lookup for every PV
129-
* operation
130-
*/
131-
if (best)
132-
vcpu->arch.pv_cpuid.features = best->eax;
133-
134141
if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT)) {
135142
best = kvm_find_cpuid_entry(vcpu, 0x1, 0);
136143
if (best)
@@ -162,6 +169,8 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
162169
vcpu->arch.guest_supported_xcr0 =
163170
(best->eax | ((u64)best->edx << 32)) & supported_xcr0;
164171

172+
kvm_update_pv_runtime(vcpu);
173+
165174
vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
166175
kvm_mmu_reset_context(vcpu);
167176

arch/x86/kvm/cpuid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern u32 kvm_cpu_caps[NCAPINTS] __read_mostly;
1111
void kvm_set_cpu_caps(void);
1212

1313
void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu);
14+
void kvm_update_pv_runtime(struct kvm_vcpu *vcpu);
1415
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
1516
u32 function, u32 index);
1617
int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,

arch/x86/kvm/mmu/mmu.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,14 @@ static int pte_list_add(struct kvm_vcpu *vcpu, u64 *spte,
856856
} else {
857857
rmap_printk("pte_list_add: %p %llx many->many\n", spte, *spte);
858858
desc = (struct pte_list_desc *)(rmap_head->val & ~1ul);
859-
while (desc->sptes[PTE_LIST_EXT-1] && desc->more) {
860-
desc = desc->more;
859+
while (desc->sptes[PTE_LIST_EXT-1]) {
861860
count += PTE_LIST_EXT;
862-
}
863-
if (desc->sptes[PTE_LIST_EXT-1]) {
864-
desc->more = mmu_alloc_pte_list_desc(vcpu);
861+
862+
if (!desc->more) {
863+
desc->more = mmu_alloc_pte_list_desc(vcpu);
864+
desc = desc->more;
865+
break;
866+
}
865867
desc = desc->more;
866868
}
867869
for (i = 0; desc->sptes[i]; ++i)

0 commit comments

Comments
 (0)