Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1783769rwi; Thu, 3 Nov 2022 09:02:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fokHJrLfisG7IY7aSWe5sxcLyKlDCosuEniV2Ao4PAUvNvT0X14q2tKxMXd2KyxqDJZyq X-Received: by 2002:a50:ec0a:0:b0:461:c0ca:a0bc with SMTP id g10-20020a50ec0a000000b00461c0caa0bcmr30991204edr.306.1667491360371; Thu, 03 Nov 2022 09:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667491360; cv=none; d=google.com; s=arc-20160816; b=ZaQTlZlr2Jw4y/Oei+AO35xEtGCcoxZrouNe39pdVv1SeionwGSlxPE82u+S/fHU68 k0/ZPX//QXlN9WrO5HUNhwkslul54FidSeh8vptaD+WFYgbJjnut3rxQivaeBGqo1JjL D3U80jhuf4papyoxVm1mFWefrxJLHj9An3pfJb3gs1IkgIzbPn/Q/C2TFOTFPFtLpN2Q EVsPO//ASbQCd8f6OcOQ2yDqQ48AIMoiT5zGGcJokYvSln1loFYhHN9PomJovGhShWwA wuIoyJqI9r/DMADZFa8eaZzDSJeemVbZELb5avLlW2B5rzi2SLDoBRKskLUIH0X1iHVc +N2w== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UyUe+HbRzSrTdJquQCMiaXWC2coZG28I37xguDaJaYg=; b=d+6hkDiTStIt1NNalZWelb18F1YyTeHgliosJtR1dXvf020/D/nh3xS6K5VO1vuG5y UdW44vQHcwWMirU7//1HRxVmb1Oai1a8NhMxHVVbBHiNTpjn+1CJi4ydbKHZO9ZPaJHF xZCQNhyz5ysqOdRlNSXE8WlAjYZgQbId5zcv/kLSHhy915gBYqtRTicGtl5WKdFQBuLI xDtEDm0X+Koq3v9ULVWpexiMU4NRr7qPoHONKklRn+oxr9cVMFdBu7kETw9Fv0bmSyc0 vVpvK4TwP5x16ZM3dMp+F6ESvhq6X7pwVzbiEptKV+WLHaHhBvWJG2gMRiWUF7gKm3nQ HqsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JxP3em5m; 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 c11-20020a05640227cb00b00461a144e980si2053095ede.379.2022.11.03.09.02.00; Thu, 03 Nov 2022 09:02:40 -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=JxP3em5m; 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 S231460AbiKCPaz (ORCPT + 97 others); Thu, 3 Nov 2022 11:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231491AbiKCPae (ORCPT ); Thu, 3 Nov 2022 11:30:34 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B90581C43B for ; Thu, 3 Nov 2022 08:30:02 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id q1so1946271pgl.11 for ; Thu, 03 Nov 2022 08:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=UyUe+HbRzSrTdJquQCMiaXWC2coZG28I37xguDaJaYg=; b=JxP3em5mMEo8M/seyYjwqQClKWueZhrkefM7iopEbtJ9U0ARhXsBBlBaHvB0YZ+mCq 7I2lDIbzgsTnUJXXFFd+Mf2MRkvMQ3d/mi120+0k+co+feliF2fGnlDGLipP3oo4jHIs yhCQnzB0LNdLsoCiyP2ThdGCDug/wevVBzx4ZCIoRVJzM62ULFanZrMyKnrfoLhgGw7L LE3NJVvLI80qGdb5QUdNBUYtcEfD6sTxNonp/rLGuh5no7R8ACiBwreWQkoFJnyoE1Nq joZ/uzznkWHqO7mwwbSR52gm1kYa+vf+hliw2Y9f1o05+cN6N5swUWJ7vJszMr5BEKoW HTcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding: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=UyUe+HbRzSrTdJquQCMiaXWC2coZG28I37xguDaJaYg=; b=0XKmf2yWKqvEV7/KwfkZmUBOc7XUtBY+RVQviavtZS7IlDBV+iuE4v55OZ2X/OpS/3 zVTgby9qRGw66KBobMhIoBE4UmbKNyWKlBww7Kny9bun2nMNpTyVvXgnEjCxBkaSRm50 1k6xclwpqTqfYa3aCACbU9+BewLOQOxqoBSV/jz6TGEgVXRI3GDEpsXe6PpwEmLcNbRe icPsIvaUZsbTb7V7Hm4GaTYq0jmw7APNT33HicYokmiE1ApcfJR6Etj+QoMQOuReLBrT AHVsBKbIgMEpIkiK4iBsrWDf6y7I9cexGhc0WQLcOYsWgaWV4NWWBZxwumLnKf5/H2cA dc2g== X-Gm-Message-State: ACrzQf0bBXfRjkCVYYn6oOLOeUNMfITi1rGF3QQKDCyinyzLmTqQcbJ2 5ssLXaAgAL9Lsfn4H2QiAj2IHg== X-Received: by 2002:a05:6a00:1996:b0:56d:a845:5789 with SMTP id d22-20020a056a00199600b0056da8455789mr17697890pfl.59.1667489402026; Thu, 03 Nov 2022 08:30:02 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id f3-20020a170902f38300b0017a018221e2sm835452ple.70.2022.11.03.08.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 08:30:01 -0700 (PDT) Date: Thu, 3 Nov 2022 15:29:58 +0000 From: Sean Christopherson To: Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= 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 17/44] KVM: arm64: Do arm/arch initialiation without bouncing through kvm_init() Message-ID: References: <20221102231911.3107438-1-seanjc@google.com> <20221102231911.3107438-18-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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=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 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 > > --- > > 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.