Re: [PATCH v10 6/6] x86/split_lock: Enable split lock detection by kernel parameter

From: Andy Lutomirski
Date: Thu Dec 12 2019 - 11:02:17 EST



> On Dec 12, 2019, at 5:04 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> Waiting for a store-buffer drain is *expensive*.
>
> Try timing:
>
> LOCK INC (ptr);
>
> vs
>
> LOCK INC (ptr);
> MFENCE
>
> My guess is the second one *far* more expensive. MFENCE drains (and waits
> for completion thereof) the store-buffer -- it must since it fences
> against non-coherent stuff.

MFENCE also implies LFENCE, and LFENCE is fairly slow despite having no architectural semantics other than blocking speculative execution. AFAICT, in the absence of side channels timing oddities, there is no code whatsoever that would be correct with LFENCE but incorrect without it. âSerializationâ is, to some extent, a weaker example of this â MOV to CR2 is *much* slower than MFENCE or LOCK despite the fact that, as far as the memory model is concerned, it doesnât do a whole lot more.

So the fact that draining some buffer or stalling some superscalar thingy is expensive doesnât necessarily mean that the lack of said draining is observable in the memory model.

(LFENCE before RDTSC counts as âtimingâ here.)