diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2022-01-31 10:24:50 +0300 |
---|---|---|
committer | Peter Zijlstra <peterz@infradead.org> | 2022-02-02 15:11:42 +0300 |
commit | 1fb85d06ad6754796cd1b920639ca9d8840abefd (patch) | |
tree | ccf0da8a52c5e498ff19c86c317e616c66ebbf1c /arch/x86/include/asm/page.h | |
parent | c243cecb58e3905baeace8827201c14df8481e2a (diff) | |
download | linux-1fb85d06ad6754796cd1b920639ca9d8840abefd.tar.xz |
x86: Share definition of __is_canonical_address()
Reduce code duplication by moving canonical address code to a common header
file.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220131072453.2839535-3-adrian.hunter@intel.com
Diffstat (limited to 'arch/x86/include/asm/page.h')
-rw-r--r-- | arch/x86/include/asm/page.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 4d5810c8fab7..9cc82f305f4b 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -71,6 +71,16 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr, extern bool __virt_addr_valid(unsigned long kaddr); #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr)) +static __always_inline u64 __canonical_address(u64 vaddr, u8 vaddr_bits) +{ + return ((s64)vaddr << (64 - vaddr_bits)) >> (64 - vaddr_bits); +} + +static __always_inline u64 __is_canonical_address(u64 vaddr, u8 vaddr_bits) +{ + return __canonical_address(vaddr, vaddr_bits) == vaddr; +} + #endif /* __ASSEMBLY__ */ #include <asm-generic/memory_model.h> |