Re: [PATCH v2 2/3] KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages

[email protected]
Newsgroups org.kernel.vger.kvm,dev.linux.lists.kvmarm
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] get_free_hugepages() overestimates available hugepages by ignoring reserved pages, which allows the test to proceed and crash with ENOMEM on systems with reserved pools.
--

--- Patch [2]: [PATCH v2 2/3] KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages ---
commit 5fa5666824342b3dd28a5ef6a04bb5ac183257c8
Author: Like Xu <[email protected]>

KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages

This commit adds a check to skip the sea_to_user test if the host does not
have enough 1GB hugepages available, preventing a hard failure on systems
without an empty pool.

[ ... ]
> diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> index bab1bd2b775b6..29f9c1d60b1b7 100644
> --- a/tools/testing/selftests/kvm/lib/test_util.c
> +++ b/tools/testing/selftests/kvm/lib/test_util.c
> @@ -222,6 +222,21 @@ size_t get_def_hugetlb_pagesz(void)
>  	TEST_FAIL("Error in reading /proc/meminfo");
>  }
>  
> +size_t get_free_hugepages(size_t page_size)
> +{
> +	char path[128];
> +	size_t free;
> +
> +	snprintf(path, sizeof(path),
> +		 "/sys/kernel/mm/hugepages/hugepages-%zukB/free_hugepages",
> +		 page_size >> 10);
> +	if (!test_sysfs_path(path))
> +		return 0;
> +
> +	free = get_sysfs_val(path);
> +	return free * page_size;

[Severity: Medium]
Does this calculation overestimate the available hugepages by ignoring the
reserved pool?

The sysfs free_hugepages value includes pages that are already committed to
other mappings but not yet allocated (which are tracked via resv_hugepages). 

If the test runs on a host where free_hugepages meets the VM_MEM_SIZE
requirement but some or all of those pages are reserved, the test will
incorrectly proceed and still crash with an -ENOMEM abort instead of cleanly
skipping.

Could we also read and subtract resv_hugepages to determine the actual
allocatable count?

> +}
> +
>  #define ANON_FLAGS	(MAP_PRIVATE | MAP_ANONYMOUS)
>  #define ANON_HUGE_FLAGS	(ANON_FLAGS | MAP_HUGETLB)
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.