Le 24/07/2019 à 10:46, Nicholas Piggin a écrit :
Ensure __va is given a physical address below PAGE_OFFSET, and __pa is
given a virtual address above PAGE_OFFSET.

Signed-off-by: Nicholas Piggin <npig...@gmail.com>
---
  arch/powerpc/include/asm/page.h | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index 0d52f57fca04..c8bb14ff4713 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -215,9 +215,19 @@ static inline bool pfn_valid(unsigned long pfn)
  /*
   * gcc miscompiles (unsigned long)(&static_var) - PAGE_OFFSET
   * with -mcmodel=medium, so we use & and | instead of - and + on 64-bit.
+ * This also results in better code generation.
   */
-#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET))
-#define __pa(x) ((unsigned long)(x) & 0x0fffffffffffffffUL)
+#define __va(x)                                                                
\
+({                                                                     \
+       VIRTUAL_BUG_ON((unsigned long)(x) >= PAGE_OFFSET);           \

Do we really want to add a BUG_ON here ?
Can't we just add a WARN_ON, like in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/arch/powerpc/include/asm/io.h?id=6bf752daca07c85c181159f75dcf65b12056883b ?

+       (void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET);        \
+})
+
+#define __pa(x)                                                                
\
+({                                                                     \
+       VIRTUAL_BUG_ON((unsigned long)(x) < PAGE_OFFSET);            \

Same

+       (unsigned long)(x) & 0x0fffffffffffffffUL;                  \
+})
#else /* 32-bit, non book E */
  #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - 
MEMORY_START))


Would it be possible to change those macros into static inlines ?

Christophe

Reply via email to