From patchwork Thu Feb 13 16:13:51 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: 13973613 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 96D7AC021A0 for ; Thu, 13 Feb 2025 16:20:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C1246B0092; Thu, 13 Feb 2025 11:20:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 270DA6B0093; Thu, 13 Feb 2025 11:20:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13876280001; Thu, 13 Feb 2025 11:20:08 -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 EA8F76B0092 for ; Thu, 13 Feb 2025 11:20:07 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 94C4A4B21B for ; Thu, 13 Feb 2025 16:20:07 +0000 (UTC) X-FDA: 83115433254.11.4DAC617 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf28.hostedemail.com (Postfix) with ESMTP id 1F34BC000B for ; Thu, 13 Feb 2025 16:20:05 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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=1739463606; 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:references; bh=Z6J5fYNdIDsKzrgP61wwTeh92jRQKGGi/P//Piv/+/Q=; b=znHBV7rwYVoNH/yZ2UA+FQGzh67e/T5//t7Ej6b9E+1ivrltkdODukB1Dl7Hux4L2INnyc dGgpGayjr0DaAcwLczRSi2m5y/bhWfCDjHmqFCHux4nys1tgim4AhJiJ5V2ObqBSAIpvSq UNRsJFh3FR4ZZmQ0ZhO1w0+BJb4DcCs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739463606; a=rsa-sha256; cv=none; b=1/TDrFlOAKSk6YNpGxY5IimlwZf26/HUIQRiYPMZG5TzFj21wEIDIzLM1nBBfWxlYo0b9q En8GeD3cpc232VeKPJfFTMLhuuHBekZcN4ZtbzvquFQYtXC7dnjze0P912hUrqFdMXDg6m 8MOD6arxTq4BXYx0Yg42AXysVsz1ZLU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.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 1tibr7-000000003xx-0Flu; Thu, 13 Feb 2025 11:14:25 -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, jackmanb@google.com, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com Subject: [PATCH v11 00/12] AMD broadcast TLB invalidation Date: Thu, 13 Feb 2025 11:13:51 -0500 Message-ID: <20250213161423.449435-1-riel@surriel.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 1F34BC000B X-Rspamd-Server: rspam07 X-Stat-Signature: 6p3wqa7cuphz6qgtia4w5yi5i93yoths X-HE-Tag: 1739463605-461927 X-HE-Meta: U2FsdGVkX19uAYS/CReIS4vzgnadFwIbOc7GKBJlfmDEwOYnkZk7oW3CqUM9goqogMSACCq6WMQEQh+M3NRAyJU5PCfBaryM6TkQ5sJc+LTPHwhrtS0tcyJ2bgs6exyqwMaU14eSmBKI6ZcSF7tnud/bcmiexrQcpp5RbGtNFtJEsQtrsSYblzJnHvEyT1ORzslsOqwms5qzx5zpo6NOBWVmsfG0ADFE6trLKcQHkFvccQzmdL5MYvby5w//2ZbFiyXmDZVpQk0l90xf3ta/hnFWVB77iXx/M3FsdbTXqCgJsJQO6ffAqJbIuP+VvvVwIZtVxIhnsSmppe/KG0zZWf+/NzaSQMcRTaILjuMa0nSCIPQmZpZgxTDxyf/gjKfy2+tlUIOpdcU1TU4cnI64BwNNqWqH/t/m75Q9Tmr2WSuXJB2/BKawLPP+e1Wco/gJjmie5SqAci7nUEoffNCNt1v8NMRQcfjYqJ7eVyOeo6g7icZkR0erzY+rG7bvHqbjDaB3l8mhmSz981b1NZBI3xzQyKK+pq+ICtuEM22wFugDGfVbl4aTCGiTyytYxyRe5SJTJmCNIT8Jm7lQTJUp0qbuwjicTF30Nc55wzyhQoxPpemEePrDu/c1DuiX+lHa0qcSt4t2dxl2IIxheNdMDfKeK5vaRy6/l/YcdBO8ymVk/U1F1Deeb4zfy2UXx83o9XurYP8Tyey+/ucX2O+5G6SnOZUEDGDRMlX6kuK9jeTn3PaNxGdKL0KjgKf98kEYnqeAAhcNNI5mMbSdNCoqodvGHM6dJetn4J/lzkGAhB84PrUwBVYcNQjKNA0GE/T1B2m3c1vCDNAJ6kHKAoVbJUdQ7ggjASJect+rCMRlTlYNvs03hKYe35AELoL1vo5Uy4NNOsoRlu+gA/zWyqZHkooHz06OGvEhkenejB8YDbz/aMfFNv9sfNHZ+25YZRmRleJpgn+p3EiLjbvzuCd 1ObcDJ23 69OIVxS62Z8iFl0CrdaXgYnO4STTm+B9wbLQG6sYdyCS7QK7oOUklztShRgIHdn0mkzRSqH33+upr/rv0qoTTNb2kbROnggnYvhnR813lNiu483Ro7JmwlnhTWkaQJgupHjvbrH1g/cwECSswwMS2LFfXY6v4QwlKoq/46QzrkORhcsosZ9GLA+dO9wOuP+rEr8sjAS5OmYmYi7rEjK3F/Fv/lSrkbO22ua2xxdBkOi93ClG9hrEMPHqitRPT+TivmdBoYENB5qnDxe0GoM9RIlhgOSumeuJGV1x84VqWrzVbHP1Q9G++pQQyJvYE716FWnMTAnF8v1FnjeRR3HXcwdBWJK+25+6DmXl4HBTK/iK5rnX7luYDPf4MZ8s+gC0qUuSZew+VE9rSx+EmKkdahBxOoHo7o8QALFL5r90qF30oGoIFW2Eq2vqmZ7YYn9g3dPjYiZykXLkOXPLym4EeXKVB6a1tCZ6A6it5Sijht9ZFN4yztPBbulRoJAddQetUBXG6qzA4V9sYsbdTOCTqlwWlmw== 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: Add support for broadcast TLB invalidation using AMD's INVLPGB instruction. This allows the kernel to invalidate TLB entries on remote CPUs without needing to send IPIs, without having to wait for remote CPUs to handle those interrupts, and with less interruption to what was running on those CPUs. Because x86 PCID space is limited, and there are some very large systems out there, broadcast TLB invalidation is only used for processes that are active on 3 or more CPUs, with the threshold being gradually increased the more the PCID space gets exhausted. Combined with the removal of unnecessary lru_add_drain calls (see https://lkml.org/lkml/2024/12/19/1388) this results in a nice performance boost for the will-it-scale tlb_flush2_threads test on an AMD Milan system with 36 cores: - vanilla kernel: 527k loops/second - lru_add_drain removal: 731k loops/second - only INVLPGB: 527k loops/second - lru_add_drain + INVLPGB: 1157k loops/second Profiling with only the INVLPGB changes showed while TLB invalidation went down from 40% of the total CPU time to only around 4% of CPU time, the contention simply moved to the LRU lock. Fixing both at the same time about doubles the number of iterations per second from this case. Some numbers closer to real world performance can be found at Phoronix, thanks to Michael: https://www.phoronix.com/news/AMD-INVLPGB-Linux-Benefits My current plan is to implement support for Intel's RAR (Remote Action Request) TLB flushing in a follow-up series, after this thing has been merged into -tip. Making things any larger would just be unwieldy for reviewers. v11: - resolve conflict with CONFIG_PT_RECLAIM code - a few more cleanups (Peter, Brendan, Nadav) v10: - simplify partial pages with min(nr, 1) in the invlpgb loop (Peter) - document x86 paravirt, AMD invlpgb, and ARM64 flush without IPI (Brendan) - remove IS_ENABLED(CONFIG_X86_BROADCAST_TLB_FLUSH) (Brendan) - various cleanups (Brendan) v9: - print warning when start or end address was rounded (Peter) - in the reclaim code, tlbsync at context switch time (Peter) - fix !CONFIG_CPU_SUP_AMD compile error in arch_tlbbatch_add_pending (Jan) v8: - round start & end to handle non-page-aligned callers (Steven & Jan) - fix up changelog & add tested-by tags (Manali) v7: - a few small code cleanups (Nadav) - fix spurious VM_WARN_ON_ONCE in mm_global_asid - code simplifications & better barriers (Peter & Dave) v6: - fix info->end check in flush_tlb_kernel_range (Michael) - disable broadcast TLB flushing on 32 bit x86 v5: - use byte assembly for compatibility with older toolchains (Borislav, Michael) - ensure a panic on an invalid number of extra pages (Dave, Tom) - add cant_migrate() assertion to tlbsync (Jann) - a bunch more cleanups (Nadav) - key TCE enabling off X86_FEATURE_TCE (Andrew) - fix a race between reclaim and ASID transition (Jann) v4: - Use only bitmaps to track free global ASIDs (Nadav) - Improved AMD initialization (Borislav & Tom) - Various naming and documentation improvements (Peter, Nadav, Tom, Dave) - Fixes for subtle race conditions (Jann) v3: - Remove paravirt tlb_remove_table call (thank you Qi Zheng) - More suggested cleanups and changelog fixes by Peter and Nadav v2: - Apply suggestions by Peter and Borislav (thank you!) - Fix bug in arch_tlbbatch_flush, where we need to do both the TLBSYNC, and flush the CPUs that are in the cpumask. - Some updates to comments and changelogs based on questions. Reviewed-by: Brendan Jackman