Re: Use CPUID to communicate with the hypervisor.
From: Gerd Hoffmann
Date: Mon Sep 29 2008 - 04:29:16 EST
Hi,
> +unsigned long hypervisor_tsc_freq(void)
> +{
> + unsigned long tsc_khz;
> + unsigned int max_cpuid_leaf;
> +
> + if (cpu_has_hypervisor) {
> + max_cpuid_leaf = cpuid_eax(HYPERVISOR_INFO_LEAF);
> + if (max_cpuid_leaf >= HYPERVISOR_TIMING_LEAF) {
> + tsc_khz = cpuid_eax(HYPERVISOR_TIMING_LEAF);
> + printk(KERN_INFO
> + "TSC frequency read from hypervisor\n");
> + return tsc_khz;
> + }
> + }
> + return 0;
> +}
Shouldn't you check the hypervisor signature here?
> /*
> + * Intel & AMD have reserved the cpuid levels 0x40000000 - 0x400000FF for
> + * software use. Hypervisors can use these levels to provide an interface
> + * to pass information from the hypervisor to the guest. This is similar
> + * to how we extract information about a physical cpu by using cpuid.
> + */
> +
> +/*
> + * This CPUID leaf returns the information about the hypervisor.
> + * EAX : maximum input value for CPUID supported by the hypervisor.
> + * EBX, ECX, EDX : Hypervisor vendor ID signature. E.g. VMwareVMware.
> + */
> +#define HYPERVISOR_INFO_LEAF 0x40000000
> +/*
> + * This leaf gets timing information from the hypervisor.info.
> + * EAX: (Virtual) TSC frequency in kHz.
> + * EBX: (Virtual) Bus (local apic timer) frequency in kHz.
> + * ECX, EDX: RESERVED
> + */
> +#define HYPERVISOR_TIMING_LEAF 0x40000010
Likewise, I think this should be HYPERVISOR_VMWARE_TIMING_LEAF.
Or we need some way to
(a) standardize hypervisor cpuid leafes (or parts of it) and
(b) handle sparsely filled cpuid info.
Right now both kvm and xen use the first one or two leafes (after info),
but in incompatible ways, so for these the signature *must* be checked
before using the info found there.
0x40000010 doesn't clash with anything as far I know, so we could
attempt to make that standard accross hypervisors.
cheers,
Gerd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/