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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 436EAC433F5 for ; Thu, 9 Dec 2021 10:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8e0hRbsmlS3HbAvERTJEWH1psRoBtxGeJrqqWKynVWI=; b=Kw4yAcmkQB99Kw HBeGkb6emPTBlUKCfjbgb70bD1UIoAmn41AqwEmR0uuLkLvvzRCT+zMkFyw3EvJ/HTnnJEU2CibRF TYJ5F8vmRr/mF0fz5xqKpFOM+/VJWamoXYUsU5MUn+UGgbqN6R7V5uk3+dUrjheiKTDLyPB1j2apQ OQJnSe8SYnIzKEp6iQ5IHwFXYpq9dgTSZDTq9U7+hZ7vU3qYiZ0Ra30G6NK7GKHpZAVLLJxVYGWsh hRrvqatF+WH3ARLIOC8Y7K5VPalrmx+nOyjj/yQxx9tYM3WyOjV1c5ZqZYmJXC56l57hma9IUYRBP 7EwP3FBHqqyAS6LGC5mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvGgC-00Fcay-W6; Thu, 09 Dec 2021 10:29:37 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvGg8-00FcZu-EK for linux-arm-kernel@lists.infradead.org; Thu, 09 Dec 2021 10:29:33 +0000 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 17651B82413; Thu, 9 Dec 2021 10:29:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0745EC004DD; Thu, 9 Dec 2021 10:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639045769; bh=/QmpjCuL6s7njp6n+riNneGXXg+eNgJnvQsS9FTssPs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kg0OeLHSNtdKhMVXmUzK4SbKdfW/VPLENXZuwCaVbwkm3WO4VU8H9W5Tis5BKW2/1 hwLrw/mYRHZXzd3PuTFvKdF6WA4nzlv+icBWWczLcuscBt3cIajskOgByQRmpV+JI8 ddtFZja/LVZRt7kzrq2fVnqLfl7KTKBDw7GhZfsDLSfsV0FeGSA5xQZBEb3xhl11uB mUEl5zf/Ehn3amARhmC8KMYAC8b92UbnjJBS1cNqb7BpI1CwDDaUPZPuZxJtLAR8TU ICRbqfkcKDcZjU2UPInYyCCz2OfMr/bCQNJoqNRwi5lBSJ0Qevao1eN9lEBRiQXRhB 8QJb5R4CJQJOQ== Date: Thu, 9 Dec 2021 10:29:24 +0000 From: Will Deacon To: Quentin Perret Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 03/15] KVM: arm64: Refcount hyp stage-1 pgtable pages Message-ID: <20211209102924.GC1833@willie-the-truck> References: <20211201170411.1561936-1-qperret@google.com> <20211201170411.1561936-4-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211201170411.1561936-4-qperret@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211209_022932_645183_B477F408 X-CRM114-Status: GOOD ( 20.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 On Wed, Dec 01, 2021 at 05:03:57PM +0000, Quentin Perret wrote: > To prepare the ground for allowing hyp stage-1 mappings to be removed at > run-time, update the KVM page-table code to maintain a correct refcount > using the ->{get,put}_page() function callbacks. > > Signed-off-by: Quentin Perret > --- > arch/arm64/kvm/hyp/pgtable.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index f8ceebe4982e..768a58835153 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -408,8 +408,10 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > return false; > > new = kvm_init_valid_leaf_pte(phys, data->attr, level); > - if (hyp_pte_needs_update(old, new)) > + if (hyp_pte_needs_update(old, new)) { > smp_store_release(ptep, new); > + data->mm_ops->get_page(ptep); In the case where we're just updating software bits for a valid pte, doesn't this result in us taking a spurious reference to the page? > @@ -482,8 +485,16 @@ static int hyp_free_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, > enum kvm_pgtable_walk_flags flag, void * const arg) > { > struct kvm_pgtable_mm_ops *mm_ops = arg; > + kvm_pte_t pte = *ptep; > + > + if (!kvm_pte_valid(pte)) > + return 0; > + > + mm_ops->put_page(ptep); > + > + if (kvm_pte_table(pte, level)) > + mm_ops->put_page(kvm_pte_follow(pte, mm_ops)); > > - mm_ops->put_page((void *)kvm_pte_follow(*ptep, mm_ops)); > return 0; This looks pretty similar to the stage-2 walker now, but given how small the functions are, I'm not sure we'd really gain much by abstracting the "pte counted" check. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel