From nobody Mon Sep 28 09:58:45 2026 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 96CD4376BD5 for ; Mon, 24 Aug 2026 03:35:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787542547; cv=none; b=ccG9Gw2hhsrgQePDgrLp7wVwhTdIUGiCav7TJKZkGVX7ryAMM6RHbUlOipZfvYLXxsaseT9vEBZiC370SyJwMfLTPyjv/lphonf05QFL2WBj99UQ5W4pofC+ycnZQAVYG3TjcNjfNuTrRFR1nVEbKMjgyfXQkuai3+BbDX3Wgp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787542547; c=relaxed/simple; bh=RX9tbEJGh8uuIbWQO+YgeJhWqknJ4mX0lzATa1cSsnw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W4+LBLMy2Ba/x0aCqVdIwiVA4ph8jXiQLG5iNCfpbEL762XvylpNJ4gNRyRXulk+pXcn038BcyRJJBuVgQrPJcWeK4CVBkjrxCG3yzFnVFsZDaBhsbT0/jP9GQeNsfj8hVGCYxL+4BAYOwRJb4xpLWoCdBL8RyFIeDnpTdkpvzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wfelipe.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VNB/g7sy; arc=none smtp.client-ip=209.85.214.199 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--wfelipe.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VNB/g7sy" Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2cf1c86963bso37728215ad.0 for ; Sun, 23 Aug 2026 20:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787542545; x=1788147345; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=uLeWQI8viIKf2ncJdeLCdpToNayUvXof6lXIwZBpCjQ=; b=VNB/g7syu5iKfwGAIFnAWhzrE/lyAEE3JUdz4SeHPDtFS2nJlSOCa1GN+RoKZ8TlK8 gLS7fNA1ME6YVq5vjSEP+e9V4AF3PP2/oQE0q8IF617bzq2JwdRbnfx/bnOpHPCNcEYq iF2tdmpVKF5t3Vve/EYh2VdlEjMGSfSD5xdMVJVerFzW19qA+V+WEe9D6X6EVDi2yRJM 049TiffLfRq6IbLHG6cfNipB1IJqS4gWHm3nqXvvSaqe29LNoVxFDXf/V2QEky/BAXc9 EsDCnTTpg0+TvzJiQSpaeiOio0IxhY+PpAsdRUnBUoOUSY5mgITaVgg4M/Yjk+O/fYtU NVdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787542545; x=1788147345; h=content-type: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:content-type; bh=uLeWQI8viIKf2ncJdeLCdpToNayUvXof6lXIwZBpCjQ=; b=m5w5EwdTkyjWtUhxwFM7TpAdev/Cv81yANTgNv48EzOI5MmabBOzV0jWkMiRWMOsGa xifZILuCRxzTpMUJX4/yN7BoXdydMarrVw5XH/HazegwQNIlaOYNYzMCROEOs4WzjzvF apbUvSpr7XUESgPR42ZVFUjR1A/cHzjgnWzD4XG/RK3oR9oJkt9PmZ3KFhxuuQ9GPzoV 9YS4gHNp4T5YyeCC+bG15E8rhAAs6IKZYJcuuaS1lc5MaHAJ/t/pMQC9MN1CNTOudHb2 DSqUd4joQjYdbfhf6PXLV64ezub3GTgnkifZp21uyJb7z51EeuCXuvPNINxVyAxG5IRO 4OrQ== X-Forwarded-Encrypted: i=1; AHgh+RqAxKcOp9hwbehv1rNQsm+Ma6WHiIe0FTNRAxYomgVwyfttWuOXGLRXDHV2g8CjldS0tGqGIpYstr3xu64=@vger.kernel.org X-Gm-Message-State: AFuF++mmzAQJreGfJ0/71xDraOOtvxcEuunRk9x04yQ1Q2w7w8V2E5P/ ZL4PYsrT2g3V48T7S1o17WjrMa08k7pgVXlEgwSUByVFpU3Oet0XFvD4vONHaDMmW2Mi1oUWpeT ozB+hSjmfPw== X-Received: from plgk2.prod.google.com ([2002:a17:902:ce02:b0:2d5:6077:5a69]) (user=wfelipe job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3b85:b0:2cc:ac15:ff4c with SMTP id d9443c01a7336-2d61a0da51fmr357601025ad.8.1787542544728; Sun, 23 Aug 2026 20:35:44 -0700 (PDT) Date: Mon, 24 Aug 2026 03:33:57 +0000 In-Reply-To: <20260824033533.2147900-1-wfelipe@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260824033533.2147900-1-wfelipe@google.com> X-Mailer: git-send-email 2.55.0.766.g2966f0265a-goog Message-ID: <20260824033533.2147900-2-wfelipe@google.com> Subject: [PATCH v2 1/2] selftests/cgroup: test_zswap: wait for cgroup to unpopulate in test_zswap_writeback From: Wilson Felipe Pereira To: Andrew Morton , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Tejun Heo , "=?UTF-8?q?Michal=20Koutn=C3=BD?=" , Shuah Khan Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Wilson Felipe Pereira Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When running test_zswap on a single-core VM (-smp 1) with 4GB of RAM, test_zswap_writeback intermittently fails on the initial run after boot. In test_zswap_writeback(), after waitpid() reaps the child process created by test_zswap_writeback_one(), writing "+memory" to cgroup.subtree_control can fail with -EBUSY. Under cgroup v2, enabling domain subtree controllers is forbidden while any tasks remain in cgroup.procs. When a child process exits, exit_notify() wakes the parent process, allowing waitpid() to return immediately. However, the cgroup populated task count (nr_populated_csets) is only decremented when the exiting task is switched away via finish_task_switch() -> cgroup_task_dead(). On single-core systems, the parent runs before the dead child has been switched out, causing "+memory" to fail with -EBUSY if written immediately after waitpid() returns. Fix this by waiting for cgroup.events to report "populated 0\n" via cg_read_strcmp_wait() before enabling subtree control. Signed-off-by: Wilson Felipe Pereira Acked-by: Michal Koutn=C3=BD --- tools/testing/selftests/cgroup/test_zswap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index 49b36ee79160..a7ff525c1267 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -407,6 +407,8 @@ static int test_zswap_writeback(const char *root, bool = wb) * Thus, the parent's setting shall be what's in effect. */ if (cg_write(test_group, "memory.zswap.max", "max")) goto out; + if (cg_read_strcmp_wait(test_group, "cgroup.events", "populated 0\n")) + goto out; if (cg_write(test_group, "cgroup.subtree_control", "+memory")) goto out; =20 --=20 2.55.0.766.g2966f0265a-goog From nobody Mon Sep 28 09:58:45 2026 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (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 B022C3769E6 for ; Mon, 24 Aug 2026 03:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787542549; cv=none; b=VrVIo/t2BqC8n6fsV2ZBcg2NmX3GruxsiLYGMUoA0zGvwaXEuzdwjOCmAHE0otljYq7r6DdBopRri+c1ZyxZTU5kXZbyvkM2CDMMK3/g4QC//M4UoguIq7bwfjNj9O9CZK08NzWWQhqjWILUnLs7qi245A5Mpij79eYrGagmoKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787542549; c=relaxed/simple; bh=ZPJSq86XxODsr8ReS9fo29csRVH7asRRDJ2W6dyxgDI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=usOcsZ3gtLGkJLdPIQHEeip4OdBafb/Nici/eG2ouao3G7SwUS9cenVwx1T7OHZmeXPhCDpkBC0kaiR249e2soPkPafyrCmzDEDVkDEXTULJUcpv536TvM/AZ6FDXz9T+logef3c7reixOR6XimoaTqIFUigSYqUQCzEuHK/gHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wfelipe.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nEnUIMVv; arc=none smtp.client-ip=209.85.210.198 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--wfelipe.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nEnUIMVv" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-848860def2cso3059853b3a.2 for ; Sun, 23 Aug 2026 20:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787542547; x=1788147347; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DZMAXxlnSgWC5Kd65SinCWudGpzS4DSeLZoz+Rd1kKo=; b=nEnUIMVvpmMlTuI/RtQGtW/efiKK2kmdiJtl2hSQj7JK+GrrN+PTZbGCf30cRAbBhD pDut+100XrDA1KG2bu2u+5iHny/06KuREhk0isKEUrSSgsg38aD8kVOPhG6A/HyNE2oB TqJBwbdGCC9WJaniQHc1ea7uDdHSfG0hJ7WbEa9Gux1gvsA8ujYSZ9RLxwxVuXNM564l VOqQ6pfO/M4P4PRzhERGgIWyS7KQVrOSPd8/8R+SvPyZW2gHZAAFOh5zkv7MC4kZbK9f C4pOia0vdzNmsmhUTv8Jj+U1ZPqVp0DbKr9lbDCz2ApCueoOJL7hUzXEweTgvgw11lpV y80g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787542547; x=1788147347; h=content-type: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:content-type; bh=DZMAXxlnSgWC5Kd65SinCWudGpzS4DSeLZoz+Rd1kKo=; b=Ok7gwIMRDWMOOtb9uULHxEXyD0yZsyL+iHRw/UDsxu8a6lrwWtLYj0zorN/j0VGWro DWiTPGMnHdm3qScr3gy7nIs9szG2hT+8anlZxJygMyH/gJPbAPemgVqTEzCtiJjCFEIq 9xNN7E4VHLqtpq1rsGxY9dKk6ak8W4Is1Qnr5Y5jXsdZpieer8mAY2pHW3liX9zainO6 T/UWX2q9oNpnxQ16sKvUL0E2oTA1X/7xjeQDty2jNQx+nvqmqsT5AN9py2a4gvJ/8DrX 2RFyt9m7NlJbEGRN/bnjJ+4wmBnFw92HELKT2d1ArFd1QofysfsMx4g4UbVXaO6LsUZQ wwpA== X-Forwarded-Encrypted: i=1; AHgh+RqzhnVnu+CuwC1AkXvLQyO29nmz+uqMAr8rfM9s2OOQKaw3mzJdKS8bXygdtCc8CsnLNRn2YfjxQQMjlv8=@vger.kernel.org X-Gm-Message-State: AFuF++kwyC8pYA6592kQo5UzMt/NtKiMZYkOfqM/sAqpVk5NfxO69PRJ Q/nzr+Gv7nGvOURilcSj1WXBAlB2IkMMYlQuHWVMGjmXddfi2ruG52bxX3x7so2zxC3YfHe0BF8 Zb+OZWTGEdA== X-Received: from pgnf25.prod.google.com ([2002:a63:7559:0:b0:cc1:513e:8b94]) (user=wfelipe job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3b89:b0:3c3:7a0a:18a6 with SMTP id adf61e73a8af0-3cd4bca353cmr29799231637.18.1787542546697; Sun, 23 Aug 2026 20:35:46 -0700 (PDT) Date: Mon, 24 Aug 2026 03:33:58 +0000 In-Reply-To: <20260824033533.2147900-1-wfelipe@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260824033533.2147900-1-wfelipe@google.com> X-Mailer: git-send-email 2.55.0.766.g2966f0265a-goog Message-ID: <20260824033533.2147900-3-wfelipe@google.com> Subject: [PATCH v2 2/2] selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass From: Wilson Felipe Pereira To: Andrew Morton , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Tejun Heo , "=?UTF-8?q?Michal=20Koutn=C3=BD?=" , Shuah Khan Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Wilson Felipe Pereira Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In test_no_kmem_bypass(), delta (stored_pages * page_size - zswapped) is checked against stored_pages * page_size / 4 to verify that the pages pushed to zswap belong to the test memory cgroup. Due to slight stat update timing differences, delta can evaluate to a small negative number (e.g. -5MB out of 1GB). Because delta is declared as a signed int and stored_pages is an unsigned size_t, C's usual arithmetic conversions implicitly promote a negative delta to a large unsigned 64-bit integer, causing `delta < stored_pages * page_size / 4` to falsely evaluate to 0 and fail the test. Fix this by declaring zswapped and delta as signed longs and comparing against a signed threshold, ensuring negative deltas correctly evaluate to true. Fixes: a549f9f31561a ("selftests: cgroup: add test_zswap with no kmem bypas= s test") Signed-off-by: Wilson Felipe Pereira --- tools/testing/selftests/cgroup/test_zswap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/se= lftests/cgroup/test_zswap.c index a7ff525c1267..15cc1dfdd1f4 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -621,9 +621,11 @@ static int test_no_kmem_bypass(const char *root) break; /* If memory was pushed to zswap, verify it belongs to memcg */ if (stored_pages > stored_pages_threshold) { - int zswapped =3D cg_read_key_long(test_group, "memory.stat", "zswapped = "); - int delta =3D stored_pages * page_size - zswapped; - int result_ok =3D delta < stored_pages * page_size / 4; + long zswapped =3D cg_read_key_long( + test_group, "memory.stat", "zswapped "); + long delta =3D stored_pages * page_size - zswapped; + long max_delta =3D (long)(stored_pages * page_size / 4); + int result_ok =3D delta < max_delta; =20 ret =3D result_ok ? KSFT_PASS : KSFT_FAIL; break; --=20 2.55.0.766.g2966f0265a-goog