From: Takuya Yoshikawa Subject: [PATCH 1/1] KVM: MMU: Fix 64-bit paging breakage on x86_32 Date: Thu, 28 Apr 2011 07:08:36 +0900 Message-ID: <20110428070836.4099477c.takuya.yoshikawa@gmail.com> References: <20110428070238.ba6e67aa.takuya.yoshikawa@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: jan.kiszka@web.de, kvm@vger.kernel.org To: avi@redhat.com, mtosatti@redhat.com Return-path: Received: from mail-pw0-f46.google.com ([209.85.160.46]:50447 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752349Ab1D0WIl (ORCPT ); Wed, 27 Apr 2011 18:08:41 -0400 Received: by pwi15 with SMTP id 15so920998pwi.19 for ; Wed, 27 Apr 2011 15:08:41 -0700 (PDT) In-Reply-To: <20110428070238.ba6e67aa.takuya.yoshikawa@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Takuya Yoshikawa Fix regression introduced by commit e30d2a170506830d5eef5e9d7990c5aedf1b0a51 KVM: MMU: Optimize guest page table walk On x86_32, get_user() does not support 64-bit values and we fail to build KVM at the point of 64-bit paging. This patch fixes this by using get_user() twice for that condition. Signed-off-by: Takuya Yoshikawa Reported-by: Jan Kiszka --- arch/x86/kvm/paging_tmpl.h | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 652d56c..7d36ac9 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -115,6 +115,20 @@ static unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, pt_element_t gpte) return access; } +static int FNAME(read_gpte)(pt_element_t *pte, pt_element_t __user *ptep_user) +{ +#if defined(CONFIG_X86_32) && (PTTYPE == 64) + u32 *p = (u32 *)pte; + u32 __user *p_user = (u32 __user *)ptep_user; + + if (unlikely(get_user(*p, p_user))) + return -EFAULT; + return get_user(*(p + 1), p_user + 1); +#else + return get_user(*pte, ptep_user); +#endif +} + /* * Fetch a guest pte for a guest virtual address */ @@ -185,7 +199,7 @@ walk: } ptep_user = (pt_element_t __user *)((void *)host_addr + offset); - if (unlikely(get_user(pte, ptep_user))) { + if (unlikely(FNAME(read_gpte)(&pte, ptep_user))) { present = false; break; } -- 1.7.1