From patchwork Fri Jun 13 15:03:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 31878 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 92C24201EF for ; Fri, 13 Jun 2014 15:04:17 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id b6sf11635195yha.4 for ; Fri, 13 Jun 2014 08:04:17 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=2hUV14U0HIKBkwroEPN+q+tuuB3GSKC6dunSOyO6UnI=; b=IfabZ6Xb0uFiywYgVCheXXIOGcT72z4AbBAL8KbgrnRgDDgq0H4vLrnwzbbUBhhOmf mTeyAgZg+PkBD1CVqbu8Sm1R44pz4Duce0gCgFAhv1GviZEJjIIjRjWIbkQJyoVEbbrL 48HzCycXD89+kJwBDyYViA+uEp7L7nXqxajHa525cpZ0LddzXG56Ig+OSxM0+7qrHEJR 3z21hZwQJ+heBpjwduteiTRw1JSKAxctLwqI24A+RV+HCWE0XF496kGOVCh0MBxrjimJ VgX0Asq84C0LzuhmzuQgSUnHL95bpHHSiu3tK6nifMcD/3X+HcBl2Op5Bmb0LPtPxjAN SneA== X-Gm-Message-State: ALoCoQlus/ZwgGQu4wqVOCmfw0rWSJwYJwhJbRYW6q8pDJJwTudXkCtoooGBTjJtv3qJGegm6Wu4 X-Received: by 10.236.207.164 with SMTP id n24mr1226978yho.5.1402671857318; Fri, 13 Jun 2014 08:04:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.8 with SMTP id y8ls3629138qgy.11.gmail; Fri, 13 Jun 2014 08:04:17 -0700 (PDT) X-Received: by 10.52.241.98 with SMTP id wh2mr1334962vdc.37.1402671857234; Fri, 13 Jun 2014 08:04:17 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id q13si1499954vci.29.2014.06.13.08.04.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Jun 2014 08:04:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hy4so2378597vcb.20 for ; Fri, 13 Jun 2014 08:04:17 -0700 (PDT) X-Received: by 10.58.22.164 with SMTP id e4mr265699vef.71.1402671857033; Fri, 13 Jun 2014 08:04:17 -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.221.54.6 with SMTP id vs6csp498723vcb; Fri, 13 Jun 2014 08:04:16 -0700 (PDT) X-Received: by 10.66.131.39 with SMTP id oj7mr4132450pab.20.1402671856231; Fri, 13 Jun 2014 08:04:16 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oy9si2433050pbc.166.2014.06.13.08.04.15; Fri, 13 Jun 2014 08:04:15 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S1752763AbaFMPED (ORCPT + 24 others); Fri, 13 Jun 2014 11:04:03 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:46422 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750901AbaFMPEC (ORCPT ); Fri, 13 Jun 2014 11:04:02 -0400 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.92]) by collaborate-mta1.arm.com (Postfix) with ESMTP id AE40C13F83E; Fri, 13 Jun 2014 10:03:47 -0500 (CDT) From: Pawel Moll To: Peter Zijlstra , Paul Mackerras , Ingo Molnar , Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Drew Richardson , Pawel Moll Subject: [PATCH] perf: Handle compat ioctl Date: Fri, 13 Jun 2014 16:03:32 +0100 Message-Id: <1402671812-9078-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 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: , 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 --- kernel/events/core.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 24d35cc..967af2c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3700,6 +3700,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; @@ -4205,7 +4225,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, };