direct-io.hg

changeset 5662:abc0a8f65be7

Fix grant-table interface by removing the unnecessary union.
This fixes a domU crash introduced over the weekend.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jul 04 15:34:57 2005 +0000 (2005-07-04)
parents e1fbb7fee1d8
children 8bd2e8933277
files linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c tools/libxc/xc_gnttab.c xen/include/public/grant_table.h
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c	Mon Jul 04 15:01:22 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c	Mon Jul 04 15:34:57 2005 +0000
     1.3 @@ -116,23 +116,23 @@ static void make_response(blkif_t *blkif
     1.4  static void fast_flush_area(int idx, int nr_pages)
     1.5  {
     1.6  #ifdef CONFIG_XEN_BLKDEV_GRANT
     1.7 -    gnttab_op_t       aop[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     1.8 -    unsigned int      i, invcount = 0;
     1.9 -    u16               handle;
    1.10 +    struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    1.11 +    unsigned int i, invcount = 0;
    1.12 +    u16 handle;
    1.13  
    1.14      for ( i = 0; i < nr_pages; i++ )
    1.15      {
    1.16          if ( BLKBACK_INVALID_HANDLE != ( handle = pending_handle(idx, i) ) )
    1.17          {
    1.18 -            aop[i].u.unmap_grant_ref.host_virt_addr = MMAP_VADDR(idx, i);
    1.19 -            aop[i].u.unmap_grant_ref.dev_bus_addr   = 0;
    1.20 -            aop[i].u.unmap_grant_ref.handle         = handle;
    1.21 +            unmap[i].host_virt_addr = MMAP_VADDR(idx, i);
    1.22 +            unmap[i].dev_bus_addr   = 0;
    1.23 +            unmap[i].handle         = handle;
    1.24              pending_handle(idx, i) = BLKBACK_INVALID_HANDLE;
    1.25              invcount++;
    1.26          }
    1.27      }
    1.28      if ( unlikely(HYPERVISOR_grant_table_op(
    1.29 -                    GNTTABOP_unmap_grant_ref, aop, invcount)))
    1.30 +                    GNTTABOP_unmap_grant_ref, unmap, invcount)))
    1.31          BUG();
    1.32  #else
    1.33  
    1.34 @@ -387,21 +387,21 @@ static void dispatch_probe(blkif_t *blki
    1.35  
    1.36  #ifdef CONFIG_XEN_BLKDEV_GRANT
    1.37      {
    1.38 -        gnttab_op_t     op;
    1.39 +        struct gnttab_map_grant_ref map;
    1.40  
    1.41 -        op.u.map_grant_ref.host_virt_addr = MMAP_VADDR(pending_idx, 0);
    1.42 -        op.u.map_grant_ref.flags = GNTMAP_host_map;
    1.43 -        op.u.map_grant_ref.ref = blkif_gref_from_fas(req->frame_and_sects[0]);
    1.44 -        op.u.map_grant_ref.dom = blkif->domid;
    1.45 +        map.host_virt_addr = MMAP_VADDR(pending_idx, 0);
    1.46 +        map.flags = GNTMAP_host_map;
    1.47 +        map.ref = blkif_gref_from_fas(req->frame_and_sects[0]);
    1.48 +        map.dom = blkif->domid;
    1.49  
    1.50          if ( unlikely(HYPERVISOR_grant_table_op(
    1.51 -                        GNTTABOP_map_grant_ref, &op, 1)))
    1.52 +                        GNTTABOP_map_grant_ref, &map, 1)))
    1.53              BUG();
    1.54  
    1.55 -        if ( op.u.map_grant_ref.handle < 0 )
    1.56 +        if ( map.handle < 0 )
    1.57              goto out;
    1.58  
    1.59 -        pending_handle(pending_idx, 0) = op.u.map_grant_ref.handle;
    1.60 +        pending_handle(pending_idx, 0) = map.handle;
    1.61      }
    1.62  #else /* else CONFIG_XEN_BLKDEV_GRANT */
    1.63  
    1.64 @@ -445,7 +445,7 @@ static void dispatch_rw_block_io(blkif_t
    1.65      int i, pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
    1.66      pending_req_t *pending_req;
    1.67  #ifdef CONFIG_XEN_BLKDEV_GRANT
    1.68 -    gnttab_op_t       aop[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    1.69 +    struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    1.70  #else
    1.71      unsigned long remap_prot;
    1.72      multicall_entry_t mcl[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    1.73 @@ -486,21 +486,21 @@ static void dispatch_rw_block_io(blkif_t
    1.74              goto bad_descriptor;
    1.75          preq.nr_sects += seg[i].nsec;
    1.76  
    1.77 -        aop[i].u.map_grant_ref.host_virt_addr = MMAP_VADDR(pending_idx, i);
    1.78 -        aop[i].u.map_grant_ref.dom = blkif->domid;
    1.79 -        aop[i].u.map_grant_ref.ref = blkif_gref_from_fas(fas);
    1.80 -        aop[i].u.map_grant_ref.flags = GNTMAP_host_map;
    1.81 +        map[i].host_virt_addr = MMAP_VADDR(pending_idx, i);
    1.82 +        map[i].dom = blkif->domid;
    1.83 +        map[i].ref = blkif_gref_from_fas(fas);
    1.84 +        map[i].flags = GNTMAP_host_map;
    1.85          if ( operation == WRITE )
    1.86 -            aop[i].u.map_grant_ref.flags |= GNTMAP_readonly;
    1.87 +            map[i].flags |= GNTMAP_readonly;
    1.88      }
    1.89  
    1.90      if ( unlikely(HYPERVISOR_grant_table_op(
    1.91 -                    GNTTABOP_map_grant_ref, aop, nseg)))
    1.92 +                    GNTTABOP_map_grant_ref, map, nseg)))
    1.93          BUG();
    1.94  
    1.95      for ( i = 0; i < nseg; i++ )
    1.96      {
    1.97 -        if ( unlikely(aop[i].u.map_grant_ref.handle < 0) )
    1.98 +        if ( unlikely(map[i].handle < 0) )
    1.99          {
   1.100              DPRINTK("invalid buffer -- could not remap it\n");
   1.101              fast_flush_area(pending_idx, nseg);
   1.102 @@ -508,9 +508,9 @@ static void dispatch_rw_block_io(blkif_t
   1.103          }
   1.104  
   1.105          phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
   1.106 -            FOREIGN_FRAME(aop[i].u.map_grant_ref.dev_bus_addr);
   1.107 +            FOREIGN_FRAME(map[i].dev_bus_addr);
   1.108  
   1.109 -        pending_handle(pending_idx, i) = aop[i].u.map_grant_ref.handle;
   1.110 +        pending_handle(pending_idx, i) = map[i].handle;
   1.111      }
   1.112  #endif
   1.113  
   1.114 @@ -518,7 +518,7 @@ static void dispatch_rw_block_io(blkif_t
   1.115      {
   1.116          fas         = req->frame_and_sects[i];
   1.117  #ifdef CONFIG_XEN_BLKDEV_GRANT
   1.118 -        seg[i].buf  = (aop[i].u.map_grant_ref.dev_bus_addr << PAGE_SHIFT) |
   1.119 +        seg[i].buf  = (map[i].dev_bus_addr << PAGE_SHIFT) |
   1.120                        (blkif_first_sect(fas) << 9);
   1.121  #else
   1.122          seg[i].buf  = (fas & PAGE_MASK) | (blkif_first_sect(fas) << 9);
     2.1 --- a/tools/libxc/xc_gnttab.c	Mon Jul 04 15:01:22 2005 +0000
     2.2 +++ b/tools/libxc/xc_gnttab.c	Mon Jul 04 15:34:57 2005 +0000
     2.3 @@ -11,20 +11,20 @@
     2.4  #include "xen/grant_table.h"
     2.5  
     2.6  static int
     2.7 -do_gnttab_op( int xc_handle,
     2.8 -              unsigned long cmd,
     2.9 -              gnttab_op_t *op,
    2.10 -              unsigned long count )
    2.11 +do_gnttab_op(int xc_handle,
    2.12 +             unsigned long cmd,
    2.13 +             void *op,
    2.14 +             unsigned long count)
    2.15  {
    2.16      int ret = -1;
    2.17      privcmd_hypercall_t hypercall;
    2.18  
    2.19      hypercall.op     = __HYPERVISOR_grant_table_op;
    2.20      hypercall.arg[0] = cmd;
    2.21 -    hypercall.arg[1] = (unsigned long)(op);
    2.22 +    hypercall.arg[1] = (unsigned long)op;
    2.23      hypercall.arg[2] = count;
    2.24  
    2.25 -    if ( mlock(op, sizeof(*op)) != 0 )
    2.26 +    if ( mlock(op, 64) )
    2.27      {
    2.28          PERROR("do_gnttab_op: op mlock failed");
    2.29          goto out;
    2.30 @@ -33,7 +33,7 @@ do_gnttab_op( int xc_handle,
    2.31      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
    2.32          ERROR("do_gnttab_op: HYPERVISOR_grant_table_op failed: %d", ret);
    2.33  
    2.34 -    safe_munlock(op, sizeof(*op));
    2.35 +    safe_munlock(op, 64);
    2.36   out:
    2.37      return ret;
    2.38  }
    2.39 @@ -47,18 +47,19 @@ int xc_gnttab_map_grant_ref(int         
    2.40                              s16        *handle,
    2.41                              memory_t   *dev_bus_addr)
    2.42  {
    2.43 -    gnttab_op_t     op;
    2.44 -    int             rc;
    2.45 +    struct gnttab_map_grant_ref op;
    2.46 +    int rc;
    2.47  
    2.48 -    op.u.map_grant_ref.host_virt_addr = host_virt_addr;
    2.49 -    op.u.map_grant_ref.dom            = (domid_t)dom;
    2.50 -    op.u.map_grant_ref.ref            = ref;
    2.51 -    op.u.map_grant_ref.flags          = flags;
    2.52 +    op.host_virt_addr = host_virt_addr;
    2.53 +    op.dom            = (domid_t)dom;
    2.54 +    op.ref            = ref;
    2.55 +    op.flags          = flags;
    2.56   
    2.57 -    if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref, &op, 1)) == 0 )
    2.58 +    if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref,
    2.59 +                            &op, 1)) == 0 )
    2.60      {
    2.61 -        *handle         = op.u.map_grant_ref.handle;
    2.62 -        *dev_bus_addr   = op.u.map_grant_ref.dev_bus_addr;
    2.63 +        *handle         = op.handle;
    2.64 +        *dev_bus_addr   = op.dev_bus_addr;
    2.65      }
    2.66  
    2.67      return rc;
    2.68 @@ -71,15 +72,18 @@ int xc_gnttab_unmap_grant_ref(int       
    2.69                                u16       handle,
    2.70                                s16      *status)
    2.71  {
    2.72 -    gnttab_op_t     op;
    2.73 -    int             rc;
    2.74 +    struct gnttab_unmap_grant_ref op;
    2.75 +    int rc;
    2.76  
    2.77 -    op.u.unmap_grant_ref.host_virt_addr = host_virt_addr;
    2.78 -    op.u.unmap_grant_ref.dev_bus_addr   = dev_bus_addr;
    2.79 -    op.u.unmap_grant_ref.handle         = handle;
    2.80 +    op.host_virt_addr = host_virt_addr;
    2.81 +    op.dev_bus_addr   = dev_bus_addr;
    2.82 +    op.handle         = handle;
    2.83   
    2.84 -    if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_unmap_grant_ref, &op, 1)) == 0 )
    2.85 -        *status = op.u.unmap_grant_ref.status;
    2.86 +    if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_unmap_grant_ref,
    2.87 +                            &op, 1)) == 0 )
    2.88 +    {
    2.89 +        *status = op.status;
    2.90 +    }
    2.91  
    2.92      return rc;
    2.93  }
    2.94 @@ -90,20 +94,17 @@ int xc_gnttab_setup_table(int        xc_
    2.95                            s16       *status,
    2.96                            memory_t **frame_list)
    2.97  {
    2.98 -    gnttab_op_t     op;
    2.99 -    int             rc;
   2.100 -    int             i;
   2.101 +    struct gnttab_setup_table op;
   2.102 +    int rc, i;
   2.103  
   2.104 -    op.u.setup_table.dom        = (domid_t)dom;
   2.105 -    op.u.setup_table.nr_frames  = nr_frames;
   2.106 +    op.dom       = (domid_t)dom;
   2.107 +    op.nr_frames = nr_frames;
   2.108   
   2.109      if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_setup_table, &op, 1)) == 0 )
   2.110      {
   2.111 -        *status = op.u.setup_table.status;
   2.112 +        *status = op.status;
   2.113          for ( i = 0; i < nr_frames; i++ )
   2.114 -        {
   2.115 -            (*frame_list)[i] = op.u.setup_table.frame_list[i];
   2.116 -        }
   2.117 +            (*frame_list)[i] = op.frame_list[i];
   2.118      }
   2.119  
   2.120      return rc;
   2.121 @@ -113,15 +114,13 @@ int xc_gnttab_dump_table(int        xc_h
   2.122                           u32        dom,
   2.123                           s16       *status)
   2.124  {
   2.125 -    gnttab_op_t     op;
   2.126 -    int             rc;
   2.127 +    struct gnttab_dump_table op;
   2.128 +    int rc;
   2.129  
   2.130 -    op.u.dump_table.dom = (domid_t)dom;
   2.131 - 
   2.132 -    printf("xc_gnttab_dump_table: domain %d\n", dom);
   2.133 +    op.dom = (domid_t)dom;
   2.134  
   2.135      if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_dump_table, &op, 1)) == 0 )
   2.136 -        *status = op.u.dump_table.status;
   2.137 +        *status = op.status;
   2.138  
   2.139      return rc;
   2.140  }
     3.1 --- a/xen/include/public/grant_table.h	Mon Jul 04 15:01:22 2005 +0000
     3.2 +++ b/xen/include/public/grant_table.h	Mon Jul 04 15:34:57 2005 +0000
     3.3 @@ -259,13 +259,4 @@ typedef struct gnttab_dump_table {
     3.4      "permission denied"                         \
     3.5  }
     3.6  
     3.7 -typedef struct gnttab_op {
     3.8 -    union {
     3.9 -        gnttab_map_grant_ref_t    map_grant_ref;
    3.10 -        gnttab_unmap_grant_ref_t  unmap_grant_ref;
    3.11 -        gnttab_setup_table_t      setup_table;
    3.12 -        gnttab_dump_table_t       dump_table;
    3.13 -    } u;
    3.14 -} gnttab_op_t;
    3.15 -
    3.16  #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */