From patchwork Sun Jan 12 15:53:50 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: 13936448 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 DA570E7719E for ; Sun, 12 Jan 2025 15:56:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A5376B009C; Sun, 12 Jan 2025 10:55:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 454A46B00A0; Sun, 12 Jan 2025 10:55:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 179A86B00A2; Sun, 12 Jan 2025 10:55:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C1BF46B009E for ; Sun, 12 Jan 2025 10:55:43 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7A1FD1A18C9 for ; Sun, 12 Jan 2025 15:55:43 +0000 (UTC) X-FDA: 82999250166.19.4E3DFEE Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf30.hostedemail.com (Postfix) with ESMTP id EE26980012 for ; Sun, 12 Jan 2025 15:55:41 +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=1736697342; 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=epfmxknCPdhgsZNUdJKqDJe9mlMzHXmtDJ0K3nFZPlg=; b=drDzH8lNv60/6IZH5P8ZkrJiAEPd+eMaEJsSLNIKodPSxE/QsMYFS+35XmvFYMLXAifXjm V68pcyEpczHo5mVeaW+DH2umF2qAKbKwOu4xBmEhPvpJKNogsKB2umngGl4gKUh/f2cRGt ennyK4QYg8qfSq1fcmBRpWGc0Y61+cc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736697342; a=rsa-sha256; cv=none; b=8pOwx4BheYs5UhIY0TnBcJtyNfQlhgtWhbzmqOO978khPTzLaA+vsHTDuqvM0LsAJjkZhJ romTMpQR3X7jE9uOUYSG0XUikWY2BAM+m06o02I4GmrjX8ca6NrHUDiNZl8Nw1A/rGaHqv xKgb2cgSEXk72NhXzGkHHQEeE4ZfZ34= 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 1tX0Ii-0000000010W-35gt; Sun, 12 Jan 2025 10:54:56 -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, Rik van Riel Subject: [PATCH v4 06/12] x86/mm: use INVLPGB for kernel TLB flushes Date: Sun, 12 Jan 2025 10:53:50 -0500 Message-ID: <20250112155453.1104139-7-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250112155453.1104139-1-riel@surriel.com> References: <20250112155453.1104139-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EE26980012 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 5aktqfyzueiy1uo31fkgctj6gjzshktp X-HE-Tag: 1736697341-934625 X-HE-Meta: U2FsdGVkX1/v+DHURXepYp3SEnTl3VpQ4HceeIS7faYRAUnYAN90DgKN4aQLlfd8y6AAtWNH+eviBadU3MTIHvajXrWmchW2c4Tzhjc6l9qdOTsLeiUtGgM3iumkXxqYiC8b2H/RmYDz/YJ+UqzAMEDODxwoAnB932R0vyOdNGufM549895hVu4rhQ6viX/p615dwH8G0tSJHkjEFbpYNDZxMqYUl6ulUuR9vdQmMB52I8oo6uy5vmAhN22lNd0F3GBbtE7MGqhQv3CqhwV2qhIQi40ihW+dxCCauR3FXeUR7p/61aTaoBHIJ4SRqFxQsMpbJjs/mnjF1hDvI8XZtgLBHwR0fJFIcg3jAOCdlYJR+h976M0gkD++6mH/snCKCqIH758v7eX+JYYfFqHGwYLXaO/wsSU8uEVeDuVGcWJrj9SQg2+2eN0X13y5TD2Xy50aj4rcwDJAuPEy6frhWJvKMQ2eNybM8OwxQjz5ltk1GMQZXpNHdHV+LsT2drC+2FfHEg+VhezwKgwpgSn7fTyuotvYtlHOtCR2soaKor/B/7u+C9d2oR3UtmTnBI4eVIsuln8mD/OC4W1sjgKqRTfPazqtmqjSClw2B5T35hgzyCaNPNytYBj1T9a9MacyaVq+DO1X6lEbLgaLMmkmBFToYNDbYYaJ5V6JZqjLWM0Rr2lTKVfafjhwkrJkGFNK8xsWv9qm2rBJ2WWQ7k22GScmbDKDnVGmHJWUNRUIP4RhaLkRWIJBdNbAftsPzxfRpcQT9Vh0Ba39vohHLxk5UZZbGbd6wXxAjl3tb6DqD6ftXak/8b1s5MlHEfQy99+RUw/UZ6+hWDHLZ8Ki7iXx5x7EDyUlk0VVJQO4HtUrDO+gTBX4zr+ds3CkDi+CQzQxMcjS6/oZoVM7uGHaTFepU6WqTfoixMPnjCElDxv12ddhlmmRz5yHjRl4Jdj0yKoc4OF7Zo+OW2QiZHumNgj 0qucrlAC R9bwlPigXP1LmQQ4O8hdh3VkUtEXiPHwGWRe3ysCgpEiQvC6KDfhc2S9r3L34L6C9cfolzDjuTKX45V8ysBe2t1wQ7VQAKLyUDHN4QZMW4LUCVAhMR95jGrhNner6B3Hy9Cpq8NFSjMPbp7NndeG13Oe2X5i+HC4KAbJ0TKmjoO19GaN3PH6XlWDfzICl6kzXi2Nh7VofvIMyyCSpmi2Y6zANavHND7cV36iu99oVi9STpkCJwuMTPixv5kkKcK22yBBi7iTszlp5kXh1qKpidBYAQZ8sDuJf+iQLK50GVwXuhkGN+gmzgooRQNMNAD+BPG35Syjhwxm9J9aiaCJlAjNCj6yzhOJg8/UjoG/lf5nrw2ACgs17FEyIPhg1jjtEivfd 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 2b339f55f839..45c7b84f6f80 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; @@ -1095,7 +1119,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);