Skip to content

Commit 539aee0

Browse files
James MorseMarc Zyngier
authored andcommitted
KVM: arm64: Share the parts of get/set events useful to 32bit
The get/set events helpers to do some work to check reserved and padding fields are zero. This is useful on 32bit too. Move this code into virt/kvm/arm/arm.c, and give the arch code some underscores. This is temporarily hidden behind __KVM_HAVE_VCPU_EVENTS until 32bit is wired up. Signed-off-by: James Morse <[email protected]> Reviewed-by: Dongjiu Geng <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent be26b3a commit 539aee0

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
350350
int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
351351
int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
352352
int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
353-
int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
354-
struct kvm_vcpu_events *events);
353+
int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
354+
struct kvm_vcpu_events *events);
355355

356-
int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
357-
struct kvm_vcpu_events *events);
356+
int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
357+
struct kvm_vcpu_events *events);
358358

359359
#define KVM_ARCH_WANT_MMU_NOTIFIER
360360
int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);

arch/arm64/kvm/guest.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,9 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
289289
return -EINVAL;
290290
}
291291

292-
int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
293-
struct kvm_vcpu_events *events)
292+
int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
293+
struct kvm_vcpu_events *events)
294294
{
295-
memset(events, 0, sizeof(*events));
296-
297295
events->exception.serror_pending = !!(vcpu->arch.hcr_el2 & HCR_VSE);
298296
events->exception.serror_has_esr = cpus_have_const_cap(ARM64_HAS_RAS_EXTN);
299297

@@ -303,23 +301,12 @@ int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
303301
return 0;
304302
}
305303

306-
int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
307-
struct kvm_vcpu_events *events)
304+
int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
305+
struct kvm_vcpu_events *events)
308306
{
309-
int i;
310307
bool serror_pending = events->exception.serror_pending;
311308
bool has_esr = events->exception.serror_has_esr;
312309

313-
/* check whether the reserved field is zero */
314-
for (i = 0; i < ARRAY_SIZE(events->reserved); i++)
315-
if (events->reserved[i])
316-
return -EINVAL;
317-
318-
/* check whether the pad field is zero */
319-
for (i = 0; i < ARRAY_SIZE(events->exception.pad); i++)
320-
if (events->exception.pad[i])
321-
return -EINVAL;
322-
323310
if (serror_pending && has_esr) {
324311
if (!cpus_have_const_cap(ARM64_HAS_RAS_EXTN))
325312
return -EINVAL;

virt/kvm/arm/arm.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,34 @@ static int kvm_arm_vcpu_has_attr(struct kvm_vcpu *vcpu,
10501050
return ret;
10511051
}
10521052

1053+
#ifdef __KVM_HAVE_VCPU_EVENTS /* temporary: until 32bit is wired up */
1054+
static int kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
1055+
struct kvm_vcpu_events *events)
1056+
{
1057+
memset(events, 0, sizeof(*events));
1058+
1059+
return __kvm_arm_vcpu_get_events(vcpu, events);
1060+
}
1061+
1062+
static int kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
1063+
struct kvm_vcpu_events *events)
1064+
{
1065+
int i;
1066+
1067+
/* check whether the reserved field is zero */
1068+
for (i = 0; i < ARRAY_SIZE(events->reserved); i++)
1069+
if (events->reserved[i])
1070+
return -EINVAL;
1071+
1072+
/* check whether the pad field is zero */
1073+
for (i = 0; i < ARRAY_SIZE(events->exception.pad); i++)
1074+
if (events->exception.pad[i])
1075+
return -EINVAL;
1076+
1077+
return __kvm_arm_vcpu_set_events(vcpu, events);
1078+
}
1079+
#endif /* __KVM_HAVE_VCPU_EVENTS */
1080+
10531081
long kvm_arch_vcpu_ioctl(struct file *filp,
10541082
unsigned int ioctl, unsigned long arg)
10551083
{

0 commit comments

Comments
 (0)