Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp178541lqo; Thu, 9 May 2024 17:06:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWPRZLayu4eeo/VfoyvEa1Q8bztNoTJ3RJUpBrxHuHeq4I1/hNAVBJIJuuKopvU11L+MUspoBQnQQU3w139ZzO956OkIG1GqT1zUCx4SA== X-Google-Smtp-Source: AGHT+IGJ3W6pT17aNALjO2HgrrkM3oz4oDnN3u7eSzT00+eyrzzAS6aEbCl4RGsAqWIdrEgNfK1r X-Received: by 2002:a17:907:7845:b0:a59:de2e:98e0 with SMTP id a640c23a62f3a-a5a2d65f2c6mr50136866b.56.1715299566464; Thu, 09 May 2024 17:06:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715299566; cv=pass; d=google.com; s=arc-20160816; b=A7X5dZTqOsMrBryCUU7WTqDPolFrrzRk+Vsm40szLTorhQ5y3A9v6ccwqbCTNRGDJw w59xasaJ2tegqJ8Mn+RNCgpsrU+4Fue8cUNk+KuXz6MNwTgRQyAd6QgSNERmqsO2YLSX MtreNwAlgR2spXrdGqEXBGQvyDwpa6N3hs9/YBHKPobFBxA8aVPo4GzJjl1xevt89kDb elx4FGTk2RtGt3KIZ25jfbRZPXy8HqtByun4QNRQwYpVetRGloPkZUjTFrYXCrGWWbP+ Orv0GKvKDFCk4OFyQ/5i7fb5lkctLzqbReHHAYs/cAXzuHRSVE+mWSpKPzST3EhGXBEf oSZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=v9grz5MJy3ZdpaUQrWKUMUhoIXt+TwKDu1fmP3H2Mh8=; fh=c2xSpn3uRyKQRlNbDjCgtLWD2HHrjmelmKrSsEctl6Y=; b=omH8IBgpsDHLzH3QjoipmqkpWOkyMNDpgi3H80Cxwhn/tDVSeGNpdRl/bBX2v/feEm gl2ye4mrbjT592m0KKArWW6NbnoWMe5UXftPSZcPZcMP+Ok/slqTJ89WTUTqm0lyGZSC Apmxa/Xo6CMv08vuNwUX5dhOyLfokfCMm8SMnHR0Coy6/IV4tmPsbhaEmu5TA6Lls1ob LCr1nrroPKBwPYCuGGsQDc2iLcziF5R1JfaUTpwXa8z1JIWken7We5XQWb3ODR0S9lfJ BgK8P6GHOVY5TyhSrkUpmGbpy3nDwmU1BziutRBT24cO9B5abJYYsonw2CdvZxZYFaEF MR8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XTKTDe4E; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175092-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175092-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b21b40si122020966b.416.2024.05.09.17.06.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 17:06:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175092-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XTKTDe4E; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175092-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175092-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3751F1F243D5 for ; Fri, 10 May 2024 00:06:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39330EADB; Fri, 10 May 2024 00:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XTKTDe4E" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA78ADDBC for ; Fri, 10 May 2024 00:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715299521; cv=none; b=Khhg2Pq51NiToAM0Xnbu6E9yfLuVZgD1dXTg/diONZOodx66Zjps1Qa/lWwjzAZzSValEQWE/QFv8Zhouqy7o9qhlSCyGEvD2yNbHqnm5j3DvrjfrPefNydlMmw0VRXgvSBPWtl+6aTvcIgWLPjriLrGQyrABiDRFjB9YpRFHjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715299521; c=relaxed/simple; bh=xySRyI8fWJdGd1hvqSCkes+7dSi689oW4NVcWrWQsMc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j92DMkqgw3iDeALrMj7QZt6ig8nZ4fvK3qck2M+NX+3rNePEUVugD+GtbHPaBs63P0aNM77E4r6ftrJNvTp074MXwcCrABgnmb//NDwqlqoLtv08Hm5nGU3cWpeUv4Qb8YgGeT/+YF5+Kq8tJnTEIn3LAok+rZgIbUMqIQI5DtQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XTKTDe4E; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de8b66d59f7so3234801276.0 for ; Thu, 09 May 2024 17:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715299519; x=1715904319; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=v9grz5MJy3ZdpaUQrWKUMUhoIXt+TwKDu1fmP3H2Mh8=; b=XTKTDe4EPTurS2SKwFqR7PkVU3LvxxYAbu/dK4qgaLimIGi2uGhPId6QkW30uWPen3 izqk7FUkKf2Gq4X2wtdBXyH/vbBFMKgNSaJa5Zw49q8TW4DlJBynlm2vXPq9IdVLGKBc 7An7SPQCVRcLD/VqCM6IpkfwRrKk/ijzi6/AixbBxj/HwfcqlZWs/I0E0tw2HVizMQ7k sqI3blZk+9HtGCE5vOxzOZKJrWb65kq/qODReAEjTYyDbBnSg61200N+Z1y80NKxdcLM w0CKwOkq63Jgkde3Jn2XyUS7ORgQrYPXSZyywLwJjnzmiWvnOcVOltG9khL+h0gP+asz uj3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715299519; x=1715904319; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=v9grz5MJy3ZdpaUQrWKUMUhoIXt+TwKDu1fmP3H2Mh8=; b=sVhA94RA2ToMhxWUI+xmhYpvJd3Ts1iVU8up+wG1nSeu1fJMZBPrtSmNdn1qD0V1x1 18pe+H3rm6tfTwNmSoHwQTjSaSEynfUPfLtOsgs0rASWBzlGevp2nrWCN/YLQYleT6zM ofT7c2ut/PBp8khx9EH1CaiAfcqo3PLkOBygzjgQmN+GAb/JFiDmsdREycp4S45eie0h kEAbnSs2kSyNWsyAXAwikbqEJ1F0mxmtczOBVLA6pumZGl02JvBqST4uXyfGtftqkc6S Edhe3LQsPQV3+CNeO+sKBKLjNilXBJJFCCxiCYdm6O1G2MPeXfn/pCNvvp/x/GR7UmLL VdCA== X-Forwarded-Encrypted: i=1; AJvYcCXUcnhy3n/SjLjN8PYyVO/3WY8wzUS6pDXdT5cXNuD1B/dYMu3qx3rXZNDXyskWmLzJJwXIOKc82Oo7SA/13xJ7gpNTdfXNscN0llcG X-Gm-Message-State: AOJu0Yzuae7pXnPOwYP5vzvDB9fw74kWMzZweWzwIwa+W+u50MZpokfB fBtbXL8TY/2PKjed2K3BbctR1QifUUQh3CCpb03OtPJBPiiqYS5lwszQQbc16J4ZNM9hJtFv96W s X-Received: from yabinc-desktop.mtv.corp.google.com ([2620:15c:211:202:1b7d:8132:c198:e24f]) (user=yabinc job=sendgmr) by 2002:a05:6902:2b03:b0:dd9:20c1:85b6 with SMTP id 3f1490d57ef6-dee4e48f302mr379961276.2.1715299518995; Thu, 09 May 2024 17:05:18 -0700 (PDT) Date: Thu, 9 May 2024 17:05:01 -0700 In-Reply-To: <20240510000502.1257463-1-yabinc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510000502.1257463-1-yabinc@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510000502.1257463-3-yabinc@google.com> Subject: [PATCH v3 2/3] perf: core: Check sample_type in perf_sample_save_callchain From: Yabin Cui To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Yabin Cui Content-Type: text/plain; charset="UTF-8" Check sample_type in perf_sample_save_callchain() to prevent saving callchain data when it isn't required. Suggested-by: Namhyung Kim Signed-off-by: Yabin Cui --- arch/x86/events/amd/ibs.c | 3 +-- arch/x86/events/intel/ds.c | 6 ++---- include/linux/perf_event.h | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index c3a2f6f57770..f02939655b2a 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -1129,8 +1129,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) * recorded as part of interrupt regs. Thus we need to use rip from * interrupt regs while unwinding call stack. */ - if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) - perf_sample_save_callchain(&data, event, iregs); + perf_sample_save_callchain(&data, event, iregs); throttle = perf_event_overflow(event, &data, ®s); out: diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index e010bfed8417..c2b5585aa6d1 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1655,8 +1655,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, * previous PMI context or an (I)RET happened between the record and * PMI. */ - if (sample_type & PERF_SAMPLE_CALLCHAIN) - perf_sample_save_callchain(data, event, iregs); + perf_sample_save_callchain(data, event, iregs); /* * We use the interrupt regs as a base because the PEBS record does not @@ -1823,8 +1822,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, * previous PMI context or an (I)RET happened between the record and * PMI. */ - if (sample_type & PERF_SAMPLE_CALLCHAIN) - perf_sample_save_callchain(data, event, iregs); + perf_sample_save_callchain(data, event, iregs); *regs = *iregs; /* The ip in basic is EventingIP */ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 9fc55193ff99..8617815456b0 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1232,6 +1232,9 @@ static inline void perf_sample_save_callchain(struct perf_sample_data *data, { int size = 1; + if (!(event->attr.sample_type & PERF_SAMPLE_CALLCHAIN)) + return; + data->callchain = perf_callchain(event, regs); size += data->callchain->nr; -- 2.45.0.118.g7fe29c98d7-goog