Re: [PATCH v7 01/12] xen/arm: enable SVE extension for Xen
On 23/05/2023 08:43, Luca Fancellu wrote: Enable Xen to handle the SVE extension, add code in cpufeature module to handle ZCR SVE register, disable trapping SVE feature on system boot only when SVE resources are accessed. While there, correct coding style for the comment on coprocessor trapping. Now cptr_el2 is part of the domain context and it will be restored on context switch, this is a preparation for saving the SVE context which will be part of VFP operations, so restore it before the call to save VFP registers. To save an additional isb barrier, restore cptr_el2 before an existing isb barrier and move the call for saving VFP context after that barrier. To keep a (mostly) specularity of ctxt_switch_to() and ctxt_switch_from(), move vfp_save_state() up in the function. Change the KConfig entry to make ARM64_SVE symbol selectable, by default it will be not selected. Create sve module and sve_asm.S that contains assembly routines for the SVE feature, this code is inspired from linux and it uses instruction encoding to be compatible with compilers that does not support SVE, imported instructions are documented in README.LinuxPrimitives. Signed-off-by: Luca Fancellu Acked-by: Julien Grall Cheers, -- Julien Grall
Re: [PATCH v7 01/12] xen/arm: enable SVE extension for Xen
On 23/05/2023 08:43, Luca Fancellu wrote: Enable Xen to handle the SVE extension, add code in cpufeature module to handle ZCR SVE register, disable trapping SVE feature on system boot only when SVE resources are accessed. While there, correct coding style for the comment on coprocessor trapping. Now cptr_el2 is part of the domain context and it will be restored on context switch, this is a preparation for saving the SVE context which will be part of VFP operations, so restore it before the call to save VFP registers. To save an additional isb barrier, restore cptr_el2 before an existing isb barrier and move the call for saving VFP context after that barrier. To keep a (mostly) specularity of ctxt_switch_to() and ctxt_switch_from(), move vfp_save_state() up in the function. Change the KConfig entry to make ARM64_SVE symbol selectable, by default it will be not selected. Create sve module and sve_asm.S that contains assembly routines for the SVE feature, this code is inspired from linux and it uses instruction encoding to be compatible with compilers that does not support SVE, imported instructions are documented in README.LinuxPrimitives. Signed-off-by: Luca Fancellu Acked-by: Julien Grall Cheers, -- Julien Grall
Re: [PATCH v7 01/12] xen/arm: enable SVE extension for Xen
Hi Julien, > On 24 May 2023, at 11:58, Julien Grall wrote: > > Hi, > > On 24/05/2023 10:01, Bertrand Marquis wrote: >>> diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c >>> index c4ec38bb2554..83b84368f6d5 100644 >>> --- a/xen/arch/arm/cpufeature.c >>> +++ b/xen/arch/arm/cpufeature.c >>> @@ -9,6 +9,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> >>> DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS); >>> @@ -143,6 +144,9 @@ void identify_cpu(struct cpuinfo_arm *c) >>> >>> c->zfr64.bits[0] = READ_SYSREG(ID_AA64ZFR0_EL1); >>> >>> +if ( cpu_has_sve ) >>> +c->zcr64.bits[0] = compute_max_zcr(); >>> + >>> c->dczid.bits[0] = READ_SYSREG(DCZID_EL0); >>> >>> c->ctr.bits[0] = READ_SYSREG(CTR_EL0); >>> @@ -199,7 +203,7 @@ static int __init create_guest_cpuinfo(void) >>> guest_cpuinfo.pfr64.mpam = 0; >>> guest_cpuinfo.pfr64.mpam_frac = 0; >>> >>> -/* Hide SVE as Xen does not support it */ >>> +/* Hide SVE by default to the guests */ >> Everything is for guests and as Jan mentioned in an other comment >> this could be wrongly interpreted. > > (Not directly related to this patch, so no changes expected here) > > Hmmm... The name of the function/variable is confusing as well given that the > cpuinfo should also apply to dom0. Should we s/guest/domain/? Would make sense to do some kind of coherency check here to use domain whenever something is for dom0 or guest. So yes that would be a good idea and I can add this to my todolist (after SVE is merged to prevent conflicts). Cheers Bertrand > > Cheers, > > -- > Julien Grall
Re: [PATCH v7 01/12] xen/arm: enable SVE extension for Xen
Hi, On 24/05/2023 10:01, Bertrand Marquis wrote: diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c index c4ec38bb2554..83b84368f6d5 100644 --- a/xen/arch/arm/cpufeature.c +++ b/xen/arch/arm/cpufeature.c @@ -9,6 +9,7 @@ #include #include #include +#include #include DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS); @@ -143,6 +144,9 @@ void identify_cpu(struct cpuinfo_arm *c) c->zfr64.bits[0] = READ_SYSREG(ID_AA64ZFR0_EL1); +if ( cpu_has_sve ) +c->zcr64.bits[0] = compute_max_zcr(); + c->dczid.bits[0] = READ_SYSREG(DCZID_EL0); c->ctr.bits[0] = READ_SYSREG(CTR_EL0); @@ -199,7 +203,7 @@ static int __init create_guest_cpuinfo(void) guest_cpuinfo.pfr64.mpam = 0; guest_cpuinfo.pfr64.mpam_frac = 0; -/* Hide SVE as Xen does not support it */ +/* Hide SVE by default to the guests */ Everything is for guests and as Jan mentioned in an other comment this could be wrongly interpreted. (Not directly related to this patch, so no changes expected here) Hmmm... The name of the function/variable is confusing as well given that the cpuinfo should also apply to dom0. Should we s/guest/domain/? Cheers, -- Julien Grall
Re: [PATCH v7 01/12] xen/arm: enable SVE extension for Xen
Hi Luca, > On 23 May 2023, at 09:43, Luca Fancellu wrote: > > Enable Xen to handle the SVE extension, add code in cpufeature module > to handle ZCR SVE register, disable trapping SVE feature on system > boot only when SVE resources are accessed. > While there, correct coding style for the comment on coprocessor > trapping. > > Now cptr_el2 is part of the domain context and it will be restored > on context switch, this is a preparation for saving the SVE context > which will be part of VFP operations, so restore it before the call > to save VFP registers. > To save an additional isb barrier, restore cptr_el2 before an > existing isb barrier and move the call for saving VFP context after > that barrier. To keep a (mostly) specularity of ctxt_switch_to() > and ctxt_switch_from(), move vfp_save_state() up in the function. > > Change the KConfig entry to make ARM64_SVE symbol selectable, by > default it will be not selected. > > Create sve module and sve_asm.S that contains assembly routines for > the SVE feature, this code is inspired from linux and it uses > instruction encoding to be compatible with compilers that does not > support SVE, imported instructions are documented in > README.LinuxPrimitives. > > Signed-off-by: Luca Fancellu Reviewed-by: Bertrand Marquis with one minor NIT that could be fixed on commit... > --- > Changes from v6: > - modified licence, add emacs block, move vfp_save_state up in the > function, add comments to CPTR_EL2 and vfp_restore_state, don't > use variable in init_traps(), code style fixes, > add entries to README.LinuxPrimitives (Julien) > - vl_to_zcr is moved into sve.c module as changes to the series led > to its usage only inside it, remove stub for compute_max_zcr and > rely on compiler DCE. > Changes from v5: > - Add R-by Bertrand > Changes from v4: > - don't use fixed types in vl_to_zcr, forgot to address that in > v3, by mistake I changed that in patch 2, fixing now (Jan) > Changes from v3: > - no changes > Changes from v2: > - renamed sve_asm.S in sve-asm.S, new files should not contain > underscore in the name (Jan) > Changes from v1: > - Add assert to vl_to_zcr, it is never called with vl==0, but just > to be sure it won't in the future. > Changes from RFC: > - Moved restoring of cptr before an existing barrier (Julien) > - Marked the feature as unsupported for now (Julien) > - Trap and un-trap only when using SVE resources in > compute_max_zcr() (Julien) > --- > xen/arch/arm/Kconfig | 10 ++-- > xen/arch/arm/README.LinuxPrimitives | 9 > xen/arch/arm/arm64/Makefile | 1 + > xen/arch/arm/arm64/cpufeature.c | 7 ++- > xen/arch/arm/arm64/sve-asm.S | 48 +++ > xen/arch/arm/arm64/sve.c | 59 > xen/arch/arm/cpufeature.c| 6 ++- > xen/arch/arm/domain.c| 20 +--- > xen/arch/arm/include/asm/arm64/sve.h | 27 +++ > xen/arch/arm/include/asm/arm64/sysregs.h | 1 + > xen/arch/arm/include/asm/cpufeature.h| 14 ++ > xen/arch/arm/include/asm/domain.h| 1 + > xen/arch/arm/include/asm/processor.h | 2 + > xen/arch/arm/setup.c | 5 +- > xen/arch/arm/traps.c | 27 ++- > 15 files changed, 210 insertions(+), 27 deletions(-) > create mode 100644 xen/arch/arm/arm64/sve-asm.S > create mode 100644 xen/arch/arm/arm64/sve.c > create mode 100644 xen/arch/arm/include/asm/arm64/sve.h > > diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig > index 239d3aed3c7f..41f45d8d1203 100644 > --- a/xen/arch/arm/Kconfig > +++ b/xen/arch/arm/Kconfig > @@ -112,11 +112,15 @@ config ARM64_PTR_AUTH > This feature is not supported in Xen. > > config ARM64_SVE > - def_bool n > + bool "Enable Scalar Vector Extension support (UNSUPPORTED)" if UNSUPPORTED > depends on ARM_64 > help > - Scalar Vector Extension support. > - This feature is not supported in Xen. > + Scalar Vector Extension (SVE/SVE2) support for guests. > + > + Please be aware that currently, enabling this feature will add latency on > + VM context switch between SVE enabled guests, between not-enabled SVE > + guests and SVE enabled guests and viceversa, compared to the time > + required to switch between not-enabled SVE guests. > > config ARM64_MTE > def_bool n > diff --git a/xen/arch/arm/README.LinuxPrimitives > b/xen/arch/arm/README.LinuxPrimitives > index 1d53e6a898da..76c8df29e416 100644 > --- a/xen/arch/arm/README.LinuxPrimitives > +++ b/xen/arch/arm/README.LinuxPrimitives > @@ -62,6 +62,15 @@ done > linux/arch/arm64/lib/clear_page.S xen/arch/arm/arm64/lib/clear_page.S > linux/arch/arm64/lib/copy_page.Sunused in Xen > > +- > + > +SVE assembly macro: last sync @ v6.3.0 (last commit: 457391b03803) > + > +linux/arch/arm64/include/asm/fpsimdmacros.h > xen/arch/arm/include/asm/arm64/sve-asm.S
[PATCH v7 01/12] xen/arm: enable SVE extension for Xen
Enable Xen to handle the SVE extension, add code in cpufeature module to handle ZCR SVE register, disable trapping SVE feature on system boot only when SVE resources are accessed. While there, correct coding style for the comment on coprocessor trapping. Now cptr_el2 is part of the domain context and it will be restored on context switch, this is a preparation for saving the SVE context which will be part of VFP operations, so restore it before the call to save VFP registers. To save an additional isb barrier, restore cptr_el2 before an existing isb barrier and move the call for saving VFP context after that barrier. To keep a (mostly) specularity of ctxt_switch_to() and ctxt_switch_from(), move vfp_save_state() up in the function. Change the KConfig entry to make ARM64_SVE symbol selectable, by default it will be not selected. Create sve module and sve_asm.S that contains assembly routines for the SVE feature, this code is inspired from linux and it uses instruction encoding to be compatible with compilers that does not support SVE, imported instructions are documented in README.LinuxPrimitives. Signed-off-by: Luca Fancellu --- Changes from v6: - modified licence, add emacs block, move vfp_save_state up in the function, add comments to CPTR_EL2 and vfp_restore_state, don't use variable in init_traps(), code style fixes, add entries to README.LinuxPrimitives (Julien) - vl_to_zcr is moved into sve.c module as changes to the series led to its usage only inside it, remove stub for compute_max_zcr and rely on compiler DCE. Changes from v5: - Add R-by Bertrand Changes from v4: - don't use fixed types in vl_to_zcr, forgot to address that in v3, by mistake I changed that in patch 2, fixing now (Jan) Changes from v3: - no changes Changes from v2: - renamed sve_asm.S in sve-asm.S, new files should not contain underscore in the name (Jan) Changes from v1: - Add assert to vl_to_zcr, it is never called with vl==0, but just to be sure it won't in the future. Changes from RFC: - Moved restoring of cptr before an existing barrier (Julien) - Marked the feature as unsupported for now (Julien) - Trap and un-trap only when using SVE resources in compute_max_zcr() (Julien) --- xen/arch/arm/Kconfig | 10 ++-- xen/arch/arm/README.LinuxPrimitives | 9 xen/arch/arm/arm64/Makefile | 1 + xen/arch/arm/arm64/cpufeature.c | 7 ++- xen/arch/arm/arm64/sve-asm.S | 48 +++ xen/arch/arm/arm64/sve.c | 59 xen/arch/arm/cpufeature.c| 6 ++- xen/arch/arm/domain.c| 20 +--- xen/arch/arm/include/asm/arm64/sve.h | 27 +++ xen/arch/arm/include/asm/arm64/sysregs.h | 1 + xen/arch/arm/include/asm/cpufeature.h| 14 ++ xen/arch/arm/include/asm/domain.h| 1 + xen/arch/arm/include/asm/processor.h | 2 + xen/arch/arm/setup.c | 5 +- xen/arch/arm/traps.c | 27 ++- 15 files changed, 210 insertions(+), 27 deletions(-) create mode 100644 xen/arch/arm/arm64/sve-asm.S create mode 100644 xen/arch/arm/arm64/sve.c create mode 100644 xen/arch/arm/include/asm/arm64/sve.h diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 239d3aed3c7f..41f45d8d1203 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -112,11 +112,15 @@ config ARM64_PTR_AUTH This feature is not supported in Xen. config ARM64_SVE - def_bool n + bool "Enable Scalar Vector Extension support (UNSUPPORTED)" if UNSUPPORTED depends on ARM_64 help - Scalar Vector Extension support. - This feature is not supported in Xen. + Scalar Vector Extension (SVE/SVE2) support for guests. + + Please be aware that currently, enabling this feature will add latency on + VM context switch between SVE enabled guests, between not-enabled SVE + guests and SVE enabled guests and viceversa, compared to the time + required to switch between not-enabled SVE guests. config ARM64_MTE def_bool n diff --git a/xen/arch/arm/README.LinuxPrimitives b/xen/arch/arm/README.LinuxPrimitives index 1d53e6a898da..76c8df29e416 100644 --- a/xen/arch/arm/README.LinuxPrimitives +++ b/xen/arch/arm/README.LinuxPrimitives @@ -62,6 +62,15 @@ done linux/arch/arm64/lib/clear_page.S xen/arch/arm/arm64/lib/clear_page.S linux/arch/arm64/lib/copy_page.Sunused in Xen +- + +SVE assembly macro: last sync @ v6.3.0 (last commit: 457391b03803) + +linux/arch/arm64/include/asm/fpsimdmacros.h xen/arch/arm/include/asm/arm64/sve-asm.S + +The following macros were taken from Linux: +_check_general_reg, _check_num, _sve_rdvl + = arm32 ===