Re: [patch, 2.6.10-rc3] safe_hlt() & NMIs

From: Chuck Ebbert
Date: Fri Dec 17 2004 - 18:40:37 EST


On Tue, 14 Dec 2004 at 15:00:56 -0800 (PST) Linus Torvalds wrote:

> Checking for kernel CS also requires checking that it's not vm86 mode,
> btw. So that's not just a "regs->xcs & 0xffff == __KERNEL_CS" either.
>
> But something like
>
> static inline int kernel_mode(struct pt_regs *regs)
> {
> return !((regs->eflags & VM_MASK) | (regs->xcs & 3));
> }
>
> should DTRT.
>
> Can you pls double-check my thinking, and test?


There is already a user_mode() macro in asm-i386/ptrace.h but it's slow.

x86_64's macro is ugly but at least there's no logical-or in it.

Your i386 code is better, so how about applying this patch (boots/runs/is faster
on my tests):

Signed-off-by: Chuck Ebbert <76306.1226@xxxxxxxxxxxxxx>

--- linux-2.6.9.1/include/asm-i386/ptrace.h 2004-10-19 15:28:18.000000000 -0400
+++ linux-2.6.9.2/include/asm-i386/ptrace.h 2004-12-17 16:59:39.956099664 -0500
@@ -55,7 +55,11 @@ struct pt_regs {
#define PTRACE_SET_THREAD_AREA 26

#ifdef __KERNEL__
-#define user_mode(regs) ((VM_MASK & (regs)->eflags) || (3 & (regs)->xcs))
+static inline int kernel_mode(struct pt_regs *regs)
+{
+ return !((3 & (regs)->xcs) | (VM_MASK & (regs)->eflags));
+}
+#define user_mode(regs) (!kernel_mode(regs))
#define instruction_pointer(regs) ((regs)->eip)
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER)
extern unsigned long profile_pc(struct pt_regs *regs);

--
Please take it as a sign of my infinite respect for you,
that I insist on you doing all the work.
-- Rusty Russell
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/