[1/4] asm-generic/page.h: apply page shift to PFN instead of VA in pfn_to_virt

Message ID 20240131055740.2579-1-yan.y.zhao@intel.com
State New
Headers
Series apply page shift to PFN instead of VA in pfn_to_virt |

Commit Message

Yan Zhao Jan. 31, 2024, 5:57 a.m. UTC
  Apply the page shift to PFN to get physical address for final VA.
The macro __va should take physical address instead of PFN as input.

Fixes: 2d78057f0dd4 ("asm-generic/page.h: Make pfn accessors static inlines")
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
 include/asm-generic/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Guo Ren Feb. 23, 2024, 11:26 a.m. UTC | #1
On Wed, Jan 31, 2024 at 2:27 PM Yan Zhao <yan.y.zhao@intel.com> wrote:
>
> Apply the page shift to PFN to get physical address for final VA.
> The macro __va should take physical address instead of PFN as input.
>
> Fixes: 2d78057f0dd4 ("asm-generic/page.h: Make pfn accessors static inlines")
> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> ---
>  include/asm-generic/page.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
> index 9773582fd96e..4f1265207b9a 100644
> --- a/include/asm-generic/page.h
> +++ b/include/asm-generic/page.h
> @@ -81,7 +81,7 @@ static inline unsigned long virt_to_pfn(const void *kaddr)
>  #define virt_to_pfn virt_to_pfn
>  static inline void *pfn_to_virt(unsigned long pfn)
>  {
> -       return __va(pfn) << PAGE_SHIFT;
> +       return __va(pfn << PAGE_SHIFT);
Oh, that's a terrible bug; Thx for fixing it.

Reviewed-by: Guo Ren <guoren@kernel.org>

>  }
>  #define pfn_to_virt pfn_to_virt
>
> --
> 2.17.1
>
  
Linus Walleij Feb. 29, 2024, 1:34 p.m. UTC | #2
On Wed, Jan 31, 2024 at 7:27 AM Yan Zhao <yan.y.zhao@intel.com> wrote:

> Apply the page shift to PFN to get physical address for final VA.
> The macro __va should take physical address instead of PFN as input.
>
> Fixes: 2d78057f0dd4 ("asm-generic/page.h: Make pfn accessors static inlines")
> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>

My bug, obviously. :(
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

I thought this was already applied with the other fixes, but maybe it
was missed?

Yours,
Linus Walleij
  
Yan Zhao Feb. 29, 2024, 11:01 p.m. UTC | #3
On Thu, Feb 29, 2024 at 02:34:35PM +0100, Linus Walleij wrote:
> On Wed, Jan 31, 2024 at 7:27 AM Yan Zhao <yan.y.zhao@intel.com> wrote:
> 
> > Apply the page shift to PFN to get physical address for final VA.
> > The macro __va should take physical address instead of PFN as input.
> >
> > Fixes: 2d78057f0dd4 ("asm-generic/page.h: Make pfn accessors static inlines")
> > Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> 
> My bug, obviously. :(
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> 
> I thought this was already applied with the other fixes, but maybe it
> was missed?
>
Hi Linus,
The other 3 in csky/hexagon/openrisc should have been applied in
https://lore.kernel.org/all/20240202140550.9886-1-yan.y.zhao@intel.com/.

This one in asm-generic is not, because Arnd said he is going to remove
the header as a whole soon. 

I explained it in the change log :)
"The pfn_to_virt() in asm-generic/page.h is not touched in this patch as
it's referenced by page_to_virt() in that header while the whole header is
going to be removed as a whole due to no one including it."

Thanks
Yan
  

Patch

diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index 9773582fd96e..4f1265207b9a 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -81,7 +81,7 @@  static inline unsigned long virt_to_pfn(const void *kaddr)
 #define virt_to_pfn virt_to_pfn
 static inline void *pfn_to_virt(unsigned long pfn)
 {
-	return __va(pfn) << PAGE_SHIFT;
+	return __va(pfn << PAGE_SHIFT);
 }
 #define pfn_to_virt pfn_to_virt