debuggers.hg

changeset 21977:6b28b2dac7dd

PV console for HVM domains

Creates a shared memory ring buffer and event channel in HVM domains
for passing debug messages from PV drivers on HVM guests
The console is used by windows pv drivers to send debug data to xenconsoled

Signed-off-by: Owen Smith <owen.smith@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Stefano Stabellini <sstabellini@xensource.com>
date Thu Aug 05 11:36:24 2010 +0100 (2010-08-05)
parents baaa4b9d385f
children fe930e1b2ce8 a8098da3461c
files tools/libxc/xc_domain_restore.c tools/libxc/xc_domain_save.c tools/libxc/xc_hvm_build.c tools/libxl/libxl_dom.c tools/libxl/libxl_internal.h tools/libxl/xenguest.c tools/libxl/xl_cmdimpl.c xen/include/public/hvm/params.h
line diff
     1.1 --- a/tools/libxc/xc_domain_restore.c	Thu Aug 05 11:33:13 2010 +0100
     1.2 +++ b/tools/libxc/xc_domain_restore.c	Thu Aug 05 11:36:24 2010 +0100
     1.3 @@ -640,6 +640,7 @@ typedef struct {
     1.4      uint64_t vcpumap;
     1.5      uint64_t identpt;
     1.6      uint64_t vm86_tss;
     1.7 +    uint64_t console_pfn;
     1.8  } pagebuf_t;
     1.9  
    1.10  static int pagebuf_init(pagebuf_t* buf)
    1.11 @@ -737,6 +738,16 @@ static int pagebuf_get_one(xc_interface 
    1.12              return -1;
    1.13          }
    1.14          return pagebuf_get_one(xch, ctx, buf, fd, dom);
    1.15 +    } else if (count == -8 ) {
    1.16 +        /* Skip padding 4 bytes then read the console pfn location. */
    1.17 +        if ( read_exact(fd, &buf->console_pfn, sizeof(uint32_t)) ||
    1.18 +             read_exact(fd, &buf->console_pfn, sizeof(uint64_t)) )
    1.19 +        {
    1.20 +            PERROR("error read the address of the console pfn");
    1.21 +            return -1;
    1.22 +        }
    1.23 +        // DPRINTF("console pfn location: %llx\n", buf->console_pfn);
    1.24 +        return pagebuf_get_one(xch, ctx, buf, fd, dom);
    1.25      } else if ( (count > MAX_BATCH_SIZE) || (count < 0) ) {
    1.26          ERROR("Max batch size exceeded (%d). Giving up.", count);
    1.27          errno = EMSGSIZE;
    1.28 @@ -1055,6 +1066,7 @@ int xc_domain_restore(xc_interface *xch,
    1.29      pagebuf_t pagebuf;
    1.30      tailbuf_t tailbuf, tmptail;
    1.31      void* vcpup;
    1.32 +    uint64_t console_pfn = 0;
    1.33  
    1.34      static struct restore_ctx _ctx = {
    1.35          .live_p2m = NULL,
    1.36 @@ -1207,6 +1219,8 @@ int xc_domain_restore(xc_interface *xch,
    1.37                  xc_set_hvm_param(xch, dom, HVM_PARAM_IDENT_PT, pagebuf.identpt);
    1.38              if ( pagebuf.vm86_tss )
    1.39                  xc_set_hvm_param(xch, dom, HVM_PARAM_VM86_TSS, pagebuf.vm86_tss);
    1.40 +            if ( pagebuf.console_pfn )
    1.41 +                console_pfn = pagebuf.console_pfn;
    1.42              break;  /* our work here is done */
    1.43          }
    1.44  
    1.45 @@ -1717,6 +1731,19 @@ int xc_domain_restore(xc_interface *xch,
    1.46      }
    1.47      *store_mfn = tailbuf.u.hvm.magicpfns[2];
    1.48  
    1.49 +    if ( console_pfn ) {
    1.50 +        if ( xc_clear_domain_page(xch, dom, console_pfn) ) {
    1.51 +            PERROR("error zeroing console page");
    1.52 +            goto out;
    1.53 +        }
    1.54 +        if ( (frc = xc_set_hvm_param(xch, dom, 
    1.55 +                                    HVM_PARAM_CONSOLE_PFN, console_pfn)) ) {
    1.56 +            PERROR("error setting HVM param: %i", frc);
    1.57 +            goto out;
    1.58 +        }
    1.59 +        *console_mfn = console_pfn;
    1.60 +    }
    1.61 +
    1.62      frc = xc_domain_hvm_setcontext(xch, dom, tailbuf.u.hvm.hvmbuf,
    1.63                                     tailbuf.u.hvm.reclen);
    1.64      if ( frc )
     2.1 --- a/tools/libxc/xc_domain_save.c	Thu Aug 05 11:33:13 2010 +0100
     2.2 +++ b/tools/libxc/xc_domain_save.c	Thu Aug 05 11:36:24 2010 +0100
     2.3 @@ -1587,6 +1587,17 @@ int xc_domain_save(xc_interface *xch, in
     2.4              PERROR("Error when writing the vm86 TSS for guest");
     2.5              goto out;
     2.6          }
     2.7 +
     2.8 +        chunk.id = -8;
     2.9 +        xc_get_hvm_param(xch, dom, HVM_PARAM_CONSOLE_PFN,
    2.10 +                         (unsigned long *)&chunk.data);
    2.11 +
    2.12 +        if ( (chunk.data != 0) &&
    2.13 +             wrexact(io_fd, &chunk, sizeof(chunk)) )
    2.14 +        {
    2.15 +            PERROR("Error when writing the console pfn for guest");
    2.16 +            goto out;
    2.17 +        }
    2.18      }
    2.19  
    2.20      /* Zero terminate */
     3.1 --- a/tools/libxc/xc_hvm_build.c	Thu Aug 05 11:33:13 2010 +0100
     3.2 +++ b/tools/libxc/xc_hvm_build.c	Thu Aug 05 11:36:24 2010 +0100
     3.3 @@ -28,7 +28,8 @@
     3.4  #define SPECIALPAGE_XENSTORE 1
     3.5  #define SPECIALPAGE_IOREQ    2
     3.6  #define SPECIALPAGE_IDENT_PT 3
     3.7 -#define NR_SPECIAL_PAGES     4
     3.8 +#define SPECIALPAGE_CONSOLE  4
     3.9 +#define NR_SPECIAL_PAGES     5
    3.10  #define special_pfn(x) (0xff000u - NR_SPECIAL_PAGES + (x))
    3.11  
    3.12  static void build_hvm_info(void *hvm_info_page, uint64_t mem_size)
    3.13 @@ -354,6 +355,8 @@ static int setup_guest(xc_interface *xch
    3.14                       special_pfn(SPECIALPAGE_BUFIOREQ));
    3.15      xc_set_hvm_param(xch, dom, HVM_PARAM_IOREQ_PFN,
    3.16                       special_pfn(SPECIALPAGE_IOREQ));
    3.17 +    xc_set_hvm_param(xch, dom, HVM_PARAM_CONSOLE_PFN,
    3.18 +                     special_pfn(SPECIALPAGE_CONSOLE));
    3.19  
    3.20      /*
    3.21       * Identity-map page table is required for running with CR0.PG=0 when
     4.1 --- a/tools/libxl/libxl_dom.c	Thu Aug 05 11:33:13 2010 +0100
     4.2 +++ b/tools/libxl/libxl_dom.c	Thu Aug 05 11:36:24 2010 +0100
     4.3 @@ -237,7 +237,7 @@ int build_hvm(libxl_ctx *ctx, uint32_t d
     4.4          return ERROR_FAIL;
     4.5      }
     4.6      ret = hvm_build_set_params(ctx->xch, domid, info, state->store_port,
     4.7 -                               &state->store_mfn);
     4.8 +                               &state->store_mfn, state->console_port, &state->console_mfn);
     4.9      if (ret) {
    4.10          XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, ret, "hvm build set params failed");
    4.11          return ERROR_FAIL;
     5.1 --- a/tools/libxl/libxl_internal.h	Thu Aug 05 11:33:13 2010 +0100
     5.2 +++ b/tools/libxl/libxl_internal.h	Thu Aug 05 11:36:24 2010 +0100
     5.3 @@ -173,7 +173,8 @@ int libxl_device_pci_reset(libxl_ctx *ct
     5.4  /* from xenguest (helper */
     5.5  int hvm_build_set_params(xc_interface *handle, uint32_t domid,
     5.6                           libxl_domain_build_info *info,
     5.7 -                         int store_evtchn, unsigned long *store_mfn);
     5.8 +                         int store_evtchn, unsigned long *store_mfn,
     5.9 +                         int console_evtchn, unsigned long *console_mfn);
    5.10  
    5.11  /* xl_exec */
    5.12  
     6.1 --- a/tools/libxl/xenguest.c	Thu Aug 05 11:33:13 2010 +0100
     6.2 +++ b/tools/libxl/xenguest.c	Thu Aug 05 11:36:24 2010 +0100
     6.3 @@ -23,7 +23,8 @@
     6.4  
     6.5  int hvm_build_set_params(xc_interface *handle, uint32_t domid,
     6.6                           libxl_domain_build_info *info,
     6.7 -                         int store_evtchn, unsigned long *store_mfn)
     6.8 +                         int store_evtchn, unsigned long *store_mfn,
     6.9 +                         int console_evtchn, unsigned long *console_mfn)
    6.10  {
    6.11      struct hvm_info_table *va_hvm;
    6.12      uint8_t *va_map, sum;
    6.13 @@ -46,6 +47,7 @@ int hvm_build_set_params(xc_interface *h
    6.14      munmap(va_map, XC_PAGE_SIZE);
    6.15  
    6.16      xc_get_hvm_param(handle, domid, HVM_PARAM_STORE_PFN, store_mfn);
    6.17 +    xc_get_hvm_param(handle, domid, HVM_PARAM_CONSOLE_PFN, console_mfn);
    6.18      xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, info->u.hvm.pae);
    6.19  #if defined(__i386__) || defined(__x86_64__)
    6.20      xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, info->u.hvm.viridian);
    6.21 @@ -54,5 +56,6 @@ int hvm_build_set_params(xc_interface *h
    6.22      xc_set_hvm_param(handle, domid, HVM_PARAM_TIMER_MODE, (unsigned long) info->u.hvm.timer_mode);
    6.23      xc_set_hvm_param(handle, domid, HVM_PARAM_VPT_ALIGN, (unsigned long) info->u.hvm.vpt_align);
    6.24      xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
    6.25 +    xc_set_hvm_param(handle, domid, HVM_PARAM_CONSOLE_EVTCHN, console_evtchn);
    6.26      return 0;
    6.27  }
     7.1 --- a/tools/libxl/xl_cmdimpl.c	Thu Aug 05 11:33:13 2010 +0100
     7.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Aug 05 11:36:24 2010 +0100
     7.3 @@ -1433,6 +1433,9 @@ start:
     7.4          }
     7.5      }
     7.6      if (d_config.c_info.hvm) {
     7.7 +        init_console_info(&console, 0, &state);
     7.8 +        console.domid = domid;
     7.9 +        libxl_device_console_add(&ctx, domid, &console);
    7.10          dm_info.domid = domid;
    7.11          MUST( libxl_create_device_model(&ctx, &dm_info,
    7.12                                          d_config.disks, d_config.num_disks,
     8.1 --- a/xen/include/public/hvm/params.h	Thu Aug 05 11:33:13 2010 +0100
     8.2 +++ b/xen/include/public/hvm/params.h	Thu Aug 05 11:36:24 2010 +0100
     8.3 @@ -109,6 +109,10 @@
     8.4  /* Boolean: Enable aligning all periodic vpts to reduce interrupts */
     8.5  #define HVM_PARAM_VPT_ALIGN    16
     8.6  
     8.7 -#define HVM_NR_PARAMS          17
     8.8 +/* Console debug shared memory ring and event channel */
     8.9 +#define HVM_PARAM_CONSOLE_PFN    17
    8.10 +#define HVM_PARAM_CONSOLE_EVTCHN 18
    8.11 +
    8.12 +#define HVM_NR_PARAMS          19
    8.13  
    8.14  #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */