linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type
@ 2024-11-25  9:47 Marc Zyngier
  2024-11-26 15:27 ` Oliver Upton
  2024-11-26 15:59 ` Oliver Upton
  0 siblings, 2 replies; 5+ messages in thread
From: Marc Zyngier @ 2024-11-25  9:47 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel
  Cc: Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu,
	Alexandru Elisei

The G.a revision of the ARM ARM had it pretty clear that HCR_EL2.FWB
had no influence on "The way that stage 1 memory types and attributes
are combined with stage 2 Device type and attributes." (D5.5.5).

However, this wording was lost in further revisions of the architecture.

Restore the intended behaviour, which is to take the strongest memory
type of S1 and S2 in this case, as if FWB was 0. The specification is
being fixed accordingly.

Fixes: be04cebf3e788 ("KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W}")
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kvm/at.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c
index 8c5d7990e5b31..98cb499fa4b11 100644
--- a/arch/arm64/kvm/at.c
+++ b/arch/arm64/kvm/at.c
@@ -739,8 +739,15 @@ static u64 compute_par_s12(struct kvm_vcpu *vcpu, u64 s1_par,
 			final_attr = s1_parattr;
 			break;
 		default:
-			/* MemAttr[2]=0, Device from S2 */
-			final_attr = s2_memattr & GENMASK(1,0) << 2;
+			/*
+			 * MemAttr[2]=0, Device from S2.
+			 *
+			 * FWB does not influence the way that stage 1
+ 			 * memory types and attributes are combined
+ 			 * with stage 2 Device type and attributes.
+			 */
+			final_attr = min(s2_memattr_to_attr(s2_memattr),
+					 s1_parattr);
 		}
 	} else {
 		/* Combination of R_HMNDG, R_TNHFM and R_GQFSF */
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type
  2024-11-25  9:47 [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type Marc Zyngier
@ 2024-11-26 15:27 ` Oliver Upton
  2024-11-26 16:30   ` Marc Zyngier
  2024-11-26 15:59 ` Oliver Upton
  1 sibling, 1 reply; 5+ messages in thread
From: Oliver Upton @ 2024-11-26 15:27 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: kvmarm, linux-arm-kernel, Joey Gouly, Suzuki K Poulose,
	Zenghui Yu, Alexandru Elisei

On Mon, Nov 25, 2024 at 09:47:56AM +0000, Marc Zyngier wrote:
> The G.a revision of the ARM ARM had it pretty clear that HCR_EL2.FWB
> had no influence on "The way that stage 1 memory types and attributes
> are combined with stage 2 Device type and attributes." (D5.5.5).
> 
> However, this wording was lost in further revisions of the architecture.
> 
> Restore the intended behaviour, which is to take the strongest memory
> type of S1 and S2 in this case, as if FWB was 0. The specification is
> being fixed accordingly.

Since you're already asking for a spec fix, could you mention that the
column headers in DDI0487K.a Table D8-95 are incorrect? MemAttr[1:0] is
used twice, although I believe the first column is actually MemAttr[3:2].

> Fixes: be04cebf3e788 ("KVM: arm64: nv: Add emulation of AT S12E{0,1}{R,W}")
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  arch/arm64/kvm/at.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c
> index 8c5d7990e5b31..98cb499fa4b11 100644
> --- a/arch/arm64/kvm/at.c
> +++ b/arch/arm64/kvm/at.c
> @@ -739,8 +739,15 @@ static u64 compute_par_s12(struct kvm_vcpu *vcpu, u64 s1_par,
>  			final_attr = s1_parattr;
>  			break;
>  		default:
> -			/* MemAttr[2]=0, Device from S2 */
> -			final_attr = s2_memattr & GENMASK(1,0) << 2;
> +			/*
> +			 * MemAttr[2]=0, Device from S2.
> +			 *
> +			 * FWB does not influence the way that stage 1
> + 			 * memory types and attributes are combined
> + 			 * with stage 2 Device type and attributes.
> +			 */
> +			final_attr = min(s2_memattr_to_attr(s2_memattr),
> +					 s1_parattr);

Otherwise, LGTM.

-- 
Thanks,
Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type
  2024-11-25  9:47 [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type Marc Zyngier
  2024-11-26 15:27 ` Oliver Upton
@ 2024-11-26 15:59 ` Oliver Upton
  1 sibling, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2024-11-26 15:59 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, Marc Zyngier
  Cc: Oliver Upton, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
	Alexandru Elisei

On Mon, 25 Nov 2024 09:47:56 +0000, Marc Zyngier wrote:
> The G.a revision of the ARM ARM had it pretty clear that HCR_EL2.FWB
> had no influence on "The way that stage 1 memory types and attributes
> are combined with stage 2 Device type and attributes." (D5.5.5).
> 
> However, this wording was lost in further revisions of the architecture.
> 
> Restore the intended behaviour, which is to take the strongest memory
> type of S1 and S2 in this case, as if FWB was 0. The specification is
> being fixed accordingly.
> 
> [...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type
      https://git.kernel.org/kvmarm/kvmarm/c/6fc3a49f2385

--
Best,
Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type
  2024-11-26 15:27 ` Oliver Upton
@ 2024-11-26 16:30   ` Marc Zyngier
  2024-11-26 18:48     ` Oliver Upton
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Zyngier @ 2024-11-26 16:30 UTC (permalink / raw)
  To: Oliver Upton
  Cc: kvmarm, linux-arm-kernel, Joey Gouly, Suzuki K Poulose,
	Zenghui Yu, Alexandru Elisei

On Tue, 26 Nov 2024 15:27:00 +0000,
Oliver Upton <oliver.upton@linux.dev> wrote:
> 
> On Mon, Nov 25, 2024 at 09:47:56AM +0000, Marc Zyngier wrote:
> > The G.a revision of the ARM ARM had it pretty clear that HCR_EL2.FWB
> > had no influence on "The way that stage 1 memory types and attributes
> > are combined with stage 2 Device type and attributes." (D5.5.5).
> > 
> > However, this wording was lost in further revisions of the architecture.
> > 
> > Restore the intended behaviour, which is to take the strongest memory
> > type of S1 and S2 in this case, as if FWB was 0. The specification is
> > being fixed accordingly.
> 
> Since you're already asking for a spec fix, could you mention that the
> column headers in DDI0487K.a Table D8-95 are incorrect? MemAttr[1:0] is
> used twice, although I believe the first column is actually MemAttr[3:2].

That one has already been fixed as D22366, as described in the Known
Issues document for version K.a (issue 07) [1].

Thanks,

	M.

[1] https://developer.arm.com/documentation/102105/latest/

-- 
Without deviation from the norm, progress is not possible.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type
  2024-11-26 16:30   ` Marc Zyngier
@ 2024-11-26 18:48     ` Oliver Upton
  0 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2024-11-26 18:48 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: kvmarm, linux-arm-kernel, Joey Gouly, Suzuki K Poulose,
	Zenghui Yu, Alexandru Elisei

On Tue, Nov 26, 2024 at 04:30:16PM +0000, Marc Zyngier wrote:
> On Tue, 26 Nov 2024 15:27:00 +0000,
> Oliver Upton <oliver.upton@linux.dev> wrote:
> > 
> > On Mon, Nov 25, 2024 at 09:47:56AM +0000, Marc Zyngier wrote:
> > > The G.a revision of the ARM ARM had it pretty clear that HCR_EL2.FWB
> > > had no influence on "The way that stage 1 memory types and attributes
> > > are combined with stage 2 Device type and attributes." (D5.5.5).
> > > 
> > > However, this wording was lost in further revisions of the architecture.
> > > 
> > > Restore the intended behaviour, which is to take the strongest memory
> > > type of S1 and S2 in this case, as if FWB was 0. The specification is
> > > being fixed accordingly.
> > 
> > Since you're already asking for a spec fix, could you mention that the
> > column headers in DDI0487K.a Table D8-95 are incorrect? MemAttr[1:0] is
> > used twice, although I believe the first column is actually MemAttr[3:2].
> 
> That one has already been fixed as D22366, as described in the Known
> Issues document for version K.a (issue 07) [1].

Ah, right on. Thanks!

-- 
Best,
Oliver


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-26 18:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-25  9:47 [PATCH] KVM: arm64: Fix S1/S2 combination when FWB==1 and S2 has Device memory type Marc Zyngier
2024-11-26 15:27 ` Oliver Upton
2024-11-26 16:30   ` Marc Zyngier
2024-11-26 18:48     ` Oliver Upton
2024-11-26 15:59 ` Oliver Upton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).