Skip to contentSkip to conversation

x86: cpu architecture debug code

PATCH In review Jaswinder Singh Rajput 5 participants 22 messages Mar 10, 2009 – Mar 13, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: cpu architecture debug code

Added more features, now it supports:
1. TSS (GPR, Segment, Eflags)
2. Control Regs
3. DT (IDT, GDT, LDT, TR)
4. Debug regs
5. LAPIC
6. MSRs

Here is the capture on AMD64 box:

[jaswinder@hpdv5 ~]$ cat /sys/kernel/debug/x86/cpu/cpu*/tss/tss
RAX : ffffffff816edfe8
RBX : 000000000007e000
RCX : ffffffff816f736e
RDX : 0000000000000000
RSI : 0000000000000000
RDI : 816f8e0000107136
RBP : 000000000000001f
ESP : 0000000000000000
R08 : 0000000000092e00
R09 : 0000000000000000
R10 : ffffffff816f729a
R11 : ffffffff816edfa8
R12 : 00000000afc723ac
R13 : 0000000000a1a074
R14 : ffffffff8172e650
R15 : ffffffff816edf88

 CS	:             0010
 DS	:             0018
 SS	:             0000
 ES	:             0018
 FS	:             0000
 GS	:             0000

EFLAGS : ffffffffff200000
EIP : 0000000000000000

RAX : 0000000000000000
RBX : ffffffff8100bb9b
RCX : 00000038b20d8330
RDX : 0000000000001000
RSI : 0000000002534000
RDI : 0000000000000003
RBP : 0000000002534000
ESP : 00007fffdc2442a8
R08 : 0000000002533020
R09 : 0000000000000003
R10 : 00000038b236da70
R11 : 0000000000000246
R12 : 0000000000000400
R13 : 0000000000000003
R14 : 0000000002534000
R15 : 0000000000001000

 CS	:             0010
 DS	:             0000
 SS	:             002b
 ES	:             0000
 FS	:             0000
 GS	:             0000

EFLAGS : 0000000000010202
EIP : 00000038b20d8330

[jaswinder@hpdv5 ~]$ cat /sys/kernel/debug/x86/cpu/cpu*/cr/cr
cr0 : 000000008005003b
cr2 : 000000000231c4b0
cr3 : 00000001296ae000
cr4 : 00000000000006a0
cr8 : 0000000000000000

cr0 : 0000000080050033
cr2 : 00000000004026d0
cr3 : 0000000126479000
cr4 : 00000000000006a0
cr8 : 0000000000000000

[jaswinder@hpdv5 ~]$ cat /sys/kernel/debug/x86/cpu/cpu*/dt/dt
IDT : ffffffff8177bfff
GDT : ffff88002802607f
LDT : ffffffff81050000
TR : 0000000000000040

IDT : ffffffff8177bfff
GDT : ffff88002803f07f
LDT : ffffffff810a0000
TR : 0000000000000040

[jaswinder@hpdv5 ~]$ cat /sys/kernel/debug/x86/cpu/cpu*/debug/debug
dr0 : 0000000000000000
dr1 : 0000000000000000
dr2 : 0000000000000000
dr3 : 0000000000000000
dr6 : 00000000ffff0ff0
dr7 : 0000000000000400

MSR :
000001d9: 00000000_00000000

dr0 : 0000000000000000
dr1 : 0000000000000000
dr2 : 0000000000000000
dr3 : 0000000000000000
dr6 : 00000000ffff0ff0
dr7 : 0000000000000400

MSR :
000001d9: 00000000_00000000

[jaswinder@hpdv5 ~]$ cat /sys/kernel/debug/x86/cpu/cpu*/apic/apic
LAPIC :
ID : 00000000
LVR : 80050010
TASKPRI : 00000000
ARBPRI : 00000000
PROCPRI : 00000000
LDR : 01000000
DFR : ffffffff
SPIV : 000001ff
ISR : 00000000
ESR : 00000000
ICR : 000208fd
ICR2 : 02000000
LVTT : 000300ef
LVTTHMR : 00010000
LVTPC : 000000ee
LVT0 : 00010700
LVT1 : 00000400
LVTERR : 000000fe
TMICT : ffffffff
TMCCT : 3aa8ec77
TDCR : 00000003

MSR :
0000001b: 00000000_fee00900

LAPIC :
ID : 00000001
LVR : 80050010
TASKPRI : 00000000
ARBPRI : 00000000
PROCPRI : 00000000
LDR : 02000000
DFR : ffffffff
SPIV : 000001ff
ISR : 00000000
ESR : 00000000
ICR : 000008fd
ICR2 : 01000000
LVTT : 000000ef
LVTTHMR : 00010000
LVTPC : 000100ee
LVT0 : 00010700
LVT1 : 00010400
LVTERR : 000000fe
TMICT : 00002e5f
TMCCT : 00000c77
TDCR : 00000003

MSR :
0000001b: 00000000_fee00800

[jaswinder@hpdv5 ~]$ cat /sys/kernel/debug/x86/cpu/cpu*/pmc/pmc
c0010000: 00000000_00430076
c0010001: 00000000_3d9f09db
c0010002: 00000000_9113fe0c
c0010003: 00000000_ec1e363e
c0010004: 00000015_fb4fa392
c0010005: 0000f9bf_a9cfa04b
c0010006: 000050e7_cdd5610e
c0010007: 0000eade_585c2a95

c0010000: 00000000_3c1585ce
c0010001: 00000000_fd9e0e89
c0010002: 00000000_7e9fd3e6
c0010003: 00000000_3f9ece5c
c0010004: 0000c55d_a4800830
c0010005: 00007a7c_e227303b
c0010006: 0000001e_8040f52a
c0010007: 0000c105_c3d2c03c

[jaswinder@hpdv5 ~]$

So here is new pull request:

Log file is available at:
http://git.kernel.org/?p=linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git;a=commitdiff;h=a932f3ae25180f8661ca531e79547d9bff8cbb2e

The following changes since commit 23eeaab0397190b112591dab13d1fb196f099254:
Ingo Molnar (1):
Merge branch 'tracing/ftrace'

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  771 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 972 insertions(+), 0 deletions(-)
 create mode 100755 arch/x86/include/asm/cpu_debug.h
 create mode 100755 arch/x86/kernel/cpu/cpu_debug.c

Complete diff:

arch/x86/Kconfig +6 -0
index 2a0ddfe..b9f6c09 100644
@@ -934,6 +934,12 @@ config X86_CPUID
 	  with major 203 and minors 0 to 31 for /dev/cpu/0/cpuid to
 	  /dev/cpu/31/cpuid.
 
+config X86_CPU_DEBUG
+	tristate "/sys/kernel/debug/x86/cpu/* - CPU Debug support"
+	---help---
+	  If you select this option, this will provide various x86 CPUs
+	  information through debugfs.
+
 choice
 	prompt "High Memory Support"
 	default HIGHMEM4G if !X86_NUMAQ
arch/x86/include/asm/cpu_debug.h new file +193 -0

193 lines not on this page · raw message

arch/x86/kernel/cpu/Makefile +2 -0
index c381330..a702bad 100644
@@ -24,6 +24,8 @@ obj-$(CONFIG_CPU_SUP_UMC_32)		+= umc.o
 
 obj-$(CONFIG_PERF_COUNTERS)		+= perf_counter.o
 
+obj-$(CONFIG_X86_CPU_DEBUG)		+= cpu_debug.o
+
 obj-$(CONFIG_X86_MCE)			+= mcheck/
 obj-$(CONFIG_MTRR)			+= mtrr/
 obj-$(CONFIG_CPU_FREQ)			+= cpufreq/
arch/x86/kernel/cpu/cpu_debug.c new file +771 -0

771 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Jaswinder Singh Rajput

Added more features, now it supports:
1. TSS (GPR, Segment, Eflags)
2. Control Regs
3. DT (IDT, GDT, LDT, TR)
4. Debug regs
5. LAPIC
6. MSRs

looks pretty good!

A few small details:

arch/x86/kernel/cpu/cpu_debug.c line 17

Quoted 9 lines
arch/x86/kernel/cpu/cpu_debug.c new file +9 -0
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/smp.h>
+#include <linux/regset.h>
+#include <linux/sched.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+#include <asm/desc.h>
+#include <asm/cpu_debug.h>

Please use the include files style as can be seen in arch/x86/mm/fault.c. The reason why we do it is to reduce conflicts when files are modified by multiple topic branches at once.

arch/x86/kernel/cpu/cpu_debug.c line 291

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c new file +4 -0
+	vendor = per_cpu(cpu_model, cpu) >> 16;
+	modelflag = per_cpu(cpu_modelflag, cpu);
+	index = get_cpu_range_count(cpu);
+	for (i = 0; i < index; i++) {

please put a newline before loops in such cases, to make it stand out some more.

arch/x86/kernel/cpu/cpu_debug.c line 360

Quoted 7 lines
arch/x86/kernel/cpu/cpu_debug.c new file +7 -0
+/* This function can also be called with seq = NULL for printk */
+static void print_msr(struct seq_file *seq, unsigned cpu, unsigned flag)
+{
+	int i, range;
+	u32 low, high;
+	unsigned msr, msr_min, msr_max;
+	struct cpu_private *priv;

please try to order local variables like this:

arch/x86/kernel/cpu/cpu_debug.c

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c new file +4 -0
+	unsigned msr, msr_min, msr_max;
+	struct cpu_private *priv;
+	u32 low, high;
+	int i, range;

(this is done for similar reasons as the include files section ordering)

this affects other functions in the file too.

arch/x86/kernel/cpu/cpu_debug.c line 578

Quoted 6 lines
arch/x86/kernel/cpu/cpu_debug.c new file +6 -0
+static const struct seq_operations cpu_seq_ops = {
+	.start = cpu_seq_start,
+	.next  = cpu_seq_next,
+	.stop  = cpu_seq_stop,
+	.show  = cpu_seq_show,
+};

Please use consistent vertical alignment wherever possible thoughout the file, i.e.:

arch/x86/kernel/cpu/cpu_debug.c line 577

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c new file +4 -0
+	.start			= cpu_seq_start,
+	.next			= cpu_seq_next,
+	.stop			= cpu_seq_stop,
+	.show			= cpu_seq_show,

(note this applies to other places too in this same file.)

arch/x86/kernel/cpu/cpu_debug.c line 592

Quoted 13 lines
arch/x86/kernel/cpu/cpu_debug.c new file +13 -0
+static int cpu_seq_open(struct inode *inode, struct file *file)
+{
+	int err;
+	struct seq_file *seq;
+	struct cpu_private *priv = inode->i_private;
+
+	err = seq_open(file, &cpu_seq_ops);
+	mutex_lock(&cpu_debug_lock);
+	if (!err) {
+		seq = file->private_data;
+		seq->private = priv;
+	}
+	mutex_unlock(&cpu_debug_lock);

what is the purpose of the locking here? What other codepath can race with this?

arch/x86/kernel/cpu/cpu_debug.c line 625

Quoted 12 lines
arch/x86/kernel/cpu/cpu_debug.c new file +12 -0
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (priv == NULL)
+		return -ENOMEM;
+
+	mutex_lock(&cpu_debug_lock);
+	priv->cpu = cpu;
+	priv->type = type;
+	priv->reg = reg;
+	priv->file = file;
+	per_cpu(priv_arr[type], cpu) = priv;
+	per_cpu(cpu_priv_count, cpu)++;
+	mutex_unlock(&cpu_debug_lock);

what's the purpose of the locking here and why does it cover more than just the per_cpu() related critical section?

Ingo

#2 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · Jaswinder Singh Rajput

Added more features, now it supports:
1. TSS (GPR, Segment, Eflags)
2. Control Regs
3. DT (IDT, GDT, LDT, TR)
4. Debug regs
5. LAPIC
6. MSRs

Quoted 3 lines

looks pretty good!

A few small details:

Ok, I fixed these issues, new pull request:

The following changes since commit 23eeaab0397190b112591dab13d1fb196f099254:
Ingo Molnar (1):
Merge branch 'tracing/ftrace'

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  784 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 985 insertions(+), 0 deletions(-)
 create mode 100755 arch/x86/include/asm/cpu_debug.h
 create mode 100755 arch/x86/kernel/cpu/cpu_debug.c

Complete diff:

arch/x86/Kconfig +6 -0
index 2a0ddfe..b9f6c09 100644
@@ -934,6 +934,12 @@ config X86_CPUID
 	  with major 203 and minors 0 to 31 for /dev/cpu/0/cpuid to
 	  /dev/cpu/31/cpuid.
 
+config X86_CPU_DEBUG
+	tristate "/sys/kernel/debug/x86/cpu/* - CPU Debug support"
+	---help---
+	  If you select this option, this will provide various x86 CPUs
+	  information through debugfs.
+
 choice
 	prompt "High Memory Support"
 	default HIGHMEM4G if !X86_NUMAQ
arch/x86/include/asm/cpu_debug.h new file +193 -0

193 lines not on this page · raw message

arch/x86/kernel/cpu/Makefile +2 -0
index c381330..a702bad 100644
@@ -24,6 +24,8 @@ obj-$(CONFIG_CPU_SUP_UMC_32)		+= umc.o
 
 obj-$(CONFIG_PERF_COUNTERS)		+= perf_counter.o
 
+obj-$(CONFIG_X86_CPU_DEBUG)		+= cpu_debug.o
+
 obj-$(CONFIG_X86_MCE)			+= mcheck/
 obj-$(CONFIG_MTRR)			+= mtrr/
 obj-$(CONFIG_CPU_FREQ)			+= cpufreq/
arch/x86/kernel/cpu/cpu_debug.c new file +784 -0

784 lines not on this page · raw message

#3 lore raw
Quoted 5 lines · Jaswinder Singh Rajput
arch/x86/kernel/cpu/cpu_debug.c new file +5 -0
+#include <linux/interrupt.h>
+#include <linux/compiler.h>
+#include <linux/kprobes.h>
+#include <linux/signal.h>
+#include <linux/kernel.h>

arch/x86/kernel/cpu/cpu_debug.c line 23

Quoted 10 lines
arch/x86/kernel/cpu/cpu_debug.c new file +10 -0
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/slab.h>
+#include <linux/percpu.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>

If you look at arch/x86/mm/fault.c, they are sorted by length, and within the same length they are sorted alphabetically.

arch/x86/kernel/cpu/cpu_debug.c line 29

Quoted 6 lines
arch/x86/kernel/cpu/cpu_debug.c new file +6 -0
+
+#include <asm/system.h>
+#include <asm/traps.h>
+#include <asm/apic.h>
+#include <asm/desc.h>
+#include <asm/cpu_debug.h>

ditto.

Ingo

#4 lore raw
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Jaswinder Singh Rajput
(quoted diff) +10 -0
+#include <linux/interrupt.h>
+#include <linux/compiler.h>
+#include <linux/kprobes.h>
+#include <linux/signal.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/init.h>
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+#include <linux/smp.h>
+#include <linux/slab.h>
+#include <linux/percpu.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>

If you look at arch/x86/mm/fault.c, they are sorted by length, and within the same length they are sorted alphabetically.

Ok fixed, new pull request:

The following changes since commit 23eeaab0397190b112591dab13d1fb196f099254:
Ingo Molnar (1):
Merge branch 'tracing/ftrace'

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  784 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 985 insertions(+), 0 deletions(-)
 create mode 100755 arch/x86/include/asm/cpu_debug.h
 create mode 100755 arch/x86/kernel/cpu/cpu_debug.c

Complete diff:

arch/x86/Kconfig +6 -0
index 2a0ddfe..b9f6c09 100644
@@ -934,6 +934,12 @@ config X86_CPUID
 	  with major 203 and minors 0 to 31 for /dev/cpu/0/cpuid to
 	  /dev/cpu/31/cpuid.
 
+config X86_CPU_DEBUG
+	tristate "/sys/kernel/debug/x86/cpu/* - CPU Debug support"
+	---help---
+	  If you select this option, this will provide various x86 CPUs
+	  information through debugfs.
+
 choice
 	prompt "High Memory Support"
 	default HIGHMEM4G if !X86_NUMAQ
arch/x86/include/asm/cpu_debug.h new file +193 -0

193 lines not on this page · raw message

arch/x86/kernel/cpu/Makefile +2 -0
index c381330..a702bad 100644
@@ -24,6 +24,8 @@ obj-$(CONFIG_CPU_SUP_UMC_32)		+= umc.o
 
 obj-$(CONFIG_PERF_COUNTERS)		+= perf_counter.o
 
+obj-$(CONFIG_X86_CPU_DEBUG)		+= cpu_debug.o
+
 obj-$(CONFIG_X86_MCE)			+= mcheck/
 obj-$(CONFIG_MTRR)			+= mtrr/
 obj-$(CONFIG_CPU_FREQ)			+= cpufreq/
arch/x86/kernel/cpu/cpu_debug.c new file +784 -0

784 lines not on this page · raw message

#5 lore raw
Quoted 35 lines · Jaswinder Singh Rajput
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Jaswinder Singh Rajput
arch/x86/kernel/cpu/cpu_debug.c new file +10 -0
+#include <linux/interrupt.h>
+#include <linux/compiler.h>
+#include <linux/kprobes.h>
+#include <linux/signal.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/init.h>
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+#include <linux/smp.h>
+#include <linux/slab.h>
+#include <linux/percpu.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>

If you look at arch/x86/mm/fault.c, they are sorted by length, and within the same length they are sorted alphabetically.

Ok fixed, new pull request:

The following changes since commit 23eeaab0397190b112591dab13d1fb196f099254:
Ingo Molnar (1):
Merge branch 'tracing/ftrace'

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

Quoted 7 lines
 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  784 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 985 insertions(+), 0 deletions(-)
 create mode 100755 arch/x86/include/asm/cpu_debug.h
 create mode 100755 arch/x86/kernel/cpu/cpu_debug.c

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

Ingo

#6 lore raw
Quoted 9 lines · Ingo Molnar

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

Here is the fix.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove some dependency

 arch/x86/kernel/cpu/cpu_debug.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +4 -4
index 0bdf4da..08c365a 100755
@@ -464,19 +464,19 @@ static void print_dt(void *seq)
 	unsigned long ldt;
 
 	/* IDT */
-	store_idt((struct desc_ptr *)&dt);
+	native_store_idt((struct desc_ptr *)&dt);
 	print_desc_ptr("IDT", seq, dt);
 
 	/* GDT */
-	store_gdt((struct desc_ptr *)&dt);
+	native_store_gdt((struct desc_ptr *)&dt);
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
 	/* TR */
-	store_tr(ldt);
+	asm volatile("str %0" : "=r" (ldt));
 	seq_printf(seq, " TR\t: %016lx\n", ldt);
 }
 
#7 lore raw
Quoted 33 lines · Jaswinder Singh Rajput
Quoted 9 lines · Ingo Molnar

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

Here is the fix.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove some dependency

 arch/x86/kernel/cpu/cpu_debug.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +0 -0
index 0bdf4da..08c365a 100755

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 467

Quoted 5 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
@@ -464,19 +464,19 @@ static void print_dt(void *seq)
 	unsigned long ldt;
 
 	/* IDT */
-	store_idt((struct desc_ptr *)&dt);
+	native_store_idt((struct desc_ptr *)&dt);

hm, this wont work on Xen then.

Quoted 6 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	print_desc_ptr("IDT", seq, dt);
 
 	/* GDT */
-	store_gdt((struct desc_ptr *)&dt);
+	native_store_gdt((struct desc_ptr *)&dt);
 	print_desc_ptr("GDT", seq, dt);

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 480

Quoted 10 lines
arch/x86/kernel/cpu/cpu_debug.c +2 -2
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
 	/* TR */
-	store_tr(ldt);
+	asm volatile("str %0" : "=r" (ldt));
 	seq_printf(seq, " TR\t: %016lx\n", ldt);

we do have a store_tr() primitive - why open code the assembly?

The real fix (if it's not just a missing include line) would be to make sure these primitives are generally available.

Ingo

#8 lore raw
Quoted 37 lines · Ingo Molnar
Quoted 35 lines · Jaswinder Singh Rajput
Quoted 9 lines · Ingo Molnar

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

Here is the fix.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove some dependency

 arch/x86/kernel/cpu/cpu_debug.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +0 -0
index 0bdf4da..08c365a 100755
@@ -464,19 +464,19 @@ static void print_dt(void *seq)
 	unsigned long ldt;
 
Quoted 6 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 467

Quoted 3 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* IDT */
-	store_idt((struct desc_ptr *)&dt);
+	native_store_idt((struct desc_ptr *)&dt);

hm, this wont work on Xen then.

Strange it should work for Xen, Are you getting any error.

Xen also uses native_store_idt:
arch/x86/xen/enlighten.c: .store_idt = native_store_idt,

Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/cpu_debug.c +2 -2
 	print_desc_ptr("IDT", seq, dt);
 
 	/* GDT */
-	store_gdt((struct desc_ptr *)&dt);
+	native_store_gdt((struct desc_ptr *)&dt);
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
Quoted 7 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 480

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* TR */
-	store_tr(ldt);
+	asm volatile("str %0" : "=r" (ldt));
 	seq_printf(seq, " TR\t: %016lx\n", ldt);

we do have a store_tr() primitive - why open code the assembly?

It is a single line code to avoid further conflicts, so i moved it here.

Can you please test are these works on your boxes.

Thanks,

--
JSR

#9 lore raw
Quoted 38 lines · Jaswinder Singh Rajput
Quoted 37 lines · Ingo Molnar
Quoted 35 lines · Jaswinder Singh Rajput
Quoted 9 lines · Ingo Molnar

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

Here is the fix.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove some dependency

 arch/x86/kernel/cpu/cpu_debug.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +0 -0
index 0bdf4da..08c365a 100755
@@ -464,19 +464,19 @@ static void print_dt(void *seq)
 	unsigned long ldt;
 
Quoted 8 lines
Quoted 6 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 467

Quoted 3 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* IDT */
-	store_idt((struct desc_ptr *)&dt);
+	native_store_idt((struct desc_ptr *)&dt);

hm, this wont work on Xen then.

Strange it should work for Xen, Are you getting any error.

s/Xen/virtualization

Look at how the native_*() primitives are used. They are not there to be open-coded in generic code. They are there for paravirt-internal reasons: they are the native version but a guest implementation might decide to override it.

Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/cpu_debug.c +2 -2
 	print_desc_ptr("IDT", seq, dt);
 
 	/* GDT */
-	store_gdt((struct desc_ptr *)&dt);
+	native_store_gdt((struct desc_ptr *)&dt);
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
Quoted 7 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 480

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* TR */
-	store_tr(ldt);
+	asm volatile("str %0" : "=r" (ldt));
 	seq_printf(seq, " TR\t: %016lx\n", ldt);

we do have a store_tr() primitive - why open code the assembly?

Quoted 2 lines

It is a single line code to avoid further conflicts, so i moved it here.

and that's wrong.

Ingo

#10 lore raw
In reply to Jaswinder Singh Rajput
Quoted 16 lines · Jaswinder Singh Rajput
Quoted 8 lines
Quoted 8 lines

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +0 -0
index 0bdf4da..08c365a 100755
@@ -464,19 +464,19 @@ static void print_dt(void *seq)
 	unsigned long ldt;
 
Quoted 7 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 469

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* IDT */
-	store_idt((struct desc_ptr *)&dt);
+	native_store_idt((struct desc_ptr *)&dt);
 

hm, this wont work on Xen then.

Quoted 5 lines

Strange it should work for Xen, Are you getting any error.

Xen also uses native_store_idt:
arch/x86/xen/enlighten.c: .store_idt = native_store_idt,

store_idt (and the others) are not used very much, and never in any code path under Xen. They're not really meaningful in Xen, and this code will probably oops if you ran it.

I guess we could do more meaningful implementations of these ops for Xen, now that there's a user.

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/cpu_debug.c +2 -2
 	print_desc_ptr("IDT", seq, dt);
 
 	/* GDT */
-	store_gdt((struct desc_ptr *)&dt);
+	native_store_gdt((struct desc_ptr *)&dt);
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
Quoted 8 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 482

Quoted 5 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* TR */
-	store_tr(ldt);
+	asm volatile("str %0" : "=r" (ldt));
 	seq_printf(seq, " TR\t: %016lx\n", ldt);
 

we do have a store_tr() primitive - why open code the assembly?

Quoted 2 lines

It is a single line code to avoid further conflicts, so i moved it here.

Definitely a bad idea.

J

#11 lore raw
Quoted 23 lines · Jeremy Fitzhardinge
Quoted 16 lines · Jaswinder Singh Rajput
Quoted 8 lines
Quoted 8 lines

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +0 -0
index 0bdf4da..08c365a 100755
@@ -464,19 +464,19 @@ static void print_dt(void *seq)
 	unsigned long ldt;
 
Quoted 7 lines

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 469

Quoted 4 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
 	/* IDT */
-	store_idt((struct desc_ptr *)&dt);
+	native_store_idt((struct desc_ptr *)&dt);
 

hm, this wont work on Xen then.

Quoted 5 lines

Strange it should work for Xen, Are you getting any error.

Xen also uses native_store_idt:
arch/x86/xen/enlighten.c: .store_idt = native_store_idt,

Quoted 7 lines

store_idt (and the others) are not used very much, and never in any code path under Xen. They're not really meaningful in Xen, and this code will probably oops if you ran it.

I guess we could do more meaningful implementations of these ops for Xen, now that there's a user.

cpu_debug is availabe in -tip.

Can you test it:

[jaswinder@ht linux-2.6-tip]$ cat /sys/kernel/debug/x86/cpu/cpu*/dt/dt
IDT : 00000000c05617ff
GDT : 00000000c17040ff
LDT : 0000000000000000
TR : 0000000000000080

IDT : 00000000c05617ff
GDT : 00000000c17140ff
LDT : 00000000fce90000
TR : 0000000000000080

[jaswinder@ht linux-2.6-tip]$

--
JSR

#12 lore raw
In reply to Ingo Molnar
Quoted 45 lines · Ingo Molnar
Quoted 35 lines · Jaswinder Singh Rajput
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Jaswinder Singh Rajput
(quoted diff) +10 -0
+#include <linux/interrupt.h>
+#include <linux/compiler.h>
+#include <linux/kprobes.h>
+#include <linux/signal.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/init.h>
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+#include <linux/smp.h>
+#include <linux/slab.h>
+#include <linux/percpu.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>

If you look at arch/x86/mm/fault.c, they are sorted by length, and within the same length they are sorted alphabetically.

Ok fixed, new pull request:

The following changes since commit 23eeaab0397190b112591dab13d1fb196f099254:
Ingo Molnar (1):
Merge branch 'tracing/ftrace'

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

Quoted 7 lines
 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  784 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 985 insertions(+), 0 deletions(-)
 create mode 100755 arch/x86/include/asm/cpu_debug.h
 create mode 100755 arch/x86/kernel/cpu/cpu_debug.c
Quoted 8 lines

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove some dependency

 arch/x86/kernel/cpu/cpu_debug.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +3 -2
index 0bdf4da..c844262 100755
@@ -23,6 +23,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu_debug.h>
+#include <asm/paravirt.h>
 #include <asm/system.h>
 #include <asm/traps.h>
 #include <asm/apic.h>
@@ -427,7 +428,7 @@ static void print_tss(void *arg)
 	seq_printf(seq, " CS\t:             %04x\n", seg);
 	asm("movl %%ds,%0" : "=r" (seg));
 	seq_printf(seq, " DS\t:             %04x\n", seg);
-	seq_printf(seq, " SS\t:             %04lx\n", regs->ss);
+	seq_printf(seq, " SS\t:             %04lx\n", regs->ss & 0xFF);
 	asm("movl %%es,%0" : "=r" (seg));
 	seq_printf(seq, " ES\t:             %04x\n", seg);
 	asm("movl %%fs,%0" : "=r" (seg));
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
 	/* TR */
#13 lore raw
Quoted 83 lines · Jaswinder Singh Rajput
Quoted 45 lines · Ingo Molnar
Quoted 35 lines · Jaswinder Singh Rajput
Quoted 12 lines · Ingo Molnar
Quoted 10 lines · Jaswinder Singh Rajput
(quoted diff) +10 -0
+#include <linux/interrupt.h>
+#include <linux/compiler.h>
+#include <linux/kprobes.h>
+#include <linux/signal.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/init.h>
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+#include <linux/smp.h>
+#include <linux/slab.h>
+#include <linux/percpu.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>

If you look at arch/x86/mm/fault.c, they are sorted by length, and within the same length they are sorted alphabetically.

Ok fixed, new pull request:

The following changes since commit 23eeaab0397190b112591dab13d1fb196f099254:
Ingo Molnar (1):
Merge branch 'tracing/ftrace'

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

Quoted 7 lines
 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  784 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 985 insertions(+), 0 deletions(-)
 create mode 100755 arch/x86/include/asm/cpu_debug.h
 create mode 100755 arch/x86/kernel/cpu/cpu_debug.c
Quoted 8 lines

Thanks - picked it up into tip:x86/debug. (Note that i rearranged the Makefile details a bit so that it does not conflict with tip:perfcounters)

Not yet in tip:master, because it triggers this build failure:

arch/x86/kernel/cpu/cpu_debug.c: In function ‘print_dt’:
arch/x86/kernel/cpu/cpu_debug.c:475: error: implicit declaration of function ‘store_ldt’

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove some dependency

 arch/x86/kernel/cpu/cpu_debug.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +1 -0
index 0bdf4da..c844262 100755
@@ -23,6 +23,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu_debug.h>
+#include <asm/paravirt.h>
 #include <asm/system.h>
 #include <asm/traps.h>
 #include <asm/apic.h>

arch/x86/kernel/cpu/cpu_debug.c static void print_tss(void *arg) · line 431

Quoted 5 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -1
@@ -427,7 +428,7 @@ static void print_tss(void *arg)
 	seq_printf(seq, " CS\t:             %04x\n", seg);
 	asm("movl %%ds,%0" : "=r" (seg));
 	seq_printf(seq, " DS\t:             %04x\n", seg);
-	seq_printf(seq, " SS\t:             %04lx\n", regs->ss);
+	seq_printf(seq, " SS\t:             %04lx\n", regs->ss & 0xFF);

oops, typo, here is the correct one:

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (1):
x86: cpu_debug.c remove store_ldt

 arch/x86/kernel/cpu/cpu_debug.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Complete diff:

arch/x86/kernel/cpu/cpu_debug.c +3 -2
index 0bdf4da..08f55ce 100755
@@ -23,6 +23,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu_debug.h>
+#include <asm/paravirt.h>
 #include <asm/system.h>
 #include <asm/traps.h>
 #include <asm/apic.h>
@@ -427,7 +428,7 @@ static void print_tss(void *arg)
 	seq_printf(seq, " CS\t:             %04x\n", seg);
 	asm("movl %%ds,%0" : "=r" (seg));
 	seq_printf(seq, " DS\t:             %04x\n", seg);
-	seq_printf(seq, " SS\t:             %04lx\n", regs->ss);
+	seq_printf(seq, " SS\t:             %04lx\n", regs->ss & 0xffff);
 	asm("movl %%es,%0" : "=r" (seg));
 	seq_printf(seq, " ES\t:             %04x\n", seg);
 	asm("movl %%fs,%0" : "=r" (seg));
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 	seq_printf(seq, " LDT\t: %016lx\n", ldt);
 
 	/* TR */
#14 lore raw

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 476

Quoted 6 lines · Jaswinder Singh Rajput
arch/x86/kernel/cpu/cpu_debug.c +1 -1
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));

this is still wrong.

Ingo

#15 lore raw
Quoted 10 lines · Ingo Molnar

arch/x86/kernel/cpu/cpu_debug.c static void print_dt(void *seq) · line 476

Quoted 6 lines · Jaswinder Singh Rajput
arch/x86/kernel/cpu/cpu_debug.c +1 -1
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));

this is still wrong.

As i pointed it out before, we should not open-code an assembly primitive - especially since store_ldt() is available in arch/x86/include/asm/desc.h.

True, that primitive is not available on CONFIG_PARAVIRT, but that is a bug: the fix is to move the store_ldt() definition outside the CONFIG_PARAVIRT section in desc.h, not to hack around the problem by open-coding assembly code.

I.e. dont let an uncleanliness and incomplete primitive spread to other code. Fix the primitive and remove the uncleanliness that way.

Ingo

#16 lore raw
Quoted 17 lines · Ingo Molnar
Quoted 10 lines · Ingo Molnar

Review static void print_dt(void *seq) · line 476

Quoted 6 lines · Jaswinder Singh Rajput
(quoted diff) +1 -1
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));

this is still wrong.

As i pointed it out before, we should not open-code an assembly primitive - especially since store_ldt() is available in arch/x86/include/asm/desc.h.

Quoted 9 lines

True, that primitive is not available on CONFIG_PARAVIRT, but that is a bug: the fix is to move the store_ldt() definition outside the CONFIG_PARAVIRT section in desc.h, not to hack around the problem by open-coding assembly code.

I.e. dont let an uncleanliness and incomplete primitive spread to other code. Fix the primitive and remove the uncleanliness that way.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (2):
x86: cpu_debug.c cleanup
x86: move store_ldt outside the CONFIG_PARAVIRT section

 arch/x86/include/asm/desc.h     |    3 ++-
 arch/x86/kernel/cpu/cpu_debug.c |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

Complete diff:

arch/x86/include/asm/desc.h +2 -1
index dc27705..ceb17cc 100644
@@ -91,7 +91,6 @@ static inline int desc_empty(const void *ptr)
 #define store_gdt(dtr) native_store_gdt(dtr)
 #define store_idt(dtr) native_store_idt(dtr)
 #define store_tr(tr) (tr = native_store_tr())
-#define store_ldt(ldt) asm("sldt %0":"=m" (ldt))
 
 #define load_TLS(t, cpu) native_load_tls(t, cpu)
 #define set_ldt native_set_ldt
@@ -112,6 +111,8 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
 }
 #endif	/* CONFIG_PARAVIRT */
 
+#define store_ldt(ldt) asm("sldt %0":"=m" (ldt))
+
 static inline void native_write_idt_entry(gate_desc *idt, int entry,
 					  const gate_desc *gate)
 {
arch/x86/kernel/cpu/cpu_debug.c +2 -1
index 0bdf4da..9abbcbd 100755
@@ -23,6 +23,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu_debug.h>
+#include <asm/paravirt.h>
 #include <asm/system.h>
 #include <asm/traps.h>
 #include <asm/apic.h>
@@ -427,7 +428,7 @@ static void print_tss(void *arg)
 	seq_printf(seq, " CS\t:             %04x\n", seg);
 	asm("movl %%ds,%0" : "=r" (seg));
 	seq_printf(seq, " DS\t:             %04x\n", seg);
-	seq_printf(seq, " SS\t:             %04lx\n", regs->ss);
+	seq_printf(seq, " SS\t:             %04lx\n", regs->ss & 0xffff);
 	asm("movl %%es,%0" : "=r" (seg));
 	seq_printf(seq, " ES\t:             %04x\n", seg);
 	asm("movl %%fs,%0" : "=r" (seg));
#17 lore raw
Quoted 36 lines · Jaswinder Singh Rajput
Quoted 17 lines · Ingo Molnar
Quoted 10 lines · Ingo Molnar

Review static void print_dt(void *seq) · line 476

Quoted 6 lines · Jaswinder Singh Rajput
(quoted diff) +1 -1
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));

this is still wrong.

As i pointed it out before, we should not open-code an assembly primitive - especially since store_ldt() is available in arch/x86/include/asm/desc.h.

Quoted 9 lines

True, that primitive is not available on CONFIG_PARAVIRT, but that is a bug: the fix is to move the store_ldt() definition outside the CONFIG_PARAVIRT section in desc.h, not to hack around the problem by open-coding assembly code.

I.e. dont let an uncleanliness and incomplete primitive spread to other code. Fix the primitive and remove the uncleanliness that way.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Quoted 7 lines

Jaswinder Singh Rajput (2):
x86: cpu_debug.c cleanup
x86: move store_ldt outside the CONFIG_PARAVIRT section

 arch/x86/include/asm/desc.h     |    3 ++-
 arch/x86/kernel/cpu/cpu_debug.c |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

this throws rejects when pulled into tip:x86/debug:

earth4:~/tip> git pull git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Quoted 1 line

From

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu
* branch master -> FETCH_HEAD

Removing Documentation/scheduler/sched-coding.txt Removing arch/ia64/dig/dig_vtd_iommu.c Auto-merging arch/x86/Kconfig
Removing arch/x86/include/asm/intel_arch_perfmon.h Auto-merging arch/x86/kernel/cpu/Makefile Auto-merging arch/x86/kernel/cpu/cpu_debug.c CONFLICT (add/add): Merge conflict in arch/x86/kernel/cpu/cpu_debug.c
Removing block/blktrace.c
Automatic merge failed; fix conflicts and then commit the result.

you should base your branch on tip:x86/debug, and you should not merge in anything else, but do the fixes.

Ingo

#18 lore raw
In reply to Jaswinder Singh Rajput
Quoted 68 lines · Jaswinder Singh Rajput
Quoted 15 lines · Ingo Molnar
Quoted 12 lines · Ingo Molnar

Review static void print_dt(void *seq) · line 477

Quoted 7 lines · Jaswinder Singh Rajput
(quoted diff) +1 -1
@@ -472,7 +473,7 @@ static void print_dt(void *seq)
 	print_desc_ptr("GDT", seq, dt);
 
 	/* LDT */
-	store_ldt(ldt);
+	asm volatile("sldt %0" : "=m" (ldt));
 

this is still wrong.

Quoted 7 lines

As i pointed it out before, we should not open-code an assembly primitive - especially since store_ldt() is available in arch/x86/include/asm/desc.h.

True, that primitive is not available on CONFIG_PARAVIRT, but that is a bug: the fix is to move the store_ldt() definition outside the CONFIG_PARAVIRT section in desc.h, not to hack around the problem by open-coding assembly code.

I.e. dont let an uncleanliness and incomplete primitive spread to other code. Fix the primitive and remove the uncleanliness that way.

The following changes since commit 259ef6fcea4046fe24495b1e3631c1b905c531c1:
Jaswinder Singh Rajput (1):
x86: cpu architecture debug code

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/jaswinder/linux-2.6-tip-cpu.git master

Jaswinder Singh Rajput (2):
x86: cpu_debug.c cleanup
x86: move store_ldt outside the CONFIG_PARAVIRT section

 arch/x86/include/asm/desc.h     |    3 ++-
 arch/x86/kernel/cpu/cpu_debug.c |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

Complete diff:

arch/x86/include/asm/desc.h +2 -1
index dc27705..ceb17cc 100644
@@ -91,7 +91,6 @@ static inline int desc_empty(const void *ptr)
 #define store_gdt(dtr) native_store_gdt(dtr)
 #define store_idt(dtr) native_store_idt(dtr)
 #define store_tr(tr) (tr = native_store_tr())
-#define store_ldt(ldt) asm("sldt %0":"=m" (ldt))
 
 #define load_TLS(t, cpu) native_load_tls(t, cpu)
 #define set_ldt native_set_ldt
@@ -112,6 +111,8 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
 }
 #endif	/* CONFIG_PARAVIRT */
 
+#define store_ldt(ldt) asm("sldt %0":"=m" (ldt))
+
 static inline void native_write_idt_entry(gate_desc *idt, int entry,
 					  const gate_desc *gate)
 {
arch/x86/kernel/cpu/cpu_debug.c +0 -0
index 0bdf4da..9abbcbd 100755

arch/x86/kernel/cpu/cpu_debug.c line 27

Quoted 5 lines
arch/x86/kernel/cpu/cpu_debug.c +1 -0
@@ -23,6 +23,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu_debug.h>
+#include <asm/paravirt.h>
 

This shouldn't be necessary. asm/desc.h should pull it in if it needs it.

J

#19 lore raw
In reply to Jaswinder Singh Rajput
Commit-ID:  9b779edf4b97798d037bb44fca2719ac184d0f14
Gitweb:     http://git.kernel.org/tip/9b779edf4b97798d037bb44fca2719ac184d0f14
Author:     "Jaswinder Singh Rajput" <[email protected]>
AuthorDate: Tue, 10 Mar 2009 15:37:51 +0530
Commit:     Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Mar 2009 18:39:45 +0100

x86: cpu architecture debug code

Introduce:

cat /sys/kernel/debug/x86/cpu/*

for Intel and AMD processors to view / debug the state of each CPU.

By using this we can debug whole range of registers and other cpu information for debugging purpose and monitor how things are changing.

This can be useful for developers as well as for users.

LKML-Reference: <[email protected]>

---
 arch/x86/Kconfig                 |    6 +
 arch/x86/include/asm/cpu_debug.h |  193 ++++++++++
 arch/x86/kernel/cpu/Makefile     |    2 +
 arch/x86/kernel/cpu/cpu_debug.c  |  784 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 985 insertions(+), 0 deletions(-)
arch/x86/Kconfig +6 -0
index 3175837..03f0a3a 100644
@@ -931,6 +931,12 @@ config X86_CPUID
 	  with major 203 and minors 0 to 31 for /dev/cpu/0/cpuid to
 	  /dev/cpu/31/cpuid.
 
+config X86_CPU_DEBUG
+	tristate "/sys/kernel/debug/x86/cpu/* - CPU Debug support"
+	---help---
+	  If you select this option, this will provide various x86 CPUs
+	  information through debugfs.
+
 choice
 	prompt "High Memory Support"
 	default HIGHMEM4G if !X86_NUMAQ
arch/x86/include/asm/cpu_debug.h new file +193 -0

193 lines not on this page · raw message

arch/x86/kernel/cpu/Makefile +2 -0
index 82db7f4..d4356f8 100644
@@ -14,6 +14,8 @@ obj-y			+= vmware.o hypervisor.o
 obj-$(CONFIG_X86_32)	+= bugs.o cmpxchg.o
 obj-$(CONFIG_X86_64)	+= bugs_64.o
 
+obj-$(CONFIG_X86_CPU_DEBUG)		+= cpu_debug.o
+
 obj-$(CONFIG_CPU_SUP_INTEL)		+= intel.o
 obj-$(CONFIG_CPU_SUP_AMD)		+= amd.o
 obj-$(CONFIG_CPU_SUP_CYRIX_32)		+= cyrix.o
arch/x86/kernel/cpu/cpu_debug.c new file +784 -0

784 lines not on this page · raw message

#20 lore raw
In reply to Ingo Molnar
Quoted 2 lines · Ingo Molnar

If you look at arch/x86/mm/fault.c, they are sorted by length, and within the same length they are sorted alphabetically.

Huh? I just did a 'git pull' of Linus's tree, and I see fault.c looking like:

#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/mmiotrace.h>
#include <linux/mman.h>
#include <linux/mm.h>
#include <linux/smp.h>
#include <linux/interrupt.h>

Not sure how it's sorted, but it's appparently not by length first. Also, wouldn't logical interdependency count for something here, including stuff in the order needed?