Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp781182rwb; Thu, 1 Dec 2022 08:17:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4uKe+QL7397F4Mz5ZZV3ioRXEXl/Nl/5FvOplj9cKbF1++EHICV+mkVjSD7GpSdY0R2UEL X-Received: by 2002:a17:903:230d:b0:189:69cf:9e9d with SMTP id d13-20020a170903230d00b0018969cf9e9dmr32623483plh.43.1669911434861; Thu, 01 Dec 2022 08:17:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669911434; cv=none; d=google.com; s=arc-20160816; b=Zdwtw21+8oRCgzVxtyWckM8MtDwi/xg1qoGWI830lLq9KmbHLIjG7Zymc9CL4yGyIu Ez5qqscQi7L+4jlZ2kbKsU5Fc3E0dGhFnKjVw+/ankTPzv38NqD/1t4RW62IV2Agy0AQ bQm931nofKcLSBtPrNJIvVpNtq8H84PpWyhkV31Ek7QMYZaErYVRl838TmHopq4QOu5x QoCteqB1ahvv3Q8hggHgeI49KudxEcA1zjS/xRcFz9Ap+4wn/UJ+GL9wjMhAoya/yPaZ 2EHm0pkeY1O0yDq28Wgd8LRW3xtwwJGR13gufyDwiN5dPZdnxVIMxhvjyp9t4nl0bs0P /8Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=0uolOOp7yoOC/673O4rWJ2SQim3eJ9tGJUopqkFhibc=; b=ZNejyipTRqQRBMl5W9INvFt6f49gPL8JltLhk35qRIqWSuZ1UyeZG2mEGc3FlSlTNx zikR179zNdo5JzzzyHhCA02DXB0yUDIb7IB724/BNtAHc3SD5cHMzwVFdohC2Onk4nIH v8YXYTjiXu6oaiA5CfyH1hEnjYGxc5JfEHZFfToxHFZVKzdVAoUf82UdGD5qZ+nprFJc JMUAODYOWhfAqaLCavZ4kD1+2hF/Md5I/9P2xHd0XTtmSvbhXOwbyUIN9XTwiswnHjnm K2AFtoZdSUAtaODjIIdPmdHU0ekjKWoPGi/pJRKFOAqmtyxZQTSa1w+hnJypgPq0ilS/ bDqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="B+Uzk/aU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a63464d000000b0047011722bc6si4634073pgk.531.2022.12.01.08.17.03; Thu, 01 Dec 2022 08:17:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="B+Uzk/aU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231673AbiLAPXs (ORCPT + 82 others); 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-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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