From patchwork Mon Jul 7 13:45:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 33161 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 83BC420969 for ; Mon, 7 Jul 2014 13:46:07 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id at1sf6501328iec.7 for ; Mon, 07 Jul 2014 06:46:07 -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=NpyUzherX9gQdOT0uUs550iqsnTPnLsqNeMzwRz7CFM=; b=bsiwLAUtRgbJ59EZLrbvaW9Ses930lixogrvPsTrqiLhMYGy+p3dN4jqyga105Nkj6 MT0a2rl48GjZQX2AH8MIgDjXx9/ri4DXahJpckLsr3grLp/pbcGZtGluefLPRllR6Z+X FhQCkrMhm/InvVdHu/GDvU3xeuQGy4VLNDYsN3fqULVmVB2P7lA1Q0dEreDUnj6SudE4 /AQdESSgPOLQ3FtDvh1spXMkBF8hMAUIvpccVRKXlmZBZskBFNQ5ZTruwdfziGJnHerl T76y4MbFGnbQsPaiqkjz6I/b9cugycn74xX6MYOmzHLnXqF64bbMRPj1odN7+Ty4P101 vywQ== X-Gm-Message-State: ALoCoQlB58Wlp6A61HvkHgM0B8/sL/25qpflSAUZKHYvgdfJXxCkSq2xwhdV0mFFvn1BCgYiONzg X-Received: by 10.182.105.230 with SMTP id gp6mr14682637obb.18.1404740767027; Mon, 07 Jul 2014 06:46:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.68 with SMTP id g62ls815227qgf.75.gmail; Mon, 07 Jul 2014 06:46:06 -0700 (PDT) X-Received: by 10.52.232.200 with SMTP id tq8mr2141573vdc.32.1404740766932; Mon, 07 Jul 2014 06:46:06 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id ux9si18404027vdc.7.2014.07.07.06.46.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jul 2014 06:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.174 as permitted sender) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id jx11so4075662veb.33 for ; Mon, 07 Jul 2014 06:46:06 -0700 (PDT) X-Received: by 10.58.209.7 with SMTP id mi7mr54860vec.80.1404740765199; Mon, 07 Jul 2014 06:46:05 -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.37.5 with SMTP id tc5csp668227vcb; Mon, 7 Jul 2014 06:46:04 -0700 (PDT) X-Received: by 10.70.87.206 with SMTP id ba14mr28522347pdb.4.1404740764325; Mon, 07 Jul 2014 06:46:04 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ff3si41092753pbd.167.2014.07.07.06.46.03; Mon, 07 Jul 2014 06:46:03 -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 S1753376AbaGGNpy (ORCPT + 27 others); Mon, 7 Jul 2014 09:45:54 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:43061 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753589AbaGGNpi (ORCPT ); Mon, 7 Jul 2014 09:45:38 -0400 Received: by mail-wi0-f180.google.com with SMTP id hi2so6766015wib.1 for ; Mon, 07 Jul 2014 06:45:32 -0700 (PDT) X-Received: by 10.194.9.198 with SMTP id c6mr3239282wjb.131.1404740732238; Mon, 07 Jul 2014 06:45:32 -0700 (PDT) Received: from rachael.linaro.local ([213.122.173.130]) by mx.google.com with ESMTPSA id e18sm26653901wic.0.2014.07.07.06.45.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jul 2014 06:45:31 -0700 (PDT) From: Jean Pihet To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Will Deacon Cc: Jiri Olsa , Ingo Molnar , Arnaldo Carvalho de Melo , steve.capper@linaro.org, Jean Pihet Subject: [PATCH 2/3] ARM: perf: disable the pagefault handler when reading from user space Date: Mon, 7 Jul 2014 15:45:09 +0200 Message-Id: <1404740710-14691-3-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1404740710-14691-1-git-send-email-jean.pihet@linaro.org> References: <1404740710-14691-1-git-send-email-jean.pihet@linaro.org> 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: jean.pihet@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.128.174 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: , Under perf, the fp unwinding scheme requires access to user space memory and can provoke a pagefault via call to __copy_from_user_inatomic from user_backtrace. This unwinding can take place in response to an interrupt (__perf_event_overflow). This is undesirable as we may already have mmap_sem held for write. One example being a process that calls mprotect just as a the PMU counters overflow. An example that can provoke this behaviour: perf record -e event:tocapture --call-graph fp ./application_to_test This patch addresses this issue by disabling pagefaults briefly in user_backtrace (as is done in the other architectures: ARM64, x86, Sparc etc.). Without the patch a deadlock occurs when __perf_event_overflow is called while reading the data from the user space: [ INFO: possible recursive locking detected ] 3.16.0-rc2-00038-g0ed7ff6 #46 Not tainted --------------------------------------------- stress/1634 is trying to acquire lock: (&mm->mmap_sem){++++++}, at: [] do_page_fault+0xa8/0x428 but task is already holding lock: (&mm->mmap_sem){++++++}, at: [] SyS_mprotect+0xa8/0x1c8 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&mm->mmap_sem); lock(&mm->mmap_sem); *** DEADLOCK *** May be due to missing lock nesting notation 2 locks held by stress/1634: #0: (&mm->mmap_sem){++++++}, at: [] SyS_mprotect+0xa8/0x1c8 #1: (rcu_read_lock){......}, at: [] __perf_event_overflow+0x120/0x294 stack backtrace: CPU: 1 PID: 1634 Comm: stress Not tainted 3.16.0-rc2-00038-g0ed7ff6 #46 [] (unwind_backtrace) from [] (show_stack+0x20/0x24) [] (show_stack) from [] (dump_stack+0x7c/0x98) [] (dump_stack) from [] (__lock_acquire+0x1484/0x1cf0) [] (__lock_acquire) from [] (lock_acquire+0xa4/0x11c) [] (lock_acquire) from [] (down_read+0x40/0x7c) [] (down_read) from [] (do_page_fault+0xa8/0x428) [] (do_page_fault) from [] (do_DataAbort+0x44/0xa8) [] (do_DataAbort) from [] (__dabt_svc+0x3c/0x60) Exception stack(0xed7c5ae0 to 0xed7c5b28) 5ae0: ed7c5b5c b6dadff4 ffffffec 00000000 b6dadff4 ebc08000 00000000 ebc08000 5b00: 0000007e 00000000 ed7c4000 ed7c5b94 00000014 ed7c5b2c c001a438 c0236c60 5b20: 00000013 ffffffff [] (__dabt_svc) from [] (__copy_from_user+0xa4/0x3a4) Signed-off-by: Jean Pihet Cc: Will Deacon Acked-by: Steve Capper --- arch/arm/kernel/perf_event.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c index 6493c4c..f5aeca2 100644 --- a/arch/arm/kernel/perf_event.c +++ b/arch/arm/kernel/perf_event.c @@ -560,11 +560,16 @@ user_backtrace(struct frame_tail __user *tail, struct perf_callchain_entry *entry) { struct frame_tail buftail; + unsigned long err; - /* Also check accessibility of one struct frame_tail beyond */ if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) return NULL; - if (__copy_from_user_inatomic(&buftail, tail, sizeof(buftail))) + + pagefault_disable(); + err = __copy_from_user_inatomic(&buftail, tail, sizeof(buftail)); + pagefault_enable(); + + if (err) return NULL; perf_callchain_store(entry, buftail.lr);