From nobody Thu Oct 9 13:34:55 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 2FE3D2E2666 for ; Tue, 17 Jun 2025 13:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167438; cv=none; b=t5knzKTz1XYKtDV78n+hQNrnGYfgz1F1Cp5mk5vqfxsRfyjDtHa68PGaMuyHncKASbKzwBpuFN165dFB2Op6dSvIHTEbjYakiiUlMzXWSPm8xpryyy4NqV9ZxIOEhyhwsGKxj5OX113MnN7zi8as3m+72xdj5PHU9/pExGzpM2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167438; c=relaxed/simple; bh=HQNlByHSUvC0ZjiG4WYHMWePhB23AV2AemjXyLk+kJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X+jYHEZdWS4kQGAFS4GldKUw2bjUGM8n1qbQ1pcui1JZHCV8GMlrn/5rKXo8vs+SO2jxkHWQ0MIAymWIxqahnjkF3uEUkNee/ouK9n/3PcbZbUttQxI4ozo2z05YESC3oFebbvdPTYC0KdVR8eJVEbBfL5x1lIhQZybhRrTZ3OI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=UxVxbjKr; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="UxVxbjKr" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-450d668c2a1so45648445e9.0 for ; Tue, 17 Jun 2025 06:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1750167434; x=1750772234; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zgiT6f/x0Fb0H0o2vrOcdtmLUewssNoc2afzunKPIvM=; b=UxVxbjKr9xU0Wp9FRJGuk8fo0GWoKenj2xGcxHgudAF64jKrJHpZIEQzaBdHITuHzv KqccH3sU+gDL2TGYLhPVuRGCsmEQpsBu0iHM2CDLGjbbsSmPHYuzV9jxBuYlonWsRkSJ eqLwTFHNtq4AqXpPxZpDNqj5DyXUVEqhfehvDEd+DcdMmS/ZOo8cGaAQId0TBRRzdrNU CyB2cdu3+kT4FFRBmCCW2upcRNiE81bWAMnNLD0i+Kh4lZGmfBASnS1wBXwbDyF/4BLl ZSUjJsVMgfMlzLzM9VTCCgPztFLSb5iVNe216ir++vw+IRedn1LdwHhWEV3eF9ZXEg0G kTtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750167434; x=1750772234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zgiT6f/x0Fb0H0o2vrOcdtmLUewssNoc2afzunKPIvM=; b=rwsh5JaHIE9iniSf3ck4nAM4/HP46UE5ajzOpT+AIvm9AdaZHOjn2S0TI0H5fljMnf ge5v4aiw+RGKVCIXTpmkB3NY+8UeG7nol6T+Y004JrEfDmTEdRM9wpPfslLHhplYF1wJ kbsVs9zVjSwgi1Povk0yAxD8A6pyLiEayvy+hzbOoAhWz4RKbSXpPWcRAjvQ3LituINo GlWA4L1jjteyfVPDiNwfyXUoK6uqjPgdokdIeXhGmrBs7qPRMiXuFwn/3q4uqrC/5Dkv mRUnQ19tu4vO/0uCJQDFm6rkxgch/Bv710Hs8W3XKVzA7V4BR2uakVPwjUtPA7GLnPSS KOZg== X-Forwarded-Encrypted: i=1; AJvYcCUPs9s8Je8bK7Xs24rJQM8ovGzOBEEPO3BrLmKKckDbtU3K+k8SGtTArxvtUcPVd9H952g6Vec+KsqdCzA=@vger.kernel.org X-Gm-Message-State: AOJu0YwA3SunmFvSfrgmVC/9axomVBRb3i0m11BTfJCjw9LIAqQFD/PH Q65xXP0yCEPlJ5DapCi5gtgn8NqfgA9ohliJyO6FVa/r2Ll0mhdYg7bHW4yaX0QVJYE= X-Gm-Gg: ASbGncvunlcRnJR4oAyPiz0RahdF11UFpasaHewhZJ1m7ppduzzB/hUhdoDSF2fEz/a /jsNIw3XTcr3agOEHiqtoyiK/B1Otj5HaGHVQXY+1ziLHJtQrKC331Tymgwy1qCEv6SqpZZf/3D RE5dmvlXp7dlfHiNAIA3Cm6Y0WDkEwS6mO3yBJYgAYLoDzoMRFp2JbbiuHnV+7pzU3BCFtYAzJR HtleMdAH8wtOf2NXlN7eTlQyfJh6XnTYBqHsLRnI7tqsbVRhRCnJ56SWjxPBKO5fzJd7JoAY0eV z71Szr6Oy2C5gzbYf10bjnIQHVRKh4YF9IgGgwR0OGCSMJMa0/C1Ody+uPuyI+7p X-Google-Smtp-Source: AGHT+IExevrLdNBxON43pa2jl4pvKa6yc0PjeTqzL/jm9rlEgPnVZnIv7wJ2pCS+hEez9KMDG8M4sg== X-Received: by 2002:a05:600c:5251:b0:453:92e:a459 with SMTP id 5b1f17b1804b1-4533b28a97emr130794415e9.16.1750167434484; Tue, 17 Jun 2025 06:37:14 -0700 (PDT) Received: from blackdock.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e224888sm179494365e9.1.2025.06.17.06.37.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 06:37:14 -0700 (PDT) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo , Johannes Weiner , Shuah Khan Subject: [PATCH 1/4] selftests: cgroup_util: Add helpers for testing named v1 hierarchies Date: Tue, 17 Jun 2025 15:36:53 +0200 Message-ID: <20250617133701.400095-2-mkoutny@suse.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617133701.400095-1-mkoutny@suse.com> References: <20250617133701.400095-1-mkoutny@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Non-functional change, the control variable will be wired in a separate commit. Signed-off-by: Michal Koutn=C3=BD --- tools/testing/selftests/cgroup/lib/cgroup_util.c | 4 +++- tools/testing/selftests/cgroup/lib/include/cgroup_util.h | 5 +++++ tools/testing/selftests/cgroup/test_core.c | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testi= ng/selftests/cgroup/lib/cgroup_util.c index 8832f3d1cb614..0e89fcff4d05d 100644 --- a/tools/testing/selftests/cgroup/lib/cgroup_util.c +++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c @@ -19,6 +19,8 @@ #include "cgroup_util.h" #include "../../clone3/clone3_selftests.h" =20 +bool cg_test_v1_named; + /* Returns read len on success, or -errno on failure. */ ssize_t read_text(const char *path, char *buf, size_t max_len) { @@ -361,7 +363,7 @@ int cg_enter_current(const char *cgroup) =20 int cg_enter_current_thread(const char *cgroup) { - return cg_write(cgroup, "cgroup.threads", "0"); + return cg_write(cgroup, CG_THREADS_FILE, "0"); } =20 int cg_run(const char *cgroup, diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/too= ls/testing/selftests/cgroup/lib/include/cgroup_util.h index adb2bc1931839..c69cab66254b4 100644 --- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h +++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h @@ -13,6 +13,10 @@ =20 #define TEST_UID 65534 /* usually nobody, any !root is fine */ =20 +#define CG_THREADS_FILE (!cg_test_v1_named ? "cgroup.threads" : "tasks") +#define CG_NAMED_NAME "selftest" +#define CG_PATH_FORMAT (!cg_test_v1_named ? "0::%s" : (":name=3D" CG_NAMED= _NAME ":%s")) + /* * Checks if two given values differ by less than err% of their sum. */ @@ -65,3 +69,4 @@ extern int dirfd_open_opath(const char *dir); extern int cg_prepare_for_wait(const char *cgroup); extern int memcg_prepare_for_wait(const char *cgroup); extern int cg_wait_for(int fd); +extern bool cg_test_v1_named; diff --git a/tools/testing/selftests/cgroup/test_core.c b/tools/testing/sel= ftests/cgroup/test_core.c index a5672a91d273c..0c4cc4e5fc8c2 100644 --- a/tools/testing/selftests/cgroup/test_core.c +++ b/tools/testing/selftests/cgroup/test_core.c @@ -573,7 +573,7 @@ static int test_cgcore_proc_migration(const char *root) } =20 cg_enter_current(dst); - if (cg_read_lc(dst, "cgroup.threads") !=3D n_threads + 1) + if (cg_read_lc(dst, CG_THREADS_FILE) !=3D n_threads + 1) goto cleanup; =20 ret =3D KSFT_PASS; @@ -605,7 +605,7 @@ static void *migrating_thread_fn(void *arg) char lines[3][PATH_MAX]; =20 for (g =3D 1; g < 3; ++g) - snprintf(lines[g], sizeof(lines[g]), "0::%s", grps[g] + strlen(grps[0])); + snprintf(lines[g], sizeof(lines[g]), CG_PATH_FORMAT, grps[g] + strlen(gr= ps[0])); =20 for (i =3D 0; i < n_iterations; ++i) { cg_enter_current_thread(grps[(i % 2) + 1]); @@ -659,7 +659,7 @@ static int test_cgcore_thread_migration(const char *roo= t) if (retval) goto cleanup; =20 - snprintf(line, sizeof(line), "0::%s", grps[1] + strlen(grps[0])); + snprintf(line, sizeof(line), CG_PATH_FORMAT, grps[1] + strlen(grps[0])); if (proc_read_strstr(0, 1, "cgroup", line)) goto cleanup; =20 --=20 2.49.0 From nobody Thu Oct 9 13:34:55 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 54FDB2E2669 for ; Tue, 17 Jun 2025 13:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167439; cv=none; b=GJt+6dPrC49AaFJ4MkR3eaWLc25Ai94FUQOMTxklGnMKTk20qLu/2FqoIRf2a7PNU+Og2u4RXO8UHQtV8h0BboBh1I768JZ9BHPu/hlmfsj+QFncnjPba1I+kSbzOUweokqyp+pEWjhwVbr7bPKtrJiW4l7y30SxRt31XkuiulI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167439; c=relaxed/simple; bh=rSH5gK1fIkc3yCi10jUMhm+yvhNwSkp/JROUVa650dM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dKFBIt6uAP7MMIAdIeWmKQVg4lBYM+edfXiOqcwmBZbQLV2pXql46ygxl2QNCXRg4RXwVmXXRIHf1sW/Q/51EfsaEQ0n+QZ1+p6BZFbjxm7Hc2Ze9Qf5nqfzaT1jgmg8H4TXzfZ5zQHsMxjXQiFqbRD6L0X8iYqONezLHkVFEzQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Y7lQxTXL; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Y7lQxTXL" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-450ccda1a6eso51521975e9.2 for ; Tue, 17 Jun 2025 06:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1750167436; x=1750772236; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0Cwa1eZzqX2/leDkDIYGlKmwMA4P+ywGvHcq/aUim7E=; b=Y7lQxTXLZWCFbO4Qd9hLPoQunlBpG9xId7JfQpy2iTqlXEm/NFiQy0ccZEvTUte9jB V8L2Bv5EXlUyvcEdlZwA/P9LceOo+3FDBQyfX75nq3KIHFnseL2MsbIptT1EIsvLP9IR uh8ktUtX26GQyRVEhX+loqNPPjT9Fzj7Cb6SSygKIWec/OZRreHWAfffx+g767amMOOx dmbJare+U7g3ZmjVpCtcJFVkdGeA+XeOHjGhSzdk2bBRzLAN8VgY4/VrtdbjoAPfqwtL zEpaTNuPo5xMVcvW1OL0kMvQZL5xiUL85qtNuPlQQlmx7mp22fHTZycPMu1rdvwWilLJ x1hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750167436; x=1750772236; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0Cwa1eZzqX2/leDkDIYGlKmwMA4P+ywGvHcq/aUim7E=; b=fMmRWfL4evstM+d5RA+goHGX4c1+INwNuKtqt0ndUFSY3DSdHZhdw+oln+JbGP7vTT t+HCEimucVrnwJX1104KvAw9XCVWdaDfyr0fQL1wLVcK8Zm1mFa+RPgYpwMQsk3Mv6JW SIzxZb7geAyPOcv0/4aDF4m74DAJEdWwRCuR/RTbJSjxYDNw/PlPgLO+YURzhuQW0aD6 /D20k1/Y11SkXkn2X3SGz3ttaNPlxlLdo8vwdj2a8GcofQlgoLv02EOYA/HUiQK57IQt lC/GH/bnNPvsZJM63KtNJeAanyDdv+9TwG1jffTcDOCqzeUZCqbaFI/KjDSZLM3o+MwV HqkQ== X-Forwarded-Encrypted: i=1; AJvYcCWtPhOR/aukWWXQTsJhjP2AWNNKjEBvVlQcJIXYHHzuK7u8xUo4K0Q2Y5Eg/MFvhJ0MBbY8dtxdXFo11Ow=@vger.kernel.org X-Gm-Message-State: AOJu0YyOieOUR9DoxWGgpa1npXbj9iEkfZ+mo4C0SdAK6Asj0wPfEoqN O5T3mh58imRytWZBnPJuFpBdl8flc0aeByzd4vDLlDm/GtcMySmVmzylQX0M8wniqTw= X-Gm-Gg: ASbGncv87dZ7lS1Ahb04KdqN5a74r/gX2ky7F9jLZzJ8ez1xrlYwHB2nXVmbaQU2LIE kHhdX8Jh2XcqWLgB+UdXUKMI94TTWRatbk+epi3d0NV9HnlCBuhyZwdftX8ndabulZ4csSPjGHl E6VCAlxMIh0uW+G9h/q/cETEPEjwZx9UapmJ7jpDvr9DttnqbiOrfaLA/uY7AHNflO4LJMWTyxO ibJgKthUbseLq/ZtbUhuOA9MePO49nI1PkU2R5qjXCmgcr7zUwqeJXGerlWEqfC3imW3omsjXil lgQOB7Gwzirsw3r3DZfigpkpLQNlh1jrXpxA9hsdA+j3DsGxpd+hIVt2kYP6KT57sRPPsglr1uU = X-Google-Smtp-Source: AGHT+IHu5Zs1DYnyygk8kqdnLgNMGefyGQi3YXLTpFpVjd2SefB+BljZFx/TaAfAHa8CxRgcfYTSMw== X-Received: by 2002:a05:600c:528e:b0:450:cabd:b4a9 with SMTP id 5b1f17b1804b1-4533cacb7dcmr114989205e9.29.1750167435624; Tue, 17 Jun 2025 06:37:15 -0700 (PDT) Received: from blackdock.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e224888sm179494365e9.1.2025.06.17.06.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 06:37:15 -0700 (PDT) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo , Johannes Weiner , Shuah Khan Subject: [PATCH 2/4] selftests: cgroup: Add support for named v1 hierarchies in test_core Date: Tue, 17 Jun 2025 15:36:54 +0200 Message-ID: <20250617133701.400095-3-mkoutny@suse.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617133701.400095-1-mkoutny@suse.com> References: <20250617133701.400095-1-mkoutny@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This comes useful when using selftests from mainline on older kernels/setups that still rely on cgroup v1. The core tests that rely on v2 specific features are skipped, the remaining ones are adjusted to work with a v1 hierarchy. The expected output on v1 system: ok 1 # SKIP test_cgcore_internal_process_constraint ok 2 # SKIP test_cgcore_top_down_constraint_enable ok 3 # SKIP test_cgcore_top_down_constraint_disable ok 4 # SKIP test_cgcore_no_internal_process_constraint_on_threads ok 5 # SKIP test_cgcore_parent_becomes_threaded ok 6 # SKIP test_cgcore_invalid_domain ok 7 # SKIP test_cgcore_populated ok 8 test_cgcore_proc_migration ok 9 test_cgcore_thread_migration ok 10 test_cgcore_destroy ok 11 test_cgcore_lesser_euid_open ok 12 # SKIP test_cgcore_lesser_ns_open Signed-off-by: Michal Koutn=C3=BD --- tools/testing/selftests/cgroup/test_core.c | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_core.c b/tools/testing/sel= ftests/cgroup/test_core.c index 0c4cc4e5fc8c2..338e276aae5da 100644 --- a/tools/testing/selftests/cgroup/test_core.c +++ b/tools/testing/selftests/cgroup/test_core.c @@ -148,6 +148,9 @@ static int test_cgcore_populated(const char *root) int cgroup_fd =3D -EBADF; pid_t pid; =20 + if (cg_test_v1_named) + return KSFT_SKIP; + cg_test_a =3D cg_name(root, "cg_test_a"); cg_test_b =3D cg_name(root, "cg_test_a/cg_test_b"); cg_test_c =3D cg_name(root, "cg_test_a/cg_test_b/cg_test_c"); @@ -277,6 +280,9 @@ static int test_cgcore_invalid_domain(const char *root) int ret =3D KSFT_FAIL; char *grandparent =3D NULL, *parent =3D NULL, *child =3D NULL; =20 + if (cg_test_v1_named) + return KSFT_SKIP; + grandparent =3D cg_name(root, "cg_test_grandparent"); parent =3D cg_name(root, "cg_test_grandparent/cg_test_parent"); child =3D cg_name(root, "cg_test_grandparent/cg_test_parent/cg_test_child= "); @@ -339,6 +345,9 @@ static int test_cgcore_parent_becomes_threaded(const ch= ar *root) int ret =3D KSFT_FAIL; char *parent =3D NULL, *child =3D NULL; =20 + if (cg_test_v1_named) + return KSFT_SKIP; + parent =3D cg_name(root, "cg_test_parent"); child =3D cg_name(root, "cg_test_parent/cg_test_child"); if (!parent || !child) @@ -378,7 +387,8 @@ static int test_cgcore_no_internal_process_constraint_o= n_threads(const char *roo int ret =3D KSFT_FAIL; char *parent =3D NULL, *child =3D NULL; =20 - if (cg_read_strstr(root, "cgroup.controllers", "cpu") || + if (cg_test_v1_named || + cg_read_strstr(root, "cgroup.controllers", "cpu") || cg_write(root, "cgroup.subtree_control", "+cpu")) { ret =3D KSFT_SKIP; goto cleanup; @@ -430,6 +440,9 @@ static int test_cgcore_top_down_constraint_enable(const= char *root) int ret =3D KSFT_FAIL; char *parent =3D NULL, *child =3D NULL; =20 + if (cg_test_v1_named) + return KSFT_SKIP; + parent =3D cg_name(root, "cg_test_parent"); child =3D cg_name(root, "cg_test_parent/cg_test_child"); if (!parent || !child) @@ -465,6 +478,9 @@ static int test_cgcore_top_down_constraint_disable(cons= t char *root) int ret =3D KSFT_FAIL; char *parent =3D NULL, *child =3D NULL; =20 + if (cg_test_v1_named) + return KSFT_SKIP; + parent =3D cg_name(root, "cg_test_parent"); child =3D cg_name(root, "cg_test_parent/cg_test_child"); if (!parent || !child) @@ -506,6 +522,9 @@ static int test_cgcore_internal_process_constraint(cons= t char *root) int ret =3D KSFT_FAIL; char *parent =3D NULL, *child =3D NULL; =20 + if (cg_test_v1_named) + return KSFT_SKIP; + parent =3D cg_name(root, "cg_test_parent"); child =3D cg_name(root, "cg_test_parent/cg_test_child"); if (!parent || !child) @@ -642,10 +661,12 @@ static int test_cgcore_thread_migration(const char *r= oot) if (cg_create(grps[2])) goto cleanup; =20 - if (cg_write(grps[1], "cgroup.type", "threaded")) - goto cleanup; - if (cg_write(grps[2], "cgroup.type", "threaded")) - goto cleanup; + if (!cg_test_v1_named) { + if (cg_write(grps[1], "cgroup.type", "threaded")) + goto cleanup; + if (cg_write(grps[2], "cgroup.type", "threaded")) + goto cleanup; + } =20 if (cg_enter_current(grps[1])) goto cleanup; --=20 2.49.0 From nobody Thu Oct 9 13:34:55 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 608AB2E2667 for ; Tue, 17 Jun 2025 13:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167441; cv=none; b=gJFb0/lCFyewe/4RZvgz65QiLc/FuJ2VeiJkffeBn+v18XxdpamrlEIWH9k0iwgw134RvmTi5T0ZV0TIfJbwaZ9D7I+mZGS5FGeQvHz6GaIjkf8DFkfjhCqfJXn1RKue7e7qqXa16ZcZqVYQFfXbMStL1Qzrv7DrNHSmXvGt8+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167441; c=relaxed/simple; bh=yGgw6Mn0umYKmzsCB8BL/2ViW2Q7/PLM5b9EyoXAOVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l3ddFuO+xblE7N+G+q/a+RRkoCvW+WfPvA3XbQiuP7BHdC6LhXYhXJRB7ei7Wj5mXpSjdt77HByDJLT9LG/u2j9OZxbenGLWS0VAv/gklL1EKyLYCcQ0x1OU6ZAWSlVPm84psfMt5d9gJi6C55yz1iz2PDNQSgjDIDbBlwa+t9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fXJ+lSyV; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fXJ+lSyV" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-450cf214200so49188155e9.1 for ; Tue, 17 Jun 2025 06:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1750167437; x=1750772237; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gY+ZL5/CdCDr9pYfYWcTDJPdb5lvMHKJxSeQMsCXxr0=; b=fXJ+lSyVZJNNYSoLKL/AmosATC7dzs5LYipU95edOrjBLXU1C+5UFwm16Itc5ZXIRC 28ltA5vTHtb6YRwPYPqAZtk9B1si5nNvbJAM4SD46pzn5ZILkY5SSpve+k/0cllhZOJ5 x1cA+r3uQAL4Rx0nv8gIw0QC0BJzlAQzKl7rutr8Wz3mk0mUrqmKefaF088mFezHMgtS VylCj4G6KLXys/xIVcZz8LzNNQkoAs/UDftEJ0ZaVp5eZVhDBYxDxp3u27FgjEGgTPPA xB3agn//DcXZmfGrEk789FgJ3ivb4GeUCZdaH9Ov04IEZnn84Hq0tPYknYH6pkgMxzsg Fv1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750167437; x=1750772237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gY+ZL5/CdCDr9pYfYWcTDJPdb5lvMHKJxSeQMsCXxr0=; b=i/H4AjC6Bo/BO5LVTAp8vl19ISeVKngpmNGMhzrmkNk8cdVI/9/Uhf08fMPKgqYBHu k/5jj+dRkXZGKFRQqRqLqDPczjXIg/R01q0S+xKhnLJDNyhfjBDHnUa4Xwk+oWg6qivx QkJuwAtGbvmMHMBGdOEvdLJYcRa0BRk4KTcEQ8o05gYaRFYokU+A+nLJZNJozFLf8sXs ujLY7SnZNcua4hC3XPke28qNkb2oVeXfaSIHdhQ0LRqAaq3RyF1cSoseyZbsK75/h9pj a9ZMtTV/bcKM2CAQlOO5ImAOnFqYngzydeo+M0gdSfmO01jYe/19HVYkkUGzqvTJyBEg UhTg== X-Forwarded-Encrypted: i=1; AJvYcCWuNGmQ4Fr5eVo75toPcrRbyhIiIp1tCfceOQqhZrauvoE7NIOFl82qcti1L7OOMLFEmQAbuNyghbtMK3A=@vger.kernel.org X-Gm-Message-State: AOJu0Yxi8z7jlpI4iibOgKINZwRAhlwi++GAHtd1jaU1ooL7HTObRR3M hycr984kBsu4JdmBG6XndBqfG8DfAy1MQUTq4XUhOmtoOFAzFkx855uBlfNXN0+W1IA= X-Gm-Gg: ASbGncsxBgfIPk2E01E/vRc/ZjIxbK9JbGmonmdSLCMnPMgPr6HA8hfV9JrKCrQkhh6 GbiN0xYZlp4A3ogy1CiE5dB+G5lss5aeH5TPqH3fues/esbI0N4KLq9Q+WpOpzndnr1QOJXM5q9 93ILFK1jrn+NtXTtizgJHgasJyeWpTjZSgmOocuGUC+zmipkTGuVeVvLcqIF7g5R17SuGMBCpNp Auc9N8Qi0VzxmfcryoDF+Q6M7u5mqAl3Ur8uMW5uawDHKbFYvNhOXfYPYlZJPpC/7hex8owXiJf ATHPMi2eXJOD22/JDkhwFyfJyPAYJWqV9YjCl1ldz0qKKvBEPnR8iDWoaCccXCFo X-Google-Smtp-Source: AGHT+IFpq9WEDmoZNu9HpxpLoTTCX7cKZVAPrAxP5TMGyBzJKcO6qgbPg4kQjxzopi6DV/N3EhJo/A== X-Received: by 2002:a05:600c:37c9:b0:43d:3df:42d8 with SMTP id 5b1f17b1804b1-453513f2aa4mr38219795e9.6.1750167436685; Tue, 17 Jun 2025 06:37:16 -0700 (PDT) Received: from blackdock.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e224888sm179494365e9.1.2025.06.17.06.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 06:37:16 -0700 (PDT) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo , Johannes Weiner , Shuah Khan Subject: [PATCH 3/4] selftests: cgroup: Optionally set up v1 environment Date: Tue, 17 Jun 2025 15:36:55 +0200 Message-ID: <20250617133701.400095-4-mkoutny@suse.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617133701.400095-1-mkoutny@suse.com> References: <20250617133701.400095-1-mkoutny@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Use the missing mount of the unifier hierarchy as a hint of legacy system and prepare our own named v1 hierarchy for tests. The code is only in test_core.c and not cgroup_util.c because other selftests are related to controllers which will be exposed on v2 hierarchy but named hierarchies are only v1 thing. Signed-off-by: Michal Koutn=C3=BD --- tools/testing/selftests/cgroup/test_core.c | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_core.c b/tools/testing/sel= ftests/cgroup/test_core.c index 338e276aae5da..452c2abf9794e 100644 --- a/tools/testing/selftests/cgroup/test_core.c +++ b/tools/testing/selftests/cgroup/test_core.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -863,6 +865,38 @@ static int test_cgcore_lesser_ns_open(const char *root) return ret; } =20 +static int setup_named_v1_root(char *root, size_t len, const char *name) +{ + char options[PATH_MAX]; + int r; + + r =3D snprintf(root, len, "/mnt/cg_selftest"); + if (r < 0) + return r; + + r =3D snprintf(options, sizeof(options), "none,name=3D%s", name); + if (r < 0) + return r; + + r =3D mkdir(root, 0755); + if (r < 0 && errno !=3D EEXIST) + return r; + + r =3D mount("none", root, "cgroup", 0, options); + if (r < 0) + return r; + + return 0; +} + +static void cleanup_named_v1_root(char *root) +{ + if (!cg_test_v1_named) + return; + umount(root); + rmdir(root); +} + #define T(x) { x, #x } struct corecg_test { int (*fn)(const char *root); @@ -888,13 +922,18 @@ int main(int argc, char *argv[]) char root[PATH_MAX]; int i, ret =3D EXIT_SUCCESS; =20 - if (cg_find_unified_root(root, sizeof(root), &nsdelegate)) - ksft_exit_skip("cgroup v2 isn't mounted\n"); + if (cg_find_unified_root(root, sizeof(root), &nsdelegate)) { + if (setup_named_v1_root(root, sizeof(root), CG_NAMED_NAME)) + ksft_exit_skip("cgroup v2 isn't mounted and could not setup named v1 hi= erarchy\n"); + cg_test_v1_named =3D true; + goto post_v2_setup; + } =20 if (cg_read_strstr(root, "cgroup.subtree_control", "memory")) if (cg_write(root, "cgroup.subtree_control", "+memory")) ksft_exit_skip("Failed to set memory controller\n"); =20 +post_v2_setup: for (i =3D 0; i < ARRAY_SIZE(tests); i++) { switch (tests[i].fn(root)) { case KSFT_PASS: @@ -910,5 +949,6 @@ int main(int argc, char *argv[]) } } =20 + cleanup_named_v1_root(root); return ret; } --=20 2.49.0 From nobody Thu Oct 9 13:34:55 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 5A71E2E2675 for ; Tue, 17 Jun 2025 13:37:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167441; cv=none; b=e/zXOBspJVLxH6se2Pr9B0iYOcfvlNfBaJ6jYeaqZjMfkhmBFo7oyuKMAa/9mV8KvHipL0/PQs7reYsIg0aW8pqnU0MRgGyqX98zqcZhj+Ne8pkjMNudtMDoKtSZxbzBibtY5WekZUjhGMsItdPoUDUWXApekP3vmZZ7GTsQ/vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750167441; c=relaxed/simple; bh=xtt2rNThOOd0Ch0ay5t/SRPt0e7QyIQa+1AuoLWf+2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RqRHMWQVAEvNfHx+GBMxc9oVoAqPGsMXB2uKBVDV92YLffwEDidh4GrwTxpqL3NU7UAVzQRhhk+a3vW8tg68akKGFL9sDHbi/Nu5/F78nmixclhb0fO/ZnpMFc9BhTKl8kruo4g569pJQEAoAWY/Jd30X89BtW0eSzD7rOrS+KI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=ZcK8urI6; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="ZcK8urI6" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-453426170b6so17706305e9.1 for ; Tue, 17 Jun 2025 06:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1750167438; x=1750772238; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/IirAviWa54+DB/4fGXki7ILuYvAogeRyMVXvAl7uRo=; b=ZcK8urI6w0HZat+W0ETrhst7YwkcpUv2RNrOMD4e51q9NcdtuCa8LB1WZylPwpgd2B bSpseIJDU1r2cJ2GlZ0j4MjwBa7n6sDdDoKxrAu7Tq4dC+0vYIAFLrkeznw/hQXHPrTh KBtGAwMekGhwBmCPEKW4sZ1W7hN7/D/4ZmndrmXvsfnhOLhOAr5YcRAtMOUzooPLAifJ TD6gI1ImQ381LaXyPLL87o04QrQWuTiRKqvQctth9IJB+zM/LNUlYScY/xolpjhGWJEZ BB5iaONU6ouovoVBnR0PGzVU7u+ADE2Hj7uQ3GzgmVskyDdD+EXzqnfkt8xkwPpxpjIV mgLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750167438; x=1750772238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/IirAviWa54+DB/4fGXki7ILuYvAogeRyMVXvAl7uRo=; b=g5sM+DurCTTylQQ0oVSWOMHd203PWiGimFCs7h5U/n3ZSBHCwQ8nIvj08T9JejrYmy KVMedfHGg5S/AZ1UpdQMJ2B1kIDtQaVv+CbwIFtduVwNEg97y01F1UBLa9VBS3NzGq5W WXbHkEpxquLAW9qYY2ib3QvugcA3A+y4udx0JoKT6aWtp3KK+y9snq9733jjk0uzc7CR WPpOVBh8bit4cJDESFaHdVNH4s78xAH5Z7aW3hh7ESG/zNh7KcLyuIcoJ9ROlnp+2GBj aumwlI2ftcKXxKSBeCTsSOxZ3aykV+FTswWg0NXDrJ9D+5zPIyP5w8C+65qPc+ezgyC7 5w6g== X-Forwarded-Encrypted: i=1; AJvYcCUgm/Gd1NTq2IxV/SsZ7B0GOP8zIA4gAOdeAF5/plzXkKTWXmMAIfJ6xRCUK8XghA1Xv6XilmEkzQ9AFYM=@vger.kernel.org X-Gm-Message-State: AOJu0YxImz1cLxlaCmt+iSO+zBpaYlzzt6SU+jit8R8oq8EqYrXL5scD qvxyOWiamDGXNhCNGClrIqFS6Hr++ikS5abN3jKN3+u+Aiw9FSe6LdRF8D8z628gTj0= X-Gm-Gg: ASbGncuOPpDcOCFkJ9j7thpqnVh22stKcAkoic5oSIxsMbkXC40HwT3Bkhl0Q1hGSY/ oVj5/Wt6jWHgvQNxCLmLyESSqJ8IRqFkD3dZ68EDCxU0u4mKg3e9hLk6Tu3mpduTJ3no/d5Z4qS 6rWa9kBytwEv4SYwftCVjExQ3MGSM1tLnsmDNiQ2x0s4q+Med+qexavXooxCtQINh0DWlT2THeA xaAHXQbvZkY3vgMHbKVhIWm0Qli/cOVRNTxSFo/ddwKzyS6cXhMPBO//6GekoRDlUkxRZem03rC qyzN3xX7FytVn2+2WU2/DQsuDYYXKWuXk1bT+W54SZCjy7+lpgNIsTnVgyUTv9cTt2twxS750c0 = X-Google-Smtp-Source: AGHT+IGrwE0n8xObbXy+xwulox5ORPMmG9dF8KEQ/VAwCkDtHw6tIijP1d7NSitWFCIxbglfxPVesg== X-Received: by 2002:a05:600c:5908:b0:453:827:d0b1 with SMTP id 5b1f17b1804b1-4533b235e16mr90149065e9.2.1750167437646; Tue, 17 Jun 2025 06:37:17 -0700 (PDT) Received: from blackdock.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e224888sm179494365e9.1.2025.06.17.06.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 06:37:17 -0700 (PDT) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo , Johannes Weiner , Shuah Khan Subject: [PATCH 4/4] selftests: cgroup: Fix compilation on pre-cgroupns kernels Date: Tue, 17 Jun 2025 15:36:56 +0200 Message-ID: <20250617133701.400095-5-mkoutny@suse.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250617133701.400095-1-mkoutny@suse.com> References: <20250617133701.400095-1-mkoutny@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The test would be skipped because of nsdelegate, so the defined value is not used (0 is always acceptable). Signed-off-by: Michal Koutn=C3=BD --- tools/testing/selftests/cgroup/test_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_core.c b/tools/testing/sel= ftests/cgroup/test_core.c index 452c2abf9794e..a360e2eb2eefd 100644 --- a/tools/testing/selftests/cgroup/test_core.c +++ b/tools/testing/selftests/cgroup/test_core.c @@ -21,6 +21,9 @@ #include "cgroup_util.h" =20 static bool nsdelegate; +#ifndef CLONE_NEWCGROUP +#define CLONE_NEWCGROUP 0 +#endif =20 static int touch_anon(char *buf, size_t size) { --=20 2.49.0