Skip to content

Commit 84886c2

Browse files
committed
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
2 parents 501cfe0 + 50a8d33 commit 84886c2

File tree

8 files changed

+19
-16
lines changed

8 files changed

+19
-16
lines changed

arch/arm64/include/asm/esr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ struct kvm_vcpu_stat {
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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,12 +1389,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,13 +869,10 @@ u32 __attribute_const__ kvm_target_cpu(void)
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)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ SYM_FUNC_END(__host_hvc)
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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int finalize_host_mappings_walker(u64 addr, u64 end, u32 level,
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)
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code)
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

0 commit comments

Comments
 (0)