x86: Remove ifdef from step.c
PATCH 1/1 x86: Remove ifdef from step.c
Similar cleanup was done when unifying kprobes_32|64.c and wrmsr() was chosen there over wrmsrl().
---
Ingo, only chose this direction based on the kprobes.c unification.
arch/x86/kernel/step.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
arch/x86/kernel/step.c +0 -4
@@ -148,11 +148,7 @@ static void write_debugctlmsr(struct task_struct *child, unsigned long val)if (child != current)return ; -#ifdef CONFIG_X86_64 -wrmsrl (MSR_IA32_DEBUGCTLMSR , val); -#else wrmsr (MSR_IA32_DEBUGCTLMSR , val,0 ); -#endif }/*
Signature · 1 line
1.5.4.rc2.1164.g6451
arch/x86/kernel/step.c static void write_debugctlmsr(struct task_struct *child, unsigned long val) · line 155
Quoted 9 lines · Harvey Harrison
arch/x86/kernel/step.c +0
-4@@ -148,11 +148,7 @@ static void write_debugctlmsr(struct task_struct *child, unsigned long val)if (child != current)return ; -#ifdef CONFIG_X86_64 -wrmsrl (MSR_IA32_DEBUGCTLMSR , val); -#else wrmsr (MSR_IA32_DEBUGCTLMSR , val,0 ); -#endif
doesnt this break 64-bit? 'val' is 64-bit, but wrmsr truncates it to 32-bit? [while wrmsrl() kept the full 64 bits]
Ingo
Quoted 6 lines · Ingo Molnar
Quoted 4 lines · Harvey Harrison
arch/x86/kernel/step.c +0
-0@@ -148,11 +148,7 @@ static void write_debugctlmsr(struct task_struct *child, unsigned long val)if (child != current)return ;
Quoted 9 lines
arch/x86/kernel/step.c static void write_debugctlmsr(struct task_struct *child, unsigned long val) · line 155
Quoted 5 lines
arch/x86/kernel/step.c +0
-4-#ifdef CONFIG_X86_64 -wrmsrl (MSR_IA32_DEBUGCTLMSR , val); -#else wrmsr (MSR_IA32_DEBUGCTLMSR , val,0 ); -#endif doesnt this break 64-bit? 'val' is 64-bit, but wrmsr truncates it to 32-bit? [while
wrmsrl()kept the full 64 bits]
I wasn't totally sure about this, but believe in this case that it is OK. If not, we'll have to add this #ifdef back to restore_btf() in kprobes.c which was lost Masami's unification.
But looking at how this is called, there shouldn't ever be anything in the high 32 bits being written to (32 bit always wrote zero anyway). In any event, it's going to be safer to use wrsmrl instead as you'll get the zero extension on 32 bit and won't effect 64 bit.
Patch to follow.
Harvey
PATCH 1/1 x86: Use wrmsrl in kprobes.c, step.c
In reply to Ingo MolnarWhere x86_32 passed zero in the high 32 bits, use wrmsrl which will zero extend for us. This allows ifdefs for 32/64 bit to be eliminated.
Eliminate ifdef in step.c. Similar cleanup was done when unifying kprobes_32|64.c and wrmsr() was chosen there over wrmsrl(). This patch changes these to wrmsrl.
--- arch/x86/kernel/kprobes.c | 4 ++-- arch/x86/kernel/step.c | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/kprobes.c +2 -2
@@ -410,13 +410,13 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,static void __kprobes clear_btf (void ) {if (test_thread_flag (TIF_DEBUGCTLMSR )) -wrmsr (MSR_IA32_DEBUGCTLMSR ,0 ,0 ); +wrmsrl (MSR_IA32_DEBUGCTLMSR ,0L ); }static void __kprobes restore_btf (void ) {if (test_thread_flag (TIF_DEBUGCTLMSR )) -wrmsr (MSR_IA32_DEBUGCTLMSR , current->thread.debugctlmsr,0 ); +wrmsrl (MSR_IA32_DEBUGCTLMSR , current->thread.debugctlmsr); }static void __kprobes prepare_singlestep (struct kprobe *p,struct pt_regs *regs)
arch/x86/kernel/step.c +0 -4
@@ -148,11 +148,7 @@ static void write_debugctlmsr(struct task_struct *child, unsigned long val)if (child != current)return ; -#ifdef CONFIG_X86_64 wrmsrl (MSR_IA32_DEBUGCTLMSR , val); -#else -wrmsr (MSR_IA32_DEBUGCTLMSR , val,0 ); -#endif }/*
Signature · 1 line
1.5.4.rc2.1164.g6451
H. Peter Anvin
reviewerRe: [PATCH] x86: Use wrmsrl in kprobes.c, step.c
Quoted 19 lines · Harvey Harrison
Where
x86_32passed zero in the high 32 bits, use wrmsrl which will zero extend for us. This allows ifdefs for 32/64 bit to be eliminated.Eliminate ifdef in
step.c. Similar cleanup was done when unifying kprobes_32|64.c andwrmsr()was chosen there overwrmsrl(). This patch changes these to wrmsrl.Signed-off-by Harvey Harrison <[email protected]>--- arch/x86/kernel/kprobes.c | 4 ++-- arch/x86/kernel/step.c | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-)arch/x86/kernel/kprobes.c +0
-0
arch/x86/kernel/kprobes.c static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs, · line 414
Quoted 6 lines
arch/x86/kernel/kprobes.c +1
-1@@ -410,13 +410,13 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,static void __kprobes clear_btf (void ) {if (test_thread_flag (TIF_DEBUGCTLMSR )) -wrmsr (MSR_IA32_DEBUGCTLMSR ,0 ,0 ); +wrmsrl (MSR_IA32_DEBUGCTLMSR ,0L ); }
Drop the L. It doesn't buy you anything, and gcc will sign-extend for you anyway. It's just visual clutter.
-hpa
PATCH v2 1/1 x86: Use wrmsrl in kprobes.c, step.c
Where x86_32 passed zero in the high 32 bits, use wrmsrl which will zero extend for us. This allows ifdefs for 32/64 bit to be eliminated.
Eliminate ifdef in step.c. Similar cleanup was done when unifying kprobes_32|64.c and wrmsr() was chosen there over wrmsrl(). This patch changes these to wrmsrl.
---
Incorporating HPA's comment removing 0L.
arch/x86/kernel/kprobes.c | 4 ++-- arch/x86/kernel/step.c | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/kernel/kprobes.c +2 -2
@@ -410,13 +410,13 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,static void __kprobes clear_btf (void ) {if (test_thread_flag (TIF_DEBUGCTLMSR )) -wrmsr (MSR_IA32_DEBUGCTLMSR ,0 ,0 ); +wrmsrl (MSR_IA32_DEBUGCTLMSR ,0 ); }static void __kprobes restore_btf (void ) {if (test_thread_flag (TIF_DEBUGCTLMSR )) -wrmsr (MSR_IA32_DEBUGCTLMSR , current->thread.debugctlmsr,0 ); +wrmsrl (MSR_IA32_DEBUGCTLMSR , current->thread.debugctlmsr); }static void __kprobes prepare_singlestep (struct kprobe *p,struct pt_regs *regs)
arch/x86/kernel/step.c +0 -4
@@ -148,11 +148,7 @@ static void write_debugctlmsr(struct task_struct *child, unsigned long val)if (child != current)return ; -#ifdef CONFIG_X86_64 wrmsrl (MSR_IA32_DEBUGCTLMSR , val); -#else -wrmsr (MSR_IA32_DEBUGCTLMSR , val,0 ); -#endif }/*
Signature · 1 line
1.5.4.rc2.1164.g6451