From nobody Mon Apr 20 20:18:34 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fzxdX1XnVz6ZXs9 for ; Mon, 20 Apr 2026 20:18:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fzxdW4GTfz3xhc for ; Mon, 20 Apr 2026 20:18:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776716319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=f/PNdvqQcj0smn2VhRVWHjPyAGyygxQeFIALL1DvDQI=; b=Flt5G9WjQdUfJGY5QoxWY2Xn01mhjzF/Q3efjApPdRu+OI9OcQqzIGK7x4YwasJtMf2nls g17P7gCq/UuYup10jw6OZyKQ+gjdfz35wLs0N2Ij3aR5Gdg6uD3MTroYhZB3xXZwWn8F0o U8+Kr82HSpkWp5bazo65bu+p/A/ZVajmTeu8RUfnPjD3NXdJBP6iftW+QC/KTY5lDK2CQ+ WI99k1cbb5CKoH6lOjwPhc8sPwjdspLoc7/uWf5ajFg1tce9vEE2lRSxXb/6QLu3i2/Lsj eqD+WBiyJz7+GIT0f0TEmZZ71uVOuDHVvDf0eFIQAVGHVHKGZ0Sd4jVxCgDMSw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776716319; a=rsa-sha256; cv=none; b=tzmeA8smy3GB8fuC6maarv1dPYJpFgjq/6Qw3y12SWsmqu1oGK7qk8NQ7JCCwL6DAPlZT2 G270BV4mSz4NgY7j4LM+tRtsryG9pJ5HOhS/oPnr5o91wt0m4uA3L5w9ntkQxwmSZguMZa KyvHhEoJ2jl5gZy/O+kiksYYhGGr1qhM0GjpxJpy8aQ4qi+9lN7kyvTA0btN/aj6yqKXNg DGg+/NjEr5+xYKGv7IA9gMlZdQ/qdCDhTLL2oxz0YVjhdBM++qFWRHE8Wvjk5hfsgo09b2 91owyONOcNH3LLZSnOSMTnAjgK/yPjOT9tSF+Md9mJsRai6UfQLMvQ/9kgtiWg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776716319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=f/PNdvqQcj0smn2VhRVWHjPyAGyygxQeFIALL1DvDQI=; b=SxmZCE4HbZR3y3iRvImQU8Wwx7fxRa/axlUUPj1W9YJba6XMnWigx05K8kAhRjgm8iCh6V IDdAjzTPWz6+9T4XpEpurTytbAD/LUQleQM5730RUUaBplo+Atn1chZMoJ+DH7lSwUsDA0 PiUN3Blx8KdawLJhBSWBBGxJDU0vj8kZUIbFB/4tt2s6g00Vxriob32S444EbC7Yw5wfJJ n7BXJfumUlz7fJWwWaWeDP9sTwCcJ1o1Z6+L2yMPEhbBYoyZZIUtZ5Xu9xkDJK4YzrYvoo XwNSOyRr3S4FZRHJ1Z6z9Sz0wB8X/x5trZa5lkj4OBWJVrKm8gt6M22hbrLkxQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fzxdW3XNmz19tP for ; Mon, 20 Apr 2026 20:18:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 210c6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 20 Apr 2026 20:18:34 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 1b8e5c02f5c0 - main - amd64: fix INVLPGB range invalidation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1b8e5c02f5c07521129e06ff8ab7c660238fd75c Auto-Submitted: auto-generated Date: Mon, 20 Apr 2026 20:18:34 +0000 Message-Id: <69e68a1a.210c6.6cfc653d@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=1b8e5c02f5c07521129e06ff8ab7c660238fd75c commit 1b8e5c02f5c07521129e06ff8ab7c660238fd75c Author: Kyle Evans AuthorDate: 2026-04-20 20:18:17 +0000 Commit: Kyle Evans CommitDate: 2026-04-20 20:18:17 +0000 amd64: fix INVLPGB range invalidation AMD64 Architecture Programmer's Manual Volume 3 says the following: > ECX[15:0] contains a count of the number of sequential pages to > invalidate in addition to the original virtual address, starting from > the virtual address specified in rAX. A count of 0 invalidates a > single page. ECX[31]=0 indicates to increment the virtual address at > the 4K boundary. ECX[31]=1 indicates to increment the virtual address > at the 2M boundary. The maximum count supported is reported in > CPUID function 8000_0008h, EDX[15:0]. ECX[31] being what we call INVLPGB_2M_CNT, signaling to increment the VA by 2M. > This instruction invalidates the TLB entry or entries, regardless of > the page size (4 Kbytes, 2 Mbytes, 4 Mbytes, or 1 Gbyte). [...] Combined with this, my interpretation of the current code is: if is aligned on a PDE boundary, we'll use INVLPGB_2M_CNT to try and invalidate PDEs with a single call, but that only works if is the start of at least 2M pages. Otherwise, if or any of the subsequent PDEs isn't actually a superpage, then we would actually only invalidate the *first* page within the PDE before skipping to the next PDE, leaving the remainder of the 4K pages in between as they were. The implication would seem to be that we would need to inspect the range that we're trying to invalidate if we're planning on using INVLPGB_2M_CNT at all, so this patch just simplifies it to a series of 4K invalidations. My gut feeling is that we likely still come out on top vs. the TLB shootdown we're avoiding. This seems to explain some issues we've seen lately with fdgrowtable() and kqueue on recent Zen4/Zen5 EPYC hardware, where we'd experience corruption that we can't explain. PR: 293382 Reviewed by: alc, kib, markj Differential Revision: https://reviews.freebsd.org/D56458 --- sys/amd64/amd64/mp_machdep.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c index 3b16845e2d87..c5c56024f561 100644 --- a/sys/amd64/amd64/mp_machdep.c +++ b/sys/amd64/amd64/mp_machdep.c @@ -739,25 +739,12 @@ smp_masked_invlpg_range(vm_offset_t addr1, vm_offset_t addr2, pmap_t pmap, addr2 = round_page(addr2); total = atop(addr2 - addr1); for (va = addr1; total > 0;) { - if ((va & PDRMASK) != 0 || total < NPDEPG) { - cnt = atop(NBPDR - (va & PDRMASK)); - if (cnt > total) - cnt = total; - if (cnt > invlpgb_maxcnt + 1) - cnt = invlpgb_maxcnt + 1; - invlpgb(INVLPGB_GLOB | INVLPGB_VA | va, 0, - cnt - 1); - va += ptoa(cnt); - total -= cnt; - } else { - cnt = total / NPTEPG; - if (cnt > invlpgb_maxcnt + 1) - cnt = invlpgb_maxcnt + 1; - invlpgb(INVLPGB_GLOB | INVLPGB_VA | va, 0, - INVLPGB_2M_CNT | (cnt - 1)); - va += cnt << PDRSHIFT; - total -= cnt * NPTEPG; - } + cnt = MIN(total, invlpgb_maxcnt + 1); + /* 4K increments because these may not be superpages. */ + invlpgb(INVLPGB_GLOB | INVLPGB_VA | va, 0, + cnt - 1); + va += ptoa(cnt); + total -= cnt; } tlbsync(); sched_unpin();