Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp787188pxb; Thu, 9 Sep 2021 12:01:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG7r9ca0SLMvIfwYHDjr1U7EVejZzeLFATSxvVfBuISDrA16TNQvQ2jW676gZaYPlWFUyI X-Received: by 2002:a05:6402:4cb:: with SMTP id n11mr4754275edw.292.1631214087381; Thu, 09 Sep 2021 12:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631214087; cv=none; d=google.com; s=arc-20160816; b=ahjuSYxU+1h2EaP22lAb5i/eOOIFISTC0/2Q/fuh+mM0CF/LWg4K+qcLWtD/xL98Y/ vXlPttXY6Hrx7wJQYl42F4sa12RUkWcb5uQ8DS51OCs2lDDI4NZNn9uVUeoUCKgDo2P3 IrKtc//d48cDmSsaVvBwXXzDNleA7IbqIRybTwy1uEBuElmg7jHOXJI1BCHbKE411eyg nub8IpeM5h+L+ln6GWyW6fA6KdguAkqfsPedI+69WgxqHQ6z1ivlx0UxKxSdu/KfPCy6 ZP8Un9L/+d7mhkcu7ou+Y0x7iACKZm9UVSj04TcLejuSB+/QHDRSd0ZtytzUWcoFGHg6 XOQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ivHQCNTMj8d081EaJs/OWp0rY18lxe7zmhcLzE6AV3M=; b=R+yBfVADPg8X1tCSL3PZBRCBSaWaDrUkRamHut2UzUY2JQMNONI6ABfy/MbFQ0hG2n 9QdUkoBYi4j2HqWn44OMCWzN7R0QWd5Ub+HR1pKWWGnv8m01qH9eAx+hMEPgNNJJ8Dqy Ubc8arBxbaxMaEh0GdnWybUeMU6uihFMV4P1BECPJEPbQxalR7mjCFJwOka2rfjJMRcc 0qEHLUE7uV4GRlJqndRcGxUQwdXwGtkm1IEDC61v0mxFrbuXFYPzVFOAOQurpnq6RV8X wPO1/7Mq81rIaRuSmF5eg0M56nr2AAuALtrkLHtD1J1BAmYoZ/LjWwXDRCqx4nxzx8kz enQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YnjGjn+A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si2885429ejv.670.2021.09.09.12.01.01; Thu, 09 Sep 2021 12:01:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YnjGjn+A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237373AbhIITAU (ORCPT + 99 others); Thu, 9 Sep 2021 15:00:20 -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-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.