From nobody Sun Dec 14 06:37:36 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 B9A821E5B95 for ; Wed, 10 Dec 2025 09:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765358054; cv=none; b=MQ2sS91t23SpVw3FvhiQPe80/AK/G7ngmSl1W+1e59GFPm56SeIiMx0KDcxC1E6e54ExXhP1Qb9ITp4XZP8q1TQo01+WosFoHpPygC6wIOvhZ7Inv+wNp82E1u/GvXc8yVpsXLwUfHnXE3K/RnwysabzT+57F+CHRP8KrpdFHDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765358054; c=relaxed/simple; bh=qA8etQBYMVx7IE9HjB0d2PDyzFeEHh6dA5fDZxxGkug=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=r/Lo737ZaqtQ9czFBHfRPyou5ma00CkOuM/Rp4xbA/CRtv1gF0d1shVJZbcwtkOujR53fclXtcI69nFhBrxuS8nry79zeuNjcsPYUo+slLnLcZBQDKa7DDnQ7GviDIOAGg3dvg5uu7R2d+5BGVfazVG4NRJTmwwb8Mu7uVzEGCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UllJiRjn; arc=none smtp.client-ip=209.85.214.202 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--wakel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UllJiRjn" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-297f587dc2eso88854565ad.2 for ; Wed, 10 Dec 2025 01:14:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765358052; x=1765962852; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=gJ+diNdvdoAjNwW4/UoG9jb3p4kgQF7Wid7xBQKDtGQ=; b=UllJiRjn/llHvkBJ7E+vHb/ubBJ4APyHD6L83HvpPROVNzvrrBaUGYK1uuCdXcDfs+ I0bJQCpKvqpaFlDssphPz4udOTiv5ZyGtRd8LqfKNT9dQdv6tAAPARHkaaTUYTQOXmoq A/oIpF6RIVz3G/uMeFkkqBSYl2DXa7Gho82/aHL34AI9tnej1UkJiHRJItk6PI5Q4dp0 sRLp7uiJGk87sPbH4vk1HffgZyvvZpyh8cApNQ6fV+MbCG1922mq1gv0vtiEG1l1YUKY Eag9uGW0LfiLSKCslKjl/QGzBKlMP/kvz4ZuEkhZl5iJLXth0kY+TfvTxklAR8vae7m/ 1Ufw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765358052; x=1765962852; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gJ+diNdvdoAjNwW4/UoG9jb3p4kgQF7Wid7xBQKDtGQ=; b=YM3z/cNcz0YUd9B8BGzbGAiq5tD83RmwkzncjB+UjIAgq99+CTHbBxrCd0njm+0wfA bUQsKOJS/roREBm2QKb7/O/1nC89/MOPF7lGNyhqp6X5H/aCJCkhvcx6n4QAsIciZF55 fZk6jm9FFusH14Ev9HJ9l371k3erTBu/qkzLSNWy5VTwI2ii/nMNwBMUR2ycN6ZewiOd cm7DM10vWjNRmZ0iktJgDB9zhMwjeNyiZ0SI/to2IBoYYyAG6RWFzTychvXfOTQ9tNoR hTPGVDE0YSrDwg5UUDj/70QV/RmW+Ph5Sm5Z29D10PuvxftdWVFoofWR7kxraRX2cot0 0Q/Q== X-Forwarded-Encrypted: i=1; AJvYcCVPyxNae8iDX9QJTiRnRYiRd5rl1ULDjfvhrE0cFk+M0mkdoGzV3cCgLLuwaVM+IL0Z+jJC3Fb/sTr05PU=@vger.kernel.org X-Gm-Message-State: AOJu0YzpwxVGdl1PnQWVLtLfCJ+FB7NQaXmTZkhcK+mmkyNW9kyjmm2s yO/y9LB/6O6NdNIJjMqe4kXQVFyLYeTJukApHt+n7+J48AhF+y/sJaB2aoz1Z23BfsIsJPYD+H2 rBQ== X-Google-Smtp-Source: AGHT+IEu6z3l2QX6KuLU3Q6OFfDJ0FX6A27zVmwG9FygHINtFnYd4ff1NV1/k8xr34jkmCShD9fTkvGN/A== X-Received: from plij11.prod.google.com ([2002:a17:903:380b:b0:290:28e2:ce65]) (user=wakel job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d482:b0:295:4d97:84fc with SMTP id d9443c01a7336-29ec2484bcemr16730975ad.32.1765358052034; Wed, 10 Dec 2025 01:14:12 -0800 (PST) Date: Wed, 10 Dec 2025 17:14:08 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251210091408.3781445-1-wakel@google.com> Subject: [PATCH] selftests/mm: Fix thread state check in uffd-unit-tests From: Wake Liu To: Andrew Morton , David Hildenbrand , Shuah Khan , Nathan Chancellor Cc: Peter Xu , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Wake Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the thread_state_get() function, the logic to find the thread's state character was using `sizeof(header) - 1` to calculate the offset from the "State:\t" string. The `header` variable is a `const char *` pointer. `sizeof()` on a pointer returns the size of the pointer itself, not the length of the string literal it points to. This makes the code's behavior dependent on the architecture's pointer size. This bug was identified on a 32-bit ARM build (`gsi_tv_arm`) for Android, running on an ARMv8-based device, compiled with Clang 19.0.1. On this 32-bit architecture, `sizeof(char *)` is 4. The expression `sizeof(header) - 1` resulted in an incorrect offset of 3, causing the test to read the wrong character from `/proc/[tid]/status` and fail. On 64-bit architectures, `sizeof(char *)` is 8, so the expression coincidentally evaluates to 7, which matches the length of "State:\t". This is why the bug likely remained hidden on 64-bit builds. To fix this and make the code portable and correct across all architectures, this patch replaces `sizeof(header) - 1` with `strlen(header)`. The `strlen()` function correctly calculates the string's length, ensuring the correct offset is always used. Signed-off-by: Wake Liu Acked-by: Peter Xu --- tools/testing/selftests/mm/uffd-unit-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/s= elftests/mm/uffd-unit-tests.c index f4807242c5b2..6f5e404a446c 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -1317,7 +1317,7 @@ static thread_state thread_state_get(pid_t tid) p =3D strstr(tmp, header); if (p) { /* For example, "State:\tD (disk sleep)" */ - c =3D *(p + sizeof(header) - 1); + c =3D *(p + strlen(header)); return c =3D=3D 'D' ? THR_STATE_UNINTERRUPTIBLE : THR_STATE_UNKNOWN; } --=20 2.52.0.223.gf5cc29aaa4-goog