* Re: [PATCH 1/2] x86: unify pt_regs accessors ptrace.h
2008-01-18 1:59 [PATCH 1/2] x86: unify pt_regs accessors ptrace.h Harvey Harrison
@ 2008-01-18 1:56 ` H. Peter Anvin
2008-01-18 2:08 ` Harvey Harrison
0 siblings, 1 reply; 4+ messages in thread
From: H. Peter Anvin @ 2008-01-18 1:56 UTC (permalink / raw)
To: Harvey Harrison; +Cc: Ingo Molnar, Thomas Gleixner, LKML
Harvey Harrison wrote:
> Unify the definiton of:
> v8086_mode
> user_mode
> user_mode_vm
> stack_pointer
> instruction_pointer
> frame_pointer
>
> in ptrace.h to make it clear where the differences are between
> 32 and 64 bit. Changes macros to static inlines as well.
>
Can you put a comment on stack_pointer() that it applies to a
kernel-mode pt_regs only?
-hpa
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] x86: unify pt_regs accessors ptrace.h
@ 2008-01-18 1:59 Harvey Harrison
2008-01-18 1:56 ` H. Peter Anvin
0 siblings, 1 reply; 4+ messages in thread
From: Harvey Harrison @ 2008-01-18 1:59 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Ingo Molnar, Thomas Gleixner, LKML
Unify the definiton of:
v8086_mode
user_mode
user_mode_vm
stack_pointer
instruction_pointer
frame_pointer
in ptrace.h to make it clear where the differences are between
32 and 64 bit. Changes macros to static inlines as well.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
include/asm-x86/ptrace.h | 84 +++++++++++++++++++++++++++++----------------
1 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/include/asm-x86/ptrace.h b/include/asm-x86/ptrace.h
index ee4b595..0ad9a2b 100644
--- a/include/asm-x86/ptrace.h
+++ b/include/asm-x86/ptrace.h
@@ -76,30 +76,6 @@ convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code);
-/*
- * user_mode_vm(regs) determines whether a register set came from user mode.
- * This is true if V8086 mode was enabled OR if the register set was from
- * protected mode with RPL-3 CS value. This tricky test checks that with
- * one comparison. Many places in the kernel can bypass this full check
- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
- */
-static inline int user_mode(struct pt_regs *regs)
-{
- return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
-}
-static inline int user_mode_vm(struct pt_regs *regs)
-{
- return ((regs->cs & SEGMENT_RPL_MASK) |
- (regs->flags & VM_MASK)) >= USER_RPL;
-}
-static inline int v8086_mode(struct pt_regs *regs)
-{
- return (regs->flags & VM_MASK);
-}
-
-#define instruction_pointer(regs) ((regs)->ip)
-#define frame_pointer(regs) ((regs)->bp)
-#define stack_pointer(regs) ((unsigned long)(regs))
#define regs_return_value(regs) ((regs)->ax)
extern unsigned long profile_pc(struct pt_regs *regs);
@@ -167,12 +143,6 @@ struct pt_regs {
/* top of stack page */
};
-#define user_mode(regs) (!!((regs)->cs & 3))
-#define user_mode_vm(regs) user_mode(regs)
-#define v8086_mode(regs) 0 /* No V86 mode support in long mode */
-#define instruction_pointer(regs) ((regs)->ip)
-#define frame_pointer(regs) ((regs)->bp)
-#define stack_pointer(regs) ((regs)->sp)
#define regs_return_value(regs) ((regs)->ax)
extern unsigned long profile_pc(struct pt_regs *regs);
@@ -189,6 +159,60 @@ convert_ip_to_linear(struct task_struct *child, struct pt_regs *regs);
#ifdef __KERNEL__
/*
+ * user_mode_vm(regs) determines whether a register set came from user mode.
+ * This is true if V8086 mode was enabled OR if the register set was from
+ * protected mode with RPL-3 CS value. This tricky test checks that with
+ * one comparison. Many places in the kernel can bypass this full check
+ * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
+ */
+static inline int user_mode(struct pt_regs *regs)
+{
+#ifdef CONFIG_X86_32
+ return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
+#else
+ return !!(regs->cs & 3);
+#endif
+}
+
+static inline int user_mode_vm(struct pt_regs *regs)
+{
+#ifdef CONFIG_X86_32
+ return ((regs->cs & SEGMENT_RPL_MASK) |
+ (regs->flags & VM_MASK)) >= USER_RPL;
+#else
+ return user_mode(regs);
+#endif
+}
+
+static inline int v8086_mode(struct pt_regs *regs)
+{
+#ifdef CONFIG_X86_32
+ return (regs->flags & VM_MASK);
+#else
+ return 0; /* No V86 mode support in long mode */
+#endif
+}
+
+static inline unsigned long stack_pointer(struct pt_regs *regs)
+{
+#ifdef CONFIG_X86_32
+ return (unsigned long)regs;
+#else
+ return regs->sp;
+#endif
+}
+
+static inline unsigned long instruction_pointer(struct pt_regs *regs)
+{
+ return regs->ip;
+}
+
+static inline unsigned long frame_pointer(struct pt_regs *regs)
+{
+ return regs->bp;
+}
+
+/*
* These are defined as per linux/ptrace.h, which see.
*/
#define arch_has_single_step() (1)
--
1.5.4.rc2.1164.g6451
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] x86: unify pt_regs accessors ptrace.h
2008-01-18 2:08 ` Harvey Harrison
@ 2008-01-18 2:05 ` H. Peter Anvin
0 siblings, 0 replies; 4+ messages in thread
From: H. Peter Anvin @ 2008-01-18 2:05 UTC (permalink / raw)
To: Harvey Harrison; +Cc: Ingo Molnar, Thomas Gleixner, LKML
Harvey Harrison wrote:
> On Thu, 2008-01-17 at 20:56 -0500, H. Peter Anvin wrote:
>> Harvey Harrison wrote:
>>> Unify the definiton of:
>>> v8086_mode
>>> user_mode
>>> user_mode_vm
>>> stack_pointer
>>> instruction_pointer
>>> frame_pointer
>>>
>>> in ptrace.h to make it clear where the differences are between
>>> 32 and 64 bit. Changes macros to static inlines as well.
>>>
>> Can you put a comment on stack_pointer() that it applies to a
>> kernel-mode pt_regs only?
>
> How about a follow-on patch that picks a better name and adds the
> comment? I'd like to leave this as a movement-only patch. Once we
> decide on a name I'll do the rename/comment. It seems like there are
> very few users currently (oprofile/backtrace.c only?).
>
> Then I'll also change the kprobes code to use this instead of their
> stack_addr helper.
>
IMO, go ahead and add a comment, but yes, renaming should be a separate
patch.
-hpa
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] x86: unify pt_regs accessors ptrace.h
2008-01-18 1:56 ` H. Peter Anvin
@ 2008-01-18 2:08 ` Harvey Harrison
2008-01-18 2:05 ` H. Peter Anvin
0 siblings, 1 reply; 4+ messages in thread
From: Harvey Harrison @ 2008-01-18 2:08 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Ingo Molnar, Thomas Gleixner, LKML
On Thu, 2008-01-17 at 20:56 -0500, H. Peter Anvin wrote:
> Harvey Harrison wrote:
> > Unify the definiton of:
> > v8086_mode
> > user_mode
> > user_mode_vm
> > stack_pointer
> > instruction_pointer
> > frame_pointer
> >
> > in ptrace.h to make it clear where the differences are between
> > 32 and 64 bit. Changes macros to static inlines as well.
> >
>
> Can you put a comment on stack_pointer() that it applies to a
> kernel-mode pt_regs only?
How about a follow-on patch that picks a better name and adds the
comment? I'd like to leave this as a movement-only patch. Once we
decide on a name I'll do the rename/comment. It seems like there are
very few users currently (oprofile/backtrace.c only?).
Then I'll also change the kprobes code to use this instead of their
stack_addr helper.
Harvey
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-01-18 2:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-18 1:59 [PATCH 1/2] x86: unify pt_regs accessors ptrace.h Harvey Harrison
2008-01-18 1:56 ` H. Peter Anvin
2008-01-18 2:08 ` Harvey Harrison
2008-01-18 2:05 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox