0001
0002 #include <asm/uv.h>
0003 #include <asm/boot_data.h>
0004 #include <asm/facility.h>
0005 #include <asm/sections.h>
0006
0007 #include "boot.h"
0008 #include "uv.h"
0009
0010
0011 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
0012 int __bootdata_preserved(prot_virt_guest);
0013 #endif
0014 #if IS_ENABLED(CONFIG_KVM)
0015 int __bootdata_preserved(prot_virt_host);
0016 #endif
0017 struct uv_info __bootdata_preserved(uv_info);
0018
0019 void uv_query_info(void)
0020 {
0021 struct uv_cb_qui uvcb = {
0022 .header.cmd = UVC_CMD_QUI,
0023 .header.len = sizeof(uvcb)
0024 };
0025
0026 if (!test_facility(158))
0027 return;
0028
0029
0030 if (uv_call(0, (uint64_t)&uvcb) && uvcb.header.rc != 0x100)
0031 return;
0032
0033 if (IS_ENABLED(CONFIG_KVM)) {
0034 memcpy(uv_info.inst_calls_list, uvcb.inst_calls_list, sizeof(uv_info.inst_calls_list));
0035 uv_info.uv_base_stor_len = uvcb.uv_base_stor_len;
0036 uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len;
0037 uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len;
0038 uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len;
0039 uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len;
0040 uv_info.max_sec_stor_addr = ALIGN(uvcb.max_guest_stor_addr, PAGE_SIZE);
0041 uv_info.max_num_sec_conf = uvcb.max_num_sec_conf;
0042 uv_info.max_guest_cpu_id = uvcb.max_guest_cpu_id;
0043 uv_info.uv_feature_indications = uvcb.uv_feature_indications;
0044 uv_info.supp_se_hdr_ver = uvcb.supp_se_hdr_versions;
0045 uv_info.supp_se_hdr_pcf = uvcb.supp_se_hdr_pcf;
0046 uv_info.conf_dump_storage_state_len = uvcb.conf_dump_storage_state_len;
0047 uv_info.conf_dump_finalize_len = uvcb.conf_dump_finalize_len;
0048 uv_info.supp_att_req_hdr_ver = uvcb.supp_att_req_hdr_ver;
0049 uv_info.supp_att_pflags = uvcb.supp_att_pflags;
0050 }
0051
0052 #ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST
0053 if (test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list) &&
0054 test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, (unsigned long *)uvcb.inst_calls_list))
0055 prot_virt_guest = 1;
0056 #endif
0057 }
0058
0059 #if IS_ENABLED(CONFIG_KVM)
0060 unsigned long adjust_to_uv_max(unsigned long limit)
0061 {
0062 if (is_prot_virt_host() && uv_info.max_sec_stor_addr)
0063 limit = min_t(unsigned long, limit, uv_info.max_sec_stor_addr);
0064 return limit;
0065 }
0066
0067 static int is_prot_virt_host_capable(void)
0068 {
0069
0070 if (!is_prot_virt_host())
0071 return 0;
0072
0073 if (is_prot_virt_guest())
0074 return 0;
0075
0076 if (!test_facility(158))
0077 return 0;
0078
0079 if (oldmem_data.start)
0080 return 0;
0081
0082 if (ipl_block_valid && is_ipl_block_dump())
0083 return 0;
0084 return 1;
0085 }
0086
0087 void sanitize_prot_virt_host(void)
0088 {
0089 prot_virt_host = is_prot_virt_host_capable();
0090 }
0091 #endif