Skip to contentSkip to conversation

x86/hvm: make sure stdvga cache cannot be re-enabled

PATCH Superseded Paul Durrant 2 participants 3 messages Nov 5, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: make sure stdvga cache cannot be re-enabled

As soon as the cache is disabled, it will become out-of-sync with the VGA device model and since no mechanism exists to acquire current VRAM state from the device model, re-enabling it leads to stale data being seen by the guest.

The problem can be seen by deliberately crashing a Windows guest; the BSOD output is corrupted.

This patch changes the existing 'cache' boolean in hvm_hw_stdvga into a tri-state enum and only allows the state to move from 'uninitialized' to 'enabled'. Once the cache state becomes 'disabled' it will remain so for the lifetime of the VM.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/save.c      |  2 +-
 xen/arch/x86/hvm/stdvga.c    | 50 ++++++++++++++++++++++++++++++++------------
 xen/include/asm-x86/hvm/io.h |  8 ++++++-
 3 files changed, 45 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/save.c +1 -1
index 4660beb..f7d4999 100644
@@ -73,7 +73,7 @@ int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr)
     d->arch.hvm_domain.sync_tsc = rdtsc();
 
     /* VGA state is not saved/restored, so we nobble the cache. */
-    d->arch.hvm_domain.stdvga.cache = 0;
+    d->arch.hvm_domain.stdvga.cache = STDVGA_CACHE_DISABLED;
 
     return 0;
 }
xen/arch/x86/hvm/stdvga.c +37 -13

77 lines not on this page · raw message

xen/include/asm-x86/hvm/io.h +7 -1
index 8585a1f..ceefa2e 100644
@@ -128,13 +128,19 @@ void hvm_dpci_eoi(struct domain *d, unsigned int guest_irq,
 void msix_write_completion(struct vcpu *);
 void msixtbl_init(struct domain *d);
 
+enum stdvga_cache_state {
+    STDVGA_CACHE_UNINITIALIZED,
+    STDVGA_CACHE_ENABLED,
+    STDVGA_CACHE_DISABLED
+};
+
 struct hvm_hw_stdvga {
     uint8_t sr_index;
     uint8_t sr[8];
     uint8_t gr_index;
     uint8_t gr[9];
     bool_t stdvga;
-    bool_t cache;
+    enum stdvga_cache_state cache;
     uint32_t latch;
     struct page_info *vram_page[64];  /* shadow of 0xa0000-0xaffff */
     spinlock_t lock;
Signature · 1 line
2.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Paul Durrant

As soon as the cache is disabled, it will become out-of-sync with the VGA device model and since no mechanism exists to acquire current VRAM state from the device model, re-enabling it leads to stale data being seen by the guest.

Quoted 7 lines

The problem can be seen by deliberately crashing a Windows guest; the BSOD output is corrupted.

This patch changes the existing 'cache' boolean in hvm_hw_stdvga into a tri-state enum and only allows the state to move from 'uninitialized' to 'enabled'. Once the cache state becomes 'disabled' it will remain so for the lifetime of the VM.

Should identify that this is a regression introduced by c/s 3bbaaec09b1b942f5624dee176da6e416d31f982

Quoted 5 lines
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

issue which could be fixed on commit...

Quoted 44 lines
---
 xen/arch/x86/hvm/save.c      |  2 +-
 xen/arch/x86/hvm/stdvga.c    | 50 ++++++++++++++++++++++++++++++++------------
 xen/include/asm-x86/hvm/io.h |  8 ++++++-
 3 files changed, 45 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/save.c +1 -1
index 4660beb..f7d4999 100644
@@ -73,7 +73,7 @@ int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr)
     d->arch.hvm_domain.sync_tsc = rdtsc();
 
     /* VGA state is not saved/restored, so we nobble the cache. */
-    d->arch.hvm_domain.stdvga.cache = 0;
+    d->arch.hvm_domain.stdvga.cache = STDVGA_CACHE_DISABLED;
 
     return 0;
 }
xen/arch/x86/hvm/stdvga.c +17 -0
index 02a97f9..246c629 100644
@@ -101,6 +101,37 @@ static void vram_put(struct hvm_hw_stdvga *s, void *p)
     unmap_domain_page(p);
 }
 
+static void stdvga_try_cache_enable(struct hvm_hw_stdvga *s)
+{
+    /*
+     * Caching mode can only be enabled if the the cache has
+     * never been used before. As soon as it is disabled, it will
+     * become out-of-sync with the VGA device model and since no
+     * mechanism exists to acquire current VRAM state from the
+     * device model, re-enabling it would lead to stale data being
+     * seen by the guest.
+     */
+    if ( s->cache != STDVGA_CACHE_UNINITIALIZED )
+        return;
+
+    gdprintk(XENLOG_INFO, "entering caching mode\n");
+    s->cache = STDVGA_CACHE_ENABLED;
+}
+

