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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 BD25EC10F27 for ; Mon, 9 Mar 2020 06:57:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83CD420675 for ; Mon, 9 Mar 2020 06:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgCIG5x (ORCPT ); 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