diff mbox series

[RFC,v3,22/24] KVM: arm64/sve: allow KVM_ARM_SVE_CONFIG_QUERY on vm fd

Message ID 1544570941-7377-23-git-send-email-Dave.Martin@arm.com (mailing list archive)
State RFC
Headers show
Series KVM: arm64: SVE guest support | expand

Commit Message

Dave Martin Dec. 11, 2018, 11:28 p.m. UTC
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@arm.com>

---

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 mbox series

Patch

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;
 	}