linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] /dev/zero: make private mapping full anonymous mapping
@ 2025-01-13 22:30 Yang Shi
  2025-01-14 12:05 ` Lorenzo Stoakes
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Yang Shi @ 2025-01-13 22:30 UTC (permalink / raw)
  To: arnd, gregkh, Liam.Howlett, lorenzo.stoakes, vbabka, jannh,
	willy, liushixin2, akpm
  Cc: yang, linux-mm, linux-kernel

When creating private mapping for /dev/zero, the driver makes it an
anonymous mapping by calling set_vma_anonymous().  But it just sets
vm_ops to NULL, vm_file is still valid and vm_pgoff is also file offset.

This is a special case and the VMA doesn't look like either anonymous VMA
or file VMA.  It confused other kernel subsystem, for example, khugepaged [1].

It seems pointless to keep such special case.  Making private /dev/zero
mapping a full anonymous mapping doesn't change the semantic of
/dev/zero either.

The user visible effect is the mapping entry shown in /proc/<PID>/smaps
and /proc/<PID>/maps.

Before the change:
ffffb7190000-ffffb7590000 rw-p 00001000 00:06 8                          /dev/zero

After the change:
ffffb6130000-ffffb6530000 rw-p 00000000 00:00 0

[1]: https://lore.kernel.org/linux-mm/20250111034511.2223353-1-liushixin2@huawei.com/

Signed-off-by: Yang Shi <yang@os.amperecomputing.com>
---
 drivers/char/mem.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 169eed162a7f..dae113f7fc1b 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -527,6 +527,10 @@ static int mmap_zero(struct file *file, struct vm_area_struct *vma)
 	if (vma->vm_flags & VM_SHARED)
 		return shmem_zero_setup(vma);
 	vma_set_anonymous(vma);
+	fput(vma->vm_file);
+	vma->vm_file = NULL;
+	vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT;
+
 	return 0;
 }
 
-- 
2.47.0



^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2025-02-19  1:12 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-13 22:30 [PATCH] /dev/zero: make private mapping full anonymous mapping Yang Shi
2025-01-14 12:05 ` Lorenzo Stoakes
2025-01-14 16:53   ` Yang Shi
2025-01-14 18:14     ` Lorenzo Stoakes
2025-01-14 18:19       ` Lorenzo Stoakes
2025-01-14 18:21         ` Lorenzo Stoakes
2025-01-14 18:22         ` Matthew Wilcox
2025-01-14 18:26           ` Lorenzo Stoakes
2025-01-14 18:32       ` Jann Horn
2025-01-14 18:38         ` Lorenzo Stoakes
2025-01-14 19:03       ` Yang Shi
2025-01-14 19:13         ` Lorenzo Stoakes
2025-01-14 21:24           ` Yang Shi
2025-01-15 12:10             ` Lorenzo Stoakes
2025-01-15 21:29               ` Yang Shi
2025-01-15 22:05                 ` Christoph Lameter (Ampere)
2025-01-14 13:01 ` David Hildenbrand
2025-01-14 14:52   ` Lorenzo Stoakes
2025-01-14 15:06     ` David Hildenbrand
2025-01-14 17:01       ` Yang Shi
2025-01-14 17:23         ` David Hildenbrand
2025-01-14 17:38           ` Yang Shi
2025-01-14 17:46             ` David Hildenbrand
2025-01-14 18:05               ` Yang Shi
2025-01-14 17:02       ` David Hildenbrand
2025-01-14 17:20         ` Yang Shi
2025-01-14 17:24           ` David Hildenbrand
2025-01-28  3:14 ` kernel test robot
2025-01-31 18:38   ` Yang Shi
2025-02-06  8:02     ` Oliver Sang
2025-02-07 18:10       ` Yang Shi
2025-02-13  2:04         ` Oliver Sang
2025-02-14 22:53           ` Yang Shi
2025-02-18  6:30             ` Oliver Sang
2025-02-19  1:12               ` Yang Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox