diff mbox series

[2/2] kselftest/arm64: mte: Skip the hugetlb tests if MTE not supported on such mappings

Message ID 20250221093331.2184245-3-catalin.marinas@arm.com (mailing list archive)
State New
Headers show
Series kselftest/arm64: mte: Minor fixes to the MTE hugetlb test | expand

Commit Message

Catalin Marinas Feb. 21, 2025, 9:33 a.m. UTC
While the kselftest was added at the same time with the kernel support
for MTE on hugetlb mappings, the tests may be run on older kernels. Skip
the tests if PROT_MTE is not supported on MAP_HUGETLB mappings.

Fixes: 27879e8cb6b0 ("selftests: arm64: add hugetlb mte tests")
Cc: Yang Shi <yang@os.amperecomputing.com>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
---
 .../selftests/arm64/mte/check_hugetlb_options.c       | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Yang Shi Feb. 21, 2025, 5:22 p.m. UTC | #1
On 2/21/25 1:33 AM, Catalin Marinas wrote:
> While the kselftest was added at the same time with the kernel support
> for MTE on hugetlb mappings, the tests may be run on older kernels. Skip
> the tests if PROT_MTE is not supported on MAP_HUGETLB mappings.
>
> Fixes: 27879e8cb6b0 ("selftests: arm64: add hugetlb mte tests")
> Cc: Yang Shi <yang@os.amperecomputing.com>
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> ---
>   .../selftests/arm64/mte/check_hugetlb_options.c       | 11 +++++++++++
>   1 file changed, 11 insertions(+)

Reviewed-by: Yang Shi <yang@os.amperecomputing.com>

>
> diff --git a/tools/testing/selftests/arm64/mte/check_hugetlb_options.c b/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
> index 11f812635b51..3bfcd3848432 100644
> --- a/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
> +++ b/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
> @@ -227,6 +227,8 @@ static int check_child_hugetlb_memory_mapping(int mem_type, int mode, int mappin
>   int main(int argc, char *argv[])
>   {
>   	int err;
> +	void *map_ptr;
> +	unsigned long map_size;
>   
>   	err = mte_default_setup();
>   	if (err)
> @@ -243,6 +245,15 @@ int main(int argc, char *argv[])
>   		return KSFT_FAIL;
>   	}
>   
> +	/* Check if MTE supports hugetlb mappings */
> +	map_size = default_huge_page_size();
> +	map_ptr = mmap(NULL, map_size, PROT_READ | PROT_MTE,
> +		       MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
> +	if (map_ptr == MAP_FAILED)
> +		ksft_exit_skip("PROT_MTE not supported with MAP_HUGETLB mappings\n");
> +	else
> +		munmap(map_ptr, map_size);
> +
>   	/* Set test plan */
>   	ksft_set_plan(12);
>
Dev Jain Feb. 21, 2025, 5:38 p.m. UTC | #2
On 21/02/25 3:03 pm, Catalin Marinas wrote:
> While the kselftest was added at the same time with the kernel support
> for MTE on hugetlb mappings, the tests may be run on older kernels. Skip
> the tests if PROT_MTE is not supported on MAP_HUGETLB mappings.
> 
> Fixes: 27879e8cb6b0 ("selftests: arm64: add hugetlb mte tests")
> Cc: Yang Shi <yang@os.amperecomputing.com>
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

Reviewed-by: Dev Jain <dev.jain@arm.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/arm64/mte/check_hugetlb_options.c b/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
index 11f812635b51..3bfcd3848432 100644
--- a/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
+++ b/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
@@ -227,6 +227,8 @@  static int check_child_hugetlb_memory_mapping(int mem_type, int mode, int mappin
 int main(int argc, char *argv[])
 {
 	int err;
+	void *map_ptr;
+	unsigned long map_size;
 
 	err = mte_default_setup();
 	if (err)
@@ -243,6 +245,15 @@  int main(int argc, char *argv[])
 		return KSFT_FAIL;
 	}
 
+	/* Check if MTE supports hugetlb mappings */
+	map_size = default_huge_page_size();
+	map_ptr = mmap(NULL, map_size, PROT_READ | PROT_MTE,
+		       MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
+	if (map_ptr == MAP_FAILED)
+		ksft_exit_skip("PROT_MTE not supported with MAP_HUGETLB mappings\n");
+	else
+		munmap(map_ptr, map_size);
+
 	/* Set test plan */
 	ksft_set_plan(12);