From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 829B93546F7 for ; Fri, 12 Jun 2026 06:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781245453; cv=none; b=dLnt8ZkBIK+uJo3Y9iYeK79QJn23o8zAX+Po+C3KAbEJbm4cpSR3y10cYrxKth8gO9Basj+GiMoQKfBplaZ5JweBD3xBQw2NZQUPJAHJU/1UeLRHcODUxiC4fm3SylPN3F9JJpuHoRxGagRbzjphnjqh2lNOTmVFOXAKkf0/FKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781245453; c=relaxed/simple; bh=V4degicP98YaeLR08jiuNOlhbT3ArmkZyO1D0XGygGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VngrjmEv6ljLkppt5a2va4rBuyn8vbmKmMKUhATOKG+8G1YRMeW0Ffu8+rSFdcuNTlAUTSNGtOOmY4UdYLed+Tp4cOq6cguNwzzbrr+RB6NSPgWMO+TQxFrVdp2dKUGUKEwDOLpZU2kW6MYpTQVC0IuDLfPJv7COi2ZdOHWmxco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UqWHhdoF; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UqWHhdoF" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2c0c2e8d381so1388785ad.1 for ; Thu, 11 Jun 2026 23:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781245452; x=1781850252; 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=45sVfS/nx2nzBsCxkzCB9QiCoVHDr0etpbiBAxE4XQM=; b=UqWHhdoFlhEJI0xLkbtfAsUB5F2i09YWQKQGcpIFNJveF+BJiYp8fSXk7Q+JAgWjum lXOSwnV5iJUiSnWmyOQ8aK2nkjyelP+w9+LKVko+S23G8FOYGXI9G7+UdaAYWeAdynyZ tBs/IvCJ3ReqFgqCgHufoKxmd93GiOdnJGKyiTZttoBCTOCHBRixiES3xP1FSFU5DwC1 Q7hGs184oBXTXDgAJRhM3LDa8Ji1mvE/kR1VMKnpP0MjvvXgZAxKoEuClEeOTFXJ2rXM dA7PWwwc22icBO4FgV2UXcvBm0Iv9UJuHcgMCo33ftV89Q4kr2hKQUKIiHY0DAVD3Q11 N9aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781245452; x=1781850252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=45sVfS/nx2nzBsCxkzCB9QiCoVHDr0etpbiBAxE4XQM=; b=fYxToZsoDyi+DJhn5wMBBbYKvIrkqeQxasHoqgKNGPunTojhbZo+BPRB5yBzJxget1 2hE0chdWE3Q+3nxU3UlRPOM/XatspzLBrU9rPpxQVWfw08GgjEwYeHUOOz642STh891d gU8ns3HH9MmMuPJTGaQYIg5ougc7ufZvGxH3JlLFYot+o0EuHAKgSkjSph3Gvc4jzi3/ fmzfubczHzd9l0EyLIIHT9oJ2L+/L3z2BFNRkHPqUoWi7wlqfUYzZZbipeGssdQYegA/ tJMo9n0Z9Y6EQshNDSSyK1VSKX6JDtbxb/nFh2pyedpfUbK110TW366Lq2ZGO5OQ0FKK 0OJg== X-Forwarded-Encrypted: i=1; AFNElJ/DD4X+pxbp3obJlQKFwRuROWgn8VDYMLVLDPPBIHQkNNLkq/GrGiVCVtmqhuoBxtRt56ckuDxZTHOFGTA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywc49kQ1bVnKleMxwwUh0Kxpzo/k5i6rdqbtB6o74D17z9mUXMi PyNbKMgVidPwNLrvkhGI1LAhKDgCUwy2pVrLb3J/KqJTf3gkuEK5ao5y X-Gm-Gg: Acq92OFY3x2039Ex3yapIRwJAmZGRIqV5KXcrhACLRO61V2mkoKjGKYt1YH+3W52hlW k6qxvkCjH+HzGHyxYfbYeoZ8XhpCNV7/dC+tz5JUrqQwG77epPGIT9lC3C4T6eRqZ4r3uLV4ghd v9ePyrynKFU9LrWFtna9cbwzCVAlTYtJh/wWXvnVx1Q/P/OphF+AMGFhX2Y/OF5Yy6CVhtLuKmf FngfXqBhgBzGduiAmTQxomtRMpUc0qh2047PHsaBqfJPMqnT1pat+RLJsF53fVwhLYVLwXAR/cx Gr50daXqKUOlnLms/Mwf25iYMJSsAdlG04A+d1S9qdq+lzJC26/kgSRPeE2IivZ2su+6U2znA/Z 8hFQpn5zIbDUg4QAU6oNEvbOaZBYnHE9o2jSsB38nO5xDqQLmeAWD9h8CPSsPwhYomuOv8l829c UZhlCto7rMaJrMBtrxE8LrDERJ97aeQRLkVtY66q5amHn5c6M= X-Received: by 2002:a17:90b:2c84:b0:36b:9798:4f6c with SMTP id 98e67ed59e1d1-37a0468a571mr789060a91.7.1781245451640; Thu, 11 Jun 2026 23:24:11 -0700 (PDT) Received: from localhost.localdomain ([106.195.67.13]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434ac9cd8dsm1064680b3a.1.2026.06.11.23.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2026 23:24:11 -0700 (PDT) From: Sailesh Nandanavanam To: sj@kernel.org Cc: shuah@kernel.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Sailesh Nandanavanam Subject: [PATCH v3] mm/damon: add KUnit test for walk_control_obsolete behavior Date: Fri, 12 Jun 2026 11:53:37 +0530 Message-Id: <20260612062337.2459-1-saileshnandanavanam@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260524100258.36819-1-saileshnandanavanam@gmail.com> References: <20260524100258.36819-1-saileshnandanavanam@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a KUnit test to verify that damos_walk() rejects new requests when walk_control_obsolete is set. Commit 33c3f6c2b48c ("mm/damon/core: fix damos_walk() vs kdamond_fn() exit race") introduced walk_control_obsolete to prevent a race condition where new requests could be registered during kdamond shutdown and never handled. This test simulates the shutdown condition by setting walk_control_obsolete and verifies that damos_walk() returns -ECANCELED immediately. This validates the invariant introduced by the fix and helps prevent regressions. Suggested-by: SeongJae Park Signed-off-by: Sailesh Nandanavanam --- Changes since v2 (https://lore.kernel.org/20260524100258.36819-1-saileshnandanavanam@gmail.com): - Dropped the userspace selftest approach entirely. SeongJae tested v2 100 times on a kernel with the fix reverted and it always passed, confirming the microsecond-wide race window cannot be reliably hit from userspace due to syscall overhead. - Added a KUnit test for damos_walk() + walk_control_obsolete instead, as suggested by SeongJae. This directly sets the obsolete flag and verifies damos_walk() returns -ECANCELED immediately, without timing dependency. Changes since v1 (https://lore.kernel.org/20260524091812.35283-1-saileshnandanavanam@gmail.com): - Addressed sashiko bot review comments (execute bit, threading, dynamic sysfs path, OSError handling) - superseded by the v3 approach above. mm/damon/tests/core-kunit.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 9e5904c2beeb..599aac056b73 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -1336,6 +1336,33 @@ static void damon_test_is_last_region(struct kunit *test) damon_free_target(t); } +/* + * Verify that damos_walk() rejects new requests when + * walk_control_obsolete is set. + * + * This tests the invariant introduced by: + * commit 33c3f6c2b48c ("mm/damon/core: fix damos_walk() vs kdamond_fn() exit race") + */ +static void damon_test_walk_control_obsolete(struct kunit *test) +{ + struct damon_ctx *ctx; + struct damos_walk_control control = {}; + int ret; + + ctx = damon_new_ctx(); + if (!ctx) + kunit_skip(test, "ctx alloc fail"); + + /* Simulate shutdown phase */ + ctx->walk_control_obsolete = true; + + ret = damos_walk(ctx, &control); + + KUNIT_EXPECT_EQ(test, ret, -ECANCELED); + + damon_destroy_ctx(ctx); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -1365,6 +1392,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_set_filters_default_reject), KUNIT_CASE(damon_test_apply_min_nr_regions), KUNIT_CASE(damon_test_is_last_region), + KUNIT_CASE(damon_test_walk_control_obsolete), {}, }; -- 2.34.1