diff mbox

[03/15] KVM: Add compat ioctl for KVM_SET_SIGNAL_MASK

Message ID 1308322192-11918-4-git-send-email-agraf@suse.de (mailing list archive)
State New, archived
Headers show

Commit Message

Alexander Graf June 17, 2011, 2:49 p.m. UTC
KVM has an ioctl to define which signal mask should be used while running
inside VCPU_RUN. At least for big endian systems, this mask is different
on 32-bit and 64-bit systems (though the size is identical).

Add a compat wrapper that converts the mask to whatever the kernel accepts,
allowing 32-bit kvm user space to set signal masks.

This patch fixes qemu with --enable-io-thread on ppc64 hosts when running
32-bit user land.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - use compat_ptr
  - only declare compat call with CONFIG_COMPAT
---
 kernel/compat.c     |    1 +
 virt/kvm/kvm_main.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletions(-)

Comments

Avi Kivity June 19, 2011, 9:04 a.m. UTC | #1
On 06/17/2011 05:49 PM, Alexander Graf wrote:
> KVM has an ioctl to define which signal mask should be used while running
> inside VCPU_RUN. At least for big endian systems, this mask is different
> on 32-bit and 64-bit systems (though the size is identical).
>
> Add a compat wrapper that converts the mask to whatever the kernel accepts,
> allowing 32-bit kvm user space to set signal masks.
>
> This patch fixes qemu with --enable-io-thread on ppc64 hosts when running
> 32-bit user land.
>

This is already in (175c60204146b644), I believe the same version.
Alexander Graf June 19, 2011, 12:53 p.m. UTC | #2
On 19.06.2011, at 11:04, Avi Kivity wrote:

> On 06/17/2011 05:49 PM, Alexander Graf wrote:
>> KVM has an ioctl to define which signal mask should be used while running
>> inside VCPU_RUN. At least for big endian systems, this mask is different
>> on 32-bit and 64-bit systems (though the size is identical).
>> 
>> Add a compat wrapper that converts the mask to whatever the kernel accepts,
>> allowing 32-bit kvm user space to set signal masks.
>> 
>> This patch fixes qemu with --enable-io-thread on ppc64 hosts when running
>> 32-bit user land.
>> 
> 
> This is already in (175c60204146b644), I believe the same version.

Oh? I rebased again against origin/master and it's not there. Which tree do you want to have this against?

 ?git://git.kernel.org/pub/scm/virt/kvm/kvm.git


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Avi Kivity June 19, 2011, 1:01 p.m. UTC | #3
On 06/19/2011 03:53 PM, Alexander Graf wrote:
> On 19.06.2011, at 11:04, Avi Kivity wrote:
>
> >  On 06/17/2011 05:49 PM, Alexander Graf wrote:
> >>  KVM has an ioctl to define which signal mask should be used while running
> >>  inside VCPU_RUN. At least for big endian systems, this mask is different
> >>  on 32-bit and 64-bit systems (though the size is identical).
> >>
> >>  Add a compat wrapper that converts the mask to whatever the kernel accepts,
> >>  allowing 32-bit kvm user space to set signal masks.
> >>
> >>  This patch fixes qemu with --enable-io-thread on ppc64 hosts when running
> >>  32-bit user land.
> >>
> >
> >  This is already in (175c60204146b644), I believe the same version.
>
> Oh? I rebased again against origin/master and it's not there. Which tree do you want to have this against?
>
>   ?git://git.kernel.org/pub/scm/virt/kvm/kvm.git
>

Sorry, it's in 'next' of the same repo.  Usually the window between 
'next' and 'master' is short, but I haven't run autotest in a while so 
'master' is a bit stale.

I'll update master later today.
diff mbox

Patch

diff --git a/kernel/compat.c b/kernel/compat.c
index fc9eb09..18197ae 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -890,6 +890,7 @@  sigset_from_compat (sigset_t *set, compat_sigset_t *compat)
 	case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32 );
 	}
 }
+EXPORT_SYMBOL_GPL(sigset_from_compat);
 
 asmlinkage long
 compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index fa2321a..11d2783 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -84,6 +84,10 @@  struct dentry *kvm_debugfs_dir;
 
 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
 			   unsigned long arg);
+#ifdef CONFIG_COMPAT
+static long kvm_vcpu_compat_ioctl(struct file *file, unsigned int ioctl,
+				  unsigned long arg);
+#endif
 static int hardware_enable_all(void);
 static void hardware_disable_all(void);
 
@@ -1586,7 +1590,9 @@  static int kvm_vcpu_release(struct inode *inode, struct file *filp)
 static struct file_operations kvm_vcpu_fops = {
 	.release        = kvm_vcpu_release,
 	.unlocked_ioctl = kvm_vcpu_ioctl,
-	.compat_ioctl   = kvm_vcpu_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl   = kvm_vcpu_compat_ioctl,
+#endif
 	.mmap           = kvm_vcpu_mmap,
 	.llseek		= noop_llseek,
 };
@@ -1875,6 +1881,50 @@  out:
 	return r;
 }
 
+#ifdef CONFIG_COMPAT
+static long kvm_vcpu_compat_ioctl(struct file *filp,
+				  unsigned int ioctl, unsigned long arg)
+{
+	struct kvm_vcpu *vcpu = filp->private_data;
+	void __user *argp = compat_ptr(arg);
+	int r;
+
+	if (vcpu->kvm->mm != current->mm)
+		return -EIO;
+
+	switch (ioctl) {
+	case KVM_SET_SIGNAL_MASK: {
+		struct kvm_signal_mask __user *sigmask_arg = argp;
+		struct kvm_signal_mask kvm_sigmask;
+		compat_sigset_t csigset;
+		sigset_t sigset;
+
+		if (argp) {
+			r = -EFAULT;
+			if (copy_from_user(&kvm_sigmask, argp,
+					   sizeof kvm_sigmask))
+				goto out;
+			r = -EINVAL;
+			if (kvm_sigmask.len != sizeof csigset)
+				goto out;
+			r = -EFAULT;
+			if (copy_from_user(&csigset, sigmask_arg->sigset,
+					   sizeof csigset))
+				goto out;
+		}
+		sigset_from_compat(&sigset, &csigset);
+		r = kvm_vcpu_ioctl_set_sigmask(vcpu, &sigset);
+		break;
+	}
+	default:
+		r = kvm_vcpu_ioctl(filp, ioctl, arg);
+	}
+
+out:
+	return r;
+}
+#endif
+
 static long kvm_vm_ioctl(struct file *filp,
 			   unsigned int ioctl, unsigned long arg)
 {