Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp691879ybh; Sat, 7 Mar 2020 08:00:12 -0800 (PST) X-Google-Smtp-Source: ADFU+vtj4X18bVM9tRgQSxmsI0FDyYoBrOiW3ltRwKvupQzWgKsAqmIFnypFZMVRHkvGSeBE9GLL X-Received: by 2002:a05:6830:1089:: with SMTP id y9mr7026658oto.293.1583596811934; Sat, 07 Mar 2020 08:00:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583596811; cv=none; d=google.com; s=arc-20160816; b=j05u13+E0k+JZCsAOj9F4dNDyprb29NyVUKhBKt1RhlF6x6/SUQhfXsZwdajORkewq DGJJ3fRwfK20cwg/p2/Dxj6R3HAO9F3EHZDDqMdDESQwbEJjGDVVJrEQlPLqSud6px/0 twHGYyHDxLNwDWaPCu6ARdlKTFxfVjDo+S/4/FcFMJBuPO5ShfbeLv0HpXO1mqykQ/3U nrRiqHKFJPd0FV9owCDh0dktTyrBg3PCrdHXhmJtKVgHAVLtWnHW835PhrDer1pvN9SJ yme0q+QAAmOzfSXfDl3Ow2Hg8+Lrfqa02nx3YzJZjZOtgzinoAXUweM0TcmiFVmdjM+m umXA== 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=srikzbk7ZLQp8UxyJ5GyaVuPCZgPK6ivdrC5Q79xL7U=; b=0c6kbT2oDjBBheIbo7jGoG6xgCD6Y4nZFwaofSEO1xEgQGNLuYLufXpWT3bLCmMJ3S z52onM0ODekZUxyvdY8nwPvvJ5x89c67qr3OzPCf9OHSNDdjnt+BCIVd0JAfKvgTuw7E v3+LzBpPBuZ7F4pW6/pgZA/IiZ/3JBY3xAxeswr0dofPiM88WET4r14pl8ZVnCxwyCT6 ZBQpXuCxlfJLksUWilkcMubp0RR/wxKD9VLZFENGOZ/z4xWEkSbmifk20U73xvOmTWN5 wlSubboxMaG9ov8286o8DF8RtCK/noWCup/B+rE3vfYPQLy5g+18Mfr+TG/FfAwFWl6C /O2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wl6DWydh; 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 c80si1342928oib.276.2020.03.07.08.00.00; Sat, 07 Mar 2020 08:00:11 -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=wl6DWydh; 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 S1726246AbgCGP7i (ORCPT + 99 others); Sat, 7 Mar 2020 10:59:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:36842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgCGP7i (ORCPT ); Sat, 7 Mar 2020 10:59:38 -0500 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 7A26520674 for ; Sat, 7 Mar 2020 15:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583596776; bh=zMkJH6cK603hkiloMil4J7KbZG+wEMJbLxkolozJ8y4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=wl6DWydhYNyJg+uXDV7caWUBz1t5DhX+qqoTIdiOgeLjAPAFFlLTyvGdS2MGNhdsD BbZNFXXAt8+rfk8lQgEp59HhLFhhQ54p1j1ZLE2N/Pz133vyTUsNnc1URmioveU0nF ob12zJh5RHBqImzhx6w4EdEknItkP2Is8eUfe71I= Received: by mail-wm1-f41.google.com with SMTP id n8so1579439wmc.4 for ; Sat, 07 Mar 2020 07:59:36 -0800 (PST) X-Gm-Message-State: ANhLgQ3yJbjpyJJn0X6oru9endy/IDq8i+YZN45nXvLsVE1rSO3LuSgz /3ByizXwGh6e2vNhxFPce0cJ99HYOaWTzO8BqL1p5Q== X-Received: by 2002:a7b:cd83:: with SMTP id y3mr10159179wmj.176.1583596774941; Sat, 07 Mar 2020 07:59:34 -0800 (PST) MIME-Version: 1.0 References: <87ftek9ngq.fsf@nanos.tec.linutronix.de> In-Reply-To: <87ftek9ngq.fsf@nanos.tec.linutronix.de> From: Andy Lutomirski Date: Sat, 7 Mar 2020 07:59:22 -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 7:47 AM Thomas Gleixner wrote: > > 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. 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.