Re: [PATCH v19 03/14] KVM: arm64: Manage GCS access and registers for guests

Mark Brown <[email protected]>
Newsgroups org.kernel.vger.linux-doc,dev.linux.lists.kvmarm,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest
Message-ID <[email protected]>
On Wed, Aug 19, 2026 at 05:32:25PM +0100, Leonardo Bras wrote:
> On Wed, Aug 12, 2026 at 08:12:02PM +0100, Mark Brown wrote:

> > 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.

> It is zero on reset, and keeping it in zero disables GCS in EL0&EL1, so 
> unless we are in EL2&0 (HCR_EL2.{E2H, TGE} is {1, 1}), we need to enable it 
> so EL1&0 (guests) can have access to it.

Right.

> > @@ -77,6 +80,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));

> Out of curiosity here,
> Why does the saving of GCSCR_EL2 depends on ctxt_has_tcrx() (and E2H set), 
> and saving SYS_GCSPR does not? ...

This is just because there isn't a preexisting ctxt_has_tcrx() check
already there, FEAT_GCS architecturally depends on FEAT_TCRX and there
was a request to make this explicit in the code to try to optimise
things a bit.  The compiler should skip over both blocks at once if TCRX
isn't there rather than having two separate tests or static branches.  I
didn't add new checks where there were none since I expect that to be
unhelpful for code generation, you'd get the reverse situation and emit
two checks.
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmqF3ccACgkQJNaLcl1U
h9CcQQf+IxvaF1y9eqa1wPv0kD6ec4r4UKmxZU1Sj6EfStbT+DJpeDDZmbR5wLHi
UIbnCP1BlGVPGIw8QfCpH7x1W3Vk397dUmfHNuEv/HACcnIe7J+3TMA3I0bSD49i
eY7wVTezjJGRBNMtLzFVT9Ed1mK7iZ3xeD2oU7ii0abLeBMmEwuQyvroT6nLqa6I
hmtlWxH5Ps5ol3qaxoD+w12M6YlkXLucm5OgMZ+gpQM0JuQaxOb2UUxBb64PhcH2
0cdjq7xLFg2kz8kdcitYNVmbE34x/2ZJfg4RSV0AT4B5D6Mst3zXJLI8gVcWjO7e
hZdv8j5JdWYVkbXUdOYTVL0HppvTgw==
=FnPL
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.