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 C3033C3DA4A for ; Thu, 1 Aug 2024 20:10:25 +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=FmPXYb3LgE4pgICuxW8Y3uEaHXTH9vxvxhXRG1o8kBU=; b=igv67iteqvt3YMUp04u9n2Hapf PrP1J1fXmv9tR0teP4FpGrycPaoDZpTpCTembG/wsVdslhBvwwfbuAjDnRQx44Dtne8xkeAKH927N MTjuaWIJxxXGU0V4vgc+3YOwKQqhHGNPqJoT8Buk1k4V+VhpXK9YfChUYAqNeD+eA/wMMDNgjoqj2 6pZvvPnBhyMxZ+l7NDC0KK2UTpl42BkvVbcKT0v/93q0NmY/eF6IDGzLBDuxIiSIDgMsRgGpzfxFm GmwmAbt1rOItuTjNtoBSFkY5ouT4/2RHzD1iMBjLoOTBUB0GDYhClJTugiltvAqzlsOlJBhOJiSQO iIh9S+DQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZc7q-00000006caa-4715; Thu, 01 Aug 2024 20:10:14 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZc7N-00000006cWn-0DqA for linux-arm-kernel@lists.infradead.org; Thu, 01 Aug 2024 20:09:46 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E972E609E9; Thu, 1 Aug 2024 20:09:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98FF3C32786; Thu, 1 Aug 2024 20:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722542983; bh=OwYu5izJDFdDC+bLnsi3uCpm9R42AT+Pbfnx3S5QwQM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=uaVf5YoABf0g2ST3gdEk0dpt7BoxwNuIEY/0zP1fW/FGIy60R3suuFjO0pV9EWr+S h7aul0S6c9EoIbCuci93a57vCwekSVnp6DHoKE/j1TeN0QXJdEV2c5mlIrxt+ImR7e rdlIAtAvWskSTzSvBr+uI8Q3SaE46Q4EIMGkWuIdKoRFIMkhlbPycfYdJ8Yrv7de0y x6OFszzF9iCF8fye8rYN0Fi5OK4BgS5/hyV2NF5WaO6SQzWP7YT4HLwbYLTYgitOiI zz/eP+3ylgjHgP/zWwk+DFo8qouevFPkXwey347Yfv1MaSxmYDKb8MRQySv4vRe9aJ ptSQxH05hkPfA== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.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 1sZc7I-00HW3I-VZ; Thu, 01 Aug 2024 21:09:41 +0100 Date: Thu, 01 Aug 2024 21:09:40 +0100 Message-ID: <87ttg43szf.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Fuad Tabba , Joey Gouly Subject: Re: [PATCH v2 4/8] KVM: arm64: Add save/restore support for FPMR In-Reply-To: <1a00165f-7ae5-4c58-9283-836716205db7@sirena.org.uk> References: <20240801091955.2066364-1-maz@kernel.org> <20240801091955.2066364-5-maz@kernel.org> <1a00165f-7ae5-4c58-9283-836716205db7@sirena.org.uk> 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/28.2 (x86_64-pc-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: broonie@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, tabba@google.com, joey.gouly@arm.com 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-20240801_130945_197706_4C9D62DF X-CRM114-Status: GOOD ( 23.64 ) 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 Thu, 01 Aug 2024 20:07:16 +0100, Mark Brown wrote: > > [1 ] > On Thu, Aug 01, 2024 at 10:19:51AM +0100, Marc Zyngier wrote: > > > index 6af179c6356d..2466dd231362 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/switch.c > > +++ b/arch/arm64/kvm/hyp/nvhe/switch.c > > @@ -198,6 +198,15 @@ static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu) > > } else { > > __fpsimd_save_state(*host_data_ptr(fpsimd_state)); > > } > > + > > + if (kvm_has_fpmr(vcpu->kvm)) { > > nVHE is faulting for me, apparently on the kvm_has_fpmr() check though I > ran out of time to actually figure out where exactly it is going wrong. > I'll have a further poke tomorrow. Backtrace below. Well, that's actually pretty obvious when you see the crash (FAR:ffffff880115cd1c spills the beans). > > > + u64 fpmr = read_sysreg_s(SYS_FPMR); > > + > > + if (unlikely(is_protected_kvm_enabled())) > > + *host_data_ptr(fpmr) = fpmr; > > That looks wrong until you remember what host_data_ptr() does but but > it's actually fine. host_data_ptr() is looking inside the struct > kvm_host_data for the CPU rather than referencing the locally defined > variable fpmr here. I do think it's worth avoiding the name collision > though, perhaps just avoid the temporary variable? I'll rename the variable if that avoids people getting their brains in a twist. Full potential fix below. Thanks, M. diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 2466dd231362..c0832ca0285b 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -199,13 +199,13 @@ static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu) __fpsimd_save_state(*host_data_ptr(fpsimd_state)); } - if (kvm_has_fpmr(vcpu->kvm)) { - u64 fpmr = read_sysreg_s(SYS_FPMR); + if (kvm_has_fpmr(kern_hyp_va(vcpu->kvm))) { + u64 val = read_sysreg_s(SYS_FPMR); if (unlikely(is_protected_kvm_enabled())) - *host_data_ptr(fpmr) = fpmr; + *host_data_ptr(fpmr) = val; else - **host_data_ptr(fpmr_ptr) = fpmr; + **host_data_ptr(fpmr_ptr) = val; } } -- Without deviation from the norm, progress is not possible.