Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3116336rwb; Wed, 30 Nov 2022 15:48:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GlnsT67KEAEA2hOFywXmPzNEeWcheEVcJRaNYAJn0dqMp6GgMv2JQZq+qvgGNNTisfsHm X-Received: by 2002:a17:902:b189:b0:189:396f:7c43 with SMTP id s9-20020a170902b18900b00189396f7c43mr41718876plr.13.1669852125637; Wed, 30 Nov 2022 15:48:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669852125; cv=none; d=google.com; s=arc-20160816; b=jcbTCAIig3wzfQlTWs1NZMPQuMiZ1y4IHOpeTy+hhv2Ne1brQdeNb2BD8Em3AiC3og h77MUoo6ZZSKc4hoYGcH7jmV3VxIQc0d3+mGcy6A6Rnigw9bGgGQ6YN+QVztrpdBJ7V6 MnTfhE+40IltKQY0htceI3X67SW2fQ4dXc8zFa+Ml6mJDS9PCRXsLhBhjiDzXAes6+92 xPY65FqbpUDxkkPbAr+Miuxz//Lws5weTP31KbwsNbnoSLzowox5JYDu2fOi/W/bxvwa sPKNzFdwubc7m74gpOIbKhogU6pfu/pAZ/L9yo2MDR3253UIxsJChN3pKWLBbGfn23Xb 4/fQ== 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=3q8g1I3CG/zN/S6yfEuz3UEYEnVKGNtIkvlUCCz4wMk=; b=JLejXxs3gvrp79jA4KyHbrNrZWUTaxo2XKaYrQOMaADhdahuJEBFNwndmpLNRtqRPS f/+RJgpDGZEvrbUTqiL+utAUBaJIxTd7lghOqWb3lC0lGN/nUAX/gvuFyGXxMfBw2Mqf 8XSSvUmDR/4ThextRBHKbs8WwKKxm9zPqSRFW01swoULnQcEwcCeU9e2Zrx2K7w8l36b ip/4vrkplB6IOFyHFZUE2ryLmnqMUTLhWUgZp2MtCKLT2VLfcWQpclRKcdZIs7fII+nT Ab9xG6gJnCRCsKlTUjLEzGD2CHz3NLbxtoll868elLpwsWV3/6qMZCGt+iiS2nU/6wzY TC1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IzqZX1vp; 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 z70-20020a633349000000b00476f8b57e45si2596757pgz.61.2022.11.30.15.48.34; Wed, 30 Nov 2022 15:48:45 -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=@google.com header.s=20210112 header.b=IzqZX1vp; 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 S229969AbiK3XNA (ORCPT + 83 others); Wed, 30 Nov 2022 18:13:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbiK3XMD (ORCPT ); Wed, 30 Nov 2022 18:12:03 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B9629AE29 for ; Wed, 30 Nov 2022 15:10:28 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id m2-20020a17090aab0200b002188c801f92so169155pjq.4 for ; Wed, 30 Nov 2022 15:10:28 -0800 (PST) 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=3q8g1I3CG/zN/S6yfEuz3UEYEnVKGNtIkvlUCCz4wMk=; b=IzqZX1vpqBRD6eqp/m2lCIonVBr9d0e0dYh+rnORdsBouvRr/LJHoAVFCGYwduLpYW OTMMo4gprlzO/u6ojuhJyOc3wk8iW8vMqSUKMIfurZ/dESMUEks0XD0dELDo/XLaovGl EKo5NrbtnviyIeCdpV2+U1bLcQY9lYskXKPUNJWsxtd+ecYNZC7sEQkVg+anA/T0XgVe YvNoKh5i6BiC33HYuQOVTGAT9N1QTpRLVSSatOGlZCfv03s8ZzOwEte840f58eQcGUDe h1+xBUE24TMAZ61kNCycVQsK/JxxPJO1UMM34/IR0XeCfuqHb2uwlievzCRoo9MRdbjv 0jwg== 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=3q8g1I3CG/zN/S6yfEuz3UEYEnVKGNtIkvlUCCz4wMk=; b=hpeqr39wyJ3xo+HMCZDpF3exqi2aBpd2f++XWGseOlk/Ovz/0tV5vQvNQjvXxwYw/V MY4Io5rvnURn9e4MyiRymK//9x/SKEZRwk3O2JcqsZqW8i/TIjddWGEZh4zz0jtlzA22 dEnRMC2Ax+J6OOO+uvdIyR29N3WguZbHSlycy+OJ5nC3WHB/NvIpY5EmGiUDXSK8bNbV SVjMMfNF8KpkLATG49ent3ikexrOP6+83ZRZsNQIxj9XH3orP4FZElhjPlBfjJkH7M4z yV/70Xj92NGbEeHPdHBNuVGY12EMhSYq3ee9KmSzSK3htIZg+ws+WeHtI55uOkRxq2uC 9dzw== X-Gm-Message-State: ANoB5pnk1tQflqNgokz/UcEgyocTW4J0d6VVJEJPabBF/l5CsCRwrzzh srmZ+Qm+jOJEGQdATZbBXO/ziIOky2s= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:aa7:8bc1:0:b0:575:bfb9:b1fa with SMTP id s1-20020aa78bc1000000b00575bfb9b1famr7674415pfd.62.1669849810052; Wed, 30 Nov 2022 15:10:10 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 30 Nov 2022 23:09:03 +0000 In-Reply-To: <20221130230934.1014142-1-seanjc@google.com> Mime-Version: 1.0 References: <20221130230934.1014142-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221130230934.1014142-20-seanjc@google.com> Subject: [PATCH v2 19/50] KVM: arm64: Do arm/arch initialization without bouncing through kvm_init() 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 , David Woodhouse , Paul Durrant 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 , "=?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?=" , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" 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 Do arm/arch specific initialization directly in arm's module_init(), now called kvm_arm_init(), instead of bouncing through kvm_init() to reach kvm_arch_init(). Invoking kvm_arch_init() is the very first action performed by kvm_init(), so from a initialization perspective this is a glorified nop. Avoiding kvm_arch_init() also fixes a mostly benign bug as kvm_arch_exit() doesn't properly unwind if a later stage of kvm_init() fails. While the soon-to-be-deleted comment about compiling as a module being unsupported is correct, kvm_arch_exit() can still be called by kvm_init() if any step after the call to kvm_arch_init() succeeds. Add a FIXME to call out that pKVM initialization isn't unwound if kvm_init() fails, which is a pre-existing problem inherited from kvm_arch_exit(). Making kvm_arch_init() a nop will also allow dropping kvm_arch_init() and kvm_arch_exit() entirely once all other architectures follow suit. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/arm.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e6f6fcfe6bcc..d3a4db1abf32 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -2195,7 +2195,7 @@ void kvm_arch_irq_bypass_start(struct irq_bypass_consumer *cons) /** * Initialize Hyp-mode and memory mappings on all CPUs. */ -int kvm_arch_init(void *opaque) +int kvm_arm_init(void) { int err; bool in_hyp_mode; @@ -2269,6 +2269,14 @@ int kvm_arch_init(void *opaque) kvm_info("Hyp mode initialized successfully\n"); } + /* + * FIXME: Do something reasonable if kvm_init() fails after pKVM + * hypervisor protection is finalized. + */ + err = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); + if (err) + goto out_subs; + return 0; out_subs: @@ -2281,10 +2289,15 @@ int kvm_arch_init(void *opaque) return err; } +int kvm_arch_init(void *opaque) +{ + return 0; +} + /* NOP: Compiling as a module not supported */ void kvm_arch_exit(void) { - kvm_unregister_perf_callbacks(); + } static int __init early_kvm_mode_cfg(char *arg) @@ -2325,10 +2338,4 @@ enum kvm_mode kvm_get_mode(void) return kvm_mode; } -static int arm_init(void) -{ - int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); - return rc; -} - -module_init(arm_init); +module_init(kvm_arm_init); -- 2.38.1.584.g0f3c55d4c2-goog