From patchwork Tue May 6 00:40:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bandan Das X-Patchwork-Id: 4118411 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2C7D3BFF02 for ; Tue, 6 May 2014 00:41:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4898D201CE for ; Tue, 6 May 2014 00:41:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 724BA2017D for ; Tue, 6 May 2014 00:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933525AbaEFAlR (ORCPT ); Mon, 5 May 2014 20:41:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56284 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933498AbaEFAlP (ORCPT ); Mon, 5 May 2014 20:41:15 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s460fEft002127 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 May 2014 20:41:14 -0400 Received: from nelium.bos.redhat.com ([10.18.25.173]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s460f8xe013853; Mon, 5 May 2014 20:41:13 -0400 From: Bandan Das To: kvm@vger.kernel.org Cc: Paolo Bonzini , Marcelo Tosatti , Gleb Natapov , linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/3] KVM: x86: use memory_prepare in fetch helper function Date: Mon, 5 May 2014 20:40:58 -0400 Message-Id: <1399336859-7227-3-git-send-email-bsd@redhat.com> In-Reply-To: <1399336859-7227-1-git-send-email-bsd@redhat.com> References: <1399336859-7227-1-git-send-email-bsd@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Insn fetch fastpath function. Not that arch.walk_mmu->gva_to_gpa can't be used but let's piggyback on top of interface meant for our purpose Signed-off-by: Bandan Das --- arch/x86/kvm/x86.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 17e3d661..cf69e3b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4065,29 +4065,38 @@ static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes, struct x86_exception *exception) { void *data = val; - struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); int r = X86EMUL_CONTINUE; while (bytes) { - gpa_t gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, addr, access, - exception); unsigned offset = addr & (PAGE_SIZE-1); unsigned toread = min(bytes, (unsigned)PAGE_SIZE - offset); int ret; + unsigned long uaddr; - if (gpa == UNMAPPED_GVA) - return X86EMUL_PROPAGATE_FAULT; - ret = kvm_read_guest(vcpu->kvm, gpa, data, toread); + ret = ctxt->ops->memory_prepare(ctxt, addr, toread, + exception, false, + NULL, &uaddr); + if (ret != X86EMUL_CONTINUE) + return ret; + + if (unlikely(kvm_is_error_hva(uaddr))) { + r = X86EMUL_PROPAGATE_FAULT; + return r; + } + + ret = __copy_from_user(data, (void __user *)uaddr, toread); if (ret < 0) { r = X86EMUL_IO_NEEDED; - goto out; + return r; } + ctxt->ops->memory_finish(ctxt, NULL, uaddr); + bytes -= toread; data += toread; addr += toread; } -out: + return r; }