From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8134C369AB for ; Tue, 15 Apr 2025 18:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vHMExLZbFqlkwUCb5LIvhlW4hrlU8+KrTq+VpJ9MT9E=; b=wx3lBkiVra2o41hqSW5XoLcY5p Bf1YCYfMbtx3iaxhRzaLD3JGcEARnVpWu94WZ9YZmB3yIZEscvTxwObKnWY2e/S9ZERg1mvc+6usH PEbDJm/xY5icGL+P8Ojh0YCu9bqbCNm/A0JHNSY/Twt55zI3GQyP7QLTOKwhlJb3ghOLZEzeO6wjx jX02+GtifTdjXphS6T6cMSjZbC/JbZ7nJXMOzjDtGnDA/vbWe2ili2tVgEtb4kOstV9igNOktgNF1 YXxOdwqf2JGbRSqR8FT6knFnuNeGnApokh1P9N9cf/MR7rhIRtJFL578mSRL3hWCCmwqBC+CY7Etm nGbwjUHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4kxI-00000006iO0-269p; Tue, 15 Apr 2025 18:24:20 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4kvT-00000006i15-2PLi for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 18:22:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id CCDB643B8F; Tue, 15 Apr 2025 18:22:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A76A1C4CEE9; Tue, 15 Apr 2025 18:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744741346; bh=UWX6Vcwyw+Ws40wGd9jaKNvjYbvPvr9pzOB5xOkPvO4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pvcLr1TJj/oy3nrWWBYkW6Q/JEbATM2Sba8BrbXR3u0jZPmM2gInlFRGC5zd9riYT 5Tf/SeNpCqoh6xEXqoGpv+IVialYCEnqsQSaN2rebfmBk3OslmzLcJUp46P4oJfcZW NuQ7wF/elMEmE1KsIDDd3sG86Kgps9gnw5LmERQZho2c3ZaPp7PH30CScjFRKH9R1f hEnwGp88Q4+EPi7GKNkJr982e64iSt7/ABXNNdOc5kxkxmwQr+VrVHajN/MYou7xzv 5c6uVKO8fBrrP72253opO+rGAlJv1wumwCORJNC222AGpWRQn2MHkcdM3+WOdTGGv/ slguT5437mVug== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1u4kvQ-005mF3-2x; Tue, 15 Apr 2025 19:22:24 +0100 Date: Tue, 15 Apr 2025 19:22:23 +0100 Message-ID: <8634e9l1y8.wl-maz@kernel.org> From: Marc Zyngier To: D Scott Phillips Cc: Catalin Marinas , Joey Gouly , Oliver Upton , Suzuki K Poulose , Will Deacon , Zenghui Yu , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] KVM: arm64: fix config.hcr used uninitialized in __kvm_at_s1e01_fast In-Reply-To: <20250415154656.1698522-1-scott@os.amperecomputing.com> References: <20250415154656.1698522-1-scott@os.amperecomputing.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: scott@os.amperecomputing.com, catalin.marinas@arm.com, joey.gouly@arm.com, oliver.upton@linux.dev, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250415_112227_655227_2FFD6CA1 X-CRM114-Status: GOOD ( 26.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 15 Apr 2025 16:46:55 +0100, D Scott Phillips wrote: > > In the skip_mmu_switch case, config.hcr was used uninitialized. On my > machine that caused garbage to be written to HCR_EL2 and then the CPU > got stuck at the synchronous exception handler. Also, the restore of > HCR_EL2 was missing at the end of the function in the same case. Huh, how embarrassing. Thanks for spotting this one. > > In skip_mmu_switch case, initialize config.hcr with HCR_HOST_VHE_FLAGS. > > Signed-off-by: D Scott Phillips > --- > arch/arm64/kvm/at.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c > index f74a66ce3064b..ff4b06ce661af 100644 > --- a/arch/arm64/kvm/at.c > +++ b/arch/arm64/kvm/at.c > @@ -1233,8 +1233,10 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) > * the right one (as we trapped from vEL2). If not, save the > * full MMU context. > */ > - if (vcpu_el2_e2h_is_set(vcpu) && vcpu_el2_tge_is_set(vcpu)) > + if (vcpu_el2_e2h_is_set(vcpu) && vcpu_el2_tge_is_set(vcpu)) { > + config.hcr = read_sysreg(hcr_el2); > goto skip_mmu_switch; > + } > > /* > * Obtaining the S2 MMU for a L2 is horribly racy, and we may not > @@ -1299,7 +1301,9 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) > if (!fail) > par = read_sysreg_par(); > > - if (!(vcpu_el2_e2h_is_set(vcpu) && vcpu_el2_tge_is_set(vcpu))) > + if (vcpu_el2_e2h_is_set(vcpu) && vcpu_el2_tge_is_set(vcpu)) > + write_sysreg(config.hcr, hcr_el2); > + else > __mmu_config_restore(&config); > > return par; I think the diff below should do the trick (and incidently matches your commit message). Thanks, M. diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index f74a66ce3064b..773e3b4d5c7e5 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -1214,7 +1214,7 @@ static u64 handle_at_slow(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) */ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) { - struct mmu_config config; + struct mmu_config config = { .hcr = HCR_HOST_VHE_FLAGS, }; struct kvm_s2_mmu *mmu; bool fail; u64 par; @@ -1301,6 +1301,8 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) if (!(vcpu_el2_e2h_is_set(vcpu) && vcpu_el2_tge_is_set(vcpu))) __mmu_config_restore(&config); + else + write_sysreg(config.hcr, hcr_el2); return par; } -- Without deviation from the norm, progress is not possible.