From patchwork Tue Jun 17 12:43:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 32027 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AC286206A0 for ; Tue, 17 Jun 2014 12:44:10 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id uo5sf15272730pbc.4 for ; Tue, 17 Jun 2014 05:44:09 -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=NicVVp2SyqdvE48GJb5tE4T0rWti64F50A8w1SekbsY=; b=PDmVCOv4JLBi09D/AQZl8dhj2XZbVt9Qoe/pFEEOKA5U/qx/F3eEvfY25fDV/T3QIY my3KDo/cif7A8BYd2vqzHchwIMacm44Wn/Z7EyJs948vGdLu9c0MIZjTMg+cmvmlheY0 JRQBoRjcJiNQzsuk3TU3f41ayyeZqp3+9khMbm+UlfvVRFrNtEBWjLeVuOk+KW4Ny9Pp qFFQ2Iqm6XKR1JRIYn9jYLjQAY+l+QjruyKJUVH/0x/h/b5cnTpsPfE3wh6vYE6n+y5d eOO/oFLC7EQWVNdNY7H8AIGsLtIx0GUwCHIExP3gsMHJ1zG+LVS85Wi7klNxCofEZWmR K+7w== X-Gm-Message-State: ALoCoQlg0FO6lArI+f0JZVrnLxQmlIu2kZmDyoo4XOCJhiaJ7zw3R89K26PlFrmjkkH4wObd3yZB X-Received: by 10.66.165.165 with SMTP id yz5mr1121597pab.37.1403009049954; Tue, 17 Jun 2014 05:44:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.112 with SMTP id n103ls4799725qga.86.gmail; Tue, 17 Jun 2014 05:44:09 -0700 (PDT) X-Received: by 10.220.250.203 with SMTP id mp11mr21474391vcb.2.1403009049829; Tue, 17 Jun 2014 05:44:09 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id xs1si2527076vec.64.2014.06.17.05.44.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Jun 2014 05:44:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id i13so3836271veh.36 for ; Tue, 17 Jun 2014 05:44:09 -0700 (PDT) X-Received: by 10.52.52.168 with SMTP id u8mr18020380vdo.25.1403009049712; Tue, 17 Jun 2014 05:44:09 -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 vs6csp206447vcb; Tue, 17 Jun 2014 05:44:09 -0700 (PDT) X-Received: by 10.68.189.137 with SMTP id gi9mr32482447pbc.79.1403009048931; Tue, 17 Jun 2014 05:44:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id zz3si17197789pac.115.2014.06.17.05.44.08; Tue, 17 Jun 2014 05:44:08 -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 S1756237AbaFQMoF (ORCPT + 26 others); Tue, 17 Jun 2014 08:44:05 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:20828 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755836AbaFQMoD (ORCPT ); Tue, 17 Jun 2014 08:44:03 -0400 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.148]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 230B513F884; Tue, 17 Jun 2014 07:44:01 -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 v2] perf: Handle compat ioctl Date: Tue, 17 Jun 2014 13:43:49 +0100 Message-Id: <1403009029-30967-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20140617121328.GO3213@twins.programming.kicks-ass.net> References: <20140617121328.GO3213@twins.programming.kicks-ass.net> 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.128.177 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 | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) Changes from v1: - added missing #include diff --git a/kernel/events/core.c b/kernel/events/core.c index 5fa58e4..f081335 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "internal.h" @@ -3716,6 +3717,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; @@ -4221,7 +4242,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, };