This is an attempt to harden the typing on virt_to_pfn()
and pfn_to_virt().
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, we do the same with pfn_to_virt().
The problem with this inconsistent typing was pointed out by
Russell King:
https://lore.kernel.org/linux-arm-kernel/[email protected]/
And confirmed by Andrew Morton:
https://lore.kernel.org/linux-mm/[email protected]/
So the recognition of the problem is widespread.
These platforms have been chosen as initial conversion targets:
- ARC
- ARM
- ARM64/Aarch64
- asm-generic (including for example x86)
- m68k
The idea is that if this goes in, it will block further misuse
of the function signatures due to the large compile coverage,
and then I can go in and fix the remaining platforms on a
one-by-one basis.
Some of the patches have been circulated before but were not
picked up by subsystem maintainers, so now the arch tree is
target for this series.
It has passed zeroday builds after a lot of iterations in my
personal tree, but there could be some randconfig outliers.
The To/Cc list would be too long if I include all the minor
patches maintainers, so I have trimmed it down to the mailing
lists since these people certainly have received the patches
before.
Signed-off-by: Linus Walleij <[email protected]>
---
Linus Walleij (12):
fs/proc/kcore.c: Pass a pointer to virt_addr_valid()
m68k: Pass a pointer to virt_to_pfn() virt_to_page()
ARC: init: Pass a pointer to virt_to_pfn() in init
riscv: mm: init: Pass a pointer to virt_to_page()
cifs: Pass a pointer to virt_to_page()
cifs: Pass a pointer to virt_to_page() in cifsglob
netfs: Pass a pointer to virt_to_page()
arm64: vdso: Pass (void *) to virt_to_page()
asm-generic/page.h: Make pfn accessors static inlines
ARM: mm: Make virt_to_pfn() a static inline
arm64: memory: Make virt_to_pfn() a static inline
m68k/mm: Make pfn accessors static inlines
arch/arc/mm/init.c | 2 +-
arch/arm/common/sharpsl_param.c | 2 +-
arch/arm/include/asm/delay.h | 2 +-
arch/arm/include/asm/io.h | 2 +-
arch/arm/include/asm/memory.h | 17 ++++++++++++-----
arch/arm/include/asm/page.h | 4 ++--
arch/arm/include/asm/pgtable.h | 2 +-
arch/arm/include/asm/proc-fns.h | 2 --
arch/arm/include/asm/sparsemem.h | 2 +-
arch/arm/include/asm/uaccess-asm.h | 2 +-
arch/arm/include/asm/uaccess.h | 2 +-
arch/arm/kernel/asm-offsets.c | 2 +-
arch/arm/kernel/entry-armv.S | 2 +-
arch/arm/kernel/entry-common.S | 2 +-
arch/arm/kernel/entry-v7m.S | 2 +-
arch/arm/kernel/head-nommu.S | 3 +--
arch/arm/kernel/head.S | 2 +-
arch/arm/kernel/hibernate.c | 2 +-
arch/arm/kernel/suspend.c | 2 +-
arch/arm/kernel/tcm.c | 2 +-
arch/arm/kernel/vmlinux-xip.lds.S | 3 +--
arch/arm/kernel/vmlinux.lds.S | 3 +--
arch/arm/mach-berlin/platsmp.c | 2 +-
arch/arm/mach-keystone/keystone.c | 2 +-
arch/arm/mach-omap2/sleep33xx.S | 2 +-
arch/arm/mach-omap2/sleep43xx.S | 2 +-
arch/arm/mach-omap2/sleep44xx.S | 2 +-
arch/arm/mach-pxa/gumstix.c | 2 +-
arch/arm/mach-rockchip/sleep.S | 2 +-
arch/arm/mach-sa1100/pm.c | 2 +-
arch/arm/mach-shmobile/headsmp-scu.S | 2 +-
arch/arm/mach-shmobile/headsmp.S | 2 +-
arch/arm/mach-socfpga/headsmp.S | 2 +-
arch/arm/mach-spear/spear.h | 2 +-
arch/arm/mm/cache-fa.S | 1 -
arch/arm/mm/cache-v4wb.S | 1 -
arch/arm/mm/dma-mapping.c | 2 +-
arch/arm/mm/dump.c | 2 +-
arch/arm/mm/init.c | 2 +-
arch/arm/mm/kasan_init.c | 1 -
arch/arm/mm/mmu.c | 2 +-
arch/arm/mm/physaddr.c | 2 +-
arch/arm/mm/pmsa-v8.c | 2 +-
arch/arm/mm/proc-v7.S | 2 +-
arch/arm/mm/proc-v7m.S | 2 +-
arch/arm/mm/pv-fixup-asm.S | 2 +-
arch/arm64/include/asm/memory.h | 9 ++++++++-
arch/arm64/kernel/vdso.c | 2 +-
arch/m68k/include/asm/page_mm.h | 11 +++++++++--
arch/m68k/include/asm/page_no.h | 11 +++++++++--
arch/m68k/mm/motorola.c | 4 ++--
arch/m68k/mm/sun3mmu.c | 2 +-
arch/m68k/sun3/dvma.c | 2 +-
arch/m68k/sun3x/dvma.c | 2 +-
arch/riscv/mm/init.c | 4 ++--
drivers/memory/ti-emif-sram-pm.S | 2 +-
fs/cifs/cifsglob.h | 2 +-
fs/cifs/smbdirect.c | 2 +-
fs/netfs/iterator.c | 2 +-
fs/proc/kcore.c | 2 +-
include/asm-generic/page.h | 12 ++++++++++--
61 files changed, 103 insertions(+), 75 deletions(-)
---
base-commit: ac9a78681b921877518763ba0e89202254349d1b
change-id: 20230503-virt-to-pfn-v6-4-rc1-4f5739e8d60d
Best regards,
--
Linus Walleij <[email protected]>
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.
Since arm64 is using <asm-generic/memory_model.h> to provide
__phys_to_pfn() we need to move the inclusion of that header
up, so we can resolve the static inline at compile time.
Signed-off-by: Linus Walleij <[email protected]>
---
arch/arm64/include/asm/memory.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index c735afdf639b..4d85212b622e 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -331,6 +331,14 @@ static inline void *phys_to_virt(phys_addr_t x)
return (void *)(__phys_to_virt(x));
}
+/* Needed already here for resolving __phys_to_pfn() in virt_to_pfn() */
+#include <asm-generic/memory_model.h>
+
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+ return __phys_to_pfn(virt_to_phys(kaddr));
+}
+
/*
* Drivers should NOT use these either.
*/
@@ -339,7 +347,6 @@ static inline void *phys_to_virt(phys_addr_t x)
#define __pa_nodebug(x) __virt_to_phys_nodebug((unsigned long)(x))
#define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x)))
#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
-#define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x)))
#define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x))
/*
--
2.34.1
Like the other calls in this function virt_to_page() expects
a pointer, not an integer.
However since many architectures implement virt_to_pfn() as
a macro, this function becomes polymorphic and accepts both a
(unsigned long) and a (void *).
Fix this up with an explicit cast.
Signed-off-by: Linus Walleij <[email protected]>
---
fs/cifs/smbdirect.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/cifs/smbdirect.c b/fs/cifs/smbdirect.c
index 0362ebd4fa0f..964f07375a8d 100644
--- a/fs/cifs/smbdirect.c
+++ b/fs/cifs/smbdirect.c
@@ -2500,7 +2500,7 @@ static ssize_t smb_extract_kvec_to_rdma(struct iov_iter *iter,
if (is_vmalloc_or_module_addr((void *)kaddr))
page = vmalloc_to_page((void *)kaddr);
else
- page = virt_to_page(kaddr);
+ page = virt_to_page((void *)kaddr);
if (!smb_set_sge(rdma, page, off, seg))
return -EIO;
--
2.34.1
Functions that work on a pointer to virtual memory such as
virt_to_pfn() and users of that function such as
virt_to_page() are supposed to pass a pointer to virtual
memory, ideally a (void *) or other pointer. However since
many architectures implement virt_to_pfn() as a macro,
this function becomes polymorphic and accepts both a
(unsigned long) and a (void *).
Fix up the offending calls in arch/m68k with explicit casts.
Signed-off-by: Linus Walleij <[email protected]>
---
ChangeLog v1->v2:
- Add an extra parens around the page argument to the
PD_PTABLE() macro, as is normally required.
---
arch/m68k/mm/motorola.c | 4 ++--
arch/m68k/mm/sun3mmu.c | 2 +-
arch/m68k/sun3/dvma.c | 2 +-
arch/m68k/sun3x/dvma.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
index 911301224078..c75984e2d86b 100644
--- a/arch/m68k/mm/motorola.c
+++ b/arch/m68k/mm/motorola.c
@@ -102,7 +102,7 @@ static struct list_head ptable_list[2] = {
LIST_HEAD_INIT(ptable_list[1]),
};
-#define PD_PTABLE(page) ((ptable_desc *)&(virt_to_page(page)->lru))
+#define PD_PTABLE(page) ((ptable_desc *)&(virt_to_page((void *)(page))->lru))
#define PD_PAGE(ptable) (list_entry(ptable, struct page, lru))
#define PD_MARKBITS(dp) (*(unsigned int *)&PD_PAGE(dp)->index)
@@ -201,7 +201,7 @@ int free_pointer_table(void *table, int type)
list_del(dp);
mmu_page_dtor((void *)page);
if (type == TABLE_PTE)
- pgtable_pte_page_dtor(virt_to_page(page));
+ pgtable_pte_page_dtor(virt_to_page((void *)page));
free_page (page);
return 1;
} else if (ptable_list[type].next != dp) {
diff --git a/arch/m68k/mm/sun3mmu.c b/arch/m68k/mm/sun3mmu.c
index b619d0d4319c..c5e6a23e0262 100644
--- a/arch/m68k/mm/sun3mmu.c
+++ b/arch/m68k/mm/sun3mmu.c
@@ -75,7 +75,7 @@ void __init paging_init(void)
/* now change pg_table to kernel virtual addresses */
pg_table = (pte_t *) __va ((unsigned long) pg_table);
for (i=0; i<PTRS_PER_PTE; ++i, ++pg_table) {
- pte_t pte = pfn_pte(virt_to_pfn(address), PAGE_INIT);
+ pte_t pte = pfn_pte(virt_to_pfn((void *)address), PAGE_INIT);
if (address >= (unsigned long)high_memory)
pte_val (pte) = 0;
set_pte (pg_table, pte);
diff --git a/arch/m68k/sun3/dvma.c b/arch/m68k/sun3/dvma.c
index f15ff16b9997..83fcae6a0e79 100644
--- a/arch/m68k/sun3/dvma.c
+++ b/arch/m68k/sun3/dvma.c
@@ -29,7 +29,7 @@ static unsigned long dvma_page(unsigned long kaddr, unsigned long vaddr)
j = *(volatile unsigned long *)kaddr;
*(volatile unsigned long *)kaddr = j;
- ptep = pfn_pte(virt_to_pfn(kaddr), PAGE_KERNEL);
+ ptep = pfn_pte(virt_to_pfn((void *)kaddr), PAGE_KERNEL);
pte = pte_val(ptep);
// pr_info("dvma_remap: addr %lx -> %lx pte %08lx\n", kaddr, vaddr, pte);
if(ptelist[(vaddr & 0xff000) >> PAGE_SHIFT] != pte) {
diff --git a/arch/m68k/sun3x/dvma.c b/arch/m68k/sun3x/dvma.c
index 08bb92113026..a6034ba05845 100644
--- a/arch/m68k/sun3x/dvma.c
+++ b/arch/m68k/sun3x/dvma.c
@@ -125,7 +125,7 @@ inline int dvma_map_cpu(unsigned long kaddr,
do {
pr_debug("mapping %08lx phys to %08lx\n",
__pa(kaddr), vaddr);
- set_pte(pte, pfn_pte(virt_to_pfn(kaddr),
+ set_pte(pte, pfn_pte(virt_to_pfn((void *)kaddr),
PAGE_KERNEL));
pte++;
kaddr += PAGE_SIZE;
--
2.34.1
Like the other calls in this function virt_to_page() expects
a pointer, not an integer.
However since many architectures implement virt_to_pfn() as
a macro, this function becomes polymorphic and accepts both a
(unsigned long) and a (void *).
Fix this up with an explicit cast.
Signed-off-by: Linus Walleij <[email protected]>
---
fs/netfs/iterator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/netfs/iterator.c b/fs/netfs/iterator.c
index 8a4c86687429..0431ec4a7298 100644
--- a/fs/netfs/iterator.c
+++ b/fs/netfs/iterator.c
@@ -240,7 +240,7 @@ static ssize_t netfs_extract_kvec_to_sg(struct iov_iter *iter,
if (is_vmalloc_or_module_addr((void *)kaddr))
page = vmalloc_to_page((void *)kaddr);
else
- page = virt_to_page(kaddr);
+ page = virt_to_page((void *)kaddr);
sg_set_page(sg, page, len, off);
sgtable->nents++;
--
2.34.1
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().
Signed-off-by: Linus Walleij <[email protected]>
---
arch/m68k/include/asm/page_mm.h | 11 +++++++++--
arch/m68k/include/asm/page_no.h | 11 +++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/arch/m68k/include/asm/page_mm.h b/arch/m68k/include/asm/page_mm.h
index 3903db2e8da7..40bcc6aa33da 100644
--- a/arch/m68k/include/asm/page_mm.h
+++ b/arch/m68k/include/asm/page_mm.h
@@ -121,8 +121,15 @@ static inline void *__va(unsigned long x)
* TODO: implement (fast) pfn<->pgdat_idx conversion functions, this makes lots
* of the shifts unnecessary.
*/
-#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
-#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+ return __pa(kaddr) >> PAGE_SHIFT;
+}
+
+static inline void * pfn_to_virt(unsigned long pfn)
+{
+ return __va(pfn << PAGE_SHIFT);
+}
extern int m68k_virt_to_node_shift;
diff --git a/arch/m68k/include/asm/page_no.h b/arch/m68k/include/asm/page_no.h
index 060e4c0e7605..f1daf466a57b 100644
--- a/arch/m68k/include/asm/page_no.h
+++ b/arch/m68k/include/asm/page_no.h
@@ -19,8 +19,15 @@ extern unsigned long memory_end;
#define __pa(vaddr) ((unsigned long)(vaddr))
#define __va(paddr) ((void *)((unsigned long)(paddr)))
-#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
-#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+ return __pa(kaddr) >> PAGE_SHIFT;
+}
+
+static inline void * pfn_to_virt(unsigned long pfn)
+{
+ return __va(pfn << PAGE_SHIFT);
+}
#define virt_to_page(addr) (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))
#define page_to_virt(page) __va(((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET))
--
2.34.1
Hi Linus,
On Thu, May 11, 2023 at 1:59 PM Linus Walleij <[email protected]> wrote:
> This is an attempt to harden the typing on virt_to_pfn()
> and pfn_to_virt().
>
> 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, we do the same with pfn_to_virt().
>
> The problem with this inconsistent typing was pointed out by
> Russell King:
> https://lore.kernel.org/linux-arm-kernel/[email protected]/
>
> And confirmed by Andrew Morton:
> https://lore.kernel.org/linux-mm/[email protected]/
>
> So the recognition of the problem is widespread.
>
> These platforms have been chosen as initial conversion targets:
>
> - ARC
> - ARM
> - ARM64/Aarch64
> - asm-generic (including for example x86)
> - m68k
Thanks, builds fine on m68k with MMU, and boots fine on ARAnyM,
with the extra changes I replied on patch 2/12.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hi Linus,
On Thu, May 11, 2023 at 1:59 PM Linus Walleij <[email protected]> wrote:
> Functions that work on a pointer to virtual memory such as
> virt_to_pfn() and users of that function such as
> virt_to_page() are supposed to pass a pointer to virtual
> memory, ideally a (void *) or other pointer. However since
> many architectures implement virt_to_pfn() as a macro,
> this function becomes polymorphic and accepts both a
> (unsigned long) and a (void *).
>
> Fix up the offending calls in arch/m68k with explicit casts.
>
> Signed-off-by: Linus Walleij <[email protected]>
> ---
> ChangeLog v1->v2:
> - Add an extra parens around the page argument to the
> PD_PTABLE() macro, as is normally required.
Thanks for the update!
To build sun3_defconfig and m5475evb_defconfig cleanly, you need to
include the (Gmail-whitespace-damaged) changes below.
These were compile-tested only.
diff --git a/arch/m68k/include/asm/mcf_pgtable.h
b/arch/m68k/include/asm/mcf_pgtable.h
index 96d069829803505c..46ae379bb14d5e05 100644
--- a/arch/m68k/include/asm/mcf_pgtable.h
+++ b/arch/m68k/include/asm/mcf_pgtable.h
@@ -135,7 +135,7 @@ static inline void pte_clear(struct mm_struct *mm,
unsigned long addr,
}
#define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
-#define pte_page(pte) virt_to_page(__pte_page(pte))
+#define pte_page(pte) virt_to_page((void *)__pte_page(pte))
static inline int pmd_none2(pmd_t *pmd) { return !pmd_val(*pmd); }
#define pmd_none(pmd) pmd_none2(&(pmd))
diff --git a/arch/m68k/include/asm/sun3_pgtable.h
b/arch/m68k/include/asm/sun3_pgtable.h
index e582b0484a55cd82..f3e7728f58cd9dd0 100644
--- a/arch/m68k/include/asm/sun3_pgtable.h
+++ b/arch/m68k/include/asm/sun3_pgtable.h
@@ -109,9 +109,9 @@ static inline void pte_clear (struct mm_struct
*mm, unsigned long addr, pte_t *p
#define pfn_pte(pfn, pgprot) \
({ pte_t __pte; pte_val(__pte) = pfn | pgprot_val(pgprot); __pte; })
-#define pte_page(pte) virt_to_page(__pte_page(pte))
+#define pte_page(pte) virt_to_page((void *)__pte_page(pte))
#define pmd_pfn(pmd) (pmd_val(pmd) >> PAGE_SHIFT)
-#define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd))
+#define pmd_page(pmd) virt_to_page((void *)pmd_page_vaddr(pmd))
static inline int pmd_none2 (pmd_t *pmd) { return !pmd_val (*pmd); }
diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
index 70aa0979e02710a8..a4c552c7e2c8ca12 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -69,7 +69,7 @@ void __init paging_init(void)
/* now change pg_table to kernel virtual addresses */
for (i = 0; i < PTRS_PER_PTE; ++i, ++pg_table) {
- pte_t pte = pfn_pte(virt_to_pfn(address), PAGE_INIT);
+ pte_t pte = pfn_pte(virt_to_pfn((void
*)address), PAGE_INIT);
if (address >= (unsigned long) high_memory)
pte_val(pte) = 0;
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
On Fri, May 12, 2023 at 11:55 AM Geert Uytterhoeven
<[email protected]> wrote:
> On Thu, May 11, 2023 at 1:59 PM Linus Walleij <[email protected]> wrote:
> > Functions that work on a pointer to virtual memory such as
> > virt_to_pfn() and users of that function such as
> > virt_to_page() are supposed to pass a pointer to virtual
> > memory, ideally a (void *) or other pointer. However since
> > many architectures implement virt_to_pfn() as a macro,
> > this function becomes polymorphic and accepts both a
> > (unsigned long) and a (void *).
> >
> > Fix up the offending calls in arch/m68k with explicit casts.
> >
> > Signed-off-by: Linus Walleij <[email protected]>
> > ---
> > ChangeLog v1->v2:
> > - Add an extra parens around the page argument to the
> > PD_PTABLE() macro, as is normally required.
>
> Thanks for the update!
>
> To build sun3_defconfig and m5475evb_defconfig cleanly, you need to
> include the (Gmail-whitespace-damaged) changes below.
> These were compile-tested only.
> --- a/arch/m68k/include/asm/sun3_pgtable.h
> +++ b/arch/m68k/include/asm/sun3_pgtable.h
> @@ -109,9 +109,9 @@ static inline void pte_clear (struct mm_struct
> *mm, unsigned long addr, pte_t *p
> #define pfn_pte(pfn, pgprot) \
> ({ pte_t __pte; pte_val(__pte) = pfn | pgprot_val(pgprot); __pte; })
>
> -#define pte_page(pte) virt_to_page(__pte_page(pte))
> +#define pte_page(pte) virt_to_page((void *)__pte_page(pte))
Much simpler to drop the cast in __pte_page() instead:
@@ -91,7 +91,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
#define pmd_set(pmdp,ptep) do {} while (0)
#define __pte_page(pte) \
-((unsigned long) __va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT))
+ (__va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT))
static inline unsigned long pmd_page_vaddr(pmd_t pmd)
{
> #define pmd_pfn(pmd) (pmd_val(pmd) >> PAGE_SHIFT)
> -#define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd))
> +#define pmd_page(pmd) virt_to_page((void *)pmd_page_vaddr(pmd))
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
On Thu, May 11, 2023 at 01:59:28PM +0200, Linus Walleij wrote:
> 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.
>
> Since arm64 is using <asm-generic/memory_model.h> to provide
> __phys_to_pfn() we need to move the inclusion of that header
> up, so we can resolve the static inline at compile time.
>
> Signed-off-by: Linus Walleij <[email protected]>
Acked-by: Catalin Marinas <[email protected]>
On Fri, May 12, 2023 at 12:26 PM Geert Uytterhoeven
<[email protected]> wrote:
> Much simpler to drop the cast in __pte_page() instead:
>
> @@ -91,7 +91,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
> #define pmd_set(pmdp,ptep) do {} while (0)
>
> #define __pte_page(pte) \
> -((unsigned long) __va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT))
> + (__va ((pte_val (pte) & SUN3_PAGE_PGNUM_MASK) << PAGE_SHIFT))
Thanks, folded this into the patch!
Yours,
Linus Walleij
On 5/11/2023 7:59 AM, Linus Walleij wrote:
> Like the other calls in this function virt_to_page() expects
> a pointer, not an integer.
>
> However since many architectures implement virt_to_pfn() as
> a macro, this function becomes polymorphic and accepts both a
> (unsigned long) and a (void *).
>
> Fix this up with an explicit cast.
>
> Signed-off-by: Linus Walleij <[email protected]>
For fs/cifs:
Acked-by: Tom Talpey <[email protected]>
> ---
> fs/cifs/smbdirect.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/cifs/smbdirect.c b/fs/cifs/smbdirect.c
> index 0362ebd4fa0f..964f07375a8d 100644
> --- a/fs/cifs/smbdirect.c
> +++ b/fs/cifs/smbdirect.c
> @@ -2500,7 +2500,7 @@ static ssize_t smb_extract_kvec_to_rdma(struct iov_iter *iter,
> if (is_vmalloc_or_module_addr((void *)kaddr))
> page = vmalloc_to_page((void *)kaddr);
> else
> - page = virt_to_page(kaddr);
> + page = virt_to_page((void *)kaddr);
>
> if (!smb_set_sge(rdma, page, off, seg))
> return -EIO;
>