From patchwork Wed Nov 2 23:18:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 14516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp199036wru; Wed, 2 Nov 2022 16:20:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nG2pOF1XzvRryl0PmCVKcQ+wIqwHyvzf9XKq9+e1dg1losfxqeCzh0OznVt4apo/QY7zo X-Received: by 2002:a17:902:dac9:b0:187:411c:4f05 with SMTP id q9-20020a170902dac900b00187411c4f05mr7776085plx.147.1667431236489; Wed, 02 Nov 2022 16:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667431236; cv=none; d=google.com; s=arc-20160816; b=eyu5F6LeXM2Q4O+iaR2VBebNvz9PYIXMAml3wS3ihJhm9eYzDVwrqX2myuCdwvF2gX GexXxfVxNn2cy09LWFwMkPVRuAMOOthX8biakNCkMicz0qrUhF8LTvx8sFGmq0h2HCz7 Q1qbLVp4JRGl77x9sTLF3rRqjhlX8sEFaveR42i3S+cDVK60RgZp3vafyQsgzQIUAvjz NTTwPtgUN13s+GxvIezBc7szXZp9QK0JU5aphnAATghlE7kbSyf60Fj7YkFFfHLry1u2 hRR7z0hN/0qVKxXGwUXuZZKGXmKEu98n74K1GSp2uiq7TEvyCPEabrxmAm4q9uayzVad AsKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=Pm9EI+cM+5edeoncgirJOK1OjdMfit/iE/V7h68jiBA=; b=oiHNTHCuE5NdLGlsfodmYJCwUmJM8uEX399NUJKqgwpzKwJWCzgxIJEJgJMVjV7cUX 6WhhR0/Xe+GQLTiTFVAGcF/xpxNQCbuK3J0zZWtjuY5kYvyV598LyzU4Q0wJhPGs2Yxr LSlJ2IufJ7VhkGvXlAgEoRjGXaHXjSa6bvp3Y/bdiuh/0y4mea8YMDGZISYANTG/2+Nk Mvn2fQ1wN4yw8AfjK2pjuimGiAc/nBdImtsQv40j01DoHs2d016v0GGoGwYse/GenCuD AYsUuenQM4aYrMz01VFAsnNjn3jpMJ+qvoPi8k6khsYaHW5T+gzJOZ7Yj/wi4QeJ4pv1 qDEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bL+6TpNk; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a170902d50900b001614cd997a6si20367588plg.481.2022.11.02.16.20.23; Wed, 02 Nov 2022 16:20:36 -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=bL+6TpNk; 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 S230274AbiKBXTn (ORCPT + 99 others); Wed, 2 Nov 2022 19:19:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbiKBXT0 (ORCPT ); Wed, 2 Nov 2022 19:19:26 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9010421AC for ; Wed, 2 Nov 2022 16:19:20 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id t3-20020a170902e84300b00186ab03043dso206376plg.20 for ; Wed, 02 Nov 2022 16:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=Pm9EI+cM+5edeoncgirJOK1OjdMfit/iE/V7h68jiBA=; b=bL+6TpNkM7xunyoG+gMR3bDhbv+lOJER+h6vrXBg2jRt79YqAlbOV3s6/VQkeIpj52 Ky1J7zaHaUxciHs2i3/MW5CLnr8pffu2zrCWdSsWEvN6vkqzU4pIQp/Uj0gPLK6GDxI3 GXoAw0QLp0yQS3/DSHQFoQOG98RSEwY0diep14lnnAfxj0vljm9xePUY2AEeRFGvmBXm tRsmblxsjx3f7i/4+Y9GUkzbutc8U0tSPE9xz/PT80Ld6mJSu9LlyVnSoU2uILnp4M37 3H0YxDU1PZnTyFdDu6Y+lDm6+PExiZVQW1JgbUHVisjW0UqEwp57euCcN8FduUynf2n5 u4Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pm9EI+cM+5edeoncgirJOK1OjdMfit/iE/V7h68jiBA=; b=Cc/wObhqAqSUUuzVuENUPd9GJZwV/5ayjaGG7omlSOb/DIqh2nbBnnTjbjstO5RuMj kCIX3VSrnAmjt2ckCt63I8C/L2k8C7v8bWTAf1OVGmLu7KWL4+pOQs67g8upFcAMO5Rb cMTnCg9EiXt3r3ujSjwOZpXp+y2eReaoblBbmWZA2nXwhcQnMYUUpfv6G8acxn0NhbtC u0cmoZjo7sMtXTJ0qrPA1IOyhUuyUIK7UxSpw66CfJpjRB5JsF7YolmglGeLfzy9KWHX UbfMdmoWXQNGbxBkSVlw4oOEud5GM7I8HWJ6JUm/5xzlg25rFC21iP+DDXIRwMW5lKBa Ij5Q== X-Gm-Message-State: ACrzQf2TwBY7CGgVpMTCZPOOUnbf2eospR2hGJtpsVL/SygqnWVtsGBC 38na3fpEnhcNH1Azz4RWJrgMCOHlFSc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a62:3281:0:b0:56d:385:149b with SMTP id y123-20020a623281000000b0056d0385149bmr27381564pfy.29.1667431159662; Wed, 02 Nov 2022 16:19:19 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 2 Nov 2022 23:18:30 +0000 In-Reply-To: <20221102231911.3107438-1-seanjc@google.com> Mime-Version: 1.0 References: <20221102231911.3107438-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221102231911.3107438-4-seanjc@google.com> Subject: [PATCH 03/44] KVM: Allocate cpus_hardware_enabled after arch hardware setup From: Sean Christopherson To: 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 , Vitaly Kuznetsov 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, Isaku Yamahata , Fabiano Rosas , Michael Ellerman , Chao Gao , Thomas Gleixner , Yuan Yao X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748428376141325932?= X-GMAIL-MSGID: =?utf-8?q?1748428376141325932?= Allocate cpus_hardware_enabled after arch hardware setup so that arch "init" and "hardware setup" are called back-to-back and thus can be combined in a future patch. cpus_hardware_enabled is never used before kvm_create_vm(), i.e. doesn't have a dependency with hardware setup and only needs to be allocated before /dev/kvm is exposed to userspace. Free the object before the arch hooks are invoked to maintain symmetry, and so that arch code can move away from the hooks without having to worry about ordering changes. Signed-off-by: Sean Christopherson Reviewed-by: Yuan Yao --- virt/kvm/kvm_main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e0424af52acc..8b7534cc953b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5843,15 +5843,15 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, if (r) return r; + r = kvm_arch_hardware_setup(opaque); + if (r < 0) + goto err_hw_setup; + if (!zalloc_cpumask_var(&cpus_hardware_enabled, GFP_KERNEL)) { r = -ENOMEM; goto err_hw_enabled; } - r = kvm_arch_hardware_setup(opaque); - if (r < 0) - goto out_free_1; - c.ret = &r; c.opaque = opaque; for_each_online_cpu(cpu) { @@ -5937,10 +5937,10 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, unregister_reboot_notifier(&kvm_reboot_notifier); cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING); out_free_2: - kvm_arch_hardware_unsetup(); -out_free_1: free_cpumask_var(cpus_hardware_enabled); err_hw_enabled: + kvm_arch_hardware_unsetup(); +err_hw_setup: kvm_arch_exit(); return r; } @@ -5967,9 +5967,9 @@ void kvm_exit(void) cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING); on_each_cpu(hardware_disable_nolock, NULL, 1); kvm_irqfd_exit(); + free_cpumask_var(cpus_hardware_enabled); kvm_arch_hardware_unsetup(); kvm_arch_exit(); - free_cpumask_var(cpus_hardware_enabled); kvm_vfio_ops_exit(); } EXPORT_SYMBOL_GPL(kvm_exit);