All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] x86/devmem: move range_is_allowed() to drivers/char/mem.c
@ 2025-05-20 15:20 Arnd Bergmann
  2025-05-20 15:20 ` [PATCH 2/3] x86/devmem: remove phys_mem_access_prot_allowed() Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Arnd Bergmann @ 2025-05-20 15:20 UTC (permalink / raw)
  To: Dave Hansen, Dan Williams
  Cc: Andy Lutomirski, Peter Zijlstra, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, x86, Greg Kroah-Hartman, Nikolay Borisov,
	linux-kernel, Arnd Bergmann

From: Arnd Bergmann <arnd@arndb.de>

The global inline function in include/linux/io.h causes problems
because of the unfortunate naming that is too generic, and because
it reintroduces a dependency on the PAGE_SIZE definition that should
not exist in this header file.

Something I had not seen during the earlier review is how the
x86 phys_mem_access_prot_allowed() is called directly after the
generic check for range_is_allowed(), so checking it again actually
has no effect at all, and the definition can be made local to
drivers/char/mem.c with no other caller.

Fixes: 1b3f2bd04d90 ("x86/devmem: Remove duplicate range_is_allowed() definition")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/x86/mm/pat/memtype.c |  3 ---
 drivers/char/mem.c        | 18 ++++++++++++++++++
 include/linux/io.h        | 21 ---------------------
 3 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c
index 2e7923844afe..fe24b8d2dc4b 100644
--- a/arch/x86/mm/pat/memtype.c
+++ b/arch/x86/mm/pat/memtype.c
@@ -789,9 +789,6 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
 	if (!pat_enabled())
 		return 1;
 
-	if (!range_is_allowed(pfn, size))
-		return 0;
-
 	if (file->f_flags & O_DSYNC)
 		pcm = _PAGE_CACHE_MODE_UC_MINUS;
 
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 2a483369e255..85f963ce3b2d 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -347,6 +347,24 @@ static const struct vm_operations_struct mmap_mem_ops = {
 #endif
 };
 
+static int range_is_allowed(unsigned long pfn, unsigned long size)
+{
+	u64 from = ((u64)pfn) << PAGE_SHIFT;
+	u64 to = from + size;
+	u64 cursor = from;
+
+	if (!IS_ENABLED(CONFIG_STRICT_DEVMEM))
+		return 1;
+
+	while (cursor < to) {
+		if (!devmem_is_allowed(pfn))
+			return 0;
+		cursor += PAGE_SIZE;
+		pfn++;
+	}
+	return 1;
+}
+
 static int mmap_mem(struct file *file, struct vm_area_struct *vma)
 {
 	size_t size = vma->vm_end - vma->vm_start;
diff --git a/include/linux/io.h b/include/linux/io.h
index 28a238217aa6..8c0a8e8b6066 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -164,25 +164,4 @@ static inline void arch_io_free_memtype_wc(resource_size_t base,
 int devm_arch_io_reserve_memtype_wc(struct device *dev, resource_size_t start,
 				    resource_size_t size);
 
-#ifdef CONFIG_STRICT_DEVMEM
-static inline int range_is_allowed(unsigned long pfn, unsigned long size)
-{
-	u64 from = ((u64)pfn) << PAGE_SHIFT;
-	u64 to = from + size;
-	u64 cursor = from;
-
-	while (cursor < to) {
-		if (!devmem_is_allowed(pfn))
-			return 0;
-		cursor += PAGE_SIZE;
-		pfn++;
-	}
-	return 1;
-}
-#else
-static inline int range_is_allowed(unsigned long pfn, unsigned long size)
-{
-	return 1;
-}
-#endif
 #endif /* _LINUX_IO_H */
-- 
2.39.5


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

end of thread, other threads:[~2025-06-11 14:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-20 15:20 [PATCH 1/3] x86/devmem: move range_is_allowed() to drivers/char/mem.c Arnd Bergmann
2025-05-20 15:20 ` [PATCH 2/3] x86/devmem: remove phys_mem_access_prot_allowed() Arnd Bergmann
2025-05-21 22:08   ` Dan Williams
2025-05-20 15:20 ` [PATCH 3/3] [RFC] x86/devmem: remove low 1MB hack for x86-64 Arnd Bergmann
2025-05-21 22:14   ` Dan Williams
2025-05-22 12:24     ` Arnd Bergmann
2025-06-03 18:18       ` Dan Williams
2025-06-03 19:25         ` Arnd Bergmann
2025-06-03 19:36           ` Dan Williams
2025-06-11 14:18             ` Naveen N Rao
2025-05-21 22:05 ` [PATCH 1/3] x86/devmem: move range_is_allowed() to drivers/char/mem.c Dan Williams

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.