From patchwork Thu Jan 23 04:23:19 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: 13947931 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 4D48FC02182 for ; Thu, 23 Jan 2025 04:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D502D280002; Wed, 22 Jan 2025 23:28:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD8046B0096; Wed, 22 Jan 2025 23:28:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA03E280002; Wed, 22 Jan 2025 23:28:12 -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 99D676B0095 for ; Wed, 22 Jan 2025 23:28:12 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ED5441C7DAD for ; Thu, 23 Jan 2025 04:28:11 +0000 (UTC) X-FDA: 83037434382.15.560CCE9 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf24.hostedemail.com (Postfix) with ESMTP id 8A948180003 for ; Thu, 23 Jan 2025 04:28:10 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1737606490; 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=n74MgtiI+hlYxrlu7xTis+Lrvv+o4C6zaxoOlFz5Gug=; b=GXZzQ0LOP0cU02fst6I9gNrHsIpk1Nd6hEho7upzr3PfqJYVobWwqmii8vvOKbBjn0bq4m 1n+QDaKsfdcAlFV63dFXkqzyeRNfQLVT3fOFCU81VXitGFYL/dmhsVt2MUDOxhYGQU2Kcn fnCUDglOQM4J1pdgjOLuSGPRmBn9Nkc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1737606490; a=rsa-sha256; cv=none; b=SsxAvCTwQfO74DWHcZ75ckDLFJH68g06afGcpIduVRYydYj7px/3kL3cyRvB+D+T4oT9/r S+k8G+wbI2ikNyRTFvt5C19HdvRpuVQsNWBqkhYXB9MjEmPsYp/jPUFqAAQpt8W9/UBics 604eJe/PpKpJ3X9gJaR1Poah7tFhBno= 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-2KaJ; 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 Subject: [PATCH v7 00/12] AMD broadcast TLB invalidation Date: Wed, 22 Jan 2025 23:23:19 -0500 Message-ID: <20250123042447.2259648-1-riel@surriel.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 8A948180003 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: joekiszm9xxriarg53brnidyp75pu4tb X-HE-Tag: 1737606490-312524 X-HE-Meta: U2FsdGVkX18/K3cPNTyQS1J51zg62pklc9uf1P5VEX7hn4I4ALAFdExKNHp/v6XJMBzUD3tPrJ4xWATsKvvn0I9l3MFlSSMbknpH912eyU/2nPMovciCNdoDv7HCtwv7VHO6LmBEP7Wacz1Nm7F9ByyAPaJk1M4vdW9/1vNjNKuHC0muqx5X0KNnmqQBCH/DmA3Ed5D9A9m/xm1rOr6lWvghE7709zIprNMPNOb+En8P12O8XI9NfzManjoOYdcze2kd7Fl6cEzSnbk5oeUPjWNuj0NglaWDYGYp11wKZvecnoeOja5zPlJnsrxxtmF1oQm9qrcaqcbfKAZX1EADK5EIP6pfOEstmtm+nBtfK8+T5Bhe0Wunvon5t/TUtOTsi3y14DBwR8hvTTXNm4vX7lWq+z+WCE7AvzboB6cAwC1sYvmWQD5ITHtTzwaxK/LyNGweEz1Ytx0AaPInaHQM6zSeOF6JwX6sQbnExlSIKWV2tbjvbHDh2NqB5AEw52b8fuFYaEzB1QkzcE9aqERwVHMIlU7pWLjjGc7uM3WRdXiomyDKokYAfXFD1E3cl31zO6ohYuyW2orCSLk3rke7tM/NOZsV9J8/L3sfdT5pQonw3QNR8mqJ8LmubVVkwpPmIl8N8TMG4kznwjqj4oKok6lkn9GPL3wSXi9fLBwZpt46NA/prancWX5s0eYzSILAYVtCKs0hTlbVh3s0fl8eLTQR1iwo/eFoo8mPwm4rarNF8/YYFusB/DV5ck40l1+i3DxwLwtFzdxH785CTdFl03OHUuWV4nWCKdKp8Dj4tW8ggvwF2rXcaU+6pd0dHi0fUvnc7v9tYjAYDtPN1fBsIF/HrZ4ZrFlAN3mLuC2cW+fz0lCmR9iDOZ6e5tk+FfVPqG9wp/Yi5Fss7tpOvyq2Lrcxa1io2PGVaCLgaCOogW5/mgGDQgCfr2HKxoTv1WFLhVbCgBvDfdvzzm2TgR9 90RX54Ft NtfD7oSvL4qs6nD8FgYGKrN1CKX56mVlQjI8tUI5csIMupCUT9XYGxu4VqZhZQ6wziG+wbB1cfCYASKuEhv+J3sxY3MQu4J6RCbYIfXnQdu8Znn4wdSJADs5/tfW2Apz474pYpIjRlH0nuQ9Pf+91ePx4QVLHyVYGEfzEQ198HyyG+n0xooDrf+FirQqGCB63iRnUYdHQf7y7IG86X3Xv7O+/Y+IBO4Yx9BPoePJVAeV4TJfuqMb3+UN/N7Si6G0QWttMV1SV/QT50+rjVsvW53TyZwslNeklwbWz9uzaMfYrCqNUmJlpycQZRmbm8tjqwio4VuN6ELyagw6PpPZMnOReH8hUx271/oJ9r6MGXMSLElehjL74KAP+CrFojX8U96VvoOuXGDCupVoVEAr8MTVPkfh4M7yz7atea3dcUexbiozHiNfGoya5WjpnFlTiEL2q 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. 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.