linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glauber de Oliveira Costa <gcosta@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, glommer@gmail.com, tglx@linutronix.de,
	mingo@elte.hu, ehabkost@redhat.com, jeremy@goop.org,
	avi@qumranet.com, anthony@codemonkey.ws,
	virtualization@lists.linux-foundation.org, rusty@rustcorp.com.au,
	ak@suse.de, chrisw@sous-sol.org, rostedt@goodmis.org,
	hpa@zytor.com, zach@vmware.com, roland@redhat.com,
	Glauber de Oliveira Costa <gcosta@redhat.com>
Subject: [PATCH 18/19] move _set_gate and its users to a common location
Date: Thu, 13 Dec 2007 11:58:06 -0200	[thread overview]
Message-ID: <1197554404337-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <1197554399402-git-send-email-gcosta@redhat.com>

This patch moves _set_gate and its users to desc.h. We can now
use common code for x86_64 and i386.

Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
---
 arch/x86/kernel/traps_32.c  |   34 ----------------
 include/asm-x86/desc.h      |   88 +++++++++++++++++++++++++++++++++++++++++++
 include/asm-x86/desc_32.h   |   16 --------
 include/asm-x86/desc_64.h   |   45 ----------------------
 include/asm-x86/desc_defs.h |    5 +--
 5 files changed, 89 insertions(+), 99 deletions(-)

Index: linux-2.6-x86/arch/x86/kernel/traps_32.c
===================================================================
--- linux-2.6-x86.orig/arch/x86/kernel/traps_32.c
+++ linux-2.6-x86/arch/x86/kernel/traps_32.c
@@ -1102,40 +1102,6 @@ asmlinkage void math_emulate(long arg)
 
 #endif /* CONFIG_MATH_EMULATION */
 
