Skip to content

Commit 31679f3

Browse files
Andi KleenAndi Kleen
authored andcommitted
[PATCH] Simplify profile_pc on x86-64
Use knowledge about EFLAGS layout (bits 22:63 are always 0) to distingush EFLAGS word and kernel address in the spin lock stack frame. Signed-off-by: Andi Kleen <ak@suse.de>
1 parent 0cb91a2 commit 31679f3

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

arch/x86_64/kernel/time.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,15 @@ unsigned long profile_pc(struct pt_regs *regs)
189189
{
190190
unsigned long pc = instruction_pointer(regs);
191191

192-
/* Assume the lock function has either no stack frame or only a single
193-
word. This checks if the address on the stack looks like a kernel
194-
text address.
195-
There is a small window for false hits, but in that case the tick
196-
is just accounted to the spinlock function.
197-
Better would be to write these functions in assembler again
198-
and check exactly. */
192+
/* Assume the lock function has either no stack frame or a copy
193+
of eflags from PUSHF
194+
Eflags always has bits 22 and up cleared unlike kernel addresses. */
199195
if (!user_mode(regs) && in_lock_functions(pc)) {
200-
char *v = *(char **)regs->rsp;
201-
if ((v >= _stext && v <= _etext) ||
202-
(v >= _sinittext && v <= _einittext) ||
203-
(v >= (char *)MODULES_VADDR && v <= (char *)MODULES_END))
204-
return (unsigned long)v;
205-
return ((unsigned long *)regs->rsp)[1];
196+
unsigned long *sp = (unsigned long *)regs->rsp;
197+
if (sp[0] >> 22)
198+
return sp[0];
199+
if (sp[1] >> 22)
200+
return sp[1];
206201
}
207202
return pc;
208203
}

0 commit comments

Comments
 (0)