git: 147ea7d4092f - stable/14 - linuxkpi: Fix set_memory_*

From: Tijl Coosemans <tijl_at_FreeBSD.org>
Date: Sat, 11 May 2024 15:38:32 UTC
The branch stable/14 has been updated by tijl:

URL: https://cgit.FreeBSD.org/src/commit/?id=147ea7d4092f4b08411724bd501283a281ffa34e

commit 147ea7d4092f4b08411724bd501283a281ffa34e
Author:     Tijl Coosemans <tijl@FreeBSD.org>
AuthorDate: 2024-05-03 13:27:29 +0000
Commit:     Tijl Coosemans <tijl@FreeBSD.org>
CommitDate: 2024-05-11 15:32:35 +0000

    linuxkpi: Fix set_memory_*
    
    set_memory_* is currently implemented using PHYS_TO_DMAP but not all
    architectures have a DMAP.  Looking at how this function is used the
    given address isn't physical but virtual so the PHYS_TO_DMAP call can
    simply be removed.
    
    Also cast numpages before shifting it to avoid overflow.
    
    Reviewed by:    kib, markj
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D45057
    
    (cherry picked from commit 7206f7c619912bdd4d54dd539824733eae50c3a9)
---
 sys/compat/linuxkpi/common/include/asm/set_memory.h | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/asm/set_memory.h b/sys/compat/linuxkpi/common/include/asm/set_memory.h
index 69f659001c60..1019aaf264a0 100644
--- a/sys/compat/linuxkpi/common/include/asm/set_memory.h
+++ b/sys/compat/linuxkpi/common/include/asm/set_memory.h
@@ -34,26 +34,20 @@
 static inline int
 set_memory_uc(unsigned long addr, int numpages)
 {
-	vm_offset_t va;
 	vm_size_t len;
 
-	va = PHYS_TO_DMAP(addr);
-	len = numpages << PAGE_SHIFT;
-
-	return (-pmap_change_attr(va, len, VM_MEMATTR_UNCACHEABLE));
+	len = (vm_size_t)numpages << PAGE_SHIFT;
+	return (-pmap_change_attr(addr, len, VM_MEMATTR_UNCACHEABLE));
 }
 
 static inline int
 set_memory_wc(unsigned long addr, int numpages)
 {
 #ifdef VM_MEMATTR_WRITE_COMBINING
-	vm_offset_t va;
 	vm_size_t len;
 
-	va = PHYS_TO_DMAP(addr);
-	len = numpages << PAGE_SHIFT;
-
-	return (-pmap_change_attr(va, len, VM_MEMATTR_WRITE_COMBINING));
+	len = (vm_size_t)numpages << PAGE_SHIFT;
+	return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_COMBINING));
 #else
 	return (set_memory_uc(addr, numpages));
 #endif
@@ -62,13 +56,10 @@ set_memory_wc(unsigned long addr, int numpages)
 static inline int
 set_memory_wb(unsigned long addr, int numpages)
 {
-	vm_offset_t va;
 	vm_size_t len;
 
-	va = PHYS_TO_DMAP(addr);
-	len = numpages << PAGE_SHIFT;
-
-	return (-pmap_change_attr(va, len, VM_MEMATTR_WRITE_BACK));
+	len = (vm_size_t)numpages << PAGE_SHIFT;
+	return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_BACK));
 }
 
 static inline int