linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/ioremap: Use is_ioremap_addr() in iounmap()
@ 2024-08-12 20:35 Max Ramanouski
  2024-08-12 21:13 ` Thomas Gleixner
  2024-08-14  4:28 ` Christoph Hellwig
  0 siblings, 2 replies; 9+ messages in thread
From: Max Ramanouski @ 2024-08-12 20:35 UTC (permalink / raw)
  To: x86, dave.hansen, luto, peterz, linux-kernel, jniethe, jhubbard,
	linux-mm, tglx
  Cc: Max Ramanouski

On systems that use HMM (most notably amdgpu driver) high_memory
can jump over VMALLOC_START due to pages at the end of physical
space being added with add_pages(), while gap for new pages left
by KASLR is as small as 10TB. This results in early exit from
iounmap() leading to leaking, and additional problems with rebinding
devices to vfio_pci from other drivers with error of conflicting
memtypes, as memtypes aren't freed in iounmap().

Replace comparison against high_memory with is_ioremap_addr() to
fix the issue and make x86 iounmap() implementation more similar
to generic one, it also uses is_ioremap_addr() to validate pointer.

Fixes: 41e94a851304 ("add devm_memremap_pages")
Signed-off-by: Max Ramanouski <max8rr8@gmail.com>
---
 arch/x86/mm/ioremap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index aa7d27932..464344da4 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/ioport.h>
+#include <linux/ioremap.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/mmiotrace.h>
@@ -457,7 +458,7 @@ void iounmap(volatile void __iomem *addr)
 {
 	struct vm_struct *p, *o;
 
-	if ((void __force *)addr <= high_memory)
+	if (!is_ioremap_addr(addr))
 		return;
 
 	/*
-- 
2.45.2



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

end of thread, other threads:[~2024-08-15 13:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-12 20:35 [PATCH v2] x86/ioremap: Use is_ioremap_addr() in iounmap() Max Ramanouski
2024-08-12 21:13 ` Thomas Gleixner
2024-08-14  4:28 ` Christoph Hellwig
2024-08-14 10:30   ` Thomas Gleixner
2024-08-14 12:08     ` Alistair Popple
2024-08-14 12:16       ` Christoph Hellwig
2024-08-14 14:11         ` Thomas Gleixner
2024-08-15  5:02           ` Christoph Hellwig
2024-08-15 13:41           ` Thomas Gleixner

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