1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /******************************************************************************
3  * Copyright (c) 2022 Citrix Systems Ltd.
4  */
5 #ifndef XEN_ASM_SHSTK_H
6 #define XEN_ASM_SHSTK_H
7 
8 /*
9  * RDSSP is a nop when shadow stacks are inactive.  Also, SSP has a minimum
10  * alignment of 4 which is enforced by hardware.
11  *
12  * We load 1 into a register, then RDSSP.  If shadow stacks are not enabled,
13  * RDSSP is a nop, and the 1 is preserved.  Otherwise, the 1 is clobbered with
14  * the real SSP, which has the bottom two bits clear.
15  */
16 #define SSP_NO_SHSTK 1
17 
rdssp(void)18 static inline unsigned long rdssp(void)
19 {
20     unsigned long ssp;
21 
22     asm volatile ( "rdsspq %0" : "=r" (ssp) : "0" (SSP_NO_SHSTK) );
23 
24     return ssp;
25 }
26 
wrss(unsigned long val,unsigned long * ptr)27 static inline void wrss(unsigned long val, unsigned long *ptr)
28 {
29     asm ( "wrssq %[val], %[ptr]"
30           : [ptr] "=m" (*ptr)
31           : [val] "r" (val) );
32 }
33 
34 #endif /* XEN_ASM_SHSTK_H */
35