Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423054AbbFEPNq (ORCPT ); Fri, 5 Jun 2015 11:13:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47333 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422909AbbFEPNm (ORCPT ); Fri, 5 Jun 2015 11:13:42 -0400 Date: Fri, 5 Jun 2015 17:13:37 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, guangrong.xiao@linux.intel.com, bdas@redhat.com Subject: Re: [PATCH v2 07/13] KVM: add vcpu-specific functions to read/write/translate GFNs Message-ID: <20150605151337.GA16327@potion.brq.redhat.com> References: <1432746314-50196-1-git-send-email-pbonzini@redhat.com> <1432746314-50196-8-git-send-email-pbonzini@redhat.com> <20150529192346.GA11651@potion.brq.redhat.com> <5571795B.6080204@redhat.com> <20150605121051.GD11957@potion.brq.redhat.com> <55719A2F.3030301@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55719A2F.3030301@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3003 Lines: 79 2015-06-05 14:46+0200, Paolo Bonzini: > On 05/06/2015 14:10, Radim Krčmář wrote: > > + ret = __kvm_write_guest_page(__gfn_to_memslot(slots, gfn), gfn, > > + data, offset, seg); > > Even better, let's pass memslots to all the __ functions. Yeah, while scoping it, I noticed a bug in the series ... makes me wish that C had a useful type system. A quick fix would be to replace gpa with gfn in calls to __kvm_read_guest_atomic(). I presume you'd prefer a new patch to rebasing, so it's below. --- KVM: fix gpa/gfn mixup in __kvm_read_guest_atomic Refactoring passed gpa instead of gfn to __kvm_read_guest_atomic. While at it, lessen code duplication by extracting slots earlier. Fixes: 841509f38372 ("KVM: add vcpu-specific functions to read/write/translate GFNs") Signed-off-by: Radim Krčmář --- virt/kvm/kvm_main.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 10ae7e348dcc..4fa1edc34630 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1645,11 +1645,14 @@ int kvm_vcpu_read_guest(struct kvm_vcpu *vcpu, gpa_t gpa, void *data, unsigned l } EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest); -static int __kvm_read_guest_atomic(struct kvm_memory_slot *slot, gfn_t gfn, - void *data, int offset, unsigned long len) +static int __kvm_read_guest_atomic(struct kvm_memslots *slots, gpa_t gpa, + void *data, unsigned long len) { int r; unsigned long addr; + gfn_t gfn = gpa >> PAGE_SHIFT; + struct kvm_memory_slot *slot = __gfn_to_memslot(slots, gfn); + int offset = offset_in_page(gpa); addr = gfn_to_hva_memslot_prot(slot, gfn, NULL); if (kvm_is_error_hva(addr)) @@ -1665,22 +1668,18 @@ static int __kvm_read_guest_atomic(struct kvm_memory_slot *slot, gfn_t gfn, int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) { - gfn_t gfn = gpa >> PAGE_SHIFT; - struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); - int offset = offset_in_page(gpa); + struct kvm_memslots *slots = kvm_memslots(kvm); - return __kvm_read_guest_atomic(slot, gpa, data, offset, len); + return __kvm_read_guest_atomic(slots, gpa, data, len); } EXPORT_SYMBOL_GPL(kvm_read_guest_atomic); int kvm_vcpu_read_guest_atomic(struct kvm_vcpu *vcpu, gpa_t gpa, void *data, unsigned long len) { - gfn_t gfn = gpa >> PAGE_SHIFT; - struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn); - int offset = offset_in_page(gpa); + struct kvm_memslots *slots = kvm_vcpu_memslots(vcpu); - return __kvm_read_guest_atomic(slot, gpa, data, offset, len); + return __kvm_read_guest_atomic(slots, gpa, data, len); } EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest_atomic); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/