KVM/ARM Changes for v4.14
Subsystems (5)
Hi Paolo and Radim,
Here is v2 of the changes for kvm/arm for v4.14. Hopefully I got it right this time.
Two minor cleanups and improvements, a fix for decoding external abort types from guests, and added support for migrating the active priority of interrupts when running a GICv2 guest on a GICv3 host.
The following changes since commit 712b12d72451411c40e39d25e2140fb8c7fd0e49:
kvm: nVMX: Validate the virtual-APIC address on nested VM-entry (2017-08-25 12:34:16 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvm-arm-for-v4.14
for you to fetch changes up to 9b87e7a8bfb5098129836757608b3cbbdc11245a:
KVM: arm/arm64: Support uaccess of GICC_APRn (2017-09-05 17:33:39 +0200)
Thanks,
-Christoffer
Arvind Yadav (1):
KVM: arm/arm64: vgic: constify seq_operations and file_operations
Christoffer Dall (2):
KVM: arm/arm64: Extract GICv3 max APRn index calculation
KVM: arm/arm64: Support uaccess of GICC_APRn
James Morse (1):
KVM: arm/arm64: Fix guest external abort matching
Marc Zyngier (1):
KVM: arm/arm64: vITS: Drop its_ite->lpi field
Documentation/virtual/kvm/devices/arm-vgic.txt | 5 +++ arch/arm/include/asm/kvm_arm.h | 1 - arch/arm/include/asm/kvm_emulate.h | 24 ++++++++++--- arch/arm64/include/asm/kvm_emulate.h | 24 ++++++++++--- arch/arm64/kvm/vgic-sys-reg-v3.c | 23 ++----------- virt/kvm/arm/mmu.c | 40 ++++++---------------- virt/kvm/arm/vgic/vgic-debug.c | 4 +-- virt/kvm/arm/vgic/vgic-its.c | 10 +++--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 47 +++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.h | 16 +++++++++ 10 files changed, 125 insertions(+), 69 deletions(-)
[PULL v2 1/5] KVM: arm/arm64: Fix guest external abort matching
From: James Morse <[email protected]>
The ARM-ARM has two bits in the ESR/HSR relevant to external aborts. A range of {I,D}FSC values (of which bit 5 is always set) and bit 9 'EA' which provides:
Quoted 1 line
an IMPLEMENTATION DEFINED classification of External Aborts.
This bit is in addition to the {I,D}FSC range, and has an implementation defined meaning. KVM should always ignore this bit when handling external aborts from a guest.
Remove the ESR_ELx_EA definition and rewrite its helper kvm_vcpu_dabt_isextabt() to check the {I,D}FSC range. This merges kvm_vcpu_dabt_isextabt() and the recently added is_abort_sea() helper.
--- arch/arm/include/asm/kvm_arm.h | 1 - arch/arm/include/asm/kvm_emulate.h | 24 +++++++++++++++++----- arch/arm64/include/asm/kvm_emulate.h | 24 +++++++++++++++++----- virt/kvm/arm/mmu.c | 40 ++++++++++-------------------------- 4 files changed, 49 insertions(+), 40 deletions(-)
arch/arm/include/asm/kvm_arm.h +0 -1
@@ -227,7 +227,6 @@#define HSR_DABT_S1PTW (_AC(1, UL) << 7)#define HSR_DABT_CM (_AC(1, UL) << 8) -#define HSR_DABT_EA (_AC(1, UL) << 9)#define kvm_arm_exception_type \ {0, "RESET" }, \
arch/arm/include/asm/kvm_emulate.h +19 -5
@@ -149,11 +149,6 @@ static inline int kvm_vcpu_dabt_get_rd(struct kvm_vcpu *vcpu)return (kvm_vcpu_get_hsr (vcpu) &HSR_SRT_MASK ) >>HSR_SRT_SHIFT ; } -static inline bool kvm_vcpu_dabt_isextabt (struct kvm_vcpu *vcpu) -{ -return kvm_vcpu_get_hsr (vcpu) &HSR_DABT_EA ; -} -static inline bool kvm_vcpu_dabt_iss1tw (struct kvm_vcpu *vcpu) {return kvm_vcpu_get_hsr (vcpu) &HSR_DABT_S1PTW ;
@@ -206,6 +201,25 @@ static inline u8 kvm_vcpu_trap_get_fault_type(struct kvm_vcpu *vcpu)return kvm_vcpu_get_hsr (vcpu) &HSR_FSC_TYPE ; } +static inline bool kvm_vcpu_dabt_isextabt (struct kvm_vcpu *vcpu) +{ +switch (kvm_vcpu_trap_get_fault_type (vcpu)) { +case FSC_SEA : +case FSC_SEA_TTW0 : +case FSC_SEA_TTW1 : +case FSC_SEA_TTW2 : +case FSC_SEA_TTW3 : +case FSC_SECC : +case FSC_SECC_TTW0 : +case FSC_SECC_TTW1 : +case FSC_SECC_TTW2 : +case FSC_SECC_TTW3 : +return true; +default : +return false; + } +} +static inline u32 kvm_vcpu_hvc_get_imm (struct kvm_vcpu *vcpu) {return kvm_vcpu_get_hsr (vcpu) &HSR_HVC_IMM_MASK ;
arch/arm64/include/asm/kvm_emulate.h +19 -5
@@ -188,11 +188,6 @@ static inline int kvm_vcpu_dabt_get_rd(const struct kvm_vcpu *vcpu)return (kvm_vcpu_get_hsr (vcpu) & ESR_ELx_SRT_MASK) >> ESR_ELx_SRT_SHIFT; } -static inline bool kvm_vcpu_dabt_isextabt (const struct kvm_vcpu *vcpu) -{ -return !!(kvm_vcpu_get_hsr (vcpu) & ESR_ELx_EA); -} -static inline bool kvm_vcpu_dabt_iss1tw (const struct kvm_vcpu *vcpu) {return !!(kvm_vcpu_get_hsr (vcpu) & ESR_ELx_S1PTW);
@@ -240,6 +235,25 @@ static inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vcpu)return kvm_vcpu_get_hsr (vcpu) & ESR_ELx_FSC_TYPE; } +static inline bool kvm_vcpu_dabt_isextabt (const struct kvm_vcpu *vcpu) +{ +switch (kvm_vcpu_trap_get_fault_type (vcpu)) { +case FSC_SEA : +case FSC_SEA_TTW0 : +case FSC_SEA_TTW1 : +case FSC_SEA_TTW2 : +case FSC_SEA_TTW3 : +case FSC_SECC : +case FSC_SECC_TTW0 : +case FSC_SECC_TTW1 : +case FSC_SECC_TTW2 : +case FSC_SECC_TTW3 : +return true; +default : +return false; + } +} +static inline int kvm_vcpu_sys_get_rt (struct kvm_vcpu *vcpu) {u32 esr =kvm_vcpu_get_hsr (vcpu);
virt/kvm/arm/mmu.c +11 -29
@@ -1454,25 +1454,6 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)kvm_set_pfn_accessed (pfn); } -static bool is_abort_sea (unsigned long fault_status) -{ -switch (fault_status) { -case FSC_SEA : -case FSC_SEA_TTW0 : -case FSC_SEA_TTW1 : -case FSC_SEA_TTW2 : -case FSC_SEA_TTW3 : -case FSC_SECC : -case FSC_SECC_TTW0 : -case FSC_SECC_TTW1 : -case FSC_SECC_TTW2 : -case FSC_SECC_TTW3 : -return true; -default : -return false; - } -} -/** * kvm_handle_guest_abort - handles all 2nd stage aborts * @vcpu: the VCPU pointer
@@ -1498,20 +1479,21 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) fault_status =kvm_vcpu_trap_get_fault_type (vcpu); fault_ipa =kvm_vcpu_get_fault_ipa (vcpu); + is_iabt =kvm_vcpu_trap_is_iabt (vcpu); -/* -* The host kernel will handle the synchronous external abort. There -* is no need to pass the error into the guest. -*/ -if (is_abort_sea (fault_status)) { +/* Synchronous External Abort? */ +if (kvm_vcpu_dabt_isextabt (vcpu)) { +/* +* For RAS the host kernel may handle this abort. +* There is no need to pass the error into the guest. +*/ if (!handle_guest_sea (fault_ipa,kvm_vcpu_get_hsr (vcpu)))return 1 ; - } - is_iabt =kvm_vcpu_trap_is_iabt (vcpu); -if (unlikely (!is_iabt &&kvm_vcpu_dabt_isextabt (vcpu))) { -kvm_inject_vabt (vcpu); -return 1 ; +if (unlikely (!is_iabt)) { +kvm_inject_vabt (vcpu); +return 1 ; + } } trace_kvm_guest_fault(*vcpu_pc(vcpu), kvm_vcpu_get_hsr(vcpu),
Signature · 1 line
2.9.0
[PULL v2 2/5] KVM: arm/arm64: vgic: constify seq_operations and file_operations
In reply to Christoffer DallFrom: Arvind Yadav <[email protected]>
vgic_debug_seq_ops and file_operations are not supposed to change at runtime and none of the structures is modified.
--- virt/kvm/arm/vgic/vgic-debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-debug.c +2 -2
@@ -234,7 +234,7 @@ static int vgic_debug_show(struct seq_file *s, void *v)return 0 ; } -static struct seq_operations vgic_debug_seq_ops = { +static const struct seq_operations vgic_debug_seq_ops = { .start = vgic_debug_start, .next = vgic_debug_next, .stop = vgic_debug_stop,
@@ -255,7 +255,7 @@ static int debug_open(struct inode *inode, struct file *file)return ret; }; -static struct file_operations vgic_debug_fops = { +static const struct file_operations vgic_debug_fops = { .owner =THIS_MODULE , .open = debug_open, .read = seq_read,
Signature · 1 line
2.9.0
[PULL v2 3/5] KVM: arm/arm64: vITS: Drop its_ite->lpi field
In reply to Christoffer DallFrom: Marc Zyngier <[email protected]>
For unknown reasons, the its_ite data structure carries an "lpi" field which contains the intid of the LPI. This is an obvious duplication of the vgic_irq->intid field, so let's fix the only user and remove the now useless field.
--- virt/kvm/arm/vgic/vgic-its.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
virt/kvm/arm/vgic/vgic-its.c +4 -6
@@ -144,7 +144,6 @@ struct its_ite {struct vgic_irq *irq;struct its_collection *collection; -u32 lpi;u32 event_id; };
@@ -813,7 +812,7 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id)/* Must be called with its_lock mutex held */ static struct its_ite *vgic_its_alloc_ite (struct its_device *device,struct its_collection *collection, -u32 lpi_id,u32 event_id) +u32 event_id) {struct its_ite *ite;
@@ -823,7 +822,6 @@ static struct its_ite *vgic_its_alloc_ite(struct its_device *device, ite->event_id = event_id; ite->collection = collection; - ite->lpi = lpi_id;list_add_tail (&ite->ite_list, &device->itt_head);return ite;
@@ -873,7 +871,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, new_coll = collection; } - ite =vgic_its_alloc_ite (device, collection, lpi_nr, event_id); + ite =vgic_its_alloc_ite (device, collection, event_id);if (IS_ERR (ite)) {if (new_coll)vgic_its_free_collection (its, coll_id);
@@ -1848,7 +1846,7 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, next_offset =compute_next_eventid_offset (&dev->itt_head, ite); val = ((u64 )next_offset <<KVM_ITS_ITE_NEXT_SHIFT ) | - ((u64 )ite->lpi <<KVM_ITS_ITE_PINTID_SHIFT ) | + ((u64 )ite->irq->intid <<KVM_ITS_ITE_PINTID_SHIFT ) | ite->collection->collection_id; val =cpu_to_le64 (val);return kvm_write_guest (kvm, gpa, &val, ite_esz);
@@ -1895,7 +1893,7 @@ static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id,if (!collection)return -EINVAL ; - ite =vgic_its_alloc_ite (dev, collection, lpi_id, event_id); + ite =vgic_its_alloc_ite (dev, collection, event_id);if (IS_ERR (ite))return PTR_ERR (ite);
Signature · 1 line
2.9.0
[PULL v2 4/5] KVM: arm/arm64: Extract GICv3 max APRn index calculation
In reply to Christoffer DallAs we are about to access the APRs from the GICv2 uaccess interface, make this logic generally available.
--- arch/arm64/kvm/vgic-sys-reg-v3.c | 23 +++-------------------- virt/kvm/arm/vgic/vgic.h | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-)
arch/arm64/kvm/vgic-sys-reg-v3.c +3 -20
@@ -208,29 +208,12 @@ static void vgic_v3_access_apr_reg(struct kvm_vcpu *vcpu,static bool access_gic_aprn (struct kvm_vcpu *vcpu,struct sys_reg_params *p,const struct sys_reg_desc *r,u8 apr) { -struct vgic_cpu *vgic_v3_cpu = &vcpu->arch.vgic_cpu;u8 idx = r->Op2 &3 ; -/* -* num_pri_bits are initialized with HW supported values. -* We can rely safely on num_pri_bits even if VM has not -* restored ICC_CTLR_EL1 before restoring APnR registers. -*/ -switch (vgic_v3_cpu->num_pri_bits) { -case 7 : -vgic_v3_access_apr_reg (vcpu, p, apr, idx); -break ; -case 6 : -if (idx >1 ) - goto err; -vgic_v3_access_apr_reg (vcpu, p, apr, idx); -break ; -default : -if (idx >0 ) - goto err; -vgic_v3_access_apr_reg (vcpu, p, apr, idx); - } +if (idx >vgic_v3_max_apr_idx (vcpu)) + goto err; +vgic_v3_access_apr_reg (vcpu, p, apr, idx);return true; err:if (!p->is_write)
virt/kvm/arm/vgic/vgic.h +16 -0
@@ -220,4 +220,20 @@ int vgic_debug_destroy(struct kvm *kvm);bool lock_all_vcpus (struct kvm *kvm);void unlock_all_vcpus (struct kvm *kvm); +static inline int vgic_v3_max_apr_idx (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *cpu_if = &vcpu->arch.vgic_cpu; + +/* +* num_pri_bits are initialized with HW supported values. +* We can rely safely on num_pri_bits even if VM has not +* restored ICC_CTLR_EL1 before restoring APnR registers. +*/ +switch (cpu_if->num_pri_bits) { +case 7 :return 3 ; +case 6 :return 1 ; +default :return 0 ; + } +} +#endif
Signature · 1 line
2.9.0
[PULL v2 5/5] KVM: arm/arm64: Support uaccess of GICC_APRn
In reply to Christoffer DallWhen migrating guests around we need to know the active priorities to ensure functional virtual interrupt prioritization by the GIC.
This commit clarifies the API and how active priorities of interrupts in different groups are represented, and implements the accessor functions for the uaccess register range.
We live with a slight layering violation in accessing GICv3 data structures from vgic-mmio-v2.c, because anything else just adds too much complexity for us to deal with (it's not like there's a benefit elsewhere in the code of an intermediate representation as is the case with the VMCR). We accept this, because while doing v3 processing from a file named something-v2.c can look strange at first, this really is specific to dealing with the user space interface for something that looks like a GICv2.
--- Documentation/virtual/kvm/devices/arm-vgic.txt | 5 +++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 47 +++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-)
Documentation/virtual/kvm/devices/arm-vgic.txt +5 -0
@@ -83,6 +83,11 @@ Groups: Bits for undefined preemption levels are RAZ/WI. + Note that this differs from a CPU's view of the APRs on hardware in which + a GIC without the security extensions expose group 0 and group 1 active + priorities in separate register groups, whereas we show a combined view + similar to GICv2's GICH_APR. + For historical reasons and to provide ABI compatibility with userspace we export the GICC_PMR register in the format of the GICH_VMCR.VMPriMask field in the lower 5 bits of a word, meaning that userspace must always
virt/kvm/arm/vgic/vgic-mmio-v2.c +46 -1
59 lines not on this page · raw message
Signature · 1 line
2.9.0