Re: [PATCH] selftest: mm: Test if hugepage does not get leaked during __bio_release_pages()

From: Pankaj Raghav
Date: Thu Jun 06 2024 - 09:15:31 EST



> +void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
> +{
> + int fd;
> + char *buffer = NULL;
> + char *orig_buffer = NULL;
> + size_t h_pagesize = 0;
> + size_t writesize;
> + int free_hpage_b = 0;
> + int free_hpage_a = 0;
> +
> + writesize = end_off - start_off;
> +
> + /* Get the default huge page size */
> + h_pagesize = default_huge_page_size();
> + if (!h_pagesize)
> + ksft_exit_fail_msg("Unable to determine huge page size\n");
> +
> + /* Open the file to DIO */
> + fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT);

I encountered a build error as follows in NixOS:

In file included from /nix/store/fwh4fxd747m0py3ib3s5abamia9nrf90-glibc-2.39-52-dev/include/fcntl.h:342,
from hugetlb_dio.c:15:
In function ‘open’,
inlined from ‘run_dio_using_hugetlb’ at hugetlb_dio.c:41:7:
/nix/store/fwh4fxd747m0py3ib3s5abamia9nrf90-glibc-2.39-52-dev/include/bits/fcntl2.h:50:11: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
50 | __open_missing_mode ();


I saw a commit that fixed similar issues with open syscall before:
8b65ef5ad486 ("selftests/mm: Fix build with _FORTIFY_SOURCE")

So something like this should fix the issue?

- fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT);
+ fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);

> + if (fd < 0)
> + ksft_exit_fail_msg("Error opening file");
> +