Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2166897ybh; Sun, 8 Mar 2020 23:58:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvVyjfU7igREbNDUEqs9TJHInK4OeIXq15Em10Xc2kqSNHfa8D26L3HT1FMFvbySfp9KxrL X-Received: by 2002:a9d:27c7:: with SMTP id c65mr7267619otb.318.1583737100378; Sun, 08 Mar 2020 23:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583737100; cv=none; d=google.com; s=arc-20160816; b=i+OGRLktyJXlK4ZBWLRjJV3FdNTw4xso3zycC9sRKU7dET2Qu4u0Qc5nzOsod3bLbu lbNz64KB1PALEb4GwtTQvYDqVnGOSP3ucVX5bUXvxo0Y2w+Nj/hfV0IEBhe6Hea4DtWA T/92HJXWi7s6FuCLRT1v6fQDY2hl2HgkWUTSKOxUMGJnuiNzkoCd+tHFbdlMKi+6GBdt NGQ8TwbPbeJEOT+wMIXaBB2ElEmz2iDCY7Y2qKbZ1Mw0PFt9FnEdjtrX0N1caPSkd8jK Xgjjcgq4qL5F/r1X6X8VCPv4COmvNT5MqdcgrcT0s3PLGzvDohD+echURTr//nOROCYO MxgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=zrzpCzeqHqZ5+E8AxCeEC0hyYI5XIJV6PrSFnVmvgJI=; b=OdhuKr1Co1YTPtJtFIBMQV1zLNToxtoJ8iCZOMkdRfoOOt5HLrK8klzM+pIhSE5x3z KodfIvk/x/mnun0xhN1OxV2KFIARhQpDjmjweXcStC9zPiIcGGJ9AqBDjZzxjbenAKd+ nTEKdD3ebJE6tKR3Iw/9SpEufUNsWDd1kYE/78enMPV8dXEzD+pVKnTs4+ex4OyFDvw0 Ju5MozuZsxnRbolTqcYa3zqMicM94YcRyQqeeE+lTSmY+lpxjRdXfqDiT97sNhp28r9z CdGudWGVSZ/3d2QB1zNBPwKwvtkJTSOY3DU3sY1oYhzfqwgXcsOcrQKzumyjBYV1idxK AxIQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q142si2918724oic.174.2020.03.08.23.58.08; Sun, 08 Mar 2020 23:58:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726391AbgCIG5x (ORCPT + 99 others); Mon, 9 Mar 2020 02:57:53 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:57846 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725796AbgCIG5w (ORCPT ); Mon, 9 Mar 2020 02:57:52 -0400 Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jBCMG-00010u-G5; Mon, 09 Mar 2020 07:57:48 +0100 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id BEB1F10408A; Mon, 9 Mar 2020 07:57:47 +0100 (CET) From: Thomas Gleixner To: Andy Lutomirski Cc: LKML , X86 ML , kvm list , Paolo Bonzini , stable Subject: Re: [PATCH v2] x86/kvm: Disable KVM_ASYNC_PF_SEND_ALWAYS In-Reply-To: <87wo7v8g4j.fsf@nanos.tec.linutronix.de> References: <87ftek9ngq.fsf@nanos.tec.linutronix.de> <87a74s9ehb.fsf@nanos.tec.linutronix.de> <87wo7v8g4j.fsf@nanos.tec.linutronix.de> Date: Mon, 09 Mar 2020 07:57:47 +0100 Message-ID: <877dzu8178.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thomas Gleixner writes: > Thomas Gleixner writes: >> Andy Lutomirski writes: >>> On Sat, Mar 7, 2020 at 7:47 AM Thomas Gleixner wrote: >>>> The host knows exactly when it injects a async PF and it can store CR2 >>>> and reason of that async PF in flight. >>>> >>>> On the next VMEXIT it checks whether apf_reason is 0. If apf_reason is 0 >>>> then it knows that the guest has read CR2 and apf_reason. All good >>>> nothing to worry about. >>>> >>>> If not it needs to be careful. >>>> >>>> As long as the apf_reason of the last async #PF is not cleared by the >>>> guest no new async #PF can be injected. That's already correct because >>>> in that case IF==0 which prevents a nested async #PF. >>>> >>>> If MCE, NMI trigger a real pagefault then the #PF injection needs to >>>> clear apf_reason and set the correct CR2. When that #PF returns then the >>>> old CR2 and apf_reason need to be restored. >>> >>> How is the host supposed to know when the #PF returns? Intercepting >>> IRET sounds like a bad idea and, in any case, is not actually a >>> reliable indication that #PF returned. >> >> The host does not care about the IRET. It solely has to check whether >> apf_reason is 0 or not. That way it knows that the guest has read CR2 >> and apf_reason. > > Bah. I'm a moron. Of course it needs to trap the IRET of the #PF in > order to restore CR2 and apf_reason. Alternatively it could trap the CR2 > read of #PF, but yes that's all nasty. Some hours or sleep and not staring at this meess later and while reading the leaves of my morning tea: guest side: nmi()/mce() ... stash_crs(); + stash_and_clear_apf_reason(); .... + restore_apf_reason(); restore_cr2(); Too obvious, isn't it? Thanks, tglx