提交 34596dc9 编写于 作者: A Andi Kleen 提交者: Andi Kleen

[PATCH] Define vsyscall cache as blob to make clearer that user space shouldn't use it

Signed-off-by: NAndi Kleen <ak@suse.de>
上级 120b1142
...@@ -155,8 +155,8 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache) ...@@ -155,8 +155,8 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
We do this here because otherwise user space would do it on We do this here because otherwise user space would do it on
its own in a likely inferior way (no access to jiffies). its own in a likely inferior way (no access to jiffies).
If you don't like it pass NULL. */ If you don't like it pass NULL. */
if (tcache && tcache->t0 == (j = __jiffies)) { if (tcache && tcache->blob[0] == (j = __jiffies)) {
p = tcache->t1; p = tcache->blob[1];
} else if (__vgetcpu_mode == VGETCPU_RDTSCP) { } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
/* Load per CPU data from RDTSCP */ /* Load per CPU data from RDTSCP */
rdtscp(dummy, dummy, p); rdtscp(dummy, dummy, p);
...@@ -165,8 +165,8 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache) ...@@ -165,8 +165,8 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG)); asm("lsl %1,%0" : "=r" (p) : "r" (__PER_CPU_SEG));
} }
if (tcache) { if (tcache) {
tcache->t0 = j; tcache->blob[0] = j;
tcache->t1 = p; tcache->blob[1] = p;
} }
if (cpu) if (cpu)
*cpu = p & 0xfff; *cpu = p & 0xfff;
......
#ifndef _LINUX_GETCPU_H #ifndef _LINUX_GETCPU_H
#define _LINUX_GETCPU_H 1 #define _LINUX_GETCPU_H 1
/* Cache for getcpu() to speed it up. Results might be upto a jiffie /* Cache for getcpu() to speed it up. Results might be a short time
out of date, but will be faster. out of date, but will be faster.
User programs should not refer to the contents of this structure. User programs should not refer to the contents of this structure.
It is only a cache for vgetcpu(). It might change in future kernels. I repeat they should not refer to it. If they do they will break
in future kernels.
It is only a private cache for vgetcpu(). It will change in future kernels.
The user program must store this information per thread (__thread) The user program must store this information per thread (__thread)
If you want 100% accurate information pass NULL instead. */ If you want 100% accurate information pass NULL instead. */
struct getcpu_cache { struct getcpu_cache {
unsigned long t0; unsigned long blob[128 / sizeof(long)];
unsigned long t1;
unsigned long res[4];
}; };
#endif #endif
...@@ -2083,12 +2083,12 @@ asmlinkage long sys_getcpu(unsigned __user *cpup, unsigned __user *nodep, ...@@ -2083,12 +2083,12 @@ asmlinkage long sys_getcpu(unsigned __user *cpup, unsigned __user *nodep,
* padding * padding
*/ */
unsigned long t0, t1; unsigned long t0, t1;
get_user(t0, &cache->t0); get_user(t0, &cache->blob[0]);
get_user(t1, &cache->t1); get_user(t1, &cache->blob[1]);
t0++; t0++;
t1++; t1++;
put_user(t0, &cache->t0); put_user(t0, &cache->blob[0]);
put_user(t1, &cache->t1); put_user(t1, &cache->blob[1]);
} }
return err ? -EFAULT : 0; return err ? -EFAULT : 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册