Commit 736706be authored by Linus Torvalds's avatar Linus Torvalds

get rid of legacy 'get_ds()' function

Every in-kernel use of this function defined it to KERNEL_DS (either as
an actual define, or as an inline function).  It's an entirely
historical artifact, and long long long ago used to actually read the
segment selector valueof '%ds' on x86.

Which in the kernel is always KERNEL_DS.

Inspired by a patch from Jann Horn that just did this for a very small
subset of users (the ones in fs/), along with Al who suggested a script.
I then just took it to the logical extreme and removed all the remaining
gunk.

Roughly scripted with

   git grep -l '(get_ds())' -- :^tools/ | xargs sed -i 's/(get_ds())/(KERNEL_DS)/'
   git grep -lw 'get_ds' -- :^tools/ | xargs sed -i '/^#define get_ds()/d'

plus manual fixups to remove a few unusual usage patterns, the couple of
inline function cases and to fix up a comment that had become stale.

The 'get_ds()' function remains in an x86 kvm selftest, since in user
space it actually does something relevant.
Inspired-by: default avatarJann Horn <jannh@google.com>
Inspired-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 84c4e1f8
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#define USER_DS ((mm_segment_t) { -0x40000000000UL }) #define USER_DS ((mm_segment_t) { -0x40000000000UL })
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define get_ds() (KERNEL_DS)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
#define segment_eq(a, b) ((a).seg == (b).seg) #define segment_eq(a, b) ((a).seg == (b).seg)
......
...@@ -59,7 +59,6 @@ extern int __put_user_bad(void); ...@@ -59,7 +59,6 @@ extern int __put_user_bad(void);
* Note that this is actually 0x1,0000,0000 * Note that this is actually 0x1,0000,0000
*/ */
#define KERNEL_DS 0x00000000 #define KERNEL_DS 0x00000000
#define get_ds() (KERNEL_DS)
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
......
...@@ -150,7 +150,7 @@ void __show_regs(struct pt_regs *regs) ...@@ -150,7 +150,7 @@ void __show_regs(struct pt_regs *regs)
if ((domain & domain_mask(DOMAIN_USER)) == if ((domain & domain_mask(DOMAIN_USER)) ==
domain_val(DOMAIN_USER, DOMAIN_NOACCESS)) domain_val(DOMAIN_USER, DOMAIN_NOACCESS))
segment = "none"; segment = "none";
else if (fs == get_ds()) else if (fs == KERNEL_DS)
segment = "kernel"; segment = "kernel";
else else
segment = "user"; segment = "user";
......
...@@ -113,8 +113,7 @@ ENTRY(privcmd_call) ...@@ -113,8 +113,7 @@ ENTRY(privcmd_call)
/* /*
* Disable userspace access from kernel. This is fine to do it * Disable userspace access from kernel. This is fine to do it
* unconditionally as no set_fs(KERNEL_DS)/set_fs(get_ds()) is * unconditionally as no set_fs(KERNEL_DS) is called before.
* called before.
*/ */
uaccess_disable r4 uaccess_disable r4
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <asm/memory.h> #include <asm/memory.h>
#include <asm/extable.h> #include <asm/extable.h>
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
static inline void set_fs(mm_segment_t fs) static inline void set_fs(mm_segment_t fs)
......
...@@ -9,7 +9,6 @@ typedef struct { ...@@ -9,7 +9,6 @@ typedef struct {
} mm_segment_t; } mm_segment_t;
#define KERNEL_DS ((mm_segment_t) { 0xFFFFFFFF }) #define KERNEL_DS ((mm_segment_t) { 0xFFFFFFFF })
#define get_ds() KERNEL_DS
#define USER_DS ((mm_segment_t) { 0x80000000UL }) #define USER_DS ((mm_segment_t) { 0x80000000UL })
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
......
...@@ -33,12 +33,6 @@ static inline mm_segment_t get_fs(void) ...@@ -33,12 +33,6 @@ static inline mm_segment_t get_fs(void)
return USER_DS; return USER_DS;
} }
static inline mm_segment_t get_ds(void)
{
/* return the supervisor data space code */
return KERNEL_DS;
}
#define segment_eq(a, b) ((a).seg == (b).seg) #define segment_eq(a, b) ((a).seg == (b).seg)
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
......
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
#define KERNEL_DS ((mm_segment_t) { ~0UL }) /* cf. access_ok() */ #define KERNEL_DS ((mm_segment_t) { ~0UL }) /* cf. access_ok() */
#define USER_DS ((mm_segment_t) { TASK_SIZE-1 }) /* cf. access_ok() */ #define USER_DS ((mm_segment_t) { TASK_SIZE-1 }) /* cf. access_ok() */
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
......
...@@ -45,16 +45,9 @@ static inline void set_fs(mm_segment_t val) ...@@ -45,16 +45,9 @@ static inline void set_fs(mm_segment_t val)
: /* no outputs */ : "r" (val.seg) : "memory"); : /* no outputs */ : "r" (val.seg) : "memory");
} }
static inline mm_segment_t get_ds(void)
{
/* return the supervisor data space code */
return KERNEL_DS;
}
#else #else
#define USER_DS MAKE_MM_SEG(TASK_SIZE) #define USER_DS MAKE_MM_SEG(TASK_SIZE)
#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
#endif #endif
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
# define USER_DS MAKE_MM_SEG(TASK_SIZE - 1) # define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
# endif # endif
# define get_ds() (KERNEL_DS)
# define get_fs() (current_thread_info()->addr_limit) # define get_fs() (current_thread_info()->addr_limit)
# define set_fs(val) (current_thread_info()->addr_limit = (val)) # define set_fs(val) (current_thread_info()->addr_limit = (val))
......
...@@ -69,7 +69,6 @@ extern u64 __ua_limit; ...@@ -69,7 +69,6 @@ extern u64 __ua_limit;
#define USER_DS ((mm_segment_t) { __UA_LIMIT }) #define USER_DS ((mm_segment_t) { __UA_LIMIT })
#endif #endif
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
......
...@@ -86,7 +86,7 @@ static int ftrace_modify_code(unsigned long ip, unsigned int new_code) ...@@ -86,7 +86,7 @@ static int ftrace_modify_code(unsigned long ip, unsigned int new_code)
return -EFAULT; return -EFAULT;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
flush_icache_range(ip, ip + 8); flush_icache_range(ip, ip + 8);
set_fs(old_fs); set_fs(old_fs);
...@@ -111,7 +111,7 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1, ...@@ -111,7 +111,7 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
ip -= 4; ip -= 4;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
flush_icache_range(ip, ip + 8); flush_icache_range(ip, ip + 8);
set_fs(old_fs); set_fs(old_fs);
...@@ -135,7 +135,7 @@ static int ftrace_modify_code_2r(unsigned long ip, unsigned int new_code1, ...@@ -135,7 +135,7 @@ static int ftrace_modify_code_2r(unsigned long ip, unsigned int new_code1,
return -EFAULT; return -EFAULT;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
flush_icache_range(ip, ip + 8); flush_icache_range(ip, ip + 8);
set_fs(old_fs); set_fs(old_fs);
......
...@@ -212,7 +212,7 @@ void kgdb_call_nmi_hook(void *ignored) ...@@ -212,7 +212,7 @@ void kgdb_call_nmi_hook(void *ignored)
mm_segment_t old_fs; mm_segment_t old_fs;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
kgdb_nmicallback(raw_smp_processor_id(), NULL); kgdb_nmicallback(raw_smp_processor_id(), NULL);
...@@ -318,7 +318,7 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd, ...@@ -318,7 +318,7 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
/* Kernel mode. Set correct address limit */ /* Kernel mode. Set correct address limit */
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
if (atomic_read(&kgdb_active) != -1) if (atomic_read(&kgdb_active) != -1)
kgdb_nmicallback(smp_processor_id(), regs); kgdb_nmicallback(smp_processor_id(), regs);
......
...@@ -1077,7 +1077,7 @@ asmlinkage void do_tr(struct pt_regs *regs) ...@@ -1077,7 +1077,7 @@ asmlinkage void do_tr(struct pt_regs *regs)
seg = get_fs(); seg = get_fs();
if (!user_mode(regs)) if (!user_mode(regs))
set_fs(get_ds()); set_fs(KERNEL_DS);
prev_state = exception_enter(); prev_state = exception_enter();
current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f; current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
......
...@@ -37,7 +37,6 @@ extern int fixup_exception(struct pt_regs *regs); ...@@ -37,7 +37,6 @@ extern int fixup_exception(struct pt_regs *regs);
#define KERNEL_DS ((mm_segment_t) { ~0UL }) #define KERNEL_DS ((mm_segment_t) { ~0UL })
#define USER_DS ((mm_segment_t) {TASK_SIZE - 1}) #define USER_DS ((mm_segment_t) {TASK_SIZE - 1})
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define user_addr_max get_fs #define user_addr_max get_fs
......
...@@ -121,7 +121,7 @@ void show_regs(struct pt_regs *regs) ...@@ -121,7 +121,7 @@ void show_regs(struct pt_regs *regs)
regs->uregs[3], regs->uregs[2], regs->uregs[1], regs->uregs[0]); regs->uregs[3], regs->uregs[2], regs->uregs[1], regs->uregs[0]);
pr_info(" IRQs o%s Segment %s\n", pr_info(" IRQs o%s Segment %s\n",
interrupts_enabled(regs) ? "n" : "ff", interrupts_enabled(regs) ? "n" : "ff",
segment_eq(get_fs(), get_ds())? "kernel" : "user"); segment_eq(get_fs(), KERNEL_DS)? "kernel" : "user");
} }
EXPORT_SYMBOL(show_regs); EXPORT_SYMBOL(show_regs);
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#define USER_DS MAKE_MM_SEG(0x80000000UL) #define USER_DS MAKE_MM_SEG(0x80000000UL)
#define KERNEL_DS MAKE_MM_SEG(0) #define KERNEL_DS MAKE_MM_SEG(0)
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(seg) (current_thread_info()->addr_limit = (seg)) #define set_fs(seg) (current_thread_info()->addr_limit = (seg))
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
*/ */
#define KERNEL_DS (~0UL) #define KERNEL_DS (~0UL)
#define get_ds() (KERNEL_DS)
#define USER_DS (TASK_SIZE) #define USER_DS (TASK_SIZE)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define segment_eq(a, b) ((a).seg == (b).seg) #define segment_eq(a, b) ((a).seg == (b).seg)
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#define USER_DS MAKE_MM_SEG(TASK_SIZE - 1) #define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
#endif #endif
#define get_ds() (KERNEL_DS)
#define get_fs() (current->thread.addr_limit) #define get_fs() (current->thread.addr_limit)
static inline void set_fs(mm_segment_t fs) static inline void set_fs(mm_segment_t fs)
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#define KERNEL_DS (~0UL) #define KERNEL_DS (~0UL)
#define USER_DS (TASK_SIZE) #define USER_DS (TASK_SIZE)
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
static inline void set_fs(mm_segment_t fs) static inline void set_fs(mm_segment_t fs)
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#define USER_DS (2) #define USER_DS (2)
#define USER_DS_SACF (3) #define USER_DS_SACF (3)
#define get_ds() (KERNEL_DS)
#define get_fs() (current->thread.mm_segment) #define get_fs() (current->thread.mm_segment)
#define segment_eq(a,b) (((a) & 2) == ((b) & 2)) #define segment_eq(a,b) (((a) & 2) == ((b) & 2))
......
...@@ -26,7 +26,6 @@ typedef struct { ...@@ -26,7 +26,6 @@ typedef struct {
#define segment_eq(a, b) ((a).seg == (b).seg) #define segment_eq(a, b) ((a).seg == (b).seg)
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#define KERNEL_DS ((mm_segment_t) { 0 }) #define KERNEL_DS ((mm_segment_t) { 0 })
#define USER_DS ((mm_segment_t) { -1 }) #define USER_DS ((mm_segment_t) { -1 })
#define get_ds() (KERNEL_DS)
#define get_fs() (current->thread.current_ds) #define get_fs() (current->thread.current_ds)
#define set_fs(val) ((current->thread.current_ds) = (val)) #define set_fs(val) ((current->thread.current_ds) = (val))
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#define USER_DS ((mm_segment_t) { ASI_AIUS }) /* har har har */ #define USER_DS ((mm_segment_t) { ASI_AIUS }) /* har har har */
#define get_fs() ((mm_segment_t){(current_thread_info()->current_ds)}) #define get_fs() ((mm_segment_t){(current_thread_info()->current_ds)})
#define get_ds() (KERNEL_DS)
#define segment_eq(a, b) ((a).seg == (b).seg) #define segment_eq(a, b) ((a).seg == (b).seg)
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#define KERNEL_DS MAKE_MM_SEG(-1UL) #define KERNEL_DS MAKE_MM_SEG(-1UL)
#define USER_DS MAKE_MM_SEG(TASK_SIZE_MAX) #define USER_DS MAKE_MM_SEG(TASK_SIZE_MAX)
#define get_ds() (KERNEL_DS)
#define get_fs() (current->thread.addr_limit) #define get_fs() (current->thread.addr_limit)
static inline void set_fs(mm_segment_t fs) static inline void set_fs(mm_segment_t fs)
{ {
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#define KERNEL_DS 0 #define KERNEL_DS 0
#define USER_DS 1 #define USER_DS 1
#define get_ds (KERNEL_DS)
/* /*
* get_fs reads current->thread.current_ds into a register. * get_fs reads current->thread.current_ds into a register.
* On Entry: * On Entry:
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#define KERNEL_DS ((mm_segment_t) { 0 }) #define KERNEL_DS ((mm_segment_t) { 0 })
#define USER_DS ((mm_segment_t) { 1 }) #define USER_DS ((mm_segment_t) { 1 })
#define get_ds() (KERNEL_DS)
#define get_fs() (current->thread.current_ds) #define get_fs() (current->thread.current_ds)
#define set_fs(val) (current->thread.current_ds = (val)) #define set_fs(val) (current->thread.current_ds = (val))
......
...@@ -137,7 +137,7 @@ static int isFileReadable(char *path) ...@@ -137,7 +137,7 @@ static int isFileReadable(char *path)
ret = PTR_ERR(fp); ret = PTR_ERR(fp);
} }
else { else {
oldfs = get_fs(); set_fs(get_ds()); oldfs = get_fs(); set_fs(KERNEL_DS);
if (1!=readFile(fp, &buf, 1)) if (1!=readFile(fp, &buf, 1))
ret = -EINVAL; ret = -EINVAL;
...@@ -165,7 +165,7 @@ static int retriveFromFile(char *path, u8 *buf, u32 sz) ...@@ -165,7 +165,7 @@ static int retriveFromFile(char *path, u8 *buf, u32 sz)
if (0 == (ret =openFile(&fp, path, O_RDONLY, 0))) { if (0 == (ret =openFile(&fp, path, O_RDONLY, 0))) {
DBG_871X("%s openFile path:%s fp =%p\n", __func__, path , fp); DBG_871X("%s openFile path:%s fp =%p\n", __func__, path , fp);
oldfs = get_fs(); set_fs(get_ds()); oldfs = get_fs(); set_fs(KERNEL_DS);
ret =readFile(fp, buf, sz); ret =readFile(fp, buf, sz);
set_fs(oldfs); set_fs(oldfs);
closeFile(fp); closeFile(fp);
......
...@@ -426,7 +426,7 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) ...@@ -426,7 +426,7 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
ssize_t result; ssize_t result;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
/* The cast to a user pointer is valid due to the set_fs() */ /* The cast to a user pointer is valid due to the set_fs() */
result = vfs_read(file, (void __user *)buf, count, pos); result = vfs_read(file, (void __user *)buf, count, pos);
set_fs(old_fs); set_fs(old_fs);
...@@ -499,7 +499,7 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t ...@@ -499,7 +499,7 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t
return -EINVAL; return -EINVAL;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
p = (__force const char __user *)buf; p = (__force const char __user *)buf;
if (count > MAX_RW_COUNT) if (count > MAX_RW_COUNT)
count = MAX_RW_COUNT; count = MAX_RW_COUNT;
...@@ -521,7 +521,7 @@ ssize_t kernel_write(struct file *file, const void *buf, size_t count, ...@@ -521,7 +521,7 @@ ssize_t kernel_write(struct file *file, const void *buf, size_t count,
ssize_t res; ssize_t res;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
/* The cast to a user pointer is valid due to the set_fs() */ /* The cast to a user pointer is valid due to the set_fs() */
res = vfs_write(file, (__force const char __user *)buf, count, pos); res = vfs_write(file, (__force const char __user *)buf, count, pos);
set_fs(old_fs); set_fs(old_fs);
......
...@@ -357,7 +357,7 @@ static ssize_t kernel_readv(struct file *file, const struct kvec *vec, ...@@ -357,7 +357,7 @@ static ssize_t kernel_readv(struct file *file, const struct kvec *vec,
ssize_t res; ssize_t res;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
/* The cast to a user pointer is valid due to the set_fs() */ /* The cast to a user pointer is valid due to the set_fs() */
res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos, 0); res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos, 0);
set_fs(old_fs); set_fs(old_fs);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#endif #endif
#ifndef get_fs #ifndef get_fs
#define get_ds() (KERNEL_DS)
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
static inline void set_fs(mm_segment_t fs) static inline void set_fs(mm_segment_t fs)
......
...@@ -200,7 +200,7 @@ int integrity_kernel_read(struct file *file, loff_t offset, ...@@ -200,7 +200,7 @@ int integrity_kernel_read(struct file *file, loff_t offset,
return -EBADF; return -EBADF;
old_fs = get_fs(); old_fs = get_fs();
set_fs(get_ds()); set_fs(KERNEL_DS);
ret = __vfs_read(file, buf, count, &offset); ret = __vfs_read(file, buf, count, &offset);
set_fs(old_fs); set_fs(old_fs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment