* [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32. [not found] <20160915233324.6060-1-khuey@kylehuey.com> @ 2016-09-15 23:33 ` Kyle Huey 2016-09-15 23:51 ` Andy Lutomirski 2016-09-16 7:50 ` Thomas Gleixner 0 siblings, 2 replies; 4+ messages in thread From: Kyle Huey @ 2016-09-15 23:33 UTC (permalink / raw) To: Robert O'Callahan Cc: linux-kernel, Dave Hansen, Andy Lutomirski, Dmitry Safonov, Borislav Petkov, linux-api, xen-devel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, Jeff Dike, Richard Weinberger, Al Viro, David Howells, Anna Schumaker, Andy Lutomirski, Zach Brown, Eric B Munson, Dmitry V. Levin, Peter Zijlstra, Paul Gortmaker, Jiri Slaby, Andrey Ryabinin, Michael S. Tsirkin, Borislav Petkov, Dmitry Vyukov, Jan Beulich, Mateusz Guzik, Chuck Ebbert, Oleg Nesterov, Dmitry Safonov, chengang@emindsoft.com.cn, Jeff Moyer, Andrew Morton, Jiri Kosina, Milosz Tanski, open list:USER-MODE LINUX, , open list:USER-MODE LINUX arch_prctl is currently 64-bit only. Wire it up for 32-bits, as a no-op for now. Rename the second arg to a more generic name. Signed-off-by: Kyle Huey <khuey@kylehuey.com> --- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/include/asm/proto.h | 5 ++++- arch/x86/kernel/process.c | 10 ++++++++++ arch/x86/kernel/process_64.c | 33 +++++++++++++++++++++------------ arch/x86/kernel/ptrace.c | 8 ++++---- arch/x86/um/Makefile | 2 +- arch/x86/um/syscalls_32.c | 7 +++++++ arch/x86/um/syscalls_64.c | 4 ++-- include/linux/compat.h | 2 ++ 9 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 arch/x86/um/syscalls_32.c diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index f848572..666fa61 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -386,3 +386,4 @@ 377 i386 copy_file_range sys_copy_file_range 378 i386 preadv2 sys_preadv2 compat_sys_preadv2 379 i386 pwritev2 sys_pwritev2 compat_sys_pwritev2 +380 i386 arch_prctl compat_sys_arch_prctl compat_sys_arch_prctl diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h index 9b9b30b..f0e86aa 100644 --- a/arch/x86/include/asm/proto.h +++ b/arch/x86/include/asm/proto.h @@ -30,6 +30,9 @@ void x86_report_nx(void); extern int reboot_force; -long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); +long do_arch_prctl_common(struct task_struct *task, int code, unsigned long addr); +#ifdef CONFIG_X86_64 +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long addr); +#endif #endif /* _ASM_X86_PROTO_H */ diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 62c0b0e..1421451 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -567,3 +567,13 @@ unsigned long get_wchan(struct task_struct *p) } while (count++ < 16 && p->state != TASK_RUNNING); return 0; } + +long do_arch_prctl_common(struct task_struct *task, int code, unsigned long arg2) +{ + return -EINVAL; +} + +asmlinkage long compat_sys_arch_prctl(int code, unsigned long arg2) +{ + return do_arch_prctl_common(current, code, arg2); +} diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 63236d8..0e44608 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -35,6 +35,7 @@ #include <linux/uaccess.h> #include <linux/io.h> #include <linux/ftrace.h> +#include <linux/syscalls.h> #include <asm/pgtable.h> #include <asm/processor.h> @@ -196,7 +197,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, (struct user_desc __user *)tls, 0); else #endif - err = do_arch_prctl(p, ARCH_SET_FS, tls); + err = do_arch_prctl_64(p, ARCH_SET_FS, tls); if (err) goto out; } @@ -524,7 +525,7 @@ void set_personality_ia32(bool x32) } EXPORT_SYMBOL_GPL(set_personality_ia32); -long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long arg2) { int ret = 0; int doit = task == current; @@ -532,48 +533,50 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) switch (code) { case ARCH_SET_GS: - if (addr >= TASK_SIZE_MAX) + if (arg2 >= TASK_SIZE_MAX) return -EPERM; cpu = get_cpu(); task->thread.gsindex = 0; - task->thread.gsbase = addr; + task->thread.gsbase = arg2; if (doit) { load_gs_index(0); - ret = wrmsrl_safe(MSR_KERNEL_GS_BASE, addr); + ret = wrmsrl_safe(MSR_KERNEL_GS_BASE, arg2); } put_cpu(); break; case ARCH_SET_FS: /* Not strictly needed for fs, but do it for symmetry with gs */ - if (addr >= TASK_SIZE_MAX) + if (arg2 >= TASK_SIZE_MAX) return -EPERM; cpu = get_cpu(); task->thread.fsindex = 0; - task->thread.fsbase = addr; + task->thread.fsbase = arg2; if (doit) { /* set the selector to 0 to not confuse __switch_to */ loadsegment(fs, 0); - ret = wrmsrl_safe(MSR_FS_BASE, addr); + ret = wrmsrl_safe(MSR_FS_BASE, arg2); } put_cpu(); break; case ARCH_GET_FS: { unsigned long base; + if (doit) rdmsrl(MSR_FS_BASE, base); else base = task->thread.fsbase; - ret = put_user(base, (unsigned long __user *)addr); + ret = put_user(base, (unsigned long __user *)arg2); break; } case ARCH_GET_GS: { unsigned long base; + if (doit) rdmsrl(MSR_KERNEL_GS_BASE, base); else base = task->thread.gsbase; - ret = put_user(base, (unsigned long __user *)addr); + ret = put_user(base, (unsigned long __user *)arg2); break; } @@ -585,9 +588,15 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) return ret; } -long sys_arch_prctl(int code, unsigned long addr) +SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, arg2) { - return do_arch_prctl(current, code, addr); + long ret; + + ret = do_arch_prctl_64(current, code, arg2); + if (ret == -EINVAL) + ret = do_arch_prctl_common(current, code, arg2); + + return ret; } unsigned long KSTK_ESP(struct task_struct *task) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index f79576a..030cbc5 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -395,12 +395,12 @@ static int putreg(struct task_struct *child, if (value >= TASK_SIZE_MAX) return -EIO; /* - * When changing the segment base, use do_arch_prctl + * When changing the segment base, use do_arch_prctl_64 * to set either thread.fs or thread.fsindex and the * corresponding GDT slot. */ if (child->thread.fsbase != value) - return do_arch_prctl(child, ARCH_SET_FS, value); + return do_arch_prctl_64(child, ARCH_SET_FS, value); return 0; case offsetof(struct user_regs_struct,gs_base): /* @@ -409,7 +409,7 @@ static int putreg(struct task_struct *child, if (value >= TASK_SIZE_MAX) return -EIO; if (child->thread.gsbase != value) - return do_arch_prctl(child, ARCH_SET_GS, value); + return do_arch_prctl_64(child, ARCH_SET_GS, value); return 0; #endif } @@ -868,7 +868,7 @@ long arch_ptrace(struct task_struct *child, long request, Works just like arch_prctl, except that the arguments are reversed. */ case PTRACE_ARCH_PRCTL: - ret = do_arch_prctl(child, data, addr); + ret = do_arch_prctl_64(child, data, addr); break; #endif diff --git a/arch/x86/um/Makefile b/arch/x86/um/Makefile index 3ee2bb6..5e039d6 100644 --- a/arch/x86/um/Makefile +++ b/arch/x86/um/Makefile @@ -16,7 +16,7 @@ obj-y = bug.o bugs_$(BITS).o delay.o fault.o ksyms.o ldt.o \ ifeq ($(CONFIG_X86_32),y) -obj-y += checksum_32.o +obj-y += checksum_32.o syscalls_32.o obj-$(CONFIG_ELF_CORE) += elfcore.o subarch-y = ../lib/string_32.o ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o diff --git a/arch/x86/um/syscalls_32.c b/arch/x86/um/syscalls_32.c new file mode 100644 index 0000000..c6812c1 --- /dev/null +++ b/arch/x86/um/syscalls_32.c @@ -0,0 +1,7 @@ +#include <linux/syscalls.h> +#include <os.h> + +long compat_sys_arch_prctl(int code, unsigned long arg2) +{ + return -EINVAL; +} diff --git a/arch/x86/um/syscalls_64.c b/arch/x86/um/syscalls_64.c index e655227..d0a7160 100644 --- a/arch/x86/um/syscalls_64.c +++ b/arch/x86/um/syscalls_64.c @@ -72,9 +72,9 @@ long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr) return ret; } -long sys_arch_prctl(int code, unsigned long addr) +long sys_arch_prctl(int code, unsigned long arg2) { - return arch_prctl(current, code, (unsigned long __user *) addr); + return arch_prctl(current, code, (unsigned long __user *) arg2); } void arch_switch_to(struct task_struct *to) diff --git a/include/linux/compat.h b/include/linux/compat.h index f964ef7..0039d53 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -722,6 +722,8 @@ asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid, asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32, int, const char __user *); +asmlinkage long compat_sys_arch_prctl(int, unsigned long); + /* * For most but not all architectures, "am I in a compat syscall?" and * "am I a compat task?" are the same question. For architectures on which -- 2.9.3 base-commit: 4cea8776571b18db7485930cb422faa739580c8c ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32. 2016-09-15 23:33 ` [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32 Kyle Huey @ 2016-09-15 23:51 ` Andy Lutomirski 2016-09-16 7:50 ` Thomas Gleixner 1 sibling, 0 replies; 4+ messages in thread From: Andy Lutomirski @ 2016-09-15 23:51 UTC (permalink / raw) To: Kyle Huey Cc: Robert O'Callahan, linux-kernel@vger.kernel.org, Dave Hansen, Dmitry Safonov, Borislav Petkov, Linux API, xen-devel@lists.xenproject.org, Thomas Gleixner, Ingo Molnar, H. Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Jeff Dike, Richard Weinberger, Al Viro, David Howells, Anna Schumaker, Andy Lutomirski, Zach Brown, Eric B Munson, Dmitry V. Levin, Peter Zijlstra, Paul Gortmaker, Jiri Slaby, Andrey Ryabinin, Michael S. Tsirkin, Borislav Petkov, Dmitry Vyukov, Jan Beulich, Mateusz Guzik, Chuck Ebbert, Oleg Nesterov, Dmitry Safonov, chengang@emindsoft.com.cn, Jeff Moyer, Andrew Morton, Jiri Kosina, Milosz Tanski, open list:USER-MODE LINUX (UML), open list:USER-MODE LINUX (UML) On Thu, Sep 15, 2016 at 4:33 PM, Kyle Huey <me@kylehuey.com> wrote: > arch_prctl is currently 64-bit only. Wire it up for 32-bits, as a no-op for > now. Rename the second arg to a more generic name. > > Signed-off-by: Kyle Huey <khuey@kylehuey.com> > --- > arch/x86/entry/syscalls/syscall_32.tbl | 1 + > arch/x86/include/asm/proto.h | 5 ++++- > arch/x86/kernel/process.c | 10 ++++++++++ > arch/x86/kernel/process_64.c | 33 +++++++++++++++++++++------------ > arch/x86/kernel/ptrace.c | 8 ++++---- > arch/x86/um/Makefile | 2 +- > arch/x86/um/syscalls_32.c | 7 +++++++ > arch/x86/um/syscalls_64.c | 4 ++-- > include/linux/compat.h | 2 ++ > 9 files changed, 52 insertions(+), 20 deletions(-) > create mode 100644 arch/x86/um/syscalls_32.c > > diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl > index f848572..666fa61 100644 > --- a/arch/x86/entry/syscalls/syscall_32.tbl > +++ b/arch/x86/entry/syscalls/syscall_32.tbl > @@ -386,3 +386,4 @@ > 377 i386 copy_file_range sys_copy_file_range > 378 i386 preadv2 sys_preadv2 compat_sys_preadv2 > 379 i386 pwritev2 sys_pwritev2 compat_sys_pwritev2 > +380 i386 arch_prctl compat_sys_arch_prctl compat_sys_arch_prctl Let's call this sys_arch_prctl_32, even if it's unconventional. See below. > diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h > index 9b9b30b..f0e86aa 100644 > --- a/arch/x86/include/asm/proto.h > +++ b/arch/x86/include/asm/proto.h > @@ -30,6 +30,9 @@ void x86_report_nx(void); > > extern int reboot_force; > > -long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); > +long do_arch_prctl_common(struct task_struct *task, int code, unsigned long addr); > +#ifdef CONFIG_X86_64 > +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long addr); > +#endif > > #endif /* _ASM_X86_PROTO_H */ > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > index 62c0b0e..1421451 100644 > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -567,3 +567,13 @@ unsigned long get_wchan(struct task_struct *p) > } while (count++ < 16 && p->state != TASK_RUNNING); > return 0; > } > + > +long do_arch_prctl_common(struct task_struct *task, int code, unsigned long arg2) > +{ > + return -EINVAL; > +} > + > +asmlinkage long compat_sys_arch_prctl(int code, unsigned long arg2) I believe you mean COMPAT_SYSCALL_DEFINE2 here. But I see what you're doing here. Could you instead do: #if defined(CONFIG_IA32_EMULATION) || defined(CONFIG_X86_32) #ifdef CONFIG_X86_32 COMPAT_SYSCALL_DEFINE2(...) #else SYSCALL_DEFINE2(...) #endif ... body here ... #endif and name the thing do_arch_prctl_32? It's too bad we don't have a SYSCALL_DEFINE_32 macro. But you could add one... > diff --git a/arch/x86/um/syscalls_32.c b/arch/x86/um/syscalls_32.c > new file mode 100644 > index 0000000..c6812c1 > --- /dev/null > +++ b/arch/x86/um/syscalls_32.c > @@ -0,0 +1,7 @@ > +#include <linux/syscalls.h> > +#include <os.h> > + > +long compat_sys_arch_prctl(int code, unsigned long arg2) COMPAT_SYSCALL_DEFINE2 Also, does this really need a new file? > -long sys_arch_prctl(int code, unsigned long addr) > +long sys_arch_prctl(int code, unsigned long arg2) SYSCALL_DEFINE2 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32. 2016-09-15 23:33 ` [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32 Kyle Huey 2016-09-15 23:51 ` Andy Lutomirski @ 2016-09-16 7:50 ` Thomas Gleixner 2016-09-16 15:56 ` Kyle Huey 1 sibling, 1 reply; 4+ messages in thread From: Thomas Gleixner @ 2016-09-16 7:50 UTC (permalink / raw) To: Kyle Huey Cc: Robert O'Callahan, linux-kernel, Dave Hansen, Andy Lutomirski, Dmitry Safonov, Borislav Petkov, linux-api, xen-devel, Ingo Molnar, H. Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Jeff Dike, Richard Weinberger, Al Viro, David Howells, Anna Schumaker, Andy Lutomirski, Zach Brown, Eric B Munson, Dmitry V. Levin, Peter Zijlstra, Paul Gortmaker, Jiri Slaby, Andrey Ryabinin, Michael S. Tsirkin, Borislav Petkov, Dmitry Vyukov, Jan Beulich, Mateusz Guzik, Chuck Ebbert, Oleg Nesterov, Dmitry Safonov, chengang@emindsoft.com.cn, Jeff Moyer, Andrew Morton, Jiri Kosina, Milosz Tanski, open list:USER-MODE LINUX (UML), open list:USER-MODE LINUX (UML) On Thu, 15 Sep 2016, Kyle Huey wrote: First of all, please add a cover letter [PATCH 0/N] to your patch series and send it with something which provides proper mail threading. See: git-send-email, quilt > arch_prctl is currently 64-bit only. Wire it up for 32-bits, as a no-op for > now. Rename the second arg to a more generic name. This changelog is useless. - it does not provide any rationale for this change, i.e. why this is required. Just because its 64bit only is not a reason. - "Rename the second arg to a more generic name" does not give any useful information. Misleading information is worse than no information. Further your patch does 5 things at once. It wants to be split into parts: 1) Rename do_arch_prctl() and change the argument name, > -long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) > +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long arg2) 2) Provide do_arch_prctl_common() and hook it up to the arch_prctl syscall > -long sys_arch_prctl(int code, unsigned long addr) > +SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, arg2) > { > - return do_arch_prctl(current, code, addr); > + long ret; > + > + ret = do_arch_prctl_64(current, code, arg2); > + if (ret == -EINVAL) > + ret = do_arch_prctl_common(current, code, arg2); > + > + return ret; > } 3) Implement the compat version Thanks, tflx ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32. 2016-09-16 7:50 ` Thomas Gleixner @ 2016-09-16 15:56 ` Kyle Huey 0 siblings, 0 replies; 4+ messages in thread From: Kyle Huey @ 2016-09-16 15:56 UTC (permalink / raw) To: Thomas Gleixner Cc: Robert O'Callahan, open list, Dave Hansen, Andy Lutomirski, Dmitry Safonov, Borislav Petkov, Linux API, moderated list:XEN HYPERVISOR INTERFACE, Ingo Molnar, H. Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Jeff Dike, Richard Weinberger, Al Viro, David Howells, Anna Schumaker, Andy Lutomirski, Zach Brown, Eric B Munson, Dmitry V. Levin, Peter Zijlstra, Paul Gortmaker, Jiri Slaby, Andrey Ryabinin, Michael S. Tsirkin, Borislav Petkov, Dmitry Vyukov, Jan Beulich, Mateusz Guzik, Chuck Ebbert, Oleg Nesterov, Dmitry Safonov, chengang@emindsoft.com.cn, Jeff Moyer, Andrew Morton, Jiri Kosina, Milosz Tanski, open list:USER-MODE LINUX (UML), open list:USER-MODE LINUX (UML) On Fri, Sep 16, 2016 at 12:50 AM, Thomas Gleixner <tglx@linutronix.de> wrote: > On Thu, 15 Sep 2016, Kyle Huey wrote: > > First of all, please add a cover letter [PATCH 0/N] to your patch series > and send it with something which provides proper mail threading. > See: git-send-email, quilt I did ... seems like using git-send-email with --cc-cmd=scripts/get_maintainer.pl is not a good idea since people get CCd to some parts of the thread and not others. https://lkml.org/lkml/2016/9/15/811 >> arch_prctl is currently 64-bit only. Wire it up for 32-bits, as a no-op for >> now. Rename the second arg to a more generic name. > > This changelog is useless. > > - it does not provide any rationale for this change, i.e. why this is > required. Just because its 64bit only is not a reason. > > - "Rename the second arg to a more generic name" does not give > any useful information. > > Misleading information is worse than no information. > > Further your patch does 5 things at once. It wants to be split into parts: > > 1) Rename do_arch_prctl() and change the argument name, > >> -long do_arch_prctl(struct task_struct *task, int code, unsigned long addr) >> +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long arg2) > > 2) Provide do_arch_prctl_common() and hook it up to the arch_prctl syscall > >> -long sys_arch_prctl(int code, unsigned long addr) >> +SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, arg2) >> { >> - return do_arch_prctl(current, code, addr); >> + long ret; >> + >> + ret = do_arch_prctl_64(current, code, arg2); >> + if (ret == -EINVAL) >> + ret = do_arch_prctl_common(current, code, arg2); >> + >> + return ret; >> } > > 3) Implement the compat version Ok. - Kyle ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-16 15:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20160915233324.6060-1-khuey@kylehuey.com>
2016-09-15 23:33 ` [PATCH v3 1/3] syscalls,x86 Expose arch_prctl on x86-32 Kyle Huey
2016-09-15 23:51 ` Andy Lutomirski
2016-09-16 7:50 ` Thomas Gleixner
2016-09-16 15:56 ` Kyle Huey
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).