Message ID | 20221102231911.3107438-18-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp199877wru; Wed, 2 Nov 2022 16:22:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7pzEaCtCtZXEO315Pfo8tePc2hYhA6PeuoM96Yv50so2aNXWqiH0DY0vJav4vAM4ef+4mQ X-Received: by 2002:a63:2125:0:b0:3c2:1015:988e with SMTP id h37-20020a632125000000b003c21015988emr23636513pgh.280.1667431347333; Wed, 02 Nov 2022 16:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667431347; cv=none; d=google.com; s=arc-20160816; b=lqKgtwS8jAA52BR1vMZzGf91eqrniO+r+rA+k9lSd1n51nQbduRHoBcLTByXDAnIho v5olnGvzWTPzfimk9mDavN3tjuvGRvHydDolh3RIIY+pga4d+hEDiX6SwMSxXFmf2zU0 MwAnWEFLHtVj0ez1tsQdgtFol7JpShAHvoDm6sJiBCAj5+JOoeyDTQSk6Ciy/7SZTwCX R+/9WlwruqaOiG6L4Lgwb/cesDnf78TNWh6maA1NPXxXsVjjI+s5ZRbb/9KnA+ph5rpW Riup/ylh2oe6U3i1/2OAyFF1YYgx/QD8HId/vpR+FBIAjOb4Z8i2V6QGiKUlPq/ElkKa TzJg== 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=KSp9zIzHXrxcJceHX59wYlpimn2+3DBl6/EkdM22YDo=; b=CUpJnV2SxNFGI+REVR4fD0BTPTEGGHF5vD2WauEwIrw3afdHcX+5LHB1NEE/6oncZ5 v7+XgbcJ2gDe/u32ufIeTnZLXF7wmrODHdYS3a0bGhPeYflREAcZKvIbqmksgTYx8p43 pkGFSiDmfR3yX5+ASPbTwlCJg8JHLDGPHxFLNpUpIY5qxAotRqPs0fADZNGKE0lRQKLZ 7DTctHGMtM7nY8A0pdt907JcnsALKcFeG5Wasduf0gwoPK4e7D87jAOmpBmSoIWBJpGD nQJM3zevtb38win8EHfrezx20EwEHFLwS6Yfn5JWHXkIKV0Vy3tbp6lqCp8J3UPIPll4 qDwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GazJIJPM; 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 i9-20020a17090332c900b0017bdf43925dsi15102380plr.580.2022.11.02.16.22.14; Wed, 02 Nov 2022 16:22:27 -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=GazJIJPM; 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 S230527AbiKBXVQ (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Wed, 2 Nov 2022 19:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbiKBXUO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Nov 2022 19:20:14 -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 373455F79 for <linux-kernel@vger.kernel.org>; Wed, 2 Nov 2022 16:19:43 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id t3-20020a170902e84300b00186ab03043dso206947plg.20 for <linux-kernel@vger.kernel.org>; Wed, 02 Nov 2022 16:19:43 -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=KSp9zIzHXrxcJceHX59wYlpimn2+3DBl6/EkdM22YDo=; b=GazJIJPM/pHmiFZ05wEIEUmIWAlYuh2ZlyTopcNekluhV4UHGi1yTDkMNANFS1jscV sHaoW06GH/7QoV/u1MZ9MSnC1FGAiLQO/y23W8/5eah4jm88WvvNxPaF2O5WlqNX6AA2 8Gs4UT7UUi7/ZwHf5DCZWbM2vulQhHbwn2WtGD6rJzl/FOBfxZ8G3NM+geD74+eDAUum o1o3demNZa7SFz5SsAwJ7XKog0NdlraaEfYhRzZpffEE3gOpiTfLkShIIvuV3L13yEjN xam914sm21iReYi10+r23ej5bJnTbIKx2d2irwZwjp5ibbzs0gCmvLJoawOipg8dYos5 2Zgg== 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=KSp9zIzHXrxcJceHX59wYlpimn2+3DBl6/EkdM22YDo=; b=7P50vtmJ02ANSZye/08/bsvAe/KjipuyyzXb4/UjuqmWdp0y/jP9vwEBZSSYbiYHyI +12F3reLPE7Q+PCt5w6EA+hB3YTVsqBHrHXcpLrI0+FMfxQKVIVQHYsCWf6m6ISw6J5I BbTrxRJ7tkcOSHXDivRcgljmvrixBmFsK4ZPRDwVXlHj3hYIzFCMOCPnFJTvAo3Zgbmr pCsnOO4ybFVErEsYMTJL5kGnhhCYxXsbD7h4PbPMVAc63bR7nNyBIJvk34Gq2Yyj+DOM SehyAxv87vBHJwALt2l4+iOKRCgjNwv6pDBYp5J0YN2m9YwBfIlbiRqdx55OsovmzdPW yfdg== X-Gm-Message-State: ACrzQf1wYWuqwrcsDUezv614yzNRnfz+I3Gnt785jAOsiDUV6PtWYLMJ EcqZTtyTSZ/kdhlTmuWobdSxU2pooSM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:e0b:b0:56c:8c13:2a54 with SMTP id bq11-20020a056a000e0b00b0056c8c132a54mr27442020pfb.17.1667431182821; Wed, 02 Nov 2022 16:19:42 -0700 (PDT) Reply-To: Sean Christopherson <seanjc@google.com> Date: Wed, 2 Nov 2022 23:18:44 +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-18-seanjc@google.com> Subject: [PATCH 17/44] KVM: arm64: Do arm/arch initialiation without bouncing through kvm_init() From: Sean Christopherson <seanjc@google.com> To: Paolo Bonzini <pbonzini@redhat.com>, Marc Zyngier <maz@kernel.org>, Huacai Chen <chenhuacai@kernel.org>, Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>, Anup Patel <anup@brainfault.org>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Christian Borntraeger <borntraeger@linux.ibm.com>, Janosch Frank <frankja@linux.ibm.com>, Claudio Imbrenda <imbrenda@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Sean Christopherson <seanjc@google.com>, Vitaly Kuznetsov <vkuznets@redhat.com> Cc: James Morse <james.morse@arm.com>, Alexandru Elisei <alexandru.elisei@arm.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Oliver Upton <oliver.upton@linux.dev>, Atish Patra <atishp@atishpatra.org>, David Hildenbrand <david@redhat.com>, 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 <isaku.yamahata@intel.com>, Fabiano Rosas <farosas@linux.ibm.com>, Michael Ellerman <mpe@ellerman.id.au>, Chao Gao <chao.gao@intel.com>, Thomas Gleixner <tglx@linutronix.de>, Yuan Yao <yuan.yao@intel.com> 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=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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748428492377632685?= X-GMAIL-MSGID: =?utf-8?q?1748428492377632685?= |
Series |
KVM: Rework kvm_init() and hardware enabling
|
|
Commit Message
Sean Christopherson
Nov. 2, 2022, 11:18 p.m. UTC
Move 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(), i.e. this is a glorified nop.
Making kvm_arch_init() a nop will allow dropping it entirely once all
other architectures follow suit.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/arm64/kvm/arm.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
Comments
Hi Sean, On 3/11/22 00:18, Sean Christopherson wrote: > Move 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(), i.e. this is a glorified nop. > > Making kvm_arch_init() a nop will allow dropping it entirely once all > other architectures follow suit. > > No functional change intended. > > Signed-off-by: Sean Christopherson <seanjc@google.com> > --- > arch/arm64/kvm/arm.c | 25 ++++++++++++++++--------- > 1 file changed, 16 insertions(+), 9 deletions(-) > /* NOP: Compiling as a module not supported */ > void kvm_arch_exit(void) > { > - kvm_unregister_perf_callbacks(); Doesn't this belong to the previous patch? > + > }
On Thu, Nov 03, 2022, Philippe Mathieu-Daudé wrote: > Hi Sean, > > On 3/11/22 00:18, Sean Christopherson wrote: > > Move 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(), i.e. this is a glorified nop. > > > > Making kvm_arch_init() a nop will allow dropping it entirely once all > > other architectures follow suit. > > > > No functional change intended. > > > > Signed-off-by: Sean Christopherson <seanjc@google.com> > > --- > > arch/arm64/kvm/arm.c | 25 ++++++++++++++++--------- > > 1 file changed, 16 insertions(+), 9 deletions(-) > > > /* NOP: Compiling as a module not supported */ > > void kvm_arch_exit(void) > > { > > - kvm_unregister_perf_callbacks(); > > Doesn't this belong to the previous patch? No, but the above changelog is a lie, there is very much a functional change here. The goal of the previous patch is to fix the error paths in kvm_arch_init(), a.k.a. kvm_arm_init(). After fixing kvm_arch_init(), there are still bugs in the sequence as a whole because kvm_arch_exit() doesn't unwind other state, e.g. kvm_arch_exit() should really look something like: void kvm_arch_exit(void) { teardown_subsystems(); if (!is_kernel_in_hyp_mode()) teardown_hyp_mode(); kvm_arm_vmid_alloc_free(); if (is_protected_kvm_enabled()) ??? } Becuase although the comment "NOP: Compiling as a module not supported" is correct about KVM ARM always having to be built into the kernel, kvm_arch_exit() can still be called if a later stage of kvm_init() fails. But rather than add a patch to fix kvm_arch_exit(), I chose to fix the bug by moving code out of kvm_arch_init() so that the unwind sequence established in the previous patch could be reused. Except I managed to forget those details when writing the changelog. The changelog should instead be: KVM: arm64: Do arm/arch initialization without bouncing through kvm_init() 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.
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index f400a8c029dd..bfa2dcd3db11 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -2190,7 +2190,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; @@ -2264,6 +2264,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: @@ -2276,10 +2284,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) @@ -2320,10 +2333,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);