mbox series

[0/2] KVM: selftests: arm64: Make use of sysreg defintions in get-reg-list

Message ID 20240802-kvm-arm64-get-reg-list-v1-0-3a5bf8f80765@kernel.org
Headers show
Series KVM: selftests: arm64: Make use of sysreg defintions in get-reg-list | expand

Message

Mark Brown Aug. 2, 2024, 9:57 p.m. UTC
The system register definitions in the arm64 get-reg-list are all done
with directly specified magic numbers rather than using the definitions
we import from the main kernel.  This is error prone, and requires us to
audit the additions to get-reg-list separately to what we do when
specifying the registers for the main kernel.  Since Marc has indicated
that this isn't a deliberate or desired choice let's start using the
constants we have defined.

We first manually update the data used to filter registers based on ID
register fields to use a simplified macro that specifies the register
and ID field in a muc more compact fashion.  This is done first since
there is an error in the ID register field for the S1PIE registers.  We
then replace all the remaining named system register specifications with
use of the existing KVM_ARM64_SYS_REG() macro.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
Mark Brown (2):
      KVM: selftests: arm64: Simplify specification of filtered registers
      KVM: selftests: arm64: Use generated defines for named system registers

 tools/testing/selftests/kvm/aarch64/get-reg-list.c | 237 ++++++++++-----------
 1 file changed, 115 insertions(+), 122 deletions(-)
---
base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
change-id: 20240802-kvm-arm64-get-reg-list-a86a37460bdd

Best regards,

Comments

Marc Zyngier Aug. 4, 2024, 11:24 a.m. UTC | #1
On Fri, 02 Aug 2024 22:57:53 +0100,
Mark Brown <broonie@kernel.org> wrote:
> 
> Since we already import the generated sysreg definitions from the main
> kernel and reference them in processor.h for use in other KVM tests we
> can also make use of them for get-reg-list as well instead of having hard
> coded magic numbers in the program. Do this for the table defining which
> registers should be gated on ID register values, using a macro which allows
> us to specify the register and ID register field in a much more compact
> and direct fashion.
> 
> In the process we fix the ID register checked for S1PIE specific registers
> which was using an incorrect shift of 4, checking SCTLRX support instead.
> No other change is seen in the generated data.
> 
> Fixes: 5f0419a0083b ("KVM: selftests: get-reg-list: add Permission Indirection registers")
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
>  tools/testing/selftests/kvm/aarch64/get-reg-list.c | 29 ++++++++--------------
>  1 file changed, 11 insertions(+), 18 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
> index 709d7d721760..a00322970578 100644
> --- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c
> +++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
> @@ -22,25 +22,18 @@ struct feature_id_reg {
>  	__u64 feat_min;
>  };
>  
> -static struct feature_id_reg feat_id_regs[] = {
> -	{
> -		ARM64_SYS_REG(3, 0, 2, 0, 3),	/* TCR2_EL1 */
> -		ARM64_SYS_REG(3, 0, 0, 7, 3),	/* ID_AA64MMFR3_EL1 */
> -		0,
> -		1
> -	},
> -	{
> -		ARM64_SYS_REG(3, 0, 10, 2, 2),	/* PIRE0_EL1 */
> -		ARM64_SYS_REG(3, 0, 0, 7, 3),	/* ID_AA64MMFR3_EL1 */
> -		4,
> -		1
> -	},
> -	{
> -		ARM64_SYS_REG(3, 0, 10, 2, 3),	/* PIR_EL1 */
> -		ARM64_SYS_REG(3, 0, 0, 7, 3),	/* ID_AA64MMFR3_EL1 */
> -		4,
> -		1
> +#define FEAT_ID_CHECK(reg, id_reg, id_field, id_val)	\
> +	{						\
> +		KVM_ARM64_SYS_REG(SYS_##reg),		\
> +		KVM_ARM64_SYS_REG(SYS_##id_reg),	\
> +		id_reg##_##id_field##_SHIFT,		\
> +		id_reg##_##id_field##_##id_val,		\

Please use designated initialisers.

>  	}
> +
> +static struct feature_id_reg feat_id_regs[] = {
> +	FEAT_ID_CHECK(TCR2_EL1, ID_AA64MMFR3_EL1, TCRX, IMP),
> +	FEAT_ID_CHECK(PIRE0_EL1, ID_AA64MMFR3_EL1, S1PIE, IMP),
> +	FEAT_ID_CHECK(PIR_EL1, ID_AA64MMFR3_EL1, S1PIE, IMP),
>  };
>  
>  bool filter_reg(__u64 reg)

Thanks,

	M.