From patchwork Mon May 17 12:32:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Price X-Patchwork-Id: 12261795 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 CA2D2C433B4 for ; Mon, 17 May 2021 12:36:01 +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 4796D61244 for ; Mon, 17 May 2021 12:36:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4796D61244 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lBPsAFkzl1HU0VWjjL3eePnU/UCROijfHMKh+xreML4=; b=m1g0B13Heizooa4zRdvPVVA2Y /+MtTad+XU2NZYVulVskRP45dbMKVVX1JBwKHuEon9t6eVwI6cHn2VCuGkEUk0p7YKBKi4CVGGdD3 pk0V828PKw5Tn9vgTLXx3eHwXdDmor9bf1gcMh/2IHZGJQ5/j/nYC6P7jfx6uGSF0LELAsuQU7hNj M6SnSNO1G9CBZOg1weVvaXFCSipAkzaG8wV1z7WvZgWkbUX6OpawOczgFL/4JsEf1Bgk2jIrao5m/ 1mnuca3bJxHOFoKIalIbSPSv0eyFKT1g7KzfmHS7lhlIffAT8lSCVVUAmKO06+vpdJGYIqx8lx2zo X+49kR9aw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1licRl-00Ev07-5M; Mon, 17 May 2021 12:34:12 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1licR0-00Eund-Nf for linux-arm-kernel@desiato.infradead.org; Mon, 17 May 2021 12:33:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=nBv4+qVg5C8ahUtity7yATAkI5cIwXrmTDiA31AF4Z0=; b=1JrfbgE5hNERMKYzQSQK0b1bdQ MTGBLyiMpVPt3ia/gwN/y+7esF0mV5LhXZWH04XTYe2b6UOyKhPMDn4ub7voSMjCSqib+5Hy3GnAA Cq3SJtMBnrpy9iGYps74CBHgEyeNoWkODGSAkhqds3ic8D7zreLVEGLkU+KWBVE8a5aJAxG5Ce5DB bh40yX1qm2HwV6zzbfnzkjU4Quq9V42zwV4aewNmT9tdPav1bXlTx7rLMHDMNh+f/RoLv5lmB3I59 XTT9S6KiuuXykIyt+Z3OwL35PzoCmHwSWjyGr+kOklIeBccM/i8622hdgUziEAf+htxQLabmzwIp+ jTeZuIWg==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1licQu-00Dl7B-Pt for linux-arm-kernel@lists.infradead.org; Mon, 17 May 2021 12:33:21 +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 E29C5139F; Mon, 17 May 2021 05:33:15 -0700 (PDT) Received: from e112269-lin.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E0B943F73B; Mon, 17 May 2021 05:33:12 -0700 (PDT) From: Steven Price To: Catalin Marinas , Marc Zyngier , Will Deacon Cc: Steven Price , James Morse , Julien Thierry , Suzuki K Poulose , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Martin , Mark Rutland , Thomas Gleixner , qemu-devel@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Richard Henderson , Peter Maydell , Haibo Xu , Andrew Jones Subject: [PATCH v12 2/8] arm64: Handle MTE tags zeroing in __alloc_zeroed_user_highpage() Date: Mon, 17 May 2021 13:32:33 +0100 Message-Id: <20210517123239.8025-3-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210517123239.8025-1-steven.price@arm.com> References: <20210517123239.8025-1-steven.price@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210517_053316_955395_6F436AFC X-CRM114-Status: GOOD ( 12.95 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Catalin Marinas Currently, on an anonymous page fault, the kernel allocates a zeroed page and maps it in user space. If the mapping is tagged (PROT_MTE), set_pte_at() additionally clears the tags under a spinlock to avoid a race on the page->flags. In order to optimise the lock, clear the page tags on allocation in __alloc_zeroed_user_highpage() if the vma flags have VM_MTE set. Signed-off-by: Catalin Marinas Signed-off-by: Steven Price --- arch/arm64/include/asm/page.h | 6 ++++-- arch/arm64/mm/fault.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index 012cffc574e8..97853570d0f1 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -13,6 +13,7 @@ #ifndef __ASSEMBLY__ #include /* for READ_IMPLIES_EXEC */ +#include #include struct page; @@ -28,8 +29,9 @@ void copy_user_highpage(struct page *to, struct page *from, void copy_highpage(struct page *to, struct page *from); #define __HAVE_ARCH_COPY_HIGHPAGE -#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \ - alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) +struct page *__alloc_zeroed_user_highpage(gfp_t movableflags, + struct vm_area_struct *vma, + unsigned long vaddr); #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE #define clear_user_page(page, vaddr, pg) clear_page(page) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 871c82ab0a30..5a03428e97f3 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -921,3 +921,24 @@ void do_debug_exception(unsigned long addr_if_watchpoint, unsigned int esr, debug_exception_exit(regs); } NOKPROBE_SYMBOL(do_debug_exception); + +/* + * Used during anonymous page fault handling. + */ +struct page *__alloc_zeroed_user_highpage(gfp_t movableflags, + struct vm_area_struct *vma, + unsigned long vaddr) +{ + struct page *page; + bool tagged = system_supports_mte() && (vma->vm_flags & VM_MTE); + + page = alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, + vaddr); + if (tagged && page) { + mte_clear_page_tags(page_address(page)); + page_kasan_tag_reset(page); + set_bit(PG_mte_tagged, &page->flags); + } + + return page; +}