Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2229863lqo; Mon, 13 May 2024 11:31:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPfiNQCUNsvNnYc2OfZJVzzInMnpIXHJBEbM2k3NROSFZG4HyrS9/2QxmplTaFJc0SwlYywCY7mZl8RkZfg6misoHDato1fHYPuQr8hQ== X-Google-Smtp-Source: AGHT+IF4VNN/hSC5agULi7JNXt6xkCAyqWQlm6E5/SnHOR4ix8bp33O2VNhH91Umb8BfqpcWywil X-Received: by 2002:a05:6214:5a02:b0:6a0:e9e3:7721 with SMTP id 6a1803df08f44-6a16824d04dmr137504726d6.60.1715625117831; Mon, 13 May 2024 11:31:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715625117; cv=pass; d=google.com; s=arc-20160816; b=hwsoTyc4mNrGJpaxICjpCgrxJOftcHMBPRW6t1HSEfXBV60W1QGMAPYzzyBbpheD6Y JsNq0PprsT3rsm+npEv7JP4CNbnT4WuyFUzYIz5/c2TVxMIe+LgPbtGkOX9mMY78C8QR 2+5U8g46FqDpGZkI16MklkhTLN0lTSiairYzatC2Zd0grFUdxplHppEnOwQblvDe5BjY aSgCIrJcVWObsC+JTJYsyjpMBnQK1iGLAbvvNhW6k/ImG3NMZs2AR0YBdtBuLHeZg+6k BDn1pjJyABybHO4Nkq9c+iFJtwqIny9m7AOG7sxCj519B7csl4a5OGiAO7zWKRR/CC4C 6qrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Dp4o1bBP9g8nSA2c4EpHf9/XklxFDXV2HdHmWJKkIqw=; fh=1lDq4esp0kX2AK6XGLqF+E/9X+vhu2dj80/w5Mn4Dvo=; b=T9XYQErSv/c/2dq1cMYAFKD8TanJjotuaS8Z8E/qQrgO5nKmS3jwzlMEMsIAKrK1S3 mfgrfXb4v3DLr1ND4gkReLJzx7mImTBmhIIrIUPzFiOChgOmqxSVp5mZVivCGxpqqjK6 kTruNGMl7RAjlqvbf0g3WxlTuS5odAgK5kBUMbXe25wGEU2JavMR9AL+o3Ucbv2tx21/ hW4MMocNbD+Q+/DOA0IpYeFsGxuC4jb5dpbgChsauZirCl+fNBAHNWPgTvSs0xf0yxJR dwbJPGkT9XZw23XgARAV4r7f1D1uzGZpNyu3w94pwgbhVelSxeqAyWDryJ8nIbFCtfL8 ufPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e7elEJH7; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-177964-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177964-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f3053efsi73545136d6.565.2024.05.13.11.31.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 11:31:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177964-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e7elEJH7; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-177964-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177964-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7D22C1C2145E for ; Mon, 13 May 2024 18:31:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7658F37144; Mon, 13 May 2024 18:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="e7elEJH7" Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 EB3EA37147 for ; Mon, 13 May 2024 18:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715625110; cv=none; b=OqMY8/sE+C3BQwrLb7/pDfbGBkE5JgfCEKv//Jhawg3VKiNxhtEIvSPszdCkc5IFmgc33KuZcrBSNJhtPq/Wxvd0CHU32ynYMsL0oz6aqJ+KPh/bCxl0zCqc7TmUCxezsm7AamL7HCReFxe6WbMz5e+mIHhbUJdATLivsR/+P/k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715625110; c=relaxed/simple; bh=3ZwAB8Y8ZUIyGagmA9bMT/46c3bkaZgO1OCbdjLIhQU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sd8pz56DXU0sC+w8lX4QXJaCplRslmOtTtocLVCwVbuiBM/Lj7aBK7V8o8Ns+0ICQag/kWHVIE1PQLnLTLM4VswaLIc3lfQMex2tC1s8dAXQtdUYY9msYDwuLRzfkhFngCJVaHbloayYIGwEvO/QXFUKmXOebKlKxzEedsQYywc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=e7elEJH7; arc=none smtp.client-ip=209.85.208.52 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=google.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-572a1b3d6baso20476a12.1 for ; Mon, 13 May 2024 11:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715625107; x=1716229907; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Dp4o1bBP9g8nSA2c4EpHf9/XklxFDXV2HdHmWJKkIqw=; b=e7elEJH7NOwhPMOzmp2ISWNlOFIKZWQBH6O7f+CBhbdgjXHnDT53uh1VqoCJxStsxV FLUdMPezoowxy5UPF4fY1DKDHalQPgNCH5kc3tmcjnK9AXGdQ4SNf/N/ENGIhmsy3mcX wGPqDNgobmMVZzQaU6C1rAUf16YaQy29ZzCPpZI5LvdP7Zuj8zxuF4ojMtj/3KzUqrlI YbYv0F1fC0D48FBi95iys9tTQPNT/fB7aEmdfLiTRQtCBTIi2zNntR0TZ/z9snMIfOPw 7mYccyYxVEzvQXWtcsHweUE8B5s6aKSgWfvxP6juK+3L/4MJ6dIbnhR6abjwntYhiU/F LkLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715625107; x=1716229907; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dp4o1bBP9g8nSA2c4EpHf9/XklxFDXV2HdHmWJKkIqw=; b=NubhY8tCOh3NcuBGdH0/X8YFy1wbKUvvNl4Jp3Y6uJKxs5hGsiovZyuuL5P7fJzDAq +cFznJ/aqaJFTB3oncBMObuoMGgTlatQY4qJzTLdQdjXJcgq2xsFGZ/FTss8AsRccBVb GgfLIQ1T1MomC7WAiFSPbm69B0Vwc6MEbWBjU4FzptGa5dIt6ie2CdYmtI+9hULsZKOY revJriyQlhUsQ4mivvDnTxsVfPT6UqCOhKXWzayc9D2vR1dX2VRuNhhY3HuYyD8+O+vd Ock4FtB5FZ1Fi9EH+iN8k9qc7qMrc2iPHF42o5ezsohFvMY4a7vsve6HEQDLiCFLSWdJ dkSA== X-Forwarded-Encrypted: i=1; AJvYcCVUvX+DNkJ6weMU3pZM06iaoYqXEVWpXyFBNbRQ/ZndyqZCCTvFR/uNE4bQ5qawJqo5rhaWFTsjeZpuGinC6irjI2gZgwvevDQoOob1 X-Gm-Message-State: AOJu0Yzd0YuKO++Nur7dlegmfWVT84mJdQjCLIzYYQhgVDqZvi/H2Bhb 92Qz8aaQo/doE1iU9JEtnD8AJepdc7Rft2s+Q1MhLvkkP17LiDMUiEuV+gkXDujxVBs4WjW8JrS EMwD0CYKAB+Z2LDgT9JDpzuo1j1CzMLWlK/A= X-Received: by 2002:a50:cc0c:0:b0:572:9eec:774f with SMTP id 4fb4d7f45d1cf-57421846490mr416314a12.0.1715625106955; Mon, 13 May 2024 11:31:46 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240510191423.2297538-1-yabinc@google.com> <20240510191423.2297538-4-yabinc@google.com> In-Reply-To: From: Yabin Cui Date: Mon, 13 May 2024 11:31:34 -0700 Message-ID: Subject: Re: [PATCH v4 3/3] perf/core: Check sample_type in perf_sample_save_brstack To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable arch/powerpc/perf/core-book3s.c checks sample_type, see if (event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK) { ... perf_sample_save_brstack(&data, event, &cpuhw->bhrb_stack, NULL); } So I think we don't need the "fixes:" line. On Fri, May 10, 2024 at 2:30=E2=80=AFPM Namhyung Kim = wrote: > > On Fri, May 10, 2024 at 12:14=E2=80=AFPM Yabin Cui wr= ote: > > > > Check sample_type in perf_sample_save_brstack() to prevent > > saving branch stack data when it isn't required. > > > > Suggested-by: Namhyung Kim > > Signed-off-by: Yabin Cui > > It seems powerpc has the similar bug, then you need this: > > Fixes: eb55b455ef9c ("perf/core: Add perf_sample_save_brstack() helper") > > Thanks, > Namhyung > > > --- > > arch/x86/events/amd/core.c | 3 +-- > > arch/x86/events/core.c | 3 +-- > > arch/x86/events/intel/ds.c | 3 +-- > > include/linux/perf_event.h | 13 ++++++++----- > > 4 files changed, 11 insertions(+), 11 deletions(-) > > > > diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c > > index 985ef3b47919..fb9bf3aa1b42 100644 > > --- a/arch/x86/events/amd/core.c > > +++ b/arch/x86/events/amd/core.c > > @@ -967,8 +967,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *re= gs) > > if (!x86_perf_event_set_period(event)) > > continue; > > > > - if (has_branch_stack(event)) > > - perf_sample_save_brstack(&data, event, &cpuc->l= br_stack, NULL); > > + perf_sample_save_brstack(&data, event, &cpuc->lbr_stack= , NULL); > > > > if (perf_event_overflow(event, &data, regs)) > > x86_pmu_stop(event, 0); > > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c > > index 5b0dd07b1ef1..ff5577315938 100644 > > --- a/arch/x86/events/core.c > > +++ b/arch/x86/events/core.c > > @@ -1702,8 +1702,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) > > > > perf_sample_data_init(&data, 0, event->hw.last_period); > > > > - if (has_branch_stack(event)) > > - perf_sample_save_brstack(&data, event, &cpuc->l= br_stack, NULL); > > + perf_sample_save_brstack(&data, event, &cpuc->lbr_stack= , NULL); > > > > if (perf_event_overflow(event, &data, regs)) > > x86_pmu_stop(event, 0); > > diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c > > index c2b5585aa6d1..f25236ffa28f 100644 > > --- a/arch/x86/events/intel/ds.c > > +++ b/arch/x86/events/intel/ds.c > > @@ -1754,8 +1754,7 @@ static void setup_pebs_fixed_sample_data(struct p= erf_event *event, > > if (x86_pmu.intel_cap.pebs_format >=3D 3) > > setup_pebs_time(event, data, pebs->tsc); > > > > - if (has_branch_stack(event)) > > - perf_sample_save_brstack(data, event, &cpuc->lbr_stack,= NULL); > > + perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL); > > } > > > > static void adaptive_pebs_save_regs(struct pt_regs *regs, > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > index 8617815456b0..ecfbe22ff299 100644 > > --- a/include/linux/perf_event.h > > +++ b/include/linux/perf_event.h > > @@ -1269,6 +1269,11 @@ static inline void perf_sample_save_raw_data(str= uct perf_sample_data *data, > > data->sample_flags |=3D PERF_SAMPLE_RAW; > > } > > > > +static inline bool has_branch_stack(struct perf_event *event) > > +{ > > + return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK; > > +} > > + > > static inline void perf_sample_save_brstack(struct perf_sample_data *d= ata, > > struct perf_event *event, > > struct perf_branch_stack *b= rs, > > @@ -1276,6 +1281,9 @@ static inline void perf_sample_save_brstack(struc= t perf_sample_data *data, > > { > > int size =3D sizeof(u64); /* nr */ > > > > + if (!has_branch_stack(event)) > > + return; > > + > > if (branch_sample_hw_index(event)) > > size +=3D sizeof(u64); > > size +=3D brs->nr * sizeof(struct perf_branch_entry); > > @@ -1665,11 +1673,6 @@ extern void perf_bp_event(struct perf_event *eve= nt, void *data); > > # define perf_arch_bpf_user_pt_regs(regs) regs > > #endif > > > > -static inline bool has_branch_stack(struct perf_event *event) > > -{ > > - return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK; > > -} > > - > > static inline bool needs_branch_stack(struct perf_event *event) > > { > > return event->attr.branch_sample_type !=3D 0; > > -- > > 2.45.0.118.g7fe29c98d7-goog > >