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=-8.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 08165C6369E for ; Wed, 18 Nov 2020 16:51:36 +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 6F58D2485B for ; Wed, 18 Nov 2020 16:51:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="G0B5HGtz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F58D2485B Authentication-Results: mail.kernel.org; dmarc=fail (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:References:Message-ID: Subject: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=RYH5DIcyEkw68cDlcAcHD5ZleDIgSJRvurhLGa/87Ig=; b=G0B5HGtzYsvW5CLDhfBXBYVVi 1e5hQQ1CzMuLCLZYqquzPa+dAszxMcqAVJjY2cKyFSX8UI7vG/oNAAbTkpIr7uky6hoDGOLeIMprL ejXWgotAQ8UxH/qsRBxmVh95/q6gbA5/ZRBFXNEE/lClYwQ6YazQH08eXU6uSVVZ2gxuIfQmBN5pl 9KF2C3q0h/zbpXoPahz3bWEaES38LfVaTHGzAfJgNmtmzCAaUzxVOHC8mnm6GCpigaRZRrkRvadfZ YVDRS3dWARnN624hfdadrru3688x7bkXnx5hAqtR+8FOdSTKrdBfVSYVBmWWWJBYHYUAx0pGHUbK7 X/7K8apTA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfQf5-0006Ke-Lq; Wed, 18 Nov 2020 16:50:27 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfQeq-0006GI-SW for linux-arm-kernel@lists.infradead.org; Wed, 18 Nov 2020 16:50:13 +0000 Received: from trantor (unknown [2.26.170.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B47CF2483F; Wed, 18 Nov 2020 16:50:04 +0000 (UTC) Date: Wed, 18 Nov 2020 16:50:01 +0000 From: Catalin Marinas To: Steven Price Subject: Re: [PATCH v4 2/2] arm64: kvm: Introduce MTE VCPU feature Message-ID: References: <20201026155727.36685-1-steven.price@arm.com> <20201026155727.36685-3-steven.price@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201118_115013_010010_C6FDD234 X-CRM114-Status: GOOD ( 27.35 ) 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: Mark Rutland , Peter Maydell , "Dr. David Alan Gilbert" , Andrew Jones , Haibo Xu , Suzuki K Poulose , qemu-devel@nongnu.org, Marc Zyngier , Juan Quintela , Richard Henderson , linux-kernel@vger.kernel.org, Dave Martin , James Morse , linux-arm-kernel@lists.infradead.org, Thomas Gleixner , Will Deacon , kvmarm@lists.cs.columbia.edu, Julien Thierry 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, Nov 18, 2020 at 04:01:20PM +0000, Steven Price wrote: > On 17/11/2020 16:07, Catalin Marinas wrote: > > On Mon, Oct 26, 2020 at 03:57:27PM +0000, Steven Price wrote: > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > > index 19aacc7d64de..38fe25310ca1 100644 > > > --- a/arch/arm64/kvm/mmu.c > > > +++ b/arch/arm64/kvm/mmu.c > > > @@ -862,6 +862,26 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > > > if (vma_pagesize == PAGE_SIZE && !force_pte) > > > vma_pagesize = transparent_hugepage_adjust(memslot, hva, > > > &pfn, &fault_ipa); > > > + > > > + /* > > > + * The otherwise redundant test for system_supports_mte() allows the > > > + * code to be compiled out when CONFIG_ARM64_MTE is not present. > > > + */ > > > + if (system_supports_mte() && kvm->arch.mte_enabled && pfn_valid(pfn)) { > > > + /* > > > + * VM will be able to see the page's tags, so we must ensure > > > + * they have been initialised. > > > + */ > > > + struct page *page = pfn_to_page(pfn); > > > + long i, nr_pages = compound_nr(page); > > > + > > > + /* if PG_mte_tagged is set, tags have already been initialised */ > > > + for (i = 0; i < nr_pages; i++, page++) { > > > + if (!test_and_set_bit(PG_mte_tagged, &page->flags)) > > > + mte_clear_page_tags(page_address(page)); > > > + } > > > + } > > > > If this page was swapped out and mapped back in, where does the > > restoring from swap happen? > > Restoring from swap happens above this in the call to gfn_to_pfn_prot() Looking at the call chain, gfn_to_pfn_prot() ends up with get_user_pages() using the current->mm (the VMM) and that does a set_pte_at(), presumably restoring the tags. Does this mean that all memory mapped by the VMM in user space should have PROT_MTE set? Otherwise we don't take the mte_sync_tags() path in set_pte_at() and no tags restored from swap (we do save them since when they were mapped, PG_mte_tagged was set). So I think the code above should be similar to mte_sync_tags(), even calling a common function, but I'm not sure where to get the swap pte from. An alternative is to only enable HCR_EL2.ATA and MTE in guest if the vmm mapped the memory with PROT_MTE. Yet another option is to always call mte_sync_tags() from set_pte_at() and defer the pte_tagged() or is_swap_pte() checks to the MTE code. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel