From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50174C433F5 for ; Sun, 16 Jan 2022 11:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbiAPLOv (ORCPT ); Sun, 16 Jan 2022 06:14:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbiAPLOv (ORCPT ); Sun, 16 Jan 2022 06:14:51 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED5E0C061574 for ; Sun, 16 Jan 2022 03:14:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7C428B80CE1 for ; Sun, 16 Jan 2022 11:14:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CB10C36AE7; Sun, 16 Jan 2022 11:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642331688; bh=Dw0+z61Vby/g7tcwmetTaqn/iWYBUMkRvaEd2Kb/vn0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DGM1xzM1Omt2Sje4rdsN74k0jFar+68yXfodjr5bflHxrASLxz3E8Se5I73gyyMHD vu2Lvlw+nvGImJ4piB99Lzf1w6yjDqxV79Y31AMk7wYTZ36+P5pORqQDmtACufJH5L JYhxuqnrZdovA2e6XYcXcjynGQAx62ZxInfvyibgakxV5eZjyOILKjXMtfaRQ1JzB2 OaXoROs/nKpZMsLq5YRr9HeEgeoCo7aq3PaBnKJU1V+4TIcIxvpLwUypkr7pqVcWw0 S9oWSkG/YL8FrCsU63eMpkK7OrOKEFj3NyvQcDBeu/MaL1YNJCFHHusFo6TbLUA67+ VotKEetvBWWSw== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n93Uk-000lKC-2B; Sun, 16 Jan 2022 11:14:46 +0000 Date: Sun, 16 Jan 2022 11:14:46 +0000 Message-ID: <87wnj0x789.wl-maz@kernel.org> From: Marc Zyngier To: Jing Zhang Cc: KVM , KVMARM , Will Deacon , Paolo Bonzini , David Matlack , Oliver Upton , Reiji Watanabe , Ricardo Koller , Raghavendra Rao Ananta Subject: Re: [PATCH v1 2/3] KVM: arm64: Add fast path to handle permission relaxation during dirty logging In-Reply-To: <20220113221829.2785604-3-jingzhangos@google.com> References: <20220113221829.2785604-1-jingzhangos@google.com> <20220113221829.2785604-3-jingzhangos@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: jingzhangos@google.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, pbonzini@redhat.com, dmatlack@google.com, oupton@google.com, reijiw@google.com, ricarkol@google.com, rananta@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, 13 Jan 2022 22:18:28 +0000, Jing Zhang wrote: > > To reduce MMU lock contention during dirty logging, all permission > relaxation operations would be performed under read lock. > > Signed-off-by: Jing Zhang > --- > arch/arm64/kvm/mmu.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index cafd5813c949..15393cb61a3f 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1084,6 +1084,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > unsigned long vma_pagesize, fault_granule; > enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; > struct kvm_pgtable *pgt; > + bool use_mmu_readlock = false; Group this with the rest of the flags. It would also be better if it described the condition this represent rather than what we use it for. For example, 'perm_fault_while_logging', or something along those lines. > > fault_granule = 1UL << ARM64_HW_PGTABLE_LEVEL_SHIFT(fault_level); > write_fault = kvm_is_write_fault(vcpu); > @@ -1212,7 +1213,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > if (exec_fault && device) > return -ENOEXEC; > > - write_lock(&kvm->mmu_lock); > + if (fault_status == FSC_PERM && fault_granule == PAGE_SIZE > + && logging_active && write_fault) > + use_mmu_readlock = true; This looks a bit clumsy, and would be better if this was kept together with the rest of the logging_active==true code. Something like: diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index bc2aba953299..59b1d5f46b06 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1114,6 +1114,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, if (logging_active) { force_pte = true; vma_shift = PAGE_SHIFT; + use_readlock = (fault_status == FSC_PERM && write_fault); } else { vma_shift = get_vma_page_shift(vma, hva); } I don't think we have to check for fault_granule here, as I don't see how you could get a permission fault for something other than a page size mapping. > + /* > + * To reduce MMU contentions and enhance concurrency during dirty > + * logging dirty logging, only acquire read lock for permission > + * relaxation. This fast path would greatly reduce the performance > + * degradation of guest workloads. > + */ This comment makes more sense with the previous hunk. Drop the last sentence though, as it doesn't bring much information. > + if (use_mmu_readlock) > + read_lock(&kvm->mmu_lock); > + else > + write_lock(&kvm->mmu_lock); > pgt = vcpu->arch.hw_mmu->pgt; > if (mmu_notifier_retry(kvm, mmu_seq)) > goto out_unlock; > @@ -1271,7 +1284,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > } > > out_unlock: > - write_unlock(&kvm->mmu_lock); > + if (use_mmu_readlock) > + read_unlock(&kvm->mmu_lock); > + else > + write_unlock(&kvm->mmu_lock); > kvm_set_pfn_accessed(pfn); > kvm_release_pfn_clean(pfn); > return ret != -EAGAIN ? ret : 0; Thanks, M. -- Without deviation from the norm, progress is not possible.