Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2644880rwl; Mon, 26 Dec 2022 19:30:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXuROnwbEC/KexzKl+OszcxBFzAbtGtc0F6dONY6OOoIveDHBdSR2KeD45fegaZ+bBDYDHj+ X-Received: by 2002:a17:906:4d58:b0:7c4:fa17:7204 with SMTP id b24-20020a1709064d5800b007c4fa177204mr16542802ejv.7.1672111839612; Mon, 26 Dec 2022 19:30:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672111839; cv=none; d=google.com; s=arc-20160816; b=Japgvb/5uiAIzEY2dfWC8bhTXLA2IlojiVoummzIdkdzHRZBozys0qxOYgbIg2UGWv fjpEywpN/J5dG7sMTrPJPjzTPPuErit6jW5v9cQ88McR4ZnvCwSJavy3Uc+57Wtqa96Y 6Yp3dUWTxq7QQ26iACtagVLZ2cc6EILX2K8wsW1WVqNmONFjUxys/cgFwEc/wg9zoKHk WVljNlwKtfsz7Ve9SBgHWOae0IAatcMM5QXkNHwC4YyLSiBq+tFNTrw3jGf9w70ZJwEO JmeXMVttwRqEIy7w3CrpWZddYEmYLEsYCk3RYQJKOxMTJ9BqGExVAZwQlUlDv74nXN51 Ux6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JaHQeXh+L8VDr3v14jKHr2jtqcMM5uGvvy+DcgWw4zw=; b=oi/kH+wsh40LEjDOpUlEPQxpiTDoEoPRjjDU8XzYBjHBh8A/FNzElotYG3eGJEB4+q LQZ6uPi4NPBWmmHrPFyC19eQRr71JLmVC6Vbs+6ZPZV9tJYuF+4JOHOw41iK7RVdykb2 U+b62iJEASeLlqwYVswU2p+9xvEek5JeVD9cH19oJJnsZNO23PIcOFQlBq9g/CCJMXTR aE4xa7E9q5Pp2MbqAoU7hFxYRDxP2yk8mi5wFIRmb9BCYcglxSY8gn6JVVcHxJv8jX4z zUHwHWJefNcGW1+KHqwfmOIH4AhdTNQXRzDIXLyOwShkprCXSuxrUsVK0yoqRN6zK/Fw myMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LaH+MN7p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he33-20020a1709073da100b007acc6769292si10529550ejc.365.2022.12.26.19.30.24; Mon, 26 Dec 2022 19:30:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LaH+MN7p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbiL0DJK (ORCPT + 66 others); Mon, 26 Dec 2022 22:09:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiL0DIw (ORCPT ); Mon, 26 Dec 2022 22:08:52 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21BDF264C for ; Mon, 26 Dec 2022 19:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672110531; x=1703646531; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cWbMXq+BulH9gIMaAKVyjGjPeJ6XOcZ2RXQodh7xORI=; b=LaH+MN7ps6xJB5ynzm204FXQ8IRzOinh24arYS6jyaMrQizlLPteoXD4 LFtF5e9/g//pMsHMacbRkebUUtC0sz0H4mbcsIWiHRC8ttF6mandkDjfl mhzRcaWkZKlHFFttE7OODZiveh1evk7v0ASIFabgKT2qbD5w7PnlU6HKl mJmqeZ5BljWscLXcCrw3pNwAGm0+mRRzewgTVYnx1ej7X31sS4F0gGTim Gpd5YRRrOsman9AlOmxSWx+oMsEU5T4bQWgjzsIMZ/R7PcO8pbKVyKF9C ukBnGfT6l/Re9OodXf853N0Gd2lFJUXf+hEuEqV3rv9Mdx6y0MYmTO+DL A==; X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="300994696" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="300994696" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 19:08:50 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="741605217" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="741605217" Received: from ppogotov-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.62.152]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 19:08:46 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id BEEAE10BBB4; Tue, 27 Dec 2022 06:08:36 +0300 (+03) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv13 07/16] x86/mm: Reduce untagged_addr() overhead until the first LAM user Date: Tue, 27 Dec 2022 06:08:20 +0300 Message-Id: <20221227030829.12508-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20221227030829.12508-1-kirill.shutemov@linux.intel.com> References: <20221227030829.12508-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use static key to reduce untagged_addr() overhead. The key only gets enabled when the first process enables LAM. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/uaccess.h | 9 +++++++-- arch/x86/kernel/process_64.c | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index cbb463e9344f..1d931c7f6741 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -23,6 +23,8 @@ static inline bool pagefault_disabled(void); #endif #ifdef CONFIG_X86_64 +DECLARE_STATIC_KEY_FALSE(tagged_addr_key); + /* * Mask out tag bits from the address. * @@ -31,8 +33,11 @@ static inline bool pagefault_disabled(void); */ #define __untagged_addr(mm, addr) ({ \ u64 __addr = (__force u64)(addr); \ - s64 sign = (s64)__addr >> 63; \ - __addr &= READ_ONCE((mm)->context.untag_mask) | sign; \ + if (static_branch_likely(&tagged_addr_key)) { \ + s64 sign = (s64)__addr >> 63; \ + u64 mask = READ_ONCE((mm)->context.untag_mask); \ + __addr &= mask | sign; \ + } \ (__force __typeof__(addr))__addr; \ }) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index fef127ed79b6..09e7f3d3fb5c 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -743,6 +743,9 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) } #endif +DEFINE_STATIC_KEY_FALSE(tagged_addr_key); +EXPORT_SYMBOL_GPL(tagged_addr_key); + #define LAM_U57_BITS 6 static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) @@ -773,6 +776,7 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) mmap_write_unlock(mm); + static_branch_enable(&tagged_addr_key); return 0; } -- 2.38.2