From patchwork Tue Oct 18 11:33:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 13010296 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 980A4C4332F for ; Tue, 18 Oct 2022 11:34:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 741418E0003; Tue, 18 Oct 2022 07:34:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 660198E000A; Tue, 18 Oct 2022 07:34:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2865F8E0007; Tue, 18 Oct 2022 07:34:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E7CB68E0003 for ; Tue, 18 Oct 2022 07:34:21 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BC1CD1A0A8F for ; Tue, 18 Oct 2022 11:34:21 +0000 (UTC) X-FDA: 80033861922.27.204F173 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf06.hostedemail.com (Postfix) with ESMTP id 1C65A180033 for ; Tue, 18 Oct 2022 11:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666092861; x=1697628861; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fhYTon+Hc+WcBW6ZSEbgkDupKrv70IXcyEjN02jeYOc=; b=B3cSRA0fvCDHJZ44FQ7GQGmUPGsccAAn5+4T3DAAaiTiA1H76mpxuc/n GTWchpPRsrUJ3PdK5OD1hr3Bl2Ri23W/HXmj20Juj7hDJm3mVn/fugJwy yfemnqrgWhlc3OodBfrjC9/DpX2dYs5IngpLI2MpdkJgfT9o3fOU2GeQA I+ILse7bAUgjguJJeVv9MyLdSpo9FKpWdHK6nob9WR+MD3Po8spFBHXiY nzeHBpZ7aqe86omTQzXwSQQtJO/XUXqBuCqfc78nB9Cdn9oqkP1C2LXII wJ5Ptw5gd0TfuoXryi2PzG4VaWj9tKPCAawywUct3Fvvt+fwpFBfcS2gj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="293445876" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="293445876" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 04:34:18 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10503"; a="661861182" X-IronPort-AV: E=Sophos;i="5.95,193,1661842800"; d="scan'208";a="661861182" Received: from vhavel-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.51.115]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 04:34:13 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 4530D104A70; Tue, 18 Oct 2022 14:34:04 +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 , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv10 08/15] x86/mm: Reduce untagged_addr() overhead until the first LAM user Date: Tue, 18 Oct 2022 14:33:51 +0300 Message-Id: <20221018113358.7833-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221018113358.7833-1-kirill.shutemov@linux.intel.com> References: <20221018113358.7833-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666092861; 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=HGH62+uFEu8c6UZDAvYEhOO+nimuGapexta/TJtDuPw=; b=hDMDCg+tQ+OJTv+xHYbBWiMb9OLYUFdRohNrmYkK8Tv8UtXI9rK2WM2G670K5JtmJMpN2Q 6LcXw0bqO5uqcp8+k+r+xlLaZkHnmTy3G6thZNAQ9n6374n+WmgRSAVZWtCjQ3T3jeL2X+ Pbl+hYdIEdv+v3BG/nUsAXHyRGZ5kCQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=B3cSRA0f; spf=none (imf06.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666092861; a=rsa-sha256; cv=none; b=DfLDx7qpM4Rr21c4LzFGge1ewG4Q3qGFCM4/XBxDTK9XupwmDFAMix9KR/MEiES94iHPD2 zcf5v+dZyHjmR6EWfNFrSvahU8oImdx+bDLIKywQsNm80/sRtfMJ+dwnZB/3q4pdyPfDqH Lpu5b1k7D4xSUM+zA2WeV+vTfVnJ9cA= Authentication-Results: imf06.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=B3cSRA0f; spf=none (imf06.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.20) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) X-Stat-Signature: uhkz1srkx7hznxfkn9gmjsh8udo1od4j X-Rspamd-Queue-Id: 1C65A180033 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1666092860-457532 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 c6062c07ccd2..820234f1f750 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,10 @@ static inline bool pagefault_disabled(void); */ #define untagged_addr(mm, addr) ({ \ u64 __addr = (__force u64)(addr); \ - s64 sign = (s64)__addr >> 63; \ - __addr &= (mm)->context.untag_mask | sign; \ + if (static_branch_likely(&tagged_addr_key)) { \ + s64 sign = (s64)__addr >> 63; \ + __addr &= (mm)->context.untag_mask | sign; \ + } \ (__force __typeof__(addr))__addr; \ }) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index a98536101447..9952e9f517ec 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); + static void enable_lam_func(void *mm) { struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm); @@ -792,6 +795,7 @@ static int prctl_enable_tagged_addr(struct mm_struct *mm, unsigned long nr_bits) } on_each_cpu_mask(mm_cpumask(mm), enable_lam_func, mm, true); + static_branch_enable(&tagged_addr_key); out: mmap_write_unlock(mm); return ret;