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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A971C28B2B for ; Fri, 19 Aug 2022 17:43:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349871AbiHSRnd (ORCPT ); Fri, 19 Aug 2022 13:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351349AbiHSRnF (ORCPT ); Fri, 19 Aug 2022 13:43:05 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07EA4A18C for ; Fri, 19 Aug 2022 10:02:45 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id w138so2212703pfc.10 for ; Fri, 19 Aug 2022 10:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=RHK5G9JAHhgGCkTg4CkDfYb1xqntg9knbs5lZi1RIbo=; b=eMWi9bQ3cPenIuHSE1JOvmJB1dVh9t7Cp2IJZLR8XpIFrkabsBA8LbFNcDtuMHKGYk lO7RbJFzqoDBs8EjujmnOcJLHZooX1hawuVMA0ma5VUzEKGcpOXnOLS2CFUw/oVsO866 0U4urqsAvRT98P0gP48YbFe9EjKkLcaYDUAWnRX3saxFTQj2ISyRC9CepELsXY6jT3Hh /m0YC3rHZ9ky4EwtbhCtLhtDgckjSwQPxdm3Jtsw1cZD3VWrOfQyewqtdSQZbGRZDNBH MtELkwWWbG0wjmDUT2Z7RpO5lj/fJ9WfntfjsrQnMmBL0x9OGKnU7886JMJzb5PGqGyj Nubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=RHK5G9JAHhgGCkTg4CkDfYb1xqntg9knbs5lZi1RIbo=; b=EoRPcA3subUA+/AFhWixFnntoNvFFDQHA8CHHS5Myvm7ObMErgqsnyEzvpEOcb9CHZ ws7NuQqh5ic4YOTCiSdIpsFhfjndja4dEy99R3bTBm7/3x3uul2fI2VD5FvIXqoSMzbR /MJPpJ54Nvg7g/OTMU8vThq8bSDRawiydT4ogWJiiSxkLe3xB990pgF5giPIEnKbx1gp jp/6dxFr1YFHwfc79C5Yg7DGi3mHfW6yoyBLnB85YhVlhaDN2osREmk2/acXf3GPdcTo itnOHi57IV50guV1UAYLME2su9HTXbO79Gjd58WB+fBELQObS5h9QQcFr5T5Z+Km1hv2 2Skg== X-Gm-Message-State: ACgBeo2csfOvg9/E+3Z0/lvf2IfwEanOQeXuoLf5zVLq8Wvk20ItSBQH 9Ds36aHS+Ecfdqsr+L3YbvfP8w== X-Google-Smtp-Source: AA6agR5G2Yn1si0Ny8aEgUM18mGUOU921TVyadVX4vrrgP4oahkPCcwlt/K0QNMZO1CXlnVbKd1jxQ== X-Received: by 2002:a05:6a00:13a2:b0:52e:128a:23dd with SMTP id t34-20020a056a0013a200b0052e128a23ddmr8879857pfg.54.1660928564333; Fri, 19 Aug 2022 10:02:44 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id x1-20020aa79ac1000000b00535d3caa66fsm3469048pfp.197.2022.08.19.10.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 10:02:43 -0700 (PDT) Date: Fri, 19 Aug 2022 17:02:40 +0000 From: Sean Christopherson To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Wanpeng Li , Jim Mattson , Maxim Levitsky , Nathan Chancellor , Michael Kelley , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 09/26] KVM: VMX: nVMX: Support TSC scaling and PERF_GLOBAL_CTRL with enlightened VMCS Message-ID: References: <20220802160756.339464-1-vkuznets@redhat.com> <20220802160756.339464-10-vkuznets@redhat.com> <87sflssllu.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87sflssllu.fsf@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org On Fri, Aug 19, 2022, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > On Tue, Aug 02, 2022, Vitaly Kuznetsov wrote: > >> +static u32 evmcs_get_unsupported_ctls(struct kvm_vcpu *vcpu, > >> + enum evmcs_unsupported_ctrl_type ctrl_type) > >> +{ > >> + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); > >> + enum evmcs_revision evmcs_rev = EVMCSv1_2016; > >> + > >> + if (!hv_vcpu) > > > > This is a functiontal change, and I don't think it's correct either. Previously, > > KVM would apply the EVMCSv1_2016 filter irrespective of whether or not > > vcpu->arch.hyperv is non-NULL. nested_enable_evmcs() doesn't require a Hyper-V > > vCPU, and AFAICT nothing requires a Hyper-V vCPU to use eVMCS. > > Indeed, this *is* correct after PATCH11 when we get rid of VMX feature > MSR filtering for KVM-on-Hyper-V as the remaining use for > evmcs_get_unsupported_ctls() is Hyper-V on KVM and hv_vcpu is not NULL > there. Hmm, nested_vmx_handle_enlightened_vmptrld() will fail without a Hyper-V vCPU, so filtering eVMCS control iff there's a Hyper-V vCPU makes sense. But that's a guest visible change and should be a separate patch. But that also raises the question of whether or not KVM should honor hyperv_enabled when filtering MSRs. Same question for nested VM-Enter. nested_enlightened_vmentry() will "fail" without an assist page, and the guest can't set the assist page without hyperv_enabled==true, but nothing prevents the host from stuffing the assist page. And on a very related topic, the handling of kvm_hv_vcpu_init() in kvm_hv_set_cpuid() is buggy. KVM will not report an error to userspace for KVM_SET_CPUID2 if allocation fails. If a later operation successfully create a Hyper-V vCPU, KVM will chug along with Hyper-V enabled but without having cached the relevant Hyper-V CPUID info. Less important is that kvm_hv_set_cpuid() should also zero out the CPUID cache if Hyper-V is disabled. I'm pretty sure sure all paths check hyperv_enabled before consuming cpuid_cache, but it's unnecessarily risky. If we fix the kvm_hv_set_cpuid() allocation failure, then we can also guarantee that vcpu->arch.hyperv is non-NULL if vcpu->arch.hyperv_enabled==true. And then we can add gate guest eVMCS flow on hyperv_enabled, and evmcs_get_unsupported_ctls() can then WARN if hv_vcpu is NULL. Assuming I'm not overlooking something, I'll fold in yet more patches.