History

Merge tag 'kvmarm-fixes-5.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into kvm-master

KVM/arm64 fixes for 5.16, take #1 - Fix the host S2 finalization by solely iterating over the memblocks instead of the whole IPA space - Tighten the return value of kvm_vcpu_preferred_target() now that 32bit support is long gone - Make sure the extraction of ESR_ELx.EC is limited to the architected bits - Comment fixups

Paolo Bonzini committed 5 years ago

Commit 84886c22 parents 501cfe0 50a8d338 files · +19 −16Browse files

Unified · Split

8 files
  1. arch/arm64/include/asm/esr.h +1 −0
  2. arch/arm64/include/asm/kvm_host.h +1 −1
  3. arch/arm64/kvm/arm.c +1 −4
  4. arch/arm64/kvm/guest.c +1 −6
  5. arch/arm64/kvm/hyp/hyp-entry.S +1 −1
  6. arch/arm64/kvm/hyp/nvhe/host.S +1 −1
  7. arch/arm64/kvm/hyp/nvhe/setup.c +12 −2
  8. arch/arm64/kvm/hyp/nvhe/sys_regs.c +1 −1
arch/arm64/include/asm/esr.h+1−0
@@ -68,6 +68,7 @@ · 67 unmodified lines
6868 #define ESR_ELx_EC_MAX (0x3F)
6969
7070 #define ESR_ELx_EC_SHIFT (26)
71+#define ESR_ELx_EC_WIDTH (6)
7172 #define ESR_ELx_EC_MASK (UL(0x3F) << ESR_ELx_EC_SHIFT)
7273 #define ESR_ELx_EC(esr) (((esr) & ESR_ELx_EC_MASK) >> ESR_ELx_EC_SHIFT)
7374
arch/arm64/include/asm/kvm_host.h+1−1
@@ -584,7 +584,7 @@ struct kvm_vcpu_stat { · 583 unmodified lines
584584 u64 exits;
585585 };
586586
587−int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
587+void kvm_vcpu_preferred_target(struct kvm_vcpu_init *init);
588588 unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
589589 int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
590590 int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
arch/arm64/kvm/arm.c+1−4
@@ -1389,12 +1389,9 @@ long kvm_arch_vm_ioctl(struct file *filp, · 1388 unmodified lines
13891389 return kvm_vm_ioctl_set_device_addr(kvm, &dev_addr);
13901390 }
13911391 case KVM_ARM_PREFERRED_TARGET: {
1392− int err;
13931392 struct kvm_vcpu_init init;
13941393
1395− err = kvm_vcpu_preferred_target(&init);
1396− if (err)
1397− return err;
1394+ kvm_vcpu_preferred_target(&init);
13981395
13991396 if (copy_to_user(argp, &init, sizeof(init)))
14001397 return -EFAULT;
arch/arm64/kvm/guest.c+1−6
@@ -869,13 +869,10 @@ u32 __attribute_const__ kvm_target_cpu(void) · 868 unmodified lines
869869 return KVM_ARM_TARGET_GENERIC_V8;
870870 }
871871
872−int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init)
872+void kvm_vcpu_preferred_target(struct kvm_vcpu_init *init)
873873 {
874874 u32 target = kvm_target_cpu();
875875
876− if (target < 0)
877− return -ENODEV;
878−
879876 memset(init, 0, sizeof(*init));
880877
881878 /*
@@ -885,8 +882,6 @@ int kvm_vcpu_preferred_target(struct kvm_vcpu_init *init) · 3 unmodified lines
885882 * target type.
886883 */
887884 init->target = (__u32)target;
888−
889− return 0;
890885 }
891886
892887 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
arch/arm64/kvm/hyp/hyp-entry.S+1−1
@@ -44,7 +44,7 @@ · 43 unmodified lines
4444 el1_sync: // Guest trapped into EL2
4545
4646 mrs x0, esr_el2
47− lsr x0, x0, #ESR_ELx_EC_SHIFT
47+ ubfx x0, x0, #ESR_ELx_EC_SHIFT, #ESR_ELx_EC_WIDTH
4848 cmp x0, #ESR_ELx_EC_HVC64
4949 ccmp x0, #ESR_ELx_EC_HVC32, #4, ne
5050 b.ne el1_trap
arch/arm64/kvm/hyp/nvhe/host.S+1−1
@@ -141,7 +141,7 @@ SYM_FUNC_END(__host_hvc) · 140 unmodified lines
141141 .L__vect_start\@:
142142 stp x0, x1, [sp, #-16]!
143143 mrs x0, esr_el2
144− lsr x0, x0, #ESR_ELx_EC_SHIFT
144+ ubfx x0, x0, #ESR_ELx_EC_SHIFT, #ESR_ELx_EC_WIDTH
145145 cmp x0, #ESR_ELx_EC_HVC64
146146 b.eq __host_hvc
147147 b __host_exit
arch/arm64/kvm/hyp/nvhe/setup.c+12−2
@@ -178,7 +178,7 @@ static int finalize_host_mappings_walker(u64 addr, u64 end, u32 level, · 177 unmodified lines
178178
179179 phys = kvm_pte_to_phys(pte);
180180 if (!addr_is_memory(phys))
181− return 0;
181+ return -EINVAL;
182182
183183 /*
184184 * Adjust the host stage-2 mappings to match the ownership attributes
@@ -207,8 +207,18 @@ static int finalize_host_mappings(void) · 22 unmodified lines
207207 .cb = finalize_host_mappings_walker,
208208 .flags = KVM_PGTABLE_WALK_LEAF,
209209 };
210+ int i, ret;
211+
212+ for (i = 0; i < hyp_memblock_nr; i++) {
213+ struct memblock_region *reg = &hyp_memory[i];
214+ u64 start = (u64)hyp_phys_to_virt(reg->base);
215+
216+ ret = kvm_pgtable_walk(&pkvm_pgtable, start, reg->size, &walker);
217+ if (ret)
218+ return ret;
219+ }
210220
211− return kvm_pgtable_walk(&pkvm_pgtable, 0, BIT(pkvm_pgtable.ia_bits), &walker);
221+ return 0;
212222 }
213223
214224 void __noreturn __pkvm_init_finalise(void)
arch/arm64/kvm/hyp/nvhe/sys_regs.c+1−1
@@ -474,7 +474,7 @@ bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code) · 473 unmodified lines
474474 return true;
475475 }
476476
477−/**
477+/*
478478 * Handler for protected VM restricted exceptions.
479479 *
480480 * Inject an undefined exception into the guest and return true to indicate that