All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kunwu Chan <kunwu.chan@linux.dev>
To: sj@kernel.org, shuah@kernel.org
Cc: damon@lists.linux.dev, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Kunwu Chan <chentao@kylinos.cn>, Wang Lian <lianux.mm@gmail.com>
Subject: [PATCH v2 1/3] selftests/damon: prevent cross-context state pollution in DamonCtx
Date: Mon,  1 Jun 2026 11:23:12 +0800	[thread overview]
Message-ID: <20260601032314.424013-2-kunwu.chan@linux.dev> (raw)
In-Reply-To: <20260601032314.424013-1-kunwu.chan@linux.dev>

From: Kunwu Chan <chentao@kylinos.cn>

DamonCtx.__init__() uses mutable default values for
monitoring_attrs, targets, and schemes.  In Python these are
evaluated once at function definition time, so multiple
DamonCtx instances can unintentionally share the same lists
and DamonAttrs instance.

Replace the mutable defaults with None sentinels and
initialize the objects when needed.

Co-developed-by: Wang Lian <lianux.mm@gmail.com>
Signed-off-by: Wang Lian <lianux.mm@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: SeongJae Park <sj@kernel.org>
---
 tools/testing/selftests/damon/_damon_sysfs.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/damon/_damon_sysfs.py b/tools/testing/selftests/damon/_damon_sysfs.py
index 8b12cc048440..2f6f2699db25 100644
--- a/tools/testing/selftests/damon/_damon_sysfs.py
+++ b/tools/testing/selftests/damon/_damon_sysfs.py
@@ -624,17 +624,23 @@ class DamonCtx:
     pause = None
     idx = None
 
-    def __init__(self, ops='paddr', monitoring_attrs=DamonAttrs(), targets=[],
-            schemes=[], pause=False):
+    def __init__(self, ops='paddr', monitoring_attrs=None, targets=None,
+            schemes=None, pause=False):
         self.ops = ops
+        if monitoring_attrs is None:
+            monitoring_attrs = DamonAttrs()
         self.monitoring_attrs = monitoring_attrs
         self.monitoring_attrs.context = self
 
+        if targets is None:
+            targets = []
         self.targets = targets
         for idx, target in enumerate(self.targets):
             target.idx = idx
             target.context = self
 
+        if schemes is None:
+            schemes = []
         self.schemes = schemes
         for idx, scheme in enumerate(self.schemes):
             scheme.idx = idx
-- 
2.43.0



  reply	other threads:[~2026-06-01  3:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01  3:23 [PATCH v2 0/3] selftests/damon: misc fixes for test bugs Kunwu Chan
2026-06-01  3:23 ` Kunwu Chan [this message]
2026-06-01  3:23 ` [PATCH v2 2/3] selftests/damon/damos_tried_regions: fix expectation output and join TypeError Kunwu Chan
2026-06-01  3:23 ` [PATCH v2 3/3] selftests/damon: fix dead code, skipped checks, and broken lookups Kunwu Chan
2026-06-01 14:22 ` [PATCH v2 0/3] selftests/damon: misc fixes for test bugs SeongJae Park
2026-06-03  2:11   ` Kunwu Chan
2026-06-03  5:02     ` SeongJae Park
2026-06-03  9:15       ` Kunwu Chan
2026-06-01 14:28 ` SeongJae Park
2026-06-03  2:06   ` Kunwu Chan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260601032314.424013-2-kunwu.chan@linux.dev \
    --to=kunwu.chan@linux.dev \
    --cc=chentao@kylinos.cn \
    --cc=damon@lists.linux.dev \
    --cc=lianux.mm@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shuah@kernel.org \
    --cc=sj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.