Return-Path: Received: from mail-pg0-x231.google.com ([2607:f8b0:400e:c05::231]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1fQahj-0001pz-FF for speck@linutronix.de; Wed, 06 Jun 2018 17:50:31 +0200 Received: by mail-pg0-x231.google.com with SMTP id e11-v6so3222249pgq.0 for ; Wed, 06 Jun 2018 08:50:31 -0700 (PDT) Received: from i7.lan (c-73-11-52-149.hsd1.or.comcast.net. [73.11.52.149]) by smtp.gmail.com with ESMTPSA id y7-v6sm90025528pfy.52.2018.06.06.08.50.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jun 2018 08:50:23 -0700 (PDT) Sender: Linus Torvalds Date: Wed, 6 Jun 2018 08:50:20 -0700 (PDT) From: Linus Torvalds Subject: [MODERATED] Re: ARCH_CAPABILITIES note In-Reply-To: <5f898d80-b66a-7933-d348-c733a2b888e8@linux.intel.com> Message-ID: References: <0eca849b-fd6b-e42f-6c83-3c930d644bba@redhat.com> <3b6d8d03-945e-4efc-7baa-a7ecedfd2366@linux.intel.com> <51a5e275-67c2-5638-21e9-a3992ba1de0b@redhat.com> <5f898d80-b66a-7933-d348-c733a2b888e8@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Wed, 6 Jun 2018, speck for Dave Hansen wrote: > > Just trying to be precise: Are you saying that LFENCE is an > architecturally "serializing instruction", or that it shares some > properties will fully "serializing instructions"? Heh. Bring it up with the Intel documentation people. Intel should really stop using "serializing instruction" entirely, because the rules are so bad, and so odd, and so pointless. A _true_ serializing instruction will serialize even instruction fetch and make sure any I$ access is coherent with D$ etc. And no, lfence does not do that. But lfence - despite the name and the history of being a memory ordering device - does what you care about if you care about instruction execution ordering: it will block execution until all preceding instructions have retired. Intel really does a horrible job of documenting these kinds of serializations. They fixed their memory ordering documentation, but any ordering that is not about _normal_ cached memory ordering is imnsho very very lacking. They have some language about non-cached ordering (ie PCIe and uncached RAM with WC/WT/whatever), but it's not at all as clear or well architected as their memory ordering. And when it comes to "serializing" instructions that actually impact instruction flow, it's a complete toss-up. "lfence" isn't serializing, but it serializes execution. But Intel at no point really talks about what "serializing" means, although they in a few places talk about when you need to use a serializing instruction (but even then there are almost always exceptions). So you need a "real" serializing instruction if you want to synchronize with the TLB walker, or synchronize with another CPU modifying your instructions under you - aka cross-modifying code - or even the _same_ CPU doing self-modifying code through another virtual address. And iirc there's some verbiage how you need a "real" serializing instruction if you change execution modes that affect decoding (ie real mode to protected mode), except most of the time you don't, and just a "jump" is sufficient for legacy reasons. And again, lfence is *not* a serializing instruction, but lfence *does* stop execution until all preceding instructions have completed. Note how that is only about the front-end, and also note that this is not really what lfence was actually originally specified for. Also, afaik, lfence doesn't necessarily wait for the store buffer to drain, but since it waits for all preceding stores to be stable, it at least guarantees that stores _are_ in the store buffer, and there are no speculative store buffer entries, so it avoids the store buffer bypass (and the SB poisoning that I haven't actually seen verified if Intel has problems with or not). And no - none of the above is really spelled out very well anywhere that I can find. You need to just search for "serializing" in the SDK and see where Intel says you need a serializing instruction. Linus