Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2959419imu; Mon, 19 Nov 2018 08:38:31 -0800 (PST) X-Google-Smtp-Source: AJdET5fEH2r0Zx3S0o9xHtBDTjYUjFBwmWUgp2pciZEpTp4Xg0W4ckcUTduOIpXLk04q26Ns4rVb X-Received: by 2002:a62:6143:: with SMTP id v64mr13094333pfb.142.1542645511150; Mon, 19 Nov 2018 08:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645511; cv=none; d=google.com; s=arc-20160816; b=sHLrEthHWDU1mLpcxM5tQRorPc4EueI5UtJQaUUYowrjTBz2R3XK+TFmPl6Qj71cha tc61RRRkR30lgmUBZ3dGo4cYadiJ/3+63jBI7a4QnnF5AWB9PDIDF4WnOjHmHrvOxW4G q6jmjnze6/+Q4YD+3fPi48ua6OLOaGJ82xS3bC2wqaE+L0EsU53XLaA66AWYs+fKCZkY wsY/psH1o3QL9L93+O24DbjmIMc4cziscUZwxx0JDlS4w2HCEKW029biAFjcVIIj1SKS x87KRdILrYyYKvUaaFwyF1nwCXB9xZqEsTh41cC9SXt2WW3kP1t0ffcj1i1jcanp2B4E Cgww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JqvZOiQWZbMSr8tEVi1f/uJLakMeKjYrlftLXL8eKF8=; b=ycjkWnY2GRW7i21Ah0WpxwXkO86Y0e8HwukwwW03P4TdIMqVnKQKOL8WmgoqqbPBtH NZVMmWGbX29wIQF6TMIo1/V9gYJsfKtCo+Ielpp0He7MwsEYzO3xKlT0nJdUng7hZqQN KV/4ueNqzpSHy3NZSMwBWjsquZbKYpyX7yfEtwpfdLHBg1GRz5HME5r6ht+YmjqSTu3i 9auZlMx3OMjoCy0eFIBx8OluJk+kyP1mSymuFH4SodW9py3pMDODvDIxdkgvgpsnOOZ7 GrWvnAe3sASSOY3lxdINhUAPSw8bBlMqSpkOQVSEhAPIJX7ybm32DYkSDuB536F3VbdD f1Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iuaJXZuE; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si4169819pfi.125.2018.11.19.08.38.15; Mon, 19 Nov 2018 08:38:31 -0800 (PST) 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=@kernel.org header.s=default header.b=iuaJXZuE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731543AbeKTC7I (ORCPT + 99 others); Mon, 19 Nov 2018 21:59:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:58342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730350AbeKTC7H (ORCPT ); Mon, 19 Nov 2018 21:59:07 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A983208E4; Mon, 19 Nov 2018 16:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645299; bh=EHg9MxQPhMaYW4OZIpGDsIbg71qk+3obzXbTDYIXdYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iuaJXZuEmIyFliJJkEsLiJm/hH09YZpZBhPVwjTi6F/FARpqBaGNIgy+CRkVbvlrO fDcjqaZHJqDMgKOucd2HkWPzVyGCmdx1xYGQyIA5Ghj3Oh0WlK14Ti+ryfAf7LlxXO 4RvHNAXK/tQDCOCmQ9HUhsagVZuTlSnTIt+DSuFQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Adrian Hunter , Alexander Shishkin , David Miller , Jiri Olsa , Mathieu Poirier , Namhyung Kim , Peter Zijlstra , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , stable@kernel.org Subject: [PATCH 4.19 112/205] perf cs-etm: Correct CPU mode for samples Date: Mon, 19 Nov 2018 17:26:59 +0100 Message-Id: <20181119162634.771580711@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leo Yan commit d6c9c05fe1eb4b213b183d8a1e79416256dc833a upstream. Since commit edeb0c90df35 ("perf tools: Stop fallbacking to kallsyms for vdso symbols lookup"), the kernel address cannot be properly parsed to kernel symbol with command 'perf script -k vmlinux'. The reason is CoreSight samples is always to set CPU mode as PERF_RECORD_MISC_USER, thus it fails to find corresponding map/dso in below flows: process_sample_event() `-> machine__resolve() `-> thread__find_map(thread, sample->cpumode, sample->ip, al); In this flow it needs to pass argument 'sample->cpumode' to tell what's the CPU mode, before it always passed PERF_RECORD_MISC_USER but without any failure until the commit edeb0c90df35 ("perf tools: Stop fallbacking to kallsyms for vdso symbols lookup") has been merged. The reason is even with the wrong CPU mode the function thread__find_map() firstly fails to find map but it will rollback to find kernel map for vdso symbols lookup. In the latest code it has removed the fallback code, thus if CPU mode is PERF_RECORD_MISC_USER then it cannot find map anymore with kernel address. This patch is to correct samples CPU mode setting, it creates a new helper function cs_etm__cpu_mode() to tell what's the CPU mode based on the address with the info from machine structure; this patch has a bit extension to check not only kernel and user mode, but also check for host/guest and hypervisor mode. Finally this patch uses the function in instruction and branch samples and also apply in cs_etm__mem_access() for a minor polishing. Signed-off-by: Leo Yan Cc: Adrian Hunter Cc: Alexander Shishkin Cc: David Miller Cc: Jiri Olsa Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Cc: stable@kernel.org # v4.19 Link: http://lkml.kernel.org/r/1540883908-17018-1-git-send-email-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/cs-etm.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -244,6 +244,27 @@ static void cs_etm__free(struct perf_ses zfree(&aux); } +static u8 cs_etm__cpu_mode(struct cs_etm_queue *etmq, u64 address) +{ + struct machine *machine; + + machine = etmq->etm->machine; + + if (address >= etmq->etm->kernel_start) { + if (machine__is_host(machine)) + return PERF_RECORD_MISC_KERNEL; + else + return PERF_RECORD_MISC_GUEST_KERNEL; + } else { + if (machine__is_host(machine)) + return PERF_RECORD_MISC_USER; + else if (perf_guest) + return PERF_RECORD_MISC_GUEST_USER; + else + return PERF_RECORD_MISC_HYPERVISOR; + } +} + static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, size_t size, u8 *buffer) { @@ -258,10 +279,7 @@ static u32 cs_etm__mem_access(struct cs_ return -1; machine = etmq->etm->machine; - if (address >= etmq->etm->kernel_start) - cpumode = PERF_RECORD_MISC_KERNEL; - else - cpumode = PERF_RECORD_MISC_USER; + cpumode = cs_etm__cpu_mode(etmq, address); thread = etmq->thread; if (!thread) { @@ -653,7 +671,7 @@ static int cs_etm__synth_instruction_sam struct perf_sample sample = {.ip = 0,}; event->sample.header.type = PERF_RECORD_SAMPLE; - event->sample.header.misc = PERF_RECORD_MISC_USER; + event->sample.header.misc = cs_etm__cpu_mode(etmq, addr); event->sample.header.size = sizeof(struct perf_event_header); sample.ip = addr; @@ -665,7 +683,7 @@ static int cs_etm__synth_instruction_sam sample.cpu = etmq->packet->cpu; sample.flags = 0; sample.insn_len = 1; - sample.cpumode = event->header.misc; + sample.cpumode = event->sample.header.misc; if (etm->synth_opts.last_branch) { cs_etm__copy_last_branch_rb(etmq); @@ -706,12 +724,15 @@ static int cs_etm__synth_branch_sample(s u64 nr; struct branch_entry entries; } dummy_bs; + u64 ip; + + ip = cs_etm__last_executed_instr(etmq->prev_packet); event->sample.header.type = PERF_RECORD_SAMPLE; - event->sample.header.misc = PERF_RECORD_MISC_USER; + event->sample.header.misc = cs_etm__cpu_mode(etmq, ip); event->sample.header.size = sizeof(struct perf_event_header); - sample.ip = cs_etm__last_executed_instr(etmq->prev_packet); + sample.ip = ip; sample.pid = etmq->pid; sample.tid = etmq->tid; sample.addr = cs_etm__first_executed_instr(etmq->packet); @@ -720,7 +741,7 @@ static int cs_etm__synth_branch_sample(s sample.period = 1; sample.cpu = etmq->packet->cpu; sample.flags = 0; - sample.cpumode = PERF_RECORD_MISC_USER; + sample.cpumode = event->sample.header.misc; /* * perf report cannot handle events without a branch stack