xref: /linux/arch/s390/boot/uv.c (revision ac640db3a0260541058e95e4acd249cc166cb0eb)
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 */
11ecdc5d84SVasily Gorbik #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
125abb9351SVasily Gorbik int __bootdata_preserved(prot_virt_guest);
13ecdc5d84SVasily Gorbik #endif
141d6671aeSVasily Gorbik #if IS_ENABLED(CONFIG_KVM)
151d6671aeSVasily Gorbik int __bootdata_preserved(prot_virt_host);
161d6671aeSVasily Gorbik #endif
17ecdc5d84SVasily Gorbik struct uv_info __bootdata_preserved(uv_info);
185abb9351SVasily Gorbik 
195abb9351SVasily Gorbik void uv_query_info(void)
205abb9351SVasily Gorbik {
215abb9351SVasily Gorbik 	struct uv_cb_qui uvcb = {
225abb9351SVasily Gorbik 		.header.cmd = UVC_CMD_QUI,
235abb9351SVasily Gorbik 		.header.len = sizeof(uvcb)
245abb9351SVasily Gorbik 	};
255abb9351SVasily Gorbik 
265abb9351SVasily Gorbik 	if (!test_facility(158))
275abb9351SVasily Gorbik 		return;
285abb9351SVasily Gorbik 
2927dc0700SChristian Borntraeger 	/* rc==0x100 means that there is additional data we do not process */
3027dc0700SChristian Borntraeger 	if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc != 0x100)
315abb9351SVasily Gorbik 		return;
325abb9351SVasily Gorbik 
33ecdc5d84SVasily Gorbik 	if (IS_ENABLED(CONFIG_KVM)) {
34ecdc5d84SVasily Gorbik 		memcpy(uv_info.inst_calls_list, uvcb.inst_calls_list, sizeof(uv_info.inst_calls_list));
35ecdc5d84SVasily Gorbik 		uv_info.uv_base_stor_len = uvcb.uv_base_stor_len;
36ecdc5d84SVasily Gorbik 		uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len;
37ecdc5d84SVasily Gorbik 		uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len;
38ecdc5d84SVasily Gorbik 		uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len;
39ecdc5d84SVasily Gorbik 		uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
40ecdc5d84SVasily Gorbik 		uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
41ecdc5d84SVasily Gorbik 		uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
42e82080e1SJanosch Frank 		uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_id;
4385b18d7bSJanosch Frank 		uv_info.uv_feature_indications = uvcb.uv_feature_indications;
44*ac640db3SJanosch Frank 		uv_info.supp_se_hdr_ver = uvcb.supp_se_hdr_versions;
45*ac640db3SJanosch Frank 		uv_info.supp_se_hdr_pcf = uvcb.supp_se_hdr_pcf;
46ecdc5d84SVasily Gorbik 	}
47ecdc5d84SVasily Gorbik 
48ecdc5d84SVasily Gorbik #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
495abb9351SVasily Gorbik 	if (test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list) &&
505abb9351SVasily Gorbik 	    test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list))
515abb9351SVasily Gorbik 		prot_virt_guest = 1;
52ecdc5d84SVasily Gorbik #endif
535abb9351SVasily Gorbik }
540c4f2623SVasily Gorbik 
550c4f2623SVasily Gorbik #if IS_ENABLED(CONFIG_KVM)
560c4f2623SVasily Gorbik void adjust_to_uv_max(unsigned long *vmax)
570c4f2623SVasily Gorbik {
587f33565bSAlexander Egorenkov 	if (is_prot_virt_host() && uv_info.max_sec_stor_addr)
590c4f2623SVasily Gorbik 		*vmax = min_t(unsigned long, *vmax, uv_info.max_sec_stor_addr);
600c4f2623SVasily Gorbik }
6142c89439SAlexander Egorenkov 
627f33565bSAlexander Egorenkov static int is_prot_virt_host_capable(void)
637f33565bSAlexander Egorenkov {
647f33565bSAlexander Egorenkov 	/* disable if no prot_virt=1 given on command-line */
657f33565bSAlexander Egorenkov 	if (!is_prot_virt_host())
667f33565bSAlexander Egorenkov 		return 0;
677f33565bSAlexander Egorenkov 	/* disable if protected guest virtualization is enabled */
687f33565bSAlexander Egorenkov 	if (is_prot_virt_guest())
697f33565bSAlexander Egorenkov 		return 0;
707f33565bSAlexander Egorenkov 	/* disable if no hardware support */
717f33565bSAlexander Egorenkov 	if (!test_facility(158))
727f33565bSAlexander Egorenkov 		return 0;
737f33565bSAlexander Egorenkov 	/* disable if kdump */
74e9e7870fSAlexander Egorenkov 	if (oldmem_data.start)
757f33565bSAlexander Egorenkov 		return 0;
767f33565bSAlexander Egorenkov 	/* disable if stand-alone dump */
777f33565bSAlexander Egorenkov 	if (ipl_block_valid && is_ipl_block_dump())
787f33565bSAlexander Egorenkov 		return 0;
797f33565bSAlexander Egorenkov 	return 1;
807f33565bSAlexander Egorenkov }
817f33565bSAlexander Egorenkov 
8242c89439SAlexander Egorenkov void sanitize_prot_virt_host(void)
8342c89439SAlexander Egorenkov {
847f33565bSAlexander Egorenkov 	prot_virt_host = is_prot_virt_host_capable();
8542c89439SAlexander Egorenkov }
860c4f2623SVasily Gorbik #endif
87