From patchwork Tue Oct 25 00:17:14 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: 10449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp738290wru; Mon, 24 Oct 2022 18:11:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UEAnPaQ6YmELSsmgNc1vykpOn9LqOD/n0eTHcIg9YJpObElKI3RSz6ic/DkXA1BQuv3AY X-Received: by 2002:a17:907:da7:b0:791:8f57:6860 with SMTP id go39-20020a1709070da700b007918f576860mr30936059ejc.509.1666660307701; Mon, 24 Oct 2022 18:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666660307; cv=none; d=google.com; s=arc-20160816; b=Z/anknSWMD+x7WMopyJyOHV3F9ejwR6G5n0377Go5iTyejBKBMYD5ptkQu3AFKsGZa srimzZyA4HIwe3UvoLx4mRGW9/55i28fMK2oZX0NalkZKMaHLxE7GwUIZZEZbw127ulv ytMH+aS0RwRMJkrx3I/vbCrKvRCO/9HxI/TAppIzV4pjGDuAKwRpj4AaYwvn4OcJRNUX znqMAwfLff0J1sEzZfnq+uAvikSWuPmj1101Jo9dJ2HUROzUYs25zlNYIn8cE18mOKOc j3QKXnsFhG7bZTsnyt+P/2zlEUuJCGLpMLhJfPTONpkgiXPfxR2Zs//vMdhXa04PB8hM F4xQ== 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=HGH62+uFEu8c6UZDAvYEhOO+nimuGapexta/TJtDuPw=; b=I5o6G6nbR5bUggAj3wvS6nZd5ilwLR4mos8PMfMMQu22PMzrQCSHjHHXMEYqYpkT0D RapIt+n9k+hHKgU9kDGdAdz3+NMbzdVHROvKAme2o8NFbv7PD8ZODfmBauWFwEENVhiJ iuZeyjhj3STmNhEWsB6WoeepQS6Ru2hYMuDVKeofbvOmY2iwwSJvEBpyUKxRwipXJxwo HILGHydEUR72c1xQ5uvMjX2IO+PR+XM361L9+hofexnz2CE5aHG4wPuS95teTN4XrhpJ v7FWljCSDp0dk+uO2HvCFUohWLgge5POU88kOLHlR+jwww+2UU7zz1jmtgLiKDfHWyNZ R/KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dHPpgQ4B; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds4-20020a170907724400b0077b83f3dc20si1520837ejc.63.2022.10.24.18.11.24; Mon, 24 Oct 2022 18:11:47 -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=dHPpgQ4B; 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 S231207AbiJYBKA (ORCPT + 99 others); Mon, 24 Oct 2022 21:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbiJYBIZ (ORCPT ); Mon, 24 Oct 2022 21:08:25 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F79BD995D for ; Mon, 24 Oct 2022 17:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666657061; x=1698193061; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fhYTon+Hc+WcBW6ZSEbgkDupKrv70IXcyEjN02jeYOc=; b=dHPpgQ4BKmJY7y1Q45e5b+p3PyuvPie1RT5xF8dfXBx9m20axl6bO1VB bCKIqkEZZXANaYQl/P9vF8vEJfubyja9sMfmVxCqYvqitfLkTm547WScz 9/rKZ1jHnT5dTnGK1dqpaSIGmu+xW8HnJCXA/n895Xn21Oh/b9ioV6QVO R53WSO/LgMa7eSUkX91QPxoCGuijGdK4CtShCDhvZy1X1NDH6fIIBYuIp W18QSiooN+sT9pUwxMNsLnjLhNEVcN1JugYFB+Q4VuPstmFRorwMRQ02Y lYbeEjbc2gq7JsrPQ5et++lPvaE2RE/aiEP+0uNwLqDSRmjpMMOdpb95V Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10510"; a="308644665" X-IronPort-AV: E=Sophos;i="5.95,210,1661842800"; d="scan'208";a="308644665" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 17:17:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10510"; a="582587477" X-IronPort-AV: E=Sophos;i="5.95,210,1661842800"; d="scan'208";a="582587477" Received: from ghoyler-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.39.118]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2022 17:17:35 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id F05131095BD; Tue, 25 Oct 2022 03:17:25 +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: [PATCHv11 08/16] x86/mm: Reduce untagged_addr() overhead until the first LAM user Date: Tue, 25 Oct 2022 03:17:14 +0300 Message-Id: <20221025001722.17466-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221025001722.17466-1-kirill.shutemov@linux.intel.com> References: <20221025001722.17466-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.8 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, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747619999052836796?= X-GMAIL-MSGID: =?utf-8?q?1747619999052836796?= 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;