From: Rik van Riel <riel@surriel.com>
To: Matt Fleming <matt@readmodwrite.com>
Cc: "Henrik Böving" <henrik@lean-fro.org>,
dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, linux-kernel@vger.kernel.org,
"Sebastian Ullrich" <sebastian@lean-fro.org>,
"Joscha Mennicken" <joscha@lean-fro.org>,
kernel-team@cloudflare.com,
"Tom Lendacky" <thomas.lendacky@amd.com>,
"Borislav Petkov" <bp@alien8.de>,
David.Kaplan@amd.com, kernel-team@meta.com,
"Ingo Molnar" <mingo@redhat.com>
Subject: Re: PROBLEM: Probabilistic segfault on AMD hardware with INVLPGB
Date: Wed, 8 Jul 2026 11:27:18 -0400 [thread overview]
Message-ID: <20260708112718.13323f59@fangorn> (raw)
In-Reply-To: <akzuETUv5XEFSRL6@matt-Precision-5490>
On Tue, 7 Jul 2026 13:18:30 +0100
Matt Fleming <matt@readmodwrite.com> wrote:
> Hi Rik and Henrik,
>
> I've got a small C reproducer that triggers this within the first round
> on Cloudflare's AMD Turin machines:
>
> https://gist.github.com/mfleming/ca26ad3f8d65a12d23d62fb176480fc1
>
> Build:
>
> gcc -O2 -Wall -Wextra -pthread -static -o repro-invlpgb repro-invlpgb.c
>
> Run:
>
> ./repro-invlpgb --batch --rounds 20 --jobs 32 -d 5 -w 8 -m 2 -s 512 -q
>
> The mutator side holds a pthread rwlock write lock while doing
> munmap() + mmap(MAP_FIXED) on the same VA and filling the range with
> {cookie, slot, generation, offset} markers. Reader threads hold the read
> lock while checking those markers.
>
> The failure mode is usually a CORRUPTION line rather than a direct
> SIGSEGV: a read from one virtual offset returns a valid marker for a
> different offset. That looks consistent with a stale or wrong translation
> after VA reuse.
I poked at the reproducer yesterday, and it seems like the pages
in the buffer get reversed between uses, so in one pass they will
be ABCDEFGH while the next run they'll be HGFEDCBA.
This showed up in the observed corruption pattern,
where the second slot in run N+1 would see the data
from the second to last slot in run N, etc.
All the observed corruptions end up seeing data from
the last run, from the flipped location (Nth slot,
where the page used to be in the Nth-from-last slot).
The change below seems to close off the race in
practice with this reproducer, but since I do not
know what really goes on inside the CPU, there are
likely better ways to fix it.
AMD friends, do we need to gather any additional
data for the hardware and/or firmware people to
take a look at this, or is there anything else
needed?
diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h
index 866ea78ba156..2d30426f9183 100644
--- a/arch/x86/include/asm/tlb.h
+++ b/arch/x86/include/asm/tlb.h
@@ -110,6 +110,13 @@ static inline void __tlbsync(void)
/* TLBSYNC: supported in binutils >= 0.36. */
asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory");
+
+ /*
+ * TLBSYNC: we should not have to do this, but it seems to
+ * mitigate the stale TLB visibility issue reported by
+ * https://lore.kernel.org/lkml/CAAuFnRTyva1_3tsF3vrMBL+TLS1YL4EgUPT2c3O9k7A9hWUMnA@mail.gmail.com/
+ */
+ asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory");
}
#else
/* Some compilers (I'm looking at you clang!) simply can't do DCE */
next prev parent reply other threads:[~2026-07-08 15:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 13:17 PROBLEM: Probabilistic segfault on AMD hardware with INVLPGB Henrik Böving
2026-06-22 19:00 ` Rik van Riel
2026-06-23 12:28 ` Henrik Böving
2026-06-23 13:47 ` Andrew Cooper
2026-06-23 15:59 ` Rik van Riel
2026-07-07 12:18 ` Matt Fleming
2026-07-07 13:45 ` Henrik Böving
2026-07-07 14:11 ` Rik van Riel
2026-07-08 14:51 ` Dave Hansen
2026-07-07 16:44 ` Rik van Riel
2026-07-08 15:27 ` Rik van Riel [this message]
2026-07-08 15:51 ` Borislav Petkov
2026-07-08 16:17 ` Borislav Petkov
2026-07-09 7:21 ` Matt Fleming
2026-07-09 19:17 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708112718.13323f59@fangorn \
--to=riel@surriel.com \
--cc=David.Kaplan@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=henrik@lean-fro.org \
--cc=joscha@lean-fro.org \
--cc=kernel-team@cloudflare.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=matt@readmodwrite.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sebastian@lean-fro.org \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox