2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1994 Linus Torvalds
|
|
|
|
*
|
|
|
|
* 29 dec 2001 - Fixed oopses caused by unchecked access to the vm86
|
2006-01-15 01:43:54 +00:00
|
|
|
* stack - Manfred Spraul <manfred@colorfullife.com>
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 22 mar 2002 - Manfred detected the stackfaults, but didn't handle
|
|
|
|
* them correctly. Now the emulation will be in a
|
|
|
|
* consistent state after stackfaults - Kasper Dupont
|
|
|
|
* <kasperd@daimi.au.dk>
|
|
|
|
*
|
|
|
|
* 22 mar 2002 - Added missing clear_IF in set_vflags_* Kasper Dupont
|
|
|
|
* <kasperd@daimi.au.dk>
|
|
|
|
*
|
|
|
|
* ?? ??? 2002 - Fixed premature returns from handle_vm86_fault
|
|
|
|
* caused by Kasper Dupont's changes - Stas Sergeev
|
|
|
|
*
|
|
|
|
* 4 apr 2002 - Fixed CHECK_IF_IN_TRAP broken by Stas' changes.
|
|
|
|
* Kasper Dupont <kasperd@daimi.au.dk>
|
|
|
|
*
|
|
|
|
* 9 apr 2002 - Changed syntax of macros in handle_vm86_fault.
|
|
|
|
* Kasper Dupont <kasperd@daimi.au.dk>
|
|
|
|
*
|
|
|
|
* 9 apr 2002 - Changed stack access macros to jump to a label
|
|
|
|
* instead of returning to userspace. This simplifies
|
|
|
|
* do_int, and is needed by handle_vm6_fault. Kasper
|
|
|
|
* Dupont <kasperd@daimi.au.dk>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-01-11 20:17:48 +00:00
|
|
|
#include <linux/capability.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/ptrace.h>
|
2006-01-31 21:56:28 +00:00
|
|
|
#include <linux/audit.h>
|
2006-12-07 01:14:03 +00:00
|
|
|
#include <linux/stddef.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Known problems:
|
|
|
|
*
|
|
|
|
* Interrupt handling is not guaranteed:
|
|
|
|
* - a real x86 will disable all interrupts for one instruction
|
|
|
|
* after a "mov ss,xx" to make stack handling atomic even without
|
|
|
|
* the 'lss' instruction. We can't guarantee this in v86 mode,
|
|
|
|
* as the next instruction might result in a page fault or similar.
|
|
|
|
* - a real x86 will have interrupts disabled for one instruction
|
|
|
|
* past the 'sti' that enables them. We don't bother with all the
|
|
|
|
* details yet.
|
|
|
|
*
|
|
|
|
* Let's hope these problems do not actually matter for anything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#define KVM86 ((struct kernel_vm86_struct *)regs)
|
2008-02-22 22:10:40 +00:00
|
|
|
#define VMPI KVM86->vm86plus
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 8- and 16-bit register defines..
|
|
|
|
*/
|
2008-01-30 12:30:56 +00:00
|
|
|
#define AL(regs) (((unsigned char *)&((regs)->pt.ax))[0])
|
|
|
|
#define AH(regs) (((unsigned char *)&((regs)->pt.ax))[1])
|
|
|
|
#define IP(regs) (*(unsigned short *)&((regs)->pt.ip))
|
|
|
|
#define SP(regs) (*(unsigned short *)&((regs)->pt.sp))
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* virtual flags (16 and 32-bit versions)
|
|
|
|
*/
|
|
|
|
#define VFLAGS (*(unsigned short *)&(current->thread.v86flags))
|
|
|
|
#define VEFLAGS (current->thread.v86flags)
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
#define set_flags(X, new, mask) \
|
2005-04-16 22:20:36 +00:00
|
|
|
((X) = ((X) & ~(mask)) | ((new) & (mask)))
|
|
|
|
|
|
|
|
#define SAFE_MASK (0xDD5)
|
|
|
|
#define RETURN_MASK (0xDFF)
|
|
|
|
|
2006-12-07 01:14:03 +00:00
|
|
|
/* convert kernel_vm86_regs to vm86_regs */
|
|
|
|
static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
|
|
|
|
const struct kernel_vm86_regs *regs)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
/*
|
|
|
|
* kernel_vm86_regs is missing gs, so copy everything up to
|
|
|
|
* (but not including) orig_eax, and then rest including orig_eax.
|
|
|
|
*/
|
2008-01-30 12:30:56 +00:00
|
|
|
ret += copy_to_user(user, regs, offsetof(struct kernel_vm86_regs, pt.orig_ax));
|
|
|
|
ret += copy_to_user(&user->orig_eax, ®s->pt.orig_ax,
|
2006-12-07 01:14:03 +00:00
|
|
|
sizeof(struct kernel_vm86_regs) -
|
2008-01-30 12:30:56 +00:00
|
|
|
offsetof(struct kernel_vm86_regs, pt.orig_ax));
|
2006-12-07 01:14:03 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert vm86_regs to kernel_vm86_regs */
|
|
|
|
static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
|
|
|
|
const struct vm86_regs __user *user,
|
|
|
|
unsigned extra)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-01-30 12:30:56 +00:00
|
|
|
/* copy ax-fs inclusive */
|
|
|
|
ret += copy_from_user(regs, user, offsetof(struct kernel_vm86_regs, pt.orig_ax));
|
|
|
|
/* copy orig_ax-__gsh+extra */
|
|
|
|
ret += copy_from_user(®s->pt.orig_ax, &user->orig_eax,
|
2006-12-07 01:14:03 +00:00
|
|
|
sizeof(struct kernel_vm86_regs) -
|
2008-01-30 12:30:56 +00:00
|
|
|
offsetof(struct kernel_vm86_regs, pt.orig_ax) +
|
2006-12-07 01:14:03 +00:00
|
|
|
extra);
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct tss_struct *tss;
|
|
|
|
struct pt_regs *ret;
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This gets called from entry.S with interrupts disabled, but
|
|
|
|
* from process context. Enable interrupts here, before trying
|
|
|
|
* to access user space.
|
|
|
|
*/
|
|
|
|
local_irq_enable();
|
|
|
|
|
|
|
|
if (!current->thread.vm86_info) {
|
|
|
|
printk("no vm86_info: BAD\n");
|
|
|
|
do_exit(SIGSEGV);
|
|
|
|
}
|
2008-03-28 14:56:56 +00:00
|
|
|
set_flags(regs->pt.flags, VEFLAGS, X86_EFLAGS_VIF | current->thread.v86mask);
|
2008-02-22 22:10:40 +00:00
|
|
|
tmp = copy_vm86_regs_to_user(¤t->thread.vm86_info->regs, regs);
|
|
|
|
tmp += put_user(current->thread.screen_bitmap, ¤t->thread.vm86_info->screen_bitmap);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (tmp) {
|
|
|
|
printk("vm86: could not access userspace vm86_info\n");
|
|
|
|
do_exit(SIGSEGV);
|
|
|
|
}
|
|
|
|
|
|
|
|
tss = &per_cpu(init_tss, get_cpu());
|
2008-01-30 12:31:02 +00:00
|
|
|
current->thread.sp0 = current->thread.saved_sp0;
|
2005-04-16 22:20:36 +00:00
|
|
|
current->thread.sysenter_cs = __KERNEL_CS;
|
2008-01-30 12:31:02 +00:00
|
|
|
load_sp0(tss, ¤t->thread);
|
|
|
|
current->thread.saved_sp0 = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
put_cpu();
|
|
|
|
|
|
|
|
ret = KVM86->regs32;
|
2006-12-07 01:14:03 +00:00
|
|
|
|
2008-01-30 12:30:56 +00:00
|
|
|
ret->fs = current->thread.saved_fs;
|
2007-02-13 12:26:20 +00:00
|
|
|
loadsegment(gs, current->thread.saved_gs);
|
2006-12-07 01:14:03 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-10-30 01:16:34 +00:00
|
|
|
static void mark_screen_rdonly(struct mm_struct *mm)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
pgd_t *pgd;
|
|
|
|
pud_t *pud;
|
|
|
|
pmd_t *pmd;
|
2005-10-30 01:16:34 +00:00
|
|
|
pte_t *pte;
|
|
|
|
spinlock_t *ptl;
|
2005-04-16 22:20:36 +00:00
|
|
|
int i;
|
|
|
|
|
2005-10-30 01:16:34 +00:00
|
|
|
pgd = pgd_offset(mm, 0xA0000);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pgd_none_or_clear_bad(pgd))
|
|
|
|
goto out;
|
|
|
|
pud = pud_offset(pgd, 0xA0000);
|
|
|
|
if (pud_none_or_clear_bad(pud))
|
|
|
|
goto out;
|
|
|
|
pmd = pmd_offset(pud, 0xA0000);
|
|
|
|
if (pmd_none_or_clear_bad(pmd))
|
|
|
|
goto out;
|
2005-10-30 01:16:34 +00:00
|
|
|
pte = pte_offset_map_lock(mm, pmd, 0xA0000, &ptl);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
if (pte_present(*pte))
|
|
|
|
set_pte(pte, pte_wrprotect(*pte));
|
|
|
|
pte++;
|
|
|
|
}
|
2005-10-30 01:16:34 +00:00
|
|
|
pte_unmap_unlock(pte, ptl);
|
2005-04-16 22:20:36 +00:00
|
|
|
out:
|
|
|
|
flush_tlb();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int do_vm86_irq_handling(int subfunction, int irqnumber);
|
|
|
|
static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk);
|
|
|
|
|
|
|
|
asmlinkage int sys_vm86old(struct pt_regs regs)
|
|
|
|
{
|
2008-01-30 12:30:56 +00:00
|
|
|
struct vm86_struct __user *v86 = (struct vm86_struct __user *)regs.bx;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct kernel_vm86_struct info; /* declare this _on top_,
|
|
|
|
* this avoids wasting of stack space.
|
|
|
|
* This remains on the stack until we
|
|
|
|
* return to 32 bit user space.
|
|
|
|
*/
|
|
|
|
struct task_struct *tsk;
|
|
|
|
int tmp, ret = -EPERM;
|
|
|
|
|
|
|
|
tsk = current;
|
2008-01-30 12:31:02 +00:00
|
|
|
if (tsk->thread.saved_sp0)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
2006-12-07 01:14:03 +00:00
|
|
|
tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
|
|
|
|
offsetof(struct kernel_vm86_struct, vm86plus) -
|
|
|
|
sizeof(info.regs));
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
if (tmp)
|
|
|
|
goto out;
|
|
|
|
memset(&info.vm86plus, 0, (int)&info.regs32 - (int)&info.vm86plus);
|
|
|
|
info.regs32 = ®s;
|
|
|
|
tsk->thread.vm86_info = v86;
|
|
|
|
do_sys_vm86(&info, tsk);
|
|
|
|
ret = 0; /* we never return here */
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
asmlinkage int sys_vm86(struct pt_regs regs)
|
|
|
|
{
|
|
|
|
struct kernel_vm86_struct info; /* declare this _on top_,
|
|
|
|
* this avoids wasting of stack space.
|
|
|
|
* This remains on the stack until we
|
|
|
|
* return to 32 bit user space.
|
|
|
|
*/
|
|
|
|
struct task_struct *tsk;
|
|
|
|
int tmp, ret;
|
|
|
|
struct vm86plus_struct __user *v86;
|
|
|
|
|
|
|
|
tsk = current;
|
2008-01-30 12:30:56 +00:00
|
|
|
switch (regs.bx) {
|
2008-02-22 22:10:40 +00:00
|
|
|
case VM86_REQUEST_IRQ:
|
|
|
|
case VM86_FREE_IRQ:
|
|
|
|
case VM86_GET_IRQ_BITS:
|
|
|
|
case VM86_GET_AND_RESET_IRQ:
|
|
|
|
ret = do_vm86_irq_handling(regs.bx, (int)regs.cx);
|
|
|
|
goto out;
|
|
|
|
case VM86_PLUS_INSTALL_CHECK:
|
|
|
|
/*
|
|
|
|
* NOTE: on old vm86 stuff this will return the error
|
|
|
|
* from access_ok(), because the subfunction is
|
|
|
|
* interpreted as (invalid) address to vm86_struct.
|
|
|
|
* So the installation check works.
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we come here only for functions VM86_ENTER, VM86_ENTER_NO_BYPASS */
|
|
|
|
ret = -EPERM;
|
2008-01-30 12:31:02 +00:00
|
|
|
if (tsk->thread.saved_sp0)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
2008-01-30 12:30:56 +00:00
|
|
|
v86 = (struct vm86plus_struct __user *)regs.cx;
|
2006-12-07 01:14:03 +00:00
|
|
|
tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
|
|
|
|
offsetof(struct kernel_vm86_struct, regs32) -
|
|
|
|
sizeof(info.regs));
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
if (tmp)
|
|
|
|
goto out;
|
|
|
|
info.regs32 = ®s;
|
|
|
|
info.vm86plus.is_vm86pus = 1;
|
|
|
|
tsk->thread.vm86_info = (struct vm86_struct __user *)v86;
|
|
|
|
do_sys_vm86(&info, tsk);
|
|
|
|
ret = 0; /* we never return here */
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
struct tss_struct *tss;
|
|
|
|
/*
|
|
|
|
* make sure the vm86() system call doesn't try to do anything silly
|
|
|
|
*/
|
2008-01-30 12:30:56 +00:00
|
|
|
info->regs.pt.ds = 0;
|
|
|
|
info->regs.pt.es = 0;
|
|
|
|
info->regs.pt.fs = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-02-13 12:26:20 +00:00
|
|
|
/* we are clearing gs later just before "jmp resume_userspace",
|
2006-12-07 01:14:03 +00:00
|
|
|
* because it is not saved/restored.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-01-30 12:30:56 +00:00
|
|
|
* The flags register is also special: we cannot trust that the user
|
2005-04-16 22:20:36 +00:00
|
|
|
* has set it up safely, so this makes sure interrupt etc flags are
|
|
|
|
* inherited from protected mode.
|
|
|
|
*/
|
2008-01-30 12:30:56 +00:00
|
|
|
VEFLAGS = info->regs.pt.flags;
|
|
|
|
info->regs.pt.flags &= SAFE_MASK;
|
|
|
|
info->regs.pt.flags |= info->regs32->flags & ~SAFE_MASK;
|
2008-03-28 14:56:57 +00:00
|
|
|
info->regs.pt.flags |= X86_VM_MASK;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (info->cpu_type) {
|
2008-02-22 22:10:40 +00:00
|
|
|
case CPU_286:
|
|
|
|
tsk->thread.v86mask = 0;
|
|
|
|
break;
|
|
|
|
case CPU_386:
|
2008-03-28 14:56:56 +00:00
|
|
|
tsk->thread.v86mask = X86_EFLAGS_NT | X86_EFLAGS_IOPL;
|
2008-02-22 22:10:40 +00:00
|
|
|
break;
|
|
|
|
case CPU_486:
|
2008-03-28 14:56:56 +00:00
|
|
|
tsk->thread.v86mask = X86_EFLAGS_AC | X86_EFLAGS_NT | X86_EFLAGS_IOPL;
|
2008-02-22 22:10:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-03-28 14:56:56 +00:00
|
|
|
tsk->thread.v86mask = X86_EFLAGS_ID | X86_EFLAGS_AC | X86_EFLAGS_NT | X86_EFLAGS_IOPL;
|
2008-02-22 22:10:40 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-01-30 12:30:56 +00:00
|
|
|
* Save old state, set default return value (%ax) to 0
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2008-01-30 12:30:56 +00:00
|
|
|
info->regs32->ax = 0;
|
2008-01-30 12:31:02 +00:00
|
|
|
tsk->thread.saved_sp0 = tsk->thread.sp0;
|
2008-01-30 12:30:56 +00:00
|
|
|
tsk->thread.saved_fs = info->regs32->fs;
|
2007-02-13 12:26:20 +00:00
|
|
|
savesegment(gs, tsk->thread.saved_gs);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
tss = &per_cpu(init_tss, get_cpu());
|
2008-01-30 12:31:02 +00:00
|
|
|
tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (cpu_has_sep)
|
|
|
|
tsk->thread.sysenter_cs = 0;
|
2008-01-30 12:31:02 +00:00
|
|
|
load_sp0(tss, &tsk->thread);
|
2005-04-16 22:20:36 +00:00
|
|
|
put_cpu();
|
|
|
|
|
|
|
|
tsk->thread.screen_bitmap = info->screen_bitmap;
|
|
|
|
if (info->flags & VM86_SCREEN_BITMAP)
|
2005-10-30 01:16:34 +00:00
|
|
|
mark_screen_rdonly(tsk->mm);
|
2006-01-31 21:56:28 +00:00
|
|
|
|
|
|
|
/*call audit_syscall_exit since we do not exit via the normal paths */
|
|
|
|
if (unlikely(current->audit_context))
|
2006-12-07 01:14:03 +00:00
|
|
|
audit_syscall_exit(AUDITSC_RESULT(0), 0);
|
2006-01-31 21:56:28 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"movl %0,%%esp\n\t"
|
|
|
|
"movl %1,%%ebp\n\t"
|
2007-02-13 12:26:20 +00:00
|
|
|
"mov %2, %%gs\n\t"
|
2005-04-16 22:20:36 +00:00
|
|
|
"jmp resume_userspace"
|
|
|
|
: /* no outputs */
|
2006-12-07 01:14:03 +00:00
|
|
|
:"r" (&info->regs), "r" (task_thread_info(tsk)), "r" (0));
|
2005-04-16 22:20:36 +00:00
|
|
|
/* we never return here */
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void return_to_32bit(struct kernel_vm86_regs *regs16, int retval)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-22 22:10:40 +00:00
|
|
|
struct pt_regs *regs32;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
regs32 = save_v86_state(regs16);
|
2008-01-30 12:30:56 +00:00
|
|
|
regs32->ax = retval;
|
2005-04-16 22:20:36 +00:00
|
|
|
__asm__ __volatile__("movl %0,%%esp\n\t"
|
|
|
|
"movl %1,%%ebp\n\t"
|
|
|
|
"jmp resume_userspace"
|
|
|
|
: : "r" (regs32), "r" (current_thread_info()));
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void set_IF(struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-03-28 14:56:56 +00:00
|
|
|
VEFLAGS |= X86_EFLAGS_VIF;
|
|
|
|
if (VEFLAGS & X86_EFLAGS_VIP)
|
2005-04-16 22:20:36 +00:00
|
|
|
return_to_32bit(regs, VM86_STI);
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void clear_IF(struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-03-28 14:56:56 +00:00
|
|
|
VEFLAGS &= ~X86_EFLAGS_VIF;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void clear_TF(struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-03-28 14:56:56 +00:00
|
|
|
regs->pt.flags &= ~X86_EFLAGS_TF;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void clear_AC(struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-03-28 14:56:56 +00:00
|
|
|
regs->pt.flags &= ~X86_EFLAGS_AC;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
/*
|
|
|
|
* It is correct to call set_IF(regs) from the set_vflags_*
|
2005-04-16 22:20:36 +00:00
|
|
|
* functions. However someone forgot to call clear_IF(regs)
|
|
|
|
* in the opposite case.
|
|
|
|
* After the command sequence CLI PUSHF STI POPF you should
|
2008-01-30 12:31:42 +00:00
|
|
|
* end up with interrupts disabled, but you ended up with
|
2005-04-16 22:20:36 +00:00
|
|
|
* interrupts enabled.
|
|
|
|
* ( I was testing my own changes, but the only bug I
|
|
|
|
* could find was in a function I had not changed. )
|
|
|
|
* [KD]
|
|
|
|
*/
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void set_vflags_long(unsigned long flags, struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-30 12:30:56 +00:00
|
|
|
set_flags(VEFLAGS, flags, current->thread.v86mask);
|
|
|
|
set_flags(regs->pt.flags, flags, SAFE_MASK);
|
2008-03-28 14:56:56 +00:00
|
|
|
if (flags & X86_EFLAGS_IF)
|
2005-04-16 22:20:36 +00:00
|
|
|
set_IF(regs);
|
|
|
|
else
|
|
|
|
clear_IF(regs);
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline void set_vflags_short(unsigned short flags, struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
set_flags(VFLAGS, flags, current->thread.v86mask);
|
2008-01-30 12:30:56 +00:00
|
|
|
set_flags(regs->pt.flags, flags, SAFE_MASK);
|
2008-03-28 14:56:56 +00:00
|
|
|
if (flags & X86_EFLAGS_IF)
|
2005-04-16 22:20:36 +00:00
|
|
|
set_IF(regs);
|
|
|
|
else
|
|
|
|
clear_IF(regs);
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline unsigned long get_vflags(struct kernel_vm86_regs *regs)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-30 12:30:56 +00:00
|
|
|
unsigned long flags = regs->pt.flags & RETURN_MASK;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-03-28 14:56:56 +00:00
|
|
|
if (VEFLAGS & X86_EFLAGS_VIF)
|
|
|
|
flags |= X86_EFLAGS_IF;
|
|
|
|
flags |= X86_EFLAGS_IOPL;
|
2005-04-16 22:20:36 +00:00
|
|
|
return flags | (VEFLAGS & current->thread.v86mask);
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
static inline int is_revectored(int nr, struct revectored_struct *bitmap)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
|
|
|
|
:"=r" (nr)
|
2008-02-22 22:10:40 +00:00
|
|
|
:"m" (*bitmap), "r" (nr));
|
2005-04-16 22:20:36 +00:00
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define val_byte(val, n) (((__u8 *)&val)[n])
|
|
|
|
|
|
|
|
#define pushb(base, ptr, val, err_label) \
|
|
|
|
do { \
|
|
|
|
__u8 __val = val; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(__val, base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
2008-02-22 22:10:40 +00:00
|
|
|
} while (0)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define pushw(base, ptr, val, err_label) \
|
|
|
|
do { \
|
|
|
|
__u16 __val = val; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(val_byte(__val, 1), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(val_byte(__val, 0), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
2008-02-22 22:10:40 +00:00
|
|
|
} while (0)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define pushl(base, ptr, val, err_label) \
|
|
|
|
do { \
|
|
|
|
__u32 __val = val; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(val_byte(__val, 3), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(val_byte(__val, 2), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(val_byte(__val, 1), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr--; \
|
|
|
|
if (put_user(val_byte(__val, 0), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
2008-02-22 22:10:40 +00:00
|
|
|
} while (0)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define popb(base, ptr, err_label) \
|
|
|
|
({ \
|
|
|
|
__u8 __res; \
|
|
|
|
if (get_user(__res, base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define popw(base, ptr, err_label) \
|
|
|
|
({ \
|
|
|
|
__u16 __res; \
|
|
|
|
if (get_user(val_byte(__res, 0), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
if (get_user(val_byte(__res, 1), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define popl(base, ptr, err_label) \
|
|
|
|
({ \
|
|
|
|
__u32 __res; \
|
|
|
|
if (get_user(val_byte(__res, 0), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
if (get_user(val_byte(__res, 1), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
if (get_user(val_byte(__res, 2), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
if (get_user(val_byte(__res, 3), base + ptr) < 0) \
|
|
|
|
goto err_label; \
|
|
|
|
ptr++; \
|
|
|
|
__res; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/* There are so many possible reasons for this function to return
|
|
|
|
* VM86_INTx, so adding another doesn't bother me. We can expect
|
|
|
|
* userspace programs to be able to handle it. (Getting a problem
|
|
|
|
* in userspace is always better than an Oops anyway.) [KD]
|
|
|
|
*/
|
|
|
|
static void do_int(struct kernel_vm86_regs *regs, int i,
|
2008-02-22 22:10:40 +00:00
|
|
|
unsigned char __user *ssp, unsigned short sp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long __user *intr_ptr;
|
|
|
|
unsigned long segoffs;
|
|
|
|
|
2008-01-30 12:30:56 +00:00
|
|
|
if (regs->pt.cs == BIOSSEG)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto cannot_handle;
|
|
|
|
if (is_revectored(i, &KVM86->int_revectored))
|
|
|
|
goto cannot_handle;
|
2008-02-22 22:10:40 +00:00
|
|
|
if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto cannot_handle;
|
|
|
|
intr_ptr = (unsigned long __user *) (i << 2);
|
|
|
|
if (get_user(segoffs, intr_ptr))
|
|
|
|
goto cannot_handle;
|
|
|
|
if ((segoffs >> 16) == BIOSSEG)
|
|
|
|
goto cannot_handle;
|
|
|
|
pushw(ssp, sp, get_vflags(regs), cannot_handle);
|
2008-01-30 12:30:56 +00:00
|
|
|
pushw(ssp, sp, regs->pt.cs, cannot_handle);
|
2005-04-16 22:20:36 +00:00
|
|
|
pushw(ssp, sp, IP(regs), cannot_handle);
|
2008-01-30 12:30:56 +00:00
|
|
|
regs->pt.cs = segoffs >> 16;
|
2005-04-16 22:20:36 +00:00
|
|
|
SP(regs) -= 6;
|
|
|
|
IP(regs) = segoffs & 0xffff;
|
|
|
|
clear_TF(regs);
|
|
|
|
clear_IF(regs);
|
|
|
|
clear_AC(regs);
|
|
|
|
return;
|
|
|
|
|
|
|
|
cannot_handle:
|
|
|
|
return_to_32bit(regs, VM86_INTx + (i << 8));
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
int handle_vm86_trap(struct kernel_vm86_regs *regs, long error_code, int trapno)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (VMPI.is_vm86pus) {
|
2008-02-22 22:10:40 +00:00
|
|
|
if ((trapno == 3) || (trapno == 1))
|
2005-04-16 22:20:36 +00:00
|
|
|
return_to_32bit(regs, VM86_TRAP + (trapno << 8));
|
2008-01-30 12:30:56 +00:00
|
|
|
do_int(regs, trapno, (unsigned char __user *) (regs->pt.ss << 4), SP(regs));
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-02-22 22:10:40 +00:00
|
|
|
if (trapno != 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1; /* we let this handle by the calling routine */
|
|
|
|
current->thread.trap_no = trapno;
|
|
|
|
current->thread.error_code = error_code;
|
2008-03-17 09:21:08 +00:00
|
|
|
force_sig(SIGTRAP, current);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
void handle_vm86_fault(struct kernel_vm86_regs *regs, long error_code)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned char opcode;
|
|
|
|
unsigned char __user *csp;
|
|
|
|
unsigned char __user *ssp;
|
2005-09-03 22:56:28 +00:00
|
|
|
unsigned short ip, sp, orig_flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
int data32, pref_done;
|
|
|
|
|
|
|
|
#define CHECK_IF_IN_TRAP \
|
|
|
|
if (VMPI.vm86dbg_active && VMPI.vm86dbg_TFpendig) \
|
2008-03-28 14:56:56 +00:00
|
|
|
newflags |= X86_EFLAGS_TF
|
2005-04-16 22:20:36 +00:00
|
|
|
#define VM86_FAULT_RETURN do { \
|
2008-03-28 14:56:56 +00:00
|
|
|
if (VMPI.force_return_for_pic && (VEFLAGS & (X86_EFLAGS_IF | X86_EFLAGS_VIF))) \
|
2005-04-16 22:20:36 +00:00
|
|
|
return_to_32bit(regs, VM86_PICRETURN); \
|
2008-03-28 14:56:56 +00:00
|
|
|
if (orig_flags & X86_EFLAGS_TF) \
|
2005-09-03 22:56:28 +00:00
|
|
|
handle_vm86_trap(regs, 0, 1); \
|
2005-04-16 22:20:36 +00:00
|
|
|
return; } while (0)
|
|
|
|
|
2008-01-30 12:30:56 +00:00
|
|
|
orig_flags = *(unsigned short *)®s->pt.flags;
|
2005-09-03 22:56:28 +00:00
|
|
|
|
2008-01-30 12:30:56 +00:00
|
|
|
csp = (unsigned char __user *) (regs->pt.cs << 4);
|
|
|
|
ssp = (unsigned char __user *) (regs->pt.ss << 4);
|
2005-04-16 22:20:36 +00:00
|
|
|
sp = SP(regs);
|
|
|
|
ip = IP(regs);
|
|
|
|
|
|
|
|
data32 = 0;
|
|
|
|
pref_done = 0;
|
|
|
|
do {
|
|
|
|
switch (opcode = popb(csp, ip, simulate_sigsegv)) {
|
2008-02-22 22:10:40 +00:00
|
|
|
case 0x66: /* 32-bit data */ data32 = 1; break;
|
|
|
|
case 0x67: /* 32-bit address */ break;
|
|
|
|
case 0x2e: /* CS */ break;
|
|
|
|
case 0x3e: /* DS */ break;
|
|
|
|
case 0x26: /* ES */ break;
|
|
|
|
case 0x36: /* SS */ break;
|
|
|
|
case 0x65: /* GS */ break;
|
|
|
|
case 0x64: /* FS */ break;
|
|
|
|
case 0xf2: /* repnz */ break;
|
|
|
|
case 0xf3: /* rep */ break;
|
|
|
|
default: pref_done = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
} while (!pref_done);
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
|
|
|
/* pushf */
|
|
|
|
case 0x9c:
|
|
|
|
if (data32) {
|
|
|
|
pushl(ssp, sp, get_vflags(regs), simulate_sigsegv);
|
|
|
|
SP(regs) -= 4;
|
|
|
|
} else {
|
|
|
|
pushw(ssp, sp, get_vflags(regs), simulate_sigsegv);
|
|
|
|
SP(regs) -= 2;
|
|
|
|
}
|
|
|
|
IP(regs) = ip;
|
|
|
|
VM86_FAULT_RETURN;
|
|
|
|
|
|
|
|
/* popf */
|
|
|
|
case 0x9d:
|
|
|
|
{
|
|
|
|
unsigned long newflags;
|
|
|
|
if (data32) {
|
2008-02-22 22:10:40 +00:00
|
|
|
newflags = popl(ssp, sp, simulate_sigsegv);
|
2005-04-16 22:20:36 +00:00
|
|
|
SP(regs) += 4;
|
|
|
|
} else {
|
|
|
|
newflags = popw(ssp, sp, simulate_sigsegv);
|
|
|
|
SP(regs) += 2;
|
|
|
|
}
|
|
|
|
IP(regs) = ip;
|
|
|
|
CHECK_IF_IN_TRAP;
|
2008-02-22 22:10:40 +00:00
|
|
|
if (data32)
|
2005-04-16 22:20:36 +00:00
|
|
|
set_vflags_long(newflags, regs);
|
2008-02-22 22:10:40 +00:00
|
|
|
else
|
2005-04-16 22:20:36 +00:00
|
|
|
set_vflags_short(newflags, regs);
|
2008-02-22 22:10:40 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
VM86_FAULT_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* int xx */
|
|
|
|
case 0xcd: {
|
2008-02-22 22:10:40 +00:00
|
|
|
int intno = popb(csp, ip, simulate_sigsegv);
|
2005-04-16 22:20:36 +00:00
|
|
|
IP(regs) = ip;
|
|
|
|
if (VMPI.vm86dbg_active) {
|
2008-02-22 22:10:40 +00:00
|
|
|
if ((1 << (intno & 7)) & VMPI.vm86dbg_intxxtab[intno >> 3])
|
2005-04-16 22:20:36 +00:00
|
|
|
return_to_32bit(regs, VM86_INTx + (intno << 8));
|
|
|
|
}
|
|
|
|
do_int(regs, intno, ssp, sp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iret */
|
|
|
|
case 0xcf:
|
|
|
|
{
|
|
|
|
unsigned long newip;
|
|
|
|
unsigned long newcs;
|
|
|
|
unsigned long newflags;
|
|
|
|
if (data32) {
|
2008-02-22 22:10:40 +00:00
|
|
|
newip = popl(ssp, sp, simulate_sigsegv);
|
|
|
|
newcs = popl(ssp, sp, simulate_sigsegv);
|
|
|
|
newflags = popl(ssp, sp, simulate_sigsegv);
|
2005-04-16 22:20:36 +00:00
|
|
|
SP(regs) += 12;
|
|
|
|
} else {
|
|
|
|
newip = popw(ssp, sp, simulate_sigsegv);
|
|
|
|
newcs = popw(ssp, sp, simulate_sigsegv);
|
|
|
|
newflags = popw(ssp, sp, simulate_sigsegv);
|
|
|
|
SP(regs) += 6;
|
|
|
|
}
|
|
|
|
IP(regs) = newip;
|
2008-01-30 12:30:56 +00:00
|
|
|
regs->pt.cs = newcs;
|
2005-04-16 22:20:36 +00:00
|
|
|
CHECK_IF_IN_TRAP;
|
|
|
|
if (data32) {
|
|
|
|
set_vflags_long(newflags, regs);
|
|
|
|
} else {
|
|
|
|
set_vflags_short(newflags, regs);
|
|
|
|
}
|
|
|
|
VM86_FAULT_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cli */
|
|
|
|
case 0xfa:
|
|
|
|
IP(regs) = ip;
|
|
|
|
clear_IF(regs);
|
|
|
|
VM86_FAULT_RETURN;
|
|
|
|
|
|
|
|
/* sti */
|
|
|
|
/*
|
|
|
|
* Damn. This is incorrect: the 'sti' instruction should actually
|
|
|
|
* enable interrupts after the /next/ instruction. Not good.
|
|
|
|
*
|
|
|
|
* Probably needs some horsing around with the TF flag. Aiee..
|
|
|
|
*/
|
|
|
|
case 0xfb:
|
|
|
|
IP(regs) = ip;
|
|
|
|
set_IF(regs);
|
|
|
|
VM86_FAULT_RETURN;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return_to_32bit(regs, VM86_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
simulate_sigsegv:
|
|
|
|
/* FIXME: After a long discussion with Stas we finally
|
|
|
|
* agreed, that this is wrong. Here we should
|
|
|
|
* really send a SIGSEGV to the user program.
|
|
|
|
* But how do we create the correct context? We
|
|
|
|
* are inside a general protection fault handler
|
|
|
|
* and has just returned from a page fault handler.
|
|
|
|
* The correct context for the signal handler
|
|
|
|
* should be a mixture of the two, but how do we
|
|
|
|
* get the information? [KD]
|
|
|
|
*/
|
|
|
|
return_to_32bit(regs, VM86_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------- vm86 special IRQ passing stuff ----------------- */
|
|
|
|
|
|
|
|
#define VM86_IRQNAME "vm86irq"
|
|
|
|
|
|
|
|
static struct vm86_irqs {
|
|
|
|
struct task_struct *tsk;
|
|
|
|
int sig;
|
|
|
|
} vm86_irqs[16];
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(irqbits_lock);
|
|
|
|
static int irqbits;
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
#define ALLOWED_SIGS (1 /* 0 = don't send a signal */ \
|
2005-04-16 22:20:36 +00:00
|
|
|
| (1 << SIGUSR1) | (1 << SIGUSR2) | (1 << SIGIO) | (1 << SIGURG) \
|
2008-02-22 22:10:40 +00:00
|
|
|
| (1 << SIGUNUSED))
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t irq_handler(int intno, void *dev_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int irq_bit;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
spin_lock_irqsave(&irqbits_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
irq_bit = 1 << intno;
|
2008-02-22 22:10:40 +00:00
|
|
|
if ((irqbits & irq_bit) || !vm86_irqs[intno].tsk)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
irqbits |= irq_bit;
|
|
|
|
if (vm86_irqs[intno].sig)
|
|
|
|
send_sig(vm86_irqs[intno].sig, vm86_irqs[intno].tsk, 1);
|
|
|
|
/*
|
|
|
|
* IRQ will be re-enabled when user asks for the irq (whether
|
|
|
|
* polling or as a result of the signal)
|
|
|
|
*/
|
2005-05-01 15:58:52 +00:00
|
|
|
disable_irq_nosync(intno);
|
|
|
|
spin_unlock_irqrestore(&irqbits_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
|
|
out:
|
2008-02-22 22:10:40 +00:00
|
|
|
spin_unlock_irqrestore(&irqbits_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void free_vm86_irq(int irqnumber)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
free_irq(irqnumber, NULL);
|
|
|
|
vm86_irqs[irqnumber].tsk = NULL;
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
spin_lock_irqsave(&irqbits_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
irqbits &= ~(1 << irqnumber);
|
2008-02-22 22:10:40 +00:00
|
|
|
spin_unlock_irqrestore(&irqbits_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void release_vm86_irqs(struct task_struct *task)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = FIRST_VM86_IRQ ; i <= LAST_VM86_IRQ; i++)
|
|
|
|
if (vm86_irqs[i].tsk == task)
|
|
|
|
free_vm86_irq(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int get_and_reset_irq(int irqnumber)
|
|
|
|
{
|
|
|
|
int bit;
|
|
|
|
unsigned long flags;
|
2005-05-01 15:58:52 +00:00
|
|
|
int ret = 0;
|
2008-02-22 22:10:40 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (invalid_vm86_irq(irqnumber)) return 0;
|
|
|
|
if (vm86_irqs[irqnumber].tsk != current) return 0;
|
2008-02-22 22:10:40 +00:00
|
|
|
spin_lock_irqsave(&irqbits_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
bit = irqbits & (1 << irqnumber);
|
|
|
|
irqbits &= ~bit;
|
2005-05-01 15:58:52 +00:00
|
|
|
if (bit) {
|
|
|
|
enable_irq(irqnumber);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
2008-02-22 22:10:40 +00:00
|
|
|
spin_unlock_irqrestore(&irqbits_lock, flags);
|
2005-05-01 15:58:52 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int do_vm86_irq_handling(int subfunction, int irqnumber)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
switch (subfunction) {
|
|
|
|
case VM86_GET_AND_RESET_IRQ: {
|
|
|
|
return get_and_reset_irq(irqnumber);
|
|
|
|
}
|
|
|
|
case VM86_GET_IRQ_BITS: {
|
|
|
|
return irqbits;
|
|
|
|
}
|
|
|
|
case VM86_REQUEST_IRQ: {
|
|
|
|
int sig = irqnumber >> 8;
|
|
|
|
int irq = irqnumber & 255;
|
|
|
|
if (!capable(CAP_SYS_ADMIN)) return -EPERM;
|
|
|
|
if (!((1 << sig) & ALLOWED_SIGS)) return -EPERM;
|
|
|
|
if (invalid_vm86_irq(irq)) return -EPERM;
|
|
|
|
if (vm86_irqs[irq].tsk) return -EPERM;
|
|
|
|
ret = request_irq(irq, &irq_handler, 0, VM86_IRQNAME, NULL);
|
|
|
|
if (ret) return ret;
|
|
|
|
vm86_irqs[irq].sig = sig;
|
|
|
|
vm86_irqs[irq].tsk = current;
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
case VM86_FREE_IRQ: {
|
|
|
|
if (invalid_vm86_irq(irqnumber)) return -EPERM;
|
|
|
|
if (!vm86_irqs[irqnumber].tsk) return 0;
|
|
|
|
if (vm86_irqs[irqnumber].tsk != current) return -EPERM;
|
|
|
|
free_vm86_irq(irqnumber);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|