Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7704769rwi; Mon, 24 Oct 2022 19:15:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4o4xFdY6FP6RqT3VDfcWfx4S9QeXyzIh6irsJPxWUcn0wg2lrZWMIbl/ufPOSjsxdN1cyg X-Received: by 2002:a17:907:6e1b:b0:78e:15a3:5be6 with SMTP id sd27-20020a1709076e1b00b0078e15a35be6mr30684900ejc.750.1666664156740; Mon, 24 Oct 2022 19:15:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666664156; cv=none; d=google.com; s=arc-20160816; b=YGW7LoF1FmWEvQClKQ0G2MoKaraf5Mtv/1cVSzxMoAZEIUKEvuRLUKsXEL5wq8ey3b AxWnPnwHV9alUHmqylCKA5PG03kcnAB3iot+Gebei2fB7Q55ZvThrLkfEHmPUYB7LqVL BUxtJYcb6KWQvkT2t8X0vvqvkjRROgUjhhN0uIoR2KJuE4th3jlmU3qKamuFaHy40Bv0 1Z8w+OyzcLdgob9TAS1MGKqolvxurFwpXn7SfQvdPKxdSJuAmieWaWXmkgmI7N2Ypxeb ydJ65J7A5lPU4kg1TNSSJy8BuCeUhxp+hfOCcR6wlahKxdgp9DrVqknsrjXV2skq8yjU r3Lg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw8-20020a170907a0c800b0073d8830e4c7si1375878ejc.954.2022.10.24.19.15.31; Mon, 24 Oct 2022 19:15:56 -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 Content-Transfer-Encoding: 8bit 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 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; -- 2.38.0