Skip to content

Commit 974aa56

Browse files
committed
Merge tag 'kvm-4.15-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM updates from Radim Krčmář: "First batch of KVM changes for 4.15 Common: - Python 3 support in kvm_stat - Accounting of slabs to kmemcg ARM: - Optimized arch timer handling for KVM/ARM - Improvements to the VGIC ITS code and introduction of an ITS reset ioctl - Unification of the 32-bit fault injection logic - More exact external abort matching logic PPC: - Support for running hashed page table (HPT) MMU mode on a host that is using the radix MMU mode; single threaded mode on POWER 9 is added as a pre-requisite - Resolution of merge conflicts with the last second 4.14 HPT fixes - Fixes and cleanups s390: - Some initial preparation patches for exitless interrupts and crypto - New capability for AIS migration - Fixes x86: - Improved emulation of LAPIC timer mode changes, MCi_STATUS MSRs, and after-reset state - Refined dependencies for VMX features - Fixes for nested SMI injection - A lot of cleanups" * tag 'kvm-4.15-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (89 commits) KVM: s390: provide a capability for AIS state migration KVM: s390: clear_io_irq() requests are not expected for adapter interrupts KVM: s390: abstract conversion between isc and enum irq_types KVM: s390: vsie: use common code functions for pinning KVM: s390: SIE considerations for AP Queue virtualization KVM: s390: document memory ordering for kvm_s390_vcpu_wakeup KVM: PPC: Book3S HV: Cosmetic post-merge cleanups KVM: arm/arm64: fix the incompatible matching for external abort KVM: arm/arm64: Unify 32bit fault injection KVM: arm/arm64: vgic-its: Implement KVM_DEV_ARM_ITS_CTRL_RESET KVM: arm/arm64: Document KVM_DEV_ARM_ITS_CTRL_RESET KVM: arm/arm64: vgic-its: Free caches when GITS_BASER Valid bit is cleared KVM: arm/arm64: vgic-its: New helper functions to free the caches KVM: arm/arm64: vgic-its: Remove kvm_its_unmap_device arm/arm64: KVM: Load the timer state when enabling the timer KVM: arm/arm64: Rework kvm_timer_should_fire KVM: arm/arm64: Get rid of kvm_timer_flush_hwstate KVM: arm/arm64: Avoid phys timer emulation in vcpu entry/exit KVM: arm/arm64: Move phys_timer_emulate function KVM: arm/arm64: Use kvm_arm_timer_set/get_reg for guest register traps ...
2 parents 441692a + a6014f1 commit 974aa56

70 files changed

Lines changed: 2264 additions & 1270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,14 @@ guest physical address space and must not conflict with any memory slot
11241124
or any mmio address. The guest may malfunction if it accesses this memory
11251125
region.
11261126

1127+
Setting the address to 0 will result in resetting the address to its default
1128+
(0xfffbc000).
1129+
11271130
This ioctl is required on Intel-based hosts. This is needed on Intel hardware
11281131
because of a quirk in the virtualization implementation (see the internals
11291132
documentation when it pops into existence).
11301133

1134+
Fails if any VCPU has already been created.
11311135

11321136
4.41 KVM_SET_BOOT_CPU_ID
11331137

@@ -4347,3 +4351,12 @@ This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
43474351
value is used to denote the target vcpu for a SynIC interrupt. For
43484352
compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this
43494353
capability is absent, userspace can still query this msr's value.
4354+
4355+
8.13 KVM_CAP_S390_AIS_MIGRATION
4356+
4357+
Architectures: s390
4358+
Parameters: none
4359+
4360+
This capability indicates if the flic device will be able to get/set the
4361+
AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
4362+
to discover this without having to create a flic device.

‎Documentation/virtual/kvm/devices/arm-vgic-its.txt‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Groups:
3333
request the initialization of the ITS, no additional parameter in
3434
kvm_device_attr.addr.
3535

