From patchwork Mon Jun 20 13:38:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 897382 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5KDdVKi020155 for ; Mon, 20 Jun 2011 13:39:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754431Ab1FTNjM (ORCPT ); Mon, 20 Jun 2011 09:39:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43757 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754116Ab1FTNjM (ORCPT ); Mon, 20 Jun 2011 09:39:12 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5KDcuLM003995 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 20 Jun 2011 09:38:56 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5KDctwV003500; Mon, 20 Jun 2011 09:38:55 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 96DA518D4C4; Mon, 20 Jun 2011 16:38:54 +0300 (IDT) Date: Mon, 20 Jun 2011 16:38:54 +0300 From: Gleb Natapov To: Glauber Costa Cc: Avi Kivity , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Rik van Riel , Jeremy Fitzhardinge , Peter Zijlstra , Anthony Liguori , Eric B Munson Subject: Re: [PATCH 3/7] KVM-HV: KVM Steal time implementation Message-ID: <20110620133854.GA491@redhat.com> References: <1308007897-17013-4-git-send-email-glommer@redhat.com> <20110614074500.GM491@redhat.com> <4DF8226B.20408@redhat.com> <20110615090951.GQ491@redhat.com> <4DFDED2E.6030009@redhat.com> <20110619125956.GV491@redhat.com> <4DFDF35E.8030504@redhat.com> <20110620072128.GW491@redhat.com> <4DFEFE8A.4050101@redhat.com> <4DFF4037.20306@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4DFF4037.20306@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 20 Jun 2011 13:39:32 +0000 (UTC) On Mon, Jun 20, 2011 at 09:42:31AM -0300, Glauber Costa wrote: > On 06/20/2011 05:02 AM, Avi Kivity wrote: > >On 06/20/2011 10:21 AM, Gleb Natapov wrote: > >>On Sun, Jun 19, 2011 at 04:02:22PM +0300, Avi Kivity wrote: > >>> On 06/19/2011 03:59 PM, Gleb Natapov wrote: > >>> >On Sun, Jun 19, 2011 at 03:35:58PM +0300, Avi Kivity wrote: > >>> >> On 06/15/2011 12:09 PM, Gleb Natapov wrote: > >>> >> >> > >>> >> >> Actually, I'd expect most read/writes to benefit from caching, > >>no? > >>> >> >> So why don't we just rename kvm_write_guest_cached() to > >>> >> >> kvm_write_guest(), and the few places - if any - that need to > >>force > >>> >> >> transversing of the gfn mappings, get renamed to > >>> >> >> kvm_write_guest_uncached ? > >>> >> >> > >>> >> >Good idea. I do not see any places where > >>kvm_write_guest_uncached is > >>> >> >needed from a brief look. Avi? > >>> >> > > >>> >> > >>> >> kvm_write_guest_cached() needs something to supply the cache, and > >>> >> needs recurring writes to the same location. Neither of these are > >>> >> common (for example, instruction emulation doesn't have either). > >>> >> > >>> >Correct. Missed that. So what about changing steal time to use > >>> >kvm_write_guest_cached()? > >>> > >>> Makes sense, definitely. Want to post read_guest_cached() as well? > >>> > >>Glauber can you write read_guest_cached() as part of your series (should > >>be trivial), or do you want me to do it? I do not have a code to test it > >>with though :) > > > >Yes. > > > >(you can write it, and Glauber can include it in the series) > > > Write it, handle me the patch, I'll include it and test it. Only compile tested. --- Gleb. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html === Introduce kvm_read_guest_cached() function in addition to write one we already have. Signed-off-by: Gleb Natapov diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index fa2321a..bf62c76 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1414,6 +1414,26 @@ int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, } EXPORT_SYMBOL_GPL(kvm_write_guest_cached); +int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, + void *data, unsigned long len) +{ + struct kvm_memslots *slots = kvm_memslots(kvm); + int r; + + if (slots->generation != ghc->generation) + kvm_gfn_to_hva_cache_init(kvm, ghc, ghc->gpa); + + if (kvm_is_error_hva(ghc->hva)) + return -EFAULT; + + r = __copy_from_user(data, (void __user *)ghc->hva, len); + if (r) + return -EFAULT; + + return 0; +} +EXPORT_SYMBOL_GPL(kvm_read_guest_cached); + int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len) { return kvm_write_guest_page(kvm, gfn, (const void *) empty_zero_page,