Skip to contentSkip to conversation

KVM: arm64: Set HCR_EL2.BSU to Inner Shareable for guests

PATCH Applied Fuad Tabba 2 participants 3 messages Oct 16 – Oct 26

Subsystems (2)
lore
Share & tools
lore

Fuad Tabba

author reviewer
#0 lore raw

PATCH 1/1 KVM: arm64: Set HCR_EL2.BSU to Inner Shareable for guests

KVM sets HCR_EL2.BSU to Inner Shareable for guests, so that a guest's barriers cover the TLB and I-cache invalidations that HCR_EL2.FB broadcasts. However, since HCR_BSU_IS became an alias of the generated HCR_EL2_BSU_IS, it is the unshifted field value 0b01, which sets bit 0 (VM, already set) and leaves BSU at 0b00. A guest's DSB NSH is then not required to wait for a broadcast TLBI to complete on other CPUs.

Build the field with SYS_FIELD_PREP_ENUM().

Fixes d0f39259eff4 ("arm64: sysreg: Add layout for HCR_EL2")

---
Found while testing Marc's HCR cleanup [1]. Its patch 1 carries this line over as HCR_EL2_BSU_IS, so on top of this fix that hunk would keep SYS_FIELD_PREP_ENUM() instead. I can also rebase this on top of the series if that's easier.

[1] https://lore.kernel.org/r/[email protected]

 arch/arm64/include/asm/kvm_arm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/kvm_arm.h +1 -1
index 4bfbd827c5aa7..b3e9dd302730e 100644
@@ -98,7 +98,7 @@
  * TID1:	Trap REVIDR_EL1, AIDR_EL1, and SMIDR_EL1
  */
 #define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \
-			 HCR_BSU_IS | HCR_FB | HCR_TACR | \
+			 SYS_FIELD_PREP_ENUM(HCR_EL2, BSU, IS) | HCR_EL2_FB | HCR_EL2_TACR | \
 			 HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
 			 HCR_FMO | HCR_IMO | HCR_PTW | HCR_TID3 | HCR_TID1)
 #define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK)
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 28 lines · Fuad Tabba

KVM sets HCR_EL2.BSU to Inner Shareable for guests, so that a guest's barriers cover the TLB and I-cache invalidations that HCR_EL2.FB broadcasts. However, since HCR_BSU_IS became an alias of the generated HCR_EL2_BSU_IS, it is the unshifted field value 0b01, which sets bit 0 (VM, already set) and leaves BSU at 0b00. A guest's DSB NSH is then not required to wait for a broadcast TLBI to complete on other CPUs.

Build the field with SYS_FIELD_PREP_ENUM().

Fixes d0f39259eff4 ("arm64: sysreg: Add layout for HCR_EL2")

---
Found while testing Marc's HCR cleanup [1]. Its patch 1 carries this line over as HCR_EL2_BSU_IS, so on top of this fix that hunk would keep SYS_FIELD_PREP_ENUM() instead. I can also rebase this on top of the series if that's easier.

[1] https://lore.kernel.org/r/[email protected]

 arch/arm64/include/asm/kvm_arm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/kvm_arm.h +0 -0
index 4bfbd827c5aa7..b3e9dd302730e 100644

arch/arm64/include/asm/kvm_arm.h line 104

Quoted 8 lines
arch/arm64/include/asm/kvm_arm.h +1 -1
@@ -98,7 +98,7 @@
  * TID1:	Trap REVIDR_EL1, AIDR_EL1, and SMIDR_EL1
  */
 #define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \
-			 HCR_BSU_IS | HCR_FB | HCR_TACR | \
+			 SYS_FIELD_PREP_ENUM(HCR_EL2, BSU, IS) | HCR_EL2_FB | HCR_EL2_TACR | \
 			 HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
 			 HCR_FMO | HCR_IMO | HCR_PTW | HCR_TID3 | HCR_TID1)
 #define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK)

Huh. That's a bad one. I've added a Cc: stable to that, and queued it as a prefix of the cleanup series.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer Applied
#2 lore raw
In reply to Fuad Tabba
Quoted 8 lines · Fuad Tabba

KVM sets HCR_EL2.BSU to Inner Shareable for guests, so that a guest's barriers cover the TLB and I-cache invalidations that HCR_EL2.FB broadcasts. However, since HCR_BSU_IS became an alias of the generated HCR_EL2_BSU_IS, it is the unshifted field value 0b01, which sets bit 0 (VM, already set) and leaves BSU at 0b00. A guest's DSB NSH is then not required to wait for a broadcast TLBI to complete on other CPUs.

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Set HCR_EL2.BSU to Inner Shareable for guests

      commit: 00e73757518020273ccf6308a51f214e58c21ad5

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.