Skip to content

Commit 86d6a62

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 the handling of the phycal timer offset when FEAT_ECV and CNTPOFF_EL2 are implemented - Restore the functionnality of Permission Indirection that was broken by the Fine Grained Trapping rework - Cleanup some PMU event sharing code MIPS: - Fix W=1 build s390: - One small fix for gisa to avoid stalls x86: - Truncate writes to PMU counters to the counter's width to avoid spurious overflows when emulating counter events in software - Set the LVTPC entry mask bit when handling a PMI (to match Intel-defined architectural behavior) - Treat KVM_REQ_PMI as a wake event instead of queueing host IRQ work to kick the guest out of emulated halt - Fix for loading XSAVE state from an old kernel into a new one - Fixes for AMD AVIC selftests: - Play nice with %llx when formatting guest printf and assert statements - Clean up stale test metadata - Zero-initialize structures in memslot perf test to workaround a suspected 'may be used uninitialized' false positives from GCC" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (21 commits) KVM: arm64: timers: Correctly handle TGE flip with CNTPOFF_EL2 KVM: arm64: POR{E0}_EL1 do not need trap handlers KVM: arm64: Add nPIR{E0}_EL1 to HFG traps KVM: MIPS: fix -Wunused-but-set-variable warning KVM: arm64: pmu: Drop redundant check for non-NULL kvm_pmu_events KVM: SVM: Fix build error when using -Werror=unused-but-set-variable x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested() x86: KVM: SVM: add support for Invalid IPI Vector interception x86: KVM: SVM: always update the x2avic msr interception KVM: selftests: Force load all supported XSAVE state in state test KVM: selftests: Load XSAVE state into untouched vCPU during state test KVM: selftests: Touch relevant XSAVE state in guest for state test KVM: x86: Constrain guest-supported xfeatures only at KVM_GET_XSAVE{2} x86/fpu: Allow caller to constrain xfeatures when copying to uabi buffer KVM: selftests: Zero-initialize entire test_result in memslot perf test KVM: selftests: Remove obsolete and incorrect test case metadata KVM: selftests: Treat %llx like %lx when formatting guest printf KVM: x86/pmu: Synthesize at most one PMI per VM-exit KVM: x86: Mask LVTPC when handling a PMI KVM: x86/pmu: Truncate counter value to allowed width on write ...
2 parents 5872080 + 2b3f232 commit 86d6a62

36 files changed

+276
-120
lines changed

arch/arm64/include/asm/kvm_arm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@
344344
*/
345345
#define __HFGRTR_EL2_RES0 (GENMASK(63, 56) | GENMASK(53, 51))
346346
#define __HFGRTR_EL2_MASK GENMASK(49, 0)
347-
#define __HFGRTR_EL2_nMASK (GENMASK(55, 54) | BIT(50))
347+
#define __HFGRTR_EL2_nMASK (GENMASK(58, 57) | GENMASK(55, 54) | BIT(50))
348348

349349
#define __HFGWTR_EL2_RES0 (GENMASK(63, 56) | GENMASK(53, 51) | \
350350
BIT(46) | BIT(42) | BIT(40) | BIT(28) | \
351351
GENMASK(26, 25) | BIT(21) | BIT(18) | \
352352
GENMASK(15, 14) | GENMASK(10, 9) | BIT(2))
353353
#define __HFGWTR_EL2_MASK GENMASK(49, 0)
354-
#define __HFGWTR_EL2_nMASK (GENMASK(55, 54) | BIT(50))
354+
#define __HFGWTR_EL2_nMASK (GENMASK(58, 57) | GENMASK(55, 54) | BIT(50))
355355

356356
#define __HFGITR_EL2_RES0 GENMASK(63, 57)
357357
#define __HFGITR_EL2_MASK GENMASK(54, 0)

arch/arm64/kvm/arch_timer.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ static struct irq_ops arch_timer_irq_ops = {
5555
.get_input_level = kvm_arch_timer_get_input_level,
5656
};
5757

58-
static bool has_cntpoff(void)
59-
{
60-
return (has_vhe() && cpus_have_final_cap(ARM64_HAS_ECV_CNTPOFF));
61-
}
62-
6358
static int nr_timers(struct kvm_vcpu *vcpu)
6459
{
6560
if (!vcpu_has_nv(vcpu))
@@ -180,7 +175,7 @@ u64 kvm_phys_timer_read(void)
180175
return timecounter->cc->read(timecounter->cc);
181176
}
182177

