From patchwork Wed Feb 5 01:39:49 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: 13960410 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 00890C02193 for ; Wed, 5 Feb 2025 01:42:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2583528002F; Tue, 4 Feb 2025 20:42:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 208FD280029; Tue, 4 Feb 2025 20:42:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 059B828002F; Tue, 4 Feb 2025 20:42:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D0CED280029 for ; Tue, 4 Feb 2025 20:42:00 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 92DE4C032B for ; Wed, 5 Feb 2025 01:42:00 +0000 (UTC) X-FDA: 83084190000.12.05A7DE4 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf10.hostedemail.com (Postfix) with ESMTP id 1C109C000D for ; Wed, 5 Feb 2025 01:41:58 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738719719; a=rsa-sha256; cv=none; b=SByLrA62h7poFMTLBAvZkmgzleXI2jsV9Ji1aaj/BVjsKG3O5BwIIHukNSmzVm/UdB8dRL DcAzGc3VzIv7tOtbhDLtyqSX5CxE1iCtgAOQFBORJaieNdBceG0PAeZG2uOPleOeRytx3B klE9liZJ7Gd3hCKplczqTXDcBNj5L00= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.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=1738719719; 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=MULbLw+MqfCRKLPj/368UEI3/L52LmUPMFNvwQQ+dmA=; b=m8XiGy5DzQxOa6YCSdoG4HhKqIOi+b5BXzcLJG6JIsLrlkKVAySnUmsfVe6WFfQeWlZrAJ GbFUMRvygc3ARryVvKE5qUzH3tcSPu9hs1bC7BaxBRQTiTk6DSy4NNNU0rG7soNaDrYeoC 2qnBR9PwT8Bk5oFZ/2XxwsKVuzTZjWg= 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 1tfUP4-000000004Cs-2M6m; Tue, 04 Feb 2025 20:40:34 -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 v8 00/12] AMD broadcast TLB invalidation Date: Tue, 4 Feb 2025 20:39:49 -0500 Message-ID: <20250205014033.3626204-1-riel@surriel.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1C109C000D X-Stat-Signature: 4bbusegzbp5kf4fa6ccd1sbtdnydweyi X-Rspam-User: X-HE-Tag: 1738719718-194782 X-HE-Meta: U2FsdGVkX1/JDx5+EPtq/76ngaCkzLiOCVT0OMp1YclmoxSWrmjdcv3tSyG/XNEYjEUngWiZq03MxK883FxKVCb7cGmPLDTmqwt0FAWjuWlrWuMP3JyrE3vQYJYJOAc/5PmVfZUIXi+PASKhP/OPWfknZcfH7mdyr9yJofGUT7C/PoTHga7FG6HVimA90X8Iknc95FAAItbdGogBmxI/eiKNk+Qtn9GiTFioCutQWlC6J6MJLXbAgXtaUI29GCkOjhI4v0y7KWQF0daEi6q1P0t+Bo/beealI7CpLZPX0sH14ZkQlzN7hCszQ/BXbQ+i25bGjz6+XQJvlhkk75J5w4g7HD/jQaZ/btg1TiLILwImU1OdFBk0lyeWs5w/VjWT/MxUg05tSERoiq8iCsPu5W94+JsySUsU38TLrXymkJ6RxNr2P4q5r+plLhk/JO9awpr/WPpucfyHqwTlCZGiDM3WUL2CnUrFv2Hi4Fm2B1MzprqlpQkOHcOgR71cSqNgw3k0KuKI3JkDCstLzyNTF49DunzZjqKxVw63uRxzTJpBhx43hZHD4k3kCi4HEtK4GOwxUm1YKPcjnOmnickt4wHbCvfi2C5KsHWuidbuz/KVslaa5HYq1N6kuRl8u6f+jHC1WEi3xNLHBdUycpUybRt0q7ptH7M2mIeEo59yPdZhB/1LlsA0QW4ZyvpsmijTyU1u63CxI8KGx809MiXzWqjkkrCuGTtxEAqz44ntaBR4JpuZB+LjwbEGNXIzAXFupDc9kZ8NRISPWQGjyFePceGnr5dk8Co0EXrg6ZS+t9k5YoF9vCPwYhKoZZf9mVsruOReYPkc0bgnSNtu7cnvBmNT7kjjmRmo131tvw14/IA13AeMdMlO5WZcEjkAWxItsy3awSQIHII0yC+Qe0AlruCw8Jn+MN8C4GfxfcHZA9T+3Ov1OJWUwmnwnOsj1X2Xt1UlzrI8EnL/fZXxWf6 YBDpztVu WpZI+xegRGDQxb4iY5UWV8wDZMW5KHuJSvHi0veLUBGl4Tmo3UicbyWlesljR2QKMI89GhF8rgnZFJOLQwzq7RxXtdbpNmM2522Ghi6wsoku/qDh39SuoMvzG/BW958sES32icV3kWbLoHnElD/8iosZVziIqklVFwAEsi4H1nlXcbhm5Elvi6VR2rVBePE298G8vawAL5Ssgmcs/WgVI6YfbBkTNmc29tEh3ddf2Vz9213YpUgiXhTUlbCbC+yHQkr9/T5lh6ibcofXYt1duqjduRyjUw477m9C6K4fX4FPTafwxwf2fKlzcYf25aszgPSGZrzZ3Ry/w8FGahmqNKoAqrma6YslhvpKvM/FOAv/lISVkmOCs88R8v1jNzF7Oj94P7ef17CSbEmPe+I2mhuZdaw5H1eRL743TDyVaqsxMe+xR5CsNg5zmvx/GnlxpGS9to7t2bpphL2DTwl9mykQLzsz/xI0vcxkL4F/ykh9KwQ3buQNayqB5aTTUbqF6COVLJYILYLMvJ6NBBcyDBv0RGQ== 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. 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.