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 C7371C43217 for ; Thu, 1 Dec 2022 15:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbiLAPXs (ORCPT ); Thu, 1 Dec 2022 10:23:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231638AbiLAPXq (ORCPT ); Thu, 1 Dec 2022 10:23:46 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 409662EF09 for ; Thu, 1 Dec 2022 07:22:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669908172; 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=B+Uzk/aU+G0kyeVnZME32d4YN4l7sLEVdy7VP6JuIJVqdFtpi6L4u9AR4foUS4yhJn04ji IbCpdEjCFiv/Ox5p9ri3H0diiVKuINuS06MGQTlm7eAeA92w2eMUUp1TObuZXodswa8hnv xYmqwHPcu0DVGFsFXIzPOza1/s2AbEU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-362-2GnRhtVYMgOAgLeMQA27cA-1; Thu, 01 Dec 2022 10:22:51 -0500 X-MC-Unique: 2GnRhtVYMgOAgLeMQA27cA-1 Received: by mail-wm1-f69.google.com with SMTP id i8-20020a1c3b08000000b003d0683389daso2677594wma.6 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=FdhDA50F063w3DSkf9khxEMKJgKpqICOsEXMQQ4feGdBOj1dxQ9H3R+/6bfhFGCBsn CPzIHM7WRQX2HFfEWYcSWW7+TjWOOQfOLQjohkUSV8TTAfjQyBpNdMNjxniXdCIQmhrV iFelSmugeW6DG0sKRGyvyge3CBkRTCWGTVII1MLh8rbRv5rolvifWwsVfSrWb8Qy8f8E s74PeYLcrn+3F4ZGpfT/S8KzhLbN3lRuBKzb8rEF0OuD9MboeSJOQZG70hd3QaiEQAdW g7hVD4b/qkxpf5erqbHtQ0pjUk52yP84ppznOqDBLmgO1V1zAp3kjQEnpwwcLWthQUUR aAnQ== X-Gm-Message-State: ANoB5pkt1sEcCQDIFeB0+Dp/TB+fCz/ir0QMBXdkRxMj3RIY3ijlmx+i dJL+lPcQBOb9x4DMU7pqApRtxWVdsnWhwzTOXoHTBtlxg4wGtPFEfLoZ8A3Oo0bK52D6SFDA/Pm m4fDIUiPRaAL5lq7xyHrnwqhS X-Received: by 2002:adf:f54e:0:b0:242:1534:7b57 with SMTP id j14-20020adff54e000000b0024215347b57mr14035619wrp.404.1669908170120; 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 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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