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 52C01C433EF for ; Thu, 9 Dec 2021 11:24:11 +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=dvQ76OMNJuVSZ0NgGiY4Nkp959OY6S56JpnMYSPq9F8=; b=Cfxs/HfJ3HeZMm OaQgFp1ek+RPNiOqjp7QpudZNvO45/k1VTF8sBGcdQZsZsSSXnakPVa2+H/bQ66LFXyA8dQC+USjQ 8IGrZq+mAu+SqT/jJwy+BLz64XJ4gZcmYwm3TmcBsC+sj+TrAOFIEak+c88FKSrT3gPsVH+oe4h60 xsMHo3zhkcByK2ZJ6TwfaJDfeiLe6ra0xDH7SQZ9FxZ5pXTr5hx4bsxvEV5KtDF3oymrLmre/YKOM xrfldXeGG1aJvWMMAuWILTNcsIcSHnKXK+hT4xukoZsZQEGJ5viQ9oSr17QA47iQAYYSFa0p8EOLZ pgpaq68LtDHFqmVTSEww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvHVb-00FmRK-FJ; Thu, 09 Dec 2021 11:22:43 +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 1mvHVY-00FmQS-4M for linux-arm-kernel@lists.infradead.org; Thu, 09 Dec 2021 11:22:41 +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 D2B98B8245A; Thu, 9 Dec 2021 11:22:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0BDCC004DD; Thu, 9 Dec 2021 11:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639048958; bh=O1MP/jZT+iP4CkJdmDjsljgxpj4vHoKDEn9+msO/wM0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P294UhYKpxbWw0WFvDMWrDL/T6MfhlqNnKVGPQ8P3Z7ZZ+hfspik40BxDTCBh/rxi 6TQxm2Jejt4fvjCCGXw7y82pDgzM009JJE3pmSHDD9Cxs/7NlxXsBmbhfVIVZPm2bk N4Af7QeOraNbUqP31lZtjAn5NzPe+cQ9LegtlzchMORBPTj3NKOGVkQNIkAxI2jfmE 7u2BVdFlx23AzXUGOVAFmzjBaCCEy/h7GbMYRvH/S6zY5CVRNrIsbjk5Gv+8RK5qY8 Xc0Eu1kFmCkeF1uwbicAyRRTiFWd3QBgdX7cC11otsI144MXQfin+szwb2ESmP1au5 /KCjvZDPvPnPA== Date: Thu, 9 Dec 2021 11:22:33 +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 15/15] KVM: arm64: pkvm: Unshare guest structs during teardown Message-ID: <20211209112233.GD1912@willie-the-truck> References: <20211201170411.1561936-1-qperret@google.com> <20211201170411.1561936-16-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211201170411.1561936-16-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_032240_332957_17C0E337 X-CRM114-Status: GOOD ( 22.63 ) 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:04:09PM +0000, Quentin Perret wrote: > Make use of the newly introduced unshare hypercall during guest teardown > to unmap guest-related data structures from the hyp stage-1. > > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_host.h | 2 ++ > arch/arm64/include/asm/kvm_mmu.h | 1 + > arch/arm64/kvm/arm.c | 2 ++ > arch/arm64/kvm/fpsimd.c | 34 ++++++++++++++++++++++--- > arch/arm64/kvm/mmu.c | 42 +++++++++++++++++++++++++++++++ > arch/arm64/kvm/reset.c | 8 +++++- > 6 files changed, 85 insertions(+), 4 deletions(-) [...] > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index d72566896755..8e506ba8988e 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -344,6 +344,32 @@ static int share_pfn_hyp(u64 pfn) > return ret; > } > > +static int unshare_pfn_hyp(u64 pfn) > +{ > + struct rb_node **node, *parent; > + struct hyp_shared_pfn *this; > + int ret = 0; > + > + mutex_lock(&hyp_shared_pfns_lock); > + this = find_shared_pfn(pfn, &node, &parent); > + if (WARN_ON(!this)) { > + ret = -EINVAL; -ENOENT? > + goto unlock; > + } > + > + this->count--; > + if (this->count) > + goto unlock; Again, if we did an RCU lookup then this could be converted to a refcount_t to take the mutex only when it hits zero. But for now I think it's fine. > + > + rb_erase(&this->node, &hyp_shared_pfns); > + kfree(this); > + ret = kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, pfn, 1); > +unlock: > + mutex_unlock(&hyp_shared_pfns_lock); > + > + return ret; > +} > + > int kvm_share_hyp(void *from, void *to) > { > phys_addr_t start, end, cur; > @@ -376,6 +402,22 @@ int kvm_share_hyp(void *from, void *to) > return 0; > } > > +void kvm_unshare_hyp(void *from, void *to) > +{ > + phys_addr_t start, end, cur; > + u64 pfn; > + > + if (is_kernel_in_hyp_mode() || kvm_host_owns_hyp_mappings() || !from) I don't think you need the is_kernel_in_hyp_mode() check any more not that you've moved that into kvm_host_owns_hyp_mappings(). Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel