From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E15E0C10F00 for ; Sat, 7 Mar 2020 15:59:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0EF42075A for ; Sat, 7 Mar 2020 15:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583596778; bh=zMkJH6cK603hkiloMil4J7KbZG+wEMJbLxkolozJ8y4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=ZiJgearBP/183rXPWPoel30bxocYveqY30CkNyU8vEcu41ZdHROMo8Tb3/ZTtYk4w Dfj9BJxGeGSAckVFvMbWZdGqf80X3UDXUJRX8txJUdm4ihC9x7/wk07waIdiAZdvdj WctqgShKenJ8z38Keg6ZjXLTj9LksJBU3IhhvSYg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726199AbgCGP7h (ORCPT ); Sat, 7 Mar 2020 10:59:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:36850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgCGP7h (ORCPT ); Sat, 7 Mar 2020 10:59:37 -0500 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 85AC02077B 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-f49.google.com with SMTP id g134so5601185wme.3 for ; Sat, 07 Mar 2020 07:59:36 -0800 (PST) X-Gm-Message-State: ANhLgQ1Hh6A3Mzo73XTaphzy9RxLDcLGllx4d0vdFDbU/mi8guwO8zlL /1s7BB7qRmahk3TJz7yD92eTHRDGMNh6Gt99loaFNw== X-Google-Smtp-Source: ADFU+vvxDbLv30/SJ1GdrACcZi2erMHbijB2e7fHbV/Q2v+aZ/w3oszY1ocnI9nhuP4cv/N2cbSsd3T6zolnXE6tflg= 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: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@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.