From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796235621; b=5kzX5Hawn+7A+eFOaiPOzNkztw3nLyQhjQ529Ed4oiiQI6MW5qIJqQrpls10Fy3om2MG wVVGxG7r+8K9c93zfCXvWjJVAkyBhawtc8LzIqCwZ9/tCtj+VhQQRg48v21ph9neNJu30 IcpETEuG6F5OYBAgiDefzua4e2qGBTdHSf6Vj6tTZdKArXaHX2AEvsKrKxJUR2PA21EAq K3Tv8riBk2m3ZHNGPSOeMpdwEYaf6QXfHGByuhyavH/AZBP60K34MjESZU5Nw2ST65T2K kn2G2nclTmQ1BeePs+saBw6vLkJ9WlODvjySLlHMjq+s/YmBHb9IGrail5Rb5guwhJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796235621; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer; bh=gnBZmVP4AYBgfqc783mfAfmsBc8BR0b81uuVKyhYMGs=; b=tKo2Ua5aAZP+9PDN5JwRP5mpd04j8qcWHdyWHU+c5OLr57k8zS5wZAA060thumrMVoAX 7yeSaLiPQ3g1N7Z479+MIMXGU5Zi8Yr5lryT9vnd561I42j9MTyPRJ96HrTydxD/Pxzn7 hIf9cl4yn6QBA3lJyJV4qsFUgJydGjD2LVM8kZc2RtTUm9Xba+YNyd8oIfzFdQYXvLqOI sDlOKWaaejxOEbSvtBwC/3D4wBJ2hdtfsEUZLnGgvEnRkGtfL1zswtc8EVaXDCpO+f9qd 3/yrUBjhARfyTGu4ueE4nyT6mTiE8m8+MR1O4aCjLP7Ev7ju35c69pyflnteweOMhMA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="SK2VP/Tb"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEB47606A33A; Wed, 2 Dec 2026 18:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SK2VP/Tb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 581201F00925; Wed, 2 Dec 2026 18:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796235621; bh=gnBZmVP4AYBgfqc783mfAfmsBc8BR0b81uuVKyhYMGs=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=SK2VP/Tbm5/9v8Jr/BCW2gjPfds4iteX2Md4vjWoRZvqh+X1fdn8hfXyjxkbFFlC0 pObWMeVijUc9GUIuQ+A5N93K3LsfLOmkJrH5wdy8iTg8tK8g7X1CQ/9tJAn5LkVpcg nv+MNzKXkijj1BwiYt3iAfj6UxCb53JFRxF5mt6UnILm3QPQPrrCShxzbQtz9T8bkT 3v0jFjHG5o1saXJHJ9FVcEbyGavEhjNUiI2L7COKCuG31qj23pgRThqL4Q5O20Z58W J80XquMC3Vqz/Smt8ulnLwx3ESlvPHSTdhgdhhQEXo+MCGmUg1qcmQFEFHtn/iYBxV dWbGD93uVft6Q== From: "Mike Rapoport (Microsoft)" Date: Wed, 02 Dec 2026 20:20:09 +0200 Subject: [PATCH 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-fixes-uffd-sashiko-v1-4-a6f5a874334a@kernel.org> References: <20261202-fixes-uffd-sashiko-v1-0-a6f5a874334a@kernel.org> In-Reply-To: <20261202-fixes-uffd-sashiko-v1-0-a6f5a874334a@kernel.org> To: Andrew Morton , David Hildenbrand Cc: Mike Rapoport , Peter Xu , Suren Baghdasaryan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Sashiko X-Mailer: b4 0.16.1-dev uffd_test_ctx_init() returns on errors without unmapping the test areas it has already allocated or closing the userfaultfd. 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". Call uffd_test_ctx_clear() when uffd_test_ctx_init() fails, and initialize gopts->uffd to -1 so that uffd_test_ctx_clear() doesn't close fd 0 when the userfaultfd is not opened yet. Reported-by: Sashiko 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) --- tools/testing/selftests/mm/uffd-common.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index a76851aced4d0..284cd8a9150d5 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -325,6 +325,7 @@ int uffd_test_ctx_init(uffd_global_test_opts_t *gopts, uint64_t features, const gopts->area_src_alias = NULL; gopts->area_dst_alias = NULL; gopts->area_remap = NULL; + gopts->uffd = -1; if (uffd_test_case_ops && uffd_test_case_ops->pre_alloc) { ret = uffd_test_case_ops->pre_alloc(gopts, errmsg); @@ -337,20 +338,20 @@ int uffd_test_ctx_init(uffd_global_test_opts_t *gopts, uint64_t features, const if (ret) { if (errmsg) *errmsg = "memory allocation failed"; - return ret; + goto err_clear; } if (uffd_test_case_ops && uffd_test_case_ops->post_alloc) { ret = uffd_test_case_ops->post_alloc(gopts, errmsg); if (ret) - return ret; + goto err_clear; } ret = userfaultfd_open(gopts, &features); if (ret) { if (errmsg) *errmsg = "possible lack of privilege"; - return ret; + goto err_clear; } gopts->count_verify = malloc(gopts->nr_pages * sizeof(unsigned long long)); @@ -399,6 +400,10 @@ int uffd_test_ctx_init(uffd_global_test_opts_t *gopts, uint64_t features, const err("pipe"); return 0; + +err_clear: + uffd_test_ctx_clear(gopts); + return ret; } void wp_range(int ufd, __u64 start, __u64 len, bool wp) -- 2.53.0