From patchwork Tue Nov 1 01:37:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 9406801 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 25C25601C0 for ; Tue, 1 Nov 2016 01:40:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14CC328D62 for ; Tue, 1 Nov 2016 01:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0922F29396; Tue, 1 Nov 2016 01:40:32 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 A066728D62 for ; Tue, 1 Nov 2016 01:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034467AbcKABic (ORCPT ); Mon, 31 Oct 2016 21:38:32 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34164 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161216AbcKABi3 (ORCPT ); Mon, 31 Oct 2016 21:38:29 -0400 Received: by mail-pf0-f196.google.com with SMTP id y68so4268854pfb.1 for ; Mon, 31 Oct 2016 18:38:29 -0700 (PDT) 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=G9jDeXp+dk9KGRM046EvcEGOTa253NouB3CNGMa4rV4=; b=j1ZPfeoKhPRjNcEGqYDPKEwWL5v7L0srQ1K1ttjScuTZUcNcRO2sEv9G9lPQXfN8xv vEMtYx6C4J65FYS3SqAEu/nL0vnHGrYaMv0iq2JjbS3K7+JUYUi4KCPeB/7gjDrVXkHm sQRYqdfFasmy44CMSzrKXDWJeUPOYH1Ml9yJIMQoghJYiUNxGBYixwcssYX1eMJN5PyR cD0jMfv7ZVXcWkpkUztOS0vEP5u9aEAlNLL5LdCuYVwQzUgf+PKb/uCYjOcPvDLupLHi 5cyYIe7d++GbE5aDFRAUIsPaeXm3Gzy7emexiuLP5Hm9/Rf8iZ0Bj9kAw2zgTTamwE+A lFsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G9jDeXp+dk9KGRM046EvcEGOTa253NouB3CNGMa4rV4=; b=Bno65hXpuIgNtjEK4iWcr2C0NY88gdUc/dlghI8IWYFlW6/GeABG/h+pszSbeFRVj5 XfnL8VBnyr3OiZ6AOw2wg0xHlbcwMgGgyYgVcrP5pazx5dF8zpRPGBeFCEbIHCBKQq3M 9jM0+XUfBUSYp3h4S6I3qcJpTYoDGSRLxuBpYGDMa6ZPiDg7TyZkXWsTO26Py51GlnLE 61AdEnE7ZtIcdgAHYE0r679b+UWImIGLE7+KcPd5X4VI1EjewbcIaOo2OBDl8quLAla9 c0pnfEzsTziWfUh44uSeSVOCnmdYnTbGRucEwN5Pew/gXoINA2w0+U9Dz1pSp8VOvBlr qcxQ== X-Gm-Message-State: ABUngvdpjXfdVj6QIC/5iK6BdzoXtuO2Qc/ns/fTf2qwphUD36B9Xz8A/gMacLYyW52CXQ== X-Received: by 10.98.74.142 with SMTP id c14mr17683231pfj.139.1477964308042; Mon, 31 Oct 2016 18:38:28 -0700 (PDT) Received: from minbar.hsd1.ca.comcast.net (c-73-162-102-141.hsd1.ca.comcast.net. [73.162.102.141]) by smtp.gmail.com with ESMTPSA id u17sm38188144pfi.1.2016.10.31.18.38.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Oct 2016 18:38:27 -0700 (PDT) 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 , "Rafael J. Wysocki" , Dmitry Safonov Cc: linux-kernel@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, user-mode-linux-user@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH v8 2/7] x86/arch_prctl/64: Rename do_arch_prctl to do_arch_prctl_64 Date: Mon, 31 Oct 2016 18:37:44 -0700 Message-Id: <20161101013749.4003-3-khuey@kylehuey.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161101013749.4003-1-khuey@kylehuey.com> References: <20161101013749.4003-1-khuey@kylehuey.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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/x86/include/asm/proto.h | 4 +++- arch/x86/kernel/process_64.c | 32 +++++++++++++++++--------------- arch/x86/kernel/ptrace.c | 8 ++++---- arch/x86/um/syscalls_64.c | 4 ++-- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h index 9b9b30b..95c3e51 100644 --- a/arch/x86/include/asm/proto.h +++ b/arch/x86/include/asm/proto.h @@ -25,11 +25,13 @@ 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); +#ifdef CONFIG_X86_64 +long do_arch_prctl_64(struct task_struct *task, int code, unsigned long arg2); +#endif #endif /* _ASM_X86_PROTO_H */ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 2718cf9..611df20 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -193,17 +193,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; @@ -534,91 +534,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 0e63c02..5004302 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -390,31 +390,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; } @@ -863,17 +863,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/syscalls_64.c b/arch/x86/um/syscalls_64.c index ab3f7f4..3362c4e 100644 --- a/arch/x86/um/syscalls_64.c +++ b/arch/x86/um/syscalls_64.c @@ -68,19 +68,19 @@ long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr) case ARCH_GET_GS: ret = put_user(tmp, addr); 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);