Return-Path: Received: from mail-pg0-x236.google.com ([2607:f8b0:400e:c05::236]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1fLtDh-0003An-Fz for speck@linutronix.de; Thu, 24 May 2018 18:36:05 +0200 Received: by mail-pg0-x236.google.com with SMTP id w3-v6so1023126pgv.12 for ; Thu, 24 May 2018 09:36:05 -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 k13-v6sm38581287pfj.186.2018.05.24.09.35.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 09:35:57 -0700 (PDT) Sender: Linus Torvalds Date: Thu, 24 May 2018 09:35:57 -0700 (PDT) From: Linus Torvalds Subject: [MODERATED] Re: L1D-Fault KVM mitigation In-Reply-To: <1527177599.8186.147.camel@infradead.org> Message-ID: References: <20180424090630.wlghmrpasn7v7wbn@suse.de> <20180424093537.GC4064@hirez.programming.kicks-ass.net> <1524563292.8691.38.camel@infradead.org> <20180424110445.GU4043@hirez.programming.kicks-ass.net> <1527068745.8186.89.camel@infradead.org> <20180524094526.GE12198@hirez.programming.kicks-ass.net> <1527177599.8186.147.camel@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: On Thu, 24 May 2018, speck for David Woodhouse wrote: > > In those cases, "pause the vCPU when the sibling pCPU vmexits to > anything other than idle" is the necessary and mostly sufficient > missing piece. Because we effectively already *have* gang scheduling to > the extent that it matters. I'll believe it when I see the patch and actual numbers on real loads. As far as I can tell, if you want to avoid the data leak, you need to - on vmenter, the sibling *must* be in idle, or in "waiting to vmenter the same VM". If the sibling is doing anything else, you don't know what the f*ck it's doing, so you need to do an IPI or a sleep to synchronize with it. And regardless, you're going to have to do (probably several) atomic locked accesses just to make sure this is race-free. And you have to clear your L1 caches before that "waiting to vmenter" _and_ before the "going to idle" state, becasue otherwise there's a big race the other way waiting to happen (which is trivial for the guest to hit, since the guest trivially controls vmenter/vmexit by choice of instructions). - on exit from idle, you need to IPI the other CPU if it's in VM mode, since you're now starting to touch L1 cache lines. I guess you can do a synchronous wait, depending on why you're exiting idle, but probably not without a big hit on latencies. You're basically primarily in an interrupt handler, for chrissake! - on vmexit, you know that the sibling CPU can't have been doing anything else (unless the exit was becuise the sibling IPI'd you to _get_ you out of vmx). But if it was in vmx mode, since you're now going to pollute the L1 caches, you need to either wait for it synchronously to exit its VM, or you need to IPI it to force it to exit. Presumably, you want to wait for it most of the time, but if you exited due to an interrupt or something, that may not be an option, so maybe the IPI is the common case, the same as exit from idle above? Am I missing something fundamental? Because those three are just the basic requirements that have nothing to do with *scheduling*. They are fundamental to the whole "I must not touch any interesting data while another sibling is in VM mode". Honestly, I don't care one whit what the actual VM entry/exit code does, since it doesn't hurt anything else, and the sane workaround remains to just disable HT. But I care deeply about the enter/exit from idle, especially if it now involves locked operations and L1 cache flushing, just in case. But note how none of the above has anything to do with the *scheduler*. The gang scheduling is just to make the above fuck-up perform much better. And the above all happens when we expect real things to be going on in the system, ie the host actually has timers and networking going on, and the actual _paying_ primary clients on something like Amazon cloud don't tend to be so much about CPU in the first place (those will be using the lowest cost bulk tiers), so they likely have a fair amount of real code going on too. So absolutely none of this is *rare*. Interrupts, vmenter, and vmexit happen all the time, and whoever came up with the gang scheduling scheme was presumably looking a lot at the best-case numbers. Now you want to add gang schedulign on *top* of the above disaster? Yeah, good luck. Maybe I've explained my skepticism sufficiently above. I don't have any scheduling frequency numbers and average times in VMX, and presumably you do, and maybe I'm being just unreasonably pessimistic. But it all really sounds like a complete pipe dream to me. My guess is that the cost of all of the above is going to be *much* bigger than the advantage of HT. Last I saw, HT on Intel processors was on the order of 30% win. Are you seriously claiming that the above costs are going to be so small that you make up for it? Because that's a hard limit. If it's more expensive than 30%, it makes no sense to do. That's different from all the other mitigation we've done. It has to be cheap, and it has to be cheap for the *bad* case - the case where you actually have lots of VMX activity. The only case I see making up for it is when vm entry/exit are so rare (because you don't actually do much virtualization at all) that you're willing to make them much much slower just to keep HT for the 95% of the time when you're not doing any virtualization at all. But that case doesn't say "cloud provider" to me. It says "desktop machine that occasionally runs virtualbox". And that case doesn't care about the security issue in the first place, since it's not running other peoples untrusted shit to begin with. So I really find it unlikely that anybody comes up with something worthwhile. Linus