From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753691AbbDHJ0U (ORCPT ); Wed, 8 Apr 2015 05:26:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58390 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753627AbbDHJ0P (ORCPT ); Wed, 8 Apr 2015 05:26:15 -0400 Date: Wed, 8 Apr 2015 11:26:12 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH] KVM: dirty all pages in kvm_write_guest_cached() Message-ID: <20150408092611.GA2164@potion.brq.redhat.com> References: <1428438897-22206-1-git-send-email-rkrcmar@redhat.com> <5524EBB7.3080906@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5524EBB7.3080906@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2015-04-08 10:49+0200, Paolo Bonzini: > On 07/04/2015 22:34, Radim Krčmář wrote: > > We dirtied only one page because writes originally couldn't span more. > > Use improved syntax for '>> PAGE_SHIFT' while at it. > > > > Fixes: 8f964525a121 ("KVM: Allow cross page reads and writes from cached translations.") > > Signed-off-by: Radim Krčmář > > Cross-page reads and writes should never get here; they have > ghc->memslot set to NULL and go through the slow path in kvm_write_guest. Only cross-memslot writes have NULL memslot. > What am I missing? kvm_gfn_to_hva_cache_init() queries how many pages are remaining in the memslot and it compares it with the amount of needed pages. If the write will fit in memslot, it will be done without kvm_write_guest, regardless of the amount of written pages. The relevant code path in kvm_gfn_to_hva_cache_init(): gfn_t nr_pages_needed = end_gfn - start_gfn + 1; ghc->memslot = gfn_to_memslot(kvm, start_gfn); ghc->hva = gfn_to_hva_many(ghc->memslot, start_gfn, &nr_pages_avail); if (!kvm_is_error_hva(ghc->hva) && nr_pages_avail >= nr_pages_needed) ghc->hva += offset; return 0;