Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp684638ybh; Sat, 7 Mar 2020 07:47:42 -0800 (PST) X-Google-Smtp-Source: ADFU+vsWxV0/GCp9H7ZfIqBa+kKklQtul/1qkH06dm2d+xIAlIyhWUjGSd+Gf/NxD1yu41c+3xJa X-Received: by 2002:a9d:3e89:: with SMTP id b9mr6896260otc.3.1583596061909; Sat, 07 Mar 2020 07:47:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583596061; cv=none; d=google.com; s=arc-20160816; b=xzCE29T7iHuElxlEiJhtbdnhA1tiRxYSKYUEmW+MShA/PyOWA+4tO01Vhr3Qw73Bir 0m80xKNGYXbRfJVyzg7plna1rmWhXGlCk5ngVWudcqHnzfYRDffmglMJ5tC7lY0LWJhm vkhaCM12aV+VzhgaM1p8r5YF0gRX9mFycMX3QznPJctAu51Anh9K2VL9TNpzI2x8lC4d l7TVtVJnD8UpiaI072FXlfMPYmR1rYGyRVGg6LpnFFfp6ZaEqgz3xA4ZuJ6U7oseXCvJ aZf1Nj4ueLTa6V1Ouacaj7FnU0m+2w3AAdx5yDg3mwCp2UVDTrP0O7dYFHNJ+Uajpz22 5msw== 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=G13eA3u/ZcsPvGXleEfu5rSnWA/e2CZfYCZG1+EBLqg=; b=Ozn9T4hoAEzOu6uDvcWcO0nLlLXa9xuCtpISR7gOM6KgVZvDvfFNXvtGUrS6cckfAM i7MuLmXijYmejMs54ti3HWIu2pexi2OhNLO3xQ39d5Mz8EiHHFRPLWXyIKifMiMz21sY gBYVUtdfW6dQ7fLBlEMd2itjDGQO5y7jQ0OTi+mfSZn7g86e6DTq074QBNkROB7bQQR1 dhNt2lyi1CGng6OR9Q3yK9Q6e7cb0qwkArPPd8xQ3ekE6Ln4GlTc8wMZXwWgwi4vauAX uNijAD0hSiVsZTV1OyVxHeD5pDeYoia1l0ennUa8wDC5WQxw8kueBachq8u5jjUQUkoZ D52w== 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 y25si1419369oih.73.2020.03.07.07.47.29; Sat, 07 Mar 2020 07:47:41 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726259AbgCGPrI (ORCPT + 99 others); Sat, 7 Mar 2020 10:47:08 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:55627 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726073AbgCGPrI (ORCPT ); Sat, 7 Mar 2020 10:47:08 -0500 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 1jAbfL-0006eZ-M6; Sat, 07 Mar 2020 16:47:04 +0100 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 7F7D0104088; Sat, 7 Mar 2020 16:47:01 +0100 (CET) From: Thomas Gleixner To: Andy Lutomirski , 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: References: Date: Sat, 07 Mar 2020 16:47:01 +0100 Message-ID: <87ftek9ngq.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 Andy Lutomirski writes: > On Fri, Mar 6, 2020 at 6:26 PM Andy Lutomirski wrote: >> + /* >> + * We do not set KVM_ASYNC_PF_SEND_ALWAYS. With the current >> + * KVM paravirt ABI, the following scenario is possible: >> + * >> + * #PF: async page fault (KVM_PV_REASON_PAGE_NOT_PRESENT) >> + * NMI before CR2 or KVM_PF_REASON_PAGE_NOT_PRESENT >> + * NMI accesses user memory, e.g. due to perf >> + * #PF: normal page fault >> + * #PF reads CR2 and apf_reason -- apf_reason should be 0 >> + * >> + * outer #PF reads CR2 and apf_reason -- apf_reason should be >> + * KVM_PV_REASON_PAGE_NOT_PRESENT >> + * >> + * There is no possible way that both reads of CR2 and >> + * apf_reason get the correct values. Fixing this would >> + * require paravirt ABI changes. >> + */ >> + > > Upon re-reading my own comment, I think the problem is real, but I > don't think my patch fixes it. The outer #PF could just as easily > have come from user mode. We may actually need the NMI code (and > perhaps MCE and maybe #DB too) to save, clear, and restore apf_reason. > If we do this, then maybe CPL0 async PFs are actually okay, but the > semantics are so poorly defined that I'm not very confident about > that. I think even with the current mode this is fixable on the host side when it keeps track of the state. 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. I tried to figure out whether any of this logic exists in the KVM code, but I got completely lost in that code. Maybe I try later today again. Thanks, tglx