[parisc-linux] Re: Trap handler

Matthew Wilcox willy@debian.org
Mon, 9 Dec 2002 12:54:16 +0000


On Sun, Dec 08, 2002 at 10:19:13PM -0800, Randolph Chung wrote:
> the fix has to do with where we should return to after handling an
> interruption. in pre-2.4.20 code we used to return to intr_return. Grant
> thinks that is incorrect and changed it to intr_restore (basically just
> doing the rfi). the -pa12 patch changes it back so it will handle
> pending signals. The items that remain not handled are restoring I-bit,
> softirqs (and irqstats) and rescheduling. We are not sure if those bits
> are needed for interruptions....  can you guys shed some light on this?

Well, let's look at the reference platform (ie x86):

ENTRY(page_fault)
        pushl $do_page_fault
        jmp error_code

error_code:
(blah blah blah.  sets up stuff & calls the address on the stack)
        call *%edi
        addl $8, %esp
        jmp ret_from_exception

ret_from_exception:
        preempt_stop
ret_from_intr:
        GET_THREAD_INFO(%ebx)
        movl EFLAGS(%esp), %eax         # mix EFLAGS and CS
        movb CS(%esp), %al
        testl $(VM_MASK | 3), %eax
        jz resume_kernel                # returning to kernel or vm86-space
ENTRY(resume_userspace)
        cli                             # make sure we don't miss an interrupt
                                        # setting need_resched or sigpending
                                        # between sampling and the iret
        movl TI_FLAGS(%ebx), %ecx
        andl $_TIF_WORK_MASK, %ecx      # is there any work to be done on
                                        # int/exception return?
        jne work_pending
        jmp restore_all

(with preemption disabled, resume_kernel == restore_all)

restore_all:
        RESTORE_ALL

        # perform work that needs to be done immediately before resumption
        ALIGN
work_pending:
        testb $_TIF_NEED_RESCHED, %cl
        jz work_notifysig
work_resched:

So x86 will potentially reschedule on successfully handling a page
fault.  softirqs seem to only get run if we're returning to userspace,
unless we're switching tasks.  That might be a bug in the x86 code.
Judging from the use of cli & sti in the x86 asm, I would venture to
suggest that the I bit should be cleared.  It makes sense anyway --
you can't expect interrupts to be disabled over a page fault.

-- 
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk