diff mbox series

selftests/mm: Skip test for non-LPA2 and non-LVA systems

Message ID 20240717111011.316037-1-dev.jain@arm.com (mailing list archive)
State New
Headers show
Series selftests/mm: Skip test for non-LPA2 and non-LVA systems | expand

Commit Message

Dev Jain July 17, 2024, 11:10 a.m. UTC
Post my improvement of the test:
https://lore.kernel.org/all/20240522070435.773918-3-dev.jain@arm.com/
The test begins to fail on 4k and 16k pages, on non-LPA2 systems. To
reduce noise in the CI systems, let us skip the test when higher address
space is not implemented.

Signed-off-by: Dev Jain <dev.jain@arm.com>
---
The patch applies on linux-next.

 tools/testing/selftests/mm/va_high_addr_switch.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Ryan Roberts July 17, 2024, 11:57 a.m. UTC | #1
On 17/07/2024 12:10, Dev Jain wrote:
> Post my improvement of the test:
> https://lore.kernel.org/all/20240522070435.773918-3-dev.jain@arm.com/
> The test begins to fail on 4k and 16k pages, on non-LPA2 systems. To
> reduce noise in the CI systems, let us skip the test when higher address
> space is not implemented.
> 
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
> The patch applies on linux-next.
> 
>  tools/testing/selftests/mm/va_high_addr_switch.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testing/selftests/mm/va_high_addr_switch.c
> index fa7eabfaf841..c6040e1d6e53 100644
> --- a/tools/testing/selftests/mm/va_high_addr_switch.c
> +++ b/tools/testing/selftests/mm/va_high_addr_switch.c
> @@ -293,6 +293,18 @@ static int run_test(struct testcase *test, int count)
>  	return ret;
>  }
>  
> +/* Check if userspace VA > 48 bits */
> +static int high_address_present(void)
> +{
> +	void *ptr = mmap((void *)(1UL << 50), 1, PROT_READ | PROT_WRITE,
> +			 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);

I think there is (very unlikely) possibility that something is already mapped at
this address so it will be replaced due to MAP_FIXED. That could break the test.
But the only way something could be already mapped is if ARM64_FORCE_52BIT is
set and in that case, the test will fail anyway, right? So I think this is fine.

> +	if (ptr == MAP_FAILED)
> +		return 0;
> +
> +	munmap(ptr, 1);
> +	return 1;
> +}

I'm guessing this will cause a function-not-used warning on arches other than
arm64? Perhaps wrap it in `#ifdef __aarch64__`?

Thanks,
Ryan

