Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: uaccess: Move existing GCS accessors definitions to gcs.h

We are going to add some additional GCS access helpers to gcs.h in
order to avoid some forward reference problems with uaccess.

In preparation for that, lets move the existing gcssttr() and
put_user_gcs() routines into gcs.h where it makes sense to keep all
the accessors together. Further, the code which uses them already
includes gcs.h and there is an existing CONFIG_ARM64_GCS check we can
reuse. The GCSSTTR instruction description comment is corrected during
the move.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Jeremy Linton and committed by
Will Deacon
ea920b50 47687aa4

+36 -41
+36 -1
arch/arm64/include/asm/gcs.h
··· 21 21 register u64 *_addr __asm__ ("x0") = addr; 22 22 register long _val __asm__ ("x1") = val; 23 23 24 - /* GCSSTTR x1, x0 */ 24 + /* GCSSTTR x1, [x0] */ 25 25 asm volatile( 26 26 ".inst 0xd91f1c01\n" 27 27 : ··· 79 79 return -EBUSY; 80 80 81 81 return 0; 82 + } 83 + 84 + static inline int gcssttr(unsigned long __user *addr, unsigned long val) 85 + { 86 + register unsigned long __user *_addr __asm__ ("x0") = addr; 87 + register unsigned long _val __asm__ ("x1") = val; 88 + int err = 0; 89 + 90 + /* GCSSTTR x1, [x0] */ 91 + asm volatile( 92 + "1: .inst 0xd91f1c01\n" 93 + "2: \n" 94 + _ASM_EXTABLE_UACCESS_ERR(1b, 2b, %w0) 95 + : "+r" (err) 96 + : "rZ" (_val), "r" (_addr) 97 + : "memory"); 98 + 99 + return err; 100 + } 101 + 102 + static inline void put_user_gcs(unsigned long val, unsigned long __user *addr, 103 + int *err) 104 + { 105 + int ret; 106 + 107 + if (!access_ok((char __user *)addr, sizeof(u64))) { 108 + *err = -EFAULT; 109 + return; 110 + } 111 + 112 + uaccess_ttbr0_enable(); 113 + ret = gcssttr(addr, val); 114 + if (ret != 0) 115 + *err = ret; 116 + uaccess_ttbr0_disable(); 82 117 } 83 118 84 119 #else
-40
arch/arm64/include/asm/uaccess.h
··· 502 502 503 503 #endif /* CONFIG_ARCH_HAS_SUBPAGE_FAULTS */ 504 504 505 - #ifdef CONFIG_ARM64_GCS 506 - 507 - static inline int gcssttr(unsigned long __user *addr, unsigned long val) 508 - { 509 - register unsigned long __user *_addr __asm__ ("x0") = addr; 510 - register unsigned long _val __asm__ ("x1") = val; 511 - int err = 0; 512 - 513 - /* GCSSTTR x1, x0 */ 514 - asm volatile( 515 - "1: .inst 0xd91f1c01\n" 516 - "2: \n" 517 - _ASM_EXTABLE_UACCESS_ERR(1b, 2b, %w0) 518 - : "+r" (err) 519 - : "rZ" (_val), "r" (_addr) 520 - : "memory"); 521 - 522 - return err; 523 - } 524 - 525 - static inline void put_user_gcs(unsigned long val, unsigned long __user *addr, 526 - int *err) 527 - { 528 - int ret; 529 - 530 - if (!access_ok((char __user *)addr, sizeof(u64))) { 531 - *err = -EFAULT; 532 - return; 533 - } 534 - 535 - uaccess_ttbr0_enable(); 536 - ret = gcssttr(addr, val); 537 - if (ret != 0) 538 - *err = ret; 539 - uaccess_ttbr0_disable(); 540 - } 541 - 542 - 543 - #endif /* CONFIG_ARM64_GCS */ 544 - 545 505 #endif /* __ASM_UACCESS_H */