From patchwork Fri Oct 31 11:42:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 39878 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 896E1202FE for ; Fri, 31 Oct 2014 11:42:54 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id n15sf3999525lbi.2 for ; Fri, 31 Oct 2014 04:42:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=cZejvu8Gr/Jn5M0PGgL575K5gCrF5h9QjADQ5uCD+j8=; b=X+C8h4zVD2wdplNCxAoLM2Jf2fFMTwwOdBcSVlQtEMLrov06QYnvQmPHnvV7k9lbNm Tl+emXdPiTQ3Lgj0GgEIBa0o1utyAwKpWnDe06HJh7MSrFwbSrRvCzu5BFgVYCv0yLb8 Vsg46qImHfI+2eSiKSdfejGi9kjuKJ65P+krDrU3ule2YPmkPyvQkstrVunTS6xq8MnC RtJLn3nWnhLGCUk32ZZM3gi/lztuG//IrZdx2VxCBsd2zs1gcPGn5aKDKEa3rOxNoDbO jpyw5qEOGdLLLUSKPUZYIVOqqb6ny/Iawd/GeSWJSNhMuLh/Rkaq+fWukuN4B3nsztip 9DBg== X-Gm-Message-State: ALoCoQn5espRIxLJktlsyOK5NZgfBpKnnBi7tqxbNn7ED8Tl2UkQLx3pVrDtLrDjJJJuMuwzSEXC X-Received: by 10.194.172.35 with SMTP id az3mr3960233wjc.0.1414755773348; Fri, 31 Oct 2014 04:42:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.6 with SMTP id r6ls303272lae.5.gmail; Fri, 31 Oct 2014 04:42:53 -0700 (PDT) X-Received: by 10.152.9.201 with SMTP id c9mr25319526lab.38.1414755773219; Fri, 31 Oct 2014 04:42:53 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id jl10si16220852lbc.96.2014.10.31.04.42.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 04:42:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so6486092lbj.23 for ; Fri, 31 Oct 2014 04:42:53 -0700 (PDT) X-Received: by 10.152.5.38 with SMTP id p6mr25364119lap.44.1414755773114; Fri, 31 Oct 2014 04:42:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp187205lbz; Fri, 31 Oct 2014 04:42:52 -0700 (PDT) X-Received: by 10.70.88.201 with SMTP id bi9mr23937051pdb.73.1414755767549; Fri, 31 Oct 2014 04:42:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gt4si4525832pac.206.2014.10.31.04.42.46 for ; Fri, 31 Oct 2014 04:42:47 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759148AbaJaLmp (ORCPT + 1 other); Fri, 31 Oct 2014 07:42:45 -0400 Received: from ip4-83-240-67-251.cust.nbox.cz ([83.240.67.251]:46831 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759081AbaJaLmo (ORCPT ); Fri, 31 Oct 2014 07:42:44 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.83) (envelope-from ) id 1XkAbG-0003XN-W2; Fri, 31 Oct 2014 12:42:38 +0100 From: Jiri Slaby To: stable@vger.kernel.org Cc: Pawel Moll , Peter Zijlstra , Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar , Jiri Slaby Subject: [patch added to the 3.12 stable tree] perf: Handle compat ioctl Date: Fri, 31 Oct 2014 12:42:36 +0100 Message-Id: <1414755758-13557-2-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1414755758-13557-1-git-send-email-jslaby@suse.cz> References: <1414755758-13557-1-git-send-email-jslaby@suse.cz> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Pawel Moll This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== commit b3f207855f57b9c8f43a547a801340bb5cbc59e5 upstream. When running a 32-bit userspace on a 64-bit kernel (eg. i386 application on x86_64 kernel or 32-bit arm userspace on arm64 kernel) some of the perf ioctls must be treated with special care, as they have a pointer size encoded in the command. For example, PERF_EVENT_IOC_ID in 32-bit world will be encoded as 0x80042407, but 64-bit kernel will expect 0x80082407. In result the ioctl will fail returning -ENOTTY. This patch solves the problem by adding code fixing up the size as compat_ioctl file operation. Reported-by: Drew Richardson Signed-off-by: Pawel Moll Signed-off-by: Peter Zijlstra Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Link: http://lkml.kernel.org/r/1402671812-9078-1-git-send-email-pawel.moll@arm.com Signed-off-by: Ingo Molnar Signed-off-by: Jiri Slaby --- kernel/events/core.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index cf2413f6ce7f..63bd27c861fe 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -39,6 +39,7 @@ #include #include #include +#include #include "internal.h" @@ -3630,6 +3631,26 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return 0; } +#ifdef CONFIG_COMPAT +static long perf_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + switch (_IOC_NR(cmd)) { + case _IOC_NR(PERF_EVENT_IOC_SET_FILTER): + case _IOC_NR(PERF_EVENT_IOC_ID): + /* Fix up pointer size (usually 4 -> 8 in 32-on-64-bit case */ + if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) { + cmd &= ~IOCSIZE_MASK; + cmd |= sizeof(void *) << IOCSIZE_SHIFT; + } + break; + } + return perf_ioctl(file, cmd, arg); +} +#else +# define perf_compat_ioctl NULL +#endif + int perf_event_task_enable(void) { struct perf_event *event; @@ -4122,7 +4143,7 @@ static const struct file_operations perf_fops = { .read = perf_read, .poll = perf_poll, .unlocked_ioctl = perf_ioctl, - .compat_ioctl = perf_ioctl, + .compat_ioctl = perf_compat_ioctl, .mmap = perf_mmap, .fasync = perf_fasync, };