From patchwork Mon Dec 23 02:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13918422 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 F2986E7718D for ; Mon, 23 Dec 2024 03:04:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BC476B0092; Sun, 22 Dec 2024 22:04:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 86CA76B0093; Sun, 22 Dec 2024 22:04:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75AF86B0095; Sun, 22 Dec 2024 22:04:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4BE9D6B0092 for ; Sun, 22 Dec 2024 22:04:36 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 14981AF96F for ; Mon, 23 Dec 2024 03:04:36 +0000 (UTC) X-FDA: 82924729188.19.691C39D Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf16.hostedemail.com (Postfix) with ESMTP id 51EE4180006 for ; Mon, 23 Dec 2024 03:03:56 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.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=1734923048; 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=qpzsSMqzE1dtO59H1mvpeuDeXnr/EnNIUrW282zrREQ=; b=D/H4VxNUK1B2uzxmMmdV4n4mrKtfEXMG7bImpqLNegMst5re/LjVBV24Jc8c7p9tGyGdfc B2O4e1gUprZs4qlpcBnqIE8sBtP/0mS03wGR8Hn2hoj8fsC0OWHY080Hnr+U5Us/IgKuSa rNkTl2iIfz+8HFIIbzUrTeb8CinIgWk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734923049; a=rsa-sha256; cv=none; b=JsDypIXqbc/EjhCJ1w7Lxlg/0YbgFN3qY/7YLMEPbb4dz+18eovglNBwjsnhvEKDaF8wFx O3vEADOxMs9oDaA1dME6/Xhz+Mb2Ox5DmLGIzahNU09xkKgcP83JTkwGJzH77rQ6o0zDnj wOMh/rG5I/535PTTFZZ74Y7rGD47Zis= 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 1tPYdp-000000001Ih-10Ae; Sun, 22 Dec 2024 21:57:57 -0500 From: Rik van Riel To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, akpm@linux-foundation.org, linux-mm@kvack.org, Rik van Riel Subject: [PATCH 05/11] x86/mm: use INVLPGB for kernel TLB flushes Date: Sun, 22 Dec 2024 21:55:11 -0500 Message-ID: <20241223025751.3268975-6-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241223025751.3268975-1-riel@surriel.com> References: <20241223025751.3268975-1-riel@surriel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 4r8xdq5cje6ke988agnug5f1amm7mopd X-Rspamd-Queue-Id: 51EE4180006 X-Rspam-User: X-HE-Tag: 1734923036-588664 X-HE-Meta: U2FsdGVkX19oa4TGx5lD1ekfZIJ037tIaZK7/8NXwqf1jYWfonej5Kk/xvF/XAK36SG+W1o0RljJUnNdZa5i+tUzbKSrCkWZ97l4YKMKGWi6BprSbEG46EtrCemAghaH8bhML2gm/tGKiTlvVL0z75tW1PPg6q1IeN9BL1IW1s5pQ9KubKh+nA+B6tiw2eqF/KKvdIhCi+Fvu1za/sauhW28FptbuCyMp4KAeFx8LbRjZZUxtmiIBAk+eUpLQtJgnM8ROI5SFhvjivrhuS5iski2fpxtv5HtICz3C/vOz8BeWaPVobyFXa+2zVDnsU7krGHWwWXVQoc6raWseS6NEVs/lIzbPEcCcl6rp0t4SMqglJaIqkJzOd1cHLrJYllwcsxZ/OV7RG50ZYJ1zRysCvw9y3tNzsh/vd72MGtGw9XIKvjPydlDaVBnaLl+GzuhuINqUj0un/ojNGuJbfn9eJmkBhTTq6xh3ap5u8sftAOIhkZ5hq7sIy1PpWpneI+lATMbNYJcmJyZL/5rhbw8kA2e2pQ+VoVkwIIrSmb4xi/LyxUBcWZePXG+U2MxcRancWRZIEvDom5jLggfQApjPh+6qtZvQ6ooIsnVf2Wd2drw9DMf5t+sfvb7UP0j2X9OLUk9q7gsXidSFZLrZ+1O9VNyt47FBNmX0bvOLUONQU4CWw86UoAlXI4A7DTLv9dayQLvezhwhMM0gEKg1OxIy0SdfL5IXJRvUDIAaYWtwqjeQ3IooJCytte3QL0V8Y6B496Rh6+W2ciHCJZoVboWEfdFOptK6T1IXmhWQfWqbM5lJ8jH1fzgKbdNASSFf+tlvthFdGrCwruGsr9A6ib1l4QRV2TSY8dKpYba4nyneewzKcD9G4z9TlAftdzGyldRO6i+aCqC8mYzUbB8ahcjLvY4WTS9r8e4zSusKRgCDKuHtfAxDAhhLaWY1ft+DUDuequ2WbU5lGFigtkxxna 6aSo/VSd 5aAp9M758Tj27m+r5qYXi/iD3ALjCa/eX2JiX0aQpD0OX07S42cqexK934vYiFhErOYsrJPHp52qE0h72xAsIdvLr1B3aQx/I8Con0nE7DY4m6+PjSMLCLpz/q1EwdbfE4bJqvrZhi6WjjhziiN7sUCQx+9oaXyufDukndeuhY0pu3BRlVVZ2hx6LJjiyqIeCKasqfc6foPSX4keh76jfybGVy+X6ZPksHz+7PbkuyGKQD/79yRugH5KmVl5qUgYKmcg0N0bH+cZxvtiQeKanIxJxHw20lHG4TeA9wxxeDOI/ywXvLAgReesBaId8zO8X7DuE 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. This stops us from having to send IPIs for kernel TLB flushes. Signed-off-by: Rik van Riel --- arch/x86/mm/tlb.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 6cf881a942bb..29207dc5b807 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -1077,6 +1077,32 @@ void flush_tlb_all(void) on_each_cpu(do_flush_tlb_all, NULL, 1); } +static void broadcast_kernel_range_flush(unsigned long start, unsigned long end) +{ + unsigned long addr; + unsigned long maxnr = invlpgb_count_max; + unsigned long threshold = tlb_single_page_flush_ceiling * maxnr; + + /* + * TLBSYNC only waits for flushes originating on the same CPU. + * Disabling migration allows us to wait on all flushes. + */ + guard(preempt)(); + + if (end == TLB_FLUSH_ALL || + (end - start) > threshold << PAGE_SHIFT) { + invlpgb_flush_all(); + } else { + unsigned long nr; + for (addr = start; addr < end; addr += nr << PAGE_SHIFT) { + nr = min((end - addr) >> PAGE_SHIFT, maxnr); + invlpgb_flush_addr(addr, nr); + } + } + + tlbsync(); +} + static void do_kernel_range_flush(void *info) { struct flush_tlb_info *f = info; @@ -1089,6 +1115,11 @@ static void do_kernel_range_flush(void *info) void flush_tlb_kernel_range(unsigned long start, unsigned long end) { + if (cpu_feature_enabled(X86_FEATURE_INVLPGB)) { + broadcast_kernel_range_flush(start, end); + return; + } + /* Balance as user space task's flush, a bit conservative */ if (end == TLB_FLUSH_ALL || (end - start) > tlb_single_page_flush_ceiling << PAGE_SHIFT) {