Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6780791yba; Tue, 14 May 2019 13:35:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtoWwPtU3wPlzbbfPcxTXozVY8Ut18ShkXYxKMYga7Ms5j/CdjCsz2Eh6xG2vPfICSnKaL X-Received: by 2002:a17:902:446:: with SMTP id 64mr38941273ple.322.1557866116378; Tue, 14 May 2019 13:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557866116; cv=none; d=google.com; s=arc-20160816; b=hrwoqv4a6ZyiwVAel5YAhPTKopg+CNicBsAIJur8Ba+Q2G4dYxL1+araQSrwxMTb1h YtIwOut6tXKGkaJK7hAJNJ+jp2jNh7UYzz5bhWdMH0XS4iBu/AxWai82xwNiZ7qqSSYR PDBJ7+OJ+fT7XtxwdDjbwGoToBLfLYHlVJitxz2TnT7x5l8aVE9b5rxUwvAJgUg7B75l y8mEU7SIDFR0My2NcD3WB0Zi9geLuUVj7X6UuqL3T6mS+55jmUgIoEMcdVm6vW2NG5fT 5lVK3+KWOEc6n8pC8Y/IC+yj/BRepb6cGgmAALemDbfZuKBkUzH0eNmeuHER0Cn8FF4p Aryg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yav7d1wlPb+DvwhGNViqHCLh8/mNKXZ8fYeFkNMpf4w=; b=wgIIknuvGS2GVmQ/T0/MNG/2pFWKslI/sLNDJ5ps3L52fxJJeGAmiRu9qATv/7mCPQ NU1avUl9MPAgjjOt37QcmeHyhe4/uPwcHGVTG5AlIrOxNDo9NiS3R+MYjxeVsy2+ViRE eFebwvyLlkzSKMzfFSJwS639LGFpDWf4ZcDhdqf6UuGEqkFgk7SjWM4XwSjxx3oy7X1M /XGF2Lfmmql4i5URL4E9oFhyBBqEbyg5AhgQVOEVspg2R1vUVFliTK4ZC3g43LroBrTH gCb+t1tSVe8aidhLVKrEmGNIZW/ZlbFarmA20WlsRDVgpmv3XmzeY+Oe55N/+M5IkTei iQ3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="U/yY8Nvh"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z186si20114670pgd.126.2019.05.14.13.35.00; Tue, 14 May 2019 13:35:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="U/yY8Nvh"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbfENUdg (ORCPT + 99 others); Tue, 14 May 2019 16:33:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:37442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbfENUdf (ORCPT ); Tue, 14 May 2019 16:33:35 -0400 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 35081216FD for ; Tue, 14 May 2019 20:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557866014; bh=/S2BDC6o9SOizwLDYiMYffbUvwSokVCxv3BmfflaHzY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=U/yY8Nvhi8iji1+459+sjubgg/1JF0X07D7wRnqqKjlo6h1Ahjbdv/0J0MnwVVdl5 PvBDOd4AkYiGhiqxEc6ukoCYeoOoDLIXKbu/M85AdHMxpL9STA5P0oBhzNoLQvnalz Wel3PIj0edEHiSp4UKTwYSZR0xDnIvhhppn9Cwe8= Received: by mail-wm1-f43.google.com with SMTP id j187so3180766wma.1 for ; Tue, 14 May 2019 13:33:34 -0700 (PDT) X-Gm-Message-State: APjAAAVdUOTiDLHI94/U/JuxoIPiWw1sGjIEdP0OBhxgifPY0+X13Wea 0kyTkhTKof7ohMq9nyntDVKE0srxUvDylQgbUYq+pg== X-Received: by 2002:a1c:a745:: with SMTP id q66mr11466245wme.83.1557866012756; Tue, 14 May 2019 13:33:32 -0700 (PDT) MIME-Version: 1.0 References: <1557758315-12667-1-git-send-email-alexandre.chartre@oracle.com> <1557758315-12667-19-git-send-email-alexandre.chartre@oracle.com> <20190514070941.GE2589@hirez.programming.kicks-ass.net> <4e7d52d7-d4d2-3008-b967-c40676ed15d2@oracle.com> <20190514170522.GW2623@hirez.programming.kicks-ass.net> <20190514180936.GA1977@linux.intel.com> In-Reply-To: <20190514180936.GA1977@linux.intel.com> From: Andy Lutomirski Date: Tue, 14 May 2019 13:33:21 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC KVM 18/27] kvm/isolation: function to copy page table entries for percpu buffer To: Sean Christopherson Cc: Peter Zijlstra , Alexandre Chartre , Andy Lutomirski , Paolo Bonzini , Radim Krcmar , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Dave Hansen , kvm list , X86 ML , Linux-MM , LKML , Konrad Rzeszutek Wilk , jan.setjeeilers@oracle.com, Liran Alon , Jonathan Adams Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 14, 2019 at 11:09 AM Sean Christopherson wrote: > > On Tue, May 14, 2019 at 07:05:22PM +0200, Peter Zijlstra wrote: > > On Tue, May 14, 2019 at 06:24:48PM +0200, Alexandre Chartre wrote: > > > On 5/14/19 5:23 PM, Andy Lutomirski wrote: > > > > > > How important is the ability to enable IRQs while running with the KVM > > > > page tables? > > > > > > > > > > I can't say, I would need to check but we probably need IRQs at least for > > > some timers. Sounds like you would really prefer IRQs to be disabled. > > > > > > > I think what amluto is getting at, is: > > > > again: > > local_irq_disable(); > > switch_to_kvm_mm(); > > /* do very little -- (A) */ > > VMEnter() > > > > /* runs as guest */ > > > > /* IRQ happens */ > > WMExit() > > /* inspect exit raisin */ > > if (/* IRQ pending */) { > > switch_from_kvm_mm(); > > local_irq_restore(); > > goto again; > > } > > > > > > but I don't know anything about VMX/SVM at all, so the above might not > > be feasible, specifically I read something about how VMX allows NMIs > > where SVM did not somewhere around (A) -- or something like that, > > earlier in this thread. > > For IRQs it's somewhat feasible, but not for NMIs since NMIs are unblocked > on VMX immediately after VM-Exit, i.e. there's no way to prevent an NMI > from occuring while KVM's page tables are loaded. > > Back to Andy's question about enabling IRQs, the answer is "it depends". > Exits due to INTR, NMI and #MC are considered high priority and are > serviced before re-enabling IRQs and preemption[1]. All other exits are > handled after IRQs and preemption are re-enabled. > > A decent number of exit handlers are quite short, e.g. CPUID, most RDMSR > and WRMSR, any event-related exit, etc... But many exit handlers require > significantly longer flows, e.g. EPT violations (page faults) and anything > that requires extensive emulation, e.g. nested VMX. In short, leaving > IRQs disabled across all exits is not practical. > > Before going down the path of figuring out how to handle the corner cases > regarding kvm_mm, I think it makes sense to pinpoint exactly what exits > are a) in the hot path for the use case (configuration) and b) can be > handled fast enough that they can run with IRQs disabled. Generating that > list might allow us to tightly bound the contents of kvm_mm and sidestep > many of the corner cases, i.e. select VM-Exits are handle with IRQs > disabled using KVM's mm, while "slow" VM-Exits go through the full context > switch. I suspect that the context switch is a bit of a red herring. A PCID-don't-flush CR3 write is IIRC under 300 cycles. Sure, it's slow, but it's probably minor compared to the full cost of the vm exit. The pain point is kicking the sibling thread. When I worked on the PTI stuff, I went to great lengths to never have a copy of the vmalloc page tables. The top-level entry is either there or it isn't, so everything is always in sync. I'm sure it's *possible* to populate just part of it for this KVM isolation, but it's going to be ugly. It would be really nice if we could avoid it. Unfortunately, this interacts unpleasantly with having the kernel stack in there. We can freely use a different stack (the IRQ stack, for example) as long as we don't schedule, but that means we can't run preemptable code. Another issue is tracing, kprobes, etc -- I don't think anyone will like it if a kprobe in KVM either dramatically changes performance by triggering isolation exits or by crashing. So you may need to restrict the isolated code to a file that is compiled with tracing off and has everything marked NOKPROBE. Yuck. I hate to say this, but at what point do we declare that "if you have SMT on, you get to keep both pieces, simultaneously!"?