Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/mm: make virt_to_pfn() a static inline

Making virt_to_pfn() a static inline taking a strongly typed
(const void *) makes the contract of a passing a pointer of that
type to the function explicit and exposes any misuse of the
macro virt_to_pfn() acting polymorphic and accepting many types
such as (void *), (unitptr_t) or (unsigned long) as arguments
without warnings.

For symmetry do the same with pfn_to_virt() reflecting the
current layout in asm-generic/page.h.

Doing this reveals a number of offenders in the arch code and
the S390-specific drivers, so just bite the bullet and fix up
all of those as well.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Link: https://lore.kernel.org/r/20230812-virt-to-phys-s390-v2-1-6c40f31fe36f@linaro.org
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

authored by

Linus Walleij and committed by
Heiko Carstens
2d1494fb 5cfdff02

+15 -7
+1 -1
arch/s390/include/asm/kfence.h
··· 35 35 36 36 static inline bool kfence_protect_page(unsigned long addr, bool protect) 37 37 { 38 - __kernel_map_pages(virt_to_page(addr), 1, !protect); 38 + __kernel_map_pages(virt_to_page((void *)addr), 1, !protect); 39 39 return true; 40 40 } 41 41
+10 -2
arch/s390/include/asm/page.h
··· 191 191 #define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys)) 192 192 #define page_to_phys(page) pfn_to_phys(page_to_pfn(page)) 193 193 194 - #define pfn_to_virt(pfn) __va(pfn_to_phys(pfn)) 195 - #define virt_to_pfn(kaddr) (phys_to_pfn(__pa(kaddr))) 194 + static inline void *pfn_to_virt(unsigned long pfn) 195 + { 196 + return __va(pfn_to_phys(pfn)); 197 + } 198 + 199 + static inline unsigned long virt_to_pfn(const void *kaddr) 200 + { 201 + return phys_to_pfn(__pa(kaddr)); 202 + } 203 + 196 204 #define pfn_to_kaddr(pfn) pfn_to_virt(pfn) 197 205 198 206 #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
+1 -1
arch/s390/mm/cmm.c
··· 90 90 } else 91 91 free_page((unsigned long) npa); 92 92 } 93 - diag10_range(virt_to_pfn(addr), 1); 93 + diag10_range(virt_to_pfn((void *)addr), 1); 94 94 pa->pages[pa->index++] = addr; 95 95 (*counter)++; 96 96 spin_unlock(&cmm_lock);
+1 -1
arch/s390/mm/vmem.c
··· 36 36 { 37 37 /* We don't expect boot memory to be removed ever. */ 38 38 if (!slab_is_available() || 39 - WARN_ON_ONCE(PageReserved(virt_to_page(addr)))) 39 + WARN_ON_ONCE(PageReserved(virt_to_page((void *)addr)))) 40 40 return; 41 41 free_pages(addr, order); 42 42 }
+1 -1
drivers/s390/block/scm_blk.c
··· 134 134 135 135 if ((msb->flags & MSB_FLAG_IDA) && aidaw && 136 136 IS_ALIGNED(aidaw, PAGE_SIZE)) 137 - mempool_free(virt_to_page(aidaw), aidaw_pool); 137 + mempool_free(virt_to_page((void *)aidaw), aidaw_pool); 138 138 } 139 139 140 140 spin_lock_irqsave(&list_lock, flags);
+1 -1
drivers/s390/char/vmcp.c
··· 89 89 order = get_order(session->bufsize); 90 90 nr_pages = ALIGN(session->bufsize, PAGE_SIZE) >> PAGE_SHIFT; 91 91 if (session->cma_alloc) { 92 - page = virt_to_page((unsigned long)session->response); 92 + page = virt_to_page(session->response); 93 93 cma_release(vmcp_cma, page, nr_pages); 94 94 session->cma_alloc = 0; 95 95 } else {