Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 02 Jul 2018 22:03:11 -0000 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fa6uc-0004z9-7b for speck@linutronix.de; Tue, 03 Jul 2018 00:03:11 +0200 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-428a6f71.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w62M2tFa123634 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL) for ; Mon, 2 Jul 2018 22:02:56 GMT From: Anthony Liguori Subject: [MODERATED] Re: KVM L1TF options In-Reply-To: <47ec967f-ae94-cb68-65ce-64d4aaf14609@suse.de> References: <47ec967f-ae94-cb68-65ce-64d4aaf14609@suse.de> Date: Mon, 2 Jul 2018 15:02:54 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain To: speck@linutronix.de List-ID: speck for Alexander Graf writes: > > Howdy, > > I've been wondering for a while what options we (realistically) have to > mitigate L1TF with SMT in the KVM case. So far I gathered: > > 1) Disable SMT > 1.1) on boot > 1.2) dynamically, magically > > I guess we all agree that while it's an easy option out, it's not > necessarily the best user experience for mixed environments, where both > host Linux applications and guests are running. This typically happens > in any "secure" container environment, hyper-converged cloud, etc etc. > > > 2) Gang scheduling for vcpus, disallow non-kvm processes to run with kvm > > This seems to be quite tricky to get right from what I gather. I > remember IBM had similar approaches for HV KVM on PowerPC initially, but > eventually went with SMT1 on the host and SMTx in the guest, with KVM > doing the ganging. There are at least a couple implementations of this already but my understanding is that mingo/tglx have pushed back on doing this. Regardless, we plan on posting an implementation once the embargo lifts. > 3) Shadow page tables > > We lose quite some performance, but would be 100% safe. The biggest > problem is that we degrade on single-core performance rather than > overall system performance. > > Also with KPTI, shadow page tables started to perform much worse. > > > -- > > > So I've been wondering whether there is any other option: We really > don't need the big shadow page table hammer. Instead, we can happily > allow the guest to use nested pages during runtime as long as the page > tables it is using are sanitized. > > 4) EPT with PT sanitization > > We could map additional guest read only RAM in an unused window of the > guest physical address space as a page table cache. Then trap CR3 > writes. On CR3 writes, check if we have a counter-page to the original > CR3 entry, point to our sanitized clone instead. Otherwise create one. > > Then we can slowly propagate that clone similar to shadow page tables, > but we would never have to do the GPA->HVA->GPA dance. Instead, all we > need to do is check whether a PTE has the P bit set or not. If it does, > copy it. If it doesn't, just set the whole clone PTE to 0. > > The most annoying part about this approach is that we would need to > implement A and D bits by hand, because a) the HW walker can not write > to the clone PTE because it's mapped read-only and b) we should > propagate the bits immediately into the real PTE anyway. > > Another idea J=C3=B6rg came up with was that we could try to optimize the= > > sanitization even more using PML (Page Modification Log). Using that we > know which pages the guest modified, so if we find a page in there that > we have in our sanitized cache, we can just redo that whole page in one g= > o. > > What I'm not quite sure of yet are page invalidations. Is there > something we can trap on for those? Otherwise we'd have to set all page > table pages to read-only in the EPT and that would end up very expensive.= > > > So what do people think about the idea? Does it sound doable? You need to write protect all levels of the page table so you really do need to do full blown shadow paging, no? I'm not able to get my head around what gets simplified with this approach. I think there is also another thing needed: 5) Secret hiding Data cannot end up in the L1 cache unless it's in the virtual address space. We can attempt to ensure that any guest secret is only present in it's virtual address space and never in another guest's address space. This requires not carrying a kernel virtual address mapping for any physical memory used by the guest but also some care in placing guest register state and potentially device model state into a userspace va instead of kernel memory as it is today. It also requires stack scrubbing and a few other things. The advantage is that it avoids the L1 cache clearing. Regards, Anthony Liguori > > > Alex