From patchwork Mon Jul 18 16:43:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 72216 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp206849qga; Mon, 18 Jul 2016 09:44:42 -0700 (PDT) X-Received: by 10.36.19.75 with SMTP id 72mr5426451itz.83.1468860281764; Mon, 18 Jul 2016 09:44:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 77si10194807itf.109.2016.07.18.09.44.41; Mon, 18 Jul 2016 09:44:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752023AbcGRQoA (ORCPT + 3 others); Mon, 18 Jul 2016 12:44:00 -0400 Received: from mail-it0-f47.google.com ([209.85.214.47]:36615 "EHLO mail-it0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751831AbcGRQn7 (ORCPT ); Mon, 18 Jul 2016 12:43:59 -0400 Received: by mail-it0-f47.google.com with SMTP id f6so72192465ith.1 for ; Mon, 18 Jul 2016 09:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0YKHKNNsrKlBEQGhMpSNuTmgfA4jiNi2zdQ8bg+5fF0=; b=jBngjJqAPzlZVeJihuhGUiyfRfF/X4v6ozL3jR8IRUVAKGVfrCF5dSGm/M7WnUMQHp 4i4fUJO4GSLIHFy97hLW5IE008DIFqHPnRqFHkxV7Y+O/6lTTxVLgtsthRfJjLN2yMj1 CMzZDt6kkRNoruwaiNwN5DdwURd/0dIlmcA2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0YKHKNNsrKlBEQGhMpSNuTmgfA4jiNi2zdQ8bg+5fF0=; b=XRV+yJa7IORD3gJyDcr92q37UcvvLGW+FTKeLNdr70cy6sz6YMos4IWBEBZ0jHxRtF /J3xQcD77D2I55EWuWTND666Wnax78hjdFLiz87NkXGCFoLPCzqSBkfeYuSSoYuQotib zKbqGCZCxZt2jiCoc8k9TFisS5F86r2HqneuBWZWXJfj7C60zb5zORHfb2tY7qYmyQKP z1ya5RUZAqfRpPv6RCPL0+OrUMfInCC12U8WuEVjZeJucsbPpeNKBZnx0BNzgSR2XHvr A1XA3x082ayZN/VnD/S0aSWQVa1FMNQB19SZS3GnOe5fMbASyCvQKn9yYhxyixzfTYud 4NpA== X-Gm-Message-State: ALyK8tJO7BeVHSNxJbNI3tU+bWb+BaOA02CctlDQzTO5qsUiX1/Ou2rOT6p2yYF+bQ7T2Qhn X-Received: by 10.36.125.70 with SMTP id b67mr46985051itc.24.1468860237377; Mon, 18 Jul 2016 09:43:57 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 6sm9195332iov.34.2016.07.18.09.43.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jul 2016 09:43:56 -0700 (PDT) From: Mathieu Poirier To: alexander.shishkin@linux.intel.com Cc: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org, Mathieu Poirier , "# 4 . 7" Subject: [PATCH V2 2/3] perf/core: Update filter only on executable mmap Date: Mon, 18 Jul 2016 10:43:06 -0600 Message-Id: <1468860187-318-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468860187-318-1-git-send-email-mathieu.poirier@linaro.org> References: <1468860187-318-1-git-send-email-mathieu.poirier@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Function perf_event_mmap() is called by the MM subsystem each time part of a binary is loaded in memory. There can be several mapping for a binary, many times unrelated to the code section. Each time a section of a binary is mapped address filters are updated, event when the map doesn't pertain to the code section. The end result is that filters are configured based on the last map event that was received rather than the last mapping of the code segment. For example if we have an executable 'main' that calls library 'libcstest.so.1.0', and that we want to collect traces on code that is in that library. The perf cmd line for this scenario would be: perf record -e cs_etm// --filter 'filter 0x72c/0x40@/opt/lib/libcstest.so.1.0' --per-thread ./main Resulting in binaries being mapped this way: root@linaro-nano:~# cat /proc/1950/maps 00400000-00401000 r-xp 00000000 08:02 33169 /home/linaro/main 00410000-00411000 r--p 00000000 08:02 33169 /home/linaro/main 00411000-00412000 rw-p 00001000 08:02 33169 /home/linaro/main 7fa2464000-7fa2474000 rw-p 00000000 00:00 0 7fa2474000-7fa25a4000 r-xp 00000000 08:02 543 /lib/aarch64-linux-gnu/libc-2.21.so 7fa25a4000-7fa25b3000 ---p 00130000 08:02 543 /lib/aarch64-linux-gnu/libc-2.21.so 7fa25b3000-7fa25b7000 r--p 0012f000 08:02 543 /lib/aarch64-linux-gnu/libc-2.21.so 7fa25b7000-7fa25b9000 rw-p 00133000 08:02 543 /lib/aarch64-linux-gnu/libc-2.21.so 7fa25b9000-7fa25bd000 rw-p 00000000 00:00 0 7fa25bd000-7fa25be000 r-xp 00000000 08:02 38308 /opt/lib/libcstest.so.1.0 7fa25be000-7fa25cd000 ---p 00001000 08:02 38308 /opt/lib/libcstest.so.1.0 7fa25cd000-7fa25ce000 r--p 00000000 08:02 38308 /opt/lib/libcstest.so.1.0 7fa25ce000-7fa25cf000 rw-p 00001000 08:02 38308 /opt/lib/libcstest.so.1.0 7fa25cf000-7fa25eb000 r-xp 00000000 08:02 574 /lib/aarch64-linux-gnu/ld-2.21.so 7fa25ef000-7fa25f2000 rw-p 00000000 00:00 0 7fa25f7000-7fa25f9000 rw-p 00000000 00:00 0 7fa25f9000-7fa25fa000 r--p 00000000 00:00 0 [vvar] 7fa25fa000-7fa25fb000 r-xp 00000000 00:00 0 [vdso] 7fa25fb000-7fa25fc000 r--p 0001c000 08:02 574 /lib/aarch64-linux-gnu/ld-2.21.so 7fa25fc000-7fa25fe000 rw-p 0001d000 08:02 574 /lib/aarch64-linux-gnu/ld-2.21.so 7ff2ea8000-7ff2ec9000 rw-p 00000000 00:00 0 [stack] root@linaro-nano:~# Before 'main' can execute 'libcstest.so.1.0' has to be loaded in memory. Once that has been done perf_event_mmap() has been called 4 times, with the last map starting at address 0x7fa25ce000 and the address filter configured to start filtering when the IP has passed over address 0x0x7fa25ce72c (0x7fa25ce000 + 0x72c). But that is wrong since the code segment for library 'libcstest.so.1.0' as been mapped at 0x7fa25bd000, resulting in traces not being collected. This patch corrects the situation by requesting that address filters be updated only if the mapped event is for a code segment. Signed-off-by: Mathieu Poirier Cc: # 4.7 --- kernel/events/core.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kernel/events/core.c b/kernel/events/core.c index a8371814dbf4..f2bb2a0fae2b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6562,6 +6562,13 @@ static void perf_addr_filters_adjust(struct vm_area_struct *vma) struct perf_event_context *ctx; int ctxn; + /* + * Data tracing isn't supported yet and as such there is no need + * to keep track of anything that isn't related to executable code. + */ + if (!(vma->vm_flags & VM_EXEC)) + return; + rcu_read_lock(); for_each_task_context_nr(ctxn) { ctx = rcu_dereference(current->perf_event_ctxp[ctxn]);