Skip to contentSkip to conversation

x86/hvm: do not register hpet mmio during s3 cycle

PATCH Superseded Eric Chanudet 2 participants 2 messages Nov 7, 2017 – Nov 8, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: do not register hpet mmio during s3 cycle

Do it once at domain creation (hpet_init).

Sleep -> Resume cycles will end up crashing an HVM guest with hpet as the sequence during resume takes the path:
-> hvm_s3_suspend
-> hpet_reset

    -> hpet_deinit
    -> hpet_init
      -> register_mmio_handler
        -> hvm_next_io_handler

register_mmio_handler will use a new io handler each time, until eventually it reaches NR_IO_HANDLERS, then hvm_next_io_handler calls domain_crash.

---
 xen/arch/x86/hvm/hpet.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/hpet.c +21 -6
index 3ea895a0fb..7635f1a644 100644
@@ -635,14 +635,10 @@ static int hpet_load(struct domain *d, hvm_domain_context_t *h)
 
 HVM_REGISTER_SAVE_RESTORE(HPET, hpet_save, hpet_load, 1, HVMSR_PER_DOM);
 
-void hpet_init(struct domain *d)
+static void hpet_set(HPETState *h)
 {
-    HPETState *h = domain_vhpet(d);
     int i;
 
-    if ( !has_vhpet(d) )
-        return;
-
     memset(h, 0, sizeof(HPETState));
 
     rwlock_init(&h->lock);
@@ -668,11 +664,30 @@ void hpet_init(struct domain *d)
         h->hpet.comparator64[i] = ~0ULL;
         h->pt[i].source = PTSRC_isa;
     }
+}
 
+void hpet_init(struct domain *d)
+{
+    HPETState *h = domain_vhpet(d);
+
+    if ( !has_vhpet(d) )
+        return;
+
+    hpet_set(h);
     register_mmio_handler(d, &hpet_mmio_ops);
     d->arch.hvm_domain.params[HVM_PARAM_HPET_ENABLED] = 1;
 }
 
+void hpet_reinit(struct domain *d)
+{
+    HPETState *h = domain_vhpet(d);
+
+    if ( !has_vhpet(d) )
+        return;
+
+    hpet_set(h);
+}
+
 void hpet_deinit(struct domain *d)
 {
     int i;
@@ -698,7 +713,7 @@ void hpet_deinit(struct domain *d)
 void hpet_reset(struct domain *d)
 {
     hpet_deinit(d);
-    hpet_init(d);
+    hpet_reinit(d);
 }
 
 /*
Signature · 6 lines
2.14.2

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 07.11.17 at 21:39, <[email protected]> wrote:

Do it once at domain creation (hpet_init).

Sleep -> Resume cycles will end up crashing an HVM guest with hpet as the sequence during resume takes the path:
-> hvm_s3_suspend
-> hpet_reset

    -> hpet_deinit
    -> hpet_init
      -> register_mmio_handler
        -> hvm_next_io_handler
Quoted 5 lines

register_mmio_handler will use a new io handler each time, until eventually it reaches NR_IO_HANDLERS, then hvm_next_io_handler calls domain_crash.

This is certainly worthwhile to consider for 4.10 - please Cc Julien on v2.

Quoted 1 line

+void hpet_reinit(struct domain *d)

static

xen/arch/x86/hvm/hpet.c void hpet_init(struct domain *d) · line 676

Quoted 7 lines
xen/arch/x86/hvm/hpet.c +7 -0
+{
+    HPETState *h = domain_vhpet(d);
+
+    if ( !has_vhpet(d) )
+        return;
+
+    hpet_set(h);

The local variable, being used only once, isn't needed.

xen/arch/x86/hvm/hpet.c void hpet_deinit(struct domain *d) · line 717

Quoted 7 lines
xen/arch/x86/hvm/hpet.c +1 -1
@@ -698,7 +713,7 @@ void hpet_deinit(struct domain *d)
 void hpet_reset(struct domain *d)
 {
     hpet_deinit(d);
-    hpet_init(d);
+    hpet_reinit(d);
 }

This being the only caller, it then becomes questionable whether hpet_reinit() needs to be a separate function, or wouldn't better be inlined here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel