Skip to content

Commit dad947c

Browse files
brooniectmarinas
authored andcommitted
arm64/gcs: Add manual encodings of GCS instructions
Define C callable functions for GCS instructions used by the kernel. In order to avoid ambitious toolchain requirements for GCS support these are manually encoded, this means we have fixed register numbers which will be a bit limiting for the compiler but none of these should be used in sufficiently fast paths for this to be a problem. Note that GCSSTTR is used to store to EL0. Reviewed-by: Thiago Jung Bauermann <[email protected]> Acked-by: Catalin Marinas <[email protected]> Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent ce0641d commit dad947c

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

arch/arm64/include/asm/gcs.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2023 ARM Ltd.
4+
*/
5+
#ifndef __ASM_GCS_H
6+
#define __ASM_GCS_H
7+
8+
#include <asm/types.h>
9+
#include <asm/uaccess.h>
10+
11+
static inline void gcsb_dsync(void)
12+
{
13+
asm volatile(".inst 0xd503227f" : : : "memory");
14+
}
15+
16+
static inline void gcsstr(u64 *addr, u64 val)
17+
{
18+
register u64 *_addr __asm__ ("x0") = addr;
19+
register long _val __asm__ ("x1") = val;
20+
21+
/* GCSSTTR x1, x0 */
22+
asm volatile(
23+
".inst 0xd91f1c01\n"
24+
:
25+
: "rZ" (_val), "r" (_addr)
26+
: "memory");
27+
}
28+
29+
static inline void gcsss1(u64 Xt)
30+
{
31+
asm volatile (
32+
"sys #3, C7, C7, #2, %0\n"
33+
:
34+
: "rZ" (Xt)
35+
: "memory");
36+
}
37+
38+
static inline u64 gcsss2(void)
39+
{
40+
u64 Xt;
41+
42+
asm volatile(
43+
"SYSL %0, #3, C7, C7, #3\n"
44+
: "=r" (Xt)
45+
:
46+
: "memory");
47+
48+
return Xt;
49+
}
50+
51+
#endif

arch/arm64/include/asm/uaccess.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,4 +502,26 @@ static inline size_t probe_subpage_writeable(const char __user *uaddr,
502502

503503
#endif /* CONFIG_ARCH_HAS_SUBPAGE_FAULTS */
504504

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+
#endif /* CONFIG_ARM64_GCS */
526+
505527
#endif /* __ASM_UACCESS_H */

0 commit comments

Comments
 (0)