Browse Source

hv_vcpu_create: support PAC updates

osy 2 years ago
parent
commit
306fb7eca0
1 changed files with 12 additions and 1 deletions
  1. 12 1
      hv.m

+ 12 - 1
hv.m

@@ -205,7 +205,14 @@ struct hv_vcpu_create_kernel_args {
 // ' hyp', 0xe
 // ' hyp', 0xe
 static const uint64_t kHvVcpuMagic = 0x206879700000000eull;
 static const uint64_t kHvVcpuMagic = 0x206879700000000eull;
 
 
+struct hv_vcpu_config_private {
+  char field_0[16];
+  uint64_t vmkeylo_el2;
+  uint64_t vmkeyhi_el2;
+};
+
 hv_return_t hv_vcpu_create(hv_vcpu_t* vcpu, hv_vcpu_exit_t** exit, hv_vcpu_config_t config) {
 hv_return_t hv_vcpu_create(hv_vcpu_t* vcpu, hv_vcpu_exit_t** exit, hv_vcpu_config_t config) {
+  struct hv_vcpu_config_private *_config = (struct hv_vcpu_config_private *)config;
   pthread_mutex_lock(&vcpus_mutex);
   pthread_mutex_lock(&vcpus_mutex);
   hv_vcpu_t cpuid = 0;
   hv_vcpu_t cpuid = 0;
   for (; cpuid < kHvMaxVcpus; cpuid++) {
   for (; cpuid < kHvMaxVcpus; cpuid++) {
@@ -249,7 +256,11 @@ hv_return_t hv_vcpu_create(hv_vcpu_t* vcpu, hv_vcpu_exit_t** exit, hv_vcpu_confi
     hv_vcpu_destroy(cpuid);
     hv_vcpu_destroy(cpuid);
     return err;
     return err;
   }
   }
-  // TODO(zhuowei): set vmkeyhi_el2/vmkeylo_el2
+
+  if (config) {
+    vcpu_data->vcpu_zone->rw.controls.vmkeylo_el2 = _config->vmkeylo_el2;
+    vcpu_data->vcpu_zone->rw.controls.vmkeyhi_el2 = _config->vmkeyhi_el2;
+  }
 
 
   // Apple traps PMCCNTR_EL0 using this proprietary register, then translates the syndrome.
   // Apple traps PMCCNTR_EL0 using this proprietary register, then translates the syndrome.
   // No, I don't know why Apple doesn't just use HDFGRTR_EL2 or MDCR_EL2
   // No, I don't know why Apple doesn't just use HDFGRTR_EL2 or MDCR_EL2