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 1C17EC4332F for ; Fri, 4 Nov 2022 16:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231649AbiKDQbm (ORCPT ); Fri, 4 Nov 2022 12:31:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231663AbiKDQbc (ORCPT ); Fri, 4 Nov 2022 12:31:32 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A39C1326F3 for ; Fri, 4 Nov 2022 09:31:30 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id m6so5002361pfb.0 for ; Fri, 04 Nov 2022 09:31:30 -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:subject:date:message-id:reply-to; bh=tykh0C7NQoqMsiv0FEJ8nDBTc1ar6j/4SljcpXaw+gg=; b=ZvfqWRbmiygXbQlvUXzlFPIy6pWgi3NnbKZ9axUfvTwSG1jmeczFdzfmEBk6JPul9u KtfoNDPD7+7L7ckLKxE85H3i30VZE1cLcwZqr+9Pmyt/Uvr0gsenysKMrttjRd1DNmYa taHLNc4BlGL4LuS+a5zOzje7JmI5lr7pLr83tPoJKPDxZ+8mRqo1TUsZIcKB3+pLirGc 61VotfoTC994tXlc+pHq0IWsR3SGM7VfiO/hK89Ek0CoqTLSvnWOMLSW6BMMx8STYHyn tAWojTUjFC5IOfCMzJ25ZkS53CsxfaYW+If16SDvap+gn/hFvgnPNsAIXJ/ZXr/CVgup nXnw== 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:subject:date :message-id:reply-to; bh=tykh0C7NQoqMsiv0FEJ8nDBTc1ar6j/4SljcpXaw+gg=; b=HF63O8Q6FTcxldaOp3ZoNppbWK/LdO+1WIzzeBxXopR80OVN+6YmRbzDcmp5wSGa40 QVsDMwRRqKG5JrjKA0EHsm7wll81wjdO5N3OeAcKZ0GBcP3PDtExT3OGZKh/isFLD3vc 4inHvmQKcocS+dJXBPFr00p6zGLGEcNd9Z+0iMOPArpVpYPCpkG75Kzq6i5SlkXCJyTy fjqDGMCvIn5OEAw4TDCEzMWd7kfnzh9Oe1T8z+ahXIghn9SgmcWK2dLOKU0BhVd7E+0b dWN5UtltSSwN1vvURyFVHCBhKSGDnb9otLmDO8JO01aezV6pqfDfsvSleeBLAYlwUgBR OGEw== X-Gm-Message-State: ACrzQf1PyWWVMk6ZYForKnw4NybM1YbpLAuJ/GmS+T9xCtSiAfSzCSQo 1bCoFS278z4WQmjLVwf++FwiwA== X-Google-Smtp-Source: AMsMyM4q4CNgN2lQ4PyaYyADoR+QimlVBokrxw9X6LS0+cBweFifUR+XVuuTHXr8UlnLM2zvHk12kA== X-Received: by 2002:a05:6a00:248e:b0:56e:ad31:b976 with SMTP id c14-20020a056a00248e00b0056ead31b976mr1059125pfv.51.1667579490004; Fri, 04 Nov 2022 09:31:30 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id y133-20020a62ce8b000000b00565cbad9616sm2954667pfg.6.2022.11.04.09.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 09:31:29 -0700 (PDT) Date: Fri, 4 Nov 2022 16:31:25 +0000 From: Sean Christopherson To: Yuan Yao Cc: 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 , Vitaly Kuznetsov , 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, Isaku Yamahata , Fabiano Rosas , Michael Ellerman , Chao Gao , Thomas Gleixner , Yuan Yao Subject: Re: [PATCH 08/44] KVM: x86: Move hardware setup/unsetup to init/exit Message-ID: References: <20221102231911.3107438-1-seanjc@google.com> <20221102231911.3107438-9-seanjc@google.com> <20221104062223.7kcrbt66mlmqxk7f@yy-desk-7060> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221104062223.7kcrbt66mlmqxk7f@yy-desk-7060> Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Fri, Nov 04, 2022, Yuan Yao wrote: > On Wed, Nov 02, 2022 at 11:18:35PM +0000, Sean Christopherson wrote: > > To avoid having to unwind various setup, e.g registration of several > > notifiers, slot in the vendor hardware setup before the registration of > > said notifiers and callbacks. Introducing a functional change while > > moving code is less than ideal, but the alternative is adding a pile of > > unwinding code, which is much more error prone, e.g. several attempts to > > move the setup code verbatim all introduced bugs. ... > > @@ -9325,6 +9343,24 @@ int kvm_arch_init(void *opaque) > > kvm_caps.supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0; > > } > > > > + rdmsrl_safe(MSR_EFER, &host_efer); > > + > > + if (boot_cpu_has(X86_FEATURE_XSAVES)) > > + rdmsrl(MSR_IA32_XSS, host_xss); > > + > > + kvm_init_pmu_capability(); > > + > > + r = ops->hardware_setup(); > > + if (r != 0) > > + goto out_mmu_exit; > > The failure case of ops->hardware_setup() is unwound > by kvm_arch_exit() before this patch, do we need to > keep that old behavior ? As called out in the changelog, the call to ops->hardware_setup() was deliberately slotted in before the call to kvm_timer_init() so that kvm_arch_init() wouldn't need to unwind more stuff if harware_setup() fails. > > + /* > > + * Point of no return! DO NOT add error paths below this point unless > > + * absolutely necessary, as most operations from this point forward > > + * require unwinding. > > + */ > > + kvm_ops_update(ops); > > + > > kvm_timer_init(); > > > > if (pi_inject_timer == -1) > > @@ -9336,8 +9372,32 @@ int kvm_arch_init(void *opaque) > > set_hv_tscchange_cb(kvm_hyperv_tsc_notifier); > > #endif > > > > + kvm_register_perf_callbacks(ops->handle_intel_pt_intr); > > + > > + if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES)) > > + kvm_caps.supported_xss = 0; > > + > > +#define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f) > > + cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_); > > +#undef __kvm_cpu_cap_has > > + > > + if (kvm_caps.has_tsc_control) { > > + /* > > + * Make sure the user can only configure tsc_khz values that > > + * fit into a signed integer. > > + * A min value is not calculated because it will always > > + * be 1 on all machines. > > + */ > > + u64 max = min(0x7fffffffULL, > > + __scale_tsc(kvm_caps.max_tsc_scaling_ratio, tsc_khz)); > > + kvm_caps.max_guest_tsc_khz = max; > > + } > > + kvm_caps.default_tsc_scaling_ratio = 1ULL << kvm_caps.tsc_scaling_ratio_frac_bits; > > + kvm_init_msr_list(); > > return 0; > > > > +out_mmu_exit: > > + kvm_mmu_vendor_module_exit(); > > out_free_percpu: > > free_percpu(user_return_msrs); > > out_free_x86_emulator_cache: