From patchwork Mon Jan 20 02:40:20 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: 13944706 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 3A005C0218A for ; Mon, 20 Jan 2025 02:42:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AD406B0093; Sun, 19 Jan 2025 21:42:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10F32280004; Sun, 19 Jan 2025 21:42:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C18C8280003; Sun, 19 Jan 2025 21:42:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9678A280004 for ; Sun, 19 Jan 2025 21:42:30 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 59976A25C4 for ; Mon, 20 Jan 2025 02:42:30 +0000 (UTC) X-FDA: 83026281660.23.CB48CB5 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf02.hostedemail.com (Postfix) with ESMTP id D2B9880008 for ; Mon, 20 Jan 2025 02:42:28 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.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=1737340948; 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=Hy4D9J9nmBUb9Lf1G6acOHlxSECGuf5KiKDnY6lG3eQ=; b=csLJOISc15G0eYTzUtc7r07vflor6pGD0rlKr5DtrMCi0EaCQfn0GAj9pdk0roxZnHD3MJ qU9gn/doyFMpioMdBHrzI5vFLVEccHHDzstvg51+FMUsAWG7wmHe4SoLfsam7Qzw+dXZkw yG8Xvx4lTIZjjYefyYGJ5YsIesQQRZs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737340948; a=rsa-sha256; cv=none; b=3u6tfiyE47cuW4cQ23OXDPHGYj4axtsK/75MYxfR/pJbdvC3NTGsRXUX5CWS6TMBGlMv5j ehc5NBSSHyASxcFHCGDAhaN/NmlezhIxokt4ra2t8vaL7APQDC4DgY2sZclfKenzXr9xIj 68/yrmTQ02cIzN+J0YflRJbv/h2LRSg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none 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 1tZhis-000000002w5-1hzA; Sun, 19 Jan 2025 21:41:06 -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, Rik van Riel Subject: [PATCH v6 12/12] x86/mm: only invalidate final translations with INVLPGB Date: Sun, 19 Jan 2025 21:40:20 -0500 Message-ID: <20250120024104.1924753-13-riel@surriel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120024104.1924753-1-riel@surriel.com> References: <20250120024104.1924753-1-riel@surriel.com> MIME-Version: 1.0 X-Stat-Signature: yym5wto4ncy4o4i4ncodj1xq9qj1oe1u X-Rspamd-Queue-Id: D2B9880008 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1737340948-521718 X-HE-Meta: U2FsdGVkX1+ERRYISK9dcEOWdA2AGAhttcHjqxYbB1bVj1ajZ8EB2XG9IUyuLOQBXbKAQC0bRuvUtCjW/fKic1U5J93jN0Ms8RD/Yj970SY1FuEBhi9dPbsPjAnDnk4bD7MWhdEWDTHkZAApK0DKkRW7F25ndGsuCW3E1Qt5cDvUtHCpJWyoMUyv9wGJ02nM/etBktrp7BTd9y9C1krCNOk8gtnzDslwecIIukN2CtOApeQ0rTk+Ouo/S4FKlQXacgBgDM0/SHuwEF4LNYD7Toxp6o6TCf5atKWu4cSgWX+GgWW45FVBWPwaJOiEJKNq/XvjSN2zhz4Lxmn5BaK/RdeMCo7B8lL6MzELcqtcoDT03w9Sv1qPGEwzUCM/9ZI92OT7S9xm6/CQz/7yWRHccsFHvZjUyEEZasN38vEhEOnbTp5HX7oqLCb7MFby4eJkCyYjsHmz3ADObjh7YYug8Do9W9ykZehi6UMAYNVoA2mRFlcM0lUWVezNk563dVOx9CmAildmm6NWAaOz71lt/ysdyHZb9+z7CoM/tuEiaev0LKoh3jtnubgJ6Jt+rdCE++C0hNA0evLB1DiOjlkQhtn6uzPJrU9u5WDaXNp8xvAmowcmG/cmLqhKq5v5RRrCklmwIW4yOfNMirRdbiII7JCxBDul+FZwvXNUQaMY9NwJP2E2k70ZVEboF2hKe1wEuowS3uEx3SJcmDTNUX2PfeymSomsmKMh40gqH5xaXO0v/4kfA6BoleErJL2voWfi9wAsiT0bwXZMgpDinAQDd2WefLXMF8S9JYjFQuPKeK4dpZ86f0S2tMFumo0OKdLDwwdqvpUOCs+d2oiDHTqXWXAnf6vfgBpJgJwoOLRwC/TzMjvrahUlXhhoRyTCn5cjvSKQwJYukyl82tzuICVk2XUdvsrw+IDTrXRZgGAwd7VHK5z/jT4fFnaddQJ97YUEUxDjZXLnIMduWhAm5gh PNcVm4sC Sinro0p8R7qTzybpN5nl4UNpL4M/ytKFBt1F0f34RX3J7Un2cB+hnVzrg19V5eCrZLKWzvcOQW7kYwPjEva8ejR/VZQ8CIvoYTM9U2QCxFJss8wV/G6ixbBu1exaifgfGnkqWZ2fOaHaEbmBwzDPJyi8rzSFlPLEGNkuuv8dAYGXWfVrlv7FKQg211wEVKibitqwRnSA2A7DcIMCtYjwx9KDzVH+lg5U3etmNdbXX1RclEkz/aNlybIMSl0BiomX/zoeZwguW5+B38gvFwgcbUlbekkS67ZjFb8bgt7ZqfdfsUgzIXAa2+Qls6VBqoqXDbeLB6m62/ShP8nJ3wWi2YE9Q4kHa3K+QbJoSVlwus8pSBw4XbORJTbiD7qqkOs6UtgBZjkatj4qLE74= 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 the INVLPGB_FINAL_ONLY flag when invalidating mappings with INVPLGB. This way only leaf mappings get removed from the TLB, leaving intermediate translations cached. On the (rare) occasions where we free page tables we do a full flush, ensuring intermediate translations get flushed from the TLB. Signed-off-by: Rik van Riel --- arch/x86/include/asm/invlpgb.h | 10 ++++++++-- arch/x86/mm/tlb.c | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/invlpgb.h b/arch/x86/include/asm/invlpgb.h index 4dfd09e65fa6..418402535319 100644 --- a/arch/x86/include/asm/invlpgb.h +++ b/arch/x86/include/asm/invlpgb.h @@ -63,9 +63,15 @@ static inline void invlpgb_flush_user(unsigned long pcid, static inline void invlpgb_flush_user_nr_nosync(unsigned long pcid, unsigned long addr, u16 nr, - bool pmd_stride) + bool pmd_stride, + bool freed_tables) { - __invlpgb(0, pcid, addr, nr - 1, pmd_stride, INVLPGB_PCID | INVLPGB_VA); + unsigned long flags = INVLPGB_PCID | INVLPGB_VA; + + if (!freed_tables) + flags |= INVLPGB_FINAL_ONLY; + + __invlpgb(0, pcid, addr, nr - 1, pmd_stride, flags); } /* Flush all mappings for a given PCID, not including globals. */ diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index f731e6cfaa29..4057afb6edc0 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -538,10 +538,10 @@ static void broadcast_tlb_flush(struct flush_tlb_info *info) nr = min(maxnr, (info->end - addr) >> info->stride_shift); nr = max(nr, 1); - invlpgb_flush_user_nr_nosync(kern_pcid(asid), addr, nr, pmd); + invlpgb_flush_user_nr_nosync(kern_pcid(asid), addr, nr, pmd, info->freed_tables); /* Do any CPUs supporting INVLPGB need PTI? */ if (static_cpu_has(X86_FEATURE_PTI)) - invlpgb_flush_user_nr_nosync(user_pcid(asid), addr, nr, pmd); + invlpgb_flush_user_nr_nosync(user_pcid(asid), addr, nr, pmd, info->freed_tables); } finish_asid_transition(info); @@ -1700,10 +1700,10 @@ void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *batch, batch->used_invlpgb = true; migrate_disable(); } - invlpgb_flush_user_nr_nosync(kern_pcid(asid), uaddr, 1, false); + invlpgb_flush_user_nr_nosync(kern_pcid(asid), uaddr, 1, false, false); /* Do any CPUs supporting INVLPGB need PTI? */ if (static_cpu_has(X86_FEATURE_PTI)) - invlpgb_flush_user_nr_nosync(user_pcid(asid), uaddr, 1, false); + invlpgb_flush_user_nr_nosync(user_pcid(asid), uaddr, 1, false, false); /* * Some CPUs might still be using a local ASID for this