From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FE3B3E2759 for ; Mon, 4 May 2026 23:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777937806; cv=none; b=eoal95nI8LVbVz/8y0bEU4rfW+8LDMl+DnGe/V7AA6pERGO5BNk5yJNcaVAguuUCMAR+TgDaU/KNU09jWEEm2XWcyx+ryDRUnAKXhFpQoIrBmLwbd0JYTZrxvBQoypP1xrLQoUZJY0O8q9LwPx/RJkoDk20b8YV2zgIsvFMTTtE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777937806; c=relaxed/simple; bh=+Rk1ExFYE/5E0lN6OmyGkdUYjVIsSU316GsMwHwOZRI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pMQ7Mfh8hrFarrsU/0xwsPPLBwJN6yDXWS/aoahSMVcepUnvKgRhTX4gI68sYc+XfGGEXgqN07qXMW7Gsc/spRI4OSPzyByLynvbtqVbA5I2ISrFn5KgK3h9wuf1xDbR5ltF37Uw9CFIuyWu6oYJser9TDHrCdKe6HV7xdQgE+U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--abhishekbapat.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rvKAGHwh; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--abhishekbapat.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rvKAGHwh" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2bdf75bc88fso7369475eec.0 for ; Mon, 04 May 2026 16:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777937803; x=1778542603; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G+hEq3xcQpeNbVKkmlLzQ0aZOXZlDNVaIlQ1vlmIpXk=; b=rvKAGHwhTCHml8tiPMiOijz/n18bUuNPP7SyhS0YbsJ1luwhM0naGLbqZ34nxnUdBF ymKiEEV58UPVtF7osW02RL0ceMQAFCZ3liHU7YCyrMtMlHcHa5AMH8vNGPyaAM9FsRql XupzcD9bYfGv1qEoL0U+kLh3JRodM4rto5k0nvWKdkzfNYYYK6WRdNH6AM9+nBzpJ6Ar E8bzli8/8NovAmOIZgnKdq+lhVUi35/TjINk04ASljNIgV5u+qycWlXrToRgphIPltKt wAR5dUs9tHTKa3DGcL2KtUHTKOwd4WcwMo3lQhuMuEnIFsCNBiqeYv/vr04vhTo0jWr6 U2ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777937803; x=1778542603; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G+hEq3xcQpeNbVKkmlLzQ0aZOXZlDNVaIlQ1vlmIpXk=; b=mLf5UvnIWyis2f+/s5eKFMkidaZQSUXdCm1pzdzCXjpHIKVbnsBDG8Nc2mTtxLugAG 9AVublEwwNvJD7mAvXQo6RGY4smYfyHGXRU6o2YP8yhJeXzwVymE6WxhXNCyHE5fST2z JU2tlMdsETfYo+deylcqTy5QpMFGQHO4imcZ6cVaio1RvCFY7ferYG6DLCBTXI8kQewJ zXP3/apxnIY8iaM2LBphMvy4PBCr6jlxrlmZdW7dJIeReq/dqcZ/AfSNDNRDHSQtIAug cPcFQbko7VluENWGqNqZV92ZK1DXEGmdROTC5YdCG3O8FPDra0kV20kfgWhBJ5e20gP/ Q+UQ== X-Forwarded-Encrypted: i=1; AFNElJ+2A0ePf2Bgl5w2Wma9QE21cp3m5FwJqq464phglHkJ0dMBbq8GAVp9d9CiGjCtwuKQkBiC1EnPCUE=@vger.kernel.org X-Gm-Message-State: AOJu0YylKCYUwoOsA8WSfySfD1oYl3dP3GYWeXzjVfqJF7w771TSX1Yy eYM3gmywNsoKg00rPVBSHg/cnXBS6V18igo9Ug12JggXnr9ueOmaJ3KOfi7VGAbwILvjBn1ZWFI yfxo6Y1gTCgkTvCSoGp5VbVAW6JpUwq4A3g== X-Received: from dyclh13.prod.google.com ([2002:a05:7301:6d0d:b0:2f3:f2a4:6ea3]) (user=abhishekbapat job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:cd8e:b0:2d2:96e8:1bf5 with SMTP id 5a478bee46e88-2efb7bdc5bamr5234886eec.3.1777937802855; Mon, 04 May 2026 16:36:42 -0700 (PDT) Date: Mon, 4 May 2026 23:36:24 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <26468cbbff1760513043fd3589f9c106dfbbf5bc.1777936301.git.abhishekbapat@google.com> Subject: [PATCH 6/6] kselftest: alloc_tag: extend the allocinfo ioctl kselftest From: Abhishek Bapat To: Suren Baghdasaryan , Andrew Morton , Kent Overstreet Cc: Shuah Khan , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sourav Panda , Abhishek Bapat Content-Type: text/plain; charset="UTF-8" Add the following 2 scenarios to the allocinfo ioctl kselftest: 1. Validate size based filtering 2. Validate lineno based filtering The first test uses "do_init_module" as the candidate function for the test. This is because the associated site will only allocate memory when a kernel module is loaded. The return value of get_content_id() changes every time modules are loaded or unloaded. Hence, as long as get_content_id() values at the start and the end of the test are the same, the memory allocated by the do_init_module call site should also remain the same. Consequently, the test can assume consistency between the value returned by the ioctl and the procfs resulting in less flakiness. Signed-off-by: Abhishek Bapat --- .../alloc_tag/allocinfo_ioctl_test.c | 194 +++++++++++++++++- 1 file changed, 193 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/alloc_tag/allocinfo_ioctl_test.c b/tools/testing/selftests/alloc_tag/allocinfo_ioctl_test.c index 543023ca3d27..573d84a3619a 100644 --- a/tools/testing/selftests/alloc_tag/allocinfo_ioctl_test.c +++ b/tools/testing/selftests/alloc_tag/allocinfo_ioctl_test.c @@ -294,11 +294,191 @@ static int test_function_filter(void) return run_filter_test(&filter); } +static int test_size_filter(void) +{ + int fd; + struct allocinfo_tag_data_vec *tags = malloc(sizeof(*tags)); + struct allocinfo_tag_data_vec *procfs_entries = malloc(sizeof(*procfs_entries)); + struct allocinfo_filter filter; + int ret = KSFT_PASS; + __u64 target_size, i; + bool found = false; + const char *target_function = "do_init_module"; + + if (!tags || !procfs_entries) { + ksft_print_msg("Memory allocation failed.\n"); + ret = KSFT_FAIL; + goto freemem; + } + + fd = open(ALLOCINFO_PROC, O_RDONLY); + if (fd < 0) { + ksft_exit_skip("Failed to open " ALLOCINFO_PROC ": %s\n", strerror(errno)); + ret = KSFT_FAIL; + goto freemem; + } + + memset(&filter, 0, sizeof(filter)); + filter.mask |= ALLOCINFO_FILTER_MASK_FUNCTION; + strncpy(filter.fields.function, target_function, ALLOCINFO_STR_SIZE); + + if (get_filtered_procfs_entries(procfs_entries, &filter, fd)) { + ksft_print_msg("Error retrieving entries from " ALLOCINFO_PROC "\n"); + ret = KSFT_FAIL; + goto exit; + } + + if (procfs_entries->count == 0) { + ksft_print_msg("Function %s not found in procfs\n", target_function); + ret = KSFT_SKIP; + goto exit; + } + + /* + * We depend on the result of procfs entries to create the ioctl_filter. Hence we + * cannot recycle the run_filter_test function here. + */ + target_size = procfs_entries->tag[0].counter.bytes; + + memset(&filter, 0, sizeof(filter)); + filter.mask |= ALLOCINFO_FILTER_MASK_MIN_SIZE | ALLOCINFO_FILTER_MASK_MAX_SIZE; + filter.fields.min_size = target_size; + filter.fields.max_size = target_size; + + __u64 pos = 0; + enum ioctl_ret ioctl_status; + + /* + * This loop is required because the first 32 entries fetched by the IOCTL based on + * the size parameter might not contain the exact entry that was used from procfs. + * If that happens, we must update pos and fetch again until we find the exact entry. + */ + while (1) { + ioctl_status = get_filtered_ioctl_entries(tags, &filter, fd, pos); + if (ioctl_status == IOCTL_INVALID_DATA) { + ksft_print_msg("Trouble retrieving valid IOCTL entries, skipping.\n"); + ret = KSFT_SKIP; + goto exit; + } + if (ioctl_status == IOCTL_FAILURE) { + ksft_print_msg("Error retrieving IOCTL entries.\n"); + ret = KSFT_FAIL; + goto exit; + } + + for (i = 0; i < tags->count; i++) { + if (strcmp(tags->tag[i].tag.function, target_function) == 0) { + found = true; + break; + } + } + + if (found) + break; + + if (tags->count < VEC_MAX_ENTRIES) + break; + + pos += tags->count; + } + + if (!found) { + ksft_print_msg("Entry with function %s not found in IOCTL results\n", + target_function); + ret = KSFT_FAIL; + } + +exit: + close(fd); +freemem: + free(tags); + free(procfs_entries); + return ret; +} + +static int test_lineno_filter(void) +{ + int fd; + struct allocinfo_tag_data_vec *tags = malloc(sizeof(*tags)); + struct allocinfo_tag_data_vec *procfs_entries = malloc(sizeof(*procfs_entries)); + struct allocinfo_filter filter; + enum ioctl_ret ioctl_status; + int ret = KSFT_PASS; + __u64 target_lineno, i; + + if (!tags || !procfs_entries) { + ksft_print_msg("Memory allocation failed.\n"); + ret = KSFT_FAIL; + goto freemem; + } + + fd = open(ALLOCINFO_PROC, O_RDONLY); + if (fd < 0) { + ksft_exit_skip("Failed to open " ALLOCINFO_PROC ": %s\n", strerror(errno)); + ret = KSFT_FAIL; + goto freemem; + } + + memset(&filter, 0, sizeof(filter)); + + if (get_filtered_procfs_entries(procfs_entries, &filter, fd)) { + ksft_print_msg("Error retrieving entries from " ALLOCINFO_PROC "\n"); + ret = KSFT_FAIL; + goto exit; + } + if (procfs_entries->count == 0) { + ksft_print_msg("Could not retrieve procfs entries\n"); + ret = KSFT_SKIP; + goto exit; + } + /* + * We depend on the result of procfs entries to create the ioctl_filter. Hence we + * cannot recycle the run_filter_test function here. + */ + target_lineno = procfs_entries->tag[0].tag.lineno; + + filter.mask |= ALLOCINFO_FILTER_MASK_LINENO; + filter.fields.lineno = target_lineno; + + ioctl_status = get_filtered_ioctl_entries(tags, &filter, fd, 0); + if (ioctl_status == IOCTL_INVALID_DATA) { + ksft_print_msg("Trouble retrieving valid IOCTL entries, skipping.\n"); + ret = KSFT_SKIP; + goto exit; + } + if (ioctl_status == IOCTL_FAILURE) { + ksft_print_msg("Error retrieving IOCTL entries.\n"); + ret = KSFT_FAIL; + goto exit; + } + + if (tags->count == 0) { + ksft_print_msg("IOCTL returned 0 matches for target lineno %llu.\n", target_lineno); + ret = KSFT_FAIL; + goto exit; + } + for (i = 0; i < tags->count; i++) { + if (tags->tag[i].tag.lineno != target_lineno) { + ksft_print_msg("IOCTL entry %llu has incorrect lineno %llu.\n", + i, tags->tag[i].tag.lineno); + ret = KSFT_FAIL; + goto exit; + } + } + +exit: + close(fd); +freemem: + free(tags); + free(procfs_entries); + return ret; +} + int main(int argc, char *argv[]) { int ret; - ksft_set_plan(2); + ksft_set_plan(4); ret = test_filename_filter(); if (ret == KSFT_SKIP) @@ -312,5 +492,17 @@ int main(int argc, char *argv[]) else ksft_test_result(ret == KSFT_PASS, "test_function_filter\n"); + ret = test_size_filter(); + if (ret == KSFT_SKIP) + ksft_test_result_skip("Skipping test_size_filter\n"); + else + ksft_test_result(ret == KSFT_PASS, "test_size_filter\n"); + + ret = test_lineno_filter(); + if (ret == KSFT_SKIP) + ksft_test_result_skip("Skipping test_lineno_filter\n"); + else + ksft_test_result(ret == KSFT_PASS, "test_lineno_filter\n"); + ksft_finished(); } -- 2.54.0.545.g6539524ca2-goog