Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp837709ybh; Sat, 7 Mar 2020 11:37:21 -0800 (PST) X-Google-Smtp-Source: ADFU+vu33q77smtZv0DtuWDLDI7iX3/5qvsFPtMhln+XWfSZkLD5on8OTOgsdjKe8UYWxV/C7UwQ X-Received: by 2002:aca:220a:: with SMTP id b10mr4398667oic.160.1583609841744; Sat, 07 Mar 2020 11:37:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583609841; cv=none; d=google.com; s=arc-20160816; b=I8Xe+104b6EdLJKTSUtx/L3hVS2T8mL9P+fWO0K3q957ffwO4MAblrfmsNaZVar2sm sBwZK1QufRV8O17nGF83RVrOB94ivy9sq9wn3IGh+fIOmUpum4yAdwQJFo/YldfXil51 Pf5ojrtcLNWGP7x5rhcFSzabFJTpkMgypAo/7v8N3BEl7owqNyjlS81sJAeVfprR/gDM 0mCUR27zad/u2SuWQ4gLZoRDJkfUVnxeMId/aVi/cMQfaDUWCnpwWpzZjLtfuFnotXRo doHv3xvBLTwFiwOEhopb4ppBCOcPg1ou0J5hnTijmWVW7TjrZC5oInDySoEPvUv7GoAs iC+Q== 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=i/7/6UJU4diHGXDBBkzYLRsDcKmawdt1AiIHgB4qvGw=; b=nB7Az6EGG7yyrqxxWiR57WIh+KINs+KQKqmZA1m8cLM70twVigWC3vTlQj5nun05V+ 51ijbQHNIkzLMvoxNr5j2RkFPHU/3428q0QfL0kRrQON44fsACw+gasxWL2obKvQJyNd 6vvbvp1zxUsSZtA+lkwGiDkn/YRlN6B2fooFNn03SiYiHUvJH6SwhvFqRXxJl8iyX05F M4x4A3sSENCaKqcMt5hLymgagkezuKuewjpIskOQT2YOSoD9mu8nM0OZNn+lyzuUaDcV 7g2QuSX+ufP+k4DHiW1P20d50UXkRieBmohjnbd9AFcWUYex1eYzhv66pPOXk9PEoGxp sr0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Lk/iUN9l"; 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 k16si1566589oiw.128.2020.03.07.11.36.57; Sat, 07 Mar 2020 11:37:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b="Lk/iUN9l"; 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 S1726327AbgCGTfL (ORCPT + 99 others); Sat, 7 Mar 2020 14:35:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:58644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726246AbgCGTfL (ORCPT ); Sat, 7 Mar 2020 14:35:11 -0500 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 F03722075B for ; Sat, 7 Mar 2020 19:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583609710; bh=JDv7bMpMvn1QXvUKWn3wky5CJY+BxT3OIOtmyrSEU1A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Lk/iUN9lj+kHJKWKb7GJZsjdZ6gVAKJWr5tXpmu734LhckBUJn2JQEwjDyRn04lT0 Rg1tw+7kaGYu+cs0IIU2bMJKqM6YQI8MGGruitvSdOSIcp0xxUAcbc5ATppuScCZbN bIIOyh5Ld+wDxxxD5/qfJd6MZhvbeplFfxGZtiSA= Received: by mail-wr1-f44.google.com with SMTP id t11so6258014wrw.5 for ; Sat, 07 Mar 2020 11:35:09 -0800 (PST) X-Gm-Message-State: ANhLgQ12BFco5OAjFGfLPowkseBYh8pERM0U/Qh7zIuXuC48LYvmgwBc g4K5N+Pj9OeFKVws6tlerprIwo6NKhTyjRkJVtie3w== X-Received: by 2002:adf:b641:: with SMTP id i1mr10938601wre.18.1583609708391; Sat, 07 Mar 2020 11:35:08 -0800 (PST) MIME-Version: 1.0 References: <87ftek9ngq.fsf@nanos.tec.linutronix.de> <87a74s9ehb.fsf@nanos.tec.linutronix.de> In-Reply-To: <87a74s9ehb.fsf@nanos.tec.linutronix.de> From: Andy Lutomirski Date: Sat, 7 Mar 2020 11:34:57 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] x86/kvm: Disable KVM_ASYNC_PF_SEND_ALWAYS To: Thomas Gleixner Cc: Andy Lutomirski , LKML , X86 ML , kvm list , Paolo Bonzini , stable 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 Sat, Mar 7, 2020 at 11:01 AM Thomas Gleixner wrote: > > 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. /me needs actual details Suppose the host delivers an async #PF. apf_reason != 0 and CR2 contains something meaningful. Host resumes the guest. The guest does whatever (gets NMI, and does perf stuff, for example). The guest gets a normal #PF. Somehow the host needs to do: if (apf_reason != 0) { prev_apf_reason = apf_reason; prev_cr2 = cr2; apf_reason = 0; cr2 = actual fault address; } resume guest; Obviously this can only happen if the host intercepts #PF. Let's pretend for now that this is even possible on SEV-ES (it may well be, but I would also believe that it's not. SEV-ES intercepts are weird and I don't have the whole manual in my head. I'm not sure the host has any way to read CR2 for a SEV-ES guest.) So now the guest runs some more and finishes handling the inner #PF. Some time between doing that and running the outer #PF code that reads apf_reason, the host needs to do: apf_reason = prev_apf_reason; cr2 = prev_cr2; prev_apf_reason = 0; How is the host supposed to know when to do that? --Andy