On 29.09.2009, at 18:42, Avi Kivity wrote:

On 09/29/2009 06:29 PM, Alexander Graf wrote:

How about this one? (broken whitespace!)

From c3864a2c5e1fccff7839e47f12c09d9739ca441e Mon Sep 17 00:00:00 2001
From: Alexander Graf <ag...@suse.de>
Date: Thu, 23 Jul 2009 21:05:57 +0200
Subject: [PATCH] Enable 32bit dirty log pointers on 64bit host

With big endian userspace, passing a pointer from 32-bit userspace to
64-bit kernel space breaks.

This is what happens with dirty logging. To get the pointer interpreted correctly, we can just check the guest's 32bit flag and treat the pointer
as 32 bits then.

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

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e27b7a9..00f2c59 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -703,6 +703,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
       int r, i;
       int n;
       unsigned long any = 0;
+       void *target_bm;

void __user *target_bm;

k, done.



       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 :)

Heh, yeah :). At times like this I see the benefits of little endian...

The new code is in git://csgraf.de/kvm branch ppc-v5.
(Don't expect to pull updates from that branch until I release it - I will push -f in there, breaking git pull.)

Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to