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 X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29607C433E2 for ; Tue, 8 Sep 2020 16:24:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C5FE3205CB for ; Tue, 8 Sep 2020 16:24:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jpRKlb/I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5FE3205CB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=maIzVPzBsfNzVL2O+Soqfz5aTARagsCUtCA5b8lIyX0=; b=jpRKlb/I6ZpdKn500rxBqjLOY NzrKWgQSM5n1ZPi/RtfROGCH6NBzs+VilN9somLgs4CJFN0dxBYTilJdja1gl5La6js7uHV2t0LTk mYG7F/VL2Yb79+gcI2Nt90tZkuTv+jqPadhrxY101zY9wY0ghudQAKFuWqzcVwpLasQb31uT5cVh7 CA606m5mQpx64LgvEc6LYh0otH/K3SqvTG2iyxQDRMgM4XVSvukFYw8bitNmEhEfvTJWz5/AYzA8G 93wvupn3WIQQBcov6fD/MEwQAguL01Khc+DArN65nkWxHhSkyOf0i4aic8+h02PyXrr4QmhVwdUFn oChW0389Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFfho-0006DD-Cv; Tue, 08 Sep 2020 15:38:48 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFfhk-0006CI-RO for linux-arm-kernel@lists.infradead.org; Tue, 08 Sep 2020 15:38:45 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0F5001045; Tue, 8 Sep 2020 08:38:44 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B74A33F73C; Tue, 8 Sep 2020 08:38:42 -0700 (PDT) Subject: Re: [PATCH v4 11/21] KVM: arm64: Convert page-aging and access faults to generic page-table API To: Will Deacon , kvmarm@lists.cs.columbia.edu References: <20200907152344.12978-1-will@kernel.org> <20200907152344.12978-12-will@kernel.org> From: Alexandru Elisei Message-ID: Date: Tue, 8 Sep 2020 16:39:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200907152344.12978-12-will@kernel.org> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200908_113845_000077_5C282D49 X-CRM114-Status: GOOD ( 25.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gavin Shan , Suzuki Poulose , Marc Zyngier , Quentin Perret , James Morse , Catalin Marinas , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Will, On 9/7/20 4:23 PM, Will Deacon wrote: > Convert the page-aging functions and access fault handler to use the > generic page-table code instead of walking the page-table directly. > > Cc: Marc Zyngier > Cc: Quentin Perret > Reviewed-by: Gavin Shan > Signed-off-by: Will Deacon > --- > arch/arm64/kvm/mmu.c | 74 ++++++++++---------------------------------- > 1 file changed, 16 insertions(+), 58 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index a7021509231c..a036aac3ed24 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1703,46 +1703,23 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > return ret; > } > > -/* > - * Resolve the access fault by making the page young again. > - * Note that because the faulting entry is guaranteed not to be > - * cached in the TLB, we don't need to invalidate anything. > - * Only the HW Access Flag updates are supported for Stage 2 (no DBM), > - * so there is no need for atomic (pte|pmd)_mkyoung operations. > - */ > +/* Resolve the access fault by making the page young again. */ > static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) > { > - pud_t *pud; > - pmd_t *pmd; > - pte_t *pte; > - kvm_pfn_t pfn; > - bool pfn_valid = false; > + pte_t pte; > + kvm_pte_t kpte; > + struct kvm_s2_mmu *mmu; > > trace_kvm_access_fault(fault_ipa); > > spin_lock(&vcpu->kvm->mmu_lock); > - > - if (!stage2_get_leaf_entry(vcpu->arch.hw_mmu, fault_ipa, &pud, &pmd, &pte)) > - goto out; > - > - if (pud) { /* HugeTLB */ > - *pud = kvm_s2pud_mkyoung(*pud); > - pfn = kvm_pud_pfn(*pud); > - pfn_valid = true; > - } else if (pmd) { /* THP, HugeTLB */ > - *pmd = pmd_mkyoung(*pmd); > - pfn = pmd_pfn(*pmd); > - pfn_valid = true; > - } else { > - *pte = pte_mkyoung(*pte); /* Just a page... */ > - pfn = pte_pfn(*pte); > - pfn_valid = true; > - } > - > -out: > + mmu = vcpu->arch.hw_mmu; > + kpte = kvm_pgtable_stage2_mkyoung(mmu->pgt, fault_ipa); > spin_unlock(&vcpu->kvm->mmu_lock); > - if (pfn_valid) > - kvm_set_pfn_accessed(pfn); > + > + pte = __pte(kpte); > + if (pte_valid(pte)) > + kvm_set_pfn_accessed(pte_pfn(pte)); > } > > /** > @@ -1959,38 +1936,19 @@ int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) > > static int kvm_age_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data) > { > - pud_t *pud; > - pmd_t *pmd; > - pte_t *pte; > + pte_t pte; > + kvm_pte_t kpte; > > WARN_ON(size != PAGE_SIZE && size != PMD_SIZE && size != PUD_SIZE); > - if (!stage2_get_leaf_entry(&kvm->arch.mmu, gpa, &pud, &pmd, &pte)) > - return 0; > - > - if (pud) > - return stage2_pudp_test_and_clear_young(pud); > - else if (pmd) > - return stage2_pmdp_test_and_clear_young(pmd); > - else > - return stage2_ptep_test_and_clear_young(pte); > + kpte = kvm_pgtable_stage2_mkold(kvm->arch.mmu.pgt, gpa); > + pte = __pte(kpte); > + return pte_valid(pte) && pte_young(pte); I checked that the semantics of the return value are preserved. The old version of the function returned 1 if stage2_get_leaf_entry() returned true (entry was found and it was valid) and the entry was young, which is equivalent to pte_valid(pte) && pte_young(pte). > } > > static int kvm_test_age_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data) > { > - pud_t *pud; > - pmd_t *pmd; > - pte_t *pte; > - > WARN_ON(size != PAGE_SIZE && size != PMD_SIZE && size != PUD_SIZE); > - if (!stage2_get_leaf_entry(&kvm->arch.mmu, gpa, &pud, &pmd, &pte)) > - return 0; > - > - if (pud) > - return kvm_s2pud_young(*pud); > - else if (pmd) > - return pmd_young(*pmd); > - else > - return pte_young(*pte); > + return kvm_pgtable_stage2_is_young(kvm->arch.mmu.pgt, gpa); > } Reviewed-by: Alexandru Elisei Thanks, Alex > > int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel