[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251118203551.GQ3245006@noisy.programming.kicks-ass.net>
Date: Tue, 18 Nov 2025 21:35:51 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Maciej Wieczór-Retman <m.wieczorretman@...me>
Cc: xin@...or.com, kaleshsingh@...gle.com, kbingham@...nel.org,
akpm@...ux-foundation.org, nathan@...nel.org,
ryabinin.a.a@...il.com, dave.hansen@...ux.intel.com, bp@...en8.de,
morbo@...gle.com, jeremy.linton@....com, smostafa@...gle.com,
kees@...nel.org, baohua@...nel.org, vbabka@...e.cz,
justinstitt@...gle.com, wangkefeng.wang@...wei.com,
leitao@...ian.org, jan.kiszka@...mens.com,
fujita.tomonori@...il.com, hpa@...or.com, urezki@...il.com,
ubizjak@...il.com, ada.coupriediaz@....com,
nick.desaulniers+lkml@...il.com, ojeda@...nel.org,
brgerst@...il.com, elver@...gle.com, pankaj.gupta@....com,
glider@...gle.com, mark.rutland@....com, trintaeoitogc@...il.com,
jpoimboe@...nel.org, thuth@...hat.com, pasha.tatashin@...een.com,
dvyukov@...gle.com, jhubbard@...dia.com, catalin.marinas@....com,
yeoreum.yun@....com, mhocko@...e.com, lorenzo.stoakes@...cle.com,
samuel.holland@...ive.com, vincenzo.frascino@....com,
bigeasy@...utronix.de, surenb@...gle.com, ardb@...nel.org,
Liam.Howlett@...cle.com, nicolas.schier@...ux.dev, ziy@...dia.com,
kas@...nel.org, tglx@...utronix.de, mingo@...hat.com,
broonie@...nel.org, corbet@....net, andreyknvl@...il.com,
maciej.wieczor-retman@...el.com, david@...hat.com, maz@...nel.org,
rppt@...nel.org, will@...nel.org, luto@...nel.org,
kasan-dev@...glegroups.com, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, x86@...nel.org,
linux-kbuild@...r.kernel.org, linux-mm@...ck.org,
llvm@...ts.linux.dev, linux-doc@...r.kernel.org
Subject: Re: [PATCH v6 15/18] x86/kasan: Handle UD1 for inline KASAN reports
On Mon, Nov 17, 2025 at 09:47:20AM +0000, Maciej Wieczór-Retman wrote:
> >> +void kasan_inline_handler(struct pt_regs *regs)
> >> +{
> >> + int metadata = regs->cx;
> >> + u64 addr = regs->di;
> >> + u64 pc = regs->ip;
> >> + bool recover = metadata & KASAN_ECX_RECOVER;
> >> + bool write = metadata & KASAN_ECX_WRITE;
> >> + size_t size = KASAN_ECX_SIZE(metadata);
> >> +
> >> + if (user_mode(regs))
> >> + return;
> >> +
> >> + if (!kasan_report((void *)addr, size, write, pc))
> >> + return;
> >> +
> >> + kasan_die_unless_recover(recover, "Oops - KASAN", regs, metadata, die);
> >> +}
> >
> >I'm confused. Going by the ARM64 code, the meta-data is constant per
> >site -- it is encoded in the break immediate.
> >
> >And I suggested you do the same on x86 by using the single byte
> >displacement instruction encoding.
> >
> > ud1 0xFF(%ecx), %ecx
> >
> >Also, we don't have to use a fixed register for the address, you can do:
> >
> > ud1 0xFF(%ecx), %reg
> >
> >and have %reg tell us what register the address is in.
> >
> >Then you can recover the meta-data from the displacement immediate and
> >the address from whatever register is denoted.
> >
> >This avoids the 'callsite' from having to clobber cx and move the address
> >into di.
> >
> >What you have here will work, and I don't suppose we care about code
> >density with KASAN much, but it could've been so much better :/
>
> Thanks for checking the patch out, maybe I got too focused on just
> getting clang to work. You're right, I'll try using the displacement
> encoding.
>
> I was attempting a few different encodings because clang was fussy about
> putting data where I wanted it. The one in the patch worked fine and I
> thought it'd be consistent with the form that UBSan uses. But yeah, I'll
> work on it more.
>
> I'll also go and rebase my series onto your WARN() hackery one since
> there are a lot of changes to traps.c.
Thanks!
Powered by blists - more mailing lists