From patchwork Sat Mar 11 19:46:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 9619007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D36DD604D9 for ; Sat, 11 Mar 2017 19:47:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C10FE28733 for ; Sat, 11 Mar 2017 19:47:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5ACE28734; Sat, 11 Mar 2017 19:47:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C37FF28735 for ; Sat, 11 Mar 2017 19:47:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933767AbdCKTrj (ORCPT ); Sat, 11 Mar 2017 14:47:39 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36109 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755426AbdCKTrN (ORCPT ); Sat, 11 Mar 2017 14:47:13 -0500 Received: by mail-pg0-f67.google.com with SMTP id 25so13886055pgy.3 for ; Sat, 11 Mar 2017 11:47:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mC3dIjVFvEGtNkf25GdA3O4LMaAIvrFbctqVBv8EgrM=; b=h51H4jbv31+3tZaue5c3ugOrgkLn2tqt0qEfd0W/sCZvvLI/CR1Gwgz8B7M0Gbv6mw EKWkoX7xL8i6/kFa6GnSgZj0Vhy4Tefe/x+7huWjwm3vux+1ci9rwdhg8hhIK/PiJehn IMK0+LQlFIRluvJ8RhefH+wKy1/dFsOUkyhx+RoJlASyRTfDDhhh3CHllJPKbvAVzI9J WYg7FP5W9URKMpdD71mg8ScMeuEszBxDtgt2KiRIpK36odFevdO+sfrQ+f/ItLzzF/1t o5/ogpTPZNVdLFj+jbA3IrIqMlEdcu71kh3NOChlFS4/4eYcTz2dw5ZwukZ5JvVPGI+6 nLxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mC3dIjVFvEGtNkf25GdA3O4LMaAIvrFbctqVBv8EgrM=; b=cWlRQxXCbJBaKDMqT7KQeWG0llmpbOEbn9/mCPbjkUR4YvZ5GuSSo0D9OL9lECaBjP CEE9FW6TqfntABRmGZwv7xJdbGn+b3Rp9rs0mYg1ipE7ttMUfFY+ydchpjE+3c3PoC1F PLwQOJQfkl3mj5RNtS2skzVq5jvya6FigGuOJMkOfANYw8vltQ+lRjeiyYUrwnvgwKC2 rShIUmyqrKXaielbluGJcZYNwxvmPhOv/oAjg5WtrgrNVuEuIzmC71nCw2Gd/BaJz4we 7HVGrL2HX3sKBikMygaE8fwhLBcHq8sYUhAWLljZs+TSXBPeUM170h+h37vM5AKsBu7B 0WDA== X-Gm-Message-State: AMke39nWqbIJBcy0jXiYdycc9G3/qOwcz6zAu5mdCAV4Qf7thxZjsACiiJKFQTDjTqq9jg== X-Received: by 10.99.181.86 with SMTP id u22mr27607095pgo.120.1489261632370; Sat, 11 Mar 2017 11:47:12 -0800 (PST) Received: from minbar.home.kylehuey.com (c-50-150-100-179.hsd1.ca.comcast.net. [50.150.100.179]) by smtp.gmail.com with ESMTPSA id t67sm25421584pfd.76.2017.03.11.11.47.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Mar 2017 11:47:11 -0800 (PST) From: Kyle Huey X-Google-Original-From: Kyle Huey To: Robert O'Callahan , Thomas Gleixner , Andy Lutomirski , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Jeff Dike , Richard Weinberger , Alexander Viro , Shuah Khan , Dave Hansen , Borislav Petkov , Peter Zijlstra , Boris Ostrovsky , Len Brown , Dmitry Safonov , "Rafael J. Wysocki" , David Matlack , Nadav Amit , Andi Kleen Cc: linux-kernel@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, user-mode-linux-user@lists.sourceforge.net, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH v15 2/9] x86/arch_prctl/64: Rename do_arch_prctl to do_arch_prctl_64 Date: Sat, 11 Mar 2017 11:46:55 -0800 Message-Id: <20170311194702.28754-3-khuey@kylehuey.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170311194702.28754-1-khuey@kylehuey.com> References: <20170311194702.28754-1-khuey@kylehuey.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to introduce new arch_prctls that are not 64 bit only, rename the existing 64 bit implementation to do_arch_prctl_64(). Also rename the second argument to arch_prctl(), which will no longer always be an address. Signed-off-by: Kyle Huey Reviewed-by: Andy Lutomirski --- arch/um/include/shared/os.h | 2 +- arch/x86/include/asm/proto.h | 3 +-- arch/x86/kernel/process_64.c | 32 +++++++++++++++++--------------- arch/x86/kernel/ptrace.c | 8 ++++---- arch/x86/um/os-Linux/prctl.c | 4 ++-- arch/x86/um/syscalls_64.c | 12 ++++++------ 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index de5d572225f3..2b47e0e8d414 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -298,17 +298,17 @@ extern void os_set_ioignore(void); /* sigio.c */ extern int add_sigio_fd(int fd); extern int ignore_sigio_fd(int fd); extern void maybe_sigio_broken(int fd, int read); extern void sigio_broken(int fd, int read); /* sys-x86_64/prctl.c */ -extern int os_arch_prctl(int pid, int code, unsigned long *addr); +extern int os_arch_prctl(int pid, int code, unsigned long *arg2); /* tty.c */ extern int get_pty(void); /* sys-$ARCH/task_size.c */ extern unsigned long os_get_top_address(void); long syscall(long number, ...); diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h index 9b9b30b19441..f8e9194e100c 100644 --- a/arch/x86/include/asm/proto.h +++ b/arch/x86/include/asm/proto.h @@ -4,16 +4,17 @@ #include /* misc architecture specific prototypes */ void syscall_init(void); #ifdef CONFIG_X86_64 void entry_SYSCALL_64(void); +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long arg2); #endif #ifdef CONFIG_X86_32 void entry_INT80_32(void); void entry_SYSENTER_32(void); void __begin_SYSENTER_singlestep_region(void); void __end_SYSENTER_singlestep_region(void); #endif @@ -25,11 +26,9 @@ void entry_SYSCALL_compat(void); void entry_INT80_compat(void); #endif void x86_configure_nx(void); void x86_report_nx(void); extern int reboot_force; -long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); - #endif /* _ASM_X86_PROTO_H */ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 9a72612b25ee..4c139922c2fb 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -200,17 +200,17 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, */ if (clone_flags & CLONE_SETTLS) { #ifdef CONFIG_IA32_EMULATION if (in_ia32_syscall()) err = do_set_thread_area(p, -1, (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; } err = 0; out: if (err && p->thread.io_bitmap_ptr) { kfree(p->thread.io_bitmap_ptr); p->thread.io_bitmap_max = 0; @@ -543,91 +543,93 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) ret = map_vdso_once(image, addr); if (ret) return ret; return (long)image->size; } #endif -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; int cpu; 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; } #ifdef CONFIG_CHECKPOINT_RESTORE # ifdef CONFIG_X86_X32_ABI case ARCH_MAP_VDSO_X32: - return prctl_map_vdso(&vdso_image_x32, addr); + return prctl_map_vdso(&vdso_image_x32, arg2); # endif # if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION case ARCH_MAP_VDSO_32: - return prctl_map_vdso(&vdso_image_32, addr); + return prctl_map_vdso(&vdso_image_32, arg2); # endif case ARCH_MAP_VDSO_64: - return prctl_map_vdso(&vdso_image_64, addr); + return prctl_map_vdso(&vdso_image_64, arg2); #endif default: ret = -EINVAL; break; } return ret; } -SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, addr) +SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, arg2) { - return do_arch_prctl(current, code, addr); + return do_arch_prctl_64(current, code, arg2); } unsigned long KSTK_ESP(struct task_struct *task) { return task_pt_regs(task)->sp; } diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 2364b23ea3e5..f37d18124648 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -391,31 +391,31 @@ static int putreg(struct task_struct *child, case offsetof(struct user_regs_struct, flags): return set_flags(child, value); #ifdef CONFIG_X86_64 case offsetof(struct user_regs_struct,fs_base): 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): /* * Exactly the same here as the %fs handling above. */ 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 } *pt_regs_access(task_pt_regs(child), offset) = value; return 0; } @@ -864,17 +864,17 @@ long arch_ptrace(struct task_struct *child, long request, break; #endif #ifdef CONFIG_X86_64 /* normal 64bit interface to access TLS data. 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 default: ret = ptrace_request(child, request, addr, data); break; } diff --git a/arch/x86/um/os-Linux/prctl.c b/arch/x86/um/os-Linux/prctl.c index 96eb2bd28832..efc9d7484e72 100644 --- a/arch/x86/um/os-Linux/prctl.c +++ b/arch/x86/um/os-Linux/prctl.c @@ -1,12 +1,12 @@ /* * Copyright (C) 2007 Jeff Dike (jdike@{addtoit.com,linux.intel.com}) * Licensed under the GPL */ #include #include -int os_arch_prctl(int pid, int code, unsigned long *addr) +int os_arch_prctl(int pid, int code, unsigned long *arg2) { - return ptrace(PTRACE_ARCH_PRCTL, pid, (unsigned long) addr, code); + return ptrace(PTRACE_ARCH_PRCTL, pid, (unsigned long) arg2, code); } diff --git a/arch/x86/um/syscalls_64.c b/arch/x86/um/syscalls_64.c index 2041acd77e73..f73ec5c35eb0 100644 --- a/arch/x86/um/syscalls_64.c +++ b/arch/x86/um/syscalls_64.c @@ -7,19 +7,19 @@ #include #include #include #include #include /* XXX This should get the constants from libc */ #include -long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr) +long arch_prctl(struct task_struct *task, int code, unsigned long __user *arg2) { - unsigned long *ptr = addr, tmp; + unsigned long *ptr = arg2, tmp; long ret; int pid = task->mm->context.id.u.pid; /* * With ARCH_SET_FS (and ARCH_SET_GS is treated similarly to * be safe), we need to call arch_prctl on the host because * setting %fs may result in something else happening (like a * GDT or thread.fs being set instead). So, we let the host @@ -59,29 +59,29 @@ long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr) case ARCH_SET_FS: current->thread.arch.fs = (unsigned long) ptr; ret = save_registers(pid, ¤t->thread.regs.regs); break; case ARCH_SET_GS: ret = save_registers(pid, ¤t->thread.regs.regs); break; case ARCH_GET_FS: - ret = put_user(tmp, addr); + ret = put_user(tmp, arg2); break; case ARCH_GET_GS: - ret = put_user(tmp, addr); + ret = put_user(tmp, arg2); break; } return ret; } -SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, addr) +SYSCALL_DEFINE2(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) { if ((to->thread.arch.fs == 0) || (to->mm == NULL)) return; arch_prctl(to, ARCH_SET_FS, (void __user *) to->thread.arch.fs);