Skip to contentSkip to conversation

x86: Remove ifdef from step.c

PATCH In review Harvey Harrison 3 participants 6 messages Jan 10, 2008 x86

lore
Share & tools
lore
#0 lore raw

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
index 21ea22f..d73c537 100644
@@ -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
#1 lore raw

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

#2 lore raw
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

#3 lore raw

PATCH 1/1 x86: Use wrmsrl in kprobes.c, step.c

In reply to Ingo Molnar

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.

---
 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
index 53ba6a5..34becd1 100644
@@ -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
index 21ea22f..bf7047d 100644
@@ -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
#4 lore raw

Re: [PATCH] x86: Use wrmsrl in kprobes.c, step.c

Quoted 19 lines · Harvey Harrison

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.

---
 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
index 53ba6a5..34becd1 100644

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

#5 lore raw

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
index 53ba6a5..34becd1 100644
@@ -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
index 21ea22f..bf7047d 100644
@@ -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