From: Chuck Ebbert <76306.1226@compuserve.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Linus Torvalds <torvalds@osdl.org>, Ingo Molnar <mingo@elte.hu>,
Andi Kleen <ak@suse.de>
Subject: [RFC, patch] i386: vgetcpu(), take 2
Date: Wed, 21 Jun 2006 03:27:30 -0400 [thread overview]
Message-ID: <200606210329_MC3-1-C305-E008@compuserve.com> (raw)
Use a GDT entry's limit field to store per-cpu data for fast access
from userspace, and provide a vsyscall to access the current CPU
number stored there.
Questions:
1. Will the vdso relocation patch break this?
2. Should the version number of the vsyscall .so be incremented?
Test program using the new call:
/* vgetcpu.c: get CPU number we are running on.
* build kernel with vgetcpu patch first, then:
* gcc -o vgetcpu vgetcpu.c <srcpath>/arch/i386/kernel/vsyscall-sysenter.so
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
extern int __vgetcpu(void);
int main(int argc, char * const argv[])
{
printf("cpu: %u\n", __vgetcpu());
return 0;
}
---
arch/i386/kernel/cpu/common.c | 3 +++
arch/i386/kernel/head.S | 8 +++++++-
arch/i386/kernel/vsyscall-getcpu.S | 25 +++++++++++++++++++++++++
arch/i386/kernel/vsyscall-int80.S | 2 ++
arch/i386/kernel/vsyscall-sysenter.S | 2 ++
arch/i386/kernel/vsyscall.lds.S | 1 +
6 files changed, 40 insertions(+), 1 deletion(-)
--- 2.6.17-32.orig/arch/i386/kernel/cpu/common.c
+++ 2.6.17-32/arch/i386/kernel/cpu/common.c
@@ -642,6 +642,9 @@ void __cpuinit cpu_init(void)
((((__u64)stk16_off) << 32) & 0xff00000000000000ULL) |
(CPU_16BIT_STACK_SIZE - 1);
+ /* Set up GDT entry for per-cpu data */
+ *(__u64 *)(&gdt[27]) |= cpu;
+
cpu_gdt_descr->size = GDT_SIZE - 1;
cpu_gdt_descr->address = (unsigned long)gdt;
--- 2.6.17-32.orig/arch/i386/kernel/head.S
+++ 2.6.17-32/arch/i386/kernel/head.S
@@ -525,7 +525,13 @@ ENTRY(cpu_gdt_table)
.quad 0x004092000000ffff /* 0xc8 APM DS data */
.quad 0x0000920000000000 /* 0xd0 - ESPFIX 16-bit SS */
- .quad 0x0000000000000000 /* 0xd8 - unused */
+
+ /*
+ * Use a GDT entry to store per-cpu data for user space (DPL 3.)
+ * 32-bit data segment, byte granularity, base 0, limit set at runtime.
+ */
+ .quad 0x0040f20000000000 /* 0xd8 - for per-cpu user data */
+
.quad 0x0000000000000000 /* 0xe0 - unused */
.quad 0x0000000000000000 /* 0xe8 - unused */
.quad 0x0000000000000000 /* 0xf0 - unused */
--- /dev/null
+++ 2.6.17-32/arch/i386/kernel/vsyscall-getcpu.S
@@ -0,0 +1,25 @@
+/*
+ * vgetcpu
+ * This file is #include'd by vsyscall-*.S to define them after the
+ * vsyscall entry point. The kernel assumes that the addresses of these
+ * routines are constant for all vsyscall implementations.
+ */
+
+#include <linux/errno.h>
+
+ .text
+ .org __kernel_rt_sigreturn+32,0x90
+ .globl __vgetcpu
+ .type __vgetcpu,@function
+__vgetcpu:
+.LSTART_vgetcpu:
+ movl $-EFAULT,%eax
+ movl $((27<<3)|3),%edx
+ lsll %edx,%eax
+ jnz 1f
+ andl $0xff,%eax
+1:
+ ret
+.LEND_vgetcpu:
+ .size __vgetcpu,.-.LSTART_vgetcpu
+
--- 2.6.17-32.orig/arch/i386/kernel/vsyscall-int80.S
+++ 2.6.17-32/arch/i386/kernel/vsyscall-int80.S
@@ -51,3 +51,5 @@ __kernel_vsyscall:
* Get the common code for the sigreturn entry points.
*/
#include "vsyscall-sigreturn.S"
+
+#include "vsyscall-getcpu.S"
--- 2.6.17-32.orig/arch/i386/kernel/vsyscall-sysenter.S
+++ 2.6.17-32/arch/i386/kernel/vsyscall-sysenter.S
@@ -120,3 +120,5 @@ SYSENTER_RETURN:
* Get the common code for the sigreturn entry points.
*/
#include "vsyscall-sigreturn.S"
+
+#include "vsyscall-getcpu.S"
--- 2.6.17-32.orig/arch/i386/kernel/vsyscall.lds.S
+++ 2.6.17-32/arch/i386/kernel/vsyscall.lds.S
@@ -57,6 +57,7 @@ VERSION
__kernel_vsyscall;
__kernel_sigreturn;
__kernel_rt_sigreturn;
+ __vgetcpu;
local: *;
};
--
Chuck
"You can't read a newspaper if you can't read." --George W. Bush
next reply other threads:[~2006-06-21 7:32 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-21 7:27 Chuck Ebbert [this message]
2006-06-21 8:15 ` Ingo Molnar
2006-06-21 17:38 ` Artur Skawina
2006-06-28 5:44 ` Paul Jackson
2006-06-28 8:53 ` Andi Kleen
2006-06-28 9:00 ` Ingo Molnar
2006-06-29 8:47 ` Paul Jackson
2006-06-21 9:26 ` Andi Kleen
2006-06-21 9:35 ` Ingo Molnar
2006-06-21 21:54 ` Rohit Seth
2006-06-21 22:21 ` Andi Kleen
2006-06-21 22:59 ` Rohit Seth
2006-06-21 23:05 ` Andi Kleen
2006-06-21 23:18 ` Rohit Seth
2006-06-21 23:29 ` Andi Kleen
2006-06-22 0:55 ` Rohit Seth
2006-06-22 8:08 ` Andi Kleen
2006-06-22 21:06 ` Rohit Seth
2006-06-22 22:14 ` Andi Kleen
2006-06-22 23:10 ` Rohit Seth
2006-06-23 12:42 ` [discuss] " Andi Kleen
2006-06-24 2:06 ` Rohit Seth
2006-06-24 8:42 ` Andi Kleen
2006-06-27 1:13 ` Rohit Seth
2006-06-21 12:24 Chuck Ebbert
2006-06-21 17:14 ` Andi Kleen
2006-06-21 17:27 ` Linus Torvalds
2006-06-21 17:50 ` Andi Kleen
2006-06-22 12:23 Chuck Ebbert
2006-06-22 12:44 ` Andi Kleen
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=200606210329_MC3-1-C305-E008@compuserve.com \
--to=76306.1226@compuserve.com \
--cc=ak@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=torvalds@osdl.org \
/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