Skip to content

Commit 626f000

Browse files
committed
handlers: handle leaf 40000004 on Xen
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
1 parent 667fb94 commit 626f000

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

‎feature.c‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,19 @@ static const struct cpu_feature_t features [] = {
634634
/* { 0x40000003, 0, REG_EDX, 0x80000000, , ""}, */ /* Reserved */
635635

636636
/* Hypervisor implementation recommendations (4000_0004h) */
637+
{ 0x40000004, 0, REG_EAX, 0x00000001, VENDOR_HV_XEN , "Virtualized APIC registers"},
637638
{ 0x40000004, 0, REG_EAX, 0x00000001, VENDOR_HV_HYPERV , "Hypercall for address space switches"},
639+
{ 0x40000004, 0, REG_EAX, 0x00000002, VENDOR_HV_XEN , "Virtualized x2APIC accesses"},
638640
{ 0x40000004, 0, REG_EAX, 0x00000002, VENDOR_HV_HYPERV , "Hypercall for local TLB flushes"},
641+
{ 0x40000004, 0, REG_EAX, 0x00000004, VENDOR_HV_XEN , "IOMMU mappings"},
639642
{ 0x40000004, 0, REG_EAX, 0x00000004, VENDOR_HV_HYPERV , "Hypercall for remote TLB flushes"},
643+
{ 0x40000004, 0, REG_EAX, 0x00000008, VENDOR_HV_XEN , "VCPU ID present in 40000004:EBX"},
640644
{ 0x40000004, 0, REG_EAX, 0x00000008, VENDOR_HV_HYPERV , "MSRs for accessing APIC registers"},
645+
{ 0x40000004, 0, REG_EAX, 0x00000010, VENDOR_HV_XEN , "Domain ID present in 40000004:ECX"},
641646
{ 0x40000004, 0, REG_EAX, 0x00000010, VENDOR_HV_HYPERV , "Hypervisor MSR for system RESET"},
647+
{ 0x40000004, 0, REG_EAX, 0x00000020, VENDOR_HV_XEN , "Extended APIC destination ID"},
642648
{ 0x40000004, 0, REG_EAX, 0x00000020, VENDOR_HV_HYPERV , "Relaxed timing"},
649+
{ 0x40000004, 0, REG_EAX, 0x00000040, VENDOR_HV_XEN , "Per-vCPU event channel upcalls with PIRQs"},
643650
{ 0x40000004, 0, REG_EAX, 0x00000040, VENDOR_HV_HYPERV , "DMA remapping"},
644651
{ 0x40000004, 0, REG_EAX, 0x00000080, VENDOR_HV_HYPERV , "Interrupt remapping"},
645652
{ 0x40000004, 0, REG_EAX, 0x00000100, VENDOR_HV_HYPERV , "x2APIC MSRs"},
@@ -1312,16 +1319,26 @@ int print_features(const struct cpu_regs_t *regs, struct cpuid_state_t *state)
13121319
reg_name(last_reg));
13131320
break;
13141321
case 0x40000004:
1315-
printf("Hyper-V implementation recommendations, %s:\n",
1316-
reg_name(last_reg));
1322+
if (state->vendor & VENDOR_HV_XEN) {
1323+
printf("Xen HVM-specific features, %s:\n", reg_name(last_reg));
1324+
1325+
/* We only look at EAX for this leaf. */
1326+
accounting.ebx = 0;
1327+
accounting.ecx = 0;
1328+
accounting.edx = 0;
1329+
} else if (state->vendor & VENDOR_HV_HYPERV) {
1330+
printf("Hyper-V implementation recommendations, %s:\n",
1331+
reg_name(last_reg));
13171332

1318-
/* EBX doesn't contain feature bits. We should zero these
1319-
* out so they don't appear to be unaccounted for.
1320-
*/
1321-
accounting.ebx = 0;
1333+
/* EBX doesn't contain feature bits. We should zero these
1334+
* out so they don't appear to be unaccounted for.
1335+
*/
1336+
accounting.ebx = 0;
1337+
1338+
/* ECX[0:6] are not feature bits. */
1339+
accounting.ecx &= ~0x3f;
1340+
}
13221341

1323-
/* ECX[0:6] are not feature bits. */
1324-
accounting.ecx &= ~0x3f;
13251342
break;
13261343
case 0x40000006:
13271344
printf("Hyper-V hardware features detected and in use, %s:\n",

‎handlers.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,8 +2315,10 @@ static void handle_vmm_leaf03(struct cpu_regs_t *regs, struct cpuid_state_t *sta
23152315
break;
23162316
case 1:
23172317
printf(" TSC offset: 0x%08x%08x\n", regs->ebx, regs->eax);
2318-
if (regs->ecx && regs->edx)
2319-
printf(" TSC ns conversion: (n * 0x%0x) >> %08x\n", regs->ecx, regs->edx);
2318+
if (regs->ecx)
2319+
printf(" TSC multiplier for ns conversion: 0x%08x\n", regs->ecx);
2320+
if (regs->edx)
2321+
printf(" TSC shift for ns conversion: 0x%08x\n", regs->edx);
23202322
break;
23212323
case 2:
23222324
if (regs->eax)
@@ -2336,7 +2338,17 @@ static void handle_vmm_leaf03(struct cpu_regs_t *regs, struct cpuid_state_t *sta
23362338
/* EAX = 4000 0004 */
23372339
static void handle_vmm_leaf04(struct cpu_regs_t *regs, struct cpuid_state_t *state)
23382340
{
2339-
if (state->vendor & VENDOR_HV_HYPERV) {
2341+
if (state->vendor & VENDOR_HV_XEN) {
2342+
print_features(regs, state);
2343+
if (regs->eax & ((1u << 3) | (1u << 4))) {
2344+
printf("Xen HVM domain info:\n");
2345+
if (regs->eax & (1u << 3))
2346+
printf(" VCPU ID: %d\n", regs->ebx);
2347+
if (regs->eax & (1u << 4))
2348+
printf(" Domain ID: %d\n", regs->ecx);
2349+
}
2350+
printf("\n");
2351+
} else if (state->vendor & VENDOR_HV_HYPERV) {
23402352
struct ecx_addressing {
23412353
unsigned physbits:7;
23422354
unsigned reserved:25;

0 commit comments

Comments
 (0)