From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BD902DFA58; Tue, 15 Apr 2025 18:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744741347; cv=none; b=HGBdyLN4uPO/8lzVy3RhT3vMmRo9i5z27fC+1PShX+KVyhr7iN2WU15I1PSGrDA6IMQ14TRttrf/9VcSvwr/ar//l6ZFuBNa6fmCdB2WGMQkVHXXxHoJTC+dCX0quDSRN+uzS2IR2fmMBjanK6RA74fQfFEw7tKvFfs6ozRMTzE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744741347; c=relaxed/simple; bh=UWX6Vcwyw+Ws40wGd9jaKNvjYbvPvr9pzOB5xOkPvO4=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=cx1a2q3up8aQmbThEerftLC6Jgcm3K2GUBQahNQWAugbMUSejFJ0I+WLJ/+/DbvD6axt0Rm4FykVxV6jOWqjntytRFFVLpXQPQyuAiyprGTAJLCmqRsSV8uvdwLjW3Rj63AbTuOChXxi9yK4rqNXr/O8N0pYydQ8cLYTCGWtZRc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pvcLr1TJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pvcLr1TJ" 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.