On Thu, 14 Dec 2023 at 08:55, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote: > > And yes, this does get called in NMI context. Not on an i486-class machine they won't. You don't have a local apic on those, and they won't have any NMI sources under our control (ie NMI does exist, but we're talking purely legacy NMI for "motherboard problems" like RAM parity errors etc) > I had a patch that added: > > + /* ring buffer does cmpxchg, make sure it is safe in NMI context */ > + if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && > + (unlikely(in_nmi()))) { > + return NULL; > + } CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG doesn't work on x86 in this context, because the issue is that yes, there's a safe 'cmpxchg', but that's not what you want. You want the save cmpxchg64, which is an entirely different beast. And honestly, I don't think that NMI_SAFE_CMPXCHG covers the double-word case anywhere else either, except purely by luck. In mm/slab.c, we also use a double-wide cmpxchg, and there the rule has literally been that it's conditional on (a) system_has_cmpxchg64() existing as a macro (b) using that macro to then gate - at runtime - whether it actually works or not I think - but didn't check - that we essentially only enable the two-word case on x86 as a result, and fall back to the slow case on all other architectures - and on the i486 case. That said, other architectures *do* have a working double-word cmpxchg, but I wouldn't guarantee it. For example, 32-bit arm does have one using ldrexd/strexd, but that only exists on arm v6+. And guess what? You'll silently get a "disable interrupts, do it as a non-atomic load-store" on arm too for that case. And again, pre-v6 arm is about as relevant as i486 is, but my point is, that double-word cmpxchg you rely on simply DOES NOT EXIST on 32-bit platforms except under special circumstances. So this isn't a "x86 is the odd man out". This is literally generic. > Now back to my original question. Are you OK with me sending this to you > now, or should I send you just the subtle fixes to the 32-bit rb_time_* > code and keep this patch for the merge window? I'm absolutely not taking some untested random "let's do 64-bit cmpxchg that we know is broken on 32-bit using broken conditionals" shit. What *would* work is that slab approach, which is essentially #ifndef system_has_cmpxchg64 #define system_has_cmpxchg64() false #endif ... if (!system_has_cmpxchg64()) return error or slow case do_64bit_cmpxchg_case(); (although the slub case is much more indirect, and uses a __CMPXCHG_DOUBLE flag that only gets set when that define exists etc). But that would literally cut off support for all non-x86 32-bit architectures. So no. You need to forget about the whole "do a 64-bit cmpxchg on 32-bit architectures" as being some kind of solution in the short term. Linus