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: 440101 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp1047213jac; Mon, 17 May 2021 05:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyatC0T+763WOXCjkaDs4VKwkBsF2EvvyR63ZwCEApUo4vhLRGN1SoxWmsJGoWt7pTxYbfc X-Received: by 2002:a05:6e02:1a49:: with SMTP id u9mr56048912ilv.306.1621254961067; Mon, 17 May 2021 05:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621254961; cv=none; d=google.com; s=arc-20160816; b=NK0y8fvNVAY06fboc8m2v2QGsQOjj/Z8dwG0YfB6HFmdU9iTyxfXr3ya/b4maiLJS/ IAAJwDlFPaGy4BWFERiIgz5Zq/IG7RnWHWSw953zcD4Saq1VYqz45Pn+KeYK/Wh7+Bg5 aaklMbnC9kB+E8HwDtI7b5x/x1Pyf6BUkAi3Gjz1fBHs+ok4EOrA3V3lXD9yNCze9e7w dPZCrBOSHyqXHqrEDIEqnsHk0s1jyFH2Hne/IzD7rB3c0RO1A4W1gJtzBWsc+hja8akA NHq1584af0cQ6GlGJCu0wRwpOpEQZ+V0YVn0lFsm1jdte1xW78mtbHYBYRD3sGdnH1QT 0V4g== 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=cyvc5nr9ngvn8JZiVjALJJHNYm5mKMFMiVtptHTSS8ugPgHr3m2RwaGGHNLW8zchxu HDq1oD2kC1G9LvboyemQ+A1xqpQlYn05VrEYBzheL5hDJbxFJ1QA+TdviZbEfK9wkuhq LlobJi33mOnNyMsbFZFy7j/VEZaYphYEqNLTJoqyp2ZUqUgDZcEgZKiNXo7BGgygtm+U TYfuf1nQ8FzXCmF8slb/HtMBurFd827oQ/+BLl/2BHggVpdQeJxcQeMm8aVwZb/fEiMy Yskq1G0tiUyYvEig8MD8Z579WCqyR+OmbBK5ZF6ASu48aMbY0JfXl7IsqpJsuxJmCSWB cjRg== 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 z13si18846725ilu.28.2021.05.17.05.36.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 May 2021 05:36:01 -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]:44806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1licTY-0003op-H8 for patch@linaro.org; Mon, 17 May 2021 08:36:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1licQx-0006i1-4V for qemu-devel@nongnu.org; Mon, 17 May 2021 08:33:19 -0400 Received: from foss.arm.com ([217.140.110.172]:42744) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1licQu-0007oS-Uh for qemu-devel@nongnu.org; Mon, 17 May 2021 08:33:18 -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 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 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 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; +}