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=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 B9433C433DB for ; Mon, 15 Mar 2021 16:38:08 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 5E5C964F26 for ; Mon, 15 Mar 2021 16:38:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E5C964F26 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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=desiato.20200630; 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=8lLA8EohKCodI1yrJpKMYep4+aCK7Qmq8R4Ok0iryXo=; b=OCNtV2Ru3Kc63rB9oV4NnOkkv JvHxopalbWgZ00TrkWCqA4EQmckit4j4DDdgdRkPJ6fF5/eK8jeX0o2LOfSE3uQN8gLP1LN3vFfq7 oNoynuJc22rMyn0+FwNQSEpo/4lVOigkzncWHLb9PNgPU/C+n3+KX/Mwt3qjfY0gciaLbna/e5uoK MgasqpJDpfxnDjvXUG+ROMbgFwnovi2bzu4kNqaUcTLR1wTTFEFb2bQEOoYZ+IhiuygqZNc6Nexdu ropV5MGXlbo4mxePGWnfm+Tmtb9P9udExmdP4bEDfHeFWB3fgDljL+gLt3JGBkgNvu/+eGzaKiLXu HVOq81n2w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lLqCp-00GNHe-SD; Mon, 15 Mar 2021 16:36:36 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lLqCg-00GNFl-OG for linux-arm-kernel@lists.infradead.org; Mon, 15 Mar 2021 16:36:30 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 68FD764F2A; Mon, 15 Mar 2021 16:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615826185; bh=1Xwscs3ewFC/ckcZe2Mub61AbvcLlOZQm3jYjGo/Hps=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ftzkhVltLnJUDH+nslYFoDibNxchiIwqSBYAUyqmUoyhKSpgMDUw7gZ00SxPD/pRz x7rQjqklacB+cNMb53guaeOxIX44Mk1oKTS7FxAZwIP6PEopHnHSelS3tVWvAj80yD i3foenEICDDkEXvU7xs31FDEjJExZV2+Ojfj7SptG84iWLgbQw2JHYdIkeWHz7WO+c jzP7oxaRVCISCyU3EwXoJy/XIhxPto+N+dEKrZXXa2DSJNOaokpeZBGFnhcMNVMaDk /uwayLS3iXaCPBamwUps2QVNsoF7dTEMN4APU3MuBHJsj6KhonXZNTlS01h0Z2GgMx 3VSgaaJf9KEmg== Date: Mon, 15 Mar 2021 16:36:19 +0000 From: Will Deacon To: Quentin Perret Cc: catalin.marinas@arm.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, android-kvm@google.com, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com Subject: Re: [PATCH v5 29/36] KVM: arm64: Use page-table to track page ownership Message-ID: <20210315163618.GF3430@willie-the-truck> References: <20210315143536.214621-1-qperret@google.com> <20210315143536.214621-30-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210315143536.214621-30-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-20210315_163629_123787_E6DA8156 X-CRM114-Status: GOOD ( 24.87 ) 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 Mon, Mar 15, 2021 at 02:35:29PM +0000, Quentin Perret wrote: > As the host stage 2 will be identity mapped, all the .hyp memory regions > and/or memory pages donated to protected guestis will have to marked > invalid in the host stage 2 page-table. At the same time, the hypervisor > will need a way to track the ownership of each physical page to ensure > memory sharing or donation between entities (host, guests, hypervisor) is > legal. > > In order to enable this tracking at EL2, let's use the host stage 2 > page-table itself. The idea is to use the top bits of invalid mappings > to store the unique identifier of the page owner. The page-table owner > (the host) gets identifier 0 such that, at boot time, it owns the entire > IPA space as the pgd starts zeroed. > > Provide kvm_pgtable_stage2_set_owner() which allows to modify the > ownership of pages in the host stage 2. It re-uses most of the map() > logic, but ends up creating invalid mappings instead. This impacts > how we do refcount as we now need to count invalid mappings when they > are used for ownership tracking. > > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_pgtable.h | 21 +++++ > arch/arm64/kvm/hyp/pgtable.c | 127 ++++++++++++++++++++++----- > 2 files changed, 124 insertions(+), 24 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > index 4ae19247837b..683e96abdc24 100644 > --- a/arch/arm64/include/asm/kvm_pgtable.h > +++ b/arch/arm64/include/asm/kvm_pgtable.h > @@ -238,6 +238,27 @@ int kvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, > u64 phys, enum kvm_pgtable_prot prot, > void *mc); > > +/** > + * kvm_pgtable_stage2_set_owner() - Annotate invalid mappings with metadata > + * encoding the ownership of a page in the > + * IPA space. The function does more than this, though, as it will also go ahead and unmap existing valid mappings which I think should be mentioned here, no? > +int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, > + void *mc, u8 owner_id) > +{ > + int ret; > + struct stage2_map_data map_data = { > + .phys = KVM_PHYS_INVALID, > + .mmu = pgt->mmu, > + .memcache = mc, > + .mm_ops = pgt->mm_ops, > + .owner_id = owner_id, > + }; > + struct kvm_pgtable_walker walker = { > + .cb = stage2_map_walker, > + .flags = KVM_PGTABLE_WALK_TABLE_PRE | > + KVM_PGTABLE_WALK_LEAF | > + KVM_PGTABLE_WALK_TABLE_POST, > + .arg = &map_data, > + }; > + > + if (owner_id > KVM_MAX_OWNER_ID) > + return -EINVAL; > + > + ret = kvm_pgtable_walk(pgt, addr, size, &walker); > + dsb(ishst); Why is the DSB needed here? afaict, we only ever unmap a valid entry (which will have a DSB as part of the TLBI sequence) or we update the owner for an existing invalid entry, in which case the walker doesn't care. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel