direct-io.hg

changeset 12453:bda05853cf21

[XEN] Define remaining x86 public pointer fields as guest handles.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Nov 15 16:44:35 2006 +0000 (2006-11-15)
parents 85f331c7af76
children a9d2106313fa
files xen/arch/x86/domain.c xen/arch/x86/mm.c xen/arch/x86/physdev.c xen/arch/x86/traps.c xen/include/asm-x86/domain.h xen/include/public/physdev.h xen/include/public/vcpu.h xen/include/public/xen-compat.h xen/include/public/xen.h xen/include/xen/sched.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Wed Nov 15 14:59:57 2006 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Wed Nov 15 16:44:35 2006 +0000
     1.3 @@ -396,21 +396,20 @@ arch_do_vcpu_op(
     1.4          if ( copy_from_guest(&area, arg, 1) )
     1.5              break;
     1.6  
     1.7 -        if ( !access_ok(area.addr.v, sizeof(*area.addr.v)) )
     1.8 +        if ( !guest_handle_okay(area.addr.h, 1) )
     1.9              break;
    1.10  
    1.11          rc = 0;
    1.12 -        v->runstate_guest = area.addr.v;
    1.13 +        v->runstate_guest = area.addr.h;
    1.14  
    1.15          if ( v == current )
    1.16          {
    1.17 -            __copy_to_user(v->runstate_guest, &v->runstate,
    1.18 -                           sizeof(v->runstate));
    1.19 +            __copy_to_guest(v->runstate_guest, &v->runstate, 1);
    1.20          }
    1.21          else
    1.22          {
    1.23              vcpu_runstate_get(v, &runstate);
    1.24 -            __copy_to_user(v->runstate_guest, &runstate, sizeof(runstate));
    1.25 +            __copy_to_guest(v->runstate_guest, &runstate, 1);
    1.26          }
    1.27  
    1.28          break;
    1.29 @@ -767,9 +766,8 @@ void context_switch(struct vcpu *prev, s
    1.30      context_saved(prev);
    1.31  
    1.32      /* Update per-VCPU guest runstate shared memory area (if registered). */
    1.33 -    if ( next->runstate_guest != NULL )
    1.34 -        __copy_to_user(next->runstate_guest, &next->runstate,
    1.35 -                       sizeof(next->runstate));
    1.36 +    if ( !guest_handle_is_null(next->runstate_guest) )
    1.37 +        __copy_to_guest(next->runstate_guest, &next->runstate, 1);
    1.38  
    1.39      schedule_tail(next);
    1.40      BUG();
     2.1 --- a/xen/arch/x86/mm.c	Wed Nov 15 14:59:57 2006 +0000
     2.2 +++ b/xen/arch/x86/mm.c	Wed Nov 15 16:44:35 2006 +0000
     2.3 @@ -2067,7 +2067,7 @@ int do_mmuext_op(
     2.4          {
     2.5              unsigned long vmask;
     2.6              cpumask_t     pmask;
     2.7 -            if ( unlikely(get_user(vmask, (unsigned long *)op.arg2.vcpumask)) )
     2.8 +            if ( unlikely(copy_from_guest(&vmask, op.arg2.vcpumask, 1)) )
     2.9              {
    2.10                  okay = 0;
    2.11                  break;
     3.1 --- a/xen/arch/x86/physdev.c	Wed Nov 15 14:59:57 2006 +0000
     3.2 +++ b/xen/arch/x86/physdev.c	Wed Nov 15 16:44:35 2006 +0000
     3.3 @@ -125,7 +125,7 @@ long do_physdev_op(int cmd, XEN_GUEST_HA
     3.4          if ( copy_from_guest(&set_iobitmap, arg, 1) != 0 )
     3.5              break;
     3.6          ret = -EINVAL;
     3.7 -        if ( !access_ok(set_iobitmap.bitmap, IOBMP_BYTES) ||
     3.8 +        if ( !guest_handle_okay(set_iobitmap.bitmap, IOBMP_BYTES) ||
     3.9               (set_iobitmap.nr_ports > 65536) )
    3.10              break;
    3.11          ret = 0;
     4.1 --- a/xen/arch/x86/traps.c	Wed Nov 15 14:59:57 2006 +0000
     4.2 +++ b/xen/arch/x86/traps.c	Wed Nov 15 16:44:35 2006 +0000
     4.3 @@ -952,7 +952,6 @@ static inline int guest_io_okay(
     4.4      unsigned int port, unsigned int bytes,
     4.5      struct vcpu *v, struct cpu_user_regs *regs)
     4.6  {
     4.7 -    u16 x;
     4.8  #if defined(__x86_64__)
     4.9      /* If in user mode, switch to kernel mode just to read I/O bitmap. */
    4.10      int user_mode = !(v->arch.flags & TF_kernel_mode);
    4.11 @@ -967,10 +966,23 @@ static inline int guest_io_okay(
    4.12  
    4.13      if ( v->arch.iobmp_limit > (port + bytes) )
    4.14      {
    4.15 +        union { uint8_t bytes[2]; uint16_t mask; } x;
    4.16 +
    4.17 +        /*
    4.18 +         * Grab permission bytes from guest space. Inaccessible bytes are
    4.19 +         * read as 0xff (no access allowed).
    4.20 +         */
    4.21          TOGGLE_MODE();
    4.22 -        __get_user(x, (u16 *)(v->arch.iobmp+(port>>3)));
    4.23 +        switch ( __copy_from_guest_offset(&x.bytes[0], v->arch.iobmp,
    4.24 +                                          port>>3, 2) )
    4.25 +        {
    4.26 +        default: x.bytes[0] = ~0;
    4.27 +        case 1:  x.bytes[1] = ~0;
    4.28 +        case 0:  break;
    4.29 +        }
    4.30          TOGGLE_MODE();
    4.31 -        if ( (x & (((1<<bytes)-1) << (port&7))) == 0 )
    4.32 +
    4.33 +        if ( (x.mask & (((1<<bytes)-1) << (port&7))) == 0 )
    4.34              return 1;
    4.35      }
    4.36  
     5.1 --- a/xen/include/asm-x86/domain.h	Wed Nov 15 14:59:57 2006 +0000
     5.2 +++ b/xen/include/asm-x86/domain.h	Wed Nov 15 16:44:35 2006 +0000
     5.3 @@ -171,7 +171,7 @@ struct arch_vcpu
     5.4      struct trap_bounce trap_bounce;
     5.5  
     5.6      /* I/O-port access bitmap. */
     5.7 -    u8 *iobmp;        /* Guest kernel virtual address of the bitmap. */
     5.8 +    XEN_GUEST_HANDLE(uint8_t) iobmp; /* Guest kernel virtual address of the bitmap. */
     5.9      int iobmp_limit;  /* Number of ports represented in the bitmap.  */
    5.10      int iopl;         /* Current IOPL for this VCPU. */
    5.11  
     6.1 --- a/xen/include/public/physdev.h	Wed Nov 15 14:59:57 2006 +0000
     6.2 +++ b/xen/include/public/physdev.h	Wed Nov 15 16:44:35 2006 +0000
     6.3 @@ -1,4 +1,3 @@
     6.4 -
     6.5  /*
     6.6   * Permission is hereby granted, free of charge, to any person obtaining a copy
     6.7   * of this software and associated documentation files (the "Software"), to
     6.8 @@ -82,7 +81,7 @@ DEFINE_XEN_GUEST_HANDLE(physdev_set_iopl
     6.9  #define PHYSDEVOP_set_iobitmap           7
    6.10  struct physdev_set_iobitmap {
    6.11      /* IN */
    6.12 -    uint8_t *bitmap;
    6.13 +    XEN_GUEST_HANDLE_00030205(uint8_t) bitmap;
    6.14      uint32_t nr_ports;
    6.15  };
    6.16  typedef struct physdev_set_iobitmap physdev_set_iobitmap_t;
     7.1 --- a/xen/include/public/vcpu.h	Wed Nov 15 14:59:57 2006 +0000
     7.2 +++ b/xen/include/public/vcpu.h	Wed Nov 15 16:44:35 2006 +0000
     7.3 @@ -86,6 +86,7 @@ struct vcpu_runstate_info {
     7.4      uint64_t time[4];
     7.5  };
     7.6  typedef struct vcpu_runstate_info vcpu_runstate_info_t;
     7.7 +DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t);
     7.8  
     7.9  /* VCPU is currently running on a physical CPU. */
    7.10  #define RUNSTATE_running  0
    7.11 @@ -108,8 +109,9 @@ typedef struct vcpu_runstate_info vcpu_r
    7.12   * Register a shared memory area from which the guest may obtain its own
    7.13   * runstate information without needing to execute a hypercall.
    7.14   * Notes:
    7.15 - *  1. The registered address may be virtual or physical, depending on the
    7.16 - *     platform. The virtual address should be registered on x86 systems.
    7.17 + *  1. The registered address may be virtual or physical or guest handle,
    7.18 + *     depending on the platform. Virtual address or guest handle should be
    7.19 + *     registered on x86 systems.
    7.20   *  2. Only one shared area may be registered per VCPU. The shared area is
    7.21   *     updated by the hypervisor each time the VCPU is scheduled. Thus
    7.22   *     runstate.state will always be RUNSTATE_running and
    7.23 @@ -120,6 +122,7 @@ typedef struct vcpu_runstate_info vcpu_r
    7.24  #define VCPUOP_register_runstate_memory_area 5
    7.25  struct vcpu_register_runstate_memory_area {
    7.26      union {
    7.27 +        XEN_GUEST_HANDLE(vcpu_runstate_info_t) h;
    7.28          struct vcpu_runstate_info *v;
    7.29          uint64_t p;
    7.30      } addr;
     8.1 --- a/xen/include/public/xen-compat.h	Wed Nov 15 14:59:57 2006 +0000
     8.2 +++ b/xen/include/public/xen-compat.h	Wed Nov 15 16:44:35 2006 +0000
     8.3 @@ -27,7 +27,7 @@
     8.4  #ifndef __XEN_PUBLIC_XEN_COMPAT_H__
     8.5  #define __XEN_PUBLIC_XEN_COMPAT_H__
     8.6  
     8.7 -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00030204
     8.8 +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00030205
     8.9  
    8.10  #if defined(__XEN__) || defined(__XEN_TOOLS__)
    8.11  /* Xen is built with matching headers and implements the latest interface. */
    8.12 @@ -41,4 +41,11 @@
    8.13  #error "These header files do not support the requested interface version."
    8.14  #endif
    8.15  
    8.16 +/* Fields defined as a Xen guest handle since 0x00030205. */
    8.17 +#if __XEN_INTERFACE_VERSION__ >= 0x00030205
    8.18 +#define XEN_GUEST_HANDLE_00030205(type) XEN_GUEST_HANDLE(type)
    8.19 +#else
    8.20 +#define XEN_GUEST_HANDLE_00030205(type) type *
    8.21 +#endif
    8.22 +
    8.23  #endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */
     9.1 --- a/xen/include/public/xen.h	Wed Nov 15 14:59:57 2006 +0000
     9.2 +++ b/xen/include/public/xen.h	Wed Nov 15 16:44:35 2006 +0000
     9.3 @@ -246,7 +246,7 @@ struct mmuext_op {
     9.4          /* SET_LDT */
     9.5          unsigned int nr_ents;
     9.6          /* TLB_FLUSH_MULTI, INVLPG_MULTI */
     9.7 -        void *vcpumask;
     9.8 +        XEN_GUEST_HANDLE_00030205(void) vcpumask;
     9.9      } arg2;
    9.10  };
    9.11  typedef struct mmuext_op mmuext_op_t;
    10.1 --- a/xen/include/xen/sched.h	Wed Nov 15 14:59:57 2006 +0000
    10.2 +++ b/xen/include/xen/sched.h	Wed Nov 15 16:44:35 2006 +0000
    10.3 @@ -75,7 +75,7 @@ struct vcpu
    10.4      void            *sched_priv;    /* scheduler-specific data */
    10.5  
    10.6      struct vcpu_runstate_info runstate;
    10.7 -    struct vcpu_runstate_info *runstate_guest; /* guest address */
    10.8 +    XEN_GUEST_HANDLE(vcpu_runstate_info_t) runstate_guest; /* guest address */
    10.9  
   10.10      unsigned long    vcpu_flags;
   10.11