Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3756817rwb; Fri, 30 Sep 2022 07:59:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RTCt9KejPO9oAO0O3xVg8ku1FcRP51OY/0zX8kkZ+piuus4EauNyfLxWmrLL2jRHKgiBQ X-Received: by 2002:a17:907:94d2:b0:783:e5dd:9c79 with SMTP id dn18-20020a17090794d200b00783e5dd9c79mr6971087ejc.18.1664549958641; Fri, 30 Sep 2022 07:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664549958; cv=none; d=google.com; s=arc-20160816; b=K9ou8pmcjkYn/cKBmEGv7Yqjyf3u8g/7htM9ptbZm5eQybgk8BdN51tkzGJrJMCCWZ 9jgpCquIodwjnosPOBDfXRFD40+qZPUyVVFZl8gFzB31CTi1agWAHofjsadngGAp/kDP AzYkra7uaMZMrWzeAAEfZEd/1gNEhG1XX9k6vg3HZXNyfeUiR37dw7gA3qzCjRtIKgYg BDBhSypupR3t1YYnGU4mMDG0GAkrDk3Im1tzPR9Eihcd+0hlqXxFyWz0AQT6JMmMEMtT 0sbvTlHc20pOYbRlmjtp34ExBiSMnGwjIVhjftXghGia6Zy2Oml3MjheUH5s0gPaPH5i y6Bw== 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=182mUYb2xfynMugUeQjzc+2oZJR0xz9IE3wxmtxC6WA=; b=VYaj2Hy7ibRrTMpfescpjBc87Q8j+xP0vpI5Tu05LfyAXZSMPS1buHsJdX3LdL6g8E bnt3v2FPoYRspBsYhC2eDEcd1YbhOEYoWdALFBgKzx6sGLHGGHLMjiZrVjIOI3cDroNj pKlZTDO58EkO1SjlwCAfy2zeEbrFvQNEHHaRxOQczZzZIiGDJWHSrn1EHnyh6I+SiB5c j/nizcz5en6Uzr7QhllVTDXF+IhB71I08/d3kBx2NMpPm+i+Tvdh0Kc4orvZwAL5Kkro MUUjBCCXnlzL557LrPxxUizGH6pP0ewiGu45aqqPHF/7/yxtR2io1t5mEVmL2KvysPkG bTkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iFNAjYs8; 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 e25-20020a056402089900b00456964d3369si2115524edy.230.2022.09.30.07.58.52; Fri, 30 Sep 2022 07:59:18 -0700 (PDT) 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=iFNAjYs8; 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 S231659AbiI3Osv (ORCPT + 99 others); Fri, 30 Sep 2022 10:48:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbiI3OsV (ORCPT ); Fri, 30 Sep 2022 10:48:21 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF2A12B5F0 for ; Fri, 30 Sep 2022 07:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664549297; x=1696085297; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sExrmnnOGqgb/icKqEgn6j12KzbzBwzl0nhEtIquc4M=; b=iFNAjYs8ekBUtYtoNI72xfsre1V7sbEp5jpdOwSXgwjOQlG06iE3aUF2 ULOmBifZWLoIXon3p8XcPPwdhtMytJqLtbUE3dkMV8hBtFoKo1kv6MNop ZIEeTPeD7QohUVEtsHiPP4ECB5TwW0l1uxl/Iv5kwOat12z6zzmKcTx0Y R/xgC9IC2BQoUVS2eJsow99aswOD5yXF+nu6blCV5Jy86snYyJFy3U5xv /NzwSQbKVCFcL3orA/jkf35pd6f1BB6wHZs7xJFaP9RsH4pyVk4c76yDo 0003ZYXBuk+X7mWG6Ro+iu5ywaimnj01AFcDI8+69Uh8yH5MTU4RXCKYX g==; X-IronPort-AV: E=McAfee;i="6500,9779,10486"; a="289367994" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="289367994" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 07:48:15 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10486"; a="653563756" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="653563756" Received: from herrerop-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.38.128]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 07:48:11 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 7776A104D62; Fri, 30 Sep 2022 17:48:02 +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: [PATCHv9 08/14] x86/mm: Reduce untagged_addr() overhead until the first LAM user Date: Fri, 30 Sep 2022 17:47:52 +0300 Message-Id: <20220930144758.30232-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220930144758.30232-1-kirill.shutemov@linux.intel.com> References: <20220930144758.30232-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 803241dfc473..fc33d6ba1090 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -22,6 +22,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. * @@ -30,8 +32,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 d75252a5c7be..1730c2fcc7ab 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -742,6 +742,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); @@ -791,6 +794,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; -- 2.35.1