mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: ebiederm@xmission.com, cl@linux-foundation.org,
	rusty@rustcorp.com.au, mingo@elte.hu, travis@sgi.com,
	linux-kernel@vger.kernel.org, hpa@zytor.com,
	akpm@linux-foundation.org, steiner@sgi.com, hugh@veritas.com
Cc: Tejun Heo <tj@kernel.org>
Subject: [PATCH 13/13] x86_32: make percpu symbols zerobased on SMP
Date: Tue, 13 Jan 2009 19:38:17 +0900	[thread overview]
Message-ID: <1231843097-18003-14-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1231843097-18003-1-git-send-email-tj@kernel.org>

This patch makes percpu symbols zerobased on x86_32 SMP by using
PERCPU_VADDR() with 0 vaddr in vmlinux_32.lds.S.  A new PHDR is added
as existing ones cannot contain sections near address zero.

The following adjustments have been made to accomodate the address
change.

* code to locate percpu gdt_page in head_64.S is updated to add the
  load address to the gdt_page offset.

* for boot CPU, we can't use __KERNEL_DS for %fs.  initialize
  gdt_page.gdt[GDT_ENTRY_PERCPU] with flags and limit and set the base
  address to __per_cpu_load from head_32.S and load it.  the base
  address needs to be set manually because linker can't shift bits as
  required for segment descriptors.

* __per_cpu_offset[0] is now initialized to __per_cpu_load like on
  x86_64.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Mike Travis <travis@sgi.com>
---
 arch/x86/kernel/cpu/common.c     |    8 ++++++++
 arch/x86/kernel/head_32.S        |   37 ++++++++++++++++++++++++++++++++++---
 arch/x86/kernel/setup_percpu.c   |    4 ----
 arch/x86/kernel/vmlinux_32.lds.S |   16 +++++++++++++++-
 4 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index bd38a0f..376e142 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -90,7 +90,15 @@ DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
 	[GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
 
 	[GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
+#ifdef CONFIG_SMP
+	/*
+	 * Linker can't handle the address bit shifting.  Address will
+	 * be set in head_32.S for boot CPU and init_gdt for others.
+	 */
+	[GDT_ENTRY_PERCPU] = { { { 0x0000ffff, 0x00cf9200 } } },
+#else
 	[GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
+#endif
 } };
 #endif
 EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index e835b4e..3284199 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -19,6 +19,7 @@
 #include <asm/asm-offsets.h>
 #include <asm/setup.h>
 #include <asm/processor-flags.h>
+#include <asm/percpu.h>
 
 /* Physical address */
 #define pa(X) ((X) - __PAGE_OFFSET)
@@ -424,12 +425,39 @@ is386:	movl $2,%ecx		# set MP
 	movl %eax,%cr0
 
 	call check_x87
+#ifdef CONFIG_SMP
+	/*
+	 * early_gdt_base should point to the gdt_page in static percpu init
+	 * data area.  Computing this requires two symbols - __per_cpu_load
+	 * and per_cpu__gdt_page.  As linker can't do no such relocation, do
+	 * it by hand.  As early_gdt_descr is manipulated by C code for
+	 * secondary CPUs, this should be done only once for the boot CPU
+	 * when early_gdt_descr_base contains zero.
+	 *
+	 * Also, manually load __per_cpu_load into address fields of PERCPU
+	 * segment descriptor for boot CPU.  Linker can't do it.
+	 */
+	movl	early_gdt_descr_base, %eax
+	testl	%eax, %eax
+	jnz	3f
+	movl	$__per_cpu_load, %eax
+	movl	%eax, %ecx
+	addl	$per_cpu__gdt_page, %eax
+	movl	%eax, early_gdt_descr_base
+
+	movw	%cx, 8 * GDT_ENTRY_PERCPU + 2(%eax)
+	shrl	$16, %ecx
+	movb	%cl, 8 * GDT_ENTRY_PERCPU + 4(%eax)
+	movb	%ch, 8 * GDT_ENTRY_PERCPU + 7(%eax)
+3:
+#endif /* CONFIG_SMP */
 	lgdt early_gdt_descr
 	lidt idt_descr
 	ljmp $(__KERNEL_CS),$1f
 1:	movl $(__KERNEL_DS),%eax	# reload all the segment registers
 	movl %eax,%ss			# after changing gdt.
-	movl %eax,%fs			# gets reset once there's real percpu
+	movl $(__KERNEL_PERCPU),%eax
+	movl %eax,%fs			# will be reloaded for boot cpu
 
 	movl $(__USER_DS),%eax		# DS/ES contains default USER segment
 	movl %eax,%ds
@@ -446,8 +474,6 @@ is386:	movl $2,%ecx		# set MP
 	movb $1, ready
 	cmpb $0,%cl		# the first CPU calls start_kernel
 	je   1f
-	movl $(__KERNEL_PERCPU), %eax
-	movl %eax,%fs		# set this cpu's percpu
 	movl (stack_start), %esp
 1:
 #endif /* CONFIG_SMP */
@@ -702,7 +728,12 @@ idt_descr:
 	.word 0				# 32 bit align gdt_desc.address
 ENTRY(early_gdt_descr)
 	.word GDT_ENTRIES*8-1
+#ifdef CONFIG_SMP
+early_gdt_descr_base:
+	.long 0x00000000
+#else
 	.long per_cpu__gdt_page		/* Overwritten for secondary CPUs */
+#endif
 
 /*
  * The boot_gdt must mirror the equivalent in setup.S and is
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
index 9edc081..6f47227 100644
--- a/arch/x86/kernel/setup_percpu.c
+++ b/arch/x86/kernel/setup_percpu.c
@@ -119,13 +119,9 @@ static void __init setup_per_cpu_maps(void)
 #endif
 }
 
-#ifdef CONFIG_X86_64
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
 	[0] = (unsigned long)__per_cpu_load,
 };
-#else
-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
-#endif
 EXPORT_SYMBOL(__per_cpu_offset);
 
 /*
diff --git a/arch/x86/kernel/vmlinux_32.lds.S b/arch/x86/kernel/vmlinux_32.lds.S
index 3eba7f7..03abadf 100644
--- a/arch/x86/kernel/vmlinux_32.lds.S
+++ b/arch/x86/kernel/vmlinux_32.lds.S
@@ -24,6 +24,9 @@ jiffies = jiffies_64;
 PHDRS {
 	text PT_LOAD FLAGS(5);	/* R_E */
 	data PT_LOAD FLAGS(7);	/* RWE */
+#ifdef CONFIG_SMP
+	percpu PT_LOAD FLAGS(7);	/* RWE */
+#endif
 	note PT_NOTE FLAGS(0);	/* ___ */
 }
 SECTIONS
@@ -178,7 +181,18 @@ SECTIONS
 	__initramfs_end = .;
   }
 #endif
+
+#ifdef CONFIG_SMP
+  /*
+   * percpu offsets are zero-based on SMP.  PERCPU_VADDR() changes the
+   * output PHDR, so the next output section - bss - should switch it
+   * back to data.
+   */
+  . = ALIGN(PAGE_SIZE);
+  PERCPU_VADDR(0, :percpu)
+#else
   PERCPU(PAGE_SIZE)
+#endif
   . = ALIGN(PAGE_SIZE);
   /* freed after init ends here */
 
@@ -193,7 +207,7 @@ SECTIONS
 	/* This is where the kernel creates the early boot page tables */
 	. = ALIGN(PAGE_SIZE);
 	pg0 = . ;
-  }
+  } :data	/* switch back to data, see PERCPU_VADDR() above */
 
   /* Sections to be discarded */
   /DISCARD/ : {
-- 
1.5.6


  parent reply	other threads:[~2009-01-13 10:39 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-13 10:38 [PATCHSET linux-2.6-x86:tip] x86: make percpu offsets zero-based " Tejun Heo
2009-01-13 10:38 ` [PATCH 01/13] x86_64: fix pda_to_op() Tejun Heo
2009-01-13 10:38 ` [PATCH 02/13] x86: make early_per_cpu() a lvalue and use it Tejun Heo
2009-01-13 11:43   ` [PATCH 02/13 UPDATED] " Tejun Heo
2009-01-13 10:38 ` [PATCH 03/13] x86_64: Cleanup early setup_percpu references Tejun Heo
2009-01-13 10:38 ` [PATCH 04/13] x86_32: make vmlinux_32.lds.S use PERCPU() macro Tejun Heo
2009-01-13 10:38 ` [PATCH 05/13] x86_64: make percpu symbols zerobased on SMP Tejun Heo
2009-01-13 10:38 ` [PATCH 06/13] x86_64: load pointer to pda into %gs while brining up a CPU Tejun Heo
2009-01-13 10:38 ` [PATCH 07/13] x86_64: use static _cpu_pda array Tejun Heo
2009-01-13 10:38 ` [PATCH 08/13] x86_64: fold pda into percpu area on SMP Tejun Heo
2009-01-13 10:38 ` [PATCH 09/13] x86_64: merge 64 and 32 SMP percpu handling Tejun Heo
2009-01-13 10:38 ` [PATCH 10/13] x86_64: make pda a percpu variable Tejun Heo
2009-01-13 10:38 ` [PATCH 11/13] x86_64: convert pda ops to wrappers around x86 percpu accessors Tejun Heo
2009-01-13 10:38 ` [PATCH 12/13] x86_64: misc clean up after the percpu update Tejun Heo
2009-01-13 10:38 ` Tejun Heo [this message]
2009-01-14  0:18   ` [PATCH 13/13] x86_32: make percpu symbols zerobased on SMP Rusty Russell
2009-01-14  2:03     ` Tejun Heo
2009-01-13 10:48 ` [PATCHSET linux-2.6-x86:tip] x86: make percpu offsets zero-based " Tejun Heo
2009-01-13 13:27   ` Brian Gerst
2009-01-13 14:05     ` Tejun Heo
2009-01-13 14:26       ` Brian Gerst
2009-01-13 14:37         ` Tejun Heo
2009-01-14  6:57       ` H. Peter Anvin
2009-01-14  9:38         ` [patch] add optimized generic percpu accessors Ingo Molnar
2009-01-14  9:45           ` Ingo Molnar
     [not found]           ` <200901151253.44016.rusty@rustcorp.com.au>
2009-01-15  9:55             ` Ingo Molnar
2009-01-15 10:27             ` Tejun Heo
2009-01-15 10:04           ` roel kluin
2009-01-15 10:26             ` Tejun Heo
2009-01-15 11:32               ` Ingo Molnar
2009-01-15 11:36                 ` Tejun Heo
2009-01-15 12:22                   ` Ingo Molnar
2009-01-15 13:09                     ` Tejun Heo
2009-01-15 13:32                       ` Ingo Molnar
2009-01-15 13:33                         ` Ingo Molnar
2009-01-15 13:39                         ` Ingo Molnar
2009-01-15 21:54                           ` Tejun Heo
2009-01-16  1:28                             ` [PATCH x86/percpu] x86: fix build bug introduced during merge Tejun Heo
2009-01-16  3:25                               ` [PATCH x86/percpu] x86_64: initialize this_cpu_off to __per_cpu_load Tejun Heo
2009-01-16 13:16                                 ` Ingo Molnar
2009-01-16 13:47                                   ` Tejun Heo
     [not found]                                     ` <20090116221651.GA32736@elte.hu>
     [not found]                                       ` <20090116223828.GA9294@elte.hu>
     [not found]                                         ` <49716F0E.7060605@gmail.com>
     [not found]                                           ` <49716FBF.7080203@kernel.org>
2009-01-17  6:29                                             ` [PATCH core/percpu REPOST] linker script: add missing VMLINUX_SYMBOL Tejun Heo
2009-01-17  6:32                                               ` [PATCH] linker script: add missing .data.percpu.page_aligned Tejun Heo
2009-01-17  8:21                                                 ` Ingo Molnar
2009-01-21 23:46                                                 ` Christoph Lameter
2009-01-21 23:45                                               ` [PATCH core/percpu REPOST] linker script: add missing VMLINUX_SYMBOL Christoph Lameter
2009-01-15 22:34                           ` [patch] add optimized generic percpu accessors Ingo Molnar
2009-01-15 20:31                     ` Christoph Lameter
2009-01-16  9:41                       ` Tejun Heo
2009-01-16 13:23                         ` Ingo Molnar
2009-01-16 13:49                           ` Tejun Heo
2009-01-15 10:26           ` Tejun Heo
2009-01-15 11:30             ` Ingo Molnar
2009-01-15 11:38               ` Tejun Heo
2009-01-15 12:26                 ` Ingo Molnar
2009-01-15 13:04                   ` Tejun Heo
2009-01-15 13:07                     ` Ingo Molnar
2009-01-15 13:23                       ` [PATCH] percpu: " Tejun Heo
2009-01-15 13:36                         ` Ingo Molnar
2009-01-15 17:30                         ` Andrew Morton
2009-01-15 18:02                           ` Ingo Molnar
2009-01-15 18:34                             ` Andrew Morton
2009-01-15 18:39                               ` Ingo Molnar
2009-01-15 21:53                                 ` Tejun Heo
2009-01-16  0:12                                 ` Herbert Xu
2009-01-16  0:15                                   ` Ingo Molnar
2009-01-16  0:18                                     ` Herbert Xu
     [not found]                                       ` <200901170827.33729.rusty@rustcorp.com.au>
2009-01-16 22:08                                         ` Ingo Molnar
     [not found]                                           ` <200901201328.24605.rusty@rustcorp.com.au>
2009-01-20  6:25                                             ` Tejun Heo
2009-01-20 10:36                                               ` Ingo Molnar
     [not found]                                               ` <200901271213.18605.rusty@rustcorp.com.au>
2009-01-27  2:24                                                 ` Tejun Heo
2009-01-27 13:13                                                   ` Ingo Molnar
2009-01-27 23:07                                                     ` Tejun Heo
2009-01-28  3:36                                                       ` Tejun Heo
2009-01-28  8:12                                                         ` Tejun Heo
2009-01-27 20:08                                                   ` Christoph Lameter
2009-01-27 21:47                                                     ` David Miller
2009-01-27 22:47                                                       ` Rick Jones
2009-01-28  0:17                                                         ` Luck, Tony
2009-01-28 16:48                                                           ` Christoph Lameter
2009-01-28 17:15                                                             ` Luck, Tony
2009-01-28 16:45                                                       ` Christoph Lameter
2009-01-28 20:47                                                         ` David Miller
2009-01-28 10:38                                                   ` Rusty Russell
2009-01-28 10:56                                                     ` Tejun Heo
2009-01-29  2:06                                                       ` Rusty Russell
2009-01-31  6:11                                                         ` Tejun Heo
2009-01-28 16:50                                                     ` Christoph Lameter
2009-01-28 18:07                                                       ` Mathieu Desnoyers
2009-01-29 18:33                                                         ` Christoph Lameter
2009-01-29 18:48                                                           ` H. Peter Anvin
2009-01-20 10:40                                             ` Ingo Molnar
2009-01-21  5:52                                               ` Tejun Heo
2009-01-21 10:05                                                 ` Ingo Molnar
2009-01-21 11:21                                                 ` Eric W. Biederman
2009-01-21 12:45                                                   ` Stephen Hemminger
2009-01-21 14:13                                                     ` Eric W. Biederman
2009-01-21 20:34                                                     ` David Miller
2009-01-16  1:09                                     ` H. Peter Anvin
     [not found]                                   ` <200901170804.18622.rusty@rustcorp.com.au>
2009-01-16 21:59                                     ` Ingo Molnar
2009-01-16 22:09                                     ` Ingo Molnar
2009-01-16 14:10                               ` Mark Lord
2009-01-15 18:46                         ` Ingo Molnar
2009-01-31 10:36                         ` Jeremy Fitzhardinge
2009-01-15 13:59                     ` [patch] " roel kluin
2009-01-15 21:51                       ` Tejun Heo
     [not found]                 ` <200901170748.53734.rusty@rustcorp.com.au>
2009-01-16 21:24                   ` Ingo Molnar
2009-01-31 10:30           ` Jeremy Fitzhardinge
2009-01-31 16:00             ` Ingo Molnar

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=1231843097-18003-14-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=hpa@zytor.com \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rusty@rustcorp.com.au \
    --cc=steiner@sgi.com \
    --cc=travis@sgi.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

Powered by JetHome