From patchwork Wed Jan 11 12:37:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 13096663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04F33C54EBC for ; Wed, 11 Jan 2023 13:24:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11DFE900002; Wed, 11 Jan 2023 08:24:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A73E940008; Wed, 11 Jan 2023 08:24:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED697900008; Wed, 11 Jan 2023 08:24:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DDF92900002 for ; Wed, 11 Jan 2023 08:24:04 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C2F95A0C56 for ; Wed, 11 Jan 2023 13:24:04 +0000 (UTC) X-FDA: 80342586408.19.122408B Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf17.hostedemail.com (Postfix) with ESMTP id CBDE240010 for ; Wed, 11 Jan 2023 13:24:02 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EQ2ZbevF; spf=none (imf17.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673443443; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OEfHSuGHxXrdy3tTJ9locmwSqOVY/2Ji+MT08R/VhuQ=; b=gGjEzaRjxl6EG4LpEgFMYLwFkGAaAwaRkV/QFF008zNKWVkNH9+N9OqdF3L/gfukcfQYci IA2fCO3B8F5FLUZrRZM5A4wmugp31N888ZwpsT8ttBq2WCixIFpUN+ebnC/5AAoipgRrRJ 1eXAd9BRK8fW9w6lbW9oMAs/lVBt0Xg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EQ2ZbevF; spf=none (imf17.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673443443; a=rsa-sha256; cv=none; b=fW53YzLIB5KlSUScph0SqgzpHzXYn/DnUwafBRFNSIT0v86Ih/aPZ9jRs6sXcrrxD29Ndv oreHixm+iYE4BnY6NVvetLdohlvuK+qFGKwUtJ0adKgmdrhuylu+AlkvyIPTjGCSnP2PhH dcaEYx37rjouqG9eqJf5qc+6eLl9150= 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="387872551" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="387872551" 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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CBDE240010 X-Stat-Signature: 3gwjbh3nf4h63y8btfei8czdek6triqh X-Rspam-User: X-HE-Tag: 1673443442-973342 X-HE-Meta: U2FsdGVkX19DkJ6lY3gtywTb3ma6Q4BU866qUvOfe8F8KtDffqzmGyJeVEDI7qSHXPUfnVcI1iHru3gO/mkBt3CCEDd+GcbvlvQTmoD/CLou1noVP4d69miZp5u8tR1lbkwMRglGlq70gLPQoXyZetQAbsWUILmmGOgVv0FFb5xLZnlrPZoiFa1UOtuDA09Px1WpBGiy+KAbAOHB5E7hH3pVqShZ0MZh7hvPiFqoKCtSaI3zLStwCARdNTs0bAuzel/uNDjT//tOwTJBd1mBxp6tV6815agg2FsVMG4OzTO+i5XANeyUomUldqUf6lb5ZazLXXBWoSoPrvi2kSvqvAHAhfVLJwnqQYrG5duSLYZ0pVzuGa6v/Y74KKtnw6it0i1jCph6AjISKzAbrr/ykh81zrEWJP+pVxXexzsgDEOR0rPbGnHQndY7+QA9PM5fyKLW6cNJSKbqJCPDx9dVSvgzjpSFiIyftb59nTmAmGZcLLMUG6muc+RB0/lzbQ/1tCE9pXGaYay1YpP9tDiWyKlMSC5CxiljH3uhQFrg+FnFHtN7LBScX2nIjnUPmFeO/kMovtbCVjn52zmRD80g8wel5dpDf1j92RRYsAx9k1FMG8tfipk+Im3AYkJodDYv9n1nelQkTNgsfTNHX9/jmo69Ok25eUpuDG37NM2ytMkZfraBoLVwXtv5sI5VRO9QiWsRzUvH3VWpryilTSMm54pyD5L4RcnO5vPHbNU9qwGyLRsMXHcIiLZV4NN95q6usHUfjzu77EKJv4HHkyTi8qrjmWwit3buBahLwaA1TGUFF1ZenKgz73XAIRucHHDQApr/dVWxIT7FaQIwg3sZDujS1ezm4p7m/9i41AGgstj4dnupnskbLZWFw3FJCMibOGrsymqdI7DWoPMIkZezaRpQKALfDIGWmKv1zu9uwEssTStIerUIAUfXg5U2ylkJXwrFQ51Bi57ufO9MSbt PSytu/U4 cS2C7KzKF4s9fYwePNRZTTA9Pm5hVmt9JNh06 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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