From patchwork Fri Oct 31 13:14:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 39917 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2A83D2405B for ; Fri, 31 Oct 2014 14:25:00 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id mc6sf4183936lab.11 for ; Fri, 31 Oct 2014 07:24:59 -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: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=Rla0yq2r0E7Vvq6j6+qV0qahvOcg980uhO/OnNVtXWg=; b=F0rm9V/lRHvv1YLn/9Uf1L6+TuIbIm4P6oj4vhhZuGPe+h0ROkEOzmHHcGiLFIzEY6 RaFdmUdl9I1LLEgFrcjPfIbx8wC2ORMnIm2tgKw6uWFAz4lqwu9TsB/qGCR2QjR9NF+j WSgBwkZPRLvQqInq20upWJFlF4YL448ELywx0Qp0jMz7kDtyOM/cdZgYjCqDQu+2gmeC oTRz2/uUevBnGR0OEWANDXVyfK3lnyLLL/saD+NdGKN5hsEgd/zHgQNy3/ZIyEawYunu qWf2lDrB0noFDirMk4yIczwXNLuDzz+ef5hC0wocnz31rt7wKus+U/ZuDYJONY+WGVPa B7UQ== X-Gm-Message-State: ALoCoQnYfc0z8paiGkGCAjMC9OASGw76yjosSl17tzv8Zu94zsSFIwaoOXYAHrc9KzgNTSVQgJYl X-Received: by 10.112.97.35 with SMTP id dx3mr54633lbb.20.1414765498934; Fri, 31 Oct 2014 07:24:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.135 with SMTP id v7ls494296lae.40.gmail; Fri, 31 Oct 2014 07:24:58 -0700 (PDT) X-Received: by 10.112.63.70 with SMTP id e6mr3858621lbs.93.1414765498822; Fri, 31 Oct 2014 07:24:58 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id k10si16874091lbp.126.2014.10.31.07.24.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 07:24:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id s18so909923lam.41 for ; Fri, 31 Oct 2014 07:24:58 -0700 (PDT) X-Received: by 10.112.130.41 with SMTP id ob9mr26148800lbb.74.1414765498707; Fri, 31 Oct 2014 07:24:58 -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 c5csp210442lbz; Fri, 31 Oct 2014 07:24:57 -0700 (PDT) X-Received: by 10.70.130.174 with SMTP id of14mr25332006pdb.90.1414765494886; Fri, 31 Oct 2014 07:24:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi9si9112364pdb.55.2014.10.31.07.24.54 for ; Fri, 31 Oct 2014 07:24:54 -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 S1756593AbaJaOYx (ORCPT + 1 other); Fri, 31 Oct 2014 10:24:53 -0400 Received: from ip4-83-240-67-251.cust.nbox.cz ([83.240.67.251]:48145 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758449AbaJaOYx (ORCPT ); Fri, 31 Oct 2014 10:24:53 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.83) (envelope-from ) id 1XkC28-0004Pt-36; Fri, 31 Oct 2014 14:14:28 +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 3.12 137/144] perf: Handle compat ioctl Date: Fri, 31 Oct 2014 14:14:19 +0100 Message-Id: <34d0978c5d497bcd56b5942be7fa261660635e47.1414759455.git.jslaby@suse.cz> X-Mailer: git-send-email 2.1.2 In-Reply-To: <8d9c8c3980a85d79db13c5ce4bb118fef32d4f50.1414759455.git.jslaby@suse.cz> References: <8d9c8c3980a85d79db13c5ce4bb118fef32d4f50.1414759455.git.jslaby@suse.cz> In-Reply-To: References: 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.215.54 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 3.12-stable review patch. If anyone has any objections, please let me 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, };