From patchwork Mon Jun 7 11:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Price X-Patchwork-Id: 455276 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp2661704jae; Mon, 7 Jun 2021 04:29:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6Cg/2NJ45qhwfucs1wG2Y/k+JYQFfrcOM51ss5lKgSs/H6InqedVHKWSe4bzrdJrfTwIL X-Received: by 2002:a5d:9e41:: with SMTP id i1mr13844905ioi.72.1623065370197; Mon, 07 Jun 2021 04:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623065370; cv=none; d=google.com; s=arc-20160816; b=YDSpfPYTRvX8hM5v2KGjNiv5ySEy2X3AbcWBD+U9g/aHvCKKuM2eARWc7eMJWIJ98X /7oYiTMkt0pykqlQvkdFhGOSRRRWfn/CUpV+J1mEM0Q8jnt7Jfzom5vcM5szunf5vOZk k3s8zuwRdP2QMnNgt/kBhh9npMo00KNGuWeHH5KQSDILfTqOLzusW8z6Iad6wYV131Hm /rxDoAJugLjfRJL5gLuyEDVFdXt1o6qZepQuY86JE8a90zIJjTUOCqvyo7tN4GIYbjmK UYrx0F7OpiS9mTCVOR7q+OGNmGQ/5PcLIMDghUSL7j80rQtm80l7DhYYnSr4JBD2Z8Vp 2yGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=nBv4+qVg5C8ahUtity7yATAkI5cIwXrmTDiA31AF4Z0=; b=h7mC4c0wmTl39r4+cOGJTs9JbMU95KYE1CNKD1p2kqV9WFSBhdss25wf2+OO1j5MHD uIF0aBKvsruQhbkWc5UHmPRzESm3LV0QS9QPVmh6MU0H98tOxIrHEr8k9xLAuY8ICZFL tqlQ735i9NlVB+YdokS9fp7dpV6Uc4iFcVZCA1IfxSZJmFKYdfWX+B6pP3OIlJZjGZiT 8SAOzDFLSa/2TBMT2qY0H1vaILr1gmVNz2IPhEe89uBC/IgTfCWWmJHubvsy8Qp6OHD5 3QuPwKI9ro3/Jo//9a8SGTZC6qoKNkJ1XWpQoDfmIhhC34ArhTHrrF7ynE6goTsnJ+9s 5nOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n15si15329398ili.8.2021.06.07.04.29.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jun 2021 04:29:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from localhost ([::1]:37214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqDRh-0007Ll-I3 for patch@linaro.org; Mon, 07 Jun 2021 07:29:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqD7c-0002G1-Fn for qemu-devel@nongnu.org; Mon, 07 Jun 2021 07:08:44 -0400 Received: from foss.arm.com ([217.140.110.172]:51194) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqD7X-0007ZP-Eo for qemu-devel@nongnu.org; Mon, 07 Jun 2021 07:08:44 -0400 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 942B6143D; Mon, 7 Jun 2021 04:08:38 -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 B2F5E3F73D; Mon, 7 Jun 2021 04:08:35 -0700 (PDT) From: Steven Price To: Catalin Marinas , Marc Zyngier , Will Deacon Subject: [PATCH v14 2/8] arm64: Handle MTE tags zeroing in __alloc_zeroed_user_highpage() Date: Mon, 7 Jun 2021 12:08:10 +0100 Message-Id: <20210607110816.25762-3-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210607110816.25762-1-steven.price@arm.com> References: <20210607110816.25762-1-steven.price@arm.com> MIME-Version: 1.0 Received-SPF: pass client-ip=217.140.110.172; envelope-from=steven.price@arm.com; helo=foss.arm.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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, Dave Martin , Juan Quintela , Richard Henderson , linux-kernel@vger.kernel.org, Steven Price , James Morse , Julien Thierry , Thomas Gleixner , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.20.1 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; +}