Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp651322ybh; Sat, 7 Mar 2020 07:04:16 -0800 (PST) X-Google-Smtp-Source: ADFU+vs8B7/JKhsKifTuUZF7ISsTDTxHAFzXIyfpX9ICaGD9yCRXLucKhavWoU/gdVNRBw3e6LEs X-Received: by 2002:a05:6830:1d5:: with SMTP id r21mr6903809ota.54.1583593456668; Sat, 07 Mar 2020 07:04:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583593456; cv=none; d=google.com; s=arc-20160816; b=MDvxnikHP+OGXp7nEWbUOcYN5ZRgQKCX2pACYTnS+d4sZYQWzfdVz2oOQ1HDsrlY+O 33UeB9qifVXIIYcD0yGf70DoBU19bzp2f6sYTr8nK1Sdgi6l5HDcbb7yb20rkmVqoE4Q uscxAiLuXYv1WN90tJDyYbG/1jgFfkzV7Hj9/zC4dOofpxY2Q2mJxYdQ/gfNY6ZudFH6 XJnuHQSr4ViPrlUDlnmDO4UdGPW2lobJwWVGfrQXawd7Mnux3c6bO0i3npjJ3eWiZLZX UKNwW38taQMM71XGkoQ2WbnRu9hWodssAsCt/z/bDYa3Vli81yTNwKwEp9r32pWdniCX fDHg== 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=tZxjTSkdKy1kOuUUGDsTPaJLD5/Jk7qLnhGsUgGPfXs=; b=XL4+bAEE7fSbA3WvLplnuKgEahgcM95a45I+C4OMlBr8H9MWViwBPJ1/sv098vgu+r HLXy7B/juQeJGh0B1ECdBUfOYNS0LqNdgzH17XEq4yO4HeT6IgFdqN5GCR0cap9UlivG YLEloNys3ibq38mo1Cc+l0sYI4cVnnn0YQnF0Hr7EHf9gxmMDq6wkRaV7dglEQCNhNDw jLP8QoQQz+FTZrnv4GPoWHhujb6VxZACAAGVoodOhCJVMXoKRhN6L49AEfuSxGpjUAI6 eouugcNHxqRbdwN1hvo6StYMBgkfZXF2QLZhvMBU8CEFC53tt0WBiHc8/0DbonrXyLG8 3xHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U7olKMgO; 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 t130si1458948oib.202.2020.03.07.07.04.04; Sat, 07 Mar 2020 07:04:16 -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=U7olKMgO; 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 S1726105AbgCGPDi (ORCPT + 99 others); Sat, 7 Mar 2020 10:03:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:46118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726086AbgCGPDi (ORCPT ); Sat, 7 Mar 2020 10:03:38 -0500 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 597CB206D5 for ; Sat, 7 Mar 2020 15:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583593417; bh=gb+O6z+9Bp+875fdIg1OajoBwMGiyVEXOzXUFw4o4j4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=U7olKMgOCMIcDQr5xxy2ln7zt7vri1p5Wm43iRVBTnuDReATLV/mEwYGQyMlRhdtB iW+fy0kGwfBantX7l57vHro/6qk+bBhNbhU+qK23EC31X2iYDlWI/HKpkvDMIBUyVc HcJL52xfTHOWFk1keNbp4cG8BOdbsGYKB+Fm7n+0= Received: by mail-wr1-f47.google.com with SMTP id r7so5773118wro.2 for ; Sat, 07 Mar 2020 07:03:37 -0800 (PST) X-Gm-Message-State: ANhLgQ2NM5xF8+vkCeXT7QGF+hv2OT7Ihm23yCOyVtqplCdqdokHZ/oy KtrZe4wYFct25YYOnpTG/R9azvuLM9XCSXrRQw7stg== X-Received: by 2002:adf:b641:: with SMTP id i1mr10119012wre.18.1583593415752; Sat, 07 Mar 2020 07:03:35 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andy Lutomirski Date: Sat, 7 Mar 2020 07:03:24 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] x86/kvm: Disable KVM_ASYNC_PF_SEND_ALWAYS To: Andy Lutomirski Cc: 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 Fri, Mar 6, 2020 at 6:26 PM Andy Lutomirski wrote: > > The ABI is broken and we cannot support it properly. Turn it off. > > If this causes a meaningful performance regression for someone, KVM > can introduce an improved ABI that is supportable. > > Cc: stable@vger.kernel.org > Signed-off-by: Andy Lutomirski > --- > arch/x86/kernel/kvm.c | 21 ++++++++++++++++++--- > 1 file changed, 18 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index 93ab0cbd304e..e6f2aefa298b 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -318,11 +318,26 @@ static void kvm_guest_cpu_init(void) > > pa = slow_virt_to_phys(this_cpu_ptr(&apf_reason)); > > -#ifdef CONFIG_PREEMPTION > - pa |= KVM_ASYNC_PF_SEND_ALWAYS; > -#endif > pa |= KVM_ASYNC_PF_ENABLED; > > + /* > + * 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.