Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9409476rwl; Wed, 11 Jan 2023 05:29:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXtXpnGJKNuD+ZSv7mfEsjixvQD/RP+GJFGFQIWEbd3tWG1TXUUqm5LpzE9MzP7zw3GMd5ym X-Received: by 2002:a17:907:80ce:b0:7c1:26b9:c556 with SMTP id io14-20020a17090780ce00b007c126b9c556mr65678378ejc.15.1673443771883; Wed, 11 Jan 2023 05:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673443771; cv=none; d=google.com; s=arc-20160816; b=xryzp+a5rQ9D7llfkq63vx+a6i3FDtsdtVkbwOOXM7PIr+J9y6wKWk+xNTaaLUjJyK c/9yZ3nkv2tYbgbchXuDosqb6DaYEHTIGo0Dr/MjDR/fPc6ww8ke1xVtRxakqCurs21Q eBDPSXHefoacLdoWosvsfKgLDf6JO5EdBvYyd2EDKXUq3a++n5HBoEqA/uqUNogeo4ws zfvaU/YFYW3LWClYnlPSxH06rmYSiMMMzD7MGFFohyUWuLVi8ve6pAV5PiFJDvcdpcus fCT+UioFMPFEA/+uDzdkUWW/ZIHR1Yhr8+GD87h13SZ6T6tQzxH2Cn7eZd59L3BgotVH c2kQ== 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=OEfHSuGHxXrdy3tTJ9locmwSqOVY/2Ji+MT08R/VhuQ=; b=YApX6TSX4wm1T12o0RVWSt94Ddi3HGzpFqTQPDA6Wc6RjxGQDTHpMbNLbZYOudZbD/ uPPsCn7TSdWG44zuhDEs3as3bB3qu2pCZb7a5ZYcUJkytsF1F3f7q9uR3MrXviuXp+Pd tQlXZmo6gd3oCX03x4kSkXQT7mzdg6RfNv3aq5FcjVQFc3MDAoXsTwXK4UDDUl5q6eyB Bz31r1iRBkrT60Ny+b/nGckwCgtBAvB6qMDn9Z1SMSgcO746U0g0aY7caWeI2T2pNjwC D2fs87Hsd8p/AX56N1pJYjiWKSq9EhyrhHEzdn0soVEwCVxi7azHXlf3sZ2cyHTRBR3z WNfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EQ2ZbevF; 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 sh39-20020a1709076ea700b008361e2a67b2si3274360ejc.0.2023.01.11.05.29.18; Wed, 11 Jan 2023 05:29:31 -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=EQ2ZbevF; 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 S229554AbjAKNZp (ORCPT + 53 others); Wed, 11 Jan 2023 08:25:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbjAKNYD (ORCPT ); Wed, 11 Jan 2023 08:24:03 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3D2F25EF for ; Wed, 11 Jan 2023 05:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673443442; x=1704979442; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yKZbUwdFl1OELkYDtSril3bPVHQFFQ9B8sbyyX7BAAY=; b=EQ2ZbevFjOEvN9UyTZaGVsOxOPKZ8o2xgIq4ro1gin8J9WRslxBEv48V AHg6EJg7dqabeKEHImrNfIMJ3WonY2XGS2h1Ohy6Szhz6wNPRZ2F1u/vP 1A3QBu5NoXaHpjPkjxGjrzrb+UpsY90lSPdwYtWuph/DRoe3KNItY9eZZ n2L4RmFBMhnAVJ25nQBYylqaidjCA0Bs3UViqaulQSAWKxeh8vdU8LlIG wBBbHfwD4L5aXf3HcOBi7gADkZr+IQnXaE9PZw8azPkKcNxHHTRBKFnDo jVR2PjadwviMfMd8BkJACq9yecxCTBD4K7HgscHq4kJ1oVJ+cHGmU4lfG w==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="387872549" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="387872549" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:24:02 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="687927431" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="687927431" Received: from bachaue1-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.37.250]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:23:56 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 53F0E109CB3; Wed, 11 Jan 2023 15:37:41 +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: [PATCHv14 08/17] x86/mm: Reduce untagged_addr() overhead until the first LAM user Date: Wed, 11 Jan 2023 15:37:27 +0300 Message-Id: <20230111123736.20025-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230111123736.20025-1-kirill.shutemov@linux.intel.com> References: <20230111123736.20025-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 | 8 ++++++-- arch/x86/kernel/process_64.c | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 32c9dd052e43..f9f85d596581 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -24,6 +24,8 @@ static inline bool pagefault_disabled(void); #endif #ifdef CONFIG_ADDRESS_MASKING +DECLARE_STATIC_KEY_FALSE(tagged_addr_key); + /* * Mask out tag bits from the address. * @@ -32,8 +34,10 @@ static inline bool pagefault_disabled(void); */ #define __untagged_addr(untag_mask, addr) ({ \ u64 __addr = (__force u64)(addr); \ - s64 sign = (s64)__addr >> 63; \ - __addr &= untag_mask | sign; \ + if (static_branch_likely(&tagged_addr_key)) { \ + s64 sign = (s64)__addr >> 63; \ + __addr &= untag_mask | sign; \ + } \ (__force __typeof__(addr))__addr; \ }) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 88aae519c8f8..1b41c60ebf6e 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -745,6 +745,9 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) #ifdef CONFIG_ADDRESS_MASKING +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) @@ -781,6 +784,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; } #endif -- 2.38.2