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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC06DC43217 for ; Thu, 1 Dec 2022 15:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References :In-Reply-To:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/Um6pIcHVhxCXfOAtWcpX2rz788ept+fUqwxp9gyppg=; b=uBvvTHr+rv/sLA L/bOLQfCl5g0t5ytCIQWArMPyFQAFnYLxjiSTfU+mC79uu/5c4ZZluU61B1HmPk+0b7v5s0MV8VUn KOhv7QMdUgqR7nvUqGY/iQxy+XiT/YYvsG+nFgpI/aF9mUl5++oXgDj4sJjyC7S30Se2b5npJqR2d dAvrtO80Yfv9FebpIRMnqfGVy4FVMNnte15cAEby0zdcyGG+jzV8pW3FCTl/MVJMQuRqButyb4SdO +WrRV1yHUVxIInyZdieniXjSLC/Jn7J290KIz4Z0HIVo6b9sfwMJfLs2fkdheFFjSm9S8oSkiOSUw 5j2f3FmlUvaH4zBW4iEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0lOv-008Bi0-Hs; Thu, 01 Dec 2022 15:23:01 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0lOs-008BgF-FE for linux-arm-kernel@lists.infradead.org; Thu, 01 Dec 2022 15:23:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669908177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0uolOOp7yoOC/673O4rWJ2SQim3eJ9tGJUopqkFhibc=; b=ZArWGwRN8Gf+fzuPcn+6LvgOauW3RVCyO1gLLPOwCGCRTp+uv30h7TMQ0b/kdNI1+sJqZ/ hpX9t7lZ1jp2fI8JpaoGLmhyJkjYXSSFXxQkPS0PwFJrynYANdMoSPKOFWaGxBAAXs4lsl n/f0qpKtyM68tzGQ8SKBXq5L4faqK8g= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-362-ibFWOpd9O_Cc5DrczpRkWg-1; Thu, 01 Dec 2022 10:22:51 -0500 X-MC-Unique: ibFWOpd9O_Cc5DrczpRkWg-1 Received: by mail-wm1-f70.google.com with SMTP id bg25-20020a05600c3c9900b003cf3ed7e27bso985722wmb.4 for ; Thu, 01 Dec 2022 07:22:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0uolOOp7yoOC/673O4rWJ2SQim3eJ9tGJUopqkFhibc=; b=toG14zJV2CD+LExwkFr0P3ACZ4GT+Olx8KOJUeRDJm3mMSbwQ7joaqVUmAcx/MrYDs Uu1P1kgSefr1FM1D2VNiFbXG0857eP87p/8jZrQj3R9O10Urj6xg1xu+ppmk4t8tobJU i8VxplX+rzxz4UQyvJ3FoE3zVhgopKugCRg4X/v/0zlJNVkb4qfVrehqXZnQ0Swrqlx2 NZV313amojnH5Xqh+ga6uiB5+JEsc0d4AY6/IEo2y/v0gQDMF4F/OQx2G1LFEl6nWSaQ naPdu5Pd+RrMHeziVHsAt509zrkR0uDd8s3zcMMzHG7dDFDV0swm7n1whHMbgcKh02m5 ictA== X-Gm-Message-State: ANoB5pnpIW2X3cayqY213uFhzpuLZs66X1MaAMMcDoimJDvgQLMqmkf1 CPHy7cVKNR746mMKBqlq6uFhT2GfAq1sbL5pbBrdlZlSRc07kO0A8lLuIvOtWBzQjC31kxpWl6x 7MqQA+fLO0urUi29vJSVOzGKWVfHIYmoDsfc= X-Received: by 2002:adf:f54e:0:b0:242:1534:7b57 with SMTP id j14-20020adff54e000000b0024215347b57mr14035627wrp.404.1669908170125; Thu, 01 Dec 2022 07:22:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+3YusiSWHR13O3MACnIQbSphop/g7AmmIFME21D1fv2+5ZYUMJJrVIeLUQmj0nQTJeAmHuA== X-Received: by 2002:adf:f54e:0:b0:242:1534:7b57 with SMTP id j14-20020adff54e000000b0024215347b57mr14035606wrp.404.1669908169821; Thu, 01 Dec 2022 07:22:49 -0800 (PST) Received: from ovpn-194-141.brq.redhat.com (nat-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id j11-20020a05600c190b00b003b47e75b401sm10593279wmq.37.2022.12.01.07.22.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 07:22:49 -0800 (PST) From: Vitaly Kuznetsov To: Sean Christopherson Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Yao , Cornelia Huck , Isaku Yamahata , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner , Paolo Bonzini , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Matthew Rosato , Eric Farman , Sean Christopherson , David Woodhouse , Paul Durrant Subject: Re: [PATCH v2 12/50] KVM: VMX: Move Hyper-V eVMCS initialization to helper In-Reply-To: <20221130230934.1014142-13-seanjc@google.com> References: <20221130230934.1014142-1-seanjc@google.com> <20221130230934.1014142-13-seanjc@google.com> Date: Thu, 01 Dec 2022 16:22:45 +0100 Message-ID: <87k03bf8sa.fsf@ovpn-194-141.brq.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221201_072258_605067_6BB36636 X-CRM114-Status: GOOD ( 25.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Sean Christopherson writes: > Move Hyper-V's eVMCS initialization to a dedicated helper to clean up > vmx_init(), and add a comment to call out that the Hyper-V init code > doesn't need to be unwound if vmx_init() ultimately fails. > > No functional change intended. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/vmx.c | 73 +++++++++++++++++++++++++----------------- > 1 file changed, 43 insertions(+), 30 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index c0de7160700b..b8bf95b9710d 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -523,6 +523,8 @@ static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx) > static unsigned long host_idt_base; > > #if IS_ENABLED(CONFIG_HYPERV) > +static struct kvm_x86_ops vmx_x86_ops __initdata; > + > static bool __read_mostly enlightened_vmcs = true; > module_param(enlightened_vmcs, bool, 0444); > > @@ -551,6 +553,43 @@ static int hv_enable_l2_tlb_flush(struct kvm_vcpu *vcpu) > return 0; > } > > +static __init void hv_init_evmcs(void) > +{ > + int cpu; > + > + if (!enlightened_vmcs) > + return; > + > + /* > + * Enlightened VMCS usage should be recommended and the host needs > + * to support eVMCS v1 or above. > + */ > + if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED && > + (ms_hyperv.nested_features & HV_X64_ENLIGHTENED_VMCS_VERSION) >= > + KVM_EVMCS_VERSION) { > + > + /* Check that we have assist pages on all online CPUs */ > + for_each_online_cpu(cpu) { > + if (!hv_get_vp_assist_page(cpu)) { > + enlightened_vmcs = false; > + break; > + } > + } > + > + if (enlightened_vmcs) { > + pr_info("KVM: vmx: using Hyper-V Enlightened VMCS\n"); > + static_branch_enable(&enable_evmcs); > + } > + > + if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) > + vmx_x86_ops.enable_l2_tlb_flush > + = hv_enable_l2_tlb_flush; > + > + } else { > + enlightened_vmcs = false; > + } > +} > + > static void hv_reset_evmcs(void) > { > struct hv_vp_assist_page *vp_ap; > @@ -577,6 +616,7 @@ static void hv_reset_evmcs(void) > } > > #else /* IS_ENABLED(CONFIG_HYPERV) */ > +static void hv_init_evmcs(void) {} > static void hv_reset_evmcs(void) {} > #endif /* IS_ENABLED(CONFIG_HYPERV) */ > > @@ -8500,38 +8540,11 @@ static int __init vmx_init(void) > { > int r, cpu; > > -#if IS_ENABLED(CONFIG_HYPERV) > /* > - * Enlightened VMCS usage should be recommended and the host needs > - * to support eVMCS v1 or above. We can also disable eVMCS support > - * with module parameter. > + * Note, hv_init_evmcs() touches only VMX knobs, i.e. there's nothing > + * to unwind if a later step fails. > */ > - if (enlightened_vmcs && > - ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED && > - (ms_hyperv.nested_features & HV_X64_ENLIGHTENED_VMCS_VERSION) >= > - KVM_EVMCS_VERSION) { > - > - /* Check that we have assist pages on all online CPUs */ > - for_each_online_cpu(cpu) { > - if (!hv_get_vp_assist_page(cpu)) { > - enlightened_vmcs = false; > - break; > - } > - } > - > - if (enlightened_vmcs) { > - pr_info("KVM: vmx: using Hyper-V Enlightened VMCS\n"); > - static_branch_enable(&enable_evmcs); > - } > - > - if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) > - vmx_x86_ops.enable_l2_tlb_flush > - = hv_enable_l2_tlb_flush; > - > - } else { > - enlightened_vmcs = false; > - } > -#endif > + hv_init_evmcs(); > > r = kvm_init(&vmx_init_ops, sizeof(struct vcpu_vmx), > __alignof__(struct vcpu_vmx), THIS_MODULE); Reviewed-by: Vitaly Kuznetsov -- Vitaly _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel