From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Date: Tue, 29 Sep 2009 16:42:34 +0000 Subject: Re: [PATCH 26/27] Enable 32bit dirty log pointers on 64bit host Message-Id: <4AC238FA.9020804@redhat.com> List-Id: References: <1254212303-8737-27-git-send-email-agraf@suse.de> In-Reply-To: <1254212303-8737-27-git-send-email-agraf@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm-ppc@vger.kernel.org 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 > 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 > > 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; > > 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 :) -- error compiling committee.c: too many arguments to function