From patchwork Thu Jan 16 02:30:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13941159 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 00656C02180 for ; Thu, 16 Jan 2025 02:32:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 520B96B008C; Wed, 15 Jan 2025 21:32:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A70E6B0093; Wed, 15 Jan 2025 21:32:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E7A2280001; Wed, 15 Jan 2025 21:32:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0372A6B0089 for ; Wed, 15 Jan 2025 21:32:47 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AF4B01A0669 for ; Thu, 16 Jan 2025 02:32:47 +0000 (UTC) X-FDA: 83011741974.30.5DAB336 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf24.hostedemail.com (Postfix) with ESMTP id 3DD0A18000C for ; Thu, 16 Jan 2025 02:32:46 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736994766; a=rsa-sha256; cv=none; b=GOFSctjs60Jy+LanIIZAcogh0PWvUqapScZmCJahz55lggpojF/v570tR9nZ3ZA8ICz2Xk doHe9uebItuzSRZMOMADceBbYC++WXXhlrwcJuT7vRUN32EhHGYFy2yhirQTyXWkik41he KovG7d77JaNDUINjUcZhkN5UYD9/vOc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736994766; h=from:from:sender: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; bh=fxCD3xy+OxxqHxrPDR48qSO6ejbegAvHmdEDWAk2U4c=; b=AcOj4nprIMh2ynkZa99mZcp3fC9pfTTv2lHaiN/u9FPEfgsXFW9amEdnsApFEJHtAHU2a/ ZFveob5sIQ4sPoB/haj8rn5X8x2syErB8Er5j7GPFiEMerSw2OydIcGPX4wkh+UGbkz2Qe zecD2FXOQd6FNlV/cQO17UHiCWYB1sg= Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tYFfO-000000003nd-3QRo; Wed, 15 Jan 2025 21:31:30 -0500 From: Rik van Riel To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, dave.hansen@linux.intel.com, zhengqi.arch@bytedance.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com, Rik van Riel Subject: [PATCH v5 06/12] x86/mm: use INVLPGB for kernel TLB flushes Date: Wed, 15 Jan 2025 21:30:29 -0500 Message-ID: <20250116023127.1531583-7-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250116023127.1531583-1-riel@surriel.com> References: <20250116023127.1531583-1-riel@surriel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3DD0A18000C X-Stat-Signature: mqacy8aok6ji8jx1zgjz5fbqugrncqaj X-HE-Tag: 1736994766-348451 X-HE-Meta: U2FsdGVkX19bcsnfAqY51bTZJQ6i+Y9533b0LIX/MsHgPduyYr7qub25diGBDkLA9URKNzwKVNBAWt/DxWXGJjWsACHmRGgAKX4z8Jk6Yzwr+Fdw0Toho7DRfCUZxsAQI9Nq6XCLkPWtJusn5Bn9WiWI449HncLsRw5+c56Zb4787RCSEUAjcfTCgXYvdrXXONw6eIx5Q8FayT5p3DKXIF6LifzdCMnepOgFjoPZZkeSiOf2CZVAv08QpcsOGJ0QMjVUOq67iR7dsYI2EZ3UMlrEZH9uAErmOaecMCucBVPPq8YdmBLRjl941UIAxHxoLkJyEbvpNPgHY1MsfmmaHjzMFTafxPIaaRyFYviysINHDfxOLzUJprhFr/COJoeP2YMt2Tb4b0CHWeLxkutOHNeCCclrrN6WzFxQHGS1pPF87UHlH1TgvEr+RHeBXXCbmPjnk2waQFSEyoVTsTMZ0AkvvqlTXRZm6cb/ORzBMVOkyYefyDns93Ef02i5+Hp+PAD/M2rAsAFqDsFGEVcXJYI4s+5Awt5mmmeFo3lSFXsnQei4Uozh+c8RBBUh0rVpwz2WXJLerLfCtwZ9LzmZykay0+xN97s7edcjjP8449mgYp4TLN9C6ay8GsMEIJuYxazRgWx0RAoK+VFjNBxsBeD4++i1sIL5R174aObMSOK388rigiAaPmtiRtwH+9oQr4h2skrl7j0G+tXNKUJlHZorA/W+TAXDbmX8ThEy6LAoJ9CWYNwphYiIcaFB6xD8n7Bsd8Iro5bH9X86S8MRdvLJJYpNJeGmuzgGGpEe5/dn+e4Hy3mIW38G9Kj6TQcFFECX90QM9HKjYfSwX4frm1SODoGeZFUAfq7BpBn1fYO/YZ67oCwnoLT42rteFo6hkHB5H7DPQUnUkf0dmLbpyTzBAgvYsiD7i0HDfCb6l+/MLD5K+YVMVkGEV3GOQUodBP6C7TE3BXkR6hP63ry WHV2Hvv3 dx6Mu7SBiY1hzGXFkedQyA5e5Q4zJnlQ2Tp+kSQiN6bPinfd+JfodB32B7kjr7LnHmh0ud5Ba5kMgg80WM2047w/7zCT/POCW4EIfccYmRVj7yB8dwaOIIcxdoJxF+lKYo0hCpjlH4bVOJt7Sf8ZKzE7i8fP+M9ksbjt3WdQ3K0ON1OQm7iKpkP5yW28Gl3NxU/gzc9NZJyZzig3f7J1st52anZLmgqVkmShL+OVdpEjOKhT8EWZC0OWkIpl0PWhCvgjW5MzR235Kn3QGginowfLrROSLiPutNYLEqXsf/jTh5bt/Op0esuTCKH2BmzjelmY7RQBXIvRN1EeRlFgOXzUsZMiPjgfscyv0p78m1LLvT/TlQ3qWuZwmnxRy94NGZpDw 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: List-Subscribe: List-Unsubscribe: Use broadcast TLB invalidation for kernel addresses when available. Remove the need to send IPIs for kernel TLB flushes. Signed-off-by: Rik van Riel --- arch/x86/mm/tlb.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 2f38cf95dee3..0761dd224e84 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1077,6 +1077,30 @@ void flush_tlb_all(void) on_each_cpu(do_flush_tlb_all, NULL, 1); } +static bool broadcast_kernel_range_flush(struct flush_tlb_info *info) +{ + unsigned long addr; + unsigned long nr; + + if (!IS_ENABLED(CONFIG_X86_BROADCAST_TLB_FLUSH)) + return false; + + if (!cpu_feature_enabled(X86_FEATURE_INVLPGB)) + return false; + + if (info->end == TLB_FLUSH_ALL) { + invlpgb_flush_all(); + return true; + } + + for (addr = info->start; addr < info->end; addr += nr << PAGE_SHIFT) { + nr = min((info->end - addr) >> PAGE_SHIFT, invlpgb_count_max); + invlpgb_flush_addr_nosync(addr, nr); + } + tlbsync(); + return true; +} + static void do_kernel_range_flush(void *info) { struct flush_tlb_info *f = info; @@ -1096,7 +1120,9 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end) info = get_flush_tlb_info(NULL, start, end, PAGE_SHIFT, false, TLB_GENERATION_INVALID); - if (end == TLB_FLUSH_ALL) + if (broadcast_kernel_range_flush(info)) + ; /* Fall through. */ + else if (end == TLB_FLUSH_ALL) on_each_cpu(do_flush_tlb_all, NULL, 1); else on_each_cpu(do_kernel_range_flush, info, 1);