1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Ultravisor Interfaces
5 * Copyright IBM Corp. 2019
8 * Vasily Gorbik <gor@linux.ibm.com>
9 * Janosch Frank <frankja@linux.ibm.com>
11 #ifndef _ASM_S390_UV_H
12 #define _ASM_S390_UV_H
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/bug.h>
17 #include <linux/sched.h>
21 #define UVC_RC_EXECUTED 0x0001
22 #define UVC_RC_INV_CMD 0x0002
23 #define UVC_RC_INV_STATE 0x0003
24 #define UVC_RC_INV_LEN 0x0005
25 #define UVC_RC_NO_RESUME 0x0007
26 #define UVC_RC_NEED_DESTROY 0x8000
28 #define UVC_CMD_QUI 0x0001
29 #define UVC_CMD_INIT_UV 0x000f
30 #define UVC_CMD_CREATE_SEC_CONF 0x0100
31 #define UVC_CMD_DESTROY_SEC_CONF 0x0101
32 #define UVC_CMD_CREATE_SEC_CPU 0x0120
33 #define UVC_CMD_DESTROY_SEC_CPU 0x0121
34 #define UVC_CMD_CONV_TO_SEC_STOR 0x0200
35 #define UVC_CMD_CONV_FROM_SEC_STOR 0x0201
36 #define UVC_CMD_DESTR_SEC_STOR 0x0202
37 #define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300
38 #define UVC_CMD_UNPACK_IMG 0x0301
39 #define UVC_CMD_VERIFY_IMG 0x0302
40 #define UVC_CMD_CPU_RESET 0x0310
41 #define UVC_CMD_CPU_RESET_INITIAL 0x0311
42 #define UVC_CMD_PREPARE_RESET 0x0320
43 #define UVC_CMD_CPU_RESET_CLEAR 0x0321
44 #define UVC_CMD_CPU_SET_STATE 0x0330
45 #define UVC_CMD_SET_UNSHARE_ALL 0x0340
46 #define UVC_CMD_PIN_PAGE_SHARED 0x0341
47 #define UVC_CMD_UNPIN_PAGE_SHARED 0x0342
48 #define UVC_CMD_SET_SHARED_ACCESS 0x1000
49 #define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001
51 /* Bits in installed uv calls */
54 BIT_UVC_CMD_INIT_UV
= 1,
55 BIT_UVC_CMD_CREATE_SEC_CONF
= 2,
56 BIT_UVC_CMD_DESTROY_SEC_CONF
= 3,
57 BIT_UVC_CMD_CREATE_SEC_CPU
= 4,
58 BIT_UVC_CMD_DESTROY_SEC_CPU
= 5,
59 BIT_UVC_CMD_CONV_TO_SEC_STOR
= 6,
60 BIT_UVC_CMD_CONV_FROM_SEC_STOR
= 7,
61 BIT_UVC_CMD_SET_SHARED_ACCESS
= 8,
62 BIT_UVC_CMD_REMOVE_SHARED_ACCESS
= 9,
63 BIT_UVC_CMD_SET_SEC_PARMS
= 11,
64 BIT_UVC_CMD_UNPACK_IMG
= 13,
65 BIT_UVC_CMD_VERIFY_IMG
= 14,
66 BIT_UVC_CMD_CPU_RESET
= 15,
67 BIT_UVC_CMD_CPU_RESET_INITIAL
= 16,
68 BIT_UVC_CMD_CPU_SET_STATE
= 17,
69 BIT_UVC_CMD_PREPARE_RESET
= 18,
70 BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET
= 19,
71 BIT_UVC_CMD_UNSHARE_ALL
= 20,
72 BIT_UVC_CMD_PIN_PAGE_SHARED
= 21,
73 BIT_UVC_CMD_UNPIN_PAGE_SHARED
= 22,
78 u16 cmd
; /* Command Code */
79 u16 rc
; /* Response Code */
80 u16 rrc
; /* Return Reason Code */
81 } __packed
__aligned(8);
83 /* Query Ultravisor Information */
85 struct uv_cb_header header
;
87 u64 inst_calls_list
[4];
91 u64 conf_base_phys_stor_len
;
92 u64 conf_base_virt_stor_len
;
93 u64 conf_virt_var_stor_len
;
97 u64 max_guest_stor_addr
;
98 u8 reserved88
[158 - 136];
100 u8 reserveda0
[200 - 160];
101 } __packed
__aligned(8);
103 /* Initialize Ultravisor */
105 struct uv_cb_header header
;
110 } __packed
__aligned(8);
112 /* Create Guest Configuration */
114 struct uv_cb_header header
;
117 u64 conf_base_stor_origin
;
118 u64 conf_virt_stor_origin
;
120 u64 guest_stor_origin
;
125 } __packed
__aligned(8);
127 /* Create Secure CPU */
129 struct uv_cb_header header
;
138 } __packed
__aligned(8);
140 /* Convert to Secure */
142 struct uv_cb_header header
;
146 } __packed
__aligned(8);
148 /* Convert from Secure / Pin Page Shared */
150 struct uv_cb_header header
;
153 } __packed
__aligned(8);
155 /* Set Secure Config Parameter */
157 struct uv_cb_header header
;
160 u64 sec_header_origin
;
164 } __packed
__aligned(8);
168 struct uv_cb_header header
;
174 } __packed
__aligned(8);
176 #define PV_CPU_STATE_OPR 1
177 #define PV_CPU_STATE_STP 2
178 #define PV_CPU_STATE_CHKSTP 3
179 #define PV_CPU_STATE_OPR_LOAD 5
181 struct uv_cb_cpu_set_state
{
182 struct uv_cb_header header
;
191 * A common UV call struct for calls that take no payload
196 struct uv_cb_nodata
{
197 struct uv_cb_header header
;
201 } __packed
__aligned(8);
203 /* Set Shared Access */
205 struct uv_cb_header header
;
209 } __packed
__aligned(8);
211 static inline int __uv_call(unsigned long r1
, unsigned long r2
)
216 " .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n"
220 : [r1
] "a" (r1
), [r2
] "a" (r2
)
225 static inline int uv_call(unsigned long r1
, unsigned long r2
)
230 cc
= __uv_call(r1
, r2
);
235 /* Low level uv_call that avoids stalls for long running busy conditions */
236 static inline int uv_call_sched(unsigned long r1
, unsigned long r2
)
241 cc
= __uv_call(r1
, r2
);
248 * special variant of uv_call that only transports the cpu or guest
249 * handle and the command, like destroy or verify.
251 static inline int uv_cmd_nodata(u64 handle
, u16 cmd
, u16
*rc
, u16
*rrc
)
253 struct uv_cb_nodata uvcb
= {
255 .header
.len
= sizeof(uvcb
),
260 WARN(!handle
, "No handle provided to Ultravisor call cmd %x\n", cmd
);
261 cc
= uv_call_sched(0, (u64
)&uvcb
);
262 *rc
= uvcb
.header
.rc
;
263 *rrc
= uvcb
.header
.rrc
;
264 return cc
? -EINVAL
: 0;
268 unsigned long inst_calls_list
[4];
269 unsigned long uv_base_stor_len
;
270 unsigned long guest_base_stor_len
;
271 unsigned long guest_virt_base_stor_len
;
272 unsigned long guest_virt_var_stor_len
;
273 unsigned long guest_cpu_stor_len
;
274 unsigned long max_sec_stor_addr
;
275 unsigned int max_num_sec_conf
;
276 unsigned short max_guest_cpus
;
279 extern struct uv_info uv_info
;
281 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
282 extern int prot_virt_guest
;
284 static inline int is_prot_virt_guest(void)
286 return prot_virt_guest
;
289 static inline int share(unsigned long addr
, u16 cmd
)
291 struct uv_cb_share uvcb
= {
293 .header
.len
= sizeof(uvcb
),
297 if (!is_prot_virt_guest())
300 * Sharing is page wise, if we encounter addresses that are
301 * not page aligned, we assume something went wrong. If
302 * malloced structs are passed to this function, we could leak
303 * data to the hypervisor.
305 BUG_ON(addr
& ~PAGE_MASK
);
307 if (!uv_call(0, (u64
)&uvcb
))
313 * Guest 2 request to the Ultravisor to make a page shared with the
316 * @addr: Real or absolute address of the page to be shared
318 static inline int uv_set_shared(unsigned long addr
)
320 return share(addr
, UVC_CMD_SET_SHARED_ACCESS
);
324 * Guest 2 request to the Ultravisor to make a page unshared.
326 * @addr: Real or absolute address of the page to be unshared
328 static inline int uv_remove_shared(unsigned long addr
)
330 return share(addr
, UVC_CMD_REMOVE_SHARED_ACCESS
);
334 #define is_prot_virt_guest() 0
335 static inline int uv_set_shared(unsigned long addr
) { return 0; }
336 static inline int uv_remove_shared(unsigned long addr
) { return 0; }
339 #if IS_ENABLED(CONFIG_KVM)
340 extern int prot_virt_host
;
342 static inline int is_prot_virt_host(void)
344 return prot_virt_host
;
347 int gmap_make_secure(struct gmap
*gmap
, unsigned long gaddr
, void *uvcb
);
348 int uv_destroy_page(unsigned long paddr
);
349 int uv_convert_from_secure(unsigned long paddr
);
350 int gmap_convert_to_secure(struct gmap
*gmap
, unsigned long gaddr
);
353 void adjust_to_uv_max(unsigned long *vmax
);
355 #define is_prot_virt_host() 0
356 static inline void setup_uv(void) {}
357 static inline void adjust_to_uv_max(unsigned long *vmax
) {}
359 static inline int uv_destroy_page(unsigned long paddr
)
364 static inline int uv_convert_from_secure(unsigned long paddr
)
370 #if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) || IS_ENABLED(CONFIG_KVM)
371 void uv_query_info(void);
373 static inline void uv_query_info(void) {}
376 #endif /* _ASM_S390_UV_H */