Re: [PATCH v2 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails

From: Jose A. Perez de Azpillaga

Date: Fri Dec 04 2026 - 04:39:21 EST


On 12/3/26 6:15 PM, Mike Rapoport (Microsoft) wrote:
> uffd_test_ctx_init() returns on errors without unmapping the test areas
> it has already allocated, and userfaultfd_open() leaves the userfaultfd
> open when UFFDIO_API fails. uffd-unit-tests then skips the test and goes
> on to the next one in the same process, so everything allocated for the
> failed test stays around until the end of the run.
>
> For hugetlb, the leaked areas keep their huge pages reserved, and the
> following hugetlb tests can fail to allocate their areas and get skipped
> with a misleading "memory allocation failed".
>
> Unmap the areas allocated so far when uffd_test_ctx_init() fails and
> close the userfaultfd when userfaultfd_open() fails.
>
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://sashiko.dev/bug/linux-3a91f55a-ede8-4950-bbda-cd0b03f9076a
> Fixes: 1c8d39fa7b63 ("selftests/mm: call uffd_test_ctx_clear at the end of the test")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>

LGTM:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

--
cheers,
jose a. p-a