xen/arch/x86/hvm/stdvga.c static void vram_put(struct hvm_hw_stdvga *s, void *p) · line 130

Quoted 10 lines
xen/arch/x86/hvm/stdvga.c +10 -0
+static void stdvga_cache_disable(struct hvm_hw_stdvga *s)
+{
+    if ( s->cache != STDVGA_CACHE_ENABLED )
+        return;
+
+    gdprintk(XENLOG_INFO, "leaving caching mode\n");
+    s->cache = STDVGA_CACHE_DISABLED;
+}
+
+static bool_t stdvga_cache_is_enabled(struct hvm_hw_stdvga *s)

const struct hvm_hw_stdvga *s

~Andrew

#2 lore raw
Quoted 86 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 November 2015 12:32
To: Paul Durrant; [email protected]
Cc: Keir (Xen.org); Jan Beulich
Subject: Re: [PATCH] x86/hvm: make sure stdvga cache cannot be re- enabled

Quoted 5 lines · Paul Durrant

As soon as the cache is disabled, it will become out-of-sync with the VGA device model and since no mechanism exists to acquire current VRAM state from the device model, re-enabling it leads to stale data being seen by the guest.

Quoted 7 lines

The problem can be seen by deliberately crashing a Windows guest; the BSOD output is corrupted.

This patch changes the existing 'cache' boolean in hvm_hw_stdvga into a tri-state enum and only allows the state to move from 'uninitialized' to 'enabled'. Once the cache state becomes 'disabled' it will remain so for the lifetime of the VM.

Should identify that this is a regression introduced by c/s 3bbaaec09b1b942f5624dee176da6e416d31f982

Quoted 5 lines
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

small
issue which could be fixed on commit...

Quoted 3 lines
---
 xen/arch/x86/hvm/save.c      |  2 +-
 xen/arch/x86/hvm/stdvga.c    | 50

++++++++++++++++++++++++++++++++------------

xen/arch/x86/hvm/save.c int arch_hvm_load(struct domain *d, struct

Quoted 8 lines
 xen/include/asm-x86/hvm/io.h |  8 ++++++-
 3 files changed, 45 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/save.c +0 -0
index 4660beb..f7d4999 100644
@@ -73,7 +73,7 @@ int arch_hvm_load(struct domain *d, struct

hvm_save_header *hdr)

xen/arch/x86/hvm/stdvga.c static void vram_put(struct hvm_hw_stdvga *s,

Quoted 13 lines
xen/arch/x86/hvm/save.c +1 -1
     d->arch.hvm_domain.sync_tsc = rdtsc();
 
     /* VGA state is not saved/restored, so we nobble the cache. */
-    d->arch.hvm_domain.stdvga.cache = 0;
+    d->arch.hvm_domain.stdvga.cache = STDVGA_CACHE_DISABLED;
 
     return 0;
 }
xen/arch/x86/hvm/stdvga.c +0 -0
index 02a97f9..246c629 100644
@@ -101,6 +101,37 @@ static void vram_put(struct hvm_hw_stdvga *s,

void *p)

Quoted 24 lines
xen/arch/x86/hvm/stdvga.c +21 -0
     unmap_domain_page(p);
 }
 
+static void stdvga_try_cache_enable(struct hvm_hw_stdvga *s)
+{
+    /*
+     * Caching mode can only be enabled if the the cache has
+     * never been used before. As soon as it is disabled, it will
+     * become out-of-sync with the VGA device model and since no
+     * mechanism exists to acquire current VRAM state from the
+     * device model, re-enabling it would lead to stale data being
+     * seen by the guest.
+     */
+    if ( s->cache != STDVGA_CACHE_UNINITIALIZED )
+        return;
+
+    gdprintk(XENLOG_INFO, "entering caching mode\n");
+    s->cache = STDVGA_CACHE_ENABLED;
+}
+
+static void stdvga_cache_disable(struct hvm_hw_stdvga *s)
+{
+    if ( s->cache != STDVGA_CACHE_ENABLED )
+        return;
Quoted 9 lines

xen/arch/x86/hvm/stdvga.c static void vram_put(struct hvm_hw_stdvga *s, void *p) · line 130

Quoted 6 lines
xen/arch/x86/hvm/stdvga.c +6 -0
+
+    gdprintk(XENLOG_INFO, "leaving caching mode\n");
+    s->cache = STDVGA_CACHE_DISABLED;
+}
+
+static bool_t stdvga_cache_is_enabled(struct hvm_hw_stdvga *s)

const struct hvm_hw_stdvga *s

I'll re-spin with this fixed and regression-introducing commit mentioned in the message.

Paul

Quoted 1 line

~Andrew