Kernel KVM-PPC virtualization development
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: kvm-ppc@vger.kernel.org
Subject: Re: [PATCH 26/27] Enable 32bit dirty log pointers on 64bit host
Date: Wed, 30 Sep 2009 12:04:31 +0000	[thread overview]
Message-ID: <200909301404.32367.arnd@arndb.de> (raw)
In-Reply-To: <1254212303-8737-27-git-send-email-agraf@suse.de>

On Tuesday 29 September 2009, Avi Kivity wrote:
> >
> >         r = -EINVAL;
> >         if (log->slot >= KVM_MEMORY_SLOTS)
> > @@ -718,8 +719,15 @@ int kvm_get_dirty_log(struct kvm *kvm,
> >         for (i = 0; !any && i < n/sizeof(long); ++i)
> >                 any = memslot->dirty_bitmap[i];
> >
> > +#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
> > +       /* Need to convert user pointers */
> > +       if (test_thread_flag(TIF_32BIT))
> > +               target_bm = (void*)((u64)log->dirty_bitmap >> 32);
> > +       else
> > +#endif
> > +       target_bm = log->dirty_bitmap;
> >         r = -EFAULT;
> > -       if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
> > +       if (copy_to_user(target_bm, memslot->dirty_bitmap, n))
> >                 goto out;
> >
> >         if (any)
> 
> Ah, that's much better.  Plus a mental note not to put pointers in 
> user-visible structures in the future.  This can serve as a reminder :)

It's still broken on s390, which 

1. uses TIF_31BIT instead of TIF_32BIT
2. needs to call compat_ptr() to do a real conversion instead of a cast

The TIF_32BIT method is also not reliable. E.g. on x86_64 you are supposed
to get the 32 bit ABI when calling through INT80 instead of syscall/sysenter,
independent of the value of TIF_32BIT.

A better way to do this is to add a separate compat_ioctl() method that
converts this for you.

The patch below is an example for the canonical way to do this. Not tested!

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 897bff3..20f88ad 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2297,6 +2297,49 @@ out:
 	return r;
 }
 
+#ifdef CONFIG_COMPAT
+struct compat_kvm_dirty_log {
+	__u32 slot;
+	__u32 padding1;
+	union {
+		compat_uptr_t dirty_bitmap; /* one bit per page */
+		__u64 padding2;
+	};
+};
+
+static long kvm_vm_compat_ioctl(struct file *filp,
+			   unsigned int ioctl, unsigned long arg)
+{
+	struct kvm *kvm = filp->private_data;
+	int r;
+
+	if (kvm->mm != current->mm)
+		return -EIO;
+	switch (ioctl) {
+	case KVM_GET_DIRTY_LOG: {
+		struct compat_kvm_dirty_log compat_log;
+		struct kvm_dirty_log log;
+
+		r = -EFAULT;
+		if (copy_from_user(&compat_log, (void __user *)arg, sizeof log))
+			goto out;
+		log.slot	 = compat_log.slot;
+		log.padding1	 = compat_log.padding1;
+		log.padding2	 = compat_log.padding2;
+		log.dirty_bitmap = compat_ptr(compat_log.dirty_bitmap);
+
+		r = kvm_vm_ioctl_get_dirty_log(kvm, &log.log);
+		if (r)
+			goto out;
+		break;
+	default:
+		r = kvm_vm_ioctl(filp, ioctl, arg);
+	}
+
+	return r;
+}
+#endif
+
 static int kvm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
 	struct page *page[1];
@@ -2331,7 +2374,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
 static struct file_operations kvm_vm_fops = {
 	.release        = kvm_vm_release,
 	.unlocked_ioctl = kvm_vm_ioctl,
-	.compat_ioctl   = kvm_vm_ioctl,
+	.compat_ioctl   = kvm_vm_compat_ioctl,
 	.mmap           = kvm_vm_mmap,
 };
 

  parent reply	other threads:[~2009-09-30 12:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29  8:18 [PATCH 26/27] Enable 32bit dirty log pointers on 64bit host Alexander Graf
2009-09-29  9:14 ` Avi Kivity
2009-09-29  9:17 ` Alexander Graf
2009-09-29 13:25 ` Avi Kivity
2009-09-29 14:08 ` Alexander Graf
2009-09-29 16:29 ` Alexander Graf
2009-09-29 16:42 ` Avi Kivity
2009-09-29 17:09 ` Alexander Graf
2009-09-30 12:04 ` Arnd Bergmann [this message]
2009-09-30 13:17 ` Avi Kivity
2009-09-30 13:29 ` Avi Kivity
2009-10-20 10:09 ` Alexander Graf
2009-10-20 13:23 ` Avi Kivity
2009-10-20 13:28 ` Alexander Graf
2009-10-20 13:32 ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200909301404.32367.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=kvm-ppc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox