Re: [Question] arch-independent way to differentiate between user andkernel

Steven Rostedt
2005-08-03T12:31:12Z

On Wed, 2005-08-03 at 14:04 +0200, Ingo Molnar wrote:
> * Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > On Wed, 2005-08-03 at 06:56 -0400, linux-os (Dick Johnson) wrote:
> > > On Wed, 3 Aug 2005, Steven Rostedt wrote:
> > > The interrupt handler gets a pointer to a structure called "struct pt_regs".
> > > That contains, amongst other things, the registers pushed onto the stack
> > > during the interrupt. If the segments were kernel segments, the interrupt
> > > occurred while in kernel mode. But..... If you have any code that
> > > needs to know, it's horribly and irreparably broken beyond all
> > > repair. Interrupts need to be handled NOW, without regard to what
> > > got interrupted.
> > >
> >
> > By the time you get to __do_IRQ there's already more stuff on the
> > stack. And the pt_regs is arch specific so this doesn't help.
>
> the actual layout of pt_regs is arch-specific, but user_mode(regs) is
> pretty much generic across most arches.
>

OK I did the following:

find arch -name "*.c" ! -type d | xargs grep "update_process_times" |grep -v user_mode
arch/arm/kernel/smp.c: update_process_times(user);
arch/um/kernel/time_kern.c: update_process_times(CHOOSE_MODE(user_context(UPT_SP(regs)), (regs)->skas.is_user));
arch/sparc64/kernel/smp.c: update_process_times(user);
arch/m32r/kernel/smp.c: update_process_times(user);
arch/alpha/kernel/smp.c: update_process_times(user);
arch/i386/kernel/apic.c: * update_process_times() expects us to have done irq_enter().
arch/x86_64/kernel/apic.c: * update_process_times() expects us to have done irq_enter().
arch/sparc/kernel/sun4d_smp.c: update_process_times(user);
arch/sparc/kernel/sun4m_smp.c: update_process_times(user);

I also did a find without the -v user_mode and here's some of the output
(filtered to only show what's relevant):

arch/arm/kernel/time.c: update_process_times(user_mode(regs));
arch/sparc64/kernel/time.c: update_process_times(user_mode(regs));
arch/m32r/kernel/time.c: update_process_times(user_mode(regs));
arch/alpha/kernel/time.c: update_process_times(user_mode(regs));
arch/i386/kernel/apic.c: update_process_times(user_mode_vm(regs));
arch/x86_64/kernel/time.c: update_process_times(user_mode(regs));
arch/sparc/kernel/pcic.c: update_process_times(user_mode(regs));

So all but (amusingly) user-mode-linux use the user_mode macro. So it
does look good. I'm not too worried right now for user-mode-linux, but
that sould be fixed too if need be.

So I'll add this to the patch I'll be sending you soon (after it's all
tested).

-- Steve