2 * This contains the io-permission bitmap code - written by obz, with changes
3 * by Linus. 32/64 bits code unification by Miguel Botón.
6 #include <linux/sched.h>
7 #include <linux/kernel.h>
8 #include <linux/capability.h>
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/ioport.h>
12 #include <linux/smp.h>
13 #include <linux/stddef.h>
14 #include <linux/slab.h>
15 #include <linux/thread_info.h>
16 #include <linux/syscalls.h>
17 #include <asm/syscalls.h>
18 #include <xen/interface/physdev.h>
20 /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
21 static void set_bitmap(unsigned long *bitmap, unsigned int base,
22 unsigned int extent, int new_value)
26 for (i = base; i < base + extent; i++) {
30 __clear_bit(i, bitmap);
35 * this changes the io permissions bitmap in the current task.
37 asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
39 struct thread_struct *t = ¤t->thread;
40 struct physdev_set_iobitmap set_iobitmap;
42 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
44 if (turn_on && !capable(CAP_SYS_RAWIO))
48 * If it's the first ioperm() call in this thread's lifetime, set the
49 * IO bitmap up. ioperm() is much less timing critical than clone(),
50 * this is why we delay this operation until now:
52 if (!t->io_bitmap_ptr) {
53 unsigned long *bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
58 memset(bitmap, 0xff, IO_BITMAP_BYTES);
59 t->io_bitmap_ptr = bitmap;
60 set_thread_flag(TIF_IO_BITMAP);
62 set_xen_guest_handle(set_iobitmap.bitmap, (char *)bitmap);
63 set_iobitmap.nr_ports = IO_BITMAP_BITS;
64 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap,
68 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
74 * sys_iopl has to be used when you want to access the IO ports
75 * beyond the 0x3ff range: to get the full 65536 ports bitmapped
76 * you'd need 8kB of bitmaps/process, which is a bit excessive.
78 long sys_iopl(unsigned int level, struct pt_regs *regs)
80 struct thread_struct *t = ¤t->thread;
81 unsigned int old = t->iopl >> 12;
85 /* Trying to gain more privileges? */
87 if (!capable(CAP_SYS_RAWIO))
90 t->iopl = level << 12;
91 set_iopl_mask(t->iopl);