ia64/xen-unstable

changeset 3051:e16455258e29

bitkeeper revision 1.1159.170.51 (419dbb56dorYDf7SCsweJDYesNBypg)

Merge scramble.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-2.0-testing.bk
into scramble.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-unstable.bk
author kaf24@scramble.cl.cam.ac.uk
date Fri Nov 19 09:22:30 2004 +0000 (2004-11-19)
parents 81e74f5bf690 ef0abb9f8b5d
children d64da6d97856
files xen/arch/x86/domain.c xen/arch/x86/setup.c xen/arch/x86/traps.c xen/common/physdev.c xen/include/asm-x86/processor.h xen/include/xen/sched.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Thu Nov 18 16:06:42 2004 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Fri Nov 19 09:22:30 2004 +0000
     1.3 @@ -389,60 +389,23 @@ void switch_to(struct domain *prev_p, st
     1.4          write_ptbase(&next_p->mm);
     1.5      }
     1.6  
     1.7 -    if ( unlikely(prev_p->io_bitmap != NULL) || 
     1.8 -         unlikely(next_p->io_bitmap != NULL) )
     1.9 +    if ( unlikely(prev_p->thread.io_bitmap != NULL) )
    1.10      {
    1.11 -        if ( next_p->io_bitmap != NULL )
    1.12 -        {
    1.13 -            /* Copy in the appropriate parts of the IO bitmap.  We use the
    1.14 -             * selector to copy only the interesting parts of the bitmap. */
    1.15 -
    1.16 -            u64 old_sel = ~0ULL; /* IO bitmap selector for previous task. */
    1.17 -
    1.18 -            if ( prev_p->io_bitmap != NULL)
    1.19 -            {
    1.20 -                old_sel = prev_p->io_bitmap_sel;
    1.21 -
    1.22 -                /* Replace any areas of the IO bitmap that had bits cleared. */
    1.23 -                for ( i = 0; i < sizeof(prev_p->io_bitmap_sel) * 8; i++ )
    1.24 -                    if ( !test_bit(i, &prev_p->io_bitmap_sel) )
    1.25 -                        memcpy(&tss->io_bitmap[i * IOBMP_SELBIT_LWORDS],
    1.26 -                               &next_p->io_bitmap[i * IOBMP_SELBIT_LWORDS],
    1.27 -                               IOBMP_SELBIT_LWORDS * sizeof(unsigned long));
    1.28 -            }
    1.29 +        for ( i = 0; i < sizeof(prev_p->thread.io_bitmap_sel) * 8; i++ )
    1.30 +            if ( !test_bit(i, &prev_p->thread.io_bitmap_sel) )
    1.31 +                memset(&tss->io_bitmap[i * IOBMP_BYTES_PER_SELBIT],
    1.32 +                       ~0U, IOBMP_BYTES_PER_SELBIT);
    1.33 +        tss->bitmap = IOBMP_INVALID_OFFSET;
    1.34 +    }
    1.35  
    1.36 -            /* Copy in any regions of the new task's bitmap that have bits
    1.37 -             * clear and we haven't already dealt with. */
    1.38 -            for ( i = 0; i < sizeof(prev_p->io_bitmap_sel) * 8; i++ )
    1.39 -            {
    1.40 -                if ( test_bit(i, &old_sel)
    1.41 -                     && !test_bit(i, &next_p->io_bitmap_sel) )
    1.42 -                    memcpy(&tss->io_bitmap[i * IOBMP_SELBIT_LWORDS],
    1.43 -                           &next_p->io_bitmap[i * IOBMP_SELBIT_LWORDS],
    1.44 -                           IOBMP_SELBIT_LWORDS * sizeof(unsigned long));
    1.45 -            }
    1.46 -
    1.47 -            tss->bitmap = IO_BITMAP_OFFSET;
    1.48 -
    1.49 -	}
    1.50 -        else
    1.51 -        {
    1.52 -            /* In this case, we're switching FROM a task with IO port access,
    1.53 -             * to a task that doesn't use the IO bitmap.  We set any TSS bits
    1.54 -             * that might have been cleared, ready for future use. */
    1.55 -            for ( i = 0; i < sizeof(prev_p->io_bitmap_sel) * 8; i++ )
    1.56 -                if ( !test_bit(i, &prev_p->io_bitmap_sel) )
    1.57 -                    memset(&tss->io_bitmap[i * IOBMP_SELBIT_LWORDS],
    1.58 -                           0xFF, IOBMP_SELBIT_LWORDS * sizeof(unsigned long));
    1.59 -
    1.60 -            /*
    1.61 -             * a bitmap offset pointing outside of the TSS limit
    1.62 -             * causes a nicely controllable SIGSEGV if a process
    1.63 -             * tries to use a port IO instruction. The first
    1.64 -             * sys_ioperm() call sets up the bitmap properly.
    1.65 -             */
    1.66 -            tss->bitmap = INVALID_IO_BITMAP_OFFSET;
    1.67 -	}
    1.68 +    if ( unlikely(next_p->thread.io_bitmap != NULL) )
    1.69 +    {
    1.70 +        for ( i = 0; i < sizeof(next_p->thread.io_bitmap_sel) * 8; i++ )
    1.71 +            if ( !test_bit(i, &next_p->thread.io_bitmap_sel) )
    1.72 +                memcpy(&tss->io_bitmap[i * IOBMP_BYTES_PER_SELBIT],
    1.73 +                       &next_p->thread.io_bitmap[i * IOBMP_BYTES_PER_SELBIT],
    1.74 +                       IOBMP_BYTES_PER_SELBIT);
    1.75 +        tss->bitmap = IOBMP_OFFSET;
    1.76      }
    1.77  
    1.78      set_current(next_p);
     2.1 --- a/xen/arch/x86/setup.c	Thu Nov 18 16:06:42 2004 +0000
     2.2 +++ b/xen/arch/x86/setup.c	Fri Nov 19 09:22:30 2004 +0000
     2.3 @@ -268,7 +268,7 @@ void __init cpu_init(void)
     2.4          panic("CPU#%d already initialized!!!\n", nr);
     2.5      printk("Initializing CPU#%d\n", nr);
     2.6  
     2.7 -    t->bitmap = INVALID_IO_BITMAP_OFFSET;
     2.8 +    t->bitmap = IOBMP_INVALID_OFFSET;
     2.9      memset(t->io_bitmap, ~0, sizeof(t->io_bitmap));
    2.10  
    2.11      /* Set up GDT and IDT. */
     3.1 --- a/xen/arch/x86/traps.c	Thu Nov 18 16:06:42 2004 +0000
     3.2 +++ b/xen/arch/x86/traps.c	Fri Nov 19 09:22:30 2004 +0000
     3.3 @@ -721,7 +721,7 @@ void __init trap_init(void)
     3.4      tss->cs     = __HYPERVISOR_CS;
     3.5      tss->eip    = (unsigned long)do_double_fault;
     3.6      tss->eflags = 2;
     3.7 -    tss->bitmap = INVALID_IO_BITMAP_OFFSET;
     3.8 +    tss->bitmap = IOBMP_INVALID_OFFSET;
     3.9      _set_tssldt_desc(gdt_table+__DOUBLEFAULT_TSS_ENTRY,
    3.10                       (int)tss, 235, 0x89);
    3.11  
     4.1 --- a/xen/common/physdev.c	Thu Nov 18 16:06:42 2004 +0000
     4.2 +++ b/xen/common/physdev.c	Fri Nov 19 09:22:30 2004 +0000
     4.3 @@ -169,16 +169,16 @@ int physdev_pci_access_modify(
     4.4  
     4.5      /* Now, setup access to the IO ports and memory regions for the device. */
     4.6  
     4.7 -    if ( p->io_bitmap == NULL )
     4.8 +    if ( p->thread.io_bitmap == NULL )
     4.9      {
    4.10 -        if ( (p->io_bitmap = xmalloc(IO_BITMAP_BYTES)) == NULL )
    4.11 +        if ( (p->thread.io_bitmap = xmalloc(IOBMP_BYTES)) == NULL )
    4.12          {
    4.13              rc = -ENOMEM;
    4.14              goto out;
    4.15          }
    4.16 -        memset(p->io_bitmap, 0xFF, IO_BITMAP_BYTES);
    4.17 +        memset(p->thread.io_bitmap, 0xFF, IOBMP_BYTES);
    4.18  
    4.19 -        p->io_bitmap_sel = ~0ULL;
    4.20 +        p->thread.io_bitmap_sel = ~0ULL;
    4.21      }
    4.22  
    4.23      for ( i = 0; i < DEVICE_COUNT_RESOURCE; i++ )
    4.24 @@ -195,13 +195,8 @@ int physdev_pci_access_modify(
    4.25                   "for device %s\n", dom, r->start, r->end, pdev->slot_name);
    4.26              for ( j = r->start; j < r->end + 1; j++ )
    4.27              {
    4.28 -                clear_bit(j, p->io_bitmap);
    4.29 -                /* Record that we cleared a bit using bit n of the selector:
    4.30 -                 * n = (j / (4 bytes in a word * 8 bits in a byte))
    4.31 -                 *     / number of words per selector bit
    4.32 -                 */
    4.33 -                clear_bit((j / (8 * 4)) / IOBMP_SELBIT_LWORDS,
    4.34 -                          &p->io_bitmap_sel);
    4.35 +                clear_bit(j, p->thread.io_bitmap);
    4.36 +                clear_bit(j / IOBMP_BITS_PER_SELBIT, &p->thread.io_bitmap_sel);
    4.37              }
    4.38          }
    4.39  
     5.1 --- a/xen/include/asm-x86/processor.h	Thu Nov 18 16:06:42 2004 +0000
     5.2 +++ b/xen/include/asm-x86/processor.h	Fri Nov 19 09:22:30 2004 +0000
     5.3 @@ -244,15 +244,11 @@ static inline void clear_in_cr4 (unsigne
     5.4              :"ax");
     5.5  }
     5.6  
     5.7 -/*
     5.8 - * Size of io_bitmap in longwords:
     5.9 - * For Xen we support the full 8kbyte IO bitmap but use the io_bitmap_sel field
    5.10 - * to avoid a full 8kbyte copy when switching to domains with bits cleared.
    5.11 - */
    5.12 -#define IO_BITMAP_SIZE	2048
    5.13 -#define IO_BITMAP_BYTES (IO_BITMAP_SIZE * 4)
    5.14 -#define IO_BITMAP_OFFSET offsetof(struct tss_struct,io_bitmap)
    5.15 -#define INVALID_IO_BITMAP_OFFSET 0x8000
    5.16 +#define IOBMP_BYTES             8192
    5.17 +#define IOBMP_BYTES_PER_SELBIT  (IOBMP_BYTES / 64)
    5.18 +#define IOBMP_BITS_PER_SELBIT   (IOBMP_BYTES_PER_SELBIT * 8)
    5.19 +#define IOBMP_OFFSET            offsetof(struct tss_struct,io_bitmap)
    5.20 +#define IOBMP_INVALID_OFFSET    0x8000
    5.21  
    5.22  struct i387_state {
    5.23      u8 state[512]; /* big enough for FXSAVE */
    5.24 @@ -293,7 +289,7 @@ struct tss_struct {
    5.25      u16 trace;
    5.26  #endif
    5.27      u16 bitmap;
    5.28 -    u32 io_bitmap[IO_BITMAP_SIZE+1];
    5.29 +    u8  io_bitmap[IOBMP_BYTES];
    5.30      /* Pads the TSS to be cacheline-aligned (total size is 0x2080). */
    5.31      u32 __cacheline_filler[5];
    5.32  };
    5.33 @@ -335,6 +331,11 @@ struct thread_struct {
    5.34      /* Bounce information for propagating an exception to guest OS. */
    5.35      struct trap_bounce trap_bounce;
    5.36  
    5.37 +    /* I/O-port access bitmap. */
    5.38 +    u64 io_bitmap_sel; /* Selector to tell us which part of the IO bitmap are
    5.39 +                        * "interesting" (i.e. have clear bits) */
    5.40 +    u8 *io_bitmap; /* Pointer to task's IO bitmap or NULL */
    5.41 +
    5.42      /* Trap info. */
    5.43  #ifdef __i386__
    5.44      int                fast_trap_idx;
     6.1 --- a/xen/include/xen/sched.h	Thu Nov 18 16:06:42 2004 +0000
     6.2 +++ b/xen/include/xen/sched.h	Fri Nov 19 09:22:30 2004 +0000
     6.3 @@ -104,14 +104,6 @@ struct domain
     6.4      spinlock_t       pcidev_lock;
     6.5      struct list_head pcidev_list;
     6.6  
     6.7 -    /* The following IO bitmap stuff is x86-dependent. */
     6.8 -    u64 io_bitmap_sel; /* Selector to tell us which part of the IO bitmap are
     6.9 -                        * "interesting" (i.e. have clear bits) */
    6.10 -
    6.11 -    /* Handy macro - number of bytes of the IO bitmap, per selector bit. */
    6.12 -#define IOBMP_SELBIT_LWORDS (IO_BITMAP_SIZE / 64)
    6.13 -    unsigned long *io_bitmap; /* Pointer to task's IO bitmap or NULL */
    6.14 -
    6.15      unsigned long flags;
    6.16      unsigned long vm_assist;
    6.17