All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nikolai Dokutovich" <ndokutovich@gmail.com>,
	"David Hildenbrand" <david@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Shuah Khan" <shuah@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>, "Xu Xin" <xu.xin@linux.dev>,
	linux-mm@kvack.org
Subject: Re: [PATCH v4 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem
Date: Wed, 02 Dec 2026 16:28:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-246208@kernel.org> (raw)
In-Reply-To: <20261201162600.42818-2-ndokutovich@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/mm: unaddressed v3 feedback in
  proc_mem_force_write_allowed()
--

commit 08995802b6cf0750e79384ecbd8c2d42d5886d8d
Author: Nikolai Dokutovich <ndokutovich@gmail.com>

selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem

This commit adds a proc_mem_force_write_allowed() helper to vm_util to
probe and cache whether forced writes to read-only mappings through
/proc/self/mem are permitted by the running kernel.

> diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
> index b5485326fa0bc..2df6d92e5afd6 100644
> --- a/tools/testing/selftests/mm/vm_util.c
> +++ b/tools/testing/selftests/mm/vm_util.c
> @@ -1176,3 +1176,50 @@ void shm_limits_prepare(unsigned long length)
>  		shmall = val;
>  	}
>  }
> +
> +bool proc_mem_force_write_allowed(void)
> +{
> +	static int allowed = -1;
> +	const size_t pagesize = getpagesize();
> +	ssize_t ret;
> +	char data = 1;
> +	char *mem;
> +	int fd;
> +
> +	if (allowed >= 0)
> +		return allowed;
> +
> +	mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +	if (mem == MAP_FAILED)
> +		return true;
> +
> +	fd = open("/proc/self/mem", O_RDWR);
> +	if (fd < 0) {
> +		munmap(mem, pagesize);
> +		return true;
> +	}
> +
> +	if (lseek(fd, (off_t)(uintptr_t)mem, SEEK_SET) == (off_t)-1) {
> +		close(fd);
> +		munmap(mem, pagesize);
> +		return true;
> +	}
> +
> +	ret = write(fd, &data, 1);
> +	if (ret < 0)
> +		ret = -errno;
> +	close(fd);
> +	munmap(mem, pagesize);
> +
> +	/*
> +	 * A refused forced write transfers zero bytes and mem_rw() reports
> +	 * that as -EIO, but any other zero-byte remote access reports the
> +	 * same.  Cache only the two decisive results and leave anything else
> +	 * to the test.
> +	 */
> +	if (ret != 1 && ret != -EIO)
> +		return true;
> +
> +	allowed = (ret == 1);
> +	return allowed;
> +}
> diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
> index 6fd92a3ee6996..2898cd8877cec 100644
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -81,6 +81,23 @@ static inline void force_read_pages(char *addr, unsigned int nr_pages,
>  
>  bool detect_huge_zeropage(void);
>  
> +/*
> + * Whether a write through /proc/self/mem into a mapping that is not
> + * writable is permitted.  The kernel performs such a write as a forced
> + * (FOLL_FORCE) write.  The answer depends on the kernel configuration,
> + * the boot parameters and whether the writing task traces the target,
> + * not on the mapping, so a decisive result is cached after one probe.
> + * This holds for the self probe only: another target or a policy that
> + * could change during the run would not be safe to cache.
> + *
> + * A successful write returns true; -EIO returns false, although -EIO can
> + * also mean another zero-byte remote access and so indicates a refusal
> + * without proving one.  Any other result is inconclusive: the probe
> + * returns true and caches nothing, so the test runs and reports its own
> + * failure instead of skipping.
> + */
> +bool proc_mem_force_write_allowed(void);

[Severity: Low]
As reported by David Hildenbrand (Arm) on v3 [1], why does
proc_mem_force_write_allowed() need special handling to distinguish -EIO
from other write() failures on a freshly mapped read-only anonymous page,
and could this two-paragraph comment in vm_util.h be reduced to a brief
summary?

[1] https://lore.kernel.org/r/b9714a42-e690-440b-8eba-474c6b8dcfbf@kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201162600.42818-1-ndokutovich@gmail.com?part=1


  reply	other threads:[~2026-12-02 16:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:25 [PATCH v4 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied Nikolai Dokutovich
2026-12-01 16:25 ` [PATCH v4 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Nikolai Dokutovich
2026-12-02 16:28   ` sashiko-bot [this message]
2026-12-01 16:25 ` [PATCH v4 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
2026-12-01 16:27 ` [PATCH v4 0/3] selftests/mm: skip tests when FOLL_FORCE writes are denied David Hildenbrand (Arm)
2026-12-01 16:32   ` Nikolai Dokutovich
2026-12-01 16:28 ` [PATCH v4 3/3] selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE Nikolai Dokutovich

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=sashiko-outbox-246208@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=ndokutovich@gmail.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=xu.xin@linux.dev \
    /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.