From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060395; b=XmdujTjr4Zs3GWV6DgyYJlLQrqFgRiSlVcpXjvS33eFZKgfcGkBs5RJe0P/fFy7r4+wH 9yRi5tSuXHf1MWukE6RWXC4d1re+TwgiCCQoxC6tkLAFUIlX2OVg0Q/3HsWptTIgPoG+u OEpni5glNxCf2LwuaAT7wgsnh63/G5MRfN+C3w+WhVS8IvkrE1EFO+OwbakTIYNsRmmBt kOHl2EgUrbcRO/H0oy/rsJbNxx535meKuftQZZuAcTD+o5gpfx8Eiium61j5r5Sw4Hr91 7lAVWNQVnGqFYoY2NMGq1jsN/lSgh5zCI+nTPhRY7ZfksSi+Sc52nAT4j4DNQvVWhhw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060395; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=SgjJbukO5SC45lK/7bOZ744kABfBQfKwM+Z5n5QBb8k=; b=SshbyoLinZgXgggGzimkM+m/YOFqUfaXEKt6fDjIipqixgjebRcMEDbtuWbkiYqKopQU sKdv0OkXuSwutjtcG1REnA8FImlG57IcKPNZGklqo/dCnNKdMOIkqzmYW2iVPKA00JH8W AlvS7yvPlsAniwm8ZjNUad/z4iGBdO0ERRzQhPoG5RBhh1E1rSITvedpffA+e0OaQsHod C5g+0+uVKORbvz68lPGQjCd/9POTPsNVqNIaKQaQpVB/yd27+VVKDi3/YqixRq4pBLReN rP1W53Jjr0AH6wgNhpilnpOU31Hr/h6x3qKwFq2KtfJx+o4z4CZd+bkw8IfnDSOIsxA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UXxXJNdO; arc=none smtp.remote-ip=209.85.222.181 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 100D4606A31C for ; Mon, 30 Nov 2026 17:39:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 100D4606A31C 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.a=rsa-sha256 header.s=20260707 header.b=UXxXJNdO Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-949664ee41cso1115281085a.3 for ; Mon, 30 Nov 2026 09:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796060394; x=1796665194; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=SgjJbukO5SC45lK/7bOZ744kABfBQfKwM+Z5n5QBb8k=; b=UXxXJNdOB/JFRXM3cVl2C8O3M9iCpUO0dhY7DRh9FGOuQBL7KfZdYXXwOOb84m4/Y0 wcuJfcno1FvS28vZnXnnvxJGWURHpDwKp96lyi6x8CGnjZPtytlXOZtFQI0Mz3D8NVs/ YeoQ36vtfSRFqSVo/826DSzBXvrztgx1JdzFf1DfpyVHZt+4wTtcXA826GnsKUG2PM5e iwycpK+egvIFr0l0LYv0YjJ93LgMCI2Q6XC+kLKdRJlfX8qZIsmV9RER/wd17nPe24Hw aIdeDriH64tcWA0VPxC5vAClDEAIJBHSQvjA7NzrMSg69tG93+wyGt7nVhOCWqwaaB2X VG4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796060394; x=1796665194; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SgjJbukO5SC45lK/7bOZ744kABfBQfKwM+Z5n5QBb8k=; b=lQaId2Q80Cqnfbw/m7H9DGIn3CDRWG8lfSI/5KZfHWhy1Tfv6zY56fPv/sgvnLEa2r Cu1ihOHoyKCiJMpph/DI2CZOFAmYlwCgpbVq87O4BsaQA0tY78C9Kqjk+RDos1itdvYE GCwHpz6lfD9bk/BDHUjmHuLKwK2O2fWc92/u54wl5fxR8S8vnaScJlR5HKK0ktEyI034 ew9Nz0RrJyMkwzvYkub0og8jEzLYzLw8jZRcD4rn7QcP6/bRGdL8mRF2gTI3b2EzYys/ svsIWJ4N/F9HY1ZQWyHAAu1MLHnQkQanx9Iddad08r5s+xUKq+CGeb8DOOpXJwK5p/X/ WUDQ== X-Forwarded-Encrypted: i=1; AL+hErERqJvR0ns3RXVydJP5gu35wWM/joMh5J6nHPrbuZQdbn/CUmAR0D4JOZAvarfX0Ycf/aVkYyetCQSaqo8=@vger.kernel.org X-Gm-Message-State: APuU4Z9Npi36PjN2Ukw82zfg0PLAQoEvTKfi1aRbOH3+1uJpsUfMxEjX nCwPoD1tw5HT0yl2hKEYMsouqzYDcOAGFOGEzRc5W0Dd3cuy/LlVP38d X-Gm-Gg: AZFdTZdB/gqFzpdxq2BdU8zUhvwTD+tK4Qi21W3RivND0XpM3BkrTBn+KExIirxhYWl r9/t80LFSvj/8Ll0ywpPtf9rjCZUWiOoie7H3MruLukKdhy1V3TWhM+FNaj6jYT4deY0UHbZHPP GuNLHlBpeqvYZYDyYBNAehqn8IR5HbunffqBtENiGGM0vrN/F4cdqHqR/ai9Be5/5d045YXfddI W2HC1aO7EJscJAok+etpKd4fZGo/ol1MZ8tn4hcgqKuWUi7DD5JmLSIUHmwGZOYTSnEMTuWM4kE /J5Zh/9KFW6PXIqoFT2MRIvLuaPCaqWUubt3v53+1gCq0e2F+LEpoE6RdhpYKZXVIoEQTf9QWif V5WnoZDIDmaNq6NXfd//dcn8XrxDWq91w7h4TVoRiHL4hlfczSqdK3KgV4yvAY0nOpYBErGN/A9 UyqxqNwRBo1W+cpLpGirzeTNDehKTRu/BpUj6SwmKZdbJIKqr72KaG/0NMaSzoxpFG+314RD+Lj SKYCldbzcOelaAyA1eT9krx/cvEKXvYYi0k8XCxjHH4JDkMd1MUw35Fj8mNsOBmTVHktQnG6EiB 0rbnPhNV9hsSm7K8IxfCzsR8IH3hmvwAhzTxtFOtB3xuv/JJcx9L4lWS6HetC0kH8PgYj2q94yj SoNN4 X-Received: by 2002:a05:620a:7113:b0:949:569a:a3fa with SMTP id af79cd13be357-949ba9b82f4mr6063046385a.25.1796060393850; Mon, 30 Nov 2026 09:39:53 -0800 (PST) Received: from localhost ([138.197.109.108]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949c555faf9sm2495962785a.0.2026.11.30.09.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 09:39:53 -0800 (PST) From: Nikolai Dokutovich To: David Hildenbrand , Andrew Morton Cc: Shuah Khan , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Nikolai Dokutovich Subject: [PATCH v3 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied Date: Mon, 30 Nov 2026 20:39:47 +0300 Message-ID: <20261130173950.41003-1-ndokutovich@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A write through /proc/self/mem into a mapping that is not writable is performed by the kernel as a forced write. Since commit 41e8149c8892 ("proc: add config & param to block forcing mem writes") such a write is refused unless the writing task is tracing the target task, the kernel was built with CONFIG_PROC_MEM_ALWAYS_FORCE, or it was booted with proc_mem.force_override=always. Commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE the Kconfig default") made the refusal the default. Commit a3907a3169d0 ("selftests/mm: specify requirement for PROC_MEM_ALWAYS_FORCE=y") set CONFIG_PROC_MEM_ALWAYS_FORCE=y in mm/config. That fragment is merged into the kernel configuration only when it is requested, so a test binary run against a distribution kernel is not covered, and mkdirty and the ksm PROT_NONE test then report failures instead of skipping: not ok 1 write() failed not ok 5 ptrace write failed The first patch adds a probe to vm_util that reports whether such a write is permitted. The permission belongs to the kernel and the calling task, not to the mapping, so the probe takes no protection argument: it maps one read-only page and writes a byte through /proc/self/mem. A refused forced write copies zero bytes and mem_rw() reports that as -EIO, but any other zero-byte remote access reports the same, so -EIO can indicate a refusal without proving one. Only the two decisive results are cached; anything else is inconclusive, returns allowed and is not cached, so the test below still runs and can fail. This is deliberately not a check of errno on the tests' own write: that was raised in the April discussion of the mm/config fix, and checking the result of the operation under test cannot tell a policy refusal from a failure of the operation itself. The probe isolates the question, and the test then either runs unchanged or is skipped at its entry. Tested with this series on x86_64 against a kernel built from this base whose .config has CONFIG_PROC_MEM_FORCE_PTRACE=y, CONFIG_CHECKPOINT_RESTORE=n, CONFIG_USERFAULTFD=n, CONFIG_KSM=y: default boot mkdirty pass:3 skip:3 (2 probe skips, 1 no uffd) ksm_functional_tests pass:8 skip:2 (test_prot_none, 1 no uffd) boot with proc_mem.force_override=always mkdirty pass:5 skip:1 (no uffd) ksm_functional_tests pass:9 skip:1 (no uffd) When the probe causes a skip, it is reported as "FOLL_FORCE write probe returned EIO", and no other test changes its result. Changes in v3: - Reduce the probe to bool proc_mem_force_write_allowed(void), taking no protection argument and caching the answer internally, as David Hildenbrand asked. - Call it at the entry of each affected test instead of caching the result in mkdirty's main(). Nikolai Dokutovich (3): selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE .../selftests/mm/ksm_functional_tests.c | 5 ++ tools/testing/selftests/mm/mkdirty.c | 10 ++++ tools/testing/selftests/mm/vm_util.c | 47 +++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 17 +++++++ 4 files changed, 79 insertions(+) -- 2.43.0