[PATCH v14 0/5] KVM: arm64: Provide guest support for GCS

2024-10-05 Thread Mark Brown
The arm64 Guarded Control Stack (GCS) feature provides support for hardware protected stacks of return addresses, intended to provide hardening against return oriented programming (ROP) attacks and to make it easier to gather call stacks for applications such as profiling. When GCS is active a sec

[PATCH v14 4/5] KVM: arm64: Set PSTATE.EXLOCK when entering an exception

2024-10-05 Thread Mark Brown
As per DDI 0487 RWTXBY 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(). Signed-off-by: Mark Brown --- a

[PATCH v14 5/5] KVM: selftests: arm64: Add GCS registers to get-reg-list

2024-10-05 Thread Mark Brown
GCS adds new registers GCSCR_EL1, GCSCRE0_EL1, GCSPR_EL1 and GCSPR_EL0. Add these to those validated by get-reg-list. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- tools/testing/selftests/kvm/aarch64/get-reg-list.c | 28 ++ 1 file changed, 28 insertions(+)

[PATCH v14 1/5] KVM: arm64: Expose S1PIE to guests

2024-10-05 Thread Mark Brown
Prior to commit 70ed7238297f ("KVM: arm64: Sanitise ID_AA64MMFR3_EL1") we just exposed the santised view of ID_AA64MMFR3_EL1 to guests, meaning that they saw both TCRX and S1PIE if present on the host machine. That commit added VMM control over the contents of the register and exposed S1POE but rem

[PATCH v14 2/5] arm64/gcs: Ensure FGTs for EL1 GCS instructions are disabled

2024-10-05 Thread Mark Brown
The initial EL2 setup for GCS did not include disabling of EL1 usage of GCS instructions, also disable these traps. This is the first disabling of instruction traps, use x2 to store the value to be written. Signed-off-by: Mark Brown --- arch/arm64/include/asm/el2_setup.h | 7 ++- 1 file cha

[PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Mark Brown
GCS introduces a number of system registers for EL1 and EL0, on systems with GCS we need to context switch them and expose them to VMMs to allow guests to use 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 CH

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Mark Brown
On Sat, Oct 05, 2024 at 02:18:57PM +0100, Marc Zyngier wrote: > Mark Brown wrote: > > On Sat, Oct 05, 2024 at 12:34:20PM +0100, Marc Zyngier wrote: > > > Where is the handling of traps resulting of HFGITR_EL2.nGCSSTR_EL1? > > These will trap with an EC of 0x2d which isn't known so I was expectin

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Mark Brown
On Sat, Oct 05, 2024 at 03:02:09PM +0100, Marc Zyngier wrote: > Mark Brown wrote: > > Ah, I see. I'd been under the impression that the generic machinery was > > supposed to handle this already using the descriptions in > > emulate-nested.c and we only needed handlers for more specific actions.

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Marc Zyngier
On Sat, 05 Oct 2024 15:26:38 +0100, Mark Brown wrote: > > [1 ] > On Sat, Oct 05, 2024 at 03:02:09PM +0100, Marc Zyngier wrote: > > Mark Brown wrote: > > > > Ah, I see. I'd been under the impression that the generic machinery was > > > supposed to handle this already using the descriptions in

Re: [PATCH v14 4/5] KVM: arm64: Set PSTATE.EXLOCK when entering an exception

2024-10-05 Thread Mark Brown
On Sat, Oct 05, 2024 at 01:36:09PM +0100, Marc Zyngier wrote: > Mark Brown wrote: > > + // 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 RWTXBY, D.1.3.2 in K.a. > > +

Re: [PATCH v2 1/6] Add AutoFDO support for Clang build

2024-10-05 Thread Jonathan Corbet
Kees Cook writes: > The tradition in kernel .rst is to do this with the trailing "::", e.g.: > > +Configure the kernel with:: > + > + CONFIG_AUTOFDO_CLANG=y > > This loses the language-specific highlighting when rendered. Perhaps the > "::" extension can be further extended? > > +Configure th

Re: [PATCH v14 4/5] KVM: arm64: Set PSTATE.EXLOCK when entering an exception

2024-10-05 Thread Marc Zyngier
On Sat, 05 Oct 2024 15:14:21 +0100, Mark Brown wrote: > > On Sat, Oct 05, 2024 at 01:36:09PM +0100, Marc Zyngier wrote: > > Mark Brown wrote: > > > > + // PSTATE.EXLOCK is set to 0 upon any exception to a higher > > > + // EL, or to GCSCR_ELx.EXLOCKEN for an exception to the same > > > + // exc

Re: [PATCH v2 1/6] Add AutoFDO support for Clang build

2024-10-05 Thread Peter Zijlstra
On Fri, Oct 04, 2024 at 02:23:45PM -0700, Justin Stitt wrote: > On Fri, Oct 4, 2024 at 11:29 AM Peter Zijlstra wrote: > > > > On Fri, Oct 04, 2024 at 11:10:04AM -0700, Kees Cook wrote: > > > > > +Configure the kernel with::(make) > > > + > > > + CONFIG_AUTOFDO_CLANG=y > > > > > > Then we could

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Marc Zyngier
On Sat, 05 Oct 2024 11:37:30 +0100, Mark Brown wrote: > > GCS introduces a number of system registers for EL1 and EL0, on systems > with GCS we need to context switch them and expose them to VMMs to allow > guests to use GCS. > > In order to allow guests to use GCS we also need to configure > HC

Re: [PATCH v14 4/5] KVM: arm64: Set PSTATE.EXLOCK when entering an exception

2024-10-05 Thread Marc Zyngier
On Sat, 05 Oct 2024 11:37:31 +0100, Mark Brown wrote: > > As per DDI 0487 RWTXBY 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 be

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Mark Brown
On Sat, Oct 05, 2024 at 12:34:20PM +0100, Marc Zyngier wrote: > Mark Brown wrote: > > + if (!kvm_has_gcs(kvm)) { > > + kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nGCS_EL0 | > > + HFGxTR_EL2_nGCS_EL1); > > + kvm->arch.fgu[HFGITR_GROUP

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Marc Zyngier
On Sat, 05 Oct 2024 14:08:39 +0100, Mark Brown wrote: > > On Sat, Oct 05, 2024 at 12:34:20PM +0100, Marc Zyngier wrote: > > Mark Brown wrote: > > > > + if (!kvm_has_gcs(kvm)) { > > > + kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nGCS_EL0 | > > > +

Re: [PATCH v14 3/5] KVM: arm64: Manage GCS access and registers for guests

2024-10-05 Thread Marc Zyngier
On Sat, 05 Oct 2024 14:48:09 +0100, Mark Brown wrote: > > [1 ] > On Sat, Oct 05, 2024 at 02:18:57PM +0100, Marc Zyngier wrote: > > Mark Brown wrote: > > > On Sat, Oct 05, 2024 at 12:34:20PM +0100, Marc Zyngier wrote: > > > > > Where is the handling of traps resulting of HFGITR_EL2.nGCSSTR_EL1?