[PATCH 2/2] Hexagon: Make pfn accessors statics inlines

2023-11-15 Thread Linus Walleij
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().

For compiletime resolution of __pa() we need PAGE_OFFSET which
was not available to __pa() and resolved by the preprocessor
wherever __pa() was used. Fix this by explicitly including
 where required, following the pattern of the
architectures page.h file.

Acked-by: Brian Cain 
Signed-off-by: Linus Walleij 
---
 arch/hexagon/include/asm/page.h | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
index 9c03b9965f07..10f1bc07423c 100644
--- a/arch/hexagon/include/asm/page.h
+++ b/arch/hexagon/include/asm/page.h
@@ -78,6 +78,9 @@ typedef struct page *pgtable_t;
 #define __pgd(x)   ((pgd_t) { (x) })
 #define __pgprot(x)((pgprot_t) { (x) })
 
+/* Needed for PAGE_OFFSET used in the macro right below */
+#include 
+
 /*
  * We need a __pa and a __va routine for kernel space.
  * MIPS says they're only used during mem_init.
@@ -125,8 +128,16 @@ static inline void clear_page(void *page)
  */
 #define page_to_phys(page)  (page_to_pfn(page) << PAGE_SHIFT)
 
-#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 (void *)((unsigned long)__va(pfn) << PAGE_SHIFT);
+}
+
 
 #define page_to_virt(page) __va(page_to_phys(page))
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 0/2] arch: Virt to phys to static inlines

2023-11-15 Thread Linus Walleij
Some architectures have been given patches to switch their
virt_to_phys()/phys_to_virt() or underlying *pfn etc functions
over to static inlines.

Some patches have been ignored or have no maintained arch
tree.

This set includes patches that I suggest to simply be applied
to the arch tree so they get in.

Signed-off-by: Linus Walleij 
---
Linus Walleij (2):
  ARC: mm: Make virt_to_pfn() a static inline
  Hexagon: Make pfn accessors statics inlines

 arch/arc/include/asm/page.h   | 21 -
 arch/arc/include/asm/pgtable-levels.h |  2 +-
 arch/hexagon/include/asm/page.h   | 15 +--
 3 files changed, 26 insertions(+), 12 deletions(-)
---
base-commit: b85ea95d086471afb4ad062012a4d73cd328fa86
change-id: 20231115-virt-to-phy-arch-tree-137bc87046e1

Best regards,
-- 
Linus Walleij 


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 1/2] ARC: mm: Make virt_to_pfn() a static inline

2023-11-15 Thread Linus Walleij
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.

In order to do this we move the virt_to_phys() and
below the definition of the __pa() and __va() macros so it
compiles. The macro version was also able to do recursive
symbol resolution.

Signed-off-by: Linus Walleij 
---
 arch/arc/include/asm/page.h   | 21 -
 arch/arc/include/asm/pgtable-levels.h |  2 +-
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index 02b53ad811fb..def0dfb95b43 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -84,15 +84,6 @@ typedef struct {
 
 typedef struct page *pgtable_t;
 
-/*
- * Use virt_to_pfn with caution:
- * If used in pte or paddr related macros, it could cause truncation
- * in PAE40 builds
- * As a rule of thumb, only use it in helpers starting with virt_
- * You have been warned !
- */
-#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
-
 /*
  * When HIGHMEM is enabled we have holes in the memory map so we need
  * pfn_valid() that takes into account the actual extents of the physical
@@ -122,6 +113,18 @@ extern int pfn_valid(unsigned long pfn);
 #define __pa(vaddr)((unsigned long)(vaddr))
 #define __va(paddr)((void *)((unsigned long)(paddr)))
 
+/*
+ * Use virt_to_pfn with caution:
+ * If used in pte or paddr related macros, it could cause truncation
+ * in PAE40 builds
+ * As a rule of thumb, only use it in helpers starting with virt_
+ * You have been warned !
+ */
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+   return __pa(kaddr) >> PAGE_SHIFT;
+}
+
 #define virt_to_page(kaddr)pfn_to_page(virt_to_pfn(kaddr))
 #define virt_addr_valid(kaddr)  pfn_valid(virt_to_pfn(kaddr))
 
diff --git a/arch/arc/include/asm/pgtable-levels.h 
b/arch/arc/include/asm/pgtable-levels.h
index fc417c75c24d..86e148226463 100644
--- a/arch/arc/include/asm/pgtable-levels.h
+++ b/arch/arc/include/asm/pgtable-levels.h
@@ -159,7 +159,7 @@
 #define pmd_clear(xp)  do { pmd_val(*(xp)) = 0; } while (0)
 #define pmd_page_vaddr(pmd)(pmd_val(pmd) & PAGE_MASK)
 #define pmd_pfn(pmd)   ((pmd_val(pmd) & PAGE_MASK) >> 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))
 #define set_pmd(pmdp, pmd) (*(pmdp) = pmd)
 #define pmd_pgtable(pmd)   ((pgtable_t) pmd_page(pmd))
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] ARC: mm: Make virt_to_pfn() a static inline

2023-09-14 Thread Linus Walleij
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.

In order to do this we move the virt_to_phys() and
below the definition of the __pa() and __va() macros so it
compiles. The macro version was also able to do recursive
symbol resolution.

Signed-off-by: Linus Walleij 
---
 arch/arc/include/asm/page.h   | 21 -
 arch/arc/include/asm/pgtable-levels.h |  2 +-
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index 02b53ad811fb..def0dfb95b43 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -84,15 +84,6 @@ typedef struct {
 
 typedef struct page *pgtable_t;
 
-/*
- * Use virt_to_pfn with caution:
- * If used in pte or paddr related macros, it could cause truncation
- * in PAE40 builds
- * As a rule of thumb, only use it in helpers starting with virt_
- * You have been warned !
- */
-#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
-
 /*
  * When HIGHMEM is enabled we have holes in the memory map so we need
  * pfn_valid() that takes into account the actual extents of the physical
@@ -122,6 +113,18 @@ extern int pfn_valid(unsigned long pfn);
 #define __pa(vaddr)((unsigned long)(vaddr))
 #define __va(paddr)((void *)((unsigned long)(paddr)))
 
+/*
+ * Use virt_to_pfn with caution:
+ * If used in pte or paddr related macros, it could cause truncation
+ * in PAE40 builds
+ * As a rule of thumb, only use it in helpers starting with virt_
+ * You have been warned !
+ */
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+   return __pa(kaddr) >> PAGE_SHIFT;
+}
+
 #define virt_to_page(kaddr)pfn_to_page(virt_to_pfn(kaddr))
 #define virt_addr_valid(kaddr)  pfn_valid(virt_to_pfn(kaddr))
 
diff --git a/arch/arc/include/asm/pgtable-levels.h 
b/arch/arc/include/asm/pgtable-levels.h
index fc417c75c24d..86e148226463 100644
--- a/arch/arc/include/asm/pgtable-levels.h
+++ b/arch/arc/include/asm/pgtable-levels.h
@@ -159,7 +159,7 @@
 #define pmd_clear(xp)  do { pmd_val(*(xp)) = 0; } while (0)
 #define pmd_page_vaddr(pmd)(pmd_val(pmd) & PAGE_MASK)
 #define pmd_pfn(pmd)   ((pmd_val(pmd) & PAGE_MASK) >> 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))
 #define set_pmd(pmdp, pmd) (*(pmdp) = pmd)
 #define pmd_pgtable(pmd)   ((pgtable_t) pmd_page(pmd))
 

---
base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
change-id: 20230913-virt-to-phys-arc-b0b613c689b0

Best regards,
-- 
Linus Walleij 


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 2/2] csky: Make pfn accessors static inlines

2023-08-10 Thread Linus Walleij
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 to the same thing with pfn_to_virt().

In order to do this we move the virt_to_phys() and
phys_to_virt() below the definitions of the __pa()
and __va() macros so it compiles. The macro version was also
able to do recursive symbol resolution.

Acked-by: Guo Ren 
Signed-off-by: Linus Walleij 
---
 arch/csky/include/asm/page.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
index b23e3006a9e0..4a0502e324a6 100644
--- a/arch/csky/include/asm/page.h
+++ b/arch/csky/include/asm/page.h
@@ -34,9 +34,6 @@
 
 #include 
 
-#define virt_to_pfn(kaddr)  (__pa(kaddr) >> PAGE_SHIFT)
-#define pfn_to_virt(pfn)__va((pfn) << PAGE_SHIFT)
-
 #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
(void *)(kaddr) < high_memory)
 
@@ -80,6 +77,16 @@ extern unsigned long va_pa_offset;
 
 #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 
+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 (void *)((unsigned long)__va(pfn) << PAGE_SHIFT);
+}
+
 #define MAP_NR(x)  PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
 PHYS_OFFSET_OFFSET)
 #define virt_to_page(x)(mem_map + MAP_NR(x))

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 0/2] csky: Convert memory accessors to static inlines

2023-08-10 Thread Linus Walleij
This converts the virt_to_pfn and pfn_to_virt macros
into static inlines so we get proper type checking on
the pointers passed in.

Signed-off-by: Linus Walleij 
---
Changes in v3:
- Do not return const void * from pfn_to_virt(), return
  void * so we don't case a mess.
- Link to v2: 
https://lore.kernel.org/r/20230809-csky-virt-to-phys-v2-0-2697c93f6...@linaro.org

Changes in v2:
- Fix compilation error on pfn_to_virt() by more casting.
- Return const void * rather than just void * from pfn_to_virt()
- Link to v1: 
https://lore.kernel.org/r/20230808-csky-virt-to-phys-v1-0-ac727f8de...@linaro.org

---
Linus Walleij (2):
  csky: Cast argument to virt_to_pfn() to (void *)
  csky: Make pfn accessors static inlines

 arch/arc/include/asm/page.h  |  2 +-
 arch/csky/include/asm/page.h | 13 ++---
 2 files changed, 11 insertions(+), 4 deletions(-)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230808-csky-virt-to-phys-3d80c17211f9

Best regards,
-- 
Linus Walleij 


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 1/2] csky: Cast argument to virt_to_pfn() to (void *)

2023-08-10 Thread Linus Walleij
The virt_to_pfn() function takes a (void *) as argument, fix
this up to avoid exploiting the unintended polymorphism of
virt_to_pfn.

Acked-by: Guo Ren 
Signed-off-by: Linus Walleij 
---
 arch/arc/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index e43fe27ec54d..02b53ad811fb 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -108,7 +108,7 @@ extern int pfn_valid(unsigned long pfn);
 
 #else /* CONFIG_HIGHMEM */
 
-#define ARCH_PFN_OFFSETvirt_to_pfn(CONFIG_LINUX_RAM_BASE)
+#define ARCH_PFN_OFFSETvirt_to_pfn((void 
*)CONFIG_LINUX_RAM_BASE)
 
 #endif /* CONFIG_HIGHMEM */
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 2/2] csky: Make pfn accessors static inlines

2023-08-09 Thread Linus Walleij
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 to the same thing with pfn_to_virt().

In order to do this we move the virt_to_phys() and
phys_to_virt() below the definitions of the __pa()
and __va() macros so it compiles. The macro version was also
able to do recursive symbol resolution.

Acked-by: Guo Ren 
Signed-off-by: Linus Walleij 
---
 arch/csky/include/asm/page.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
index b23e3006a9e0..57b3f106ae77 100644
--- a/arch/csky/include/asm/page.h
+++ b/arch/csky/include/asm/page.h
@@ -34,9 +34,6 @@
 
 #include 
 
-#define virt_to_pfn(kaddr)  (__pa(kaddr) >> PAGE_SHIFT)
-#define pfn_to_virt(pfn)__va((pfn) << PAGE_SHIFT)
-
 #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
(void *)(kaddr) < high_memory)
 
@@ -80,6 +77,16 @@ extern unsigned long va_pa_offset;
 
 #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+   return __pa(kaddr) >> PAGE_SHIFT;
+}
+
+static inline const void * pfn_to_virt(unsigned long pfn)
+{
+   return (const void *)((unsigned long)__va(pfn) << PAGE_SHIFT);
+}
+
 #define MAP_NR(x)  PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
 PHYS_OFFSET_OFFSET)
 #define virt_to_page(x)(mem_map + MAP_NR(x))

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 0/2] csky: Convert memory accessors to static inlines

2023-08-09 Thread Linus Walleij
This converts the virt_to_pfn and pfn_to_virt macros
into static inlines so we get proper type checking on
the pointers passed in.

Signed-off-by: Linus Walleij 
---
Changes in v2:
- Fix compilation error on pfn_to_virt() by more casting.
- Return const void * rather than just void * from pfn_to_virt()
- Link to v1: 
https://lore.kernel.org/r/20230808-csky-virt-to-phys-v1-0-ac727f8de...@linaro.org

---
Linus Walleij (2):
  csky: Cast argument to virt_to_pfn() to (void *)
  csky: Make pfn accessors static inlines

 arch/arc/include/asm/page.h  |  2 +-
 arch/csky/include/asm/page.h | 13 ++---
 2 files changed, 11 insertions(+), 4 deletions(-)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230808-csky-virt-to-phys-3d80c17211f9

Best regards,
-- 
Linus Walleij 


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 1/2] csky: Cast argument to virt_to_pfn() to (void *)

2023-08-09 Thread Linus Walleij
The virt_to_pfn() function takes a (void *) as argument, fix
this up to avoid exploiting the unintended polymorphism of
virt_to_pfn.

Acked-by: Guo Ren 
Signed-off-by: Linus Walleij 
---
 arch/arc/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index e43fe27ec54d..02b53ad811fb 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -108,7 +108,7 @@ extern int pfn_valid(unsigned long pfn);
 
 #else /* CONFIG_HIGHMEM */
 
-#define ARCH_PFN_OFFSETvirt_to_pfn(CONFIG_LINUX_RAM_BASE)
+#define ARCH_PFN_OFFSETvirt_to_pfn((void 
*)CONFIG_LINUX_RAM_BASE)
 
 #endif /* CONFIG_HIGHMEM */
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 0/2] csky: Convert memory accessors to static inlines

2023-08-08 Thread Linus Walleij
This converts the virt_to_pfn and pfn_to_virt macros
into static inlines so we get proper type checking on
the pointers passed in.

Signed-off-by: Linus Walleij 
---
Linus Walleij (2):
  csky: Cast argument to virt_to_pfn() to (void *)
  csky: Make pfn accessors static inlines

 arch/arc/include/asm/page.h  |  2 +-
 arch/csky/include/asm/page.h | 13 ++---
 2 files changed, 11 insertions(+), 4 deletions(-)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230808-csky-virt-to-phys-3d80c17211f9

Best regards,
-- 
Linus Walleij 


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 2/2] csky: Make pfn accessors static inlines

2023-08-08 Thread Linus Walleij
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 to the same thing with pfn_to_virt().

In order to do this we move the virt_to_phys() and
phys_to_virt() below the definitions of the __pa()
and __va() macros so it compiles. The macro version was also
able to do recursive symbol resolution.

Signed-off-by: Linus Walleij 
---
 arch/csky/include/asm/page.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
index b23e3006a9e0..80da7e96a8fa 100644
--- a/arch/csky/include/asm/page.h
+++ b/arch/csky/include/asm/page.h
@@ -34,9 +34,6 @@
 
 #include 
 
-#define virt_to_pfn(kaddr)  (__pa(kaddr) >> PAGE_SHIFT)
-#define pfn_to_virt(pfn)__va((pfn) << PAGE_SHIFT)
-
 #define virt_addr_valid(kaddr)  ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
(void *)(kaddr) < high_memory)
 
@@ -80,6 +77,16 @@ extern unsigned long va_pa_offset;
 
 #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 
+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 MAP_NR(x)  PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
 PHYS_OFFSET_OFFSET)
 #define virt_to_page(x)(mem_map + MAP_NR(x))

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 1/2] csky: Cast argument to virt_to_pfn() to (void *)

2023-08-08 Thread Linus Walleij
The virt_to_pfn() function takes a (void *) as argument, fix
this up to avoid exploiting the unintended polymorphism of
virt_to_pfn.

Signed-off-by: Linus Walleij 
---
 arch/arc/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index e43fe27ec54d..02b53ad811fb 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -108,7 +108,7 @@ extern int pfn_valid(unsigned long pfn);
 
 #else /* CONFIG_HIGHMEM */
 
-#define ARCH_PFN_OFFSETvirt_to_pfn(CONFIG_LINUX_RAM_BASE)
+#define ARCH_PFN_OFFSETvirt_to_pfn((void 
*)CONFIG_LINUX_RAM_BASE)
 
 #endif /* CONFIG_HIGHMEM */
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 04/12] riscv: mm: init: Pass a pointer to virt_to_page()

2023-05-23 Thread Linus Walleij
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 this in the RISCV mm init code, so we can implement
a strongly typed virt_to_pfn().

Reviewed-by: Alexandre Ghiti 
Signed-off-by: Linus Walleij 
---
 arch/riscv/mm/init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 747e5b1ef02d..2f7a7c345a6a 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -356,7 +356,7 @@ static phys_addr_t __init alloc_pte_late(uintptr_t va)
unsigned long vaddr;
 
vaddr = __get_free_page(GFP_KERNEL);
-   BUG_ON(!vaddr || !pgtable_pte_page_ctor(virt_to_page(vaddr)));
+   BUG_ON(!vaddr || !pgtable_pte_page_ctor(virt_to_page((void *)vaddr)));
 
return __pa(vaddr);
 }
@@ -439,7 +439,7 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va)
unsigned long vaddr;
 
vaddr = __get_free_page(GFP_KERNEL);
-   BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+   BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page((void *)vaddr)));
 
return __pa(vaddr);
 }

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 03/12] ARC: init: Pass a pointer to virt_to_pfn() in init

2023-05-23 Thread Linus Walleij
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 call in arch/arc with an explicit cast.

Signed-off-by: Linus Walleij 
---
 arch/arc/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 2b89b6c53801..9f64d729c9f8 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -87,7 +87,7 @@ void __init setup_arch_memory(void)
setup_initial_init_mm(_text, _etext, _edata, _end);
 
/* first page of system - kernel .vector starts here */
-   min_low_pfn = virt_to_pfn(CONFIG_LINUX_RAM_BASE);
+   min_low_pfn = virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE);
 
/* Last usable page of low mem */
max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 02/12] m68k: Pass a pointer to virt_to_pfn() virt_to_page()

2023-05-23 Thread Linus Walleij
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.

The page table include  will include different
variants of the defines depending on whether you build for
classic m68k, ColdFire or Sun3, so fix all variants.

Tested-by: Geert Uytterhoeven 
Signed-off-by: Linus Walleij 
---
ChangeLog v2->v3:
- Fix up versioning. This is v3.
- Let Coldfire __pte_page() return a (void *) instead of __va
- Delete Coldfire pte_pagenr() which was using unsigned long
  semantics from __pte_page()
- Drop ill-advised change to Coldfire pmd_page_vaddr()
ChangeLog v1->v2:
- Fix the sun3 pgtable macro to not cast to unsigned long.
- Make a similar change to the ColdFire include.
- Add an extra parens around the page argument to the
  PD_PTABLE() macro, as is normally required.
---
 arch/m68k/include/asm/mcf_pgtable.h  | 3 +--
 arch/m68k/include/asm/sun3_pgtable.h | 4 ++--
 arch/m68k/mm/mcfmmu.c| 3 ++-
 arch/m68k/mm/motorola.c  | 4 ++--
 arch/m68k/mm/sun3mmu.c   | 2 +-
 arch/m68k/sun3/dvma.c| 2 +-
 arch/m68k/sun3x/dvma.c   | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/m68k/include/asm/mcf_pgtable.h 
b/arch/m68k/include/asm/mcf_pgtable.h
index d97fbb812f63..43e8da8465f9 100644
--- a/arch/m68k/include/asm/mcf_pgtable.h
+++ b/arch/m68k/include/asm/mcf_pgtable.h
@@ -115,7 +115,7 @@ static inline void pgd_set(pgd_t *pgdp, pmd_t *pmdp)
pgd_val(*pgdp) = virt_to_phys(pmdp);
 }
 
-#define __pte_page(pte)((unsigned long) (pte_val(pte) & PAGE_MASK))
+#define __pte_page(pte)((void *) (pte_val(pte) & PAGE_MASK))
 #define pmd_page_vaddr(pmd)((unsigned long) (pmd_val(pmd)))
 
 static inline int pte_none(pte_t pte)
@@ -134,7 +134,6 @@ static inline void pte_clear(struct mm_struct *mm, unsigned 
long addr,
pte_val(*ptep) = 0;
 }
 
-#define pte_pagenr(pte)((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
 #define pte_page(pte)  virt_to_page(__pte_page(pte))
 
 static inline int pmd_none2(pmd_t *pmd) { return !pmd_val(*pmd); }
diff --git a/arch/m68k/include/asm/sun3_pgtable.h 
b/arch/m68k/include/asm/sun3_pgtable.h
index e582b0484a55..f428f73125d5 100644
--- a/arch/m68k/include/asm/sun3_pgtable.h
+++ b/arch/m68k/include/asm/sun3_pgtable.h
@@ -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)
 {
@@ -111,7 +111,7 @@ static inline void pte_clear (struct mm_struct *mm, 
unsigned long addr, pte_t *p
 
 #define pte_page(pte)  virt_to_page(__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 70aa0979e027..278e85fcecd4 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -69,7 +69,8 @@ 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;
 
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 *)_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));
+ 

[PATCH v3 09/12] asm-generic/page.h: Make pfn accessors static inlines

2023-05-23 Thread Linus Walleij
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 change for pfn_to_virt.

Immediately define virt_to_pfn and pfn_to_virt to the static
inline after the static inline since this style of defining
functions is used for the generic helpers.

Signed-off-by: Linus Walleij 
---
 include/asm-generic/page.h | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index c0be2edeb484..9773582fd96e 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -74,8 +74,16 @@ extern unsigned long memory_end;
 #define __va(x) ((void *)((unsigned long) (x)))
 #define __pa(x) ((unsigned long) (x))
 
-#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;
+}
+#define virt_to_pfn virt_to_pfn
+static inline void *pfn_to_virt(unsigned long pfn)
+{
+   return __va(pfn) << PAGE_SHIFT;
+}
+#define pfn_to_virt pfn_to_virt
 
 #define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr))
 #define page_to_virt(page) pfn_to_virt(page_to_pfn(page))

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 10/12] ARM: mm: Make virt_to_pfn() a static inline

2023-05-23 Thread Linus Walleij
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.

Doing this is a bit intrusive: virt_to_pfn() requires
PHYS_PFN_OFFSET and PAGE_SHIFT to be defined, and this is defined in
, so this must be included *before* .

The use of macros were obscuring the unclear inclusion order here,
as the macros would eventually be resolved, but a static inline
like this cannot be compiled with unresolved macros.

The naive solution to include  at the top of
 does not work, because  sometimes
includes  at the end of itself, which would create a
confusing inclusion loop. So instead, take the approach to always
unconditionally include  at the end of 

arch/arm uses  explicitly in a lot of places,
however it turns out that if we just unconditionally include
 into  and switch all inclusions of
 to  instead, we enforce the right
order and  will always have access to the
definitions.

Put an inclusion guard in place making it impossible to include
 explicitly.

Link: 
https://lore.kernel.org/linux-mm/20220701160004.24e5ab59a55499f4c...@linux-foundation.org/
Signed-off-by: Linus Walleij 
---
Russell: the  vs  inclusion really
gave me headaches, if you have a better idea how to do it
I'm all ears!
---
 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 +-
 drivers/memory/ti-emif-sram-pm.S |  2 +-
 46 files changed, 54 insertions(+), 55 deletions(-)

diff --git a/arch/arm/common/sharpsl_param.c b/arch/arm/common/sharpsl_param.c
index 6237ede2f0c7..1ca26c063f80 100644
--- a/arch/arm/common/sharpsl_param.c
+++ b/arch/arm/common/sharpsl_param.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /*
  * Certain hardware parameters determined at the time of device manufacture,
diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
index 4f80b72372b4..1d069e558d8d 100644
--- a/arch/arm/include/asm/delay.h
+++ b/arch/arm/include/asm/delay.h
@@ -7,7 +7,7 @@
 #ifndef __ASM_ARM_DELAY_H
 #define __ASM_ARM_DELAY_H
 
-#include 
+#include 
 #include  /* HZ */
 
 /*
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 7fcdc785366c..56b08ed6cc3b 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -23,7 +23,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 /*
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 62e9df024445..ef2aa79ece5a 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -5,11 +5,16 @@
  *  Copyright (C) 2000-2002 Russell King
  *  modification for nommu, Hyok S. Choi, 2004
  *
- *  Note: this file should not be included by non-asm/.h files
+ *  Note: this file should not be included explicitly

[PATCH v3 11/12] arm64: memory: Make virt_to_pfn() a static inline

2023-05-23 Thread Linus Walleij
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  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.

Acked-by: Catalin Marinas 
Signed-off-by: Linus Walleij 
---
 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 
+
+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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 12/12] m68k/mm: Make pfn accessors static inlines

2023-05-23 Thread Linus Walleij
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 
---
 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..363aa0f9ba8a 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..af3a10973233 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 06/12] cifs: Pass a pointer to virt_to_page() in cifsglob

2023-05-23 Thread Linus Walleij
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.

Acked-by: Tom Talpey 
Signed-off-by: Linus Walleij 
---
 fs/cifs/cifsglob.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 414685c5d530..3d29a4bbbc40 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -2218,7 +2218,7 @@ static inline void cifs_sg_set_buf(struct sg_table 
*sgtable,
} while (buflen);
} else {
sg_set_page(>sgl[sgtable->nents++],
-   virt_to_page(addr), buflen, off);
+   virt_to_page((void *)addr), buflen, off);
}
 }
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 08/12] arm64: vdso: Pass (void *) to virt_to_page()

2023-05-23 Thread Linus Walleij
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.

Acked-by: Catalin Marinas 
Signed-off-by: Linus Walleij 
---
 arch/arm64/kernel/vdso.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 0119dc91abb5..d9e1355730ef 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -288,7 +288,7 @@ static int aarch32_alloc_kuser_vdso_page(void)
 
memcpy((void *)(vdso_page + 0x1000 - kuser_sz), __kuser_helper_start,
   kuser_sz);
-   aarch32_vectors_page = virt_to_page(vdso_page);
+   aarch32_vectors_page = virt_to_page((void *)vdso_page);
return 0;
 }
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 07/12] netfs: Pass a pointer to virt_to_page()

2023-05-23 Thread Linus Walleij
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 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 05/12] cifs: Pass a pointer to virt_to_page()

2023-05-23 Thread Linus Walleij
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.

Acked-by: Tom Talpey 
Signed-off-by: Linus Walleij 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v3 00/12] arch: Make virt_to_pfn into a static inline

2023-05-23 Thread Linus Walleij
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/yojdkjxc0mj2q...@shell.armlinux.org.uk/

And confirmed by Andrew Morton:
https://lore.kernel.org/linux-mm/20220701160004.24e5ab59a55499f4c...@linux-foundation.org/

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 
---
Changes in v3:
- Fix up the Coldfire changes in accordance with Geert's feedback.
- Link to v2: 
https://lore.kernel.org/r/20230503-virt-to-pfn-v6-4-rc1-v2-0-0948d38bd...@linaro.org

Changes in v2:
- Fix some "void * x" into "void *x" in generic page accessors and
  in m68k.
- Collected a few ACKs
- All build tests appear to pass!
- Added Andrew Mortin to To: line to see what he thinks
- Link to v1: 
https://lore.kernel.org/r/20230503-virt-to-pfn-v6-4-rc1-v1-0-6c4698dcf...@linaro.org

---
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 

[PATCH v3 01/12] fs/proc/kcore.c: Pass a pointer to virt_addr_valid()

2023-05-23 Thread Linus Walleij
The virt_addr_valid() should be passed a pointer, the current
code passing a long unsigned int is just exploiting the
unintentional polymorphism of these calls being implemented
as preprocessor macros.

Signed-off-by: Linus Walleij 
---
 fs/proc/kcore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 25b44b303b35..75708c66527f 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -199,7 +199,7 @@ kclist_add_private(unsigned long pfn, unsigned long 
nr_pages, void *arg)
ent->addr = (unsigned long)page_to_virt(p);
ent->size = nr_pages << PAGE_SHIFT;
 
-   if (!virt_addr_valid(ent->addr))
+   if (!virt_addr_valid((void *)ent->addr))
goto free_out;
 
/* cut not-mapped area. from ppc-32 code. */

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 12/12] m68k/mm: Make pfn accessors static inlines

2023-05-22 Thread Linus Walleij
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 
---
 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..363aa0f9ba8a 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..af3a10973233 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 07/12] netfs: Pass a pointer to virt_to_page()

2023-05-22 Thread Linus Walleij
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 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 04/12] riscv: mm: init: Pass a pointer to virt_to_page()

2023-05-22 Thread Linus Walleij
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 this in the RISCV mm init code, so we can implement
a strongly typed virt_to_pfn().

Reviewed-by: Alexandre Ghiti 
Signed-off-by: Linus Walleij 
---
 arch/riscv/mm/init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 747e5b1ef02d..2f7a7c345a6a 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -356,7 +356,7 @@ static phys_addr_t __init alloc_pte_late(uintptr_t va)
unsigned long vaddr;
 
vaddr = __get_free_page(GFP_KERNEL);
-   BUG_ON(!vaddr || !pgtable_pte_page_ctor(virt_to_page(vaddr)));
+   BUG_ON(!vaddr || !pgtable_pte_page_ctor(virt_to_page((void *)vaddr)));
 
return __pa(vaddr);
 }
@@ -439,7 +439,7 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va)
unsigned long vaddr;
 
vaddr = __get_free_page(GFP_KERNEL);
-   BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+   BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page((void *)vaddr)));
 
return __pa(vaddr);
 }

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 06/12] cifs: Pass a pointer to virt_to_page() in cifsglob

2023-05-22 Thread Linus Walleij
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.

Acked-by: Tom Talpey 
Signed-off-by: Linus Walleij 
---
 fs/cifs/cifsglob.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 414685c5d530..3d29a4bbbc40 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -2218,7 +2218,7 @@ static inline void cifs_sg_set_buf(struct sg_table 
*sgtable,
} while (buflen);
} else {
sg_set_page(>sgl[sgtable->nents++],
-   virt_to_page(addr), buflen, off);
+   virt_to_page((void *)addr), buflen, off);
}
 }
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 08/12] arm64: vdso: Pass (void *) to virt_to_page()

2023-05-22 Thread Linus Walleij
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.

Acked-by: Catalin Marinas 
Signed-off-by: Linus Walleij 
---
 arch/arm64/kernel/vdso.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 0119dc91abb5..d9e1355730ef 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -288,7 +288,7 @@ static int aarch32_alloc_kuser_vdso_page(void)
 
memcpy((void *)(vdso_page + 0x1000 - kuser_sz), __kuser_helper_start,
   kuser_sz);
-   aarch32_vectors_page = virt_to_page(vdso_page);
+   aarch32_vectors_page = virt_to_page((void *)vdso_page);
return 0;
 }
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 11/12] arm64: memory: Make virt_to_pfn() a static inline

2023-05-22 Thread Linus Walleij
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  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.

Acked-by: Catalin Marinas 
Signed-off-by: Linus Walleij 
---
 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 
+
+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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 09/12] asm-generic/page.h: Make pfn accessors static inlines

2023-05-22 Thread Linus Walleij
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 change for pfn_to_virt.

Immediately define virt_to_pfn and pfn_to_virt to the static
inline after the static inline since this style of defining
functions is used for the generic helpers.

Signed-off-by: Linus Walleij 
---
 include/asm-generic/page.h | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index c0be2edeb484..9773582fd96e 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -74,8 +74,16 @@ extern unsigned long memory_end;
 #define __va(x) ((void *)((unsigned long) (x)))
 #define __pa(x) ((unsigned long) (x))
 
-#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;
+}
+#define virt_to_pfn virt_to_pfn
+static inline void *pfn_to_virt(unsigned long pfn)
+{
+   return __va(pfn) << PAGE_SHIFT;
+}
+#define pfn_to_virt pfn_to_virt
 
 #define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr))
 #define page_to_virt(page) pfn_to_virt(page_to_pfn(page))

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 10/12] ARM: mm: Make virt_to_pfn() a static inline

2023-05-22 Thread Linus Walleij
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.

Doing this is a bit intrusive: virt_to_pfn() requires
PHYS_PFN_OFFSET and PAGE_SHIFT to be defined, and this is defined in
, so this must be included *before* .

The use of macros were obscuring the unclear inclusion order here,
as the macros would eventually be resolved, but a static inline
like this cannot be compiled with unresolved macros.

The naive solution to include  at the top of
 does not work, because  sometimes
includes  at the end of itself, which would create a
confusing inclusion loop. So instead, take the approach to always
unconditionally include  at the end of 

arch/arm uses  explicitly in a lot of places,
however it turns out that if we just unconditionally include
 into  and switch all inclusions of
 to  instead, we enforce the right
order and  will always have access to the
definitions.

Put an inclusion guard in place making it impossible to include
 explicitly.

Link: 
https://lore.kernel.org/linux-mm/20220701160004.24e5ab59a55499f4c...@linux-foundation.org/
Signed-off-by: Linus Walleij 
---
Russell: the  vs  inclusion really
gave me headaches, if you have a better idea how to do it
I'm all ears!
---
 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 +-
 drivers/memory/ti-emif-sram-pm.S |  2 +-
 46 files changed, 54 insertions(+), 55 deletions(-)

diff --git a/arch/arm/common/sharpsl_param.c b/arch/arm/common/sharpsl_param.c
index 6237ede2f0c7..1ca26c063f80 100644
--- a/arch/arm/common/sharpsl_param.c
+++ b/arch/arm/common/sharpsl_param.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /*
  * Certain hardware parameters determined at the time of device manufacture,
diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
index 4f80b72372b4..1d069e558d8d 100644
--- a/arch/arm/include/asm/delay.h
+++ b/arch/arm/include/asm/delay.h
@@ -7,7 +7,7 @@
 #ifndef __ASM_ARM_DELAY_H
 #define __ASM_ARM_DELAY_H
 
-#include 
+#include 
 #include  /* HZ */
 
 /*
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 7fcdc785366c..56b08ed6cc3b 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -23,7 +23,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 /*
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 62e9df024445..ef2aa79ece5a 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -5,11 +5,16 @@
  *  Copyright (C) 2000-2002 Russell King
  *  modification for nommu, Hyok S. Choi, 2004
  *
- *  Note: this file should not be included by non-asm/.h files
+ *  Note: this file should not be included explicitly

[PATCH v2 05/12] cifs: Pass a pointer to virt_to_page()

2023-05-22 Thread Linus Walleij
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.

Acked-by: Tom Talpey 
Signed-off-by: Linus Walleij 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 01/12] fs/proc/kcore.c: Pass a pointer to virt_addr_valid()

2023-05-22 Thread Linus Walleij
The virt_addr_valid() should be passed a pointer, the current
code passing a long unsigned int is just exploiting the
unintentional polymorphism of these calls being implemented
as preprocessor macros.

Signed-off-by: Linus Walleij 
---
 fs/proc/kcore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 25b44b303b35..75708c66527f 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -199,7 +199,7 @@ kclist_add_private(unsigned long pfn, unsigned long 
nr_pages, void *arg)
ent->addr = (unsigned long)page_to_virt(p);
ent->size = nr_pages << PAGE_SHIFT;
 
-   if (!virt_addr_valid(ent->addr))
+   if (!virt_addr_valid((void *)ent->addr))
goto free_out;
 
/* cut not-mapped area. from ppc-32 code. */

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 00/12] arch: Make virt_to_pfn into a static inline

2023-05-22 Thread Linus Walleij
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/yojdkjxc0mj2q...@shell.armlinux.org.uk/

And confirmed by Andrew Morton:
https://lore.kernel.org/linux-mm/20220701160004.24e5ab59a55499f4c...@linux-foundation.org/

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 
---
Changes in v2:
- Fix some "void * x" into "void *x" in generic page accessors and
  in m68k.
- Collected a few ACKs
- All build tests appear to pass!
- Added Andrew Mortin to To: line to see what he thinks
- Link to v1: 
https://lore.kernel.org/r/20230503-virt-to-pfn-v6-4-rc1-v1-0-6c4698dcf...@linaro.org

---
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/mcf_pgtable.h  |  4 ++--
 arch/m68k/include/asm/page_mm.h  | 11 +--
 arch/m68k/include/asm

[PATCH v2 02/12] m68k: Pass a pointer to virt_to_pfn() virt_to_page()

2023-05-22 Thread Linus Walleij
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.

The page table include  will include different
variants of the defines depending on whether you build for
classic m68k, ColdFire or Sun3, so fix all variants.

Tested-by: Geert Uytterhoeven 
Signed-off-by: Linus Walleij 
---
ChangeLog v2->v3:
- Fix the sun3 pgtable macro to not cast to unsigned long.
- Make a similar change to the ColdFire include.
ChangeLog v1->v2:
- Add an extra parens around the page argument to the
  PD_PTABLE() macro, as is normally required.
---
 arch/m68k/include/asm/mcf_pgtable.h  | 4 ++--
 arch/m68k/include/asm/sun3_pgtable.h | 4 ++--
 arch/m68k/mm/mcfmmu.c| 3 ++-
 arch/m68k/mm/motorola.c  | 4 ++--
 arch/m68k/mm/sun3mmu.c   | 2 +-
 arch/m68k/sun3/dvma.c| 2 +-
 arch/m68k/sun3x/dvma.c   | 2 +-
 7 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/m68k/include/asm/mcf_pgtable.h 
b/arch/m68k/include/asm/mcf_pgtable.h
index d97fbb812f63..f67c59336ab4 100644
--- a/arch/m68k/include/asm/mcf_pgtable.h
+++ b/arch/m68k/include/asm/mcf_pgtable.h
@@ -115,8 +115,8 @@ static inline void pgd_set(pgd_t *pgdp, pmd_t *pmdp)
pgd_val(*pgdp) = virt_to_phys(pmdp);
 }
 
-#define __pte_page(pte)((unsigned long) (pte_val(pte) & PAGE_MASK))
-#define pmd_page_vaddr(pmd)((unsigned long) (pmd_val(pmd)))
+#define __pte_page(pte)(__va (pte_val(pte) & PAGE_MASK))
+#define pmd_page_vaddr(pmd)(__va (pmd_val(pmd)))
 
 static inline int pte_none(pte_t pte)
 {
diff --git a/arch/m68k/include/asm/sun3_pgtable.h 
b/arch/m68k/include/asm/sun3_pgtable.h
index e582b0484a55..f428f73125d5 100644
--- a/arch/m68k/include/asm/sun3_pgtable.h
+++ b/arch/m68k/include/asm/sun3_pgtable.h
@@ -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)
 {
@@ -111,7 +111,7 @@ static inline void pte_clear (struct mm_struct *mm, 
unsigned long addr, pte_t *p
 
 #define pte_page(pte)  virt_to_page(__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 70aa0979e027..278e85fcecd4 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -69,7 +69,8 @@ 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;
 
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 *)_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_

[PATCH v2 03/12] ARC: init: Pass a pointer to virt_to_pfn() in init

2023-05-22 Thread Linus Walleij
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 call in arch/arc with an explicit cast.

Signed-off-by: Linus Walleij 
---
 arch/arc/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 2b89b6c53801..9f64d729c9f8 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -87,7 +87,7 @@ void __init setup_arch_memory(void)
setup_initial_init_mm(_text, _etext, _edata, _end);
 
/* first page of system - kernel .vector starts here */
-   min_low_pfn = virt_to_pfn(CONFIG_LINUX_RAM_BASE);
+   min_low_pfn = virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE);
 
/* Last usable page of low mem */
max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 02/12] m68k: Pass a pointer to virt_to_pfn() virt_to_page()

2023-05-16 Thread Linus Walleij
On Fri, May 12, 2023 at 12:26 PM Geert Uytterhoeven
 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

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 07/12] netfs: Pass a pointer to virt_to_page()

2023-05-11 Thread Linus Walleij
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 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 09/12] asm-generic/page.h: Make pfn accessors static inlines

2023-05-11 Thread Linus Walleij
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 change for pfn_to_virt.

Immediately define virt_to_pfn and pfn_to_virt to the static
inline after the static inline since this style of defining
functions is used for the generic helpers.

Signed-off-by: Linus Walleij 
---
 include/asm-generic/page.h | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index c0be2edeb484..e8ef12bb858c 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -74,8 +74,16 @@ extern unsigned long memory_end;
 #define __va(x) ((void *)((unsigned long) (x)))
 #define __pa(x) ((unsigned long) (x))
 
-#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;
+}
+#define virt_to_pfn virt_to_pfn
+static inline void * pfn_to_virt(unsigned long pfn)
+{
+   return __va(pfn) << PAGE_SHIFT;
+}
+#define pfn_to_virt pfn_to_virt
 
 #define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr))
 #define page_to_virt(page) pfn_to_virt(page_to_pfn(page))

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 11/12] arm64: memory: Make virt_to_pfn() a static inline

2023-05-11 Thread Linus Walleij
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  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 
---
 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 
+
+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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 06/12] cifs: Pass a pointer to virt_to_page() in cifsglob

2023-05-11 Thread Linus Walleij
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 
---
 fs/cifs/cifsglob.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 414685c5d530..3d29a4bbbc40 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -2218,7 +2218,7 @@ static inline void cifs_sg_set_buf(struct sg_table 
*sgtable,
} while (buflen);
} else {
sg_set_page(>sgl[sgtable->nents++],
-   virt_to_page(addr), buflen, off);
+   virt_to_page((void *)addr), buflen, off);
}
 }
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 04/12] riscv: mm: init: Pass a pointer to virt_to_page()

2023-05-11 Thread Linus Walleij
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 this in the RISCV mm init code, so we can implement
a strongly typed virt_to_pfn().

Signed-off-by: Linus Walleij 
---
 arch/riscv/mm/init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 747e5b1ef02d..2f7a7c345a6a 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -356,7 +356,7 @@ static phys_addr_t __init alloc_pte_late(uintptr_t va)
unsigned long vaddr;
 
vaddr = __get_free_page(GFP_KERNEL);
-   BUG_ON(!vaddr || !pgtable_pte_page_ctor(virt_to_page(vaddr)));
+   BUG_ON(!vaddr || !pgtable_pte_page_ctor(virt_to_page((void *)vaddr)));
 
return __pa(vaddr);
 }
@@ -439,7 +439,7 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va)
unsigned long vaddr;
 
vaddr = __get_free_page(GFP_KERNEL);
-   BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+   BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page((void *)vaddr)));
 
return __pa(vaddr);
 }

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 05/12] cifs: Pass a pointer to virt_to_page()

2023-05-11 Thread Linus Walleij
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 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 02/12] m68k: Pass a pointer to virt_to_pfn() virt_to_page()

2023-05-11 Thread Linus Walleij
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 
---
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 *)_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= (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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 10/12] ARM: mm: Make virt_to_pfn() a static inline

2023-05-11 Thread Linus Walleij
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.

Doing this is a bit intrusive: virt_to_pfn() requires
PHYS_PFN_OFFSET and PAGE_SHIFT to be defined, and this is defined in
, so this must be included *before* .

The use of macros were obscuring the unclear inclusion order here,
as the macros would eventually be resolved, but a static inline
like this cannot be compiled with unresolved macros.

The naive solution to include  at the top of
 does not work, because  sometimes
includes  at the end of itself, which would create a
confusing inclusion loop. So instead, take the approach to always
unconditionally include  at the end of 

arch/arm uses  explicitly in a lot of places,
however it turns out that if we just unconditionally include
 into  and switch all inclusions of
 to  instead, we enforce the right
order and  will always have access to the
definitions.

Put an inclusion guard in place making it impossible to include
 explicitly.

Link: 
https://lore.kernel.org/linux-mm/20220701160004.24e5ab59a55499f4c...@linux-foundation.org/
Signed-off-by: Linus Walleij 
---
Russell: the  vs  inclusion really
gave me headaches, if you have a better idea how to do it
I'm all ears!
---
 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 +-
 drivers/memory/ti-emif-sram-pm.S |  2 +-
 46 files changed, 54 insertions(+), 55 deletions(-)

diff --git a/arch/arm/common/sharpsl_param.c b/arch/arm/common/sharpsl_param.c
index 6237ede2f0c7..1ca26c063f80 100644
--- a/arch/arm/common/sharpsl_param.c
+++ b/arch/arm/common/sharpsl_param.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /*
  * Certain hardware parameters determined at the time of device manufacture,
diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
index 4f80b72372b4..1d069e558d8d 100644
--- a/arch/arm/include/asm/delay.h
+++ b/arch/arm/include/asm/delay.h
@@ -7,7 +7,7 @@
 #ifndef __ASM_ARM_DELAY_H
 #define __ASM_ARM_DELAY_H
 
-#include 
+#include 
 #include  /* HZ */
 
 /*
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 7fcdc785366c..56b08ed6cc3b 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -23,7 +23,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 /*
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 62e9df024445..ef2aa79ece5a 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -5,11 +5,16 @@
  *  Copyright (C) 2000-2002 Russell King
  *  modification for nommu, Hyok S. Choi, 2004
  *
- *  Note: this file should not be included by non-asm/.h files
+ *  Note: this file should not be included explicitly

[PATCH 08/12] arm64: vdso: Pass (void *) to virt_to_page()

2023-05-11 Thread Linus Walleij
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 
---
 arch/arm64/kernel/vdso.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 0119dc91abb5..d9e1355730ef 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -288,7 +288,7 @@ static int aarch32_alloc_kuser_vdso_page(void)
 
memcpy((void *)(vdso_page + 0x1000 - kuser_sz), __kuser_helper_start,
   kuser_sz);
-   aarch32_vectors_page = virt_to_page(vdso_page);
+   aarch32_vectors_page = virt_to_page((void *)vdso_page);
return 0;
 }
 

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 12/12] m68k/mm: Make pfn accessors static inlines

2023-05-11 Thread Linus Walleij
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 
---
 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


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 01/12] fs/proc/kcore.c: Pass a pointer to virt_addr_valid()

2023-05-11 Thread Linus Walleij
The virt_addr_valid() should be passed a pointer, the current
code passing a long unsigned int is just exploiting the
unintentional polymorphism of these calls being implemented
as preprocessor macros.

Signed-off-by: Linus Walleij 
---
 fs/proc/kcore.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 25b44b303b35..75708c66527f 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -199,7 +199,7 @@ kclist_add_private(unsigned long pfn, unsigned long 
nr_pages, void *arg)
ent->addr = (unsigned long)page_to_virt(p);
ent->size = nr_pages << PAGE_SHIFT;
 
-   if (!virt_addr_valid(ent->addr))
+   if (!virt_addr_valid((void *)ent->addr))
goto free_out;
 
/* cut not-mapped area. from ppc-32 code. */

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 03/12] ARC: init: Pass a pointer to virt_to_pfn() in init

2023-05-11 Thread Linus Walleij
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 call in arch/arc with an explicit cast.

Signed-off-by: Linus Walleij 
---
 arch/arc/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 2b89b6c53801..9f64d729c9f8 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -87,7 +87,7 @@ void __init setup_arch_memory(void)
setup_initial_init_mm(_text, _etext, _edata, _end);
 
/* first page of system - kernel .vector starts here */
-   min_low_pfn = virt_to_pfn(CONFIG_LINUX_RAM_BASE);
+   min_low_pfn = virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE);
 
/* Last usable page of low mem */
max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);

-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 17/21] ARM: dma-mapping: use arch_sync_dma_for_{device,cpu}() internally

2023-03-31 Thread Linus Walleij
On Mon, Mar 27, 2023 at 2:16 PM Arnd Bergmann  wrote:

> From: Arnd Bergmann 
>
> The arm specific iommu code in dma-mapping.c uses the page+offset based
> __dma_page_cpu_to_dev()/__dma_page_dev_to_cpu() helpers in place of the
> phys_addr_t based arch_sync_dma_for_device()/arch_sync_dma_for_cpu()
> wrappers around the.

Broken sentence?

> In order to be able to move the latter part set of functions into
> common code, change the iommu implementation to use them directly
> and remove the internal ones as a separate interface.
>
> As page+offset and phys_address are equivalent, but are used in
> different parts of the code here, this allows removing some of
> the conversion but adds them elsewhere.
>
> Signed-off-by: Arnd Bergmann 

Looks good to me, took me some time to verify and understand
the open-coded version of PFN_UP() and this refactoring alone
makes the patch highly valuable.
Reviewed-by: Linus Walleij 

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 15/21] ARM: dma-mapping: always invalidate WT caches before DMA

2023-03-31 Thread Linus Walleij
On Mon, Mar 27, 2023 at 2:16 PM Arnd Bergmann  wrote:

> From: Arnd Bergmann 
>
> Most ARM CPUs can have write-back caches and that require
> cache management to be done in the dma_sync_*_for_device()
> operation. This is typically done in both writeback and
> writethrough mode.
>
> The cache-v4.S (arm720/740/7tdmi/9tdmi) and cache-v4wt.S
> (arm920t, arm940t) implementations are the exception here,
> and only do the cache management after the DMA is complete,
> in the dma_sync_*_for_cpu() operation.
>
> Change this for consistency with the other platforms. This
> should have no user visible effect.
>
> Signed-off-by: Arnd Bergmann 

Looks good to me.
Reviewed-by: Linus Walleij 

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 18/21] ARM: drop SMP support for ARM11MPCore

2023-03-30 Thread Linus Walleij
On Mon, Mar 27, 2023 at 2:16 PM Arnd Bergmann  wrote:

