From patchwork Thu Jan 23 04:23:25 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: 13947942 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 14458C02182 for ; Thu, 23 Jan 2025 04:30:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86F2D28000B; Wed, 22 Jan 2025 23:30:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81FC428000A; Wed, 22 Jan 2025 23:30:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E80928000B; Wed, 22 Jan 2025 23:30:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4C6F828000A for ; Wed, 22 Jan 2025 23:30:56 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 00BE2120B77 for ; Thu, 23 Jan 2025 04:30:55 +0000 (UTC) X-FDA: 83037441312.19.666B12A Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf30.hostedemail.com (Postfix) with ESMTP id 6861A8000A for ; Thu, 23 Jan 2025 04:30:54 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.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=1737606654; 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=g42cjHb2aIEThCXX+573g6QlgGX+6rdSWUpGjtlNPxo=; b=bRbzZ9trvnTJCCGgkskGeBQ7HmjHMVoStgYG2Ibadw3G6iuXF9OKYypqJ1drlELBLu/rmu Q5zujL0lXQIXGFPsHkH9cLprPtkENM+71HUsCOgSzQiu9YDjM+g6TOYQCZSgLkL7/H+wKf Rzu3w6/4EFkfzK3kfl06/3mNZ8/Ixjw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737606654; a=rsa-sha256; cv=none; b=IJ8juLfgxUnfCD9knZbqU02jtkiZgHpwntXF2WGcg1rroMCYQWragDVU4dYhJSISA/VnqG 15/y7SVE0/ME/G5/QkmTsINFOoobOcKIAaK7ucCSfnu555hbCl8Yw+RAGDDODLm++GXBua z7pkdv8BzFCJSqDhHKFV6A4l51Rwjg4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com 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 1taols-000000005uH-2wHI; Wed, 22 Jan 2025 23:24:48 -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 v7 06/12] x86/mm: use INVLPGB for kernel TLB flushes Date: Wed, 22 Jan 2025 23:23:25 -0500 Message-ID: <20250123042447.2259648-7-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123042447.2259648-1-riel@surriel.com> References: <20250123042447.2259648-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6861A8000A X-Stat-Signature: ky49m58zh6mfpjsk468tig8yzfp41nbf X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1737606654-854434 X-HE-Meta: U2FsdGVkX1/rq3iZUzelVh5cKjt9NOTqXOSq+qV7CF3dvC4ji85FKHy+guCFevnJ+/Vrgs4TIbTyBn+AoVB+ErnkjB8TzBpqMgMiXukNv2zDcBVE72E/4kq+5Vs8zuUdav/nruROaEXUI521S0d3yI0puIvp1fk5S9N1/5SB6Yil16VgaMPB+9iNbLzV0Perdzfqc4YoSOoRe+CF1IyRqnZgPHQi0p6eR6eZQIfv+IjqBXa4qouk9Evo0cKY00GiRSI7k4bQmTQL/UIOt7XzN/VsWDVmxxuImwF+Y5E5sbQk0wfo+2rWRyg5p043fffZFScLSimUh8dyepqCHkYlBHu1DdoQfVn4rX113kg90GbuSHfkS33gyEVTkAeTTCHs1K+DYDSc94RQ2siWCZbrmUEdPvkiQ4txiUVyf1xrNua0mA2d+PawJVlGjRjW2eLwGHyoXPw3gUvuqCtQ/oEqWhugYUxqKSAsGDKFwD/kTCx20bEWVhtbYhV6kqSI7zLm7mkHLO2M4BTr7ZgOpBLEV/skaSdqJvo2xJH9l84D8xvBmZ5c/SB9jAXdxmvzhfEgafN/v6QiQz+AY9gkcpcl0hrVfuJ+0dtDAkpmnPBckqE9POnS+OjLcfzHCNv245+GGPrfzinBmKM0dpZPVxMS/VgKyk7HGevpVHuRYEEXtfnZUQqCoJKdYTtGy4wLxczeLWRN44GHunBWQLUq7jLVdYC9DmCSSpH8WUZSze/ij4ymjID8l+iyxWV3hAqXbAKQxzSBZf5RlvUDY+nedvLqTBXbLUK6AuUzyiIAb6u6NhXUQ81WW8cwTymph68ugyO/VOFAgafT8PGnX6hctQqDrLRbeNYuFnt4FJCDd2OBJCMT3Y4+ZK8o+YqzF6gD4YjL2H+4xuM3HjkpzerJHgOM7uEAPddfTT6LiAabiyim/Nwmw7lIBWNpxlYSyhWS9p6UleZyThsFQbXrGFqnXUO uZisjIgp nZ8MRDnSK5zk4/qQl++T8dD0nxtv0TyqIudj2UcCq6ThxraHYArWybQ+mcoNxxOn9epRTdCoE1gMA/pvPp1kNnFTpINsapWt53b/jmKByechsgR0uke8Lc9UBNi2EeadD6kBT1V4z6zd3IeUAa2/QFYf4JlrC43eMkqKOqvGT8gfmAgmRohW/GrlpOjhzNEXvVVcm+aOM+ALAgzoh4BslqfDA+Q20BbpdWxp0ZNWj6Q/APfboILWxQEfXLBBLlftW2nR4JG1IkAJ7KOng3qx4yVp2LNfI5bVfKgeyr6M8n3zuRdFx88habamN5Iw8Q3GNmezQDg915QbGCepGmbrDpTRacqc+9NxsApGjG4jNhSfgBNdTxylykHqrSHY9BU007HRL 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 4c2feb7259b1..2c9e9b7482dd 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 (info->end == TLB_FLUSH_ALL) + if (broadcast_kernel_range_flush(info)) + ; /* Fall through. */ + else if (info->end == TLB_FLUSH_ALL) on_each_cpu(do_flush_tlb_all, NULL, 1); else on_each_cpu(do_kernel_range_flush, info, 1);