win-pvdrivers
changeset 1093:5be1f70687ad
Refactor xenpci init to fix a bug when drivers are installed on a non-xen machine
author | James Harper <james.harper@bendigoit.com.au> |
---|---|
date | Mon Jan 13 20:24:56 2014 +1100 (2014-01-13) |
parents | 85b99b9795a6 |
children | 64ddfb914cd9 |
files | xenpci/xenpci.c xenpci/xenpci_export.c xenpci/xenpci_fdo.c |
line diff
1.1 --- a/xenpci/xenpci.c Sat Jan 04 18:17:51 2014 +1100 1.2 +++ b/xenpci/xenpci.c Mon Jan 13 20:24:56 2014 +1100 1.3 @@ -377,7 +377,9 @@ XenPci_EvtDeviceAdd_XenHide(WDFDRIVER dr 1.4 static NTSTATUS 1.5 XenPci_EvtDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init) 1.6 { 1.7 - if (XenPci_IdSuffixMatches(device_init, L"VEN_5853&DEV_0001")) { 1.8 + if (!hypercall_stubs) { 1.9 + return STATUS_SUCCESS; 1.10 + } else if (XenPci_IdSuffixMatches(device_init, L"VEN_5853&DEV_0001")) { 1.11 FUNCTION_MSG("Xen PCI device found - must be fdo\n"); 1.12 return XenPci_EvtDeviceAdd_XenPci(driver, device_init); 1.13 } else if (WdfCollectionGetCount(qemu_hide_devices) > 0) { 1.14 @@ -551,19 +553,9 @@ XenPci_FixLoadOrder() 1.15 return; 1.16 } 1.17 1.18 -VOID 1.19 -XenPci_EvtDriverUnload(WDFDRIVER driver) 1.20 -{ 1.21 - UNREFERENCED_PARAMETER(driver); 1.22 - 1.23 -// #if DBG 1.24 -// XenPci_UnHookDbgPrint(); 1.25 -// #endif 1.26 -} 1.27 - 1.28 #if (NTDDI_VERSION >= NTDDI_WS03SP1) 1.29 /* this isn't freed on shutdown... perhaps it should be */ 1.30 -static PUCHAR dump_header; 1.31 +static PUCHAR dump_header = NULL; 1.32 static ULONG dump_header_size; 1.33 static ULONG dump_header_refreshed_flag = FALSE; 1.34 static KBUGCHECK_REASON_CALLBACK_RECORD callback_record; 1.35 @@ -589,6 +581,87 @@ XenPci_DebugHeaderDumpIoCallback( 1.36 } 1.37 } 1.38 #endif 1.39 + 1.40 +#define XEN_SIGNATURE_LOWER 0x40000000 1.41 +#define XEN_SIGNATURE_UPPER 0x4000FFFF 1.42 + 1.43 +USHORT xen_version_major = (USHORT)-1; 1.44 +USHORT xen_version_minor = (USHORT)-1; 1.45 +PVOID hypercall_stubs = NULL; 1.46 + 1.47 +static VOID 1.48 +XenPCI_GetHypercallStubs() { 1.49 + ULONG base; 1.50 + DWORD32 cpuid_output[4]; 1.51 + char xensig[13]; 1.52 + ULONG i; 1.53 + ULONG pages; 1.54 + ULONG msr; 1.55 + 1.56 + if (hypercall_stubs) { 1.57 + FUNCTION_MSG("hypercall_stubs already set\n"); 1.58 + return; 1.59 + } 1.60 + 1.61 + for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100) { 1.62 + __cpuid(cpuid_output, base); 1.63 + *(ULONG*)(xensig + 0) = cpuid_output[1]; 1.64 + *(ULONG*)(xensig + 4) = cpuid_output[2]; 1.65 + *(ULONG*)(xensig + 8) = cpuid_output[3]; 1.66 + xensig[12] = '\0'; 1.67 + FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]); 1.68 + if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2)) 1.69 + break; 1.70 + } 1.71 + if (base >= XEN_SIGNATURE_UPPER) { 1.72 + FUNCTION_MSG("Cannot find Xen signature\n"); 1.73 + return; 1.74 + } 1.75 + 1.76 + __cpuid(cpuid_output, base + 1); 1.77 + xen_version_major = (USHORT)(cpuid_output[0] >> 16); 1.78 + xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF); 1.79 + FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor); 1.80 + 1.81 + __cpuid(cpuid_output, base + 2); 1.82 + pages = cpuid_output[0]; 1.83 + msr = cpuid_output[1]; 1.84 + 1.85 + hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG); 1.86 + FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs); 1.87 + 1.88 + if (!hypercall_stubs) 1.89 + return; 1.90 + for (i = 0; i < pages; i++) { 1.91 + ULONGLONG pfn; 1.92 + pfn = (MmGetPhysicalAddress((PUCHAR)hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT); 1.93 + __writemsr(msr, (pfn << PAGE_SHIFT) + i); 1.94 + } 1.95 +} 1.96 + 1.97 +static VOID 1.98 +XenPCI_FreeHypercallStubs() { 1.99 + if (hypercall_stubs) { 1.100 + ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG); 1.101 + } 1.102 + hypercall_stubs = NULL; 1.103 +} 1.104 + 1.105 +VOID 1.106 +XenPci_EvtDriverUnload(WDFDRIVER driver) { 1.107 + UNREFERENCED_PARAMETER(driver); 1.108 + 1.109 + FUNCTION_ENTER(); 1.110 + 1.111 +#if (NTDDI_VERSION >= NTDDI_WS03SP1) 1.112 + KeDeregisterBugCheckReasonCallback(&callback_record); 1.113 + if (dump_header) { 1.114 + MmFreeContiguousMemory(dump_header); 1.115 + } 1.116 +#endif 1.117 + FUNCTION_EXIT(); 1.118 +} 1.119 + 1.120 1.121 NTSTATUS 1.122 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) 1.123 @@ -619,127 +692,128 @@ DriverEntry(PDRIVER_OBJECT DriverObject, 1.124 1.125 FUNCTION_MSG(__DRIVER_NAME " " VER_FILEVERSION_STR "\n"); 1.126 1.127 + XenPCI_GetHypercallStubs(); 1.128 + 1.129 #if (NTDDI_VERSION >= NTDDI_WS03SP1) 1.130 - status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, NULL, 0, &dump_header_size); 1.131 - /* try and allocate contiguous memory as low as possible */ 1.132 - dump_header = NULL; 1.133 - dump_header_mem_max.QuadPart = 0xFFFFF; 1.134 - while (!dump_header && dump_header_mem_max.QuadPart != 0xFFFFFFFFFFFFFFFF) { 1.135 - dump_header = MmAllocateContiguousMemory(DUMP_HEADER_PREFIX_SIZE + dump_header_size + DUMP_HEADER_SUFFIX_SIZE, dump_header_mem_max); 1.136 - if (dump_header) { 1.137 - FUNCTION_MSG("Allocated crash dump header < 0x%016I64x\n", dump_header_mem_max.QuadPart); 1.138 - break; 1.139 + if (hypercall_stubs) { 1.140 + status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, NULL, 0, &dump_header_size); 1.141 + /* try and allocate contiguous memory as low as possible */ 1.142 + dump_header_mem_max.QuadPart = 0xFFFFF; 1.143 + while (!dump_header && dump_header_mem_max.QuadPart != 0xFFFFFFFFFFFFFFFF) { 1.144 + dump_header = MmAllocateContiguousMemory(DUMP_HEADER_PREFIX_SIZE + dump_header_size + DUMP_HEADER_SUFFIX_SIZE, dump_header_mem_max); 1.145 + if (dump_header) { 1.146 + FUNCTION_MSG("Allocated crash dump header < 0x%016I64x\n", dump_header_mem_max.QuadPart); 1.147 + break; 1.148 + } 1.149 + dump_header_mem_max.QuadPart = (dump_header_mem_max.QuadPart << 4) | 0xF; 1.150 } 1.151 - dump_header_mem_max.QuadPart = (dump_header_mem_max.QuadPart << 4) | 0xF; 1.152 - } 1.153 - if (dump_header) { 1.154 - status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, dump_header + DUMP_HEADER_PREFIX_SIZE, dump_header_size, &dump_header_size); 1.155 - FUNCTION_MSG("KeInitializeCrashDumpHeader status = %08x, size = %d\n", status, dump_header_size); 1.156 - memcpy(dump_header + 0, "XENXEN", 6); /* magic number */ 1.157 - *(PUSHORT)(dump_header + 6) = (USHORT)(INT_PTR)dump_header & (PAGE_SIZE - 1); /* store offset too as additional verification */ 1.158 - memcpy(dump_header + DUMP_HEADER_PREFIX_SIZE + dump_header_size, "XENXEN", 6); 1.159 - *(PUSHORT)(dump_header + DUMP_HEADER_PREFIX_SIZE + dump_header_size + 6) = (USHORT)(INT_PTR)dump_header & (PAGE_SIZE - 1); /* store offset too as additional verification */ 1.160 - KeInitializeCallbackRecord(&callback_record); 1.161 - KeRegisterBugCheckReasonCallback(&callback_record, XenPci_DebugHeaderDumpIoCallback, KbCallbackDumpIo, (PUCHAR)"XenPci_DebugHeaderDumpIoCallback"); 1.162 - } else { 1.163 - FUNCTION_MSG("Failed to allocate memory for crash dump header\n"); 1.164 + if (dump_header) { 1.165 + status = KeInitializeCrashDumpHeader(DUMP_TYPE_FULL, 0, dump_header + DUMP_HEADER_PREFIX_SIZE, dump_header_size, &dump_header_size); 1.166 + FUNCTION_MSG("KeInitializeCrashDumpHeader status = %08x, size = %d\n", status, dump_header_size); 1.167 + memcpy(dump_header + 0, "XENXEN", 6); /* magic number */ 1.168 + *(PUSHORT)(dump_header + 6) = (USHORT)(INT_PTR)dump_header & (PAGE_SIZE - 1); /* store offset too as additional verification */ 1.169 + memcpy(dump_header + DUMP_HEADER_PREFIX_SIZE + dump_header_size, "XENXEN", 6); 1.170 + *(PUSHORT)(dump_header + DUMP_HEADER_PREFIX_SIZE + dump_header_size + 6) = (USHORT)(INT_PTR)dump_header & (PAGE_SIZE - 1); /* store offset too as additional verification */ 1.171 + KeInitializeCallbackRecord(&callback_record); 1.172 + KeRegisterBugCheckReasonCallback(&callback_record, XenPci_DebugHeaderDumpIoCallback, KbCallbackDumpIo, (PUCHAR)"XenPci_DebugHeaderDumpIoCallback"); 1.173 + } else { 1.174 + FUNCTION_MSG("Failed to allocate memory for crash dump header\n"); 1.175 + } 1.176 } 1.177 #endif 1.178 - 1.179 WDF_DRIVER_CONFIG_INIT(&config, XenPci_EvtDeviceAdd); 1.180 config.EvtDriverUnload = XenPci_EvtDriverUnload; 1.181 status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, &driver); 1.182 if (!NT_SUCCESS(status)) { 1.183 FUNCTION_MSG("WdfDriverCreate failed with status 0x%x\n", status); 1.184 FUNCTION_EXIT(); 1.185 - //#if DBG 1.186 - //XenPci_UnHookDbgPrint(); 1.187 - //#endif 1.188 return status; 1.189 } 1.190 - WDF_OBJECT_ATTRIBUTES_INIT(&parent_attributes); 1.191 - parent_attributes.ParentObject = driver; 1.192 - 1.193 - status = WdfDriverOpenParametersRegistryKey(driver, KEY_QUERY_VALUE, &parent_attributes, ¶m_key); 1.194 - if (!NT_SUCCESS(status)) { 1.195 - FUNCTION_MSG("Error opening parameters key %08x\n", status); 1.196 - goto error; 1.197 - } 1.198 - 1.199 - status = AuxKlibInitialize(); 1.200 - if(!NT_SUCCESS(status)) { 1.201 - FUNCTION_MSG("AuxKlibInitialize failed %08x\n", status); 1.202 - goto error; 1.203 - } 1.204 - 1.205 - XenPci_FixLoadOrder(); 1.206 + if (hypercall_stubs) { 1.207 + WDF_OBJECT_ATTRIBUTES_INIT(&parent_attributes); 1.208 + parent_attributes.ParentObject = driver; 1.209 + 1.210 + status = WdfDriverOpenParametersRegistryKey(driver, KEY_QUERY_VALUE, &parent_attributes, ¶m_key); 1.211 + if (!NT_SUCCESS(status)) { 1.212 + FUNCTION_MSG("Error opening parameters key %08x\n", status); 1.213 + goto error; 1.214 + } 1.215 1.216 - RtlInitUnicodeString(&system_start_options, L"failed to read"); 1.217 - status = WdfRegistryOpenKey(NULL, &control_key_name, GENERIC_READ, &parent_attributes, &control_key); 1.218 - if (NT_SUCCESS(status)) { 1.219 - status = WdfStringCreate(NULL, &parent_attributes, &wdf_system_start_options); 1.220 - status = WdfRegistryQueryString(control_key, &system_start_options_name, wdf_system_start_options); 1.221 - if (NT_SUCCESS(status)) 1.222 - WdfStringGetUnicodeString(wdf_system_start_options, &system_start_options); 1.223 - } 1.224 - WdfRegistryClose(control_key); 1.225 + status = AuxKlibInitialize(); 1.226 + if(!NT_SUCCESS(status)) { 1.227 + FUNCTION_MSG("AuxKlibInitialize failed %08x\n", status); 1.228 + goto error; 1.229 + } 1.230 + 1.231 + XenPci_FixLoadOrder(); 1.232 1.233 - FUNCTION_MSG("SystemStartOptions = %wZ\n", &system_start_options); 1.234 - 1.235 - always_patch = 0; 1.236 - WdfRegistryQueryULong(param_key, &txt_always_patch_name, &always_patch); 1.237 - if (always_patch || (system_start_options.Buffer && wcsstr(system_start_options.Buffer, L"PATCHTPR"))) { 1.238 - DECLARE_CONST_UNICODE_STRING(verifier_key_name, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"); 1.239 - WDFKEY memory_key; 1.240 - ULONG verifier_value; 1.241 - 1.242 - FUNCTION_MSG("PATCHTPR found\n"); 1.243 + RtlInitUnicodeString(&system_start_options, L"failed to read"); 1.244 + status = WdfRegistryOpenKey(NULL, &control_key_name, GENERIC_READ, &parent_attributes, &control_key); 1.245 + if (NT_SUCCESS(status)) { 1.246 + status = WdfStringCreate(NULL, &parent_attributes, &wdf_system_start_options); 1.247 + status = WdfRegistryQueryString(control_key, &system_start_options_name, wdf_system_start_options); 1.248 + if (NT_SUCCESS(status)) 1.249 + WdfStringGetUnicodeString(wdf_system_start_options, &system_start_options); 1.250 + } 1.251 + WdfRegistryClose(control_key); 1.252 + 1.253 + FUNCTION_MSG("SystemStartOptions = %wZ\n", &system_start_options); 1.254 1.255 - tpr_patch_requested = TRUE; 1.256 - status = WdfRegistryOpenKey(NULL, &verifier_key_name, KEY_READ, &parent_attributes, &memory_key); 1.257 - if (NT_SUCCESS(status)) 1.258 - { 1.259 - DECLARE_CONST_UNICODE_STRING(verifier_value_name, L"VerifyDriverLevel"); 1.260 - status = WdfRegistryQueryULong(memory_key, &verifier_value_name, &verifier_value); 1.261 - if (NT_SUCCESS(status) && verifier_value != 0) 1.262 + always_patch = 0; 1.263 + WdfRegistryQueryULong(param_key, &txt_always_patch_name, &always_patch); 1.264 + if (always_patch || (system_start_options.Buffer && wcsstr(system_start_options.Buffer, L"PATCHTPR"))) { 1.265 + DECLARE_CONST_UNICODE_STRING(verifier_key_name, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"); 1.266 + WDFKEY memory_key; 1.267 + ULONG verifier_value; 1.268 + 1.269 + FUNCTION_MSG("PATCHTPR found\n"); 1.270 + 1.271 + tpr_patch_requested = TRUE; 1.272 + status = WdfRegistryOpenKey(NULL, &verifier_key_name, KEY_READ, &parent_attributes, &memory_key); 1.273 + if (NT_SUCCESS(status)) 1.274 { 1.275 - FUNCTION_MSG("Verifier active - not patching\n"); 1.276 - tpr_patch_requested = FALSE; 1.277 + DECLARE_CONST_UNICODE_STRING(verifier_value_name, L"VerifyDriverLevel"); 1.278 + status = WdfRegistryQueryULong(memory_key, &verifier_value_name, &verifier_value); 1.279 + if (NT_SUCCESS(status) && verifier_value != 0) 1.280 + { 1.281 + FUNCTION_MSG("Verifier active - not patching\n"); 1.282 + tpr_patch_requested = FALSE; 1.283 + } 1.284 + WdfRegistryClose(memory_key); 1.285 } 1.286 - WdfRegistryClose(memory_key); 1.287 } 1.288 - } 1.289 1.290 - WdfCollectionCreate(&parent_attributes, &qemu_hide_devices); 1.291 - WdfRegistryQueryULong(param_key, &txt_always_hide_name, &always_hide); 1.292 - conf_info = IoGetConfigurationInformation(); 1.293 - if (always_hide || ((conf_info == NULL || conf_info->DiskCount == 0) 1.294 - && !(system_start_options.Buffer && wcsstr(system_start_options.Buffer, L"NOGPLPV")) 1.295 - && !*InitSafeBootMode)) { 1.296 - if (!(system_start_options.Buffer && wcsstr(system_start_options.Buffer, L"GPLPVUSEFILTERHIDE")) && XenPci_CheckHideQemuDevices()) { 1.297 - DECLARE_CONST_UNICODE_STRING(qemu_hide_flags_name, L"qemu_hide_flags"); 1.298 - DECLARE_CONST_UNICODE_STRING(txt_qemu_hide_flags_name, L"txt_qemu_hide_flags"); 1.299 - WDFCOLLECTION qemu_hide_flags; 1.300 - ULONG i; 1.301 + WdfCollectionCreate(&parent_attributes, &qemu_hide_devices); 1.302 + WdfRegistryQueryULong(param_key, &txt_always_hide_name, &always_hide); 1.303 + conf_info = IoGetConfigurationInformation(); 1.304 + if (always_hide || ((conf_info == NULL || conf_info->DiskCount == 0) 1.305 + && !(system_start_options.Buffer && wcsstr(system_start_options.Buffer, L"NOGPLPV")) 1.306 + && !*InitSafeBootMode)) { 1.307 + if (!(system_start_options.Buffer && wcsstr(system_start_options.Buffer, L"GPLPVUSEFILTERHIDE")) && XenPci_CheckHideQemuDevices()) { 1.308 + DECLARE_CONST_UNICODE_STRING(qemu_hide_flags_name, L"qemu_hide_flags"); 1.309 + DECLARE_CONST_UNICODE_STRING(txt_qemu_hide_flags_name, L"txt_qemu_hide_flags"); 1.310 + WDFCOLLECTION qemu_hide_flags; 1.311 + ULONG i; 1.312 1.313 - WdfCollectionCreate(&parent_attributes, &qemu_hide_flags); 1.314 - WdfRegistryQueryMultiString(param_key, &qemu_hide_flags_name, &parent_attributes, qemu_hide_flags); 1.315 - WdfRegistryQueryMultiString(param_key, &txt_qemu_hide_flags_name, &parent_attributes, qemu_hide_flags); 1.316 - for (i = 0; i < WdfCollectionGetCount(qemu_hide_flags); i++) { 1.317 - ULONG value; 1.318 - WDFSTRING wdf_string = WdfCollectionGetItem(qemu_hide_flags, i); 1.319 - UNICODE_STRING unicode_string; 1.320 - WdfStringGetUnicodeString(wdf_string, &unicode_string); 1.321 - status = RtlUnicodeStringToInteger(&unicode_string, 0, &value); 1.322 - qemu_hide_flags_value |= value; 1.323 + WdfCollectionCreate(&parent_attributes, &qemu_hide_flags); 1.324 + WdfRegistryQueryMultiString(param_key, &qemu_hide_flags_name, &parent_attributes, qemu_hide_flags); 1.325 + WdfRegistryQueryMultiString(param_key, &txt_qemu_hide_flags_name, &parent_attributes, qemu_hide_flags); 1.326 + for (i = 0; i < WdfCollectionGetCount(qemu_hide_flags); i++) { 1.327 + ULONG value; 1.328 + WDFSTRING wdf_string = WdfCollectionGetItem(qemu_hide_flags, i); 1.329 + UNICODE_STRING unicode_string; 1.330 + WdfStringGetUnicodeString(wdf_string, &unicode_string); 1.331 + status = RtlUnicodeStringToInteger(&unicode_string, 0, &value); 1.332 + qemu_hide_flags_value |= value; 1.333 + } 1.334 + WdfObjectDelete(qemu_hide_flags); 1.335 + XenPci_HideQemuDevices(); 1.336 + } else { 1.337 + WdfRegistryQueryMultiString(param_key, &hide_devices_name, &parent_attributes, qemu_hide_devices); 1.338 } 1.339 - WdfObjectDelete(qemu_hide_flags); 1.340 - XenPci_HideQemuDevices(); 1.341 - } else { 1.342 - WdfRegistryQueryMultiString(param_key, &hide_devices_name, &parent_attributes, qemu_hide_devices); 1.343 } 1.344 + WdfRegistryClose(param_key); 1.345 } 1.346 - WdfRegistryClose(param_key); 1.347 FUNCTION_EXIT(); 1.348 return STATUS_SUCCESS; 1.349
2.1 --- a/xenpci/xenpci_export.c Sat Jan 04 18:17:51 2014 +1100 2.2 +++ b/xenpci/xenpci_export.c Mon Jan 13 20:24:56 2014 +1100 2.3 @@ -402,8 +402,6 @@ XnGetValue(XN_HANDLE handle, ULONG value 2.4 } 2.5 } 2.6 2.7 -//externPVOID hypercall_stubs = NULL; 2.8 - 2.9 PVOID 2.10 XnGetHypercallStubs() { 2.11 return hypercall_stubs;
3.1 --- a/xenpci/xenpci_fdo.c Sat Jan 04 18:17:51 2014 +1100 3.2 +++ b/xenpci/xenpci_fdo.c Mon Jan 13 20:24:56 2014 +1100 3.3 @@ -33,69 +33,6 @@ static EVT_WDF_WORKITEM XenPci_SuspendRe 3.4 static KSTART_ROUTINE XenPci_BalloonThreadProc; 3.5 #endif 3.6 3.7 -#define XEN_SIGNATURE_LOWER 0x40000000 3.8 -#define XEN_SIGNATURE_UPPER 0x4000FFFF 3.9 - 3.10 -USHORT xen_version_major = (USHORT)-1; 3.11 -USHORT xen_version_minor = (USHORT)-1; 3.12 -PVOID hypercall_stubs = NULL; 3.13 - 3.14 -static VOID 3.15 -hvm_get_hypercall_stubs() { 3.16 - ULONG base; 3.17 - DWORD32 cpuid_output[4]; 3.18 - char xensig[13]; 3.19 - ULONG i; 3.20 - ULONG pages; 3.21 - ULONG msr; 3.22 - 3.23 - if (hypercall_stubs) { 3.24 - FUNCTION_MSG("hypercall_stubs alread set\n"); 3.25 - return; 3.26 - } 3.27 - 3.28 - for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100) { 3.29 - __cpuid(cpuid_output, base); 3.30 - *(ULONG*)(xensig + 0) = cpuid_output[1]; 3.31 - *(ULONG*)(xensig + 4) = cpuid_output[2]; 3.32 - *(ULONG*)(xensig + 8) = cpuid_output[3]; 3.33 - xensig[12] = '\0'; 3.34 - FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]); 3.35 - if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2)) 3.36 - break; 3.37 - } 3.38 - if (base == XEN_SIGNATURE_UPPER) { 3.39 - FUNCTION_MSG("Cannot find Xen signature\n"); 3.40 - return; 3.41 - } 3.42 - 3.43 - __cpuid(cpuid_output, base + 1); 3.44 - xen_version_major = (USHORT)(cpuid_output[0] >> 16); 3.45 - xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF); 3.46 - FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor); 3.47 - 3.48 - __cpuid(cpuid_output, base + 2); 3.49 - pages = cpuid_output[0]; 3.50 - msr = cpuid_output[1]; 3.51 - 3.52 - hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG); 3.53 - FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs); 3.54 - 3.55 - if (!hypercall_stubs) 3.56 - return; 3.57 - for (i = 0; i < pages; i++) { 3.58 - ULONGLONG pfn; 3.59 - pfn = (MmGetPhysicalAddress((PUCHAR)hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT); 3.60 - __writemsr(msr, (pfn << PAGE_SHIFT) + i); 3.61 - } 3.62 -} 3.63 - 3.64 -static VOID 3.65 -hvm_free_hypercall_stubs() { 3.66 - ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG); 3.67 - hypercall_stubs = NULL; 3.68 -} 3.69 - 3.70 static VOID 3.71 XenPci_MapHalThenPatchKernel(PXENPCI_DEVICE_DATA xpdd) 3.72 { 3.73 @@ -175,11 +112,6 @@ XenPci_Init(PXENPCI_DEVICE_DATA xpdd) 3.74 FUNCTION_ENTER(); 3.75 3.76 if (!hypercall_stubs) 3.77 - { 3.78 - XN_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL); 3.79 - hvm_get_hypercall_stubs(); 3.80 - } 3.81 - if (!hypercall_stubs) 3.82 return STATUS_UNSUCCESSFUL; 3.83 3.84 if (!xpdd->shared_info_area)