Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753543AbbFEMK6 (ORCPT ); Fri, 5 Jun 2015 08:10:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38388 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751693AbbFEMK4 (ORCPT ); Fri, 5 Jun 2015 08:10:56 -0400 Date: Fri, 5 Jun 2015 14:10:52 +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: <20150605121051.GD11957@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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5571795B.6080204@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2480 Lines: 78 2015-06-05 12:26+0200, Paolo Bonzini: > On 29/05/2015 21:23, Radim Krčmář wrote: >>> > +int kvm_vcpu_write_guest(struct kvm_vcpu *vcpu, gpa_t gpa, const void *data, >>> > + unsigned long len) >>> > +{ | [...] >>> > +} >> (There is no need to pass vcpu, and kvm, in this API. > > How so? A single kvm_vcpu_write_guest can cross multiple slots. I meant passing 'struct kvm_memslots *' instead and as soon as possible, which would still allow more slots. Something like this hunk: diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 10ae7e348dcc..8c6d84c12f18 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1718,8 +1718,8 @@ int kvm_vcpu_write_guest_page(struct kvm_vcpu *vcpu, gfn_t gfn, } EXPORT_SYMBOL_GPL(kvm_vcpu_write_guest_page); -int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, - unsigned long len) +static int __kvm_write_guest(struct kvm_memslots *slots, gpa_t gpa, const void *data, + unsigned long len) { gfn_t gfn = gpa >> PAGE_SHIFT; int seg; @@ -1727,7 +1727,8 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, int ret; while ((seg = next_segment(len, offset)) != 0) { - ret = kvm_write_guest_page(kvm, gfn, data, offset, seg); + ret = __kvm_write_guest_page(__gfn_to_memslot(slots, gfn), gfn, + data, offset, seg); if (ret < 0) return ret; offset = 0; @@ -1737,26 +1738,18 @@ int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, } return 0; } + +int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, + unsigned long len) +{ + return __kvm_write_guest(kvm_memslots(kvm), gpa, data, len); +} EXPORT_SYMBOL_GPL(kvm_write_guest); int kvm_vcpu_write_guest(struct kvm_vcpu *vcpu, gpa_t gpa, const void *data, unsigned long len) { - gfn_t gfn = gpa >> PAGE_SHIFT; - int seg; - int offset = offset_in_page(gpa); - int ret; - - while ((seg = next_segment(len, offset)) != 0) { - ret = kvm_vcpu_write_guest_page(vcpu, gfn, data, offset, seg); - if (ret < 0) - return ret; - offset = 0; - len -= seg; - data += seg; - ++gfn; - } - return 0; + return __kvm_write_guest(kvm_vcpu_memslots(vcpu), gpa, data, len); } EXPORT_SYMBOL_GPL(kvm_vcpu_write_guest); -- 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/