xref: /linux/arch/s390/boot/uv.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
15abb9351SVasily Gorbik // SPDX-License-Identifier: GPL-2.0
25abb9351SVasily Gorbik #include <asm/uv.h>
342c89439SAlexander Egorenkov #include <asm/boot_data.h>
45abb9351SVasily Gorbik #include <asm/facility.h>
55abb9351SVasily Gorbik #include <asm/sections.h>
65abb9351SVasily Gorbik 
742c89439SAlexander Egorenkov #include "boot.h"
8c5cf5054SAlexander Egorenkov #include "uv.h"
9c5cf5054SAlexander Egorenkov 
10ecdc5d84SVasily Gorbik /* will be used in arch/s390/kernel/uv.c */
115abb9351SVasily Gorbik int __bootdata_preserved(prot_virt_guest);
121d6671aeSVasily Gorbik int __bootdata_preserved(prot_virt_host);
13ecdc5d84SVasily Gorbik struct uv_info __bootdata_preserved(uv_info);
145abb9351SVasily Gorbik 
uv_query_info(void)155abb9351SVasily Gorbik void uv_query_info(void)
165abb9351SVasily Gorbik {
175abb9351SVasily Gorbik 	struct uv_cb_qui uvcb = {
185abb9351SVasily Gorbik 		.header.cmd = UVC_CMD_QUI,
195abb9351SVasily Gorbik 		.header.len = sizeof(uvcb)
205abb9351SVasily Gorbik 	};
215abb9351SVasily Gorbik 
225abb9351SVasily Gorbik 	if (!test_facility(158))
235abb9351SVasily Gorbik 		return;
245abb9351SVasily Gorbik 
2527dc0700SChristian Borntraeger 	/* rc==0x100 means that there is additional data we do not process */
2627dc0700SChristian Borntraeger 	if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc != 0x100)
275abb9351SVasily Gorbik 		return;
285abb9351SVasily Gorbik 
29ecdc5d84SVasily Gorbik 	if (IS_ENABLED(CONFIG_KVM)) {
30ecdc5d84SVasily Gorbik 		memcpy(uv_info.inst_calls_list, uvcb.inst_calls_list, sizeof(uv_info.inst_calls_list));
31ecdc5d84SVasily Gorbik 		uv_info.uv_base_stor_len = uvcb.uv_base_stor_len;
32ecdc5d84SVasily Gorbik 		uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len;
33ecdc5d84SVasily Gorbik 		uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len;
34ecdc5d84SVasily Gorbik 		uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len;
35ecdc5d84SVasily Gorbik 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
36ecdc5d84SVasily Gorbik 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
37ecdc5d84SVasily Gorbik 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
38e82080e1SJanosch Frank 		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_id;
3985b18d7bSJanosch Frank 		uv_info.uv_feature_indications = uvcb.uv_feature_indications;
40ac640db3SJanosch Frank 		uv_info.supp_se_hdr_ver = uvcb.supp_se_hdr_versions;
41ac640db3SJanosch Frank 		uv_info.supp_se_hdr_pcf = uvcb.supp_se_hdr_pcf;
4238c21825SJanosch Frank 		uv_info.conf_dump_storage_state_len = uvcb.conf_dump_storage_state_len;
4338c21825SJanosch Frank 		uv_info.conf_dump_finalize_len = uvcb.conf_dump_finalize_len;
441b6abe95SSteffen Eiden 		uv_info.supp_att_req_hdr_ver = uvcb.supp_att_req_hdr_ver;
451b6abe95SSteffen Eiden 		uv_info.supp_att_pflags = uvcb.supp_att_pflags;
46*db54dfc9SSteffen Eiden 		uv_info.supp_add_secret_req_ver = uvcb.supp_add_secret_req_ver;
47*db54dfc9SSteffen Eiden 		uv_info.supp_add_secret_pcf = uvcb.supp_add_secret_pcf;
48*db54dfc9SSteffen Eiden 		uv_info.supp_secret_types = uvcb.supp_secret_types;
49*db54dfc9SSteffen Eiden 		uv_info.max_secrets = uvcb.max_secrets;
50ecdc5d84SVasily Gorbik 	}
51ecdc5d84SVasily Gorbik 
525abb9351SVasily Gorbik 	if (test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list) &&
535abb9351SVasily Gorbik 	    test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list))
545abb9351SVasily Gorbik 		prot_virt_guest = 1;
555abb9351SVasily Gorbik }
560c4f2623SVasily Gorbik 
adjust_to_uv_max(unsigned long limit)5757ad19bcSAlexander Gordeev unsigned long adjust_to_uv_max(unsigned long limit)
580c4f2623SVasily Gorbik {
597f33565bSAlexander Egorenkov 	if (is_prot_virt_host() && uv_info.max_sec_stor_addr)
6057ad19bcSAlexander Gordeev 		limit = min_t(unsigned long, limit, uv_info.max_sec_stor_addr);
6157ad19bcSAlexander Gordeev 	return limit;
620c4f2623SVasily Gorbik }
6342c89439SAlexander Egorenkov 
is_prot_virt_host_capable(void)647f33565bSAlexander Egorenkov static int is_prot_virt_host_capable(void)
657f33565bSAlexander Egorenkov {
667f33565bSAlexander Egorenkov 	/* disable if no prot_virt=1 given on command-line */
677f33565bSAlexander Egorenkov 	if (!is_prot_virt_host())
687f33565bSAlexander Egorenkov 		return 0;
697f33565bSAlexander Egorenkov 	/* disable if protected guest virtualization is enabled */
707f33565bSAlexander Egorenkov 	if (is_prot_virt_guest())
717f33565bSAlexander Egorenkov 		return 0;
727f33565bSAlexander Egorenkov 	/* disable if no hardware support */
737f33565bSAlexander Egorenkov 	if (!test_facility(158))
747f33565bSAlexander Egorenkov 		return 0;
757f33565bSAlexander Egorenkov 	/* disable if kdump */
76e9e7870fSAlexander Egorenkov 	if (oldmem_data.start)
777f33565bSAlexander Egorenkov 		return 0;
787f33565bSAlexander Egorenkov 	/* disable if stand-alone dump */
797f33565bSAlexander Egorenkov 	if (ipl_block_valid && is_ipl_block_dump())
807f33565bSAlexander Egorenkov 		return 0;
817f33565bSAlexander Egorenkov 	return 1;
827f33565bSAlexander Egorenkov }
837f33565bSAlexander Egorenkov 
sanitize_prot_virt_host(void)8442c89439SAlexander Egorenkov void sanitize_prot_virt_host(void)
8542c89439SAlexander Egorenkov {
867f33565bSAlexander Egorenkov 	prot_virt_host = is_prot_virt_host_capable();
8742c89439SAlexander Egorenkov }
88