From patchwork Mon Jan 20 02:40:14 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: 13944698 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 344B4C02187 for ; Mon, 20 Jan 2025 02:42:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99CBA6B0085; Sun, 19 Jan 2025 21:42:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94CFE6B0088; Sun, 19 Jan 2025 21:42:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83B7D6B0089; Sun, 19 Jan 2025 21:42:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 686BE6B0085 for ; Sun, 19 Jan 2025 21:42:29 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1C662B0D0A for ; Mon, 20 Jan 2025 02:42:29 +0000 (UTC) X-FDA: 83026281618.29.F6614EB Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf11.hostedemail.com (Postfix) with ESMTP id 7BF9A4000F for ; Mon, 20 Jan 2025 02:42:27 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737340947; 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=Bbp0/sigDBTr+f+CtrqSr07MXuq1Z6IqhYRRaMuzoo+aYQPrAoqEJIbaKOencqvVqzq8PW rQMEDz4Yy+fm1isjlygbMmHBz8JvGttHwszpA/uqiDLVRkHxzVXqh4cfrrVI7Y5SXVBeOh e3BeeT2JHVesDWq6q6OwOfLlQPR4qMg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737340947; a=rsa-sha256; cv=none; b=NwYw+U27uhDK7SsVebT3ng1dLW7xRddTuRM4b1Shr5vczwIP7yiV2zPl8oJUs0V4m8XMK0 qJPU52N+8p6bJPMc4qyoSMrRG/xNextukEQ56MBGauQp5xl1D5ub/jSOdB4+2H5oX4sjzu o36SDKS293ZyCA7PdA+k3Z780e713JY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none 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 1tZhis-000000002w5-17Y4; Sun, 19 Jan 2025 21:41:06 -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 v6 06/12] x86/mm: use INVLPGB for kernel TLB flushes Date: Sun, 19 Jan 2025 21:40:14 -0500 Message-ID: <20250120024104.1924753-7-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120024104.1924753-1-riel@surriel.com> References: <20250120024104.1924753-1-riel@surriel.com> MIME-Version: 1.0 X-Stat-Signature: dqaahb4jfnr45i8weubpncsk4ywxex5z X-Rspamd-Queue-Id: 7BF9A4000F X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1737340947-769232 X-HE-Meta: U2FsdGVkX1904r5pnw2ZRJPGPcajTe+4CC0zyuRFVfZZimaB6Hu/4GRpViCJZ13buW1gZtXz8XQv95kvOSuQR87fTs00LqDzy7FEXH5SuOmxXK2KpaD/YAIiTm6uUQ7wj3y+ZElZpi9ufaxQSGxtX04jTVaWac4oazPlz/weqUdLiWXkStiSN0D74D+/hpmJtyeD2/0b3PkaEZM1N0KiLq3thB8nrCfnmzfra5cozY/vtluqPNRL6TciUPwBeFYxDsW8oCJCfhLjN71Lr64EJUE/HGwliNhJhXpYoVUaT4mfQx8UMjVmQH5ypQJNIqABsrWeqsYQ7Y59txea48mW5E3LujhiPOrPEAfb32o2CJUNYqnOB6GCkh0suWUyw22yCnQcVbkxmdyQbxVizJceI3fCF2aOBDA+WLDmjwqfwf99pO8/nk5FNdCgl7/WN57Rmn7IsCQAGf9PykVfL1m+sliLZL0xAZLLcV3X1+gNns5Dzx9yBaj88agr1mjTnpwvnVfgXypIO66W27u/ymI0BOiSuNgwbkFqMX4xzZZow26g2kRVJPilyiPQsk2nR7cBqVv/wj98HrnBGkkluIeyF/Dixq0hxi3kqGtOTv1bkSOAdBY+aY6CMKKNQdYXfCigN1+20EEHs8ZqRH7hMYnbDX+7emPLu+PScp8YTuaaBu3BjaQSDLIWR8hsyky/j77OQxoWHsVcsUaViNq9hilB6aO/VJNscKxOW4+b64U2cMcHGdE5+kJXIxs4EaUAs4yL4UDRplwY9rTw7zGzEUXs4WLZcjYTj3nKfNYJI5+sUpSRZJwHDi1PBDvbauZpgWYcBGmbpon03eJBkanhfsJ0iHu2EKwGharw2PeHA0jTCXoMTa5GceoUlXkT5NopC4XEGzDW5uWugJ4NvIZXymN7mCMAMvktlYiJDmTaa1M9O9Cb3x42QQVQLEAH5Xk+B44SbyXuF0sL6aWcWvyRqxt n+/IbXdm uXF5w+ywq7u21F1XQCTTN33sqIn6XteVIFdnWtLfBrQOd2mv+qQ305W7oiqx2vizy63M66EBdKR/qqfGlhwxl2SaMury+Oj0xAoTrSMCw4iKPw6EWAzOtL2IT1NSDopaL78lPZSoTYR9/KPngrGJZTWdLuF8Fr3W+eQc253M4aTjiqn6MgOCRw+Psrh7zsF/yHqg3ID5gvZjnxO79lLeqmF0WCLYkQdYuMrsnrsxe/GJgFa9Usp3YcM+5CG/+FTWBkQ5V/TJQbackZ75AU1pKLvBUAZBZWEHhdIkywDb5a7k8FLm6/LBkGHwKuz0Sn7LUv15Vt5bOybtR4VVF5CrFSB4kDe608zFbeXBykX+X1Y2xVbKsgw/eYuvmHex4XvEoEDGL 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);