> From: Arnd Bergmann 
>
> The cache management operations for noncoherent DMA on ARMv6 work
> in two different ways:
>
>  * When CONFIG_DMA_CACHE_RWFO is set, speculative prefetches on in-flight
>DMA buffers lead to data corruption when the prefetched data is written
>back on top of data from the device.
>
>  * When CONFIG_DMA_CACHE_RWFO is disabled, a cache flush on one CPU
>is not seen by the other core(s), leading to inconsistent contents
>accross the system.
>
> As a consequence, neither configuration is actually safe to use in a
> general-purpose kernel that is used on both MPCore systems and ARM1176
> with prefetching enabled.
>
> We could add further workarounds to make the behavior more dynamic based
> on the system, but realistically, there are close to zero remaining
> users on any ARM11MPCore anyway, and nobody seems too interested in it,
> compared to the more popular ARM1176 used in BMC2835 and AST2500.
>
> The Oxnas platform has some minimal support in OpenWRT, but most of the
> drivers and dts files never made it into the mainline kernel, while the
> Arm Versatile/Realview platform mainly serves as a reference system but
> is not necessary to be kept working once all other ARM11MPCore are gone.
>
> Take the easy way out here and drop support for multiprocessing on
> ARMv6, along with the CONFIG_DMA_CACHE_RWFO option and the cache
> management implementation for it. This also helps with other ARMv6
> issues, but for the moment leaves the ability to build a kernel that
> can run on both ARMv7 SMP and single-processor ARMv6, which we probably
> want to stop supporting as well, but not as part of this series.
>
> Cc: Neil Armstrong 
> Cc: Daniel Golle 
> Cc: Linus Walleij 
> Cc: linux-ox...@groups.io
> Signed-off-by: Arnd Bergmann 

Yeah, we discussed this earlier, let's just drop it. Not worth the effort.
Acked-by: Linus Walleij 

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] ARC: init: Pass a pointer to virt_to_pfn() in init

2023-03-23 Thread Linus Walleij
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 call in arch/arc with an explicit cast.

Signed-off-by: Linus Walleij 
---
 arch/arc/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index ce4e939a7f07..d8688f61c61b 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -92,7 +92,7 @@ void __init setup_arch_memory(void)
setup_initial_init_mm(_text, _etext, _edata, _end);
 
/* first page of system - kernel .vector starts here */
-   min_low_pfn = virt_to_pfn(CONFIG_LINUX_RAM_BASE);
+   min_low_pfn = virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE);
 
/* Last usable page of low mem */
max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);
-- 
2.34.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 4/7] dt-bindings: chosen: Add clocksource and clockevent selection

2019-09-12 Thread Linus Walleij
On Wed, Sep 11, 2019 at 8:18 AM  wrote:
> [Me]
> > In that case why not just pick the first one you find as clocksource
> > and the second one as clock event?

> That was also my proposal for the driver I'm sending this series for (see
> [1]) but it has been proposed to implement a mechanism similar to this one
> in this series (see [2] and [3]).

OK I am not going to challenge the clock source maintainers on this,
so if that is what they want then that is what they should get.
It's fine to convert the Integrator driver too!

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 4/7] dt-bindings: chosen: Add clocksource and clockevent selection

2019-09-10 Thread Linus Walleij
On Tue, Sep 10, 2019 at 4:11 PM Alexandre Belloni
 wrote:
> On 10/09/2019 16:08:26+0100, Sudeep Holla wrote:
> > On Tue, Sep 10, 2019 at 02:51:50PM +, claudiu.bez...@microchip.com 
> > wrote:

> > In that case, why can't we identify capability that with the compatibles
> > for this timer IP ?
> >
> > IOW, I don't like the proposal as it's hardware limitation.
>
> To be clear, bot timers are exactly the same but can't be clocksource
> and clockevent at the same time. Why would we have different compatibles
> for the exact same IP?

In that case why not just pick the first one you find as clocksource
and the second one as clock event? As they all come to the
same timer of init function two simple local state variables can
solve that:

static bool registered_clocksource;
static bool registered_clockevent;

probe(timer) {
   if (!registered_clocksource) {
   register_clocksource(timer);
   registrered_clocksource = true;
   return;
   }
   if (!registered_clockevent) {
   register_clockevent(timer);
   registered_clockevent = true;
   return;
   }
   pr_info("surplus timer %p\n", timer);
}

Clocksource and clockevent are natural singletons so there is
no need to handle more than one of each in a driver for identical
hardware.

With the Integrator AP timer there is a real reason to select one over
the other but as I replied to that patch it is pretty easy to just identify
which block has this limitation by simply commenting out the IRQ
line for it from the device tree.

Maybe there is something about this I don't understand.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 7/7] clocksource/drivers/integrator-ap: parse the chosen node

2019-09-10 Thread Linus Walleij
On Tue, Sep 10, 2019 at 2:50 PM Claudiu Beznea
 wrote:
> From: Alexandre Belloni 
>
> The driver currently uses aliases to know whether the timer is the
> clocksource or the clockevent.

OK maybe that wasn't the most elegant solution.

> Add the /chosen/linux,clocksource and
> /chosen/linux,clockevent parsing while keeping backward compatibility.

This is not how I would solve this today.

I would simply remove/comment out the IRQ from the timer
that cannot be used for clockevent from the device tree
(apparently it doesn't work anyway), and make the code only
pick a timer with a valid interrupt assigned as clock event,
while a timer without interrupt can be used for clock source.

This has the upside of not needing any special aliases or
chosen things.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v4 1/2] GPIO: add single-register GPIO via CREG driver

2018-10-10 Thread Linus Walleij
On Fri, Sep 28, 2018 at 3:15 PM Eugeniy Paltsev
 wrote:

> Add single-register MMIO GPIO driver for complex cases where
> only several fields in register belong to GPIO lines and each GPIO
> line owns a field with different length and on/off value.
>
> Such CREG GPIOs are used in Synopsys AXS10x and HSDK boards.
>
> Signed-off-by: Eugeniy Paltsev 
> ---
> Changes v3->v4:
>  * Cleanup 'include' section.
>  * Get rid of 'of_mm_gpio_chip' using.
>  * Get rid of custom 'creg_gpio_xlate' function.
>  * Get rid of dummy 'creg_gpio_get_direction' function.
>  * Small fixies.

Patch applied.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v4 2/2] dt-bindings: Document the Synopsys GPIO via CREG bindings

2018-10-10 Thread Linus Walleij
On Fri, Sep 28, 2018 at 3:15 PM Eugeniy Paltsev
 wrote:

> This patch adds documentation of device tree bindings for the Synopsys
> GPIO via CREG driver.
>
> Reviewed-by: Rob Herring 
> Reviewed-by: Linus Walleij 
> Signed-off-by: Eugeniy Paltsev 
> ---
> Changes v3->v4:
>  * Fix #gpio-cells description as driver is used generic GPIO binding.

Patch applied.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v2 2/2] dt-bindings: Document the Synopsys GPIO via CREG bindings

2018-09-05 Thread Linus Walleij
On Thu, Aug 30, 2018 at 8:16 PM Eugeniy Paltsev
 wrote:
> On Thu, 2018-08-30 at 10:43 +0200, Linus Walleij wrote:

> > > +- snps,bit-per-line: Number of bits per each gpio line (see picture).
> > > +  Array the size of "snps,ngpios"
> > > +- snps,shift: Shift (in bits) of the each GPIO field from the previous 
> > > one in
> > > +  register (see picture). Array the size of "snps,ngpios"
> > > +- snps,on-val: Value should be set in corresponding field to set
> > > +  output to "1" (see picture). Array the size of "snps,ngpios"
> > > +- snps,off-val: Value should be set in corresponding field to set
> > > +  output to "0" (see picture). Array the size of "snps,ngpios"
> >
> > Move this into a lookup table in the driver instead, and match
> > the lookup table to the compatible string. The format of the
> > register is known for a certain compatible, right?
>
> Actually I really don't want to hardcode this values into lookup table as I 
> going to use
> this driver on 3 already upstreamed platforms and at least one upcoming.
>
> They all have such CREG pseudo-'GPIOs' differently mapped with different IO 
> lines number,
> different enable/disable value, etc...

So each of them will have their own compatible, and table entry,
so what's the problem? If they don't have their own compatible,
they should be added, because they are per definition not compatible
if they need different values into different parts of the register.

> Is it really a problem to have this values configured via device tree?

Yes because the DT maintainers do not like that we use the device
tree as a data dumping ground.

pinctrl-single.c and some other real big pin controllers are dumping
data into the device tree, but it is a dubious practice. Two wrongs
doesn't make one right.

> If we read them from DT we are able to use this generic and configurable 
> driver to handle
> both existing and upcoming platforms without the need of patching the driver 
> on every new
> platform upstreaming.

But you will have to patch the driver to add a new compatible for each
platform you're upstreaming anyway, so this isn't going to make things
easier.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v2 2/2] dt-bindings: Document the Synopsys GPIO via CREG bindings

2018-08-30 Thread Linus Walleij
On Tue, Aug 28, 2018 at 1:27 PM Eugeniy Paltsev
 wrote:

> +++ b/Documentation/devicetree/bindings/gpio/snps,creg-gpio.txt
> @@ -0,0 +1,49 @@
> +GPIO via CREG (Control REGisers) driver

Speling

Also should be "Synopsys GPIO via CREG" as this is likely just
for Synopsys and not general purpose.

> +This is is single-register MMIO GPIO driver to control such strangely mapped
> +outputs:
> +
> +31118 75 0   < bit number
> +|  || || |
> +[   not used   | gpio-1 | shift-1 | gpio-0 | shift-0 ]   < 32 bit MMIO 
> register
> +   ^  ^
> +   |  |
> +   |   write 0x2 == set output to "1" (on)
> +   |   write 0x3 == set output to "0" (off)
> +   |
> +write 0x1 == set output to "1" (on)
> +write 0x4 == set output to "0" (off)

Move this documentation into the driver instead.

> +Required properties:
> +- compatible : "snps,creg-gpio"
> +- reg : Exactly one register range with length 0x4.
> +- #gpio-cells : Should be one - the pin number.
> +- gpio-controller : Marks the device node as a GPIO controller.

OK

> +- snps,ngpios: Number of GPIO pins.

Use the existing ngpios attribute for this, see gpio.txt

> +- snps,bit-per-line: Number of bits per each gpio line (see picture).
> +  Array the size of "snps,ngpios"
> +- snps,shift: Shift (in bits) of the each GPIO field from the previous one in
> +  register (see picture). Array the size of "snps,ngpios"
> +- snps,on-val: Value should be set in corresponding field to set
> +  output to "1" (see picture). Array the size of "snps,ngpios"
> +- snps,off-val: Value should be set in corresponding field to set
> +  output to "0" (see picture). Array the size of "snps,ngpios"

Move this into a lookup table in the driver instead, and match
the lookup table to the compatible string. The format of the
register is known for a certain compatible, right?

> +Optional properties:
> +- snps,default-val: default output field values. Array the size of 
> "snps,ngpios"

Default values for different lines can be achieved by hogs
if it's OK to tie them up perpetually, else work on creating generic
inialization values in gpio.txt and implement that in
gpiolib-of.c for everyone. This discussion comes up from time
to time.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 2/2] gpio: tb10x: Use GENERIC_GPIO

2018-08-06 Thread Linus Walleij
Instead of open coding logic for reading and writing GPIO lines,
use the generic GPIO library. Also switch to using the spinlock
from the generic GPIO to protect the registers.

Cc: linux-snps-arc@lists.infradead.org
Cc: Christian Ruppert 
Signed-off-by: Linus Walleij 
---
 drivers/gpio/Kconfig  |  1 +
 drivers/gpio/gpio-tb10x.c | 96 ---
 2 files changed, 31 insertions(+), 66 deletions(-)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7429b30e61b0..d351548d0257 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -480,6 +480,7 @@ config GPIO_SYSCON
 
 config GPIO_TB10X
bool
+   select GPIO_GENERIC
select GENERIC_IRQ_CHIP
select OF_GPIO
 
diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c
index 422b0ac5a9de..d5e5d19f4c0a 100644
--- a/drivers/gpio/gpio-tb10x.c
+++ b/drivers/gpio/gpio-tb10x.c
@@ -45,14 +45,12 @@
 
 
 /**
- * @spinlock: used for atomic read/modify/write of registers
  * @base: register base address
  * @domain: IRQ domain of GPIO generated interrupts managed by this controller
  * @irq: Interrupt line of parent interrupt controller
  * @gc: gpio_chip structure associated to this GPIO controller
  */
 struct tb10x_gpio {
-   spinlock_t spinlock;
void __iomem *base;
struct irq_domain *domain;
int irq;
@@ -76,60 +74,14 @@ static inline void tb10x_set_bits(struct tb10x_gpio *gpio, 
unsigned int offs,
u32 r;
unsigned long flags;
 
-   spin_lock_irqsave(>spinlock, flags);
+   spin_lock_irqsave(>gc.bgpio_lock, flags);
 
r = tb10x_reg_read(gpio, offs);
r = (r & ~mask) | (val & mask);
 
tb10x_reg_write(gpio, offs, r);
 
-   spin_unlock_irqrestore(>spinlock, flags);
-}
-
-static int tb10x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
-{
-   struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip);
-   int mask = BIT(offset);
-   int val = TB10X_GPIO_DIR_IN << offset;
-
-   tb10x_set_bits(tb10x_gpio, OFFSET_TO_REG_DDR, mask, val);
-
-   return 0;
-}
-
-static int tb10x_gpio_get(struct gpio_chip *chip, unsigned offset)
-{
-   struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip);
-   int val;
-
-   val = tb10x_reg_read(tb10x_gpio, OFFSET_TO_REG_DATA);
-
-   if (val & BIT(offset))
-   return 1;
-   else
-   return 0;
-}
-
-static void tb10x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
-{
-   struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip);
-   int mask = BIT(offset);
-   int val = value << offset;
-
-   tb10x_set_bits(tb10x_gpio, OFFSET_TO_REG_DATA, mask, val);
-}
-
-static int tb10x_gpio_direction_out(struct gpio_chip *chip,
-   unsigned offset, int value)
-{
-   struct tb10x_gpio *tb10x_gpio = gpiochip_get_data(chip);
-   int mask = BIT(offset);
-   int val = TB10X_GPIO_DIR_OUT << offset;
-
-   tb10x_gpio_set(chip, offset, value);
-   tb10x_set_bits(tb10x_gpio, OFFSET_TO_REG_DDR, mask, val);
-
-   return 0;
+   spin_unlock_irqrestore(>gc.bgpio_lock, flags);
 }
 
 static int tb10x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
@@ -184,8 +136,6 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
if (tb10x_gpio == NULL)
return -ENOMEM;
 
-   spin_lock_init(_gpio->spinlock);
-
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
tb10x_gpio->base = devm_ioremap_resource(dev, mem);
if (IS_ERR(tb10x_gpio->base))
@@ -196,20 +146,34 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
if (!tb10x_gpio->gc.label)
return -ENOMEM;
 
-   tb10x_gpio->gc.parent   = >dev;
-   tb10x_gpio->gc.owner= THIS_MODULE;
-   tb10x_gpio->gc.direction_input  = tb10x_gpio_direction_in;
-   tb10x_gpio->gc.get  = tb10x_gpio_get;
-   tb10x_gpio->gc.direction_output = tb10x_gpio_direction_out;
-   tb10x_gpio->gc.set  = tb10x_gpio_set;
-   tb10x_gpio->gc.request  = gpiochip_generic_request;
-   tb10x_gpio->gc.free = gpiochip_generic_free;
-   tb10x_gpio->gc.base = -1;
-   tb10x_gpio->gc.ngpio= ngpio;
-   tb10x_gpio->gc.can_sleep= false;
-
-
-   ret = devm_gpiochip_add_data(>dev, _gpio->gc, tb10x_gpio);
+   /*
+* Initialize generic GPIO with one single register for reading and 
setting
+* the lines, no special set or clear registers and a data direction 
register
+* wher 1 means "output".
+*/
+   ret = bgpio_init(_gpio->gc, dev, 4,
+tb10x_gpio->base + OFFSET_TO_REG_DATA,
+NULL,
+NULL,
+t

[PATCH 1/2] gpio: tb10x: Create local helper variables

2018-08-06 Thread Linus Walleij
Create a local struct device *dev helper variable to make the code
easier to read.

Most GPIO drivers use "np" (node pointer) rather than "dn" (device node)
to point to the device tree node. Let's follow this convention.

Cc: linux-snps-arc@lists.infradead.org
Cc: Christian Ruppert 
Signed-off-by: Linus Walleij 
---
 drivers/gpio/gpio-tb10x.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c
index a12cd0b5c972..422b0ac5a9de 100644
--- a/drivers/gpio/gpio-tb10x.c
+++ b/drivers/gpio/gpio-tb10x.c
@@ -169,29 +169,30 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
 {
struct tb10x_gpio *tb10x_gpio;
struct resource *mem;
-   struct device_node *dn = pdev->dev.of_node;
+   struct device *dev = >dev;
+   struct device_node *np = dev->of_node;
int ret = -EBUSY;
u32 ngpio;
 
-   if (!dn)
+   if (!np)
return -EINVAL;
 
-   if (of_property_read_u32(dn, "abilis,ngpio", ))
+   if (of_property_read_u32(np, "abilis,ngpio", ))
return -EINVAL;
 
-   tb10x_gpio = devm_kzalloc(>dev, sizeof(*tb10x_gpio), GFP_KERNEL);
+   tb10x_gpio = devm_kzalloc(dev, sizeof(*tb10x_gpio), GFP_KERNEL);
if (tb10x_gpio == NULL)
return -ENOMEM;
 
spin_lock_init(_gpio->spinlock);
 
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   tb10x_gpio->base = devm_ioremap_resource(>dev, mem);
+   tb10x_gpio->base = devm_ioremap_resource(dev, mem);
if (IS_ERR(tb10x_gpio->base))
return PTR_ERR(tb10x_gpio->base);
 
-   tb10x_gpio->gc.label=
-   devm_kasprintf(>dev, GFP_KERNEL, "%pOF", 
pdev->dev.of_node);
+   tb10x_gpio->gc.label =
+   devm_kasprintf(dev, GFP_KERNEL, "%pOF", pdev->dev.of_node);
if (!tb10x_gpio->gc.label)
return -ENOMEM;
 
@@ -210,31 +211,31 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
 
ret = devm_gpiochip_add_data(>dev, _gpio->gc, tb10x_gpio);
if (ret < 0) {
-   dev_err(>dev, "Could not add gpiochip.\n");
+   dev_err(dev, "Could not add gpiochip.\n");
return ret;
}
 
platform_set_drvdata(pdev, tb10x_gpio);
 
-   if (of_find_property(dn, "interrupt-controller", NULL)) {
+   if (of_find_property(np, "interrupt-controller", NULL)) {
struct irq_chip_generic *gc;
 
ret = platform_get_irq(pdev, 0);
if (ret < 0) {
-   dev_err(>dev, "No interrupt specified.\n");
+   dev_err(dev, "No interrupt specified.\n");
return ret;
}
 
tb10x_gpio->gc.to_irq   = tb10x_gpio_to_irq;
tb10x_gpio->irq = ret;
 
-   ret = devm_request_irq(>dev, ret, tb10x_gpio_irq_cascade,
+   ret = devm_request_irq(dev, ret, tb10x_gpio_irq_cascade,
IRQF_TRIGGER_NONE | IRQF_SHARED,
-   dev_name(>dev), tb10x_gpio);
+   dev_name(dev), tb10x_gpio);
if (ret != 0)
return ret;
 
-   tb10x_gpio->domain = irq_domain_add_linear(dn,
+   tb10x_gpio->domain = irq_domain_add_linear(np,
tb10x_gpio->gc.ngpio,
_generic_chip_ops, NULL);
if (!tb10x_gpio->domain) {
-- 
2.17.0


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] gpio: tb10x: Use the right include

2018-08-06 Thread Linus Walleij
This driver includes the legacy  and
 but all it needs is really .

Cc: linux-snps-arc@lists.infradead.org
Cc: Christian Ruppert 
Signed-off-by: Linus Walleij 
---
 drivers/gpio/gpio-tb10x.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c
index ac6f2a9841e5..a12cd0b5c972 100644
--- a/drivers/gpio/gpio-tb10x.c
+++ b/drivers/gpio/gpio-tb10x.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -30,7 +30,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.17.0


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 3/7] clocksource: Rename clocksource_probe

2017-05-28 Thread Linus Walleij
On Sat, May 27, 2017 at 11:58 AM, Daniel Lezcano
<daniel.lezc...@linaro.org> wrote:

> The function name is now renamed to 'timer_probe' for consistency with
> the CLOCKSOURCE_OF_DECLARE => TIMER_OF_DECLARE change.
>
> Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org>

Reviewed-by: Linus Walleij <linus.wall...@linaro.org>

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 2/7] clocksource: Rename CLOCKSOURCE_OF_DECLARE

2017-05-28 Thread Linus Walleij
On Sat, May 27, 2017 at 11:58 AM, Daniel Lezcano
<daniel.lezc...@linaro.org> wrote:

> The CLOCKSOUCE_OF_DECLARE macro is used widely for the timers to declare the
> clocksource at early stage. However, this macro is also used to initialize
> the clockevent if any, or the clockevent only.
>
> It was originally suggested to declare another macro to initialize a
> clockevent, so in order to separate the two entities even they belong to the
> same IP. This was not accepted because of the impact on the DT where splitting
> a clocksource/clockevent definition does not make sense as it is a Linux
> concept not a hardware description.
>
> On the other side, the clocksource has not interrupt declared while the
> clockevent has, so it is easy from the driver to know if the description is
> for a clockevent or a clocksource, IOW it could be implemented at the driver
> level.
>
> So instead of dealing with a named clocksource macro, let's use a more generic
> one: TIMER_OF_DECLARE.
>
> The patch has not functional changes.
>
> Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org>'

This makes the macro make sense and I had this idea one time too.
Awesome.
Reviewed-by: Linus Walleij <linus.wall...@linaro.org>

Yours,
Linus Walleij

> ---
>  arch/arm/kernel/smp_twd.c |  6 +++---
>  arch/microblaze/kernel/timer.c|  2 +-
>  arch/mips/ralink/cevt-rt3352.c|  2 +-
>  arch/nios2/kernel/time.c  |  2 +-
>  drivers/clocksource/arc_timer.c   |  6 +++---
>  drivers/clocksource/arm_arch_timer.c  |  6 +++---
>  drivers/clocksource/arm_global_timer.c|  2 +-
>  drivers/clocksource/armv7m_systick.c  |  2 +-
>  drivers/clocksource/asm9260_timer.c   |  2 +-
>  drivers/clocksource/bcm2835_timer.c   |  2 +-
>  drivers/clocksource/bcm_kona_timer.c  |  4 ++--
>  drivers/clocksource/cadence_ttc_timer.c   |  2 +-
>  drivers/clocksource/clksrc-dbx500-prcmu.c |  2 +-
>  drivers/clocksource/clksrc_st_lpc.c   |  2 +-
>  drivers/clocksource/clps711x-timer.c  |  2 +-
>  drivers/clocksource/dw_apb_timer_of.c |  8 
>  drivers/clocksource/exynos_mct.c  |  4 ++--
>  drivers/clocksource/fsl_ftm_timer.c   |  2 +-
>  drivers/clocksource/h8300_timer16.c   |  2 +-
>  drivers/clocksource/h8300_timer8.c|  2 +-
>  drivers/clocksource/h8300_tpu.c   |  2 +-
>  drivers/clocksource/jcore-pit.c   |  2 +-
>  drivers/clocksource/meson6_timer.c|  2 +-
>  drivers/clocksource/mips-gic-timer.c  |  2 +-
>  drivers/clocksource/mps2-timer.c  |  2 +-
>  drivers/clocksource/mtk_timer.c   |  2 +-
>  drivers/clocksource/mxs_timer.c   |  2 +-
>  drivers/clocksource/nomadik-mtu.c |  2 +-
>  drivers/clocksource/pxa_timer.c   |  2 +-
>  drivers/clocksource/qcom-timer.c  |  4 ++--
>  drivers/clocksource/renesas-ostm.c|  2 +-
>  drivers/clocksource/rockchip_timer.c  |  4 ++--
>  drivers/clocksource/samsung_pwm_timer.c   |  8 
>  drivers/clocksource/sun4i_timer.c |  2 +-
>  drivers/clocksource/tango_xtal.c  |  2 +-
>  drivers/clocksource/tegra20_timer.c   |  4 ++--
>  drivers/clocksource/time-armada-370-xp.c  |  6 +++---
>  drivers/clocksource/time-efm32.c  |  4 ++--
>  drivers/clocksource/time-lpc32xx.c|  2 +-
>  drivers/clocksource/time-orion.c  |  2 +-
>  drivers/clocksource/time-pistachio.c  |  2 +-
>  drivers/clocksource/timer-atlas7.c|  2 +-
>  drivers/clocksource/timer-atmel-pit.c |  2 +-
>  drivers/clocksource/timer-atmel-st.c  |  2 +-
>  drivers/clocksource/timer-digicolor.c |  2 +-
>  drivers/clocksource/timer-fttmr010.c  | 10 +-
>  drivers/clocksource/timer-imx-gpt.c   | 24 
>  drivers/clocksource/timer-integrator-ap.c |  2 +-
>  drivers/clocksource/timer-keystone.c  |  2 +-
>  drivers/clocksource/timer-nps.c   |  6 +++---
>  drivers/clocksource/timer-oxnas-rps.c |  4 ++--
>  drivers/clocksource/timer-prima2.c|  2 +-
>  drivers/clocksource/timer-sp804.c |  4 ++--
>  drivers/clocksource/timer-stm32.c |  2 +-
>  drivers/clocksource/timer-sun5i.c |  4 ++--
>  drivers/clocksource/timer-ti-32k.c|  2 +-
>  drivers/clocksource/timer-u300.c  |  2 +-
>  drivers/clocksource/versatile.c   |  4 ++--
>  drivers/clocksource/vf_pit_timer.c|  2 +-
>  drivers/clocksource/vt8500_timer.c|  2 +-
>  drivers/clocksource/zevio-timer.c |  2 +-
>  include/linux/clocksource.h   |  2 +-
>  62 files changed, 103 insertions(+), 103 deletions(-)
>
> diff --git a/arch/arm/kernel/smp_twd.c

Re: [PATCH 02/23] arc: select GPIOLIB directly

2016-04-26 Thread Linus Walleij
On Fri, Apr 22, 2016 at 7:16 AM, Vineet Gupta
<vineet.gup...@synopsys.com> wrote:
> On Wednesday 20 April 2016 02:28 PM, Linus Walleij wrote:
>> Instead of indirectly selecting GPIOLIB via the
>> ARCH_REQUIRE_GPIOLIB symbol, just select GPIOLIB.
>>
>> Cc: Michael Büsch <m...@bues.ch>
>> Cc: Vineet Gupta <vgu...@synopsys.com>
>> Cc: linux-snps-arc@lists.infradead.org
>> Signed-off-by: Linus Walleij <linus.wall...@linaro.org>
>> ---
>> Various arch maintainers:
>
> It would be nice to get the cover latter as well to get more context. The 
> whole
> series didn't seem to be CCed to lkml either.

Sorry for that.

> Anyhow I found some reference on
> linux-gpio patchworks and seems like a nice cleanup.
>
> So for arch/arc/*
>
> Acked-by: Vineet Gupta <vg...@synopsys.com>

Thanks, patch applied to the GPIO tree with your ACK.

Yours,
Linus Walleij

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

[PATCH 02/23] arc: select GPIOLIB directly

2016-04-20 Thread Linus Walleij
Instead of indirectly selecting GPIOLIB via the
ARCH_REQUIRE_GPIOLIB symbol, just select GPIOLIB.

Cc: Michael Büsch <m...@bues.ch>
Cc: Vineet Gupta <vgu...@synopsys.com>
Cc: linux-snps-arc@lists.infradead.org
Signed-off-by: Linus Walleij <linus.wall...@linaro.org>
---
Various arch maintainers:

either ACK this and I will merge it into the GPIO tree for v4.7
anticipating no clashes, or you wait until I have the enabling patch
upstream (patch 1 in this series, removing deps on
ARCH_[WANTS_OPTIONAL|REQUIRES]_GPIOLIB), and you will be able to
merge it to your arch trees yourselves for late v4.7
(post GPIO tree merge) or for v4.8.

You can also ask me for an immutable branch if you prefer that, I
will put the enabling patch on a branch and the patch for your arch
on top and ask you to pull it.

Select your option from the menu, silence probably means I will
merge it to the GPIO tree. Unless you are X86 or ARM in which case
I will be cautious.
---
 arch/arc/plat-axs10x/Kconfig | 2 +-
 arch/arc/plat-tb10x/Kconfig  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arc/plat-axs10x/Kconfig b/arch/arc/plat-axs10x/Kconfig
index 426ac4b8bb39..c54d1ae57fe0 100644
--- a/arch/arc/plat-axs10x/Kconfig
+++ b/arch/arc/plat-axs10x/Kconfig
@@ -13,7 +13,7 @@ menuconfig ARC_PLAT_AXS10X
select OF_GPIO
select MIGHT_HAVE_PCI
select GENERIC_IRQ_CHIP
-   select ARCH_REQUIRE_GPIOLIB
+   select GPIOLIB
help
  Support for the ARC AXS10x Software Development Platforms.
 
diff --git a/arch/arc/plat-tb10x/Kconfig b/arch/arc/plat-tb10x/Kconfig
index d14b3d3c5dfd..149e0917645d 100644
--- a/arch/arc/plat-tb10x/Kconfig
+++ b/arch/arc/plat-tb10x/Kconfig
@@ -21,7 +21,7 @@ menuconfig ARC_PLAT_TB10X
select PINCTRL
select PINCTRL_TB10X
select PINMUX
-   select ARCH_REQUIRE_GPIOLIB
+   select GPIOLIB
select GPIO_TB10X
select TB10X_IRQC
help
-- 
2.4.11


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc