* [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:49 ` Leonardo Bras
2026-11-30 16:35 ` [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible Mark Brown
` (9 subsequent siblings)
10 siblings, 1 reply; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown
GCS introduces a number of system registers, on systems with GCS we need
to context switch them and expose them to VMMs to allow guests to use
GCS, including forwarding of traps for the EL2 registers with nested
guests.
Since the effects of GCSCR_ELx.EXLOCKEN are not controlled by
HCRX_EL2.GCSEn we always load GCSCR_EL1 for guests, even if they are not
using GCS.
In order to allow guests to use GCS we also need to configure
HCRX_EL2.GCSEn, if this is not set GCS instructions will be noops and
CHKFEAT will report GCS as disabled.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/include/asm/kvm_emulate.h | 3 +++
arch/arm64/include/asm/kvm_host.h | 14 ++++++++++
arch/arm64/include/asm/vncr_mapping.h | 2 ++
arch/arm64/kvm/emulate-nested.c | 2 ++
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 39 +++++++++++++++++++++++++++
arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 20 ++++++++++++++
arch/arm64/kvm/sys_regs.c | 42 ++++++++++++++++++++++++++++++
7 files changed, 122 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 2d7c82cfb8a4..f5b0b0393f9c 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -743,6 +743,9 @@ static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu)
if (kvm_has_feat(kvm, ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA))
vcpu->arch.hcrx_el2 |= HCRX_EL2_EnAS0;
+ if (kvm_has_gcs(kvm))
+ vcpu->arch.hcrx_el2 |= HCRX_EL2_GCSEn;
+
/*
* NV3 is a host-specific extension, and we always use
* it when present and that the guest uses NV. It may
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 0614c3b3a40d..5130e34fae07 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -587,6 +587,10 @@ enum vcpu_sysreg {
POR_EL0, /* Permission Overlay Register 0 (EL0) */
+ /* Guarded Control Stack registers */
+ GCSCRE0_EL1, /* Guarded Control Stack Control (EL0) */
+ GCSPR_EL0, /* Guarded Control Stack Pointer (EL0) */
+
/* FP/SIMD/SVE */
SVCR,
FPMR,
@@ -606,6 +610,8 @@ enum vcpu_sysreg {
PIRE0_EL2, /* Permission Indirection Register 0 (EL2) */
PIR_EL2, /* Permission Indirection Register 1 (EL2) */
POR_EL2, /* Permission Overlay Register 2 (EL2) */
+ GCSCR_EL2, /* Guarded Control Stack Control Register (EL2) */
+ GCSPR_EL2, /* Guarded Control Stack Pointer Register (EL2) */
SPSR_EL2, /* EL2 saved program status register */
ELR_EL2, /* EL2 exception link register */
AFSR0_EL2, /* Auxiliary Fault Status Register 0 (EL2) */
@@ -679,6 +685,10 @@ enum vcpu_sysreg {
VNCR(VDISR_EL2),
VNCR(VSESR_EL2),
+ /* Guarded Control Stack registers */
+ VNCR(GCSPR_EL1), /* Guarded Control Stack Pointer (EL1) */
+ VNCR(GCSCR_EL1), /* Guarded Control Stack Control (EL1) */
+
VNCR(HFGRTR_EL2),
VNCR(HFGWTR_EL2),
VNCR(HFGITR_EL2),
@@ -1745,6 +1755,10 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val);
#define kvm_has_sctlr2(k) \
(kvm_has_feat((k), ID_AA64MMFR3_EL1, SCTLRX, IMP))
+#define kvm_has_gcs(k) \
+ (system_supports_gcs() && \
+ kvm_has_feat((k), ID_AA64PFR1_EL1, GCS, IMP))
+
static inline bool kvm_arch_has_irq_bypass(void)
{
return true;
diff --git a/arch/arm64/include/asm/vncr_mapping.h b/arch/arm64/include/asm/vncr_mapping.h
index 9e8a49fa8b63..e589adccc2f3 100644
--- a/arch/arm64/include/asm/vncr_mapping.h
+++ b/arch/arm64/include/asm/vncr_mapping.h
@@ -97,6 +97,8 @@
#define VNCR_PMSNEVFR_EL1 0x850
#define VNCR_PMSDSFR_EL1 0x858
#define VNCR_TRFCR_EL1 0x880
+#define VNCR_GCSPR_EL1 0x8C0
+#define VNCR_GCSCR_EL1 0x8D0
#define VNCR_MPAM1_EL1 0x900
#define VNCR_MPAMHCR_EL2 0x930
#define VNCR_MPAMVPMV_EL2 0x938
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index 39136a89d74b..cb9bf3b9340a 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -873,6 +873,8 @@ static const struct encoding_to_trap_config encoding_to_cgt[] __initconst = {
SR_TRAP(SYS_VTTBR_EL2, CGT_HCR_NV),
SR_TRAP(SYS_VTCR_EL2, CGT_HCR_NV),
SR_TRAP(SYS_VNCR_EL2, CGT_HCR_NV),
+ SR_TRAP(SYS_GCSCR_EL2, CGT_HCR_NV),
+ SR_TRAP(SYS_GCSPR_EL2, CGT_HCR_NV),
SR_RANGE_TRAP(SYS_HDFGRTR_EL2,
SYS_HAFGRTR_EL2, CGT_HCR_NV),
/* Skip the SP_EL1 encoding... */
diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index 4a008c8a696b..bdaaa3c85a91 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -18,6 +18,7 @@
static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt);
static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt);
+static inline bool ctxt_has_gcs(struct kvm_cpu_context *ctxt);
static inline struct kvm_vcpu *ctxt_to_vcpu(struct kvm_cpu_context *ctxt)
{
@@ -75,6 +76,11 @@ static inline void __sysreg_save_user_state(struct kvm_cpu_context *ctxt)
*/
if (ctxt_has_accdata(ctxt))
ctxt_sys_reg(ctxt, ACCDATA_EL1) = read_sysreg_s(SYS_ACCDATA_EL1);
+
+ if (ctxt_has_gcs(ctxt)) {
+ ctxt_sys_reg(ctxt, GCSPR_EL0) = read_sysreg_s(SYS_GCSPR_EL0);
+ ctxt_sys_reg(ctxt, GCSCRE0_EL1) = read_sysreg_s(SYS_GCSCRE0_EL1);
+ }
}
static inline bool ctxt_has_mte(struct kvm_cpu_context *ctxt)
@@ -151,6 +157,13 @@ static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt)
return kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA);
}
+static inline bool ctxt_has_gcs(struct kvm_cpu_context *ctxt)
+{
+ struct kvm_vcpu *vcpu = ctxt_to_vcpu(ctxt);
+
+ return kvm_has_gcs(kern_hyp_va(vcpu->kvm));
+}
+
static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
{
ctxt_sys_reg(ctxt, SCTLR_EL1) = read_sysreg_el1(SYS_SCTLR);
@@ -164,6 +177,10 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
if (ctxt_has_s1pie(ctxt)) {
ctxt_sys_reg(ctxt, PIR_EL1) = read_sysreg_el1(SYS_PIR);
ctxt_sys_reg(ctxt, PIRE0_EL1) = read_sysreg_el1(SYS_PIRE0);
+ if (ctxt_has_gcs(ctxt)) {
+ ctxt_sys_reg(ctxt, GCSPR_EL1) = read_sysreg_el1(SYS_GCSPR);
+ ctxt_sys_reg(ctxt, GCSCR_EL1) = read_sysreg_el1(SYS_GCSCR);
+ }
}
if (ctxt_has_s1poe(ctxt))
@@ -233,6 +250,12 @@ static inline void __sysreg_restore_user_state(struct kvm_cpu_context *ctxt)
if (ctxt_has_accdata(ctxt))
write_sysreg_s(ctxt_sys_reg(ctxt, ACCDATA_EL1), SYS_ACCDATA_EL1);
+
+ if (ctxt_has_gcs(ctxt)) {
+ write_sysreg_s(ctxt_sys_reg(ctxt, GCSPR_EL0), SYS_GCSPR_EL0);
+ write_sysreg_s(ctxt_sys_reg(ctxt, GCSCRE0_EL1),
+ SYS_GCSCRE0_EL1);
+ }
}
static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt,
@@ -266,11 +289,27 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt,
if (ctxt_has_s1pie(ctxt)) {
write_sysreg_el1(ctxt_sys_reg(ctxt, PIR_EL1), SYS_PIR);
write_sysreg_el1(ctxt_sys_reg(ctxt, PIRE0_EL1), SYS_PIRE0);
+
+ if (ctxt_has_gcs(ctxt))
+ write_sysreg_el1(ctxt_sys_reg(ctxt, GCSPR_EL1), SYS_GCSPR);
}
if (ctxt_has_s1poe(ctxt))
write_sysreg_el1(ctxt_sys_reg(ctxt, POR_EL1), SYS_POR);
}
+
+ /*
+ * EXLOCK is not suppressed by HCRX_EL2.GCSEn, ensure we don't
+ * inherit a bad value from another guest with GCS.
+ */
+ if (system_supports_gcs()) {
+ u64 val = 0;
+
+ if (ctxt_has_gcs(ctxt))
+ val = ctxt_sys_reg(ctxt, GCSCR_EL1);
+ write_sysreg_el1(val, SYS_GCSCR);
+ }
+
write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1), SYS_ESR);
write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR0_EL1), SYS_AFSR0);
write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR1_EL1), SYS_AFSR1);
diff --git a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
index 0c4ef1ce32ae..a961fe1e91ae 100644
--- a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
+++ b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
@@ -59,6 +59,9 @@ static void __sysreg_save_vel2_state(struct kvm_vcpu *vcpu)
if (ctxt_has_s1pie(&vcpu->arch.ctxt)) {
__vcpu_assign_sys_reg(vcpu, PIRE0_EL2, read_sysreg_el1(SYS_PIRE0));
__vcpu_assign_sys_reg(vcpu, PIR_EL2, read_sysreg_el1(SYS_PIR));
+
+ if (ctxt_has_gcs(&vcpu->arch.ctxt))
+ __vcpu_assign_sys_reg(vcpu, GCSCR_EL2, read_sysreg_el1(SYS_GCSCR));
}
if (ctxt_has_s1poe(&vcpu->arch.ctxt))
@@ -86,6 +89,8 @@ static void __sysreg_save_vel2_state(struct kvm_vcpu *vcpu)
__vcpu_assign_sys_reg(vcpu, SP_EL2, read_sysreg(sp_el1));
__vcpu_assign_sys_reg(vcpu, ELR_EL2, read_sysreg_el1(SYS_ELR));
__vcpu_assign_sys_reg(vcpu, SPSR_EL2, read_sysreg_el1(SYS_SPSR));
+ if (ctxt_has_gcs(&vcpu->arch.ctxt))
+ __vcpu_assign_sys_reg(vcpu, GCSPR_EL2, read_sysreg_el1(SYS_GCSPR));
if (ctxt_has_sctlr2(&vcpu->arch.ctxt))
__vcpu_assign_sys_reg(vcpu, SCTLR2_EL2, read_sysreg_el1(SYS_SCTLR2));
@@ -138,12 +143,27 @@ static void __sysreg_restore_vel2_state(struct kvm_vcpu *vcpu)
if (ctxt_has_s1pie(&vcpu->arch.ctxt)) {
write_sysreg_el1(__vcpu_sys_reg(vcpu, PIR_EL2), SYS_PIR);
write_sysreg_el1(__vcpu_sys_reg(vcpu, PIRE0_EL2), SYS_PIRE0);
+
+ if (ctxt_has_gcs(&vcpu->arch.ctxt))
+ write_sysreg_el1(__vcpu_sys_reg(vcpu, GCSPR_EL2), SYS_GCSPR);
}
if (ctxt_has_s1poe(&vcpu->arch.ctxt))
write_sysreg_el1(__vcpu_sys_reg(vcpu, POR_EL2), SYS_POR);
}
+ /*
+ * EXLOCK is not suppressed by HCRX_EL2.GCSEn, ensure we don't
+ * inherit a bad value from another guest with GCS.
+ */
+ if (system_supports_gcs()) {
+ u64 val = 0;
+
+ if (ctxt_has_gcs(&vcpu->arch.ctxt))
+ val = __vcpu_sys_reg(vcpu, GCSCR_EL2);
+ write_sysreg_el1(val, SYS_GCSCR);
+ }
+
write_sysreg_el1(__vcpu_sys_reg(vcpu, ESR_EL2), SYS_ESR);
write_sysreg_el1(__vcpu_sys_reg(vcpu, AFSR0_EL2), SYS_AFSR0);
write_sysreg_el1(__vcpu_sys_reg(vcpu, AFSR1_EL2), SYS_AFSR1);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 399dfcf102ae..3fc9e47a3c39 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -109,6 +109,8 @@ static enum sr_loc_attr locate_direct_register(const struct kvm_vcpu *vcpu,
case PIR_EL1:
case PIRE0_EL1:
case POR_EL1:
+ case GCSCR_EL1:
+ case GCSPR_EL1:
case ESR_EL1:
case AFSR0_EL1:
case AFSR1_EL1:
@@ -135,6 +137,8 @@ static enum sr_loc_attr locate_direct_register(const struct kvm_vcpu *vcpu,
case DACR32_EL2:
case IFSR32_EL2:
case DBGVCR32_EL2:
+ case GCSCRE0_EL1:
+ case GCSPR_EL0:
/* These registers are always loaded, no matter what */
return SR_LOC_LOADED;
@@ -198,6 +202,8 @@ static void locate_register(const struct kvm_vcpu *vcpu, enum vcpu_sysreg reg,
MAPPED_EL2_SYSREG(PIR_EL2, PIR_EL1, NULL );
MAPPED_EL2_SYSREG(PIRE0_EL2, PIRE0_EL1, NULL );
MAPPED_EL2_SYSREG(POR_EL2, POR_EL1, NULL );
+ MAPPED_EL2_SYSREG(GCSCR_EL2, GCSCR_EL1, NULL );
+ MAPPED_EL2_SYSREG(GCSPR_EL2, GCSPR_EL1, NULL );
MAPPED_EL2_SYSREG(AMAIR_EL2, AMAIR_EL1, NULL );
MAPPED_EL2_SYSREG(ELR_EL2, ELR_EL1, NULL );
MAPPED_EL2_SYSREG(SPSR_EL2, SPSR_EL1, NULL );
@@ -253,6 +259,10 @@ static u64 read_sr_from_cpu(enum vcpu_sysreg reg)
case TCR2_EL1: val = read_sysreg_s(SYS_TCR2_EL12); break;
case PIR_EL1: val = read_sysreg_s(SYS_PIR_EL12); break;
case PIRE0_EL1: val = read_sysreg_s(SYS_PIRE0_EL12); break;
+ case GCSPR_EL0: val = read_sysreg_s(SYS_GCSPR_EL0); break;
+ case GCSCRE0_EL1: val = read_sysreg_s(SYS_GCSCRE0_EL1); break;
+ case GCSCR_EL1: val = read_sysreg_s(SYS_GCSCR_EL12); break;
+ case GCSPR_EL1: val = read_sysreg_s(SYS_GCSPR_EL12); break;
case POR_EL1: val = read_sysreg_s(SYS_POR_EL12); break;
case ESR_EL1: val = read_sysreg_s(SYS_ESR_EL12); break;
case AFSR0_EL1: val = read_sysreg_s(SYS_AFSR0_EL12); break;
@@ -293,6 +303,10 @@ static void write_sr_to_cpu(enum vcpu_sysreg reg, u64 val)
case PIR_EL1: write_sysreg_s(val, SYS_PIR_EL12); break;
case PIRE0_EL1: write_sysreg_s(val, SYS_PIRE0_EL12); break;
case POR_EL1: write_sysreg_s(val, SYS_POR_EL12); break;
+ case GCSCRE0_EL1: write_sysreg_s(val, SYS_GCSCRE0_EL1); break;
+ case GCSPR_EL0: write_sysreg_s(val, SYS_GCSPR_EL0); break;
+ case GCSCR_EL1: write_sysreg_s(val, SYS_GCSCR_EL12); break;
+ case GCSPR_EL1: write_sysreg_s(val, SYS_GCSPR_EL12); break;
case ESR_EL1: write_sysreg_s(val, SYS_ESR_EL12); break;
case AFSR0_EL1: write_sysreg_s(val, SYS_AFSR0_EL12); break;
case AFSR1_EL1: write_sysreg_s(val, SYS_AFSR1_EL12); break;
@@ -3074,6 +3088,21 @@ static unsigned int cnthv_visibility(const struct kvm_vcpu *vcpu,
return REG_HIDDEN;
}
+static unsigned int gcs_visibility(const struct kvm_vcpu *vcpu,
+ const struct sys_reg_desc *r)
+{
+ if (kvm_has_gcs(vcpu->kvm))
+ return 0;
+
+ return REG_HIDDEN;
+}
+
+static unsigned int gcs_el2_visibility(const struct kvm_vcpu *vcpu,
+ const struct sys_reg_desc *rd)
+{
+ return __el2_visibility(vcpu, rd, gcs_visibility);
+}
+
static bool access_mdcr(struct kvm_vcpu *vcpu,
struct sys_reg_params *p,
const struct sys_reg_desc *r)
@@ -3486,6 +3515,13 @@ static const struct sys_reg_desc sys_reg_descs[] = {
PTRAUTH_KEY(APDB),
PTRAUTH_KEY(APGA),
+ { SYS_DESC(SYS_GCSCR_EL1), NULL, reset_val, GCSCR_EL1, 0,
+ .visibility = gcs_visibility },
+ { SYS_DESC(SYS_GCSPR_EL1), NULL, reset_unknown, GCSPR_EL1,
+ .visibility = gcs_visibility },
+ { SYS_DESC(SYS_GCSCRE0_EL1), NULL, reset_val, GCSCRE0_EL1, 0,
+ .visibility = gcs_visibility },
+
{ SYS_DESC(SYS_ICC_PMR_EL1), undef_access },
{ SYS_DESC(SYS_AFSR0_EL1), access_vm_reg, reset_unknown, AFSR0_EL1 },
@@ -3609,6 +3645,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
CTR_EL0_DminLine_MASK |
CTR_EL0_L1Ip_MASK |
CTR_EL0_IminLine_MASK),
+ { SYS_DESC(SYS_GCSPR_EL0), NULL, reset_unknown, GCSPR_EL0,
+ .visibility = gcs_visibility },
{ SYS_DESC(SYS_SVCR), undef_access, reset_val, SVCR, 0, .visibility = sme_visibility },
{ SYS_DESC(SYS_FPMR), undef_access, reset_val, FPMR, 0, .visibility = fp8_visibility },
@@ -3852,6 +3890,10 @@ static const struct sys_reg_desc sys_reg_descs[] = {
EL2_REG_FILTERED(VNCR_EL2, bad_vncr_trap, reset_val, 0,
vncr_el2_visibility),
+ EL2_REG_FILTERED(GCSCR_EL2, access_rw, reset_val, 0,
+ gcs_el2_visibility),
+ EL2_REG_FILTERED(GCSPR_EL2, access_rw, reset_val, 0,
+ gcs_el2_visibility),
{ SYS_DESC(SYS_DACR32_EL2), undef_access, reset_unknown, DACR32_EL2 },
EL2_REG_VNCR_FILT(HDFGRTR2_EL2, fgt2_visibility),
EL2_REG_VNCR_FILT(HDFGWTR2_EL2, fgt2_visibility),
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests
2026-11-30 16:35 ` [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests Mark Brown
@ 2026-11-30 16:49 ` Leonardo Bras
2026-11-30 16:59 ` Mark Brown
0 siblings, 1 reply; 14+ messages in thread
From: Leonardo Bras @ 2026-11-30 16:49 UTC (permalink / raw)
To: Mark Brown
Cc: Leonardo Bras, Catalin Marinas, Will Deacon, Marc Zyngier,
Joey Gouly, Suzuki K Poulose, Shuah Khan, Oliver Upton,
Fuad Tabba, Peter Maydell, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel
On Mon, Nov 30, 2026 at 04:35:44PM +0000, Mark Brown wrote:
> GCS introduces a number of system registers, on systems with GCS we need
> to context switch them and expose them to VMMs to allow guests to use
> GCS, including forwarding of traps for the EL2 registers with nested
> guests.
>
> Since the effects of GCSCR_ELx.EXLOCKEN are not controlled by
> HCRX_EL2.GCSEn we always load GCSCR_EL1 for guests, even if they are not
> using GCS.
>
> In order to allow guests to use GCS we also need to configure
> HCRX_EL2.GCSEn, if this is not set GCS instructions will be noops and
> CHKFEAT will report GCS as disabled.
>
> Signed-off-by: Mark Brown <broonie@kernel.org>
As per [1], feel free to add my R-b.
Thx,
Leo
[1]https://lore.kernel.org/all/aphSYqKrgUq5Qycu@LeoBrasDK/
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests
2026-11-30 16:49 ` Leonardo Bras
@ 2026-11-30 16:59 ` Mark Brown
0 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:59 UTC (permalink / raw)
To: Leonardo Bras
Cc: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba,
Peter Maydell, Wei-Lin Chang, Yao Yuan, linux-arm-kernel,
linux-doc, kvmarm, linux-kselftest, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 505 bytes --]
On Mon, Nov 30, 2026 at 04:49:24PM +0000, Leonardo Bras wrote:
> On Mon, Nov 30, 2026 at 04:35:44PM +0000, Mark Brown wrote:
> > GCS introduces a number of system registers, on systems with GCS we need
> > to context switch them and expose them to VMMs to allow guests to use
> > GCS, including forwarding of traps for the EL2 registers with nested
> > guests.
> As per [1], feel free to add my R-b.
Thanks, I felt like I'd changed the patch enough to want confirmation
that you were still OK with it.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
2026-11-30 16:35 ` [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception Mark Brown
` (8 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown, Lorenzo Stoakes (ARM)
In order to allow efficient implementation of GCS implementations are
permitted to do GCS specific caching, with barriers implicit in stack
switch operations and GCSB DSYNC as an explicit barrier. Since we do
not use GCS in the hypervisor or host kernel the hypervisor cannot rely
on any barriers being present in vCPU context switches other than those
it explicitly inserts. Add explicit barriers when saving vCPU state,
unless we're doing it due to a nested EL transition in which case there
is no need since the guest will not change.
Reviewed-by: Yuan Yao <yaoyuan@linux.alibaba.com>
Reviewed-by: Leonardo Bras <leo.bras@arm.com>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/kvm/arm.c | 18 ++++++++++++++++++
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++
2 files changed, 25 insertions(+)
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index a148e80d0aef..2064cff8e92a 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -826,6 +826,16 @@ static void vhe_vcpu_put(struct kvm_vcpu *vcpu)
if (vcpu_has_nv(vcpu))
kvm_vcpu_put_hw_mmu(vcpu);
+ /*
+ * Ensure any GCS memory effects from the outgoing vCPU are
+ * visible elsewhere, nested guests transitioning ELs do not
+ * need this.
+ */
+ if (kvm_has_gcs(vcpu->kvm) &&
+ !vcpu_get_flag(vcpu, IN_NESTED_ERET) &&
+ !vcpu_get_flag(vcpu, IN_NESTED_EXCEPTION))
+ gcsb_dsync();
+
vcpu_put_mmu(vcpu);
}
@@ -836,6 +846,14 @@ static void nvhe_vcpu_put(struct kvm_vcpu *vcpu)
kvm_timer_vcpu_put(vcpu);
kvm_vgic_put(vcpu);
kvm_vcpu_pmu_restore_host(vcpu);
+
+ /*
+ * Ensure any GCS memory effects from the outgoing vCPU are
+ * visible elsewhere.
+ */
+ if (kvm_has_gcs(vcpu->kvm))
+ gcsb_dsync();
+
vcpu_put_mmu(vcpu);
}
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 0c023ee0cf42..18030dd0dc0a 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -871,6 +871,13 @@ DEFINE_KVM_HOST_HCALL0(void, __pkvm_vcpu_put)
sync_hyp_vcpu_state(hyp_vcpu);
}
+ /*
+ * Ensure any GCS memory effects from the outgoing vCPU are
+ * visible elsewhere even if the host skips syncing.
+ */
+ if (kvm_has_gcs(hyp_vcpu->vcpu.kvm))
+ gcsb_dsync();
+
pkvm_put_hyp_vcpu(hyp_vcpu);
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
2026-11-30 16:35 ` [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests Mark Brown
2026-11-30 16:35 ` [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 06/16] KVM: arm64: Validate GCS exception lock when emulating ERET Mark Brown
` (7 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown, Lorenzo Stoakes (ARM)
As per DDI 0487 R_WTXBY we need to manage PSTATE.EXLOCK when entering an
exception, when the exception is entered from a lower EL the bit is cleared
while if entering from the same EL it is set to GCSCR_ELx.EXLOCKEN.
Implement this behaviour in enter_exception64().
Reviewed-by: Yuan Yao <yaoyuan@linux.alibaba.com>
Reviewed-by: Leonardo Bras <leo.bras@arm.com>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/include/uapi/asm/ptrace.h | 1 +
arch/arm64/kvm/hyp/exception.c | 40 +++++++++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h
index 0c8c6a126c3b..ac38744951c7 100644
--- a/arch/arm64/include/uapi/asm/ptrace.h
+++ b/arch/arm64/include/uapi/asm/ptrace.h
@@ -56,6 +56,7 @@
#define PSR_C_BIT 0x20000000
#define PSR_Z_BIT 0x40000000
#define PSR_N_BIT 0x80000000
+#define PSR_EXLOCK_BIT 0x400000000
#define PSR_BTYPE_SHIFT 10
diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c
index 7521bddf73e4..ce482c5dedfc 100644
--- a/arch/arm64/kvm/hyp/exception.c
+++ b/arch/arm64/kvm/hyp/exception.c
@@ -49,6 +49,37 @@ static void __vcpu_write_spsr_und(struct kvm_vcpu *vcpu, u64 val)
vcpu->arch.ctxt.spsr_und = val;
}
+static bool compute_exlock(struct kvm *kvm, struct kvm_vcpu *vcpu,
+ unsigned long mode, unsigned long target_mode)
+{
+ u64 gcscr;
+
+ if (!(kvm && kvm_has_gcs(kvm)))
+ return false;
+
+ /* GCS can't be enabled for 32 bit */
+ if (mode & PSR_MODE32_BIT)
+ return false;
+
+ /* When taking an exception to a higher EL EXLOCK is cleared. */
+ if ((mode | PSR_MODE_THREAD_BIT) < target_mode)
+ return false;
+
+ /*
+ * When taking an exception to the same EL EXLOCK is set to
+ * the effective value of GCSCR_ELx.EXLOCKEN.
+ */
+ if (is_hyp_ctxt(vcpu))
+ gcscr = vcpu_read_sys_reg(vcpu, GCSCR_EL2);
+ else
+ gcscr = vcpu_read_sys_reg(vcpu, GCSCR_EL1);
+
+ if (gcscr & GCSCR_ELx_EXLOCKEN)
+ return true;
+
+ return false;
+}
+
/*
* This performs the exception entry at a given EL (@target_mode), stashing PC
* and PSTATE into ELR and SPSR respectively, and compute the new PC/PSTATE.
@@ -113,7 +144,6 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode,
kvm = vcpu_get_kvm(vcpu);
if (kvm && kvm_has_mte(kvm))
new |= PSR_TCO_BIT;
- vcpu_put_kvm(vcpu, kvm);
new |= (old & PSR_DIT_BIT);
@@ -141,6 +171,12 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode,
// PSTATE.BTYPE is set to zero upon any exception to AArch64
// See ARM DDI 0487E.a, pages D1-2293 to D1-2294.
+ // PSTATE.EXLOCK is set to 0 upon any exception to a higher
+ // EL, or to GCSCR_ELx.EXLOCKEN for an exception to the same
+ // exception level. See ARM DDI 0487 R_WTXBY.
+ if (compute_exlock(kvm, vcpu, mode, target_mode))
+ new |= PSR_EXLOCK_BIT;
+
new |= PSR_D_BIT;
new |= PSR_A_BIT;
new |= PSR_I_BIT;
@@ -150,6 +186,8 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode,
*vcpu_cpsr(vcpu) = new;
__vcpu_write_spsr(vcpu, target_mode, old);
+
+ vcpu_put_kvm(vcpu, kvm);
}
/*
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 06/16] KVM: arm64: Validate GCS exception lock when emulating ERET
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (2 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 07/16] KVM: arm64: Forward GCS exceptions to nested guests Mark Brown
` (6 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown
As per DDI0487 R_TYTWB GCS adds an additional case where an illegal
exception return can be generated. If all of:
- PSTATE.EXLOCK is 0.
- The EL is not being changed by the ERET.
- GCSCR_ELx.EXLOCKEN is 1.
are true then the return is illegal. Emulate this behaviour when
emulating ERET for nested guests, while we're at it using the symbolic
definition for EXLOCK in SPSR.
Reviewed-by: Leonardo Bras <leo.bras@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/include/asm/kvm_nested.h | 32 ++++++++++++++++++++++++++++++++
arch/arm64/kvm/emulate-nested.c | 7 +++++--
arch/arm64/kvm/hyp/vhe/switch.c | 4 ++++
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h
index 27ec73da02c6..a158de5f4f92 100644
--- a/arch/arm64/include/asm/kvm_nested.h
+++ b/arch/arm64/include/asm/kvm_nested.h
@@ -268,6 +268,38 @@ static inline bool kvm_auth_eretax(struct kvm_vcpu *vcpu, u64 *elr)
}
#endif
+#ifdef CONFIG_ARM64_GCS
+/* See IllegalExceptionReturn() pseudocode */
+static inline bool kvm_check_illegal_exlock_return(struct kvm_vcpu *vcpu,
+ u64 spsr)
+{
+ u64 pstate, cur_mode, target_mode;
+
+ if (!kvm_has_gcs(vcpu->kvm))
+ return false;
+
+ if (vcpu->arch.ctxt.regs.pstate & PSR_EXLOCK_BIT)
+ return false;
+
+ /* Check the EL only, ignore thread mode */
+ pstate = vcpu->arch.ctxt.regs.pstate;
+ cur_mode = (pstate & PSR_MODE_MASK) | PSR_MODE_THREAD_BIT;
+ target_mode = (spsr & PSR_MODE_MASK) | PSR_MODE_THREAD_BIT;
+
+ if (cur_mode != target_mode)
+ return false;
+
+ return vcpu_read_sys_reg(vcpu, GCSCR_EL2) & GCSCR_ELx_EXLOCKEN;
+}
+
+#else
+static inline bool kvm_check_illegal_exlock_return(struct kvm_vcpu *vcpu,
+ u64 spsr)
+{
+ return false;
+}
+#endif
+
#define KVM_NV_GUEST_MAP_SZ (KVM_PGTABLE_PROT_SW1 | KVM_PGTABLE_PROT_SW0)
static inline u64 kvm_encode_nested_level(struct kvm_s2_trans *trans)
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index cb9bf3b9340a..c4a33f1f6ad4 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -2755,10 +2755,13 @@ static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr)
* - trying to return to an illegal M value
* - trying to return to a 32bit EL
* - trying to return to EL1 with HCR_EL2.TGE set
+ * - GCSCR_ELx.EXLOCKEN is 1 and PSTATE.EXLOCK is 0 when attempting
+ * to return to the same EL.
*/
if (mode == PSR_MODE_EL3t || mode == PSR_MODE_EL3h ||
mode == 0b00001 || (mode & BIT(1)) ||
(spsr & PSR_MODE32_BIT) ||
+ kvm_check_illegal_exlock_return(vcpu, spsr) ||
(vcpu_el2_tge_is_set(vcpu) && (mode == PSR_MODE_EL1t ||
mode == PSR_MODE_EL1h))) {
u64 mask;
@@ -2784,8 +2787,8 @@ static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr)
spsr &= mask;
mask = PSR_MODE_MASK | PSR_MODE32_BIT;
- if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, GCS, IMP))
- mask |= BIT_ULL(34); /* PSTATE.EXLOCK */
+ if (kvm_has_gcs(vcpu->kvm))
+ mask |= PSR_EXLOCK_BIT;
spsr |= *vcpu_cpsr(vcpu) & mask;
spsr |= PSR_IL_BIT;
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 5f7a46c4f516..12e9762e1a86 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -395,6 +395,10 @@ static bool kvm_hyp_handle_eret(struct kvm_vcpu *vcpu, u64 *exit_code)
return false;
}
+ /* Push GCS exception lock failures into the slow path */
+ if (kvm_check_illegal_exlock_return(vcpu, spsr))
+ return false;
+
/* If ERETAx fails, take the slow path */
if (esr_iss_is_eretax(esr)) {
if (!(vcpu_has_ptrauth(vcpu) && kvm_auth_eretax(vcpu, &elr)))
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 07/16] KVM: arm64: Forward GCS exceptions to nested guests
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (3 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 06/16] KVM: arm64: Validate GCS exception lock when emulating ERET Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker Mark Brown
` (5 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown, Lorenzo Stoakes (ARM)
For nested guests where HFGITR_EL2.nGCSSTR_EL1 is clear or when there are
L2 GCS data check exceptions we need to forward the exception to the guest.
Add handling to do so.
Reviewed-by: Leonardo Bras <leo.bras@arm.com>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/kvm/handle_exit.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index 9931192735d4..acd97a435910 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -304,12 +304,24 @@ static int handle_svc(struct kvm_vcpu *vcpu)
return 1;
}
+/*
+ * We might get GCS exceptions that need to be forwarded to the
+ * hypervisor when a nested guest has HFGITR_EL2.nGCSSTR_EL1 clear, or
+ * for a GCS data check exception for a L2 guest.
+ */
static int kvm_handle_gcs(struct kvm_vcpu *vcpu)
{
- /* We don't expect GCS, so treat it with contempt */
- if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, GCS, IMP))
- WARN_ON_ONCE(1);
+ if (!kvm_has_gcs(vcpu->kvm)) {
+ kvm_inject_undefined(vcpu);
+ return 1;
+ }
+ if (vcpu_has_nv(vcpu)) {
+ kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
+ return 1;
+ }
+
+ WARN_ON_ONCE(1);
kvm_inject_undefined(vcpu);
return 1;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (4 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 07/16] KVM: arm64: Forward GCS exceptions to nested guests Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests Mark Brown
` (4 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown
When the VM exposes FEAT_GCS the GCS encoding 0b1001 grants read and
GCS access. In the EL1&0 and EL2&0 translation regimes, DDI0487 R_VFPJF
removes all base permissions when privileged execute or GCS access
coincides with unprivileged write or GCS access. Include it on both
sides of that check so software AT reports the same permission fault as
hardware.
Note that (as with the current code's handling of readability for GCS
pages) we don't gate anything on the guest having FEAT_GCS, this matches
the hardware behaviour if a guest uses this encoding on a host with GCS.
A guest that does not see FEAT_GCS should not be creating any pages with
GCS permissions and the effects are only visible within the guest.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/kvm/at.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c
index 30d8f062b2c2..42180f694093 100644
--- a/arch/arm64/kvm/at.c
+++ b/arch/arm64/kvm/at.c
@@ -1128,7 +1128,7 @@ static void compute_s1_hierarchical_permissions(struct kvm_vcpu *vcpu,
(wr)->uwxn = (v); \
} while (0)
-/* Similar to AArch64.S1IndirectBasePermissions(), without GCS */
+/* Decode the read, write and execute bits of S1IndirectBasePermissions(). */
#define set_perms(w, wr, ip) \
do { \
/* R_LLZDZ */ \
@@ -1222,7 +1222,7 @@ static void compute_s1_indirect_permissions(struct kvm_vcpu *vcpu,
wr->uov = wi->e0poe && !(up & BIT(3));
/* R_VFPJF */
- if (wr->px && wr->uw) {
+ if ((wr->px || pp == PIE_GCS) && (wr->uw || up == PIE_GCS)) {
set_priv_perms(wr, false, false, false);
set_unpriv_perms(wr, false, false, false);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (5 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 11/16] KVM: selftests: arm64: Check invalid feature combination handling Mark Brown
` (3 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown
Now that required functionality for GCS is in place expose
ID_AA64PFR1_EL1.GCS, allowing guests to be given the feature.
Enforce the architectural dependency on S1PIE.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/kvm/config.c | 14 ++++++++++++++
arch/arm64/kvm/nested.c | 3 +--
arch/arm64/kvm/sys_regs.c | 5 +++--
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
index 6f668148ccc1..4e9c4cbba9af 100644
--- a/arch/arm64/kvm/config.c
+++ b/arch/arm64/kvm/config.c
@@ -330,6 +330,12 @@ static bool feat_s1poe(struct kvm *kvm)
kvm_has_feat(kvm, FEAT_HPDS));
}
+static bool feat_gcs(struct kvm *kvm)
+{
+ return (kvm_has_feat(kvm, FEAT_GCS) &&
+ kvm_has_feat(kvm, FEAT_S1PIE));
+}
+
static bool feat_sme_smps(struct kvm *kvm)
{
/*
@@ -1442,6 +1448,13 @@ static const struct reg_bits_to_feat_map id_aa64mmfr3_el1_feat_map[] = {
static const DECLARE_IDREG_FEAT_MAP(id_aa64mmfr3_el1_desc, ID_AA64MMFR3_EL1,
id_aa64mmfr3_el1_feat_map, FEAT_AA64EL1);
+static const struct reg_bits_to_feat_map id_aa64pfr1_el1_feat_map[] = {
+ NEEDS_FEAT(ID_AA64PFR1_EL1_GCS, feat_gcs),
+};
+
+static const DECLARE_IDREG_FEAT_MAP(id_aa64pfr1_el1_desc, ID_AA64PFR1_EL1,
+ id_aa64pfr1_el1_feat_map, FEAT_AA64EL1);
+
static const struct reg_bits_to_feat_map ich_hfgrtr_feat_map[] = {
NEEDS_FEAT(ICH_HFGRTR_EL2_ICC_APR_EL1 |
ICH_HFGRTR_EL2_ICC_IDRn_EL1 |
@@ -1555,6 +1568,7 @@ void __init check_feature_map(void)
static const struct reg_feat_map_desc *idreg_feat_maps[] = {
&id_aa64mmfr3_el1_desc,
+ &id_aa64pfr1_el1_desc,
};
static bool idreg_apply_deps(struct kvm *kvm, const struct reg_feat_map_desc *r)
diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index ed10c8b41cc8..bea2816b6218 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -1857,11 +1857,10 @@ u64 limit_nv_id_reg(struct kvm *kvm, u32 reg, u64 val)
break;
case SYS_ID_AA64PFR1_EL1:
- /* Only support BTI, SSBS, CSV2_frac */
+ /* Only support GCS, BTI, SSBS, CSV2_frac */
val &= ~(ID_AA64PFR1_EL1_PFAR |
ID_AA64PFR1_EL1_MTEX |
ID_AA64PFR1_EL1_THE |
- ID_AA64PFR1_EL1_GCS |
ID_AA64PFR1_EL1_MTE_frac |
ID_AA64PFR1_EL1_NMI |
ID_AA64PFR1_EL1_SME |
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 3fc9e47a3c39..16311d87661b 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -2192,10 +2192,12 @@ static u64 sanitise_id_aa64pfr1_el1(const struct kvm_vcpu *vcpu, u64 val)
SYS_FIELD_GET(ID_AA64PFR0_EL1, RAS, pfr0) == ID_AA64PFR0_EL1_RAS_IMP))
val &= ~ID_AA64PFR1_EL1_RAS_frac;
+ if (!system_supports_gcs())
+ val &= ~ID_AA64PFR1_EL1_GCS;
+
val &= ~ID_AA64PFR1_EL1_SME;
val &= ~ID_AA64PFR1_EL1_RNDR_trap;
val &= ~ID_AA64PFR1_EL1_NMI;
- val &= ~ID_AA64PFR1_EL1_GCS;
val &= ~ID_AA64PFR1_EL1_THE;
val &= ~ID_AA64PFR1_EL1_MTEX;
val &= ~ID_AA64PFR1_EL1_PFAR;
@@ -3403,7 +3405,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
~(ID_AA64PFR1_EL1_PFAR |
ID_AA64PFR1_EL1_MTEX |
ID_AA64PFR1_EL1_THE |
- ID_AA64PFR1_EL1_GCS |
ID_AA64PFR1_EL1_MTE_frac |
ID_AA64PFR1_EL1_NMI |
ID_AA64PFR1_EL1_RNDR_trap |
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 11/16] KVM: selftests: arm64: Check invalid feature combination handling
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (6 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 12/16] KVM: selftests: arm64: Add GCS registers to get-reg-list Mark Brown
` (2 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown
In order to optimise fast paths KVM explicitly suppresses configurations
with S1PIE or S1POE but not TCR2, add coverage of this in the
set_id_regs test.
We have a list of invalid configurations, for each of them we try to run
a VM and fail the test if after running the VM any of the feature fields
involved are non-zero. This will need revisiting if we start filtering
more complex combinations but is fine for now.
We do feature detection by validating that we can write the fields with
failing values.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/kvm/arm64/set_id_regs.c | 97 +++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/set_id_regs.c b/tools/testing/selftests/kvm/arm64/set_id_regs.c
index 1d2cc25cb3f4..bea4dab7496c 100644
--- a/tools/testing/selftests/kvm/arm64/set_id_regs.c
+++ b/tools/testing/selftests/kvm/arm64/set_id_regs.c
@@ -916,6 +916,100 @@ static void test_idreg_frozen_after_failed_run(void)
ksft_test_result_pass("%s\n", __func__);
}
+struct reg_ftr_val {
+ const char *name;
+ u64 reg;
+ u64 mask;
+ u64 val;
+};
+
+#define REG_FTR_VAL(r, f, v) \
+ { .name = #r "." #f, \
+ .reg = ARM64_SYS_REG(sys_reg_Op0(SYS_ ## r), \
+ sys_reg_Op1(SYS_ ## r), \
+ sys_reg_CRn(SYS_ ## r), \
+ sys_reg_CRm(SYS_ ## r), \
+ sys_reg_Op2(SYS_ ## r)), \
+ .mask = r ## _ ## f ## _MASK, \
+ .val = (r ## _ ## f ## _ ## v << r ## _ ## f ## _SHIFT) }
+
+static const struct reg_ftr_val s1pie_no_tcr2[] = {
+ REG_FTR_VAL(ID_AA64MMFR3_EL1, TCRX, NI),
+ REG_FTR_VAL(ID_AA64MMFR3_EL1, S1PIE, IMP),
+ { }
+};
+
+static const struct reg_ftr_val s1poe_no_tcr2[] = {
+ REG_FTR_VAL(ID_AA64MMFR3_EL1, TCRX, NI),
+ REG_FTR_VAL(ID_AA64MMFR3_EL1, S1POE, IMP),
+ { }
+};
+
+struct ftr_config {
+ const char *name;
+ const struct reg_ftr_val *regs;
+};
+
+static const struct ftr_config invalid_configs[] = {
+ { .name = "S1PIE without TCRX", .regs = s1pie_no_tcr2 },
+ { .name = "S1POE without TCRX", .regs = s1poe_no_tcr2 },
+};
+
+static void test_invalid_config(const struct ftr_config *config)
+{
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ const struct reg_ftr_val *field;
+ u64 val;
+ bool pass = true;
+
+ vm = vm_create(1);
+ vm_enable_cap(vm, KVM_CAP_ARM_WRITABLE_IMP_ID_REGS, 0);
+ vcpu = vm_vcpu_add(vm, 0, guest_code);
+ kvm_arch_vm_finalize_vcpus(vm);
+
+ /*
+ * If we don't manage to set any of the fields assume the
+ * system does not support the feature and skip the test.
+ */
+ for (field = config->regs; field->reg; field++) {
+ val = vcpu_get_reg(vcpu, field->reg);
+ val &= ~field->mask;
+ val |= field->val;
+ __vcpu_set_reg(vcpu, field->reg, val);
+
+ if (vcpu_get_reg(vcpu, field->reg) != val) {
+ ksft_print_msg("Test setup not supported\n");
+ ksft_test_result_skip("filter out %s\n", config->name);
+ goto out;
+ }
+ }
+
+ vcpu_run(vcpu);
+
+ for (field = config->regs; field->reg; field++) {
+ /* For now all invalid values reset to 0 */
+ val = vcpu_get_reg(vcpu, field->reg) & field->mask;
+ if (val) {
+ ksft_print_msg("%s is %lx not 0\n", field->name, val);
+ pass = false;
+ }
+ }
+
+ ksft_test_result(pass, "filter out %s\n",
+ config->name);
+out:
+ kvm_vm_free(vm);
+}
+
+static void test_invalid_configs(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(invalid_configs); i++)
+ test_invalid_config(&invalid_configs[i]);
+}
+
int main(void)
{
struct kvm_vcpu *vcpu;
@@ -942,6 +1036,7 @@ int main(void)
ksft_print_header();
test_cnt = 4 + MPAM_IDREG_TEST + MTE_IDREG_TEST;
+ test_cnt += ARRAY_SIZE(invalid_configs);
for (i = 0; i < ARRAY_SIZE(test_regs); i++)
for (j = 0; test_regs[i].ftr_bits[j].type != FTR_END; j++)
test_cnt++;
@@ -962,5 +1057,7 @@ int main(void)
test_idreg_frozen_after_failed_run();
+ test_invalid_configs();
+
ksft_finished();
}
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 12/16] KVM: selftests: arm64: Add GCS registers to get-reg-list
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (7 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 11/16] KVM: selftests: arm64: Check invalid feature combination handling Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 13/16] KVM: selftests: arm64: Add GCS to set_id_regs Mark Brown
2026-11-30 16:35 ` [PATCH v22 15/16] tools: Synchronise the kernel esr.h Mark Brown
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown, Thiago Jung Bauermann,
Lorenzo Stoakes (ARM)
GCS adds new registers GCSCR_ELx, GCSCRE0_EL1 and GCSPR_ELx. Add
these to those validated by get-reg-list.
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/kvm/arm64/get-reg-list.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/get-reg-list.c b/tools/testing/selftests/kvm/arm64/get-reg-list.c
index 912590f9b0c2..993c137e4e4c 100644
--- a/tools/testing/selftests/kvm/arm64/get-reg-list.c
+++ b/tools/testing/selftests/kvm/arm64/get-reg-list.c
@@ -42,6 +42,12 @@ struct feature_id_reg {
static struct feature_id_reg feat_id_regs[] = {
REG_FEAT(TCR2_EL1, ID_AA64MMFR3_EL1, TCRX, IMP),
REG_FEAT(TCR2_EL2, ID_AA64MMFR3_EL1, TCRX, IMP),
+ REG_FEAT(GCSPR_EL0, ID_AA64PFR1_EL1, GCS, IMP),
+ REG_FEAT(GCSPR_EL1, ID_AA64PFR1_EL1, GCS, IMP),
+ REG_FEAT(GCSPR_EL2, ID_AA64PFR1_EL1, GCS, IMP),
+ REG_FEAT(GCSCRE0_EL1, ID_AA64PFR1_EL1, GCS, IMP),
+ REG_FEAT(GCSCR_EL1, ID_AA64PFR1_EL1, GCS, IMP),
+ REG_FEAT(GCSCR_EL2, ID_AA64PFR1_EL1, GCS, IMP),
REG_FEAT(PIRE0_EL1, ID_AA64MMFR3_EL1, S1PIE, IMP),
REG_FEAT(PIRE0_EL2, ID_AA64MMFR3_EL1, S1PIE, IMP),
REG_FEAT(PIR_EL1, ID_AA64MMFR3_EL1, S1PIE, IMP),
@@ -504,6 +510,9 @@ static __u64 base_regs[] = {
ARM64_SYS_REG(3, 0, 2, 0, 1), /* TTBR1_EL1 */
ARM64_SYS_REG(3, 0, 2, 0, 2), /* TCR_EL1 */
ARM64_SYS_REG(3, 0, 2, 0, 3), /* TCR2_EL1 */
+ ARM64_SYS_REG(3, 0, 2, 5, 0), /* GCSCR_EL1 */
+ ARM64_SYS_REG(3, 0, 2, 5, 1), /* GCSPR_EL1 */
+ ARM64_SYS_REG(3, 0, 2, 5, 2), /* GCSCRE0_EL1 */
ARM64_SYS_REG(3, 0, 5, 1, 0), /* AFSR0_EL1 */
ARM64_SYS_REG(3, 0, 5, 1, 1), /* AFSR1_EL1 */
ARM64_SYS_REG(3, 0, 5, 2, 0), /* ESR_EL1 */
@@ -521,6 +530,7 @@ static __u64 base_regs[] = {
ARM64_SYS_REG(3, 0, 13, 0, 5), /* ACCDATA_EL1 */
ARM64_SYS_REG(3, 0, 14, 1, 0), /* CNTKCTL_EL1 */
ARM64_SYS_REG(3, 2, 0, 0, 0), /* CSSELR_EL1 */
+ ARM64_SYS_REG(3, 3, 2, 5, 1), /* GCSPR_EL0 */
ARM64_SYS_REG(3, 3, 10, 2, 4), /* POR_EL0 */
ARM64_SYS_REG(3, 3, 13, 0, 2), /* TPIDR_EL0 */
ARM64_SYS_REG(3, 3, 13, 0, 3), /* TPIDRRO_EL0 */
@@ -742,6 +752,8 @@ static __u64 el2_regs[] = {
SYS_REG(VTTBR_EL2),
SYS_REG(VTCR_EL2),
SYS_REG(VNCR_EL2),
+ SYS_REG(GCSCR_EL2),
+ SYS_REG(GCSPR_EL2),
SYS_REG(HDFGRTR2_EL2),
SYS_REG(HDFGWTR2_EL2),
SYS_REG(HFGRTR2_EL2),
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 13/16] KVM: selftests: arm64: Add GCS to set_id_regs
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (8 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 12/16] KVM: selftests: arm64: Add GCS registers to get-reg-list Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 15/16] tools: Synchronise the kernel esr.h Mark Brown
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown, Lorenzo Stoakes (ARM)
Now that GCS is configurable via the ID registers update set_id_regs to
cover ID_AA64PFR1_EL1.GCS.
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/kvm/arm64/set_id_regs.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/set_id_regs.c b/tools/testing/selftests/kvm/arm64/set_id_regs.c
index bea4dab7496c..abcb84fd2fe7 100644
--- a/tools/testing/selftests/kvm/arm64/set_id_regs.c
+++ b/tools/testing/selftests/kvm/arm64/set_id_regs.c
@@ -155,6 +155,7 @@ static const struct reg_ftr_bits ftr_id_aa64pfr0_el1[] = {
static const struct reg_ftr_bits ftr_id_aa64pfr1_el1[] = {
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64PFR1_EL1, DF2, 0),
+ REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64PFR1_EL1, GCS, 0),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64PFR1_EL1, CSV2_frac, 0),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64PFR1_EL1, SSBS, ID_AA64PFR1_EL1_SSBS_NI),
REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64PFR1_EL1, BT, 0),
@@ -933,6 +934,12 @@ struct reg_ftr_val {
.mask = r ## _ ## f ## _MASK, \
.val = (r ## _ ## f ## _ ## v << r ## _ ## f ## _SHIFT) }
+static const struct reg_ftr_val gcs_no_s1pie[] = {
+ REG_FTR_VAL(ID_AA64PFR1_EL1, GCS, IMP),
+ REG_FTR_VAL(ID_AA64MMFR3_EL1, S1PIE, NI),
+ { }
+};
+
static const struct reg_ftr_val s1pie_no_tcr2[] = {
REG_FTR_VAL(ID_AA64MMFR3_EL1, TCRX, NI),
REG_FTR_VAL(ID_AA64MMFR3_EL1, S1PIE, IMP),
@@ -951,6 +958,7 @@ struct ftr_config {
};
static const struct ftr_config invalid_configs[] = {
+ { .name = "GCS without S1PIE", .regs = gcs_no_s1pie },
{ .name = "S1PIE without TCRX", .regs = s1pie_no_tcr2 },
{ .name = "S1POE without TCRX", .regs = s1poe_no_tcr2 },
};
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v22 15/16] tools: Synchronise the kernel esr.h
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
` (9 preceding siblings ...)
2026-11-30 16:35 ` [PATCH v22 13/16] KVM: selftests: arm64: Add GCS to set_id_regs Mark Brown
@ 2026-11-30 16:35 ` Mark Brown
10 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2026-11-30 16:35 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon, Marc Zyngier, Joey Gouly,
Suzuki K Poulose, Shuah Khan, Oliver Upton, Fuad Tabba
Cc: Peter Maydell, Leonardo Bras, Wei-Lin Chang, Yao Yuan,
linux-arm-kernel, linux-doc, kvmarm, linux-kselftest,
linux-kernel, Mark Brown
To pick up definitions for GCS.
Reviewed-by: Leonardo Bras <leo.bras@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/arch/arm64/include/asm/esr.h | 146 ++++++++++++++++++++++++++++++++++---
1 file changed, 134 insertions(+), 12 deletions(-)
diff --git a/tools/arch/arm64/include/asm/esr.h b/tools/arch/arm64/include/asm/esr.h
index f3c6403e5ef2..a584f88dbaf9 100644
--- a/tools/arch/arm64/include/asm/esr.h
+++ b/tools/arch/arm64/include/asm/esr.h
@@ -3,10 +3,12 @@
* Copyright (C) 2013 - ARM Ltd
* Author: Marc Zyngier <marc.zyngier@arm.com>
*/
+/* Whole file is shared with s390 */
#ifndef __ASM_ESR_H
#define __ASM_ESR_H
+#include <asm/brk-imm.h>
#include <asm/sysreg.h>
#define ESR_ELx_EC_UNKNOWN UL(0x00)
@@ -19,7 +21,8 @@
#define ESR_ELx_EC_FP_ASIMD UL(0x07)
#define ESR_ELx_EC_CP10_ID UL(0x08) /* EL2 only */
#define ESR_ELx_EC_PAC UL(0x09) /* EL2 and above */
-/* Unallocated EC: 0x0A - 0x0B */
+#define ESR_ELx_EC_OTHER UL(0x0A)
+/* Unallocated EC: 0x0B */
#define ESR_ELx_EC_CP14_64 UL(0x0C)
#define ESR_ELx_EC_BTI UL(0x0D)
#define ESR_ELx_EC_ILL UL(0x0E)
@@ -50,7 +53,8 @@
#define ESR_ELx_EC_FP_EXC32 UL(0x28)
/* Unallocated EC: 0x29 - 0x2B */
#define ESR_ELx_EC_FP_EXC64 UL(0x2C)
-/* Unallocated EC: 0x2D - 0x2E */
+#define ESR_ELx_EC_GCS UL(0x2D)
+/* Unallocated EC: 0x2E */
#define ESR_ELx_EC_SERROR UL(0x2F)
#define ESR_ELx_EC_BREAKPT_LOW UL(0x30)
#define ESR_ELx_EC_BREAKPT_CUR UL(0x31)
@@ -97,6 +101,8 @@
#define ESR_ELx_AET_CE (UL(6) << ESR_ELx_AET_SHIFT)
/* Shared ISS field definitions for Data/Instruction aborts */
+#define ESR_ELx_VNCR_SHIFT (13)
+#define ESR_ELx_VNCR (UL(1) << ESR_ELx_VNCR_SHIFT)
#define ESR_ELx_SET_SHIFT (11)
#define ESR_ELx_SET_MASK (UL(3) << ESR_ELx_SET_SHIFT)
#define ESR_ELx_FnV_SHIFT (10)
@@ -119,6 +125,16 @@
#define ESR_ELx_FSC_SEA_TTW(n) (0x14 + (n))
#define ESR_ELx_FSC_SECC (0x18)
#define ESR_ELx_FSC_SECC_TTW(n) (0x1c + (n))
+#define ESR_ELx_FSC_EXCL_ATOMIC (0x35)
+#define ESR_ELx_FSC_ADDRSZ (0x00)
+
+/*
+ * Annoyingly, the negative levels for Address size faults aren't laid out
+ * contiguously (or in the desired order)
+ */
+#define ESR_ELx_FSC_ADDRSZ_nL(n) ((n) == -1 ? 0x29 : 0x2C)
+#define ESR_ELx_FSC_ADDRSZ_L(n) ((n) < 0 ? ESR_ELx_FSC_ADDRSZ_nL(n) : \
+ (ESR_ELx_FSC_ADDRSZ + (n)))
/* Status codes for individual page table levels */
#define ESR_ELx_FSC_ACCESS_L(n) (ESR_ELx_FSC_ACCESS + (n))
@@ -141,12 +157,12 @@
#define ESR_ELx_SF (UL(1) << ESR_ELx_SF_SHIFT)
#define ESR_ELx_AR_SHIFT (14)
#define ESR_ELx_AR (UL(1) << ESR_ELx_AR_SHIFT)
-#define ESR_ELx_VNCR_SHIFT (13)
-#define ESR_ELx_VNCR (UL(1) << ESR_ELx_VNCR_SHIFT)
#define ESR_ELx_CM_SHIFT (8)
#define ESR_ELx_CM (UL(1) << ESR_ELx_CM_SHIFT)
/* ISS2 field definitions for Data Aborts */
+#define ESR_ELx_HDBSSF_SHIFT (11)
+#define ESR_ELx_HDBSSF (UL(1) << ESR_ELx_HDBSSF_SHIFT)
#define ESR_ELx_TnD_SHIFT (10)
#define ESR_ELx_TnD (UL(1) << ESR_ELx_TnD_SHIFT)
#define ESR_ELx_TagAccess_SHIFT (9)
@@ -161,8 +177,6 @@
#define ESR_ELx_Xs_MASK (GENMASK_ULL(4, 0))
/* ISS field definitions for exceptions taken in to Hyp */
-#define ESR_ELx_FSC_ADDRSZ (0x00)
-#define ESR_ELx_FSC_ADDRSZ_L(n) (ESR_ELx_FSC_ADDRSZ + (n))
#define ESR_ELx_CV (UL(1) << 24)
#define ESR_ELx_COND_SHIFT (20)
#define ESR_ELx_COND_MASK (UL(0xF) << ESR_ELx_COND_SHIFT)
@@ -174,6 +188,13 @@
#define ESR_ELx_WFx_ISS_WFE (UL(1) << 0)
#define ESR_ELx_xVC_IMM_MASK ((UL(1) << 16) - 1)
+/* ISS definitions for LD64B/ST64B/{T,P}SBCSYNC instructions */
+#define ESR_ELx_ISS_OTHER_ST64BV (0)
+#define ESR_ELx_ISS_OTHER_ST64BV0 (1)
+#define ESR_ELx_ISS_OTHER_LDST64B (2)
+#define ESR_ELx_ISS_OTHER_TSBCSYNC (3)
+#define ESR_ELx_ISS_OTHER_PSBCSYNC (4)
+
#define DISR_EL1_IDS (UL(1) << 24)
/*
* DISR_EL1 and ESR_ELx share the bottom 13 bits, but the RES0 bits may mean
@@ -371,12 +392,14 @@
/*
* ISS values for SME traps
*/
+#define ESR_ELx_SME_ISS_SMTC_MASK GENMASK(2, 0)
+#define ESR_ELx_SME_ISS_SMTC(esr) ((esr) & ESR_ELx_SME_ISS_SMTC_MASK)
-#define ESR_ELx_SME_ISS_SME_DISABLED 0
-#define ESR_ELx_SME_ISS_ILL 1
-#define ESR_ELx_SME_ISS_SM_DISABLED 2
-#define ESR_ELx_SME_ISS_ZA_DISABLED 3
-#define ESR_ELx_SME_ISS_ZT_DISABLED 4
+#define ESR_ELx_SME_ISS_SMTC_SME_DISABLED 0
+#define ESR_ELx_SME_ISS_SMTC_ILL 1
+#define ESR_ELx_SME_ISS_SMTC_SM_DISABLED 2
+#define ESR_ELx_SME_ISS_SMTC_ZA_DISABLED 3
+#define ESR_ELx_SME_ISS_SMTC_ZT_DISABLED 4
/* ISS field definitions for MOPS exceptions */
#define ESR_ELx_MOPS_ISS_MEM_INST (UL(1) << 24)
@@ -387,8 +410,62 @@
#define ESR_ELx_MOPS_ISS_SRCREG(esr) (((esr) & (UL(0x1f) << 5)) >> 5)
#define ESR_ELx_MOPS_ISS_SIZEREG(esr) (((esr) & (UL(0x1f) << 0)) >> 0)
+/* ISS field definitions for GCS */
+#define ESR_ELx_ExType_SHIFT (20)
+#define ESR_ELx_ExType_MASK GENMASK(23, 20)
+#define ESR_ELx_Raddr_SHIFT (10)
+#define ESR_ELx_Raddr_MASK GENMASK(14, 10)
+#define ESR_ELx_Rn_SHIFT (5)
+#define ESR_ELx_Rn_MASK GENMASK(9, 5)
+#define ESR_ELx_Rvalue_SHIFT 5
+#define ESR_ELx_Rvalue_MASK GENMASK(9, 5)
+#define ESR_ELx_IT_SHIFT (0)
+#define ESR_ELx_IT_MASK GENMASK(4, 0)
+
+#define ESR_ELx_ExType_DATA_CHECK 0
+#define ESR_ELx_ExType_EXLOCK 1
+#define ESR_ELx_ExType_STR 2
+
+#define ESR_ELx_IT_RET 0
+#define ESR_ELx_IT_GCSPOPM 1
+#define ESR_ELx_IT_RET_KEYA 2
+#define ESR_ELx_IT_RET_KEYB 3
+#define ESR_ELx_IT_GCSSS1 4
+#define ESR_ELx_IT_GCSSS2 5
+#define ESR_ELx_IT_GCSPOPCX 6
+#define ESR_ELx_IT_GCSPOPX 7
+
#ifndef __ASSEMBLER__
-#include <asm/types.h>
+#include <linux/types.h>
+
+static __always_inline bool esr_trap_is_iabt(unsigned long esr)
+{
+ return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_LOW;
+}
+
+/* Always check for S1PTW *before* using this. */
+static __always_inline bool esr_dabt_is_write(unsigned long esr)
+{
+ return esr & ESR_ELx_WNR;
+}
+
+static __always_inline bool esr_dabt_is_cm(unsigned long esr)
+{
+ return esr & ESR_ELx_CM;
+}
+
+static __always_inline bool esr_abt_is_sea(unsigned long esr)
+{
+ switch (esr & ESR_ELx_FSC) {
+ case ESR_ELx_FSC_EXTABT:
+ case ESR_ELx_FSC_SEA_TTW(-1) ... ESR_ELx_FSC_SEA_TTW(3):
+ case ESR_ELx_FSC_SECC:
+ case ESR_ELx_FSC_SECC_TTW(-1) ... ESR_ELx_FSC_SECC_TTW(3):
+ return true;
+ default:
+ return false;
+ }
+}
static inline unsigned long esr_brk_comment(unsigned long esr)
{
@@ -408,6 +485,11 @@ static inline bool esr_is_cfi_brk(unsigned long esr)
(esr_brk_comment(esr) & ~CFI_BRK_IMM_MASK) == CFI_BRK_IMM_BASE;
}
+static inline bool esr_is_ubsan_brk(unsigned long esr)
+{
+ return (esr_brk_comment(esr) & ~UBSAN_BRK_MASK) == UBSAN_BRK_IMM;
+}
+
static inline bool esr_fsc_is_translation_fault(unsigned long esr)
{
esr = esr & ESR_ELx_FSC;
@@ -439,6 +521,46 @@ static inline bool esr_fsc_is_access_flag_fault(unsigned long esr)
(esr == ESR_ELx_FSC_ACCESS_L(0));
}
+static inline bool esr_fsc_is_excl_atomic_fault(unsigned long esr)
+{
+ esr = esr & ESR_ELx_FSC;
+
+ return esr == ESR_ELx_FSC_EXCL_ATOMIC;
+}
+
+static inline bool esr_fsc_is_addr_sz_fault(unsigned long esr)
+{
+ esr &= ESR_ELx_FSC;
+
+ return (esr == ESR_ELx_FSC_ADDRSZ_L(3)) ||
+ (esr == ESR_ELx_FSC_ADDRSZ_L(2)) ||
+ (esr == ESR_ELx_FSC_ADDRSZ_L(1)) ||
+ (esr == ESR_ELx_FSC_ADDRSZ_L(0)) ||
+ (esr == ESR_ELx_FSC_ADDRSZ_L(-1));
+}
+
+static inline bool esr_fsc_is_sea_ttw(unsigned long esr)
+{
+ esr = esr & ESR_ELx_FSC;
+
+ return (esr == ESR_ELx_FSC_SEA_TTW(3)) ||
+ (esr == ESR_ELx_FSC_SEA_TTW(2)) ||
+ (esr == ESR_ELx_FSC_SEA_TTW(1)) ||
+ (esr == ESR_ELx_FSC_SEA_TTW(0)) ||
+ (esr == ESR_ELx_FSC_SEA_TTW(-1));
+}
+
+static inline bool esr_fsc_is_secc_ttw(unsigned long esr)
+{
+ esr = esr & ESR_ELx_FSC;
+
+ return (esr == ESR_ELx_FSC_SECC_TTW(3)) ||
+ (esr == ESR_ELx_FSC_SECC_TTW(2)) ||
+ (esr == ESR_ELx_FSC_SECC_TTW(1)) ||
+ (esr == ESR_ELx_FSC_SECC_TTW(0)) ||
+ (esr == ESR_ELx_FSC_SECC_TTW(-1));
+}
+
/* Indicate whether ESR.EC==0x1A is for an ERETAx instruction */
static inline bool esr_iss_is_eretax(unsigned long esr)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 14+ messages in thread