The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 7b02ad32d83c16abd4961d79f3154b734d1d5d9c Gitweb: https://git.kernel.org/tip/7b02ad32d83c16abd4961d79f3154b734d1d5d9c Author: Max Ramanouski <max8rr8@xxxxxxxxx> AuthorDate: Thu, 15 Aug 2024 23:56:07 +03:00 Committer: Thomas Gleixner <tglx@xxxxxxxxxxxxx> CommitterDate: Fri, 16 Aug 2024 11:33:33 +02:00 x86/ioremap: Use is_ioremap_addr() in iounmap() Restrict iounmap() to memory allocated in the ioremap region, by using is_ioremap_addr(). Similarly to the generic iounmap() implementation. Additionally, add a warning in case there is an attempt to iounmap() invalid memory, instead of silently exiting, thus helping to avoid incorrect usage of iounmap(). Signed-off-by: Max Ramanouski <max8rr8@xxxxxxxxx> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx> Link: https://lore.kernel.org/all/20240815205606.16051-2-max8rr8@xxxxxxxxx --- 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 aa7d279..70b02fc 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; /*