ia64/xen-unstable

changeset 18142:351ce3b94e2d

hvm: Fix intra-vga-mem mmio in stdvga.c

The current stdvga code never checks if the copy_from/to_guest calls
fail, and thus silenty fails if both sides of an IOREQ_COPY points
into mmio space. This patch fixes this and makes the code correctly
handle intra-vga-mem copies, as well as log & turn off caching if some
more "exotic" type of mmio (say, copy from vga mem to some other
device's iomem), so that such mmio reqs will fall through to regular
ioemu where they can hopefully be handled correctly.

In practice, this patch fixes a number of graphical glitches for
guests running in standard vga mode, including a corrupted OS/2 boot
graphic.

Signed-off-by: Trolle Selander <trolle.selander@eu.citrix.com>
Signed-off-by: Keir Fraser <keir.fraser@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jul 23 13:31:57 2008 +0100 (2008-07-23)
parents 2ba91f7495ae
children 7299346111fb
files xen/arch/x86/hvm/stdvga.c
line diff
     1.1 --- a/xen/arch/x86/hvm/stdvga.c	Wed Jul 23 09:59:21 2008 +0100
     1.2 +++ b/xen/arch/x86/hvm/stdvga.c	Wed Jul 23 13:31:57 2008 +0100
     1.3 @@ -33,6 +33,10 @@
     1.4  #include <xen/domain_page.h>
     1.5  #include <asm/hvm/support.h>
     1.6  #include <xen/numa.h>
     1.7 +#include <xen/paging.h>
     1.8 +
     1.9 +#define VGA_MEM_BASE 0xa0000
    1.10 +#define VGA_MEM_SIZE 0x20000
    1.11  
    1.12  #define PAT(x) (x)
    1.13  static const uint32_t mask16[16] = {
    1.14 @@ -464,6 +468,7 @@ static int mmio_move(struct hvm_hw_stdvg
    1.15  {
    1.16      int i;
    1.17      int sign = p->df ? -1 : 1;
    1.18 +    p2m_type_t p2mt;
    1.19  
    1.20      if ( p->data_is_ptr )
    1.21      {
    1.22 @@ -473,7 +478,19 @@ static int mmio_move(struct hvm_hw_stdvg
    1.23              for ( i = 0; i < p->count; i++ ) 
    1.24              {
    1.25                  tmp = stdvga_mem_read(addr, p->size);
    1.26 -                hvm_copy_to_guest_phys(data, &tmp, p->size);
    1.27 +                if ( hvm_copy_to_guest_phys(data, &tmp, p->size) ==
    1.28 +                     HVMCOPY_bad_gfn_to_mfn )
    1.29 +                {
    1.30 +                    (void)gfn_to_mfn_current(data >> PAGE_SHIFT, &p2mt);
    1.31 +                    /*
    1.32 +                     * The only case we handle is vga_mem <-> vga_mem.
    1.33 +                     * Anything else disables caching and leaves it to qemu-dm.
    1.34 +                     */
    1.35 +                    if ( (p2mt != p2m_mmio_dm) || (data < VGA_MEM_BASE) ||
    1.36 +                         ((data + p->size) > (VGA_MEM_BASE + VGA_MEM_SIZE)) )
    1.37 +                        return 0;
    1.38 +                    stdvga_mem_write(data, tmp, p->size);
    1.39 +                }
    1.40                  data += sign * p->size;
    1.41                  addr += sign * p->size;
    1.42              }
    1.43 @@ -483,7 +500,15 @@ static int mmio_move(struct hvm_hw_stdvg
    1.44              uint32_t addr = p->addr, data = p->data, tmp;
    1.45              for ( i = 0; i < p->count; i++ )
    1.46              {
    1.47 -                hvm_copy_from_guest_phys(&tmp, data, p->size);
    1.48 +                if ( hvm_copy_from_guest_phys(&tmp, data, p->size) ==
    1.49 +                     HVMCOPY_bad_gfn_to_mfn )
    1.50 +                {
    1.51 +                    (void)gfn_to_mfn_current(data >> PAGE_SHIFT, &p2mt);
    1.52 +                    if ( (p2mt != p2m_mmio_dm) || (data < VGA_MEM_BASE) ||
    1.53 +                         ((data + p->size) > (VGA_MEM_BASE + VGA_MEM_SIZE)) )
    1.54 +                        return 0;
    1.55 +                    tmp = stdvga_mem_read(data, p->size);
    1.56 +                }
    1.57                  stdvga_mem_write(addr, tmp, p->size);
    1.58                  data += sign * p->size;
    1.59                  addr += sign * p->size;
    1.60 @@ -536,7 +561,8 @@ static int stdvga_intercept_mmio(ioreq_t
    1.61          {
    1.62          case IOREQ_TYPE_COPY:
    1.63              buf = mmio_move(s, p);
    1.64 -            break;
    1.65 +            if ( buf )
    1.66 +                break;
    1.67          default:
    1.68              gdprintk(XENLOG_WARNING, "unsupported mmio request type:%d "
    1.69                       "addr:0x%04x data:0x%04x size:%d count:%d state:%d "
    1.70 @@ -588,7 +614,7 @@ void stdvga_init(struct domain *d)
    1.71          register_portio_handler(d, 0x3ce, 2, stdvga_intercept_pio);
    1.72          /* MMIO. */
    1.73          register_buffered_io_handler(
    1.74 -            d, 0xa0000, 0x20000, stdvga_intercept_mmio);
    1.75 +            d, VGA_MEM_BASE, VGA_MEM_SIZE, stdvga_intercept_mmio);
    1.76      }
    1.77  }
    1.78