Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6090473ybv; Wed, 12 Feb 2020 05:55:23 -0800 (PST) X-Google-Smtp-Source: APXvYqxlyDmXQuJINum8XMXhfAS2iMsxKDZbHaEk84eVfdZv3EI+tEMSUZbaZjQ1AXqMKCOtCzuq X-Received: by 2002:a9d:d06:: with SMTP id 6mr9499492oti.176.1581515723405; Wed, 12 Feb 2020 05:55:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581515723; cv=none; d=google.com; s=arc-20160816; b=ABXAu+vI/jA1IfJaD4+tNHXASWlU79x6wGKMP5pHRm6up26iT/J/kAFijfLM6X77Sc Y4SxUCIJMCowKidbBYK21q/zyCmeG1Ds3HlN8e+nbn9zFmQhzecBmQomhtx9Xr7XhoG7 0SVIilfu2s+lzpKtD3uBbWQJ8Lz/z+rcMnhx+5Jjq8WKVUWD+WMxy4Y1IzrcF57Pbxbj eoxT5JycM6zPWrArIpf9drQo0OrCivzbn02xwFFaYFZINWT3P/iVOMWiq1zHtMv+4gEy EM7H9LtX906RVtmOAvfyqwOxqaQECL3D/AxoSpFHNSbORc4Dlg+k1s7+CpGORO5jRA9j Q2qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eqVMDvRKSn3Rlb1XjkgE2zyMd8x2Y5Sse7WjAB9Y2zk=; b=LwxkYEh4Rb9NfzPJq8F+rhCtUgC4kRZ6MhKMVhdALk03V6ojRZmzJ5mXd8iM+JQPDI dBIPmHmid8W9s3HQAAsSayzlBRtAWe/SAtawhi7YedkcYcVcwRg2uRdJJ/WXcj3WX7Fr qb6PJgEtq23pQ3ElBJGJGZpgfZrTJYarx4f545Pyd4lot5yVKuar6SnsmENPnLGv3cRX /y8p+iAd06uMtCF9KinOnRgaP+mLCoEjKG8MPQNFGJm+RQAlBdPjkp8iln5YuIT+7Rr5 8b+Ryma/FRYw+Z0AFePMcVin0KnHA56UFsrk+1NURGB7+3yrRSqOn8bIf9oQwRniVI5w uPbA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si229465otk.244.2020.02.12.05.55.10; Wed, 12 Feb 2020 05:55:23 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbgBLNyt (ORCPT + 99 others); Wed, 12 Feb 2020 08:54:49 -0500 Received: from 8bytes.org ([81.169.241.247]:53890 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgBLNyt (ORCPT ); Wed, 12 Feb 2020 08:54:49 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id E433020E; Wed, 12 Feb 2020 14:54:47 +0100 (CET) Date: Wed, 12 Feb 2020 14:54:36 +0100 From: Joerg Roedel To: Andy Lutomirski Cc: Peter Zijlstra , X86 ML , "H. Peter Anvin" , Dave Hansen , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , LKML , kvm list , Linux Virtualization , Joerg Roedel Subject: Re: [RFC PATCH 00/62] Linux as SEV-ES Guest Support Message-ID: <20200212135436.GJ20066@8bytes.org> References: <20200211135256.24617-1-joro@8bytes.org> <20200211145008.GT14914@hirez.programming.kicks-ass.net> <20200211154321.GB22063@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2020 at 02:12:04PM -0800, Andy Lutomirski wrote: > On Tue, Feb 11, 2020 at 7:43 AM Joerg Roedel wrote: > > > > On Tue, Feb 11, 2020 at 03:50:08PM +0100, Peter Zijlstra wrote: > > > > > Oh gawd; so instead of improving the whole NMI situation, AMD went and > > > made it worse still ?!? > > > > Well, depends on how you want to see it. Under SEV-ES an IRET will not > > re-open the NMI window, but the guest has to tell the hypervisor > > explicitly when it is ready to receive new NMIs via the NMI_COMPLETE > > message. NMIs stay blocked even when an exception happens in the > > handler, so this could also be seen as a (slight) improvement. > > > > I don't get it. VT-x has a VMCS bit "Interruptibility > state"."Blocking by NMI" that tracks the NMI masking state. Would it > have killed AMD to solve the problem they same way to retain > architectural behavior inside a SEV-ES VM? No, but it wouldn't solve the problem. Inside an NMI handler there could be #VC exceptions, which do an IRET on their own. Hardware NMI state tracking would re-enable NMIs when the #VC exception returns to the NMI handler, which is not what every OS is comfortable with. Yes, there are many ways to hack around this. The GHCB spec mentions the single-stepping-over-IRET idea, which I also prototyped in a previous version of this patch-set. I gave up on it when I discovered that NMIs that happen when executing in kernel-mode but on entry stack will cause the #VC handler to call into C code while on entry stack, because neither paranoid_entry nor error_entry handle the from-kernel-with-entry-strack case. This could of course also be fixed, but further complicates things already complicated enough by the PTI changes and nested-NMI support. My patch for using the NMI_COMPLETE message is certainly not perfect and needs changes, but having the message specified in the protocol gives the guest the best flexibility in deciding when it is ready to receive new NMIs, imho. Regards, Joerg