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 24D3414AD02; Thu, 1 Aug 2024 20:09:43 +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=1722542984; cv=none; b=YUUhczGYQsx7r6zhhijDhN5/UC3cfc6FhrOMg4hvjBb/mRez5h9dxNEnt0104NoyA1gq1Rm3SWk6eey3JAy9XF4FFiColL3BP4uVebEABblAeGahSyGB/9ccTNvVyL3q7hoj1Fvbzx7eNZPcJent2cHrP07qsTFa4jnXRHBJa9E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722542984; c=relaxed/simple; bh=OwYu5izJDFdDC+bLnsi3uCpm9R42AT+Pbfnx3S5QwQM=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=R8mtWiOOeg9nK82SzDqLYNYOXa+huqdC87wFMthH6x5NpeblbyC6ACLWrTuC3sI+qGw/zKyDSvfEe+4osdO86RpPHMQLZIm6dzwzu/NgYN2lbrMqPTTN4aaZPbCmRUJxh/9RqtNRT/cnJ5zHzClkR0XYo8xHVkCkWCb22V9PHqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uaVf5YoA; 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="uaVf5YoA" 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) Precedence: bulk X-Mailing-List: kvm@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: 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 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.