Skip to contentSkip to conversation

x86: do not skip PKRU register if debug registers are not used

PATCH In review Nicolas Iooss 3 participants 4 messages Sep 10, 2016 – Sep 13, 2016 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: do not skip PKRU register if debug registers are not used

When commit c0b17b5bd4b7 ("x86/mm/pkeys: Dump PKRU with other kernel registers") made __show_regs() show PKRU, this register was only printed if the debug registers were not in their default state (there is an if(...) return; before).

Change the logic to report PKRU value even when debug registers are in their default state.

---
 arch/x86/kernel/process_64.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/process_64.c +7 -6
index 63236d8f84bf..a21068e49dac 100644
@@ -110,12 +110,13 @@ void __show_regs(struct pt_regs *regs, int all)
 	get_debugreg(d7, 7);
 
 	/* Only print out debug registers if they are in their non-default state. */
-	if ((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
-	    (d6 == DR6_RESERVED) && (d7 == 0x400))
-		return;
-
-	printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
-	printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
+	if (!((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
+	    (d6 == DR6_RESERVED) && (d7 == 0x400))) {
+		printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n",
+		       d0, d1, d2);
+		printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n",
+		       d3, d6, d7);
+	}
 
 	if (boot_cpu_has(X86_FEATURE_OSPKE))
 		printk(KERN_DEFAULT "PKRU: %08x\n", read_pkru());
Signature · 1 line
2.9.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Nicolas Iooss

When commit c0b17b5bd4b7 ("x86/mm/pkeys: Dump PKRU with other kernel registers") made __show_regs() show PKRU, this register was only printed if the debug registers were not in their default state (there is an if(...) return; before).

Change the logic to report PKRU value even when debug registers are in their default state.

Ahh, thanks for finding this. This looks like the correct fix to me.

#2 lore raw

[tip:mm/pkeys] x86/mm/pkeys: Do not skip PKRU register if debug registers are not used

In reply to Nicolas Iooss
x86/mm/pkeys: Do not skip PKRU register if debug registers are not used
Commit-ID:  19ab2b679c4af895ac0f3e79eea14952a6b2b2ce
Gitweb:     http://git.kernel.org/tip/19ab2b679c4af895ac0f3e79eea14952a6b2b2ce
Author:     Nicolas Iooss <[email protected]>
AuthorDate: Sat, 10 Sep 2016 20:30:45 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 13 Sep 2016 15:12:17 +0200

x86/mm/pkeys: Do not skip PKRU register if debug registers are not used

__show_regs() fails to dump the PKRU state when the debug registers are in their default state because there is a return statement on the debug register state.

Change the logic to report PKRU value even when debug registers are in their default state.

[ tglx: Switch to pr_default() while at it ]

Fixes c0b17b5bd4b7 ("x86/mm/pkeys: Dump PKRU with other kernel registers")
---
 arch/x86/kernel/process_64.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
arch/x86/kernel/process_64.c +11 -13
index 63236d8..130c4eb 100644
@@ -95,12 +95,11 @@ void __show_regs(struct pt_regs *regs, int all)
 	cr3 = read_cr3();
 	cr4 = __read_cr4();
 
-	printk(KERN_DEFAULT "FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
-	       fs, fsindex, gs, gsindex, shadowgs);
-	printk(KERN_DEFAULT "CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
-			es, cr0);
-	printk(KERN_DEFAULT "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
-			cr4);
+	pr_default("FS:  %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
+		   fs, fsindex, gs, gsindex, shadowgs);
+	pr_default("CS:  %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds,
+		   es, cr0);
+	pr_default("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4);
 
 	get_debugreg(d0, 0);
 	get_debugreg(d1, 1);
@@ -110,15 +109,14 @@ void __show_regs(struct pt_regs *regs, int all)
 	get_debugreg(d7, 7);
 
 	/* Only print out debug registers if they are in their non-default state. */
-	if ((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
-	    (d6 == DR6_RESERVED) && (d7 == 0x400))
-		return;
-
-	printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
-	printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
+	if (!((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
+	    (d6 == DR6_RESERVED) && (d7 == 0x400))) {
+		pr_default("DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
+		pr_default("DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
+	}
 
 	if (boot_cpu_has(X86_FEATURE_OSPKE))
-		printk(KERN_DEFAULT "PKRU: %08x\n", read_pkru());
+		pr_default("PKRU: %08x\n", read_pkru());
 }
 
 void release_thread(struct task_struct *dead_task)
#3 lore raw

[tip:mm/pkeys] x86/mm/pkeys: Do not skip PKRU register if debug registers are not used

In reply to Nicolas Iooss
x86/mm/pkeys: Do not skip PKRU register if debug registers are not used
Commit-ID:  ba6d018e3d2f6a0fad58a668cadf66b2d1f80f59
Gitweb:     http://git.kernel.org/tip/ba6d018e3d2f6a0fad58a668cadf66b2d1f80f59
Author:     Nicolas Iooss <[email protected]>
AuthorDate: Sat, 10 Sep 2016 20:30:45 +0200
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 13 Sep 2016 15:52:28 +0200

x86/mm/pkeys: Do not skip PKRU register if debug registers are not used

__show_regs() fails to dump the PKRU state when the debug registers are in their default state because there is a return statement on the debug register state.

Change the logic to report PKRU value even when debug registers are in their default state.

Fixes c0b17b5bd4b7 ("x86/mm/pkeys: Dump PKRU with other kernel registers")
---
 arch/x86/kernel/process_64.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/process_64.c +7 -6
index 63236d8..a21068e 100644
@@ -110,12 +110,13 @@ void __show_regs(struct pt_regs *regs, int all)
 	get_debugreg(d7, 7);
 
 	/* Only print out debug registers if they are in their non-default state. */
-	if ((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
-	    (d6 == DR6_RESERVED) && (d7 == 0x400))
-		return;
-
-	printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n", d0, d1, d2);
-	printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n", d3, d6, d7);
+	if (!((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
+	    (d6 == DR6_RESERVED) && (d7 == 0x400))) {
+		printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n",
+		       d0, d1, d2);
+		printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n",
+		       d3, d6, d7);
+	}
 
 	if (boot_cpu_has(X86_FEATURE_OSPKE))
 		printk(KERN_DEFAULT "PKRU: %08x\n", read_pkru());