36+
KVM_DEV_ARM_ITS_CTRL_RESET
37+
reset the ITS, no additional parameter in kvm_device_attr.addr.
38+
See "ITS Reset State" section.
39+
3640
KVM_DEV_ARM_ITS_SAVE_TABLES
3741
save the ITS table data into guest RAM, at the location provisioned
3842
by the guest in corresponding registers/table entries.
@@ -157,3 +161,19 @@ Then vcpus can be started.
157161
- pINTID is the physical LPI ID; if zero, it means the entry is not valid
158162
and other fields are not meaningful.
159163
- ICID is the collection ID
164+
165+
ITS Reset State:
166+
----------------
167+
168+
RESET returns the ITS to the same state that it was when first created and
169+
initialized. When the RESET command returns, the following things are
170+
guaranteed:
171+
172+
- The ITS is not enabled and quiescent
173+
GITS_CTLR.Enabled = 0 .Quiescent=1
174+
- There is no internally cached state
175+
- No collection or device table are used
176+
GITS_BASER<n>.Valid = 0
177+
- GITS_CBASER = 0, GITS_CREADR = 0, GITS_CWRITER = 0
178+
- The ABI version is unchanged and remains the one set when the ITS
179+
device was first created.

‎Documentation/virtual/kvm/devices/s390_flic.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,13 @@ struct kvm_s390_ais_all {
151151
to an ISC (MSB0 bit 0 to ISC 0 and so on). The combination of simm bit and
152152
nimm bit presents AIS mode for a ISC.
153153

154+
KVM_DEV_FLIC_AISM_ALL is indicated by KVM_CAP_S390_AIS_MIGRATION.
155+
154156
Note: The KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR device ioctls executed on
155157
FLIC with an unknown group or attribute gives the error code EINVAL (instead of
156158
ENXIO, as specified in the API documentation). It is not possible to conclude
157159
that a FLIC operation is unavailable based on the error code resulting from a
158160
usage attempt.
161+
162+
Note: The KVM_DEV_FLIC_CLEAR_IO_IRQ ioctl will return EINVAL in case a zero
163+
schid is specified.

‎arch/arm/include/asm/kvm_asm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
6868
extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
6969
extern void __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu);
7070

71+
extern void __kvm_timer_set_cntvoff(u32 cntvoff_low, u32 cntvoff_high);
72+
7173
extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu);
7274

7375
extern void __init_stage2_translation(void);

‎arch/arm/include/asm/kvm_emulate.h‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@
2525
#include <asm/kvm_arm.h>
2626
#include <asm/cputype.h>
2727

28+
/* arm64 compatibility macros */
29+
#define COMPAT_PSR_MODE_ABT ABT_MODE
30+
#define COMPAT_PSR_MODE_UND UND_MODE
31+
#define COMPAT_PSR_T_BIT PSR_T_BIT
32+
#define COMPAT_PSR_I_BIT PSR_I_BIT
33+
#define COMPAT_PSR_A_BIT PSR_A_BIT
34+
#define COMPAT_PSR_E_BIT PSR_E_BIT
35+
#define COMPAT_PSR_IT_MASK PSR_IT_MASK
36+
2837
unsigned long *vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num);
38+
39+
static inline unsigned long *vcpu_reg32(struct kvm_vcpu *vcpu, u8 reg_num)
40+
{
41+
return vcpu_reg(vcpu, reg_num);
42+
}
43+
2944
unsigned long *vcpu_spsr(struct kvm_vcpu *vcpu);
3045

3146
static inline unsigned long vcpu_get_reg(struct kvm_vcpu *vcpu,
@@ -42,10 +57,25 @@ static inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
4257

4358
bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
4459
void kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr);
45-
void kvm_inject_undefined(struct kvm_vcpu *vcpu);
60+
void kvm_inject_undef32(struct kvm_vcpu *vcpu);
61+
void kvm_inject_dabt32(struct kvm_vcpu *vcpu, unsigned long addr);
62+
void kvm_inject_pabt32(struct kvm_vcpu *vcpu, unsigned long addr);
4663
void kvm_inject_vabt(struct kvm_vcpu *vcpu);
47-
void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
48-
void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
64+
65+
static inline void kvm_inject_undefined(struct kvm_vcpu *vcpu)
66+
{
67+
kvm_inject_undef32(vcpu);
68+
}
69+
70+
static inline void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr)
71+
{
72+
kvm_inject_dabt32(vcpu, addr);
73+
}
74+
75+
static inline void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr)
76+
{
77+
kvm_inject_pabt32(vcpu, addr);
78+
}
4979

5080
static inline bool kvm_condition_valid(const struct kvm_vcpu *vcpu)
5181
{
@@ -203,7 +233,7 @@ static inline u8 kvm_vcpu_trap_get_fault_type(struct kvm_vcpu *vcpu)
203233

204234
static inline bool kvm_vcpu_dabt_isextabt(struct kvm_vcpu *vcpu)
205235
{
206-
switch (kvm_vcpu_trap_get_fault_type(vcpu)) {
236+
switch (kvm_vcpu_trap_get_fault(vcpu)) {
207237
case FSC_SEA:
208238
case FSC_SEA_TTW0:
209239
case FSC_SEA_TTW1:

‎arch/arm/include/asm/kvm_hyp.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
#define cntvoff_el2 CNTVOFF
9999
#define cnthctl_el2 CNTHCTL
100100

101-
void __timer_save_state(struct kvm_vcpu *vcpu);
102-
void __timer_restore_state(struct kvm_vcpu *vcpu);
101+
void __timer_enable_traps(struct kvm_vcpu *vcpu);
102+
void __timer_disable_traps(struct kvm_vcpu *vcpu);
103103

104104
void __vgic_v2_save_state(struct kvm_vcpu *vcpu);
105105
void __vgic_v2_restore_state(struct kvm_vcpu *vcpu);

‎arch/arm/include/uapi/asm/kvm.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ struct kvm_arch_memory_slot {
152152
(__ARM_CP15_REG(op1, 0, crm, 0) | KVM_REG_SIZE_U64)
153153
#define ARM_CP15_REG64(...) __ARM_CP15_REG64(__VA_ARGS__)
154154

155+
/* PL1 Physical Timer Registers */
156+
#define KVM_REG_ARM_PTIMER_CTL ARM_CP15_REG32(0, 14, 2, 1)
157+
#define KVM_REG_ARM_PTIMER_CNT ARM_CP15_REG64(0, 14)
158+
#define KVM_REG_ARM_PTIMER_CVAL ARM_CP15_REG64(2, 14)
159+
160+
/* Virtual Timer Registers */
155161
#define KVM_REG_ARM_TIMER_CTL ARM_CP15_REG32(0, 14, 3, 1)
156162
#define KVM_REG_ARM_TIMER_CNT ARM_CP15_REG64(1, 14)
157163
#define KVM_REG_ARM_TIMER_CVAL ARM_CP15_REG64(3, 14)
@@ -216,6 +222,7 @@ struct kvm_arch_memory_slot {
216222
#define KVM_DEV_ARM_ITS_SAVE_TABLES 1
217223
#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2
218224
#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3
225+
#define KVM_DEV_ARM_ITS_CTRL_RESET 4
219226

220227
/* KVM_IRQ_LINE irq field index values */
221228
#define KVM_ARM_IRQ_TYPE_SHIFT 24

‎arch/arm/kvm/emulate.c‎

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -165,143 +165,6 @@ unsigned long *vcpu_spsr(struct kvm_vcpu *vcpu)
165165
* Inject exceptions into the guest
166166
*/
167167

168-
static u32 exc_vector_base(struct kvm_vcpu *vcpu)
169-
{
170-
u32 sctlr = vcpu_cp15(vcpu, c1_SCTLR);
171-
u32 vbar = vcpu_cp15(vcpu, c12_VBAR);
172-
173-
if (sctlr & SCTLR_V)
174-
return 0xffff0000;
175-
else /* always have security exceptions */
176-
return vbar;
177-
}
178-
179-
/*
180-
* Switch to an exception mode, updating both CPSR and SPSR. Follow
181-
* the logic described in AArch32.EnterMode() from the ARMv8 ARM.
182-
*/
183-
static void kvm_update_psr(struct kvm_vcpu *vcpu, unsigned long mode)
184-
{
185-
unsigned long cpsr = *vcpu_cpsr(vcpu);
186-
u32 sctlr = vcpu_cp15(vcpu, c1_SCTLR);
187-
188-
*vcpu_cpsr(vcpu) = (cpsr & ~MODE_MASK) | mode;
189-
190-
switch (mode) {
191-
case FIQ_MODE:
192-
*vcpu_cpsr(vcpu) |= PSR_F_BIT;
193-
/* Fall through */
194-
case ABT_MODE:
195-
case IRQ_MODE:
196-
*vcpu_cpsr(vcpu) |= PSR_A_BIT;
197-
/* Fall through */
198-
default:
199-
*vcpu_cpsr(vcpu) |= PSR_I_BIT;
200-
}
201-
202-
*vcpu_cpsr(vcpu) &= ~(PSR_IT_MASK | PSR_J_BIT | PSR_E_BIT | PSR_T_BIT);
203-
204-
if (sctlr & SCTLR_TE)
205-
*vcpu_cpsr(vcpu) |= PSR_T_BIT;
206-
if (sctlr & SCTLR_EE)
207-
*vcpu_cpsr(vcpu) |= PSR_E_BIT;
208-
209-
/* Note: These now point to the mode banked copies */
210-
*vcpu_spsr(vcpu) = cpsr;
211-
}
212-
213-
/**
214-
* kvm_inject_undefined - inject an undefined exception into the guest
215-
* @vcpu: The VCPU to receive the undefined exception
216-
*
217-
* It is assumed that this code is called from the VCPU thread and that the
218-
* VCPU therefore is not currently executing guest code.
219-
*
220-
* Modelled after TakeUndefInstrException() pseudocode.
221-
*/
222-
void kvm_inject_undefined(struct kvm_vcpu *vcpu)
223-
{
224-
unsigned long cpsr = *vcpu_cpsr(vcpu);
225-
bool is_thumb = (cpsr & PSR_T_BIT);
226-
u32 vect_offset = 4;
227-
u32 return_offset = (is_thumb) ? 2 : 4;
228-
229-
kvm_update_psr(vcpu, UND_MODE);
230-
*vcpu_reg(vcpu, 14) = *vcpu_pc(vcpu) + return_offset;
231-
232-
/* Branch to exception vector */
233-
*vcpu_pc(vcpu) = exc_vector_base(vcpu) + vect_offset;
234-
}
235-
236-
/*
237-
* Modelled after TakeDataAbortException() and TakePrefetchAbortException
238-
* pseudocode.
239-
*/
240-
static void inject_abt(struct kvm_vcpu *vcpu, bool is_pabt, unsigned long addr)
241-
{
242-
u32 vect_offset;
243-
u32 return_offset = (is_pabt) ? 4 : 8;
244-
bool is_lpae;
245-
246-
kvm_update_psr(vcpu, ABT_MODE);
247-
*vcpu_reg(vcpu, 14) = *vcpu_pc(vcpu) + return_offset;
248-
249-
if (is_pabt)
250-
vect_offset = 12;
251-
else
252-
vect_offset = 16;
253-
254-
/* Branch to exception vector */
255-
*vcpu_pc(vcpu) = exc_vector_base(vcpu) + vect_offset;
256-
257-
if (is_pabt) {
258-
/* Set IFAR and IFSR */
259-
vcpu_cp15(vcpu, c6_IFAR) = addr;
260-
is_lpae = (vcpu_cp15(vcpu, c2_TTBCR) >> 31);
261-
/* Always give debug fault for now - should give guest a clue */
262-
if (is_lpae)
263-
vcpu_cp15(vcpu, c5_IFSR) = 1 << 9 | 0x22;
264-
else
265-
vcpu_cp15(vcpu, c5_IFSR) = 2;
266-
} else { /* !iabt */
267-
/* Set DFAR and DFSR */
268-
vcpu_cp15(vcpu, c6_DFAR) = addr;
269-
is_lpae = (vcpu_cp15(vcpu, c2_TTBCR) >> 31);
270-
/* Always give debug fault for now - should give guest a clue */
271-
if (is_lpae)
272-
vcpu_cp15(vcpu, c5_DFSR) = 1 << 9 | 0x22;
273-
else
274-
vcpu_cp15(vcpu, c5_DFSR) = 2;
275-
}
276-
277-
}
278-
279-
/**
280-
* kvm_inject_dabt - inject a data abort into the guest
281-
* @vcpu: The VCPU to receive the undefined exception
282-
* @addr: The address to report in the DFAR
283-
*
284-
* It is assumed that this code is called from the VCPU thread and that the
285-
* VCPU therefore is not currently executing guest code.
286-
*/
287-
void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr)
288-
{
289-
inject_abt(vcpu, false, addr);
290-
}
291-
292-
/**
293-
* kvm_inject_pabt - inject a prefetch abort into the guest
294-
* @vcpu: The VCPU to receive the undefined exception
295-
* @addr: The address to report in the DFAR
296-
*
297-
* It is assumed that this code is called from the VCPU thread and that the
298-
* VCPU therefore is not currently executing guest code.
299-
*/
300-
void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr)
301-
{
302-
inject_abt(vcpu, true, addr);
303-
}
304-
305168
/**
306169
* kvm_inject_vabt - inject an async abort / SError into the guest
307170
* @vcpu: The VCPU to receive the exception

‎arch/arm/kvm/hyp/switch.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
174174
__activate_vm(vcpu);
175175

176176
__vgic_restore_state(vcpu);
177-
__timer_restore_state(vcpu);
177+
__timer_enable_traps(vcpu);
178178

179179
__sysreg_restore_state(guest_ctxt);
180180
__banked_restore_state(guest_ctxt);
@@ -191,7 +191,8 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
191191

192192
__banked_save_state(guest_ctxt);
193193
__sysreg_save_state(guest_ctxt);
194-
__timer_save_state(vcpu);
194+
__timer_disable_traps(vcpu);
195+
195196
__vgic_save_state(vcpu);
196197

197198
__deactivate_traps(vcpu);
@@ -237,7 +238,7 @@ void __hyp_text __noreturn __hyp_panic(int cause)
237238

238239
vcpu = (struct kvm_vcpu *)read_sysreg(HTPIDR);
239240
host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
240-
__timer_save_state(vcpu);
241+
__timer_disable_traps(vcpu);
241242
__deactivate_traps(vcpu);
242243
__deactivate_vm(vcpu);
243244
__banked_restore_state(host_ctxt);

‎arch/arm64/include/asm/arch_timer.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct arch_timer_erratum_workaround {
5252
const char *desc;
5353
u32 (*read_cntp_tval_el0)(void);
5454
u32 (*read_cntv_tval_el0)(void);
55+
u64 (*read_cntpct_el0)(void);
5556
u64 (*read_cntvct_el0)(void);
5657
int (*set_next_event_phys)(unsigned long, struct clock_event_device *);
5758
int (*set_next_event_virt)(unsigned long, struct clock_event_device *);
@@ -149,11 +150,8 @@ static inline void arch_timer_set_cntkctl(u32 cntkctl)
149150

150151
static inline u64 arch_counter_get_cntpct(void)
151152
{
152-
/*
153-
* AArch64 kernel and user space mandate the use of CNTVCT.
154-
*/
155-
BUG();
156-
return 0;
153+
isb();
154+
return arch_timer_reg_read_stable(cntpct_el0);
157155
}
158156

159157
static inline u64 arch_counter_get_cntvct(void)

0 commit comments

Comments
 (0)