From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060396; b=G7qSP5BbRpzfyhdkg99Th4pEyC6owqyk2u9ncCrh9duowScBtNw0z1gYclH6NqfHcwBV pi7AmVr+WmEFcHTAOD1lJxw1wlXgksMH74wzgfeNbRkgZx/E43fymKflYONx055LwlFeD H5fd2U0NYEXJsKz270LqVwgxepQq9BEJqtyHprn2Cp+rt5z+9Mbm6yjeI3ruWrmT8XTZ6 L0fOwZqUS2RNArDjHUTlqLPF1tp9T3r+YwTpyA/tMFdVcioyig9R7Uwq6gTXbgX1stXtR F/BHrvDWIOJXZ26PWiN+mbxHmSOwFe3A9RtECFSQqjl8gztxsHFH65Pwhatvsy7E12Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060396; 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=KnbixebBU0x8MD3aq2FV6qgp1x6Z6KHDTOET+k39JX8P0XOjnIpJpbwJ+CDJsR1CVwyZ /xFTOuA2tAMvJzTrTXAJjpFG/z6FqnRcDCVmN9TPrbDg17RRsx3GuMYZeiHRkm4RMxAf6 09sxe8lLGIeuAE28HM9wPp/+6S9nvqNbVEvPKnvi4R5N43jZIlWpuGR/ZqnpthGV7+3aW 25eoc5XWT0FG/X+kqEPfO6SulrC0nV1FPtS1k3MituMKnoUstz8419OytA1Px4ixvqJZ2 gfAnvsKc1Jczl59P3KmNAU/I/6KAGuMoPOaIcmtOl1MAKxjpfOQYXhgapHxPtVNAe4w== 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.173 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 17182606A320 for ; Mon, 30 Nov 2026 17:39:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 17182606A320 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-f173.google.com with SMTP id af79cd13be357-93f20c3aaa5so886295085a.2 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=jGxrudQT/ew7XeO1J1iiGyzsVaRQ7SBOnGDCDI6ySKneZMwqx6x+PudOXlZZUGuLY/ mF8b4Qt58bCwXX8iDdhcmwXK2g4Z4M26A1TK6IP5XyxfItPYWdJD/uzW+UeeqmENmyZx cGyh4Cjh0wjqPtm5j8JgJpK6G65kXf9pIfOBYEr6vn2JQVjHAq4ni3t7mwpivVJKJ4q5 EExqqIihcXmRhmgqdRvCWuVwaAs6o+3+N1K00AfCrrLfkopHHtDFFybJ6a0uf6G+EbX4 p3xwNhKy5VqV53fGnlNbNf3uD67GSvu0HcH+16ONCWbYwk625u7NMFDhZo+gBe2dETdT lwFg== X-Forwarded-Encrypted: i=1; AL+hErHVD31VouOKxGmnF7H8EQ94o7Id0SzvxiSJe6+BqU/9LRnqci+7V0XOnQ+DqyQ1j5iqCIC7W7DBuRcmjJrMSGk=@vger.kernel.org X-Gm-Message-State: APuU4Z+WfCk4Sn3XGXlN9hhB6PcE8d6j6NWDXlgvG5oTTCIh8fCduoPC /GyzjMLsD9D8WMLvOfQyLqzl1jcQ8DP58xkHdWsj7qMm7ici6APOIS3QOSOSKftCpPKT/Q== X-Gm-Gg: AZFdTZfi1itLyyOcixgfWgCabNS7L+lNMgHHEMGhn/og7DDaz07WIU39jFzfV2XNHAV WiN2nYn9MfKVm96vHYjJvkwHmiWbZDbtFk+wP0npOr4cosyKxLkWYcEc8ftf15gEIJI9m38YZOk 1uC/eADChJxbF0JoEAgsb1tdN01DDHDv5C1RW8HUiXUWh/n8hwqG14m9gh/nE+Lnv5siOPPjDfQ JkoKmZ3Yiv6CbhrPy1wfkEB1xvVi9NMLJelQrLyvC66JdxnyQ4dRmbwGthWaNfcRucmgSOkWFR2 2nKJVPF4o4DMtAh7uokxPRd053gHMWxbRDW0xye1HNDAwTas8x1doKXA4p4ZlKGcu1LRd5/0qMS Kmcm+TNQ9pkgSRHAnb22TX0oKjnMnMQ/F83fMikYgX85vO4V1/Oj6rp5a7zEwuEoOskCPuwOmZm XimJZkiCZY/P5SnskqxcYmf9QbJ+KHIUtlLWFRHWiCdTvp6EYDY8j3YnGl9Nxcp5wAqnIxqvxoi bQJXKMAnRCI5A5txqupdIfHmYcD53MpgYYkESjorCJqAt8ADFWRyJGM+MzYOTNvoa1+peDTVy7Q 3Hb5gnDWRxkmm4tt3OaMkjYc6HOP1+6BlUEN9MRHIVbjam2I/I8Lze1YwewlrV7/3TG8Y4bIYQ3 kGCmv 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-kselftest@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