diff mbox

[v5,08/13] pvh: Send an SCI on VCPU hotplug event

Message ID 1481930319-4796-9-git-send-email-boris.ostrovsky@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Boris Ostrovsky Dec. 16, 2016, 11:18 p.m. UTC
When GPE0 status register gets a bit set (currently XEN_GPE0_CPUHP_BIT
only) send an SCI to the guest.

Also update send_guest_global_virq() to handle cases when VCPU0
is offlined.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
Changes in v5:
* Fixed SCI-triggering logic

 xen/arch/x86/hvm/acpi.c    | 9 +++++++++
 xen/common/event_channel.c | 7 +++++--
 xen/include/xen/domain.h   | 1 +
 xen/include/xen/event.h    | 8 ++++++++
 4 files changed, 23 insertions(+), 2 deletions(-)

Comments

Jan Beulich Dec. 20, 2016, 1:37 p.m. UTC | #1
>>> On 17.12.16 at 00:18, <boris.ostrovsky@oracle.com> wrote:
> @@ -128,6 +130,13 @@ static int acpi_access_common(struct domain *d, bool is_guest_access,
>              *en = (((v & 0xff) << 8) | (*en & 0xff)) & *mask_en;
>              break;
>          }
> +
> +        /*
> +         * If a new bit has been set in status register and corresponding
> +         * event is enabled then an SCI is sent to the guest.
> +         */
> +        if ( !is_guest_access && ((*sts & ~sts_orig) & *en) )
> +                send_guest_global_virq(d, VIRQ_SCI);

From an abstract pov: How a bit gets set in either register shouldn't
matter. Hence the !is_guest_access part here is at least questionable.
However, iirc the guest can't itself set any status bits (since they're
write-1-clear). Otoh, when an enable bit transitions from 0 to 1 (which
the guest can effect) and the respective status bit is set, an SCI
should occur according to my reading of the spec.

Also - indentation.

Jan
Boris Ostrovsky Dec. 20, 2016, 2:54 p.m. UTC | #2
On 12/20/2016 08:37 AM, Jan Beulich wrote:
>>>> On 17.12.16 at 00:18, <boris.ostrovsky@oracle.com> wrote:
>> @@ -128,6 +130,13 @@ static int acpi_access_common(struct domain *d, bool is_guest_access,
>>              *en = (((v & 0xff) << 8) | (*en & 0xff)) & *mask_en;
>>              break;
>>          }
>> +
>> +        /*
>> +         * If a new bit has been set in status register and corresponding
>> +         * event is enabled then an SCI is sent to the guest.
>> +         */
>> +        if ( !is_guest_access && ((*sts & ~sts_orig) & *en) )
>> +                send_guest_global_virq(d, VIRQ_SCI);
> From an abstract pov: How a bit gets set in either register shouldn't
> matter. Hence the !is_guest_access part here is at least questionable.
> However, iirc the guest can't itself set any status bits (since they're
> write-1-clear). Otoh, when an enable bit transitions from 0 to 1 (which
> the guest can effect) and the respective status bit is set, an SCI
> should occur according to my reading of the spec.

I haven't considered the case of enabling with a pending status. Yes,
that should trigger an SCI too, irrespective of is_guest_access.

And I guess since guests can't set status bits I can drop the
is_guest_access test in the check above too.

-boris
diff mbox

Patch

diff --git a/xen/arch/x86/hvm/acpi.c b/xen/arch/x86/hvm/acpi.c
index 044699d..c3c5ed7 100644
--- a/xen/arch/x86/hvm/acpi.c
+++ b/xen/arch/x86/hvm/acpi.c
@@ -4,6 +4,7 @@ 
  */
 #include <xen/acpi.h>
 #include <xen/errno.h>
+#include <xen/event.h>
 #include <xen/lib.h>
 #include <xen/sched.h>
 
@@ -94,6 +95,7 @@  static int acpi_access_common(struct domain *d, bool is_guest_access,
     else
     {
         uint32_t v = *val;
+        uint16_t sts_orig = *sts;
 
         /* Status register is write-1-to-clear by guests */
         switch ( port & 3 )
@@ -128,6 +130,13 @@  static int acpi_access_common(struct domain *d, bool is_guest_access,
             *en = (((v & 0xff) << 8) | (*en & 0xff)) & *mask_en;
             break;
         }
+
+        /*
+         * If a new bit has been set in status register and corresponding
+         * event is enabled then an SCI is sent to the guest.
+         */
+        if ( !is_guest_access && ((*sts & ~sts_orig) & *en) )
+                send_guest_global_virq(d, VIRQ_SCI);
     }
 
     return X86EMUL_OKAY;
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 638dc5e..1d77373 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -727,7 +727,7 @@  void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
     spin_unlock_irqrestore(&v->virq_lock, flags);
 }
 
-static void send_guest_global_virq(struct domain *d, uint32_t virq)
+void send_guest_global_virq(struct domain *d, uint32_t virq)
 {
     unsigned long flags;
     int port;
@@ -739,7 +739,10 @@  static void send_guest_global_virq(struct domain *d, uint32_t virq)
     if ( unlikely(d == NULL) || unlikely(d->vcpu == NULL) )
         return;
 
-    v = d->vcpu[0];
+    /* Send to first available VCPU */
+    for_each_vcpu(d, v)
+        if ( is_vcpu_online(v) )
+            break;
     if ( unlikely(v == NULL) )
         return;
 
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index bce0ea1..b386038 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -52,6 +52,7 @@  void vcpu_destroy(struct vcpu *v);
 int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset);
 void unmap_vcpu_info(struct vcpu *v);
 
+int arch_update_avail_vcpus(struct domain *d);
 int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config);
 
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index 5008c80..74bd605 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -23,6 +23,14 @@ 
 void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq);
 
 /*
+ * send_guest_global_virq: Notify guest via a global VIRQ.
+ *  @d:        domain to which virtual IRQ should be sent. First
+ *             online VCPU will be selected.
+ *  @virq:     Virtual IRQ number (VIRQ_*)
+ */
+void send_guest_global_virq(struct domain *d, uint32_t virq);
+
+/*
  * send_global_virq: Notify the domain handling a global VIRQ.
  *  @virq:     Virtual IRQ number (VIRQ_*)
  */