Skip to contentSkip to conversation

x86/hvm: Widen condition for is_hvm_pv_evtchn_vcpu()

PATCH Superseded Jane Malalane 3 participants 8 messages May 11, 2022 – May 18, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Widen condition for is_hvm_pv_evtchn_vcpu()

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

---
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: "Roger Pau Monné" <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/include/asm/domain.h   | 8 +++++++-
 xen/arch/x86/traps.c                | 3 +++
 xen/include/public/arch-x86/cpuid.h | 2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/domain.h +7 -1
index 35898d725f..f044e0a492 100644
@@ -14,8 +14,14 @@
 
 #define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
 
+/*
+ * Set to true if either the global vector-type callback or per-vCPU
+ * LAPIC vectors are used. Assume all vCPUs will use
+ * HVMOP_set_evtchn_upcall_vector as long as the initial vCPU does.
+ */
 #define is_hvm_pv_evtchn_domain(d) (is_hvm_domain(d) && \
-        (d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector)
+        ((d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector || \
+         (d)->vcpu[0]->arch.hvm.evtchn_upcall_vector))
 #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))
 #define is_domain_direct_mapped(d) ((void)(d), 0)
 
xen/arch/x86/traps.c +3 -0
index 25bffe47d7..2c51faab2c 100644
@@ -1152,6 +1152,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
         res->a |= XEN_HVM_CPUID_DOMID_PRESENT;
         res->c = d->domain_id;
 
+        /* Per-vCPU event channel upcalls are implemented. */
+        res->a |= XEN_HVM_CPUID_UPCALL_VECTOR;
+
         break;
 
     case 5: /* PV-specific parameters */
xen/include/public/arch-x86/cpuid.h +2 -0
index f2b2b3632c..1760e2c405 100644
@@ -109,6 +109,8 @@
  * field from 8 to 15 bits, allowing to target APIC IDs up 32768.
  */
 #define XEN_HVM_CPUID_EXT_DEST_ID      (1u << 5)
+/* Per-vCPU event channel upcalls. */
+#define XEN_HVM_CPUID_UPCALL_VECTOR    (1u << 6)
 
 /*
  * Leaf 6 (0x40000x05)
Signature · 1 line
2.11.0
#1 lore raw
Quoted 6 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

I would add something like:

The naming of the CPUID bit is a bit generic about upcall support being available. That's done so that the define name doesn't get overly long like XEN_HVM_CPUID_UPCALL_VECTOR_SUPPORTS_PIRQ or some such.

Guests that don't care about physical interrupts routed over event channels can just test for the availability of the hypercall directly (HVMOP_set_evtchn_upcall_vector) without checking the CPUID bit.

Quoted 18 lines

---
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: "Roger Pau Monné" <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/include/asm/domain.h   | 8 +++++++-
 xen/arch/x86/traps.c                | 3 +++
 xen/include/public/arch-x86/cpuid.h | 2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/domain.h +0 -0
index 35898d725f..f044e0a492 100644

xen/arch/x86/include/asm/domain.h line 19

Quoted 6 lines
xen/arch/x86/include/asm/domain.h +3 -0
@@ -14,8 +14,14 @@
 
 #define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
 
+/*
+ * Set to true if either the global vector-type callback or per-vCPU
+ * LAPIC vectors are used. Assume all vCPUs will use

I think you should remove LAPIC here. There's no such thing as 'LAPIC vectors', it's just that the old mechanism was bypassing the lapic EOI.

Quoted 14 lines
xen/arch/x86/include/asm/domain.h +4 -1
+ * HVMOP_set_evtchn_upcall_vector as long as the initial vCPU does.
+ */
 #define is_hvm_pv_evtchn_domain(d) (is_hvm_domain(d) && \
-        (d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector)
+        ((d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector || \
+         (d)->vcpu[0]->arch.hvm.evtchn_upcall_vector))
 #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))
 #define is_domain_direct_mapped(d) ((void)(d), 0)
 
xen/arch/x86/traps.c +0 -0
index 25bffe47d7..2c51faab2c 100644

xen/arch/x86/traps.c void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf, · line 1155

Quoted 4 lines
xen/arch/x86/traps.c +1 -0
@@ -1152,6 +1152,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
         res->a |= XEN_HVM_CPUID_DOMID_PRESENT;
         res->c = d->domain_id;
 
+        /* Per-vCPU event channel upcalls are implemented. */

... are implemented and work correctly with PIRQs routed over event channels.

Quoted 10 lines
xen/arch/x86/traps.c +2 -0
+        res->a |= XEN_HVM_CPUID_UPCALL_VECTOR;
+
         break;
 
     case 5: /* PV-specific parameters */
xen/include/public/arch-x86/cpuid.h +0 -0
index f2b2b3632c..1760e2c405 100644

xen/include/public/arch-x86/cpuid.h line 112

Quoted 4 lines
xen/include/public/arch-x86/cpuid.h +1 -0
@@ -109,6 +109,8 @@
  * field from 8 to 15 bits, allowing to target APIC IDs up 32768.
  */
 #define XEN_HVM_CPUID_EXT_DEST_ID      (1u << 5)
+/* Per-vCPU event channel upcalls. */

I would maybe expand the message to:

"Per-vCPU event channel upcalls work correctly with physical IRQs bound to event channels."

Thanks, Roger.

#2 lore raw
Quoted 87 lines · Roger Pau Monné
Quoted 6 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

I would add something like:

The naming of the CPUID bit is a bit generic about upcall support being available. That's done so that the define name doesn't get overly long like XEN_HVM_CPUID_UPCALL_VECTOR_SUPPORTS_PIRQ or some such.

Guests that don't care about physical interrupts routed over event channels can just test for the availability of the hypercall directly (HVMOP_set_evtchn_upcall_vector) without checking the CPUID bit.

Quoted 18 lines

---
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: "Roger Pau Monné" <[email protected]>
CC: Wei Liu <[email protected]>

---
  xen/arch/x86/include/asm/domain.h   | 8 +++++++-
  xen/arch/x86/traps.c                | 3 +++
  xen/include/public/arch-x86/cpuid.h | 2 ++
  3 files changed, 12 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/domain.h +0 -0
index 35898d725f..f044e0a492 100644

xen/arch/x86/include/asm/domain.h line 19

Quoted 6 lines
xen/arch/x86/include/asm/domain.h +3 -0
@@ -14,8 +14,14 @@
 
  #define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
 
+/*
+ * Set to true if either the global vector-type callback or per-vCPU
+ * LAPIC vectors are used. Assume all vCPUs will use

I think you should remove LAPIC here. There's no such thing as 'LAPIC vectors', it's just that the old mechanism was bypassing the lapic EOI.

Quoted 14 lines
xen/arch/x86/include/asm/domain.h +4 -1
+ * HVMOP_set_evtchn_upcall_vector as long as the initial vCPU does.
+ */
  #define is_hvm_pv_evtchn_domain(d) (is_hvm_domain(d) && \
-        (d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector)
+        ((d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector || \
+         (d)->vcpu[0]->arch.hvm.evtchn_upcall_vector))
  #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))
  #define is_domain_direct_mapped(d) ((void)(d), 0)
 
xen/arch/x86/traps.c +0 -0
index 25bffe47d7..2c51faab2c 100644

xen/arch/x86/traps.c void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf, · line 1155

Quoted 4 lines
xen/arch/x86/traps.c +1 -0
@@ -1152,6 +1152,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
          res->a |= XEN_HVM_CPUID_DOMID_PRESENT;
          res->c = d->domain_id;
 
+        /* Per-vCPU event channel upcalls are implemented. */

... are implemented and work correctly with PIRQs routed over event channels.

Quoted 10 lines
xen/arch/x86/traps.c +2 -0
+        res->a |= XEN_HVM_CPUID_UPCALL_VECTOR;
+
          break;
 
      case 5: /* PV-specific parameters */
xen/include/public/arch-x86/cpuid.h +0 -0
index f2b2b3632c..1760e2c405 100644

xen/include/public/arch-x86/cpuid.h line 112

Quoted 4 lines
xen/include/public/arch-x86/cpuid.h +1 -0
@@ -109,6 +109,8 @@
   * field from 8 to 15 bits, allowing to target APIC IDs up 32768.
   */
  #define XEN_HVM_CPUID_EXT_DEST_ID      (1u << 5)
+/* Per-vCPU event channel upcalls. */

I would maybe expand the message to:

Quoted 2 lines

"Per-vCPU event channel upcalls work correctly with physical IRQs bound to event channels."

Thanks. Yes, if others agree that the CPUID bit can still take this name if better explained, despite it being, as you say, quite generic, I will add these comments in a v2.

Thanks,

Jane.

#3 lore raw
In reply to Roger Pau Monné
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

Quoted 6 lines

I would add something like:

The naming of the CPUID bit is a bit generic about upcall support being available. That's done so that the define name doesn't get overly long like XEN_HVM_CPUID_UPCALL_VECTOR_SUPPORTS_PIRQ or some such.

On top of this at least half a sentence wants saying on why a new CPUID bit is introduced in the first place. This doesn't derive in any way from title or description. It would be only then when it is additionally explained why the name was chosen like this.

Jan

#4 lore raw
Quoted 18 lines · Jan Beulich

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

Quoted 6 lines

I would add something like:

The naming of the CPUID bit is a bit generic about upcall support being available. That's done so that the define name doesn't get overly long like XEN_HVM_CPUID_UPCALL_VECTOR_SUPPORTS_PIRQ or some such.

Quoted 4 lines

On top of this at least half a sentence wants saying on why a new
CPUID bit is introduced in the first place. This doesn't derive in
any way from title or description. It would be only then when it
is additionally explained why the name was chosen like this.Indeed it is incomplete, thanks for pointing that out.

I could add:
"A CPUID bit is added so that guests know whether the check in is_hvm_pv_evtchn_domain() will fail when using HVMOP_set_evtchn_upcall_vector. This matters for guests that route PIRQs over event channels since is_hvm_pv_evtchn_domain() is a condition in physdev_map_pirq()."

Would this be enough clarification?

Thank you,

Jane.

#5 lore raw
Quoted 24 lines · Jane Malalane
Quoted 18 lines · Jan Beulich

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

Quoted 6 lines

I would add something like:

The naming of the CPUID bit is a bit generic about upcall support being available. That's done so that the define name doesn't get overly long like XEN_HVM_CPUID_UPCALL_VECTOR_SUPPORTS_PIRQ or some such.

Quoted 4 lines

On top of this at least half a sentence wants saying on why a new
CPUID bit is introduced in the first place. This doesn't derive in
any way from title or description. It would be only then when it
is additionally explained why the name was chosen like this.Indeed it is incomplete, thanks for pointing that out.

Quoted 8 lines

I could add:
"A CPUID bit is added so that guests know whether the check in is_hvm_pv_evtchn_domain() will fail when using HVMOP_set_evtchn_upcall_vector. This matters for guests that route PIRQs over event channels since is_hvm_pv_evtchn_domain() is a condition in physdev_map_pirq()."

Would this be enough clarification?

Yes, thanks.

Jan

#6 lore raw
In reply to Jane Malalane
Quoted 3 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

I'm confused: You say "per-vCPU" here, but ...

Quoted 5 lines
xen/arch/x86/include/asm/domain.h +0 -0
@@ -14,8 +14,14 @@
 
 #define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)

xen/arch/x86/include/asm/domain.h line 24

Quoted 10 lines
xen/arch/x86/include/asm/domain.h +7 -1
 
+/*
+ * Set to true if either the global vector-type callback or per-vCPU
+ * LAPIC vectors are used. Assume all vCPUs will use
+ * HVMOP_set_evtchn_upcall_vector as long as the initial vCPU does.
+ */
 #define is_hvm_pv_evtchn_domain(d) (is_hvm_domain(d) && \
-        (d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector)
+        ((d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector || \
+         (d)->vcpu[0]->arch.hvm.evtchn_upcall_vector))

... you use (d)->vcpu[0] here (and, yes, you say so in the comment) and ...

xen/arch/x86/include/asm/domain.h line 25

Quoted 1 line
xen/arch/x86/include/asm/domain.h +0 -0
 #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))

... you don't alter this at all.

Also (re-ordering context) this ...

Quoted 2 lines

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

... isn't really true - it's is_hvm_pv_evtchn_domain() which controls this (which in turn is why above you need to make the assumption I've put under question). With that assumption I think is_hvm_pv_evtchn_vcpu() would better go away.

Jan

#7 lore raw
Quoted 34 lines · Jan Beulich

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 3 lines · Jane Malalane

Have is_hvm_pv_evtchn_vcpu() return true for vector callbacks for evtchn delivery set up on a per-vCPU basis via HVMOP_set_evtchn_upcall_vector.

I'm confused: You say "per-vCPU" here, but ...

Quoted 5 lines
xen/arch/x86/include/asm/domain.h +0 -0
@@ -14,8 +14,14 @@
 
  #define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)

xen/arch/x86/include/asm/domain.h line 24

Quoted 10 lines
xen/arch/x86/include/asm/domain.h +7 -1
 
+/*
+ * Set to true if either the global vector-type callback or per-vCPU
+ * LAPIC vectors are used. Assume all vCPUs will use
+ * HVMOP_set_evtchn_upcall_vector as long as the initial vCPU does.
+ */
  #define is_hvm_pv_evtchn_domain(d) (is_hvm_domain(d) && \
-        (d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector)
+        ((d)->arch.hvm.irq->callback_via_type == HVMIRQ_callback_vector || \
+         (d)->vcpu[0]->arch.hvm.evtchn_upcall_vector))

... you use (d)->vcpu[0] here (and, yes, you say so in the comment) and ...

xen/arch/x86/include/asm/domain.h line 25

Quoted 1 line
xen/arch/x86/include/asm/domain.h +0 -0
  #define is_hvm_pv_evtchn_vcpu(v) (is_hvm_pv_evtchn_domain(v->domain))

... you don't alter this at all.

Also (re-ordering context) this ...

Quoted 7 lines
Quoted 2 lines

is_hvm_pv_evtchn_vcpu() returning true is a condition for setting up physical IRQ to event channel mappings.

... isn't really true - it's is_hvm_pv_evtchn_domain() which controls this (which in turn is why above you need to make the assumption I've put under question). With that assumption I think is_hvm_pv_evtchn_vcpu() would better go away.

Here only is_hvm_pv_evtchn_domain() should have been mentioned. The "per-VCPU" was in regard to the vector callback for evthcn delivery setup not being global but now done on a per-vCPU basis, in any case, I will amend the description and title. Thanks for the feedback.

Jane.