183-
static void get_timer_map(struct kvm_vcpu *vcpu, struct timer_map *map)
178+
void get_timer_map(struct kvm_vcpu *vcpu, struct timer_map *map)
184179
{
185180
if (vcpu_has_nv(vcpu)) {
186181
if (is_hyp_ctxt(vcpu)) {
@@ -548,8 +543,7 @@ static void timer_save_state(struct arch_timer_context *ctx)
548543
timer_set_ctl(ctx, read_sysreg_el0(SYS_CNTP_CTL));
549544
cval = read_sysreg_el0(SYS_CNTP_CVAL);
550545

551-
if (!has_cntpoff())
552-
cval -= timer_get_offset(ctx);
546+
cval -= timer_get_offset(ctx);
553547

554548
timer_set_cval(ctx, cval);
555549

@@ -636,8 +630,7 @@ static void timer_restore_state(struct arch_timer_context *ctx)
636630
cval = timer_get_cval(ctx);
637631
offset = timer_get_offset(ctx);
638632
set_cntpoff(offset);
639-
if (!has_cntpoff())
640-
cval += offset;
633+
cval += offset;
641634
write_sysreg_el0(cval, SYS_CNTP_CVAL);
642635
isb();
643636
write_sysreg_el0(timer_get_ctl(ctx), SYS_CNTP_CTL);

arch/arm64/kvm/emulate-nested.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ enum fg_filter_id {
977977

978978
static const struct encoding_to_trap_config encoding_to_fgt[] __initconst = {
979979
/* HFGRTR_EL2, HFGWTR_EL2 */
980+
SR_FGT(SYS_PIR_EL1, HFGxTR, nPIR_EL1, 0),
981+
SR_FGT(SYS_PIRE0_EL1, HFGxTR, nPIRE0_EL1, 0),
980982
SR_FGT(SYS_TPIDR2_EL0, HFGxTR, nTPIDR2_EL0, 0),
981983
SR_FGT(SYS_SMPRI_EL1, HFGxTR, nSMPRI_EL1, 0),
982984
SR_FGT(SYS_ACCDATA_EL1, HFGxTR, nACCDATA_EL1, 0),

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
3939

4040
___activate_traps(vcpu);
4141

42+
if (has_cntpoff()) {
43+
struct timer_map map;
44+
45+
get_timer_map(vcpu, &map);
46+
47+
/*
48+
* We're entrering the guest. Reload the correct
49+
* values from memory now that TGE is clear.
50+
*/
51+
if (map.direct_ptimer == vcpu_ptimer(vcpu))
52+
val = __vcpu_sys_reg(vcpu, CNTP_CVAL_EL0);
53+
if (map.direct_ptimer == vcpu_hptimer(vcpu))
54+
val = __vcpu_sys_reg(vcpu, CNTHP_CVAL_EL2);
55+
56+
if (map.direct_ptimer) {
57+
write_sysreg_el0(val, SYS_CNTP_CVAL);
58+
isb();
59+
}
60+
}
61+
4262
val = read_sysreg(cpacr_el1);
4363
val |= CPACR_ELx_TTA;
4464
val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN |
@@ -77,6 +97,30 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
7797

7898
write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2);
7999

100+
if (has_cntpoff()) {
101+
struct timer_map map;
102+
u64 val, offset;
103+
104+
get_timer_map(vcpu, &map);
105+
106+
/*
107+
* We're exiting the guest. Save the latest CVAL value
108+
* to memory and apply the offset now that TGE is set.
109+
*/
110+
val = read_sysreg_el0(SYS_CNTP_CVAL);
111+
if (map.direct_ptimer == vcpu_ptimer(vcpu))
112+
__vcpu_sys_reg(vcpu, CNTP_CVAL_EL0) = val;
113+
if (map.direct_ptimer == vcpu_hptimer(vcpu))
114+
__vcpu_sys_reg(vcpu, CNTHP_CVAL_EL2) = val;
115+
116+
offset = read_sysreg_s(SYS_CNTPOFF_EL2);
117+
118+
if (map.direct_ptimer && offset) {
119+
write_sysreg_el0(val + offset, SYS_CNTP_CVAL);
120+
isb();
121+
}
122+
}
123+
80124
/*
81125
* ARM errata 1165522 and 1530923 require the actual execution of the
82126
* above before we can switch to the EL2/EL0 translation regime used by

arch/arm64/kvm/pmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr)
3939
{
4040
struct kvm_pmu_events *pmu = kvm_get_pmu_events();
4141

42-
if (!kvm_arm_support_pmu_v3() || !pmu || !kvm_pmu_switch_needed(attr))
42+
if (!kvm_arm_support_pmu_v3() || !kvm_pmu_switch_needed(attr))
4343
return;
4444

4545
if (!attr->exclude_host)
@@ -55,7 +55,7 @@ void kvm_clr_pmu_events(u32 clr)
5555
{
5656
struct kvm_pmu_events *pmu = kvm_get_pmu_events();
5757

58-
if (!kvm_arm_support_pmu_v3() || !pmu)
58+
if (!kvm_arm_support_pmu_v3())
5959
return;
6060

6161
pmu->events_host &= ~clr;

arch/arm64/kvm/sys_regs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,8 +2122,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
21222122
{ SYS_DESC(SYS_PMMIR_EL1), trap_raz_wi },
21232123

21242124
{ SYS_DESC(SYS_MAIR_EL1), access_vm_reg, reset_unknown, MAIR_EL1 },
2125-
{ SYS_DESC(SYS_PIRE0_EL1), access_vm_reg, reset_unknown, PIRE0_EL1 },
2126-
{ SYS_DESC(SYS_PIR_EL1), access_vm_reg, reset_unknown, PIR_EL1 },
2125+
{ SYS_DESC(SYS_PIRE0_EL1), NULL, reset_unknown, PIRE0_EL1 },
2126+
{ SYS_DESC(SYS_PIR_EL1), NULL, reset_unknown, PIR_EL1 },
21272127
{ SYS_DESC(SYS_AMAIR_EL1), access_vm_reg, reset_amair_el1, AMAIR_EL1 },
21282128

21292129
{ SYS_DESC(SYS_LORSA_EL1), trap_loregion },

arch/mips/kvm/mmu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa,
592592
gfn_t gfn = gpa >> PAGE_SHIFT;
593593
int srcu_idx, err;
594594
kvm_pfn_t pfn;
595-
pte_t *ptep, entry, old_pte;
595+
pte_t *ptep, entry;
596596
bool writeable;
597597
unsigned long prot_bits;
598598
unsigned long mmu_seq;
@@ -664,7 +664,6 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa,
664664
entry = pfn_pte(pfn, __pgprot(prot_bits));
665665

666666
/* Write the PTE */
667-
old_pte = *ptep;
668667
set_pte(ptep, entry);
669668

670669
err = 0;

arch/s390/kvm/interrupt.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ static inline u8 gisa_get_ipm_or_restore_iam(struct kvm_s390_gisa_interrupt *gi)
303303
return 0;
304304
}
305305

306-
static inline int gisa_in_alert_list(struct kvm_s390_gisa *gisa)
307-
{
308-
return READ_ONCE(gisa->next_alert) != (u32)virt_to_phys(gisa);
309-
}
310-
311306
static inline void gisa_set_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
312307
{
313308
set_bit_inv(IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
@@ -3216,11 +3211,12 @@ void kvm_s390_gisa_destroy(struct kvm *kvm)
32163211

32173212
if (!gi->origin)
32183213
return;
3219-
if (gi->alert.mask)
3220-
KVM_EVENT(3, "vm 0x%pK has unexpected iam 0x%02x",
3221-
kvm, gi->alert.mask);
3222-
while (gisa_in_alert_list(gi->origin))
3223-
cpu_relax();
3214+
WARN(gi->alert.mask != 0x00,
3215+
"unexpected non zero alert.mask 0x%02x",
3216+
gi->alert.mask);
3217+
gi->alert.mask = 0x00;
3218+
if (gisa_set_iam(gi->origin, gi->alert.mask))
3219+
process_gib_alert_list();
32243220
hrtimer_cancel(&gi->timer);
32253221
gi->origin = NULL;
32263222
VM_EVENT(kvm, 3, "gisa 0x%pK destroyed", gisa);

arch/x86/include/asm/fpu/api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ static inline void fpu_update_guest_xfd(struct fpu_guest *guest_fpu, u64 xfd) {
157157
static inline void fpu_sync_guest_vmexit_xfd_state(void) { }
158158
#endif
159159

160-
extern void fpu_copy_guest_fpstate_to_uabi(struct fpu_guest *gfpu, void *buf, unsigned int size, u32 pkru);
160+
extern void fpu_copy_guest_fpstate_to_uabi(struct fpu_guest *gfpu, void *buf,
161+
unsigned int size, u64 xfeatures, u32 pkru);
161162
extern int fpu_copy_uabi_to_guest_fpstate(struct fpu_guest *gfpu, const void *buf, u64 xcr0, u32 *vpkru);
162163

163164
static inline void fpstate_set_confidential(struct fpu_guest *gfpu)

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ struct kvm_pmu {
528528
u64 raw_event_mask;
529529
struct kvm_pmc gp_counters[KVM_INTEL_PMC_MAX_GENERIC];
530530
struct kvm_pmc fixed_counters[KVM_PMC_MAX_FIXED];
531-
struct irq_work irq_work;
532531

533532
/*
534533
* Overlay the bitmap with a 64-bit atomic so that all bits can be

0 commit comments

Comments
 (0)