> +
>  static int supported_arch(void)
>  {
>  #if defined(__powerpc64__)
> @@ -300,7 +312,7 @@ static int supported_arch(void)
>  #elif defined(__x86_64__)
>  	return 1;
>  #elif defined(__aarch64__)
> -	return 1;
> +	return high_address_present();
>  #else
>  	return 0;
>  #endif
Dev Jain July 17, 2024, 12:11 p.m. UTC | #2
On 7/17/24 17:27, Ryan Roberts wrote:
> On 17/07/2024 12:10, Dev Jain wrote:
>> Post my improvement of the test:
>> https://lore.kernel.org/all/20240522070435.773918-3-dev.jain@arm.com/
>> The test begins to fail on 4k and 16k pages, on non-LPA2 systems. To
>> reduce noise in the CI systems, let us skip the test when higher address
>> space is not implemented.
>>
>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>> ---
>> The patch applies on linux-next.
>>
>>   tools/testing/selftests/mm/va_high_addr_switch.c | 14 +++++++++++++-
>>   1 file changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testing/selftests/mm/va_high_addr_switch.c
>> index fa7eabfaf841..c6040e1d6e53 100644
>> --- a/tools/testing/selftests/mm/va_high_addr_switch.c
>> +++ b/tools/testing/selftests/mm/va_high_addr_switch.c
>> @@ -293,6 +293,18 @@ static int run_test(struct testcase *test, int count)
>>   	return ret;
>>   }
>>   
>> +/* Check if userspace VA > 48 bits */
>> +static int high_address_present(void)
>> +{
>> +	void *ptr = mmap((void *)(1UL << 50), 1, PROT_READ | PROT_WRITE,
>> +			 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
> I think there is (very unlikely) possibility that something is already mapped at
> this address so it will be replaced due to MAP_FIXED. That could break the test.
> But the only way something could be already mapped is if ARM64_FORCE_52BIT is
> set and in that case, the test will fail anyway, right? So I think this is fine.

The testcases already assume that high addresses must be empty. Yes, FORCE_52BIT
is the only way something could already be mapped at high addresses, but in that
case the test fails trivially.

>
>> +	if (ptr == MAP_FAILED)
>> +		return 0;
>> +
>> +	munmap(ptr, 1);
>> +	return 1;
>> +}
> I'm guessing this will cause a function-not-used warning on arches other than
> arm64? Perhaps wrap it in `#ifdef __aarch64__`?

Ah yes, I just checked and that is true. I shall post v2 in some time, shall
wait if any more comments are there.

>
> Thanks,
> Ryan
>
>> +
>>   static int supported_arch(void)
>>   {
>>   #if defined(__powerpc64__)
>> @@ -300,7 +312,7 @@ static int supported_arch(void)
>>   #elif defined(__x86_64__)
>>   	return 1;
>>   #elif defined(__aarch64__)
>> -	return 1;
>> +	return high_address_present();
>>   #else
>>   	return 0;
>>   #endif
Ryan Roberts July 17, 2024, 12:25 p.m. UTC | #3
On 17/07/2024 13:11, Dev Jain wrote:
> 
> On 7/17/24 17:27, Ryan Roberts wrote:
>> On 17/07/2024 12:10, Dev Jain wrote:
>>> Post my improvement of the test:
>>> https://lore.kernel.org/all/20240522070435.773918-3-dev.jain@arm.com/
>>> The test begins to fail on 4k and 16k pages, on non-LPA2 systems. To
>>> reduce noise in the CI systems, let us skip the test when higher address
>>> space is not implemented.
>>>
>>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>>> ---
>>> The patch applies on linux-next.
>>>
>>>   tools/testing/selftests/mm/va_high_addr_switch.c | 14 +++++++++++++-
>>>   1 file changed, 13 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c
>>> b/tools/testing/selftests/mm/va_high_addr_switch.c
>>> index fa7eabfaf841..c6040e1d6e53 100644
>>> --- a/tools/testing/selftests/mm/va_high_addr_switch.c
>>> +++ b/tools/testing/selftests/mm/va_high_addr_switch.c
>>> @@ -293,6 +293,18 @@ static int run_test(struct testcase *test, int count)
>>>       return ret;
>>>   }
>>>   +/* Check if userspace VA > 48 bits */
>>> +static int high_address_present(void)
>>> +{
>>> +    void *ptr = mmap((void *)(1UL << 50), 1, PROT_READ | PROT_WRITE,
>>> +             MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
>> I think there is (very unlikely) possibility that something is already mapped at
>> this address so it will be replaced due to MAP_FIXED. That could break the test.
>> But the only way something could be already mapped is if ARM64_FORCE_52BIT is
>> set and in that case, the test will fail anyway, right? So I think this is fine.
> 
> The testcases already assume that high addresses must be empty. Yes, FORCE_52BIT
> is the only way something could already be mapped at high addresses, but in that
> case the test fails trivially.

agreed.

> 
>>
>>> +    if (ptr == MAP_FAILED)
>>> +        return 0;
>>> +
>>> +    munmap(ptr, 1);
>>> +    return 1;
>>> +}
>> I'm guessing this will cause a function-not-used warning on arches other than
>> arm64? Perhaps wrap it in `#ifdef __aarch64__`?
> 
> Ah yes, I just checked and that is true. I shall post v2 in some time, shall
> wait if any more comments are there.

With this fixup:

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> 
>>
>> Thanks,
>> Ryan
>>
>>> +
>>>   static int supported_arch(void)
>>>   {
>>>   #if defined(__powerpc64__)
>>> @@ -300,7 +312,7 @@ static int supported_arch(void)
>>>   #elif defined(__x86_64__)
>>>       return 1;
>>>   #elif defined(__aarch64__)
>>> -    return 1;
>>> +    return high_address_present();
>>>   #else
>>>       return 0;
>>>   #endif
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testing/selftests/mm/va_high_addr_switch.c
index fa7eabfaf841..c6040e1d6e53 100644
--- a/tools/testing/selftests/mm/va_high_addr_switch.c
+++ b/tools/testing/selftests/mm/va_high_addr_switch.c
@@ -293,6 +293,18 @@  static int run_test(struct testcase *test, int count)
 	return ret;
 }
 
+/* Check if userspace VA > 48 bits */
+static int high_address_present(void)
+{
+	void *ptr = mmap((void *)(1UL << 50), 1, PROT_READ | PROT_WRITE,
+			 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+	if (ptr == MAP_FAILED)
+		return 0;
+
+	munmap(ptr, 1);
+	return 1;
+}
+
 static int supported_arch(void)
 {
 #if defined(__powerpc64__)
@@ -300,7 +312,7 @@  static int supported_arch(void)
 #elif defined(__x86_64__)
 	return 1;
 #elif defined(__aarch64__)
-	return 1;
+	return high_address_present();
 #else
 	return 0;
 #endif