Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp813470rwb; Wed, 9 Nov 2022 08:57:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Dtqu2Tn6k1WKSwmnMOvUgd1Ws+Sy7MI71d+J1gy+TnJka9daq1lS9IEDKZTkFWM0IUfIz X-Received: by 2002:a17:906:9bce:b0:7ae:7d78:9fa1 with SMTP id de14-20020a1709069bce00b007ae7d789fa1mr537728ejc.98.1668013020092; Wed, 09 Nov 2022 08:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668013020; cv=none; d=google.com; s=arc-20160816; b=qhp+/8HVHwkAxVAi+uUtQIWVVqSJSye7FaO3NZbhd2zMDHgfJYqFcy+Aet/IilfMRU MrwjPHgN+oPHxLQBQHe/QfitUTkZlFTb7arWpSNu4pGF+RZIUJG8WV4kFtWl0rNxlzZG 7gbmJHERUny2syc+vU3V26+rKErwl7uQKc98X3khgv+Uvqtbq4nTQm4terhu1HIFT+R9 Ybbng49JNwHvwmUIVBMnLLPYteDGqnKqtQuGyzgoBU7iLfcbuNYc7oUAbHnZDGp8jL1y XdmAsrV6aM0//shkLwdnyA33mCjoYi9bHFYbjRHkhXmwgpAtB+aDUvwLyb8OVDIuOMvA TLxQ== 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=kTxhWdg/9+KWVLyknAx/c07RpH6UpatcZ0+k9lSUfcM=; b=DAueIEWcPaLAkrPFJNtgta99Q461jJcD4qeEtENdeusilae/mj6MJdmZVzsY9mQoyR eiOQSn7JE+0xLln5ER70jH23eKBbi3zttj2REC//SvL1dfezK1K6Zx4WvVyf9DulGecf inDc3VpLFuj/SvCzdXODnn5yzTIgDEVZF7U7AhQWdPJWsolndj+qG7z0N8ccGO2N7DjZ fRTn0PB0BWorKjPO7lB+jQVYbI29/3xAJ9bYHuqjnzvh+yuOfPEmlEfkx1RZPCw+kmfA u+bnMnZAGLRAV+G73L1+QGkcobWGejgyc9LrklbRtTaOMeeQQj5vLm/ykaEFYoqpk9Ip zAew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SaLl3i7T; 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 go37-20020a1709070da500b0079fe11e92ddsi17869227ejc.906.2022.11.09.08.56.38; Wed, 09 Nov 2022 08:57:00 -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=SaLl3i7T; 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 S230216AbiKIQwy (ORCPT + 92 others); Wed, 9 Nov 2022 11:52:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbiKIQwf (ORCPT ); Wed, 9 Nov 2022 11:52:35 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF0A240A8 for ; Wed, 9 Nov 2022 08:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668012737; x=1699548737; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qQuq8QNGbNiZCBzAMV30JlXBLCHT9H1+EgK3GfrClpQ=; b=SaLl3i7TQAcy6FwgC5q8VE/gJfLmI8zS+1hzKKei6JPArTdZffD2hn5T Ncmj4HZ82vlQrszK0Zhf6HUfNh9phF4MT/6JDZigGj4Yx0VoJ9wwHhRrP WtPkK+y1JbIKV6gyMarq9N41wu13o9UETnLc9uwnE30A3l0wfa1lf41xT Cs6DuD5N9e45c7FNw1WFwE5SnHF9KHu4eTS1bLpQWA6rbDLCrKbRKIXBf l0loWXcSD8rQgA2LwwEql17RXe30OHtW3pP7J/v1Lu5HYM6NnXhfKzo4e OYphM4sNJvH8OidbPRwNEsimPM4yi6z95vbuNvXGXtyo0c598Ck2zgJGR w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="298553708" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="298553708" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 08:52:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="587827255" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="587827255" Received: from dschramm-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.219.85]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 08:52:10 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id A93E0109474; Wed, 9 Nov 2022 19:52:00 +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: [PATCHv12 08/16] x86/mm: Reduce untagged_addr() overhead until the first LAM user Date: Wed, 9 Nov 2022 19:51:32 +0300 Message-Id: <20221109165140.9137-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221109165140.9137-1-kirill.shutemov@linux.intel.com> References: <20221109165140.9137-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, 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 0db6f5451854..1d2c79246681 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 b8f2558a3aeb..457f79be8bc7 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); @@ -798,6 +801,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.38.0