From nobody Thu Apr 23 13:49:26 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 4g1cs33F33z6ZlV2 for ; Thu, 23 Apr 2026 13:49:27 +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 4g1cs30NVQz3Xmy for ; Thu, 23 Apr 2026 13:49:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776952167; 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=osoanKBERZdUoGcztq/nT/psg60OgZLw4V0iRSnUfa4=; b=jSKymASriKUPzbWhk+dsa/M6KPUOQuaxxbXZ4TE4pVj10KLfWVyCzmJgw+ykeswlkHoiJe aXK013u54jnfizTSg12RCO2eLPioj3nLUH1VyCRZfC2vEeFbHxgDx71zQ7TTcsTvsrQbeZ 7rzdLGdwsBFh71iWf6zW7OeAT/N1DzcRg+r5m3fyhnarvfXrhHKBW+Og/y6OtrYjNpM9Cf nPI2Q+HrtfqotwlYD4ay4+q297O3gT5lZAzhAy2xDo+wrFFRCzp72XlrDYBMcXjfOZpq8g HumEYFxBFyQeuPHa2u2DRSnG8LBO/grNJsuDRvy5ZStKb5NsNzg3teWdsOhRnA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776952167; a=rsa-sha256; cv=none; b=eEx65+YOEZk5uUE2/FmEkugW6lWxadAfIH5hP0NG8lQf5x5SHTJX21ap1KI9Pb5b79IVii QFODMvsVkgC5+XhvNUNMYUZE6Mt/63fZ3qzQulYYj+MziREsnHriycYXAGivgY8AaJEiJ1 W+sXsg89Z+6PM8qTbfrf1QnbS2o5DdP51JvuNd+3UnfPmhKWjEB4c/4crrvqmo1OpxE1SU HnA0NtjhIER4tO2z+vBA2oJpcNWkUIkuBJ7eq2rFLkKr43DAMXl05LYYnz86GBSlPpKTs6 m2Vu2izj7Rc4wSR2x/k/YeL+EDpUteEC6D1yKPNr2ERy1VVOfD46jcJWaK35Bg== 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=1776952167; 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=osoanKBERZdUoGcztq/nT/psg60OgZLw4V0iRSnUfa4=; b=iNgURjK0ns9XgjJCbUtmPEH55xjqGCRex3rbZfBvw099PULMK8vO9P2sc648ndIb/84jq8 K0eit//cD3hdzIoZx9Tc2cxparXM4PwOuwbn5HPONLMqC2TI4wvpURYCfBhMA31l/LSLpK y3+2ZAdJqfUbEToEePQjdvWiLMWzUpBIqWVXA3FBx8/wrGD/+L+EpnT25JUJW7eIAvQELL 3cm6XygeMgL4rHLVYTjjrO8tRSCjSiOTXwVd0TW8DZXZ7XuElPKar1JGPyAxaHvY7A47yR tyJOxYxj2gDNGfT40ow9QqFmsefV/rGGjfSFWr8UbKeouhGFk2aJr1w6uetoog== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1cs26mTMz4DH for ; Thu, 23 Apr 2026 13:49:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2315f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 23 Apr 2026 13:49:26 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: ff11ae166cd9 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: ff11ae166cd9f8ae16a5c384d46aa1218f3ff013 Auto-Submitted: auto-generated Date: Thu, 23 Apr 2026 13:49:26 +0000 Message-Id: <69ea2366.2315f.220702c5@gitrepo.freebsd.org> The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=ff11ae166cd9f8ae16a5c384d46aa1218f3ff013 commit ff11ae166cd9f8ae16a5c384d46aa1218f3ff013 Author: Kyle Evans AuthorDate: 2026-04-20 20:18:17 +0000 Commit: Kyle Evans CommitDate: 2026-04-23 13:49:23 +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 (cherry picked from commit 1b8e5c02f5c07521129e06ff8ab7c660238fd75c) --- 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 8f3d339d9dc7..015f23f75df5 100644 --- a/sys/amd64/amd64/mp_machdep.c +++ b/sys/amd64/amd64/mp_machdep.c @@ -727,25 +727,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();