[PATCH] um: Replace to_phys() and to_virt() with less generic function names

Guenter Roeck posted 1 patch 3 years, 9 months ago
arch/um/include/asm/page.h      | 4 ++--
arch/um/include/shared/mem.h    | 4 ++--
arch/um/os-Linux/skas/process.c | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)
[PATCH] um: Replace to_phys() and to_virt() with less generic function names
Posted by Guenter Roeck 3 years, 9 months ago
to_virt() and to_phys() are very generic and may be defined by drivers.
As it turns out, commit 9409c9b6709e ("pmem: refactor pmem_clear_poison()")
did exactly that. This results in build errors such as the following
when trying to build um:allmodconfig.

drivers/nvdimm/pmem.c: In function ‘pmem_dax_zero_page_range’:
./arch/um/include/asm/page.h:105:20: error:
			too few arguments to function ‘to_phys’
  105 | #define __pa(virt) to_phys((void *) (unsigned long) (virt))
      |                    ^~~~~~~

Use less generic function names for the um specific to_phys() and to_virt()
functions to fix the problem and to avoid similar problems in the future.

Fixes: 9409c9b6709e ("pmem: refactor pmem_clear_poison()")
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/um/include/asm/page.h      | 4 ++--
 arch/um/include/shared/mem.h    | 4 ++--
 arch/um/os-Linux/skas/process.c | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
index 95af12e82a32..cdbd9653aa14 100644
--- a/arch/um/include/asm/page.h
+++ b/arch/um/include/asm/page.h
@@ -102,8 +102,8 @@ extern unsigned long uml_physmem;
  * casting is the right thing, but 32-bit UML can't have 64-bit virtual
  * addresses
  */
-#define __pa(virt) to_phys((void *) (unsigned long) (virt))
-#define __va(phys) to_virt((unsigned long) (phys))
+#define __pa(virt) uml_to_phys((void *) (unsigned long) (virt))
+#define __va(phys) uml_to_virt((unsigned long) (phys))
 
 #define phys_to_pfn(p) ((p) >> PAGE_SHIFT)
 #define pfn_to_phys(pfn) PFN_PHYS(pfn)
diff --git a/arch/um/include/shared/mem.h b/arch/um/include/shared/mem.h
index 4862c91d4213..98aacd544108 100644
--- a/arch/um/include/shared/mem.h
+++ b/arch/um/include/shared/mem.h
@@ -9,12 +9,12 @@
 extern int phys_mapping(unsigned long phys, unsigned long long *offset_out);
 
 extern unsigned long uml_physmem;
-static inline unsigned long to_phys(void *virt)
+static inline unsigned long uml_to_phys(void *virt)
 {
 	return(((unsigned long) virt) - uml_physmem);
 }
 
-static inline void *to_virt(unsigned long phys)
+static inline void *uml_to_virt(unsigned long phys)
 {
 	return((void *) uml_physmem + phys);
 }
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 87d3129e7362..c316c993a949 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -251,7 +251,7 @@ static int userspace_tramp(void *stack)
 	signal(SIGTERM, SIG_DFL);
 	signal(SIGWINCH, SIG_IGN);
 
-	fd = phys_mapping(to_phys(__syscall_stub_start), &offset);
+	fd = phys_mapping(uml_to_phys(__syscall_stub_start), &offset);
 	addr = mmap64((void *) STUB_CODE, UM_KERN_PAGE_SIZE,
 		      PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, offset);
 	if (addr == MAP_FAILED) {
@@ -261,7 +261,7 @@ static int userspace_tramp(void *stack)
 	}
 
 	if (stack != NULL) {
-		fd = phys_mapping(to_phys(stack), &offset);
+		fd = phys_mapping(uml_to_phys(stack), &offset);
 		addr = mmap((void *) STUB_DATA,
 			    UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
 			    MAP_FIXED | MAP_SHARED, fd, offset);
@@ -534,7 +534,7 @@ int copy_context_skas0(unsigned long new_stack, int pid)
 	struct stub_data *data = (struct stub_data *) current_stack;
 	struct stub_data *child_data = (struct stub_data *) new_stack;
 	unsigned long long new_offset;
-	int new_fd = phys_mapping(to_phys((void *)new_stack), &new_offset);
+	int new_fd = phys_mapping(uml_to_phys((void *)new_stack), &new_offset);
 
 	/*
 	 * prepare offset and fd of child's stack as argument for parent's
-- 
2.35.1

RE: [PATCH] um: Replace to_phys() and to_virt() with less generic function names
Posted by Dan Williams 3 years, 9 months ago
[ add Jane ]

Guenter Roeck wrote:
> to_virt() and to_phys() are very generic and may be defined by drivers.
> As it turns out, commit 9409c9b6709e ("pmem: refactor pmem_clear_poison()")
> did exactly that. This results in build errors such as the following
> when trying to build um:allmodconfig.
> 
> drivers/nvdimm/pmem.c: In function ‘pmem_dax_zero_page_range’:
> ./arch/um/include/asm/page.h:105:20: error:
> 			too few arguments to function ‘to_phys’
>   105 | #define __pa(virt) to_phys((void *) (unsigned long) (virt))
>       |                    ^~~~~~~
> 
> Use less generic function names for the um specific to_phys() and to_virt()
> functions to fix the problem and to avoid similar problems in the future.
> 
> Fixes: 9409c9b6709e ("pmem: refactor pmem_clear_poison()")
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Christoph Hellwig <hch@lst.de>

Acked-by: Dan Williams <dan.j.williams@intel.com>

Jane had sent a pmem local fixup, that I was about to push to linux-next:

https://lore.kernel.org/nvdimm/20220630182802.3250449-1-jane.chu@oracle.com/

...but I like this one too, lets do both.

> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  arch/um/include/asm/page.h      | 4 ++--
>  arch/um/include/shared/mem.h    | 4 ++--
>  arch/um/os-Linux/skas/process.c | 6 +++---
>  3 files changed, 7 insertions(+), 7 deletions(-)
Re: [PATCH] um: Replace to_phys() and to_virt() with less generic function names
Posted by Anton Ivanov 3 years, 9 months ago
On 14/07/2022 19:46, Guenter Roeck wrote:
> to_virt() and to_phys() are very generic and may be defined by drivers.
> As it turns out, commit 9409c9b6709e ("pmem: refactor pmem_clear_poison()")
> did exactly that. This results in build errors such as the following
> when trying to build um:allmodconfig.
> 
> drivers/nvdimm/pmem.c: In function ‘pmem_dax_zero_page_range’:
> ./arch/um/include/asm/page.h:105:20: error:
> 			too few arguments to function ‘to_phys’
>    105 | #define __pa(virt) to_phys((void *) (unsigned long) (virt))
>        |                    ^~~~~~~
> 
> Use less generic function names for the um specific to_phys() and to_virt()
> functions to fix the problem and to avoid similar problems in the future.
> 
> Fixes: 9409c9b6709e ("pmem: refactor pmem_clear_poison()")
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>   arch/um/include/asm/page.h      | 4 ++--
>   arch/um/include/shared/mem.h    | 4 ++--
>   arch/um/os-Linux/skas/process.c | 6 +++---
>   3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
> index 95af12e82a32..cdbd9653aa14 100644
> --- a/arch/um/include/asm/page.h
> +++ b/arch/um/include/asm/page.h
> @@ -102,8 +102,8 @@ extern unsigned long uml_physmem;
>    * casting is the right thing, but 32-bit UML can't have 64-bit virtual
>    * addresses
>    */
> -#define __pa(virt) to_phys((void *) (unsigned long) (virt))
> -#define __va(phys) to_virt((unsigned long) (phys))
> +#define __pa(virt) uml_to_phys((void *) (unsigned long) (virt))
> +#define __va(phys) uml_to_virt((unsigned long) (phys))
>   
>   #define phys_to_pfn(p) ((p) >> PAGE_SHIFT)
>   #define pfn_to_phys(pfn) PFN_PHYS(pfn)
> diff --git a/arch/um/include/shared/mem.h b/arch/um/include/shared/mem.h
> index 4862c91d4213..98aacd544108 100644
> --- a/arch/um/include/shared/mem.h
> +++ b/arch/um/include/shared/mem.h
> @@ -9,12 +9,12 @@
>   extern int phys_mapping(unsigned long phys, unsigned long long *offset_out);
>   
>   extern unsigned long uml_physmem;
> -static inline unsigned long to_phys(void *virt)
> +static inline unsigned long uml_to_phys(void *virt)
>   {
>   	return(((unsigned long) virt) - uml_physmem);
>   }
>   
> -static inline void *to_virt(unsigned long phys)
> +static inline void *uml_to_virt(unsigned long phys)
>   {
>   	return((void *) uml_physmem + phys);
>   }
> diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
> index 87d3129e7362..c316c993a949 100644
> --- a/arch/um/os-Linux/skas/process.c
> +++ b/arch/um/os-Linux/skas/process.c
> @@ -251,7 +251,7 @@ static int userspace_tramp(void *stack)
>   	signal(SIGTERM, SIG_DFL);
>   	signal(SIGWINCH, SIG_IGN);
>   
> -	fd = phys_mapping(to_phys(__syscall_stub_start), &offset);
> +	fd = phys_mapping(uml_to_phys(__syscall_stub_start), &offset);
>   	addr = mmap64((void *) STUB_CODE, UM_KERN_PAGE_SIZE,
>   		      PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, offset);
>   	if (addr == MAP_FAILED) {
> @@ -261,7 +261,7 @@ static int userspace_tramp(void *stack)
>   	}
>   
>   	if (stack != NULL) {
> -		fd = phys_mapping(to_phys(stack), &offset);
> +		fd = phys_mapping(uml_to_phys(stack), &offset);
>   		addr = mmap((void *) STUB_DATA,
>   			    UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
>   			    MAP_FIXED | MAP_SHARED, fd, offset);
> @@ -534,7 +534,7 @@ int copy_context_skas0(unsigned long new_stack, int pid)
>   	struct stub_data *data = (struct stub_data *) current_stack;
>   	struct stub_data *child_data = (struct stub_data *) new_stack;
>   	unsigned long long new_offset;
> -	int new_fd = phys_mapping(to_phys((void *)new_stack), &new_offset);
> +	int new_fd = phys_mapping(uml_to_phys((void *)new_stack), &new_offset);
>   
>   	/*
>   	 * prepare offset and fd of child's stack as argument for parent's

Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/