Since userspace may need to decide on the set of vector lengths for the guest before setting up a vm, it is onerous to require a vcpu fd to be available first. KVM_ARM_SVE_CONFIG_QUERY is not vcpu-dependent anyway, so this patch wires up KVM_ARM_SVE_CONFIG to be usable on a vm fd where appropriate. Subcommands that are vcpu-dependent (currently KVM_ARM_SVE_CONFIG_SET, KVM_ARM_SVE_CONFIG_GET) will return -EINVAL if invoked on a vm fd. Signed-off-by: Dave Martin <Dave.Martin@xxxxxxx> --- Changes since RFC v2: * Removed the arch vm ioctl hook in favour of kvm_arm_vcpu_sve_config(NULL, ...). --- arch/arm64/kvm/guest.c | 7 +++++++ virt/kvm/arm/arm.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index ffb2a25..85a112c 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -675,6 +675,9 @@ static int kvm_vcpu_set_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls, unsigned int vq, max_vq; int ret; + if (!vcpu) + return -EINVAL; /* per-vcpu operation on vm fd */ + if (vcpu->arch.has_run_once || vcpu_sve_config_done(vcpu)) return -EBADFD; /* too late, or already configured */ @@ -769,6 +772,9 @@ static int kvm_vcpu_query_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls static int kvm_vcpu_get_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls, struct kvm_sve_vls __user *userp) { + if (!vcpu) + return -EINVAL; /* per-vcpu operation on vm fd */ + if (!vcpu_sve_config_done(vcpu)) return -EBADFD; /* not configured yet */ @@ -778,6 +784,7 @@ static int kvm_vcpu_get_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls, sve_vq_from_vl(vcpu->arch.sve_max_vl), userp); } +/* vcpu may be NULL if this is called via a vm fd */ int kvm_arm_vcpu_sve_config(struct kvm_vcpu *vcpu, struct kvm_sve_vls __user *userp) { diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index cafd701..0f92d54 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1286,6 +1286,9 @@ long kvm_arch_vm_ioctl(struct file *filp, return 0; } + case KVM_ARM_SVE_CONFIG: + return kvm_arm_vcpu_sve_config(NULL, argp); + default: return -EINVAL; } -- 2.1.4 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm