Skip to content

Commit e28e909

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull second batch of KVM updates from Radim Krčmář: "General: - move kvm_stat tool from QEMU repo into tools/kvm/kvm_stat (kvm_stat had nothing to do with QEMU in the first place -- the tool only interprets debugfs) - expose per-vm statistics in debugfs and support them in kvm_stat (KVM always collected per-vm statistics, but they were summarised into global statistics) x86: - fix dynamic APICv (VMX was improperly configured and a guest could access host's APIC MSRs, CVE-2016-4440) - minor fixes ARM changes from Christoffer Dall: - new vgic reimplementation of our horribly broken legacy vgic implementation. The two implementations will live side-by-side (with the new being the configured default) for one kernel release and then we'll remove the legacy one. - fix for a non-critical issue with virtual abort injection to guests" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (70 commits) tools: kvm_stat: Add comments tools: kvm_stat: Introduce pid monitoring KVM: Create debugfs dir and stat files for each VM MAINTAINERS: Add kvm tools tools: kvm_stat: Powerpc related fixes tools: Add kvm_stat man page tools: Add kvm_stat vm monitor script kvm:vmx: more complete state update on APICv on/off KVM: SVM: Add more SVM_EXIT_REASONS KVM: Unify traced vector format svm: bitwise vs logical op typo KVM: arm/arm64: vgic-new: Synchronize changes to active state KVM: arm/arm64: vgic-new: enable build KVM: arm/arm64: vgic-new: implement mapped IRQ handling KVM: arm/arm64: vgic-new: Wire up irqfd injection KVM: arm/arm64: vgic-new: Add vgic_v2/v3_enable KVM: arm/arm64: vgic-new: vgic_init: implement map_resources KVM: arm/arm64: vgic-new: vgic_init: implement vgic_init KVM: arm/arm64: vgic-new: vgic_init: implement vgic_create KVM: arm/arm64: vgic-new: vgic_init: implement kvm_vgic_hyp_init ...
2 parents dc03c0f + fabc712 commit e28e909

45 files changed

Lines changed: 5901 additions & 193 deletions

Some content is hidden

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

‎MAINTAINERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6491,6 +6491,7 @@ F: arch/*/include/asm/kvm*
64916491
F: include/linux/kvm*
64926492
F: include/uapi/linux/kvm*
64936493
F: virt/kvm/
6494+
F: tools/kvm/
64946495

64956496
KERNEL VIRTUAL MACHINE (KVM) FOR AMD-V
64966497
M: Joerg Roedel <joro@8bytes.org>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
#define KVM_MAX_VCPUS VGIC_V2_MAX_CPUS
4343

44+
#define KVM_REQ_VCPU_EXIT 8
45+
4446
u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
4547
int __attribute_const__ kvm_target_cpu(void);
4648
int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
@@ -226,6 +228,10 @@ static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
226228

227229
struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
228230
struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
231+
void kvm_arm_halt_guest(struct kvm *kvm);
232+
void kvm_arm_resume_guest(struct kvm *kvm);
233+
void kvm_arm_halt_vcpu(struct kvm_vcpu *vcpu);
234+
void kvm_arm_resume_vcpu(struct kvm_vcpu *vcpu);
229235

230236
int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices);
231237
unsigned long kvm_arm_num_coproc_regs(struct kvm_vcpu *vcpu);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct kvm_decode {
2828
bool sign_extend;
2929
};
3030

31+
void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
32+
unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
33+
3134
int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
3235
int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
3336
phys_addr_t fault_ipa);

‎arch/arm/kvm/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ config KVM_ARM_HOST
4646
---help---
4747
Provides host support for ARM processors.
4848

49+
config KVM_NEW_VGIC
50+
bool "New VGIC implementation"
51+
depends on KVM
52+
default y
53+
---help---
54+
uses the new VGIC implementation
55+
4956
source drivers/vhost/Kconfig
5057

5158
endif # VIRTUALIZATION

‎arch/arm/kvm/Makefile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ obj-$(CONFIG_KVM_ARM_HOST) += hyp/
2121
obj-y += kvm-arm.o init.o interrupts.o
2222
obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o
2323
obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o
24+
25+
ifeq ($(CONFIG_KVM_NEW_VGIC),y)
26+
obj-y += $(KVM)/arm/vgic/vgic.o
27+
obj-y += $(KVM)/arm/vgic/vgic-init.o
28+
obj-y += $(KVM)/arm/vgic/vgic-irqfd.o
29+
obj-y += $(KVM)/arm/vgic/vgic-v2.o
30+
obj-y += $(KVM)/arm/vgic/vgic-mmio.o
31+
obj-y += $(KVM)/arm/vgic/vgic-mmio-v2.o
32+
obj-y += $(KVM)/arm/vgic/vgic-kvm-device.o
33+
else
2434
obj-y += $(KVM)/arm/vgic.o
2535
obj-y += $(KVM)/arm/vgic-v2.o
2636
obj-y += $(KVM)/arm/vgic-v2-emul.o
37+
endif
2738
obj-y += $(KVM)/arm/arch_timer.o

‎arch/arm/kvm/arm.c‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static void update_vttbr(struct kvm *kvm)
455455
static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
456456
{
457457
struct kvm *kvm = vcpu->kvm;
458-
int ret;
458+
int ret = 0;
459459

460460
if (likely(vcpu->arch.has_run_once))
461461
return 0;
@@ -478,40 +478,47 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
478478
* interrupts from the virtual timer with a userspace gic.
479479
*/
480480
if (irqchip_in_kernel(kvm) && vgic_initialized(kvm))
481-
kvm_timer_enable(kvm);
481+
ret = kvm_timer_enable(vcpu);
482482

483-
return 0;
483+
return ret;
484484
}
485485

486486
bool kvm_arch_intc_initialized(struct kvm *kvm)
487487
{
488488
return vgic_initialized(kvm);
489489
}
490490

491-
static void kvm_arm_halt_guest(struct kvm *kvm) __maybe_unused;
492-
static void kvm_arm_resume_guest(struct kvm *kvm) __maybe_unused;
493-
494-
static void kvm_arm_halt_guest(struct kvm *kvm)
491+
void kvm_arm_halt_guest(struct kvm *kvm)
495492
{
496493
int i;
497494
struct kvm_vcpu *vcpu;
498495

499496
kvm_for_each_vcpu(i, vcpu, kvm)
500497
vcpu->arch.pause = true;
501-
force_vm_exit(cpu_all_mask);
498+
kvm_make_all_cpus_request(kvm, KVM_REQ_VCPU_EXIT);
499+
}
500+
501+
void kvm_arm_halt_vcpu(struct kvm_vcpu *vcpu)
502+
{
503+
vcpu->arch.pause = true;
504+
kvm_vcpu_kick(vcpu);
502505
}
503506

504-
static void kvm_arm_resume_guest(struct kvm *kvm)
507+
void kvm_arm_resume_vcpu(struct kvm_vcpu *vcpu)
508+
{
509+
struct swait_queue_head *wq = kvm_arch_vcpu_wq(vcpu);
510+
511+
vcpu->arch.pause = false;
512+
swake_up(wq);
513+
}
514+
515+
void kvm_arm_resume_guest(struct kvm *kvm)
505516
{
506517
int i;
507518
struct kvm_vcpu *vcpu;
508519

509-
kvm_for_each_vcpu(i, vcpu, kvm) {
510-
struct swait_queue_head *wq = kvm_arch_vcpu_wq(vcpu);
511-
512-
vcpu->arch.pause = false;
513-
swake_up(wq);
514-
}
520+
kvm_for_each_vcpu(i, vcpu, kvm)
521+
kvm_arm_resume_vcpu(vcpu);
515522
}
516523

517524
static void vcpu_sleep(struct kvm_vcpu *vcpu)

‎arch/arm/kvm/mmio.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "trace.h"
2525

26-
static void mmio_write_buf(char *buf, unsigned int len, unsigned long data)
26+
void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data)
2727
{
2828
void *datap = NULL;
2929
union {
@@ -55,7 +55,7 @@ static void mmio_write_buf(char *buf, unsigned int len, unsigned long data)
5555
memcpy(buf, datap, len);
5656
}
5757

58-
static unsigned long mmio_read_buf(char *buf, unsigned int len)
58+
unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len)
5959
{
6060
unsigned long data = 0;
6161
union {
@@ -66,7 +66,7 @@ static unsigned long mmio_read_buf(char *buf, unsigned int len)
6666

6767
switch (len) {
6868
case 1:
69-
data = buf[0];
69+
data = *(u8 *)buf;
7070
break;
7171
case 2:
7272
memcpy(&tmp.hword, buf, len);
@@ -87,11 +87,10 @@ static unsigned long mmio_read_buf(char *buf, unsigned int len)
8787

8888
/**
8989
* kvm_handle_mmio_return -- Handle MMIO loads after user space emulation
90+
* or in-kernel IO emulation
91+
*
9092
* @vcpu: The VCPU pointer
9193
* @run: The VCPU run struct containing the mmio data
92-
*
93-
* This should only be called after returning from userspace for MMIO load
94-
* emulation.
9594
*/
9695
int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
9796
{
@@ -104,7 +103,7 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
104103
if (len > sizeof(unsigned long))
105104
return -EINVAL;
106105

107-
data = mmio_read_buf(run->mmio.data, len);
106+
data = kvm_mmio_read_buf(run->mmio.data, len);
108107

109108
if (vcpu->arch.mmio_decode.sign_extend &&
110109
len < sizeof(unsigned long)) {
@@ -190,7 +189,7 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
190189
len);
191190

192191
trace_kvm_mmio(KVM_TRACE_MMIO_WRITE, len, fault_ipa, data);
193-
mmio_write_buf(data_buf, len, data);
192+
kvm_mmio_write_buf(data_buf, len, data);
194193

195194
ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, fault_ipa, len,
196195
data_buf);
@@ -206,18 +205,19 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
206205
run->mmio.is_write = is_write;
207206
run->mmio.phys_addr = fault_ipa;
208207
run->mmio.len = len;
209-
if (is_write)
210-
memcpy(run->mmio.data, data_buf, len);
211208

212209
if (!ret) {
213210
/* We handled the access successfully in the kernel. */
211+
if (!is_write)
212+
memcpy(run->mmio.data, data_buf, len);
214213
vcpu->stat.mmio_exit_kernel++;
215214
kvm_handle_mmio_return(vcpu, run);
216215
return 1;
217-
} else {
218-
vcpu->stat.mmio_exit_user++;
219216
}
220217

218+
if (is_write)
219+
memcpy(run->mmio.data, data_buf, len);
220+
vcpu->stat.mmio_exit_user++;
221221
run->exit_reason = KVM_EXIT_MMIO;
222222
return 0;
223223
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
#define KVM_VCPU_MAX_FEATURES 4
4545

46+
#define KVM_REQ_VCPU_EXIT 8
47+
4648
int __attribute_const__ kvm_target_cpu(void);
4749
int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
4850
int kvm_arch_dev_ioctl_check_extension(long ext);
@@ -327,6 +329,10 @@ static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
327329

328330
struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
329331
struct kvm_vcpu * __percpu *kvm_get_running_vcpus(void);
332+
void kvm_arm_halt_guest(struct kvm *kvm);
333+
void kvm_arm_resume_guest(struct kvm *kvm);
334+
void kvm_arm_halt_vcpu(struct kvm_vcpu *vcpu);
335+
void kvm_arm_resume_vcpu(struct kvm_vcpu *vcpu);
330336

331337
u64 __kvm_call_hyp(void *hypfn, ...);
332338
#define kvm_call_hyp(f, ...) __kvm_call_hyp(kvm_ksym_ref(f), ##__VA_ARGS__)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ struct kvm_decode {
3030
bool sign_extend;
3131
};
3232

33+
void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data);
34+
unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);
35+
3336
int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
3437
int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
3538
phys_addr_t fault_ipa);

‎arch/arm64/kvm/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ config KVM_ARM_PMU
5454
Adds support for a virtual Performance Monitoring Unit (PMU) in
5555
virtual machines.
5656

57+
config KVM_NEW_VGIC
58+
bool "New VGIC implementation"
59+
depends on KVM
60+
default y
61+
---help---
62+
uses the new VGIC implementation
63+
5764
source drivers/vhost/Kconfig
5865

5966
endif # VIRTUALIZATION

0 commit comments

Comments
 (0)