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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 88023C433FE for ; Thu, 9 Sep 2021 18:59:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 606996113A for ; Thu, 9 Sep 2021 18:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237593AbhIITAV (ORCPT ); Thu, 9 Sep 2021 15:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbhIITAU (ORCPT ); Thu, 9 Sep 2021 15:00:20 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFDABC061574 for ; Thu, 9 Sep 2021 11:59:10 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id j2so1704531pll.1 for ; Thu, 09 Sep 2021 11:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ivHQCNTMj8d081EaJs/OWp0rY18lxe7zmhcLzE6AV3M=; b=YnjGjn+AKEmZ920Dc2yEn3vadOv8hGcIrIfrx+Lo4uwM1Pk4c793DAW101NoeUSTn/ bXl13y7V493cBm7h6LnfqQKWturRswUuWOmhxkK55I7p1EPKL33/ZvKQAQFueqCUqPHA /6BoyCl++OiJb3DXF+UgfzFU2RyYxyddNk+PQ2SdRqDCgwC0uFE8BxiSNevMselh/ml2 +knI0+9D8zKLV5Hnq5izjaiHkCU5anlpAM35eEkW4QLHmDrlCznQ3wsm9eJbkXBudqKs 8YoMSJ20ZMc+eosSj85XHm/D2OqyTyBKVQrloLYlXSc7ZjdthMi7wlGNFfXJDmvsC63N WFwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ivHQCNTMj8d081EaJs/OWp0rY18lxe7zmhcLzE6AV3M=; b=q6WjvbDDVj3RNQNMzA6F4+iO766E/kfcyxnPDLnGBR1Kgwn5Cx+yd3pLqMKmOuTDu9 DsRMEASZcAhJYBwMt/Doo/ANfdCw9N6ppar6HTjk+Z18aNp5iecuQMiTlVAVVDiFZ1Is A8pUjrE4RgxNn5l5nHF6Qg9cjXGt1JylHOLueKE77jzGL/Ne12AN4pnFB29isG/uWsRk 1PZMxiAsMDncluaSjR892BJOBE2tWlOep2ylzZDUT7lSlWQff5j1U9Z1oRAb2/smgiAg 2uKXSM9ajj3TtfZdzYcHJRfq9Os/PcXXH5KDbrH9Fhz54gS+JixeCF9S5yr5C0gI6O40 Urnw== X-Gm-Message-State: AOAM530qhMLACpU//9nmq65UOoOcmaFNcqvrtmlL7lxGx/oIrrTow90K PIoY9t4VUScZE+PYeAKpM4msxQ== X-Google-Smtp-Source: ABdhPJzbuG9m75RBkmn+9LvIUiv0Yxgry2fXtBpxvZf91/vhVbV1zXHbF1aZnXw49a+ez/Aw4NJQ2A== X-Received: by 2002:a17:90a:f002:: with SMTP id bt2mr5227853pjb.207.1631213949990; Thu, 09 Sep 2021 11:59:09 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id u7sm3063969pjn.45.2021.09.09.11.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 11:59:09 -0700 (PDT) Date: Thu, 9 Sep 2021 18:59:05 +0000 From: Sean Christopherson To: Xiaoyao Li Cc: Chenyi Qiang , pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] KVM: VMX: Enable Notify VM exit Message-ID: References: <20210525051204.1480610-1-tao3.xu@intel.com> <080602dc-f998-ec13-ddf9-42902aa477de@intel.com> <118cd1b9-1b50-3173-05b8-4293412ca78c@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <118cd1b9-1b50-3173-05b8-4293412ca78c@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 07, 2021, Xiaoyao Li wrote: > On 9/3/2021 12:36 AM, Sean Christopherson wrote: > > On Thu, Sep 02, 2021, Sean Christopherson wrote: > > > On Tue, Aug 03, 2021, Xiaoyao Li wrote: > > > > On 8/2/2021 11:46 PM, Sean Christopherson wrote: > > > > > > > > @@ -5642,6 +5653,31 @@ static int handle_bus_lock_vmexit(struct kvm_vcpu *vcpu) > > > > > > > > return 0; > > > > > > > > } > > > > > > > > +static int handle_notify(struct kvm_vcpu *vcpu) > > > > > > > > +{ > > > > > > > > + unsigned long exit_qual = vmx_get_exit_qual(vcpu); > > > > > > > > + > > > > > > > > + if (!(exit_qual & NOTIFY_VM_CONTEXT_INVALID)) { > > > > > > > > > > > > > > What does CONTEXT_INVALID mean? The ISE doesn't provide any information whatsoever. > > > > > > > > > > > > It means whether the VM context is corrupted and not valid in the VMCS. > > > > > > > > > > Well that's a bit terrifying. Under what conditions can the VM context become > > > > > corrupted? E.g. if the context can be corrupted by an inopportune NOTIFY exit, > > > > > then KVM needs to be ultra conservative as a false positive could be fatal to a > > > > > guest. > > > > > > > > > > > > > Short answer is no case will set the VM_CONTEXT_INVALID bit. > > > > > > But something must set it, otherwise it wouldn't exist. > > For existing Intel silicon, no case will set it. Maybe in the future new > case will set it. > > > The condition(s) under > > > which it can be set matters because it affects how KVM should respond. E.g. if > > > the guest can trigger VM_CONTEXT_INVALID at will, then we should probably treat > > > it as a shutdown and reset the VMCS. > > > > Oh, and "shutdown" would be relative to the VMCS, i.e. if L2 triggers a NOTIFY > > exit with VM_CONTEXT_INVALID then KVM shouldn't kill the entire VM. The least > > awful option would probably be to synthesize a shutdown VM-Exit to L1. That > > won't communicate to L1 that vmcs12 state is stale/bogus, but I don't see any way > > to handle that via an existing VM-Exit reason :-/ > > > > > But if VM_CONTEXT_INVALID can occur if and only if there's a hardware/ucode > > > issue, then we can do: > > > > > > if (KVM_BUG_ON(exit_qual & NOTIFY_VM_CONTEXT_INVALID, vcpu->kvm)) > > > return -EIO; > > > > > > Either way, to enable this by default we need some form of documentation that > > > describes what conditions lead to VM_CONTEXT_INVALID. > > I still don't know why the conditions lead to it matters. I think the > consensus is that once VM_CONTEXT_INVALID happens, the vcpu can no longer > run. Yes, and no longer being able to run the vCPU is precisely the problem. The condition(s) matters because if there's a possibility, however small, that enabling NOTIFY_WINDOW can kill a well-behaved guest then it absolutely cannot be enabled by default. > Either KVM_BUG_ON() or a specific EXIT to userspace should be OK? Not if the VM_CONTEXT_INVALID happens while L2 is running. If software can trigger VM_CONTEXT_INVALID at will, then killing the VM would open up the door to a malicious L2 killing L1 (which would be rather ironic since this is an anti-DoS feature). IIUC, VM_CONTEXT_INVALID only means the current VMCS is garbage, thus an occurence while L2 is active means that vmcs02 is junk, but L1's state in vmcs01, vmcs12, etc... is still valid.