Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Change cpuid 1, 4 and 0x80000008 returned values according to number
Browse files Browse the repository at this point in the history
of virtual CPUs

Signed-off-by: Alexey Romko <[email protected]>
  • Loading branch information
nevilad committed Mar 14, 2020
1 parent 7f3aaab commit 3a0654a
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions core/vcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,16 @@ static void handle_cpuid_virtual(struct vcpu_t *vcpu, uint32_t a, uint32_t c)
uint32_t reserved2 : 4;
};
} cpuid_eax;
struct vm_t *vm = vcpu->vm;
hax_list_head *list;
int vcpu_count = 0;

hax_mutex_lock(vm->vm_lock);
hax_list_for_each(list, (hax_list_head *)(&vm->vcpu_list)) {
vcpu_count++;
}
hax_mutex_unlock(vm->vm_lock);

cpuid_eax.raw = state->_eax;

if (0xF != cpuid_eax.familyID)
Expand Down Expand Up @@ -2651,6 +2661,9 @@ static void handle_cpuid_virtual(struct vcpu_t *vcpu, uint32_t a, uint32_t c)
// (see IA SDM Vol. 3A 3.2, Table 3-14)
0x00;

if (vcpu_count > 1)
state->_ebx |= (vcpu_count) << 16;

// Report only the features specified, excluding any features not
// supported by the host CPU, but including "hypervisor", which is
// desirable for VMMs.
Expand All @@ -2673,8 +2686,23 @@ static void handle_cpuid_virtual(struct vcpu_t *vcpu, uint32_t a, uint32_t c)
return;
}
case 4: { // Deterministic Cache Parameters
// [31:26] cores per package - 1
// Use host cache values.
// Use host cache values, but change maximum number of addresable
// IDs according to the number of virtual CPUs (bits [31:26]).
state->_eax &= ~0xFC000000;
if (state->_eax & 31) {
struct vm_t *vm = vcpu->vm;
hax_list_head *list;
int vcpu_count = 0;

hax_mutex_lock(vm->vm_lock);
hax_list_for_each(list, (hax_list_head *)(&vm->vcpu_list)) {
vcpu_count++;
}
hax_mutex_unlock(vm->vm_lock);

if (vcpu_count > 1)
state->_eax |= (vcpu_count - 1) << 26;
}
return;
}
case 5: // MONITOR/MWAIT
Expand Down Expand Up @@ -2772,13 +2800,26 @@ static void handle_cpuid_virtual(struct vcpu_t *vcpu, uint32_t a, uint32_t c)
return;
}
case 0x80000008: { // Virtual/Physical Address Size
struct vm_t *vm = vcpu->vm;
hax_list_head *list;
int vcpu_count = 0;

hax_mutex_lock(vm->vm_lock);
hax_list_for_each(list, (hax_list_head *)(&vm->vcpu_list)) {
vcpu_count++;
}
hax_mutex_unlock(vm->vm_lock);

// Bit mask to identify the reserved bits in paging structure high
// order address field
physical_address_size = (uint8_t)state->_eax & 0xff;
pw_reserved_bits_high_mask =
~((1 << (physical_address_size - 32)) - 1);

state->_ebx = state->_ecx = state->_edx = 0;

if (vcpu_count > 1)
state->_ecx |= vcpu_count - 1;
return;
}
}
Expand Down

0 comments on commit 3a0654a

Please sign in to comment.