From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753937AbdEJPxU (ORCPT ); Wed, 10 May 2017 11:53:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59818 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753632AbdEJPxT (ORCPT ); Wed, 10 May 2017 11:53:19 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6E742ED247 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=bsd@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6E742ED247 From: Bandan Das To: "Huang\, Kai" Cc: kvm@vger.kernel.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] kvm: x86: Add a hook for arch specific dirty logging emulation References: <20170505192515.27833-1-bsd@redhat.com> <20170505192515.27833-2-bsd@redhat.com> <080e5575-8ae2-6d3a-7e4b-7ba512763b59@linux.intel.com> Date: Wed, 10 May 2017 11:53:09 -0400 In-Reply-To: <080e5575-8ae2-6d3a-7e4b-7ba512763b59@linux.intel.com> (Kai Huang's message of "Wed, 10 May 2017 22:49:13 +1200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 10 May 2017 15:53:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kai, "Huang, Kai" writes: > On 5/6/2017 7:25 AM, Bandan Das wrote: >> When KVM updates accessed/dirty bits, this hook can be used >> to invoke an arch specific function that implements/emulates >> dirty logging such as PML. >> >> Signed-off-by: Bandan Das >> --- >> arch/x86/include/asm/kvm_host.h | 2 ++ >> arch/x86/kvm/mmu.c | 15 +++++++++++++++ >> arch/x86/kvm/mmu.h | 1 + >> arch/x86/kvm/paging_tmpl.h | 4 ++++ >> 4 files changed, 22 insertions(+) >> >> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h >> index f5bddf92..9c761fe 100644 >> --- a/arch/x86/include/asm/kvm_host.h >> +++ b/arch/x86/include/asm/kvm_host.h >> @@ -1020,6 +1020,8 @@ struct kvm_x86_ops { >> void (*enable_log_dirty_pt_masked)(struct kvm *kvm, >> struct kvm_memory_slot *slot, >> gfn_t offset, unsigned long mask); >> + int (*write_log_dirty)(struct kvm_vcpu *vcpu); > > Hi, > > Thanks for adding PML to nested support! > > IMHO this callback is only used for write L2's dirty gpa to L1's PML > buffer, so probably it's better to change the name to something like: > nested_write_log_dirty. The name was meant more to signify what it does: i.e. write dirty log rather than where in the hierarchy it's being used :) But I guess, a nested_ prefix doesn't hurt either. Bandan > Thanks, > -Kai > >> + >> /* pmu operations of sub-arch */ >> const struct kvm_pmu_ops *pmu_ops; >> >> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c >> index 5586765..5d3376f 100644 >> --- a/arch/x86/kvm/mmu.c >> +++ b/arch/x86/kvm/mmu.c >> @@ -1498,6 +1498,21 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, >> kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); >> } >> >> +/** >> + * kvm_arch_write_log_dirty - emulate dirty page logging >> + * @vcpu: Guest mode vcpu >> + * >> + * Emulate arch specific page modification logging for the >> + * nested hypervisor >> + */ >> +int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu) >> +{ >> + if (kvm_x86_ops->write_log_dirty) >> + return kvm_x86_ops->write_log_dirty(vcpu); >> + >> + return 0; >> +} > > kvm_nested_arch_write_log_dirty? > >> + >> bool kvm_mmu_slot_gfn_write_protect(struct kvm *kvm, >> struct kvm_memory_slot *slot, u64 gfn) >> { >> diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h >> index d8ccb32..2797580 100644 >> --- a/arch/x86/kvm/mmu.h >> +++ b/arch/x86/kvm/mmu.h >> @@ -202,4 +202,5 @@ void kvm_mmu_gfn_disallow_lpage(struct kvm_memory_slot *slot, gfn_t gfn); >> void kvm_mmu_gfn_allow_lpage(struct kvm_memory_slot *slot, gfn_t gfn); >> bool kvm_mmu_slot_gfn_write_protect(struct kvm *kvm, >> struct kvm_memory_slot *slot, u64 gfn); >> +int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu); >> #endif >> diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h >> index 314d207..5624174 100644 >> --- a/arch/x86/kvm/paging_tmpl.h >> +++ b/arch/x86/kvm/paging_tmpl.h >> @@ -226,6 +226,10 @@ static int FNAME(update_accessed_dirty_bits)(struct kvm_vcpu *vcpu, >> if (level == walker->level && write_fault && >> !(pte & PT_GUEST_DIRTY_MASK)) { >> trace_kvm_mmu_set_dirty_bit(table_gfn, index, sizeof(pte)); >> +#if PTTYPE == PTTYPE_EPT >> + if (kvm_arch_write_log_dirty(vcpu)) >> + return -EINVAL; >> +#endif >> pte |= PT_GUEST_DIRTY_MASK; >> } >> if (pte == orig_pte) >>