Skip to content

Commit 106e4da

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull KVM fixes from Radim Krčmář: "ARM updates from Marc Zyngier: - vgic updates: - Honour disabling the ITS - Don't deadlock when deactivating own interrupts via MMIO - Correctly expose the lact of IRQ/FIQ bypass on GICv3 - I/O virtualization: - Make KVM_CAP_NR_MEMSLOTS big enough for large guests with many PCIe devices - General bug fixes: - Gracefully handle exception generated with syndroms that the host doesn't understand - Properly invalidate TLBs on VHE systems x86: - improvements in emulation of VMCLEAR, VMX MSR bitmaps, and VCPU reset * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: nVMX: do not warn when MSR bitmap address is not backed KVM: arm64: Increase number of user memslots to 512 KVM: arm/arm64: Remove KVM_PRIVATE_MEM_SLOTS definition that are unused KVM: arm/arm64: Enable KVM_CAP_NR_MEMSLOTS on arm/arm64 KVM: Add documentation for KVM_CAP_NR_MEMSLOTS KVM: arm/arm64: VGIC: Fix command handling while ITS being disabled arm64: KVM: Survive unknown traps from guests arm: KVM: Survive unknown traps from guests KVM: arm/arm64: Let vcpu thread modify its own active state KVM: nVMX: reset nested_run_pending if the vCPU is going to be reset kvm: nVMX: VMCLEAR should not cause the vCPU to shut down KVM: arm/arm64: vgic-v3: Don't pretend to support IRQ/FIQ bypass arm64: KVM: VHE: Clear HCR_TGE when invalidating guest TLBs
2 parents 4b050f2 + 6a29b51 commit 106e4da

File tree

13 files changed

+191
-101
lines changed

13 files changed

+191
-101
lines changed

Documentation/virtual/kvm/api.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,10 @@ This ioctl allows the user to create or modify a guest physical memory
951951
slot. When changing an existing slot, it may be moved in the guest
952952
physical memory space, or its flags may be modified. It may not be
953953
resized. Slots may not overlap in guest physical address space.
954+
Bits 0-15 of "slot" specifies the slot id and this value should be
955+
less than the maximum number of user memory slots supported per VM.
956+
The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS,
957+
if this capability is supported by the architecture.
954958

955959
If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
956960
specifies the address space which is being modified. They must be

arch/arm/include/asm/kvm_arm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
#define HSR_EC_IABT_HYP (0x21)
210210
#define HSR_EC_DABT (0x24)
211211
#define HSR_EC_DABT_HYP (0x25)
212+
#define HSR_EC_MAX (0x3f)
212213

213214
#define HSR_WFI_IS_WFE (_AC(1, UL) << 0)
214215

arch/arm/include/asm/kvm_host.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#define __KVM_HAVE_ARCH_INTC_INITIALIZED
3131

3232
#define KVM_USER_MEM_SLOTS 32
33-
#define KVM_PRIVATE_MEM_SLOTS 4
3433
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
3534
#define KVM_HAVE_ONE_REG
3635
#define KVM_HALT_POLL_NS_DEFAULT 500000

arch/arm/kvm/arm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
221221
case KVM_CAP_MAX_VCPUS:
222222
r = KVM_MAX_VCPUS;
223223
break;
224+
case KVM_CAP_NR_MEMSLOTS:
225+
r = KVM_USER_MEM_SLOTS;
226+
break;
224227
case KVM_CAP_MSI_DEVID:
225228
if (!kvm)
226229
r = -EINVAL;

arch/arm/kvm/handle_exit.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,19 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)
7979
return 1;
8080
}
8181

82+
static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu, struct kvm_run *run)
83+
{
84+
u32 hsr = kvm_vcpu_get_hsr(vcpu);
85+
86+
kvm_pr_unimpl("Unknown exception class: hsr: %#08x\n",
87+
hsr);
88+
89+
kvm_inject_undefined(vcpu);
90+
return 1;
91+
}
92+
8293
static exit_handle_fn arm_exit_handlers[] = {
94+
[0 ... HSR_EC_MAX] = kvm_handle_unknown_ec,
8395
[HSR_EC_WFI] = kvm_handle_wfx,
8496
[HSR_EC_CP15_32] = kvm_handle_cp15_32,
8597
[HSR_EC_CP15_64] = kvm_handle_cp15_64,
@@ -98,13 +110,6 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu)
98110
{
99111
u8 hsr_ec = kvm_vcpu_trap_get_class(vcpu);
100112

101-
if (hsr_ec >= ARRAY_SIZE(arm_exit_handlers) ||
102-
!arm_exit_handlers[hsr_ec]) {
103-
kvm_err("Unknown exception class: hsr: %#08x\n",
104-
(unsigned int)kvm_vcpu_get_hsr(vcpu));
105-
BUG();
106-
}
107-
108113
return arm_exit_handlers[hsr_ec];
109114
}
110115

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
#define __KVM_HAVE_ARCH_INTC_INITIALIZED
3232

33-
#define KVM_USER_MEM_SLOTS 32
34-
#define KVM_PRIVATE_MEM_SLOTS 4
33+
#define KVM_USER_MEM_SLOTS 512
3534
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
3635
#define KVM_HALT_POLL_NS_DEFAULT 500000
3736

arch/arm64/kvm/handle_exit.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,19 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run)
135135
return ret;
136136
}
137137

138+
static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu, struct kvm_run *run)
139+
{
140+
u32 hsr = kvm_vcpu_get_hsr(vcpu);
141+
142+
kvm_pr_unimpl("Unknown exception class: hsr: %#08x -- %s\n",
143+
hsr, esr_get_class_string(hsr));
144+
145+
kvm_inject_undefined(vcpu);
146+
return 1;
147+
}
148+
138149
static exit_handle_fn arm_exit_handlers[] = {
150+
[0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec,
139151
[ESR_ELx_EC_WFx] = kvm_handle_wfx,
140152
[ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32,
141153
[ESR_ELx_EC_CP15_64] = kvm_handle_cp15_64,
@@ -162,13 +174,6 @@ static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu)
162174
u32 hsr = kvm_vcpu_get_hsr(vcpu);
163175
u8 hsr_ec = ESR_ELx_EC(hsr);
164176

165-
if (hsr_ec >= ARRAY_SIZE(arm_exit_handlers) ||
166-
!arm_exit_handlers[hsr_ec]) {
167-
kvm_err("Unknown exception class: hsr: %#08x -- %s\n",
168-
hsr, esr_get_class_string(hsr));
169-
BUG();
170-
}
171-
172177
return arm_exit_handlers[hsr_ec];
173178
}
174179

arch/arm64/kvm/hyp/tlb.c

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,62 @@
1818
#include <asm/kvm_hyp.h>
1919
#include <asm/tlbflush.h>
2020

21+
static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm)
22+
{
23+
u64 val;
24+
25+
/*
26+
* With VHE enabled, we have HCR_EL2.{E2H,TGE} = {1,1}, and
27+
* most TLB operations target EL2/EL0. In order to affect the
28+
* guest TLBs (EL1/EL0), we need to change one of these two
29+
* bits. Changing E2H is impossible (goodbye TTBR1_EL2), so
30+
* let's flip TGE before executing the TLB operation.
31+
*/
32+
write_sysreg(kvm->arch.vttbr, vttbr_el2);
33+
val = read_sysreg(hcr_el2);
34+
val &= ~HCR_TGE;
35+
write_sysreg(val, hcr_el2);
36+
isb();
37+
}
38+
39+
static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm)
40+
{
41+
write_sysreg(kvm->arch.vttbr, vttbr_el2);
42+
isb();
43+
}
44+
45+
static hyp_alternate_select(__tlb_switch_to_guest,
46+
__tlb_switch_to_guest_nvhe,
47+
__tlb_switch_to_guest_vhe,
48+
ARM64_HAS_VIRT_HOST_EXTN);
49+
50+
static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm)
51+
{
52+
/*
53+
* We're done with the TLB operation, let's restore the host's
54+
* view of HCR_EL2.
55+
*/
56+
write_sysreg(0, vttbr_el2);
57+
write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2);
58+
}
59+
60+
static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm)
61+
{
62+
write_sysreg(0, vttbr_el2);
63+
}
64+
65+
static hyp_alternate_select(__tlb_switch_to_host,
66+
__tlb_switch_to_host_nvhe,
67+
__tlb_switch_to_host_vhe,
68+
ARM64_HAS_VIRT_HOST_EXTN);
69+
2170
void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
2271
{
2372
dsb(ishst);
2473

2574
/* Switch to requested VMID */
2675
kvm = kern_hyp_va(kvm);
27-
write_sysreg(kvm->arch.vttbr, vttbr_el2);
28-
isb();
76+
__tlb_switch_to_guest()(kvm);
2977

3078
/*
3179
* We could do so much better if we had the VA as well.
@@ -46,7 +94,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
4694
dsb(ish);
4795
isb();
4896

49-
write_sysreg(0, vttbr_el2);
97+
__tlb_switch_to_host()(kvm);
5098
}
5199

52100
void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
@@ -55,29 +103,27 @@ void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
55103

56104
/* Switch to requested VMID */
57105
kvm = kern_hyp_va(kvm);
58-
write_sysreg(kvm->arch.vttbr, vttbr_el2);
59-
isb();
106+
__tlb_switch_to_guest()(kvm);
60107

61108
__tlbi(vmalls12e1is);
62109
dsb(ish);
63110
isb();
64111

65-
write_sysreg(0, vttbr_el2);
112+
__tlb_switch_to_host()(kvm);
66113
}
67114

68115
void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
69116
{
70117
struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm);
71118

72119
/* Switch to requested VMID */
73-
write_sysreg(kvm->arch.vttbr, vttbr_el2);
74-
isb();
120+
__tlb_switch_to_guest()(kvm);
75121

76122
__tlbi(vmalle1);
77123
dsb(nsh);
78124
isb();
79125

80-
write_sysreg(0, vttbr_el2);
126+
__tlb_switch_to_host()(kvm);
81127
}
82128

83129
void __hyp_text __kvm_flush_vm_context(void)

arch/x86/kvm/vmx.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7258,9 +7258,8 @@ static int handle_vmoff(struct kvm_vcpu *vcpu)
72587258
static int handle_vmclear(struct kvm_vcpu *vcpu)
72597259
{
72607260
struct vcpu_vmx *vmx = to_vmx(vcpu);
7261+
u32 zero = 0;
72617262
gpa_t vmptr;
7262-
struct vmcs12 *vmcs12;
7263-
struct page *page;
72647263

72657264
if (!nested_vmx_check_permission(vcpu))
72667265
return 1;
@@ -7271,22 +7270,9 @@ static int handle_vmclear(struct kvm_vcpu *vcpu)
72717270
if (vmptr == vmx->nested.current_vmptr)
72727271
nested_release_vmcs12(vmx);
72737272

7274-
page = nested_get_page(vcpu, vmptr);
7275-
if (page == NULL) {
7276-
/*
7277-
* For accurate processor emulation, VMCLEAR beyond available
7278-
* physical memory should do nothing at all. However, it is
7279-
* possible that a nested vmx bug, not a guest hypervisor bug,
7280-
* resulted in this case, so let's shut down before doing any
7281-
* more damage:
7282-
*/
7283-
kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu);
7284-
return 1;
7285-
}
7286-
vmcs12 = kmap(page);
7287-
vmcs12->launch_state = 0;
7288-
kunmap(page);
7289-
nested_release_page(page);
7273+
kvm_vcpu_write_guest(vcpu,
7274+
vmptr + offsetof(struct vmcs12, launch_state),
7275+
&zero, sizeof(zero));
72907276

72917277
nested_free_vmcs02(vmx, vmptr);
72927278

@@ -9694,10 +9680,8 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu,
96949680
return false;
96959681

96969682
page = nested_get_page(vcpu, vmcs12->msr_bitmap);
9697-
if (!page) {
9698-
WARN_ON(1);
9683+
if (!page)
96999684
return false;
9700-
}
97019685
msr_bitmap_l1 = (unsigned long *)kmap(page);
97029686

97039687
memset(msr_bitmap_l0, 0xff, PAGE_SIZE);
@@ -11121,8 +11105,10 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
1112111105
*/
1112211106
static void vmx_leave_nested(struct kvm_vcpu *vcpu)
1112311107
{
11124-
if (is_guest_mode(vcpu))
11108+
if (is_guest_mode(vcpu)) {
11109+
to_vmx(vcpu)->nested.nested_run_pending = 0;
1112511110
nested_vmx_vmexit(vcpu, -1, 0, 0);
11111+
}
1112611112
free_nested(to_vmx(vcpu));
1112711113
}
1112811114

include/linux/irqchip/arm-gic-v3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@
373373
#define ICC_IGRPEN0_EL1_MASK (1 << ICC_IGRPEN0_EL1_SHIFT)
374374
#define ICC_IGRPEN1_EL1_SHIFT 0
375375
#define ICC_IGRPEN1_EL1_MASK (1 << ICC_IGRPEN1_EL1_SHIFT)
376+
#define ICC_SRE_EL1_DIB (1U << 2)
377+
#define ICC_SRE_EL1_DFB (1U << 1)
376378
#define ICC_SRE_EL1_SRE (1U << 0)
377379

378380
/*

0 commit comments

Comments
 (0)