All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] MIPS: Fixed __debug_virt_addr_valid()
@ 2022-07-14 22:25 Florian Fainelli
  2022-07-15 11:44 ` Serge Semin
  2022-07-15 12:24 ` Thomas Bogendoerfer
  0 siblings, 2 replies; 3+ messages in thread
From: Florian Fainelli @ 2022-07-14 22:25 UTC (permalink / raw)
  To: linux-mips
  Cc: fancer.lancer, gerg, Florian Fainelli, Thomas Bogendoerfer, open list

It is permissible for kernel code to call virt_to_phys() against virtual
addresses that are in KSEG0 or KSEG1 and we need to be dealing with both
types. Rewrite the test condition to ensure that the kernel virtual
addresses are above PAGE_OFFSET which they must be, and below KSEG2
where the non-linear mapping starts.

For EVA, there is not much that we can do given the linear address range
that is offered, so just return any virtual address as being valid.

Finally, when HIGHMEM is not enabled, all virtual addresses are assumed
to be valid as well.

Fixes: dfad83cb7193 ("MIPS: Add support for CONFIG_DEBUG_VIRTUAL")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
Changes in v2:

- handle lack of HIGHMEM and EVA

 arch/mips/mm/physaddr.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/arch/mips/mm/physaddr.c b/arch/mips/mm/physaddr.c
index a1ced5e44951..f9b8c85e9843 100644
--- a/arch/mips/mm/physaddr.c
+++ b/arch/mips/mm/physaddr.c
@@ -5,6 +5,7 @@
 #include <linux/mmdebug.h>
 #include <linux/mm.h>
 
+#include <asm/addrspace.h>
 #include <asm/sections.h>
 #include <asm/io.h>
 #include <asm/page.h>
@@ -12,15 +13,6 @@
 
 static inline bool __debug_virt_addr_valid(unsigned long x)
 {
-	/* high_memory does not get immediately defined, and there
-	 * are early callers of __pa() against PAGE_OFFSET
-	 */
-	if (!high_memory && x >= PAGE_OFFSET)
-		return true;
-
-	if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory)
-		return true;
-
 	/*
 	 * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
 	 * actual physical address. Enough code relies on
@@ -30,7 +22,9 @@ static inline bool __debug_virt_addr_valid(unsigned long x)
 	if (x == MAX_DMA_ADDRESS)
 		return true;
 
-	return false;
+	return x >= PAGE_OFFSET && (KSEGX(x) < KSEG2 ||
+	       IS_ENABLED(CONFIG_EVA) ||
+	       !IS_ENABLED(CONFIG_HIGHMEM));
 }
 
 phys_addr_t __virt_to_phys(volatile const void *x)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] MIPS: Fixed __debug_virt_addr_valid()
  2022-07-14 22:25 [PATCH v2] MIPS: Fixed __debug_virt_addr_valid() Florian Fainelli
@ 2022-07-15 11:44 ` Serge Semin
  2022-07-15 12:24 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 3+ messages in thread
From: Serge Semin @ 2022-07-15 11:44 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: linux-mips, gerg, Thomas Bogendoerfer, open list

Hi Florian

On Thu, Jul 14, 2022 at 03:25:12PM -0700, Florian Fainelli wrote:
> It is permissible for kernel code to call virt_to_phys() against virtual
> addresses that are in KSEG0 or KSEG1 and we need to be dealing with both
> types. Rewrite the test condition to ensure that the kernel virtual
> addresses are above PAGE_OFFSET which they must be, and below KSEG2
> where the non-linear mapping starts.
> 
> For EVA, there is not much that we can do given the linear address range
> that is offered, so just return any virtual address as being valid.
> 
> Finally, when HIGHMEM is not enabled, all virtual addresses are assumed
> to be valid as well.
> 
> Fixes: dfad83cb7193 ("MIPS: Add support for CONFIG_DEBUG_VIRTUAL")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

No objections now. Thanks.
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>

-Serge(y)

> ---
> Changes in v2:
> 
> - handle lack of HIGHMEM and EVA
> 
>  arch/mips/mm/physaddr.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/mips/mm/physaddr.c b/arch/mips/mm/physaddr.c
> index a1ced5e44951..f9b8c85e9843 100644
> --- a/arch/mips/mm/physaddr.c
> +++ b/arch/mips/mm/physaddr.c
> @@ -5,6 +5,7 @@
>  #include <linux/mmdebug.h>
>  #include <linux/mm.h>
>  
> +#include <asm/addrspace.h>
>  #include <asm/sections.h>
>  #include <asm/io.h>
>  #include <asm/page.h>
> @@ -12,15 +13,6 @@
>  
>  static inline bool __debug_virt_addr_valid(unsigned long x)
>  {
> -	/* high_memory does not get immediately defined, and there
> -	 * are early callers of __pa() against PAGE_OFFSET
> -	 */
> -	if (!high_memory && x >= PAGE_OFFSET)
> -		return true;
> -
> -	if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory)
> -		return true;
> -
>  	/*
>  	 * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
>  	 * actual physical address. Enough code relies on
> @@ -30,7 +22,9 @@ static inline bool __debug_virt_addr_valid(unsigned long x)
>  	if (x == MAX_DMA_ADDRESS)
>  		return true;
>  
> -	return false;
> +	return x >= PAGE_OFFSET && (KSEGX(x) < KSEG2 ||
> +	       IS_ENABLED(CONFIG_EVA) ||
> +	       !IS_ENABLED(CONFIG_HIGHMEM));
>  }
>  
>  phys_addr_t __virt_to_phys(volatile const void *x)
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] MIPS: Fixed __debug_virt_addr_valid()
  2022-07-14 22:25 [PATCH v2] MIPS: Fixed __debug_virt_addr_valid() Florian Fainelli
  2022-07-15 11:44 ` Serge Semin
@ 2022-07-15 12:24 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Bogendoerfer @ 2022-07-15 12:24 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: linux-mips, fancer.lancer, gerg, open list

On Thu, Jul 14, 2022 at 03:25:12PM -0700, Florian Fainelli wrote:
> It is permissible for kernel code to call virt_to_phys() against virtual
> addresses that are in KSEG0 or KSEG1 and we need to be dealing with both
> types. Rewrite the test condition to ensure that the kernel virtual
> addresses are above PAGE_OFFSET which they must be, and below KSEG2
> where the non-linear mapping starts.
> 
> For EVA, there is not much that we can do given the linear address range
> that is offered, so just return any virtual address as being valid.
> 
> Finally, when HIGHMEM is not enabled, all virtual addresses are assumed
> to be valid as well.
> 
> Fixes: dfad83cb7193 ("MIPS: Add support for CONFIG_DEBUG_VIRTUAL")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
> Changes in v2:
> 
> - handle lack of HIGHMEM and EVA
> 
>  arch/mips/mm/physaddr.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)

applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-15 12:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 22:25 [PATCH v2] MIPS: Fixed __debug_virt_addr_valid() Florian Fainelli
2022-07-15 11:44 ` Serge Semin
2022-07-15 12:24 ` Thomas Bogendoerfer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.