Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp1129401rwl; Fri, 4 Nov 2022 10:05:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5y+5IEBAdMHm4wSmIO6ixxTIWl5s39GWlwT5X4SpwFWR9C3wX8+FZU7RAuwPzU4UPsw4cq X-Received: by 2002:a17:90a:5289:b0:213:cb7d:5fe8 with SMTP id w9-20020a17090a528900b00213cb7d5fe8mr32213119pjh.8.1667581543080; Fri, 04 Nov 2022 10:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667581543; cv=none; d=google.com; s=arc-20160816; b=gIzmoX0P5RLlR80fiLpjHXEhM7dydgnY/gCIQ6BVELo/Zetvnf+z4UOvj56bIV5V7S RTo+T8iUkOjLQLFyNjKwIpNHwjZDURuFGaAjv/uA8Fic42SRG0fIqtZdThVJ6IczIVSA 1gZVJkd9yGRNKNCWoaeVixEZeULj6+JAmHe70z/CqrfJju1LwSucTHeti80S3aeG4psE K4vGfiQA+70V4dSZmXKOHXOvK6z3zLT93xLNrFpO/n5aJi+5+/+bF4HYRtTPBK3KQpTM PJmVWDNkaJBq1/O5wP6vEiT7BpDOdrA2tWI1/iS5OkKfPENaTb3flppYgzTUoGODzL8p VDhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tykh0C7NQoqMsiv0FEJ8nDBTc1ar6j/4SljcpXaw+gg=; b=fuMumH69t4nFIiSuFRyIO8fy7z6mNZSmQrup5pKjm5KBQblf3y39O36ltC5zxyOtgS bp3XQUBy+tRN2M2LuPztB/BPOaKqQu00Nzk2u81PHrHBvsWPg87sOy4qb2GjHJXqS4Gc Q/tGrJE+i/kYrG1plONuYHfDPXvhpaql1aDbV2XIcnAGGKSCJDPhU+j5eRPTv2yhYONk /MOMCkIV1BmSoFAFJL1Yi2GVhttXh/MhdK2kx19OiGEhNKPlh3xjtnjHWTncAwa/9l8W KeyjsWvAQPlG0OSgJ0AsR0TwgiLf01wcHws9PONQbQJeIiypRO6aTxyG4v4BzguQ5UHf 6Tlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZvfqWRbm; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a636c09000000b0046b322237c3si5414626pgc.804.2022.11.04.10.05.27; Fri, 04 Nov 2022 10:05:43 -0700 (PDT) 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=@google.com header.s=20210112 header.b=ZvfqWRbm; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231530AbiKDQbo (ORCPT + 97 others); Fri, 4 Nov 2022 12:31:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbiKDQbb (ORCPT ); Fri, 4 Nov 2022 12:31:31 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BDFD29802 for ; Fri, 4 Nov 2022 09:31:30 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 78so4784513pgb.13 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=C0HK0BsuAx9LcBj5eEwA4L8GZTdHqgjRPY21KSioU+YUM1IhtyL/uiMZGBlh3LJN1p ZM3cRNslQWIBzxNUSTOqEa/tFeC5yy1uqE2DFjQg8i/rtZeilwiDIivXh6j1LOf5udW4 fGf65KsNkDxEDksnFz49whRgLu9YmOxwRhsb+Ep4RLXpAyzWeshJ7azFvZwQ5K7i5Cs0 SzDx+DuGOvfiSOLhqtqJjUFjOuAElnSnLMWW0L+FOqjA3HwpjMVVsxM4+b1nahcmc5ON KuepLyzMOge/GlaR5cwdxDAY+DUyyYm3qosOdoeImzFKbgXh/wkBPbd/5TDscCicyHpY xQBw== X-Gm-Message-State: ACrzQf2U50fUICHwS/W2XiksJUV140ZhF/m1fgdhr3XX+AOHbapYRYfK GvrIGuXVu86QPl21pjr9mgpuzg== 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> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,FSL_HELO_FAKE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 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: