Skip to contentSkip to conversation

X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

PATCH RESEND Superseded K. Y. Srinivasan 4 participants 16 messages Jan 24, 2013 – Jan 25, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

Starting with win8, vmbus interrupts can be delivered on any VCPU in the guest and furthermore can be concurrently active on multiple VCPUs. Support this interrupt delivery model by setting up a separate IDT entry for Hyper-V vmbus. interrupts. I would like to thank Jan Beulich <[email protected]> and Thomas Gleixner <[email protected]>, for their help.

In this version of the patch, based on the feedback, I have merged the IDT vector for Xen and Hyper-V and made the necessary adjustments.

---
 arch/x86/include/asm/irq_vectors.h |    4 +-
 arch/x86/include/asm/mshyperv.h    |    4 +++
 arch/x86/kernel/cpu/mshyperv.c     |   39 ++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/entry_32.S         |    9 +++++++-
 arch/x86/kernel/entry_64.S         |    7 +++++-
 drivers/xen/events.c               |    6 ++--
 6 files changed, 62 insertions(+), 7 deletions(-)
arch/x86/include/asm/irq_vectors.h +2 -2
index 1508e51..d09850b 100644
@@ -109,8 +109,8 @@
 
 #define UV_BAU_MESSAGE			0xf5
 
-/* Xen vector callback to receive events in a HVM domain */
-#define XEN_HVM_EVTCHN_CALLBACK		0xf3
+/* Vector on which hypervisor callbacks will be delivered */
+#define HYPERVISOR_CALLBACK_VECTOR 	0xf3
 
 /*
  * Local APIC timer IRQ vector is on a different priority level,
arch/x86/include/asm/mshyperv.h +4 -0
index 79ce568..c2934be 100644
@@ -11,4 +11,8 @@ struct ms_hyperv_info {
 
 extern struct ms_hyperv_info ms_hyperv;
 
+void hyperv_callback_vector(void);
+void hyperv_vector_handler(struct pt_regs *regs);
+void hv_register_vmbus_handler(int irq, irq_handler_t handler);
+
 #endif
arch/x86/kernel/cpu/mshyperv.c +39 -0
index 0a630dd..3689622 100644
@@ -14,10 +14,15 @@
 #include <linux/time.h>
 #include <linux/clocksource.h>
 #include <linux/module.h>
+#include <linux/hardirq.h>
+#include <linux/interrupt.h>
 #include <asm/processor.h>
 #include <asm/hypervisor.h>
 #include <asm/hyperv.h>
 #include <asm/mshyperv.h>
+#include <asm/desc.h>
+#include <asm/idle.h>
+#include <asm/irq_regs.h>
 
 struct ms_hyperv_info ms_hyperv;
 EXPORT_SYMBOL_GPL(ms_hyperv);
@@ -69,6 +74,11 @@ static void __init ms_hyperv_init_platform(void)
 	       ms_hyperv.features, ms_hyperv.hints);
 
 	clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+
+	/*
+	 * Setup the IDT for hypervisor callback.
+	 */
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, hyperv_callback_vector);
 }
 
 const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
@@ -77,3 +87,32 @@ const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
 	.init_platform		= ms_hyperv_init_platform,
 };
 EXPORT_SYMBOL(x86_hyper_ms_hyperv);
+
+static int vmbus_irq = -1;
+static irq_handler_t vmbus_isr;
+
+void hv_register_vmbus_handler(int irq, irq_handler_t handler)
+{
+	vmbus_irq = irq;
+	vmbus_isr = handler;
+}
+EXPORT_SYMBOL_GPL(hv_register_vmbus_handler);
+
+void hyperv_vector_handler(struct pt_regs *regs)
+{
+	struct pt_regs *old_regs = set_irq_regs(regs);
+	struct irq_desc *desc;
+
+	irq_enter();
+#ifdef CONFIG_X86
+	exit_idle();
+#endif
+
+	desc = irq_to_desc(vmbus_irq);
+
+	if (desc)
+		generic_handle_irq_desc(vmbus_irq, desc);
+
+	irq_exit();
+	set_irq_regs(old_regs);
+}
arch/x86/kernel/entry_32.S +8 -1
index e9dd4c4..7d2bb62 100644
@@ -1047,11 +1047,18 @@ ENTRY(xen_failsafe_callback)
 	_ASM_EXTABLE(4b,9b)
 ENDPROC(xen_failsafe_callback)
 
-BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
+BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
 		xen_evtchn_do_upcall)
 
 #endif	/* CONFIG_XEN */
 
+#if IS_ENABLED(CONFIG_HYPERV)
+
+BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
+	hyperv_vector_handler)
+
+#endif /* CONFIG_HYPERV */
+
 #ifdef CONFIG_FUNCTION_TRACER
 #ifdef CONFIG_DYNAMIC_FTRACE
 
arch/x86/kernel/entry_64.S +6 -1
index 1975122..803ca69 100644
@@ -1446,11 +1446,16 @@ ENTRY(xen_failsafe_callback)
 	CFI_ENDPROC
 END(xen_failsafe_callback)
 
-apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
+apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
 	xen_hvm_callback_vector xen_evtchn_do_upcall
 
 #endif /* CONFIG_XEN */
 
+#if IS_ENABLED(CONFIG_HYPERV)
+apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
+	hyperv_callback_vector hyperv_vector_handler
+#endif /* CONFIG_HYPERV */
+
 /*
  * Some functions should be protected against kprobes
  */
drivers/xen/events.c +3 -3
index 4293c57..5c2e92e 100644
@@ -1787,7 +1787,7 @@ void xen_callback_vector(void)
 	int rc;
 	uint64_t callback_via;
 	if (xen_have_vector_callback) {
-		callback_via = HVM_CALLBACK_VECTOR(XEN_HVM_EVTCHN_CALLBACK);
+		callback_via = HVM_CALLBACK_VECTOR(HYPERVISOR_CALLBACK_VECTOR);
 		rc = xen_set_callback_via(callback_via);
 		if (rc) {
 			printk(KERN_ERR "Request for Xen HVM callback vector"
@@ -1798,8 +1798,8 @@ void xen_callback_vector(void)
 		printk(KERN_INFO "Xen HVM callback vector for event delivery is "
 				"enabled\n");
 		/* in the restore case the vector has already been allocated */
-		if (!test_bit(XEN_HVM_EVTCHN_CALLBACK, used_vectors))
-			alloc_intr_gate(XEN_HVM_EVTCHN_CALLBACK, xen_hvm_callback_vector);
+		if (!test_bit(HYPERVISOR_CALLBACK_VECTOR, used_vectors))
+			alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, xen_hvm_callback_vector);
 	}
 }
 #else
Signature · 1 line
1.7.4.1
#1 lore raw

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 81

Quoted 10 lines
Quoted 1 line
Quoted 1 line · K. Y. Srinivasan
arch/x86/kernel/cpu/mshyperv.c +5 -0
@@ -69,6 +74,11 @@ static void __init ms_hyperv_init_platform(void)
 	       ms_hyperv.features, ms_hyperv.hints);
 
 	clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+
+	/*
+	 * Setup the IDT for hypervisor callback.
+	 */
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR, hyperv_callback_vector);

Isn't doing this unconditionally here as problematic as the call to clocksource_register_hz() turned out to be when Xen's Hyper-V shim reacts to the CPUID inquiry above?

Quoted 14 lines
arch/x86/kernel/cpu/mshyperv.c +10 -0
@@ -77,3 +87,32 @@ const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
 	.init_platform		= ms_hyperv_init_platform,
 };
 EXPORT_SYMBOL(x86_hyper_ms_hyperv);
+
+static int vmbus_irq = -1;
+static irq_handler_t vmbus_isr;
+
+void hv_register_vmbus_handler(int irq, irq_handler_t handler)
+{
+	vmbus_irq = irq;
+	vmbus_isr = handler;
+}
+EXPORT_SYMBOL_GPL(hv_register_vmbus_handler);

arch/x86/kernel/cpu/mshyperv.c const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { · line 109

Quoted 10 lines
arch/x86/kernel/cpu/mshyperv.c +10 -0
+
+void hyperv_vector_handler(struct pt_regs *regs)
+{
+	struct pt_regs *old_regs = set_irq_regs(regs);
+	struct irq_desc *desc;
+
+	irq_enter();
+#ifdef CONFIG_X86
+	exit_idle();
+#endif

This being in a file underneath arch/x86 - why the conditional?

Jan

#2 lore raw
Quoted 24 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, January 24, 2013 3:48 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 81

Quoted 10 lines
Quoted 1 line
Quoted 1 line · K. Y. Srinivasan
arch/x86/kernel/cpu/mshyperv.c +5 -0
@@ -69,6 +74,11 @@ static void __init ms_hyperv_init_platform(void)
 	       ms_hyperv.features, ms_hyperv.hints);
 
 	clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+
+	/*
+	 * Setup the IDT for hypervisor callback.
+	 */
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,

hyperv_callback_vector);

Quoted 3 lines

Isn't doing this unconditionally here as problematic as the call to clocksource_register_hz() turned out to be when Xen's Hyper-V shim reacts to the CPUID inquiry above?

I was not sure what to make this conditional on at run-time. To the extent that Xen emulation of Hyper-V is complete, this will be a problem. Does Xen return all the "feature bits" of Hyper-V. I could discriminate on a feature that Xen does not plan to emulate.

Quoted 20 lines

Review const __refconst struct hypervisor_x86

Quoted 2 lines
(quoted diff) +0 -0
@@ -77,3 +87,32 @@ const __refconst struct hypervisor_x86

x86_hyper_ms_hyperv = {

Quoted 17 lines
arch/x86/kernel/cpu/mshyperv.c +14 -0
 	.init_platform		= ms_hyperv_init_platform,
 };
 EXPORT_SYMBOL(x86_hyper_ms_hyperv);
+
+static int vmbus_irq = -1;
+static irq_handler_t vmbus_isr;
+
+void hv_register_vmbus_handler(int irq, irq_handler_t handler)
+{
+	vmbus_irq = irq;
+	vmbus_isr = handler;
+}
+EXPORT_SYMBOL_GPL(hv_register_vmbus_handler);
+
+void hyperv_vector_handler(struct pt_regs *regs)
+{
+	struct pt_regs *old_regs = set_irq_regs(regs);
Quoted 8 lines

arch/x86/kernel/cpu/mshyperv.c const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { · line 109

Quoted 6 lines
arch/x86/kernel/cpu/mshyperv.c +6 -0
+	struct irq_desc *desc;
+
+	irq_enter();
+#ifdef CONFIG_X86
+	exit_idle();
+#endif

This being in a file underneath arch/x86 - why the conditional?

Good point, I will fix that.

Quoted 4 lines

Jan

#3 lore raw
Quoted 30 lines
Quoted 9 lines
Quoted 1 line · KY Srinivasan

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, January 24, 2013 3:48 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 16 lines

[email protected]; [email protected]; [email protected]
Subject: Re: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 81

Quoted 10 lines
Quoted 1 line
Quoted 1 line · K. Y. Srinivasan
arch/x86/kernel/cpu/mshyperv.c +5 -0
@@ -69,6 +74,11 @@ static void __init ms_hyperv_init_platform(void)
 	       ms_hyperv.features, ms_hyperv.hints);
 
 	clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+
+	/*
+	 * Setup the IDT for hypervisor callback.
+	 */
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,

hyperv_callback_vector);

Quoted 3 lines

Isn't doing this unconditionally here as problematic as the call to clocksource_register_hz() turned out to be when Xen's Hyper-V shim reacts to the CPUID inquiry above?

Quoted 5 lines

I was not sure what to make this conditional on at run-time. To the extent that Xen emulation of Hyper-V is complete, this will be a problem. Does Xen return all the "feature bits" of Hyper-V. I could discriminate on a feature that
Xen does not plan to emulate.

I've no idea what plans there might be, but that's the code there is currently:

int cpuid_viridian_leaves(unsigned int leaf, unsigned int *eax,
unsigned int *ebx, unsigned int *ecx, unsigned int *edx)

{
    struct domain *d = current->domain;

    if ( !is_viridian_domain(d) )
        return 0;

    leaf -= 0x40000000;
    if ( leaf > 6 )
        return 0;

    *eax = *ebx = *ecx = *edx = 0;
    switch ( leaf )
    {
    case 0:
        *eax = 0x40000006; /* Maximum leaf */
        *ebx = 0x7263694d; /* Magic numbers  */
        *ecx = 0x666F736F;
        *edx = 0x76482074;
        break;
    case 1:
        *eax = 0x31237648; /* Version number */
        break;
    case 2:
        /* Hypervisor information, but only if the guest has set its
           own version number. */
        if ( d->arch.hvm_domain.viridian.guest_os_id.raw == 0 )
            break;
        *eax = 1; /* Build number */
        *ebx = (xen_major_version() << 16) | xen_minor_version();
        *ecx = 0; /* SP */
        *edx = 0; /* Service branch and number */
        break;
    case 3:
        /* Which hypervisor MSRs are available to the guest */
        *eax = (CPUID3A_MSR_APIC_ACCESS |
                CPUID3A_MSR_HYPERCALL   |
                CPUID3A_MSR_VP_INDEX);
        break;
    case 4:
        /* Recommended hypercall usage. */
        if ( (d->arch.hvm_domain.viridian.guest_os_id.raw == 0) ||
             (d->arch.hvm_domain.viridian.guest_os_id.fields.os < 4) )
            break;
        *eax = (CPUID4A_MSR_BASED_APIC |
                CPUID4A_RELAX_TIMER_INT);
        *ebx = 2047; /* long spin count */
        break;
    }

    return 1;
}

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Jan

#4 lore raw
Quoted 106 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, January 24, 2013 11:16 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

Quoted 30 lines
Quoted 9 lines
Quoted 1 line · KY Srinivasan

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, January 24, 2013 3:48 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 16 lines

[email protected]; [email protected]; [email protected]
Subject: Re: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 81

Quoted 10 lines
Quoted 1 line
Quoted 1 line · K. Y. Srinivasan
arch/x86/kernel/cpu/mshyperv.c +5 -0
@@ -69,6 +74,11 @@ static void __init ms_hyperv_init_platform(void)
 	       ms_hyperv.features, ms_hyperv.hints);
 
 	clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+
+	/*
+	 * Setup the IDT for hypervisor callback.
+	 */
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,

hyperv_callback_vector);

Quoted 3 lines

Isn't doing this unconditionally here as problematic as the call to clocksource_register_hz() turned out to be when Xen's Hyper-V shim reacts to the CPUID inquiry above?

Quoted 5 lines

I was not sure what to make this conditional on at run-time. To the extent that Xen emulation of Hyper-V is complete, this will be a problem. Does Xen return all the "feature bits" of Hyper-V. I could discriminate on a feature that
Xen does not plan to emulate.

I've no idea what plans there might be, but that's the code there is currently:

int cpuid_viridian_leaves(unsigned int leaf, unsigned int *eax,
unsigned int *ebx, unsigned int *ecx, unsigned int *edx)

{
    struct domain *d = current->domain;

    if ( !is_viridian_domain(d) )
        return 0;

    leaf -= 0x40000000;
    if ( leaf > 6 )
        return 0;

    *eax = *ebx = *ecx = *edx = 0;
    switch ( leaf )
    {
    case 0:
        *eax = 0x40000006; /* Maximum leaf */
        *ebx = 0x7263694d; /* Magic numbers  */
        *ecx = 0x666F736F;
        *edx = 0x76482074;
        break;
    case 1:
        *eax = 0x31237648; /* Version number */
        break;
    case 2:
        /* Hypervisor information, but only if the guest has set its
           own version number. */
        if ( d->arch.hvm_domain.viridian.guest_os_id.raw == 0 )
            break;
        *eax = 1; /* Build number */
        *ebx = (xen_major_version() << 16) | xen_minor_version();
        *ecx = 0; /* SP */
        *edx = 0; /* Service branch and number */
        break;
    case 3:
        /* Which hypervisor MSRs are available to the guest */
        *eax = (CPUID3A_MSR_APIC_ACCESS |
                CPUID3A_MSR_HYPERCALL   |
                CPUID3A_MSR_VP_INDEX);
        break;
    case 4:
        /* Recommended hypercall usage. */
        if ( (d->arch.hvm_domain.viridian.guest_os_id.raw == 0) ||
             (d->arch.hvm_domain.viridian.guest_os_id.fields.os < 4) )
            break;
        *eax = (CPUID4A_MSR_BASED_APIC |
                CPUID4A_RELAX_TIMER_INT);
        *ebx = 2047; /* long spin count */
        break;
    }

    return 1;
}
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows guys). Perhaps, we can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Regards,

K. Y

Quoted 4 lines

Jan

#5 lore raw
Quoted 8 lines · KY Srinivasan
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows guys). Perhaps, we can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Would that really help if both pvops XEN_PVHVM and HYPERV are enabled in the config? I assume at this point the access to the DMI data is not yet possible.

Olaf

#6 lore raw
Quoted 19 lines

-----Original Message-----
From: Olaf Hering [mailto:[email protected]]
Sent: Thursday, January 24, 2013 2:00 PM
To: KY Srinivasan
Cc: Jan Beulich; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus interrupts as special hypervisor interrupts

Quoted 4 lines · KY Srinivasan
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Quoted 8 lines
Quoted 4 lines

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows guys). Perhaps, we can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Would that really help if both pvops XEN_PVHVM and HYPERV are enabled in the config? I assume at this point the access to the DMI data is not yet possible.

I was under the impression that only Dom0 Xen would emulate Hyper-V.

K. Y

Quoted 3 lines

Olaf

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#7 lore raw
Quoted 2 lines
Quoted 1 line
Quoted 1 line · KY Srinivasan

I was under the impression that only Dom0 Xen would emulate Hyper-V.

How that? It's the hypervisor that does the emulation, and obviously not for Dom0, but for (HVM) DomU-s.

Jan

#8 lore raw
In reply to Olaf Hering

Can't you discover Xen emulation by looking for Xen first? Or does Xen go "stealth"?

Quoted 20 lines · Olaf Hering
Quoted 6 lines · KY Srinivasan
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows

guys).

Quoted 2 lines

Perhaps, we can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Would that really help if both pvops XEN_PVHVM and HYPERV are enabled in
the config? I assume at this point the access to the DMI data is not yet
possible.

Olaf

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#9 lore raw
Quoted 1 line · H. Peter Anvin

Can't you discover Xen emulation by looking for Xen first? Or does Xen go "stealth"?

The current code looks at cpuid to decide what the host type is. One thing to detect a Xen host is to look for the DIM strings, which still have "Xen HVM DomU" or similar.

Olaf

#10 lore raw

And there is no evidence of Xen in CPUID?

Quoted 10 lines · Olaf Hering
Quoted 1 line · H. Peter Anvin

Can't you discover Xen emulation by looking for Xen first? Or does

Xen go "stealth"?

The current code looks at cpuid to decide what the host type is. One thing to detect a Xen host is to look for the DIM strings, which still have "Xen HVM DomU" or similar.

Olaf

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#11 lore raw
In reply to H. Peter Anvin
Quoted 3 lines
Quoted 1 line
Quoted 1 line · H. Peter Anvin

Can't you discover Xen emulation by looking for Xen first? Or does Xen go "stealth"?

That's already being done - the ordering currently is Xen, VMWare, Hyper-V, KVM. I.e. there's only a problem when !CONFIG_XEN_PVHVM.

Jan

#12 lore raw
In reply to Olaf Hering
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Quoted 4 lines · KY Srinivasan
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Quoted 8 lines
Quoted 4 lines

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows guys). Perhaps, we can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Would that really help if both pvops XEN_PVHVM and HYPERV are enabled in the config? I assume at this point the access to the DMI data is not yet possible.

As just said in another reply - with XEN_PVHVM, there's no problem, since Xen gets checked for first. There's only a problem when !XEN_PVHVM, because in that case Hyper-V will be probed for. And the problem can only get bigger when on top of that the out-of-tree PV drivers are intended to be used.

Jan

#13 lore raw
Quoted 17 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Olaf Hering
Quoted 4 lines · KY Srinivasan
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Quoted 8 lines
Quoted 4 lines

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows guys). Perhaps, we can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Would that really help if both pvops XEN_PVHVM and HYPERV are enabled in the config? I assume at this point the access to the DMI data is not yet possible.

Quoted 5 lines

As just said in another reply - with XEN_PVHVM, there's no problem, since Xen gets checked for first. There's only a problem when !XEN_PVHVM, because in that case Hyper-V will be probed for. And the problem can only get bigger when on top of that the out-of-tree PV drivers are intended to be used.

Yes, xen_cpuid_base() recognizes Xen as hypervisor even with 'viridian=1' in the .cfg file.
I think if there is no feature bit for this, the DMI can be used
because its appearently available before the host is checked:

...

[    0.000000] NX (Execute Disable) protection: active
[    0.000000] DMI 2.4 present.
[    0.000000] DMI: Xen HVM domU, BIOS 4.1.3_06-0.7.1 12/05/2012
[    0.000000] Hypervisor detected: Microsoft HyperV
[    0.000000] HyperV: features 0x70, hints 0x0
[    0.000000] e820 update range: 0000000000000000 - 0000000000010000 (usable) ==> (reserved)

...

Olaf

#14 lore raw
In reply to KY Srinivasan

I also have to point out the obvious problem with Xen masquerading as HyperV without implementing the same feature set...

Quoted 134 lines · KY Srinivasan
Quoted 8 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, January 24, 2013 11:16 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 2 lines

[email protected]; [email protected]; [email protected]
Subject: RE: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus interrupts

as

Quoted 10 lines

special hypervisor interrupts

Quoted 8 lines
Quoted 8 lines
Quoted 1 line · KY Srinivasan

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, January 24, 2013 3:48 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected];

[email protected];

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

[email protected]; [email protected];

[email protected];

Quoted 2 lines

[email protected]; [email protected]; [email protected]
Subject: Re: [PATCH RESEND 1/1] X86: Handle Hyper-V vmbus

interrupts as

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

special hypervisor interrupts

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 24.01.13 at 02:17, "K. Y. Srinivasan" <[email protected]>

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line

Review static void __init

Quoted 1 line
(quoted diff) +0 -0
@@ -69,6 +74,11 @@ static void __init

ms_hyperv_init_platform(void)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void)

Quoted 8 lines
arch/x86/kernel/cpu/mshyperv.c +5 -0
 	       ms_hyperv.features, ms_hyperv.hints);
 
 	clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
+
+	/*
+	 * Setup the IDT for hypervisor callback.
+	 */
+	alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,

hyperv_callback_vector);

Isn't doing this unconditionally here as problematic as the call

to

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

clocksource_register_hz() turned out to be when Xen's Hyper-V shim reacts to the CPUID inquiry above?

I was not sure what to make this conditional on at run-time. To the

extent

Quoted 1 line
Quoted 1 line

that Xen emulation of Hyper-V is complete, this will be a problem.

Does Xen

Quoted 1 line
Quoted 1 line

return all the "feature bits" of Hyper-V. I could discriminate on a

feature

Quoted 43 lines
Quoted 2 lines

that
Xen does not plan to emulate.

I've no idea what plans there might be, but that's the code there is currently:

int cpuid_viridian_leaves(unsigned int leaf, unsigned int *eax,
unsigned int *ebx, unsigned int *ecx, unsigned int *edx)

{
    struct domain *d = current->domain;

    if ( !is_viridian_domain(d) )
        return 0;

    leaf -= 0x40000000;
    if ( leaf > 6 )
        return 0;

    *eax = *ebx = *ecx = *edx = 0;
    switch ( leaf )
    {
    case 0:
        *eax = 0x40000006; /* Maximum leaf */
        *ebx = 0x7263694d; /* Magic numbers  */
        *ecx = 0x666F736F;
        *edx = 0x76482074;
        break;
    case 1:
        *eax = 0x31237648; /* Version number */
        break;
    case 2:
        /* Hypervisor information, but only if the guest has set its
           own version number. */
        if ( d->arch.hvm_domain.viridian.guest_os_id.raw == 0 )
            break;
        *eax = 1; /* Build number */
        *ebx = (xen_major_version() << 16) | xen_minor_version();
        *ecx = 0; /* SP */
        *edx = 0; /* Service branch and number */
        break;
    case 3:
        /* Which hypervisor MSRs are available to the guest */
Quoted 8 lines
        *eax = (CPUID3A_MSR_APIC_ACCESS |
                CPUID3A_MSR_HYPERCALL   |
                CPUID3A_MSR_VP_INDEX);
        break;
    case 4:
        /* Recommended hypercall usage. */
        if ( (d->arch.hvm_domain.viridian.guest_os_id.raw == 0) ||
             (d->arch.hvm_domain.viridian.guest_os_id.fields.os < 4)

)

Quoted 10 lines
            break;
        *eax = (CPUID4A_MSR_BASED_APIC |
                CPUID4A_RELAX_TIMER_INT);
        *ebx = 2047; /* long spin count */
        break;
    }

    return 1;
}
Quoted 3 lines

Question is - considering you stated that this is supported starting in Win8, doesn't Hyper-V itself announce that capability in some explicit way?

Thanks Jan. Unfortunately I don't think tis interrupt delivery model is specified via a "feature" bit (I will check with the Windows guys). Perhaps, we
can have a Hyper-V specific compilation switch to address the Xen emulation issue.

Regards,

K. Y

Quoted 4 lines

Jan

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#15 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · H. Peter Anvin

I also have to point out the obvious problem with Xen masquerading as HyperV without implementing the same feature set...

I can't resist to state that this is what feature bits have been introduced for in CPUID leaves. As long as Xen's shim doesn't advertise a feature bit it doesn't implement, all should be fine.

Jan