From patchwork Thu Aug 11 19:47:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 73817 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp275529qga; Thu, 11 Aug 2016 12:47:55 -0700 (PDT) X-Received: by 10.98.72.28 with SMTP id v28mr20102392pfa.139.1470944875261; Thu, 11 Aug 2016 12:47:55 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o78si4575138pfi.291.2016.08.11.12.47.54; Thu, 11 Aug 2016 12:47:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932431AbcHKTrw (ORCPT + 27 others); Thu, 11 Aug 2016 15:47:52 -0400 Received: from mail-it0-f53.google.com ([209.85.214.53]:38655 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932166AbcHKTr2 (ORCPT ); Thu, 11 Aug 2016 15:47:28 -0400 Received: by mail-it0-f53.google.com with SMTP id x130so6117861ite.1 for ; Thu, 11 Aug 2016 12:47:27 -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=un89SykD2Oxm9oWJUvwfwSyzn8eVZqlsDZ29VzjMJXE=; b=eOGbKX7c+w58YeCNlZ4YDWyRZU5J01EEeXVPZi9GkSIsR9nYz0IAK0UTkPgRhxbzSY zvcNafkVeWKYL/IboDv413JAnD9Mb1fraCncob8tYgoaxaLt1iCC8hmDcR2MBcQyX52m O6hS0FHvwnxJLefYFBvcoxSp+07ZVLAWCj4lo= 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=un89SykD2Oxm9oWJUvwfwSyzn8eVZqlsDZ29VzjMJXE=; b=IhawXk/IT6BDpPMK5gDyGTefG4QCc74YLuhalpsfFQai4h7ptuilubk6arcTl0PuL3 KfnrUHWCC7HeWGRudPxRA3mcaZmiLrhDm2Gk+DVDQNqm0oxcA809Tq5warfKBhfAl9YT orZG9aQZzZukqTCONagOzuizVW4zVQJSRY61GjJxd/BiF306SPs+1hGEPPmC5wzSxBzU XRSGepAX2MUGUu/oaMg4VIYGhEffXO5t3GMbHYJQix8ZP8Qi4eAz6A+/lUIapmQh7bpN iD9oXe7mmua1TSA4GOkfxdVBXeuEhatIx8l8k4CntAUid5sSOQc44FlxjyEHtVfIBguM KO0Q== X-Gm-Message-State: AEkooutoPeK/ZYGMOEHZiibdm2XiT0VaA1tZrzG+PutQDv7ELjVETNQb1gM5OqaCnfu78Lo0 X-Received: by 10.36.82.5 with SMTP id d5mr11985188itb.6.1470944847365; Thu, 11 Aug 2016 12:47:27 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 16sm1973750iol.23.2016.08.11.12.47.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 12:47:26 -0700 (PDT) From: Mathieu Poirier To: peterz@infradead.org Cc: mingo@redhat.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH V3 2/3] perf/core: Update filter only on executable mmap Date: Thu, 11 Aug 2016 13:47:22 -0600 Message-Id: <1470944843-7575-3-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470944843-7575-1-git-send-email-mathieu.poirier@linaro.org> References: <1470944843-7575-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Acked-by: Alexander Shishkin --- kernel/events/core.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.7.4 diff --git a/kernel/events/core.c b/kernel/events/core.c index 0662279c5729..463235ffc39c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6622,6 +6622,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]);