Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp579763ybt; Fri, 19 Jun 2020 08:36:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBlpDsvZ2t7PUhxULowl8+hdMEPU2X1i98dWj+0VxuKEM5QAgkkgDkTcyLadqqstLa5SfL X-Received: by 2002:a50:951d:: with SMTP id u29mr4018446eda.333.1592580979095; Fri, 19 Jun 2020 08:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592580979; cv=none; d=google.com; s=arc-20160816; b=DGRgwBj3QOJoetFCsKnYZRQOKm2gHXURYaS12T/e5WiIQBEIzrMHxR0pfFSyX0WsBr r58FskgnJ2p1gn/hJDcZtSO1HFo+DX7zY07y0eLIF7VTJeKfCncqxFINf04bSqbC/yya MQso62PgGgNFiCg6mSXHoCBmJ3O3vgo8qu/yDk9YxcTwRyD66ZbEU8Unz1UwhtHAVG9R vljPmqsJv+yTF32hcnNjE+Fe/0T+xTodmHhda0POQyi+g4BWjFkGogbnmQR5oSmSgfNa kCO3LChDZJIagKowCuc7UdQY0vsW6P73bHN238vIm7lrZvq52ux2CPw43NaZ/SJBPMYf shNg== 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=zGALi5pIAFhXT7Yo2Bbd6t4GxM36ELkMzCKEpBWaiSM=; b=n/CKDkgq/ytr5GC1RuCiKXFmfumth85WokPV2Zs9tG/KhySpHOY6skg+DrnrIEK1yV 8FalD4CloR55ek1P8ulFr8WcbF5LZMoJffBf7pjPNrQ60U/reKE2ZRI6JentCGMY9vDn kRCkoPgsam4QmYmzPZ7F5LJleUU5FBcqU8QOsELriZn5puaun8bA8kbm4q8LeSCEyReF olKW5doLA4OE2GYZRNLCWjVqwwx0OBaABbB1gUqwfa684W2mOCezRaWLMHheVCcaf1lV pYVzsC7EiNU/OadNJKQ8kFHBksfmRTry1hkaIdVsrU/utmPm8gl4IZkJAfDJk5GalaRA OCkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="DxZ3X/ek"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t18si4598100edt.132.2020.06.19.08.35.56; Fri, 19 Jun 2020 08:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="DxZ3X/ek"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404998AbgFSPdV (ORCPT + 99 others); Fri, 19 Jun 2020 11:33:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:36800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393921AbgFSPcr (ORCPT ); Fri, 19 Jun 2020 11:32:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 E43152193E; Fri, 19 Jun 2020 15:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580766; bh=MqiTUwiN2/J/Fok+hBOgitTkj1dSroJsDa+XbOOl9Sk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxZ3X/ekbXfQhOqVCzoEiRjpxYwqe7fPNm8v/j56QUaNQqVl936Bmq6f48gT6aR7C lr9XuOIR+BQm3Xz1Yk5iWBwI3Ty/xs2nw56dfMoRNNj3o/HDff9G05Y2VM+eeLJSt8 KwCswi6b2+kujxtdqwINtWcFnNbi4qk+TbtRkUQY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnaldo Carvalho de Melo , Masami Hiramatsu , Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim Subject: [PATCH 5.7 374/376] perf probe: Check address correctness by map instead of _etext Date: Fri, 19 Jun 2020 16:34:52 +0200 Message-Id: <20200619141727.994661073@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Masami Hiramatsu commit 2ae5d0d7d8868df7c05c2013c0b9cddd4d40610e upstream. Since commit 03db8b583d1c ("perf tools: Fix maps__find_symbol_by_name()") introduced map address range check in maps__find_symbol_by_name(), we can not get "_etext" from kernel map because _etext is placed on the edge of the kernel .text section (= kernel map in perf.) To fix this issue, this checks the address correctness by map address range information (map->start and map->end) instead of using _etext address. This can cause an error if the target inlined function is embedded in both __init function and normal function. For exaample, request_resource() is a normal function but also embedded in __init reserve_setup(). In this case, the probe point in reserve_setup() must be skipped. However, without this fix, it failes to setup all probe points: # ./perf probe -v request_resource probe-definition(0): request_resource symbol:request_resource file:(null) line:0 offset:0 return:0 lazy:(null) 0 arguments Looking at the vmlinux_path (8 entries long) Using /usr/lib/debug/lib/modules/5.5.17-200.fc31.x86_64/vmlinux for symbols Open Debuginfo file: /usr/lib/debug/lib/modules/5.5.17-200.fc31.x86_64/vmlinux Try to find probe point from debuginfo. Matched function: request_resource [15e29ad] found inline addr: 0xffffffff82fbf892 Probe point found: reserve_setup+204 found inline addr: 0xffffffff810e9790 Probe point found: request_resource+0 Found 2 probe_trace_events. Opening /sys/kernel/debug/tracing//kprobe_events write=1 Opening /sys/kernel/debug/tracing//README write=0 Writing event: p:probe/request_resource _text+33290386 Failed to write event: Invalid argument Error: Failed to add events. Reason: Invalid argument (Code: -22) # With this fix, # ./perf probe request_resource reserve_setup is out of .text, skip it. Added new events: (null):(null) (on request_resource) probe:request_resource (on request_resource) You can now use it in all perf tools, such as: perf record -e probe:request_resource -aR sleep 1 # Fixes: 03db8b583d1c ("perf tools: Fix maps__find_symbol_by_name()") Reported-by: Arnaldo Carvalho de Melo Signed-off-by: Masami Hiramatsu Tested-by: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Namhyung Kim Cc: stable@vger.kernel.org Link: http://lore.kernel.org/lkml/158763967332.30755.4922496724365529088.stgit@devnote2 Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/probe-event.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -236,21 +236,22 @@ static void clear_probe_trace_events(str static bool kprobe_blacklist__listed(unsigned long address); static bool kprobe_warn_out_range(const char *symbol, unsigned long address) { - u64 etext_addr = 0; - int ret; + struct map *map; + bool ret = false; - /* Get the address of _etext for checking non-probable text symbol */ - ret = kernel_get_symbol_address_by_name("_etext", &etext_addr, - false, false); - - if (ret == 0 && etext_addr < address) - pr_warning("%s is out of .text, skip it.\n", symbol); - else if (kprobe_blacklist__listed(address)) + map = kernel_get_module_map(NULL); + if (map) { + ret = address <= map->start || map->end < address; + if (ret) + pr_warning("%s is out of .text, skip it.\n", symbol); + map__put(map); + } + if (!ret && kprobe_blacklist__listed(address)) { pr_warning("%s is blacklisted function, skip it.\n", symbol); - else - return false; + ret = true; + } - return true; + return ret; } /*