-/*
- * This needs to use 'idt_table' rather than 'idt', and
- * thus use the _nonmapped_ version of the IDT, as the
- * Pentium F0 0F bugfix can have resulted in the mapped
- * IDT being write-protected.
- */
-void set_intr_gate(unsigned int n, void *addr)
-{
-	_set_gate(n, DESCTYPE_INT, addr, __KERNEL_CS);
-}
-
-/*
- * This routine sets up an interrupt gate at directory privilege level 3.
- */
-static inline void set_system_intr_gate(unsigned int n, void *addr)
-{
-	_set_gate(n, DESCTYPE_INT | DESCTYPE_DPL3, addr, __KERNEL_CS);
-}
-
-static void __init set_trap_gate(unsigned int n, void *addr)
-{
-	_set_gate(n, DESCTYPE_TRAP, addr, __KERNEL_CS);
-}
-
-static void __init set_system_gate(unsigned int n, void *addr)
-{
-	_set_gate(n, DESCTYPE_TRAP | DESCTYPE_DPL3, addr, __KERNEL_CS);
-}
-
-static void __init set_task_gate(unsigned int n, unsigned int gdt_entry)
-{
-	_set_gate(n, DESCTYPE_TASK, (void *)0, (gdt_entry<<3));
-}
-
 
 void __init trap_init(void)
 {
Index: linux-2.6-x86/include/asm-x86/desc.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/desc.h
+++ linux-2.6-x86/include/asm-x86/desc.h
@@ -33,6 +33,22 @@ extern struct desc_struct cpu_gdt_table[
 extern struct desc_ptr cpu_gdt_descr[];
 /* the cpu gdt accessor */
 #define get_cpu_gdt_table(x) ((struct desc_struct *)cpu_gdt_descr[x].address)
+
+static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long func,
+			     unsigned dpl, unsigned ist, unsigned seg)
+{
+	gate->offset_low = PTR_LOW(func);
+	gate->segment = __KERNEL_CS;
+	gate->ist = ist;
+	gate->p = 1;
+	gate->dpl = dpl;
+	gate->zero0 = 0;
+	gate->zero1 = 0;
+	gate->type = type;
+	gate->offset_middle = PTR_MIDDLE(func);
+	gate->offset_high = PTR_HIGH(func);
+}
+
 #else
 struct gdt_page {
 	struct desc_struct gdt[GDT_ENTRIES];
@@ -43,6 +59,16 @@ static inline struct desc_struct *get_cp
 {
 	return per_cpu(gdt_page, cpu).gdt;
 }
+
+static inline void pack_gate(gate_desc *gate, unsigned char type,
+       unsigned long base, unsigned dpl, unsigned flags, unsigned short seg)
+
+{
+	gate->a = (seg << 16) | (base & 0xffff);
+	gate->b = (base & 0xffff0000) |
+		  (((0x80 | type | (dpl << 5)) & 0xff) << 8);
+}
+
 #endif
 
 #ifdef CONFIG_PARAVIRT
@@ -234,6 +260,68 @@ static inline unsigned long get_desc_bas
 {
 	return desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24);
 }
+static inline void _set_gate(int gate, unsigned type, void *addr,
+			      unsigned dpl, unsigned ist, unsigned seg)
+{
+	gate_desc s;
+	pack_gate(&s, type, (unsigned long)addr, dpl, ist, seg);
+	/*
+	 * does not need to be atomic because it is only done once at
+	 * setup time
+	 */
+	write_idt_entry(idt_table, gate, &s);
+}
+
+/*
+ * This needs to use 'idt_table' rather than 'idt', and
+ * thus use the _nonmapped_ version of the IDT, as the
+ * Pentium F0 0F bugfix can have resulted in the mapped
+ * IDT being write-protected.
+ */
+static inline void set_intr_gate(unsigned int n, void *addr)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
+}
+
+/*
+ * This routine sets up an interrupt gate at directory privilege level 3.
+ */
+static inline void set_system_intr_gate(unsigned int n, void *addr)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
+}
+
+static inline void set_trap_gate(unsigned int n, void *addr)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
+}
+
+static inline void set_system_gate(unsigned int n, void *addr)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
+}
+
+static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
+}
+
+static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
+}
+
+static inline void set_system_gate_ist(int n, void *addr, unsigned ist)
+{
+	BUG_ON((unsigned)n > 0xFF);
+	_set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
+}
 
 #else
 /*
Index: linux-2.6-x86/include/asm-x86/desc_32.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/desc_32.h
+++ linux-2.6-x86/include/asm-x86/desc_32.h
@@ -10,22 +10,6 @@
 #include <linux/preempt.h>
 #include <linux/percpu.h>
 
-extern void set_intr_gate(unsigned int irq, void * addr);
-
-static inline void pack_gate(gate_desc *gate,
-	unsigned long base, unsigned short seg, unsigned char type, unsigned char flags)
-{
-	gate->a = (seg << 16) | (base & 0xffff);
-	gate->b = (base & 0xffff0000) | ((type & 0xff) << 8) | (flags & 0xff);
-}
-
-static inline void _set_gate(int gate, unsigned int type, void *addr, unsigned short seg)
-{
-	gate_desc g;
-	pack_gate(&g, (unsigned long)addr, seg, type, 0);
-	write_idt_entry(idt_table, gate, &g);
-}
-
 static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, const void *addr)
 {
 	tss_desc tss;
Index: linux-2.6-x86/include/asm-x86/desc_64.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/desc_64.h
+++ linux-2.6-x86/include/asm-x86/desc_64.h
@@ -11,51 +11,6 @@
 
 #include <asm/segment.h>
 
-static inline void _set_gate(int gate, unsigned type, unsigned long func,
-			     unsigned dpl, unsigned ist)
-{
-	gate_desc s;
-
-	s.offset_low = PTR_LOW(func);
-	s.segment = __KERNEL_CS;
-	s.ist = ist;
-	s.p = 1;
-	s.dpl = dpl;
-	s.zero0 = 0;
-	s.zero1 = 0;
-	s.type = type;
-	s.offset_middle = PTR_MIDDLE(func);
-	s.offset_high = PTR_HIGH(func);
-	/*
-	 * does not need to be atomic because it is only done once at
-	 * setup time
-	 */
-	write_idt_entry(idt_table, gate, &s);
-}
-
-static inline void set_intr_gate(int nr, void *func)
-{
-	BUG_ON((unsigned)nr > 0xFF);
-	_set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 0, 0);
-}
-
-static inline void set_intr_gate_ist(int nr, void *func, unsigned ist)
-{
-	BUG_ON((unsigned)nr > 0xFF);
-	_set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 0, ist);
-}
-
-static inline void set_system_gate(int nr, void *func)
-{
-	BUG_ON((unsigned)nr > 0xFF);
-	_set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 3, 0);
-}
-
-static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
-{
-	_set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 3, ist);
-}
-
 static inline void set_tss_desc(unsigned cpu, void *addr)
 {
 	struct desc_struct *d = get_cpu_gdt_table(cpu);
Index: linux-2.6-x86/include/asm-x86/desc_defs.h
===================================================================
--- linux-2.6-x86.orig/include/asm-x86/desc_defs.h
+++ linux-2.6-x86/include/asm-x86/desc_defs.h
@@ -36,6 +36,7 @@ enum {
 	GATE_INTERRUPT = 0xE,
 	GATE_TRAP = 0xF,
 	GATE_CALL = 0xC,
+	GATE_TASK = 0x5,
 };
 
 // 16byte gate
@@ -55,10 +56,6 @@ struct gate_struct64 {
 enum {
 	DESC_TSS = 0x9,
 	DESC_LDT = 0x2,
-	DESCTYPE_TASK = 0x85,   /* present, system, DPL-0, task gate */
-	DESCTYPE_INT =  0x8e,   /* present, system, DPL-0, interrupt gate */
-	DESCTYPE_TRAP = 0x8f,   /* present, system, DPL-0, trap gate */
-	DESCTYPE_DPL3 = 0x60,   /* DPL-3 */
 	DESCTYPE_S =	0x10,	/* !system */
 };
 

  reply	other threads:[~2007-12-13 16:46 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-06 16:16 [PATCH 0/19] desc_struct integration Glauber de Oliveira Costa
2007-12-06 16:16 ` [PATCH 1/19] unify desc_struct Glauber de Oliveira Costa
2007-12-06 16:16   ` [PATCH 2/19] unify struct desc_ptr Glauber de Oliveira Costa
2007-12-06 16:16     ` [PATCH 3/19] change gdt acessor macro name Glauber de Oliveira Costa
2007-12-06 16:16       ` [PATCH 4/19] removed unused variable Glauber de Oliveira Costa
2007-12-06 16:16         ` [PATCH 5/19] introduce gate_desc type Glauber de Oliveira Costa
2007-12-06 16:16           ` [PATCH 6/19] change write_idt_entry signature Glauber de Oliveira Costa
2007-12-06 16:16             ` [PATCH 7/19] introduce ldt_desc type Glauber de Oliveira Costa
2007-12-06 16:16               ` [PATCH 8/19] modify write_ldt function Glauber de Oliveira Costa
2007-12-06 16:16                 ` [PATCH 9/19] introduce fill_ldt Glauber de Oliveira Costa
2007-12-06 16:16                   ` [PATCH 10/19] change write_gdt_entry signature Glauber de Oliveira Costa
2007-12-06 16:16                     ` [PATCH 11/19] change write_ldt_entry signature Glauber de Oliveira Costa
2007-12-06 16:16                       ` [PATCH 12/19] move constants to desc_defs.h Glauber de Oliveira Costa
2007-12-06 16:16                         ` [PATCH 13/19] unify non-paravirt parts of desc.h Glauber de Oliveira Costa
2007-12-06 16:16                           ` [PATCH 14/19] use the same data type for tls_array Glauber de Oliveira Costa
2007-12-06 16:16                             ` [PATCH 15/19] modify get_desc_base Glauber de Oliveira Costa
2007-12-06 16:16                               ` [PATCH 16/19] provide tss_desc Glauber de Oliveira Costa
2007-12-06 16:16                                 ` [PATCH 17/19] unify paravirt pieces of descriptor handling Glauber de Oliveira Costa
2007-12-06 16:16                                   ` [PATCH 18/19] move _set_gate and its users to a common location Glauber de Oliveira Costa
2007-12-06 16:16                                     ` [PATCH 19/19] unify set_tss_desc Glauber de Oliveira Costa
2007-12-06 19:24   ` [PATCH 1/19] unify desc_struct Jeremy Fitzhardinge
2007-12-06 19:37     ` Glauber de Oliveira Costa
2007-12-06 20:54   ` Andi Kleen
2007-12-06 21:20     ` Glauber de Oliveira Costa
2007-12-06 22:03       ` Jeremy Fitzhardinge
2007-12-12 12:53 ` [PATCH 0/19] desc_struct integration Glauber de Oliveira Costa
2007-12-12 12:53   ` [PATCH 01/19] unify desc_struct Glauber de Oliveira Costa
2007-12-12 12:53     ` [PATCH 02/19] unify struct desc_ptr Glauber de Oliveira Costa
2007-12-12 12:53       ` [PATCH 03/19] change gdt acessor macro name Glauber de Oliveira Costa
2007-12-12 12:53         ` [PATCH 04/19] removed unused variable Glauber de Oliveira Costa
2007-12-12 12:53           ` [PATCH 05/19] introduce gate_desc type Glauber de Oliveira Costa
2007-12-12 12:53             ` [PATCH 06/19] change write_idt_entry signature Glauber de Oliveira Costa
2007-12-12 12:53               ` [PATCH 07/19] introduce ldt_desc type Glauber de Oliveira Costa
2007-12-12 12:53                 ` [PATCH 08/19] modify write_ldt function Glauber de Oliveira Costa
2007-12-12 12:53                   ` [PATCH 09/19] introduce fill_ldt Glauber de Oliveira Costa
2007-12-12 12:53                     ` [PATCH 10/19] provide tss_desc Glauber de Oliveira Costa
2007-12-12 12:53                       ` [PATCH 11/19] change write_gdt_entry signature Glauber de Oliveira Costa
2007-12-12 12:53                         ` [PATCH 12/19] change write_ldt_entry signature Glauber de Oliveira Costa
2007-12-12 12:53                           ` [PATCH 13/19] move constants to desc_defs.h Glauber de Oliveira Costa
2007-12-12 12:53                             ` [PATCH 14/19] unify non-paravirt parts of desc.h Glauber de Oliveira Costa
2007-12-12 12:54                               ` [PATCH 15/19] use the same data type for tls_array Glauber de Oliveira Costa
2007-12-12 12:54                                 ` [PATCH 16/19] modify get_desc_base Glauber de Oliveira Costa
2007-12-12 12:54                                   ` [PATCH 17/19] unify paravirt pieces of descriptor handling Glauber de Oliveira Costa
2007-12-12 12:54                                     ` [PATCH 18/19] move _set_gate and its users to a common location Glauber de Oliveira Costa
2007-12-12 12:54                                       ` [PATCH 19/19] unify set_tss_desc Glauber de Oliveira Costa
2007-12-12 17:56                     ` [PATCH 09/19] introduce fill_ldt Ingo Molnar
2007-12-12 17:20   ` [PATCH 0/19] desc_struct integration Ingo Molnar
2007-12-12 18:11     ` Ingo Molnar
2007-12-12 18:20       ` Ingo Molnar
2007-12-12 18:27         ` Glauber de Oliveira Costa
2007-12-12 18:33           ` Ingo Molnar
2007-12-12 19:05             ` Glauber de Oliveira Costa
2007-12-12 18:34           ` Ingo Molnar
2007-12-12 23:39   ` H. Peter Anvin
2007-12-13  2:01 ` [PATCH 0/19 - v3] " Glauber de Oliveira Costa
2007-12-13  2:01   ` [PATCH 01/19] unify desc_struct Glauber de Oliveira Costa
2007-12-13  2:01     ` [PATCH 02/19] unify struct desc_ptr Glauber de Oliveira Costa
2007-12-13  2:01       ` [PATCH 03/19] change gdt acessor macro name Glauber de Oliveira Costa
2007-12-13  2:01         ` [PATCH 04/19] removed unused variable Glauber de Oliveira Costa
2007-12-13  2:01           ` [PATCH 05/19] introduce gate_desc type Glauber de Oliveira Costa
2007-12-13  2:01             ` [PATCH 06/19] change write_idt_entry signature Glauber de Oliveira Costa
2007-12-13  2:01               ` [PATCH 07/19] introduce ldt_desc type Glauber de Oliveira Costa
2007-12-13  2:01                 ` [PATCH 08/19] modify write_ldt function Glauber de Oliveira Costa
2007-12-13  2:01                   ` [PATCH 09/19] introduce fill_ldt Glauber de Oliveira Costa
2007-12-13  2:01                     ` [PATCH 10/19] provide tss_desc Glauber de Oliveira Costa
2007-12-13  2:01                       ` [PATCH 11/19] change write_gdt_entry signature Glauber de Oliveira Costa
2007-12-13  2:01                         ` [PATCH 12/19] change write_ldt_entry signature Glauber de Oliveira Costa
2007-12-13  2:01                           ` [PATCH 13/19] move constants to desc_defs.h Glauber de Oliveira Costa
2007-12-13  2:01                             ` [PATCH 14/19] unify non-paravirt parts of desc.h Glauber de Oliveira Costa
2007-12-13  2:01                               ` [PATCH 15/19] use the same data type for tls_array Glauber de Oliveira Costa
2007-12-13  2:01                                 ` [PATCH 16/19] modify get_desc_base Glauber de Oliveira Costa
2007-12-13  2:01                                   ` [PATCH 17/19] unify paravirt pieces of descriptor handling Glauber de Oliveira Costa
2007-12-13  2:01                                     ` [PATCH 18/19] move _set_gate and its users to a common location Glauber de Oliveira Costa
2007-12-13  2:01                                       ` [PATCH 19/19] unify set_tss_desc Glauber de Oliveira Costa
2007-12-13 12:46                                         ` Andi Kleen
2007-12-13 14:50                                           ` Glauber de Oliveira Costa
2007-12-13 13:57   ` [PATCH 0/19 -v4] desc_struct integration Glauber de Oliveira Costa
2007-12-13 13:57     ` [PATCH 01/19] unify desc_struct Glauber de Oliveira Costa
2007-12-13 13:57       ` [PATCH 02/19] unify struct desc_ptr Glauber de Oliveira Costa
2007-12-13 13:57         ` [PATCH 03/19] change gdt acessor macro name Glauber de Oliveira Costa
2007-12-13 13:57           ` [PATCH 04/19] removed unused variable Glauber de Oliveira Costa
2007-12-13 13:57             ` [PATCH 05/19] introduce gate_desc type Glauber de Oliveira Costa
2007-12-13 13:57               ` [PATCH 06/19] change write_idt_entry signature Glauber de Oliveira Costa
2007-12-13 13:57                 ` [PATCH 07/19] introduce ldt_desc type Glauber de Oliveira Costa
2007-12-13 13:57                   ` [PATCH 08/19] modify write_ldt function Glauber de Oliveira Costa
2007-12-13 13:57                     ` [PATCH 09/19] introduce fill_ldt Glauber de Oliveira Costa
2007-12-13 13:57                       ` [PATCH 10/19] provide tss_desc Glauber de Oliveira Costa
2007-12-13 13:57                         ` [PATCH 11/19] change write_gdt_entry signature Glauber de Oliveira Costa
2007-12-13 13:58                           ` [PATCH 12/19] change write_ldt_entry signature Glauber de Oliveira Costa
2007-12-13 13:58                             ` [PATCH 13/19] move constants to desc_defs.h Glauber de Oliveira Costa
2007-12-13 13:58                               ` [PATCH 14/19] unify non-paravirt parts of desc.h Glauber de Oliveira Costa
2007-12-13 13:58                                 ` [PATCH 15/19] use the same data type for tls_array Glauber de Oliveira Costa
2007-12-13 13:58                                   ` [PATCH 16/19] modify get_desc_base Glauber de Oliveira Costa
2007-12-13 13:58                                     ` [PATCH 17/19] unify paravirt pieces of descriptor handling Glauber de Oliveira Costa
2007-12-13 13:58                                       ` Glauber de Oliveira Costa [this message]
2007-12-13 13:58                                         ` [PATCH 19/19] unify set_tss_desc Glauber de Oliveira Costa
2007-12-22  2:07                                         ` [PATCH 18/19] move _set_gate and its users to a common location Ingo Molnar
2007-12-13 16:47     ` [PATCH 0/19 -v4] desc_struct integration Ingo Molnar
2007-12-13 17:06       ` Glauber de Oliveira Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1197554404337-git-send-email-gcosta@redhat.com \
    --to=gcosta@redhat.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=anthony@codemonkey.ws \
    --cc=avi@qumranet.com \
    --cc=chrisw@sous-sol.org \
    --cc=ehabkost@redhat.com \
    --cc=glommer@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=zach@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).