On 04/15/2010 09:37 PM, Glauber Costa wrote:
We now added a new set of clock-related msrs in replacement of the old ones. In theory, we could just try to use them and get a return value indicating they do not exist, due to our use of kvm_write_msr_save. However, kvm clock registration happens very early, and if we ever try to write to a non-existant MSR, we raise a lethal #GP, since our idt handlers are not in place yet. So this patch tests for a cpuid feature exported by the host to decide which set of msrs are supported. diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 0cffb96..a32710a 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -16,6 +16,10 @@ #define KVM_FEATURE_CLOCKSOURCE 0 #define KVM_FEATURE_NOP_IO_DELAY 1 #define KVM_FEATURE_MMU_OP 2 +/* We could just try to use new msr values, but they are queried very early, + * kernel does not have idt handlers yet, and failures are fatal */ +#define KVM_FEATURE_CLOCKSOURCE2 3
This comment has no place in a header that's oriented to userspace. Instead, it's better to document what this bit exposes.
static int kvmclock = 1; +static int kvm_use_new_msrs = 0;
Instead of this and all those if ()s all over the place, you can define variables for the MSR indices. Set them up on initialization, the rest of the code just looks them up.
-- Do not meddle in the internals of kernels, for they are subtle and quick to panic. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html