From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07502EB64D7 for ; Tue, 27 Jun 2023 00:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4SVD5U9xoQxvS9cu4EimByDuX5Pc34pwDokrVtoyYMg=; b=VPD9smBMtbu2Ak bCj3OU9pM6SBjjnSBeaSaCFy2Wz/3dIEtkMpD1FpDzpHGmjTfGFyHKEzj/kYDnSWcjHR+HQIbOw6n 4roVgmumpLqJAuxHbp7/5qKy/di/9nOD+ip2DSm++rPGTmuNDF5NNgUO+FMO9aUFgUKkU2K3FSM8x +8EmqI4A+UhfAanWs8vHOmVgZPhVO1fvzqE4eoycU8z/vMBvJAOVmsHclq5gzpS7A7zs04QcP9qPW uKhkCD7hF9fL7FVEze7wGllWkLa9gGJ/WtkguaXBvNBbP/Q1GMzrxN9C8GuhTFmziAjeL5usZZylg BwORGF526G6ve9M0+Ygw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qDwAE-00BGpH-36; Tue, 27 Jun 2023 00:02:34 +0000 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qDwAB-00BGoa-1j for linux-arm-kernel@lists.infradead.org; Tue, 27 Jun 2023 00:02:32 +0000 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-341cb9528f5so19753495ab.1 for ; Mon, 26 Jun 2023 17:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687824150; x=1690416150; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=qg2KUH6YMBj2eN2aEtzkgtiYkQL1wDcya22Dq84KAL0=; b=eXnqbSBJDFJjfibslGCyT1NTo95GSTccgHpecgbt9FV06Tj4exgC8MK5RgRV9qzkbh fONb1dLS5svxkwKRcl4dng+/E1mkVJiVlGxBflnMVFWGEpD5XMZU+vCdHkuFs44CHGEI HkPUjyyWkhGG6qWt/vnyrJ8IK8p7Dk0KSY0jzFLGo8jerAno9zrSkvy0dzLrdtNLXKh+ zES3WNmWuJRFTYoJ5kmE0Qd/4Eghiq313pN+GyM7G6C6rKAKDYJOBt/S+qBpaNZmdIJj HS04TWkCcHtk01GqwmCukA11r9gxpIGHnxkiyjkIL7KEE/p9RnMqe5JX2fuGcdCXr5+v darA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687824150; x=1690416150; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qg2KUH6YMBj2eN2aEtzkgtiYkQL1wDcya22Dq84KAL0=; b=hmiYJZgNm4agJpZBMuyDOuSY+6xbjYhWU6Kq4DBb9eDxu/qJgpKtNPTIvlSYEVJrIQ vD5eF+hIScDCLSNLYzxpqsjnXE46ELR94+zDazr0084LkO0VNGcWhlLjZA/jufKNQ8/M bi4mFRhqJLe7S9dKmDV3gNP256gr+SYgDkIrAPSX3ieeF7iJcFuRZDsblZnH4jd6V8Tu 1t5bl1u1WBQYROmb6MHYNKtO6xZa9ZilEgZsH2PllNsFy7DwJf9hPqPdnUKlp1h0IQgz 7oBDhLpxmhioePeYezGaxOHDwwFPYV9zk1Ym88fT+O/5sL8Zy2H1GGpA0kpNWzFiduj+ xpCQ== X-Gm-Message-State: AC+VfDwKwEMX6Zs39j2+yR68xogVfxTq3QspAAwup/vzo7UCiEps0YAb d+/ZOYo9GZXtYqBi2e5tMls= X-Google-Smtp-Source: ACHHUZ4gqFGGIbB8wJk/toxi8obZ6ktxvt7geu159xIwH2eJFNvwUssm2izOVDiVcBkitWUuwXJYPQ== X-Received: by 2002:a92:cc0b:0:b0:343:47fb:e68a with SMTP id s11-20020a92cc0b000000b0034347fbe68amr23232190ilp.26.1687824150172; Mon, 26 Jun 2023 17:02:30 -0700 (PDT) Received: from google.com ([2601:647:6700:7f00:83fb:9433:2220:da46]) by smtp.gmail.com with ESMTPSA id e13-20020a62aa0d000000b0067526282193sm2770730pff.157.2023.06.26.17.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 17:02:29 -0700 (PDT) Date: Mon, 26 Jun 2023 17:02:27 -0700 From: Namhyung Kim To: James Clark , Ian Rogers Cc: linux-perf-users@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 2/2] perf report: Don't add to histogram when there is no thread found Message-ID: References: <20230626161059.324046-1-james.clark@arm.com> <20230626161059.324046-3-james.clark@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230626161059.324046-3-james.clark@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230626_170231_572947_118266C8 X-CRM114-Status: GOOD ( 20.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jun 26, 2023 at 05:10:58PM +0100, James Clark wrote: > thread__find_map() chooses to exit without assigning a thread to the > addr_location in some scenarios, for example when there are samples from > a guest and perf_guest == false. This results in a segfault when adding > to the histogram because it uses unguarded accesses to the thread member > of the addr_location. Looking at the commit 0dd5041c9a0ea ("perf addr_location: Add init/exit/copy functions") that introduced the change, I'm not sure if it's the intend behavior. It might change maps and map, but not thread. Then I think no reason to not set the al->thread at the beginning. How about this? Ian? (I guess we can get rid of the duplicate 'al->map = NULL' part) Thanks, Namhyung ---8<--- diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 3860b0c74829..4cbb092e0684 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -581,15 +581,14 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, maps__zput(al->maps); map__zput(al->map); thread__zput(al->thread); + al->thread = thread__get(thread); al->addr = addr; al->cpumode = cpumode; al->filtered = 0; - if (machine == NULL) { - al->map = NULL; + if (machine == NULL) return NULL; - } if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { al->level = 'k'; @@ -605,7 +604,6 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, al->level = 'u'; } else { al->level = 'H'; - al->map = NULL; if ((cpumode == PERF_RECORD_MISC_GUEST_USER || cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && @@ -619,7 +617,6 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, return NULL; } al->maps = maps__get(maps); - al->thread = thread__get(thread); al->map = map__get(maps__find(maps, al->addr)); if (al->map != NULL) { /* _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel