linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] x86/ioremap: Use is_ioremap_addr() in iounmap()
@ 2024-08-15 20:56 Max Ramanouski
  2024-08-15 22:55 ` Alistair Popple
  0 siblings, 1 reply; 2+ messages in thread
From: Max Ramanouski @ 2024-08-15 20:56 UTC (permalink / raw)
  To: x86, dave.hansen, luto, peterz, linux-kernel, jniethe, jhubbard,
	linux-mm, tglx, hch, apopple
  Cc: Max Ramanouski, Christoph Hellwig

Restrict iounmap() to memory allocated in ioremap region, by using
is_ioremap_addr(). Similarly to the generic iounmap() implementation.

Additionally, add warning in case there is an attempt to iounmap()
invalid memory, instead of silently exiting, thus helping to
avoid incorrect usage of iounmap().

Reviewed-by: Christoph Hellwig <hch@lst.de>
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 aa7d279321ea..70b02fc61d93 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 (WARN_ON_ONCE(!is_ioremap_addr((void __force *)addr)))
 		return;
 
 	/*
-- 
2.45.2



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

* Re: [PATCH v3] x86/ioremap: Use is_ioremap_addr() in iounmap()
  2024-08-15 20:56 [PATCH v3] x86/ioremap: Use is_ioremap_addr() in iounmap() Max Ramanouski
@ 2024-08-15 22:55 ` Alistair Popple
  0 siblings, 0 replies; 2+ messages in thread
From: Alistair Popple @ 2024-08-15 22:55 UTC (permalink / raw)
  To: Max Ramanouski
  Cc: x86, dave.hansen, luto, peterz, linux-kernel, jniethe, jhubbard,
	linux-mm, tglx, hch, Christoph Hellwig


Max Ramanouski <max8rr8@gmail.com> writes:

> Restrict iounmap() to memory allocated in ioremap region, by using
> is_ioremap_addr(). Similarly to the generic iounmap() implementation.
>
> Additionally, add warning in case there is an attempt to iounmap()
> invalid memory, instead of silently exiting, thus helping to
> avoid incorrect usage of iounmap().

Looks good, thanks. Feel free to add:

Reviewed-by: Alistair Popple <apopple@nvidia.com>

> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 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 aa7d279321ea..70b02fc61d93 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 (WARN_ON_ONCE(!is_ioremap_addr((void __force *)addr)))
>  		return;
>  
>  	/*



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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-15 20:56 [PATCH v3] x86/ioremap: Use is_ioremap_addr() in iounmap() Max Ramanouski
2024-08-15 22:55 ` Alistair Popple

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