[PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker

From: Mark Brown

Date: Mon Nov 30 2026 - 11:43:57 EST


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@xxxxxxxxxx>
---
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