Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1246423rwb; Thu, 6 Oct 2022 10:15:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xvXh2gh7N2cQ1blppC8p0ZHa1Qgt+GhI6sfdlXpPMhNGx0AA0+afu2AMfJiM5+5miEWbw X-Received: by 2002:a05:6402:1686:b0:459:4ddf:8f05 with SMTP id a6-20020a056402168600b004594ddf8f05mr747014edv.375.1665076514702; Thu, 06 Oct 2022 10:15:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665076514; cv=none; d=google.com; s=arc-20160816; b=YutfvmowHqRNq9I2d5murxfjzKNVshdlryEEA7ZbvajAkDVzbUwse3CykP1J1kfHUr CraXKV0lLGIUeGNzr1+MrkEu58rhX+nAmk1hEC3b9dCY8wgMyAg8uTfGgAi0MrkkfZwG K60+Gl9TrZ/Lnl1tXeNtzUfD9t2xRP7zrmZh8Z6zq0+bcGXQbsQBTNqijcK3AhYHv627 buRyiklv2DHq+imRuRRCw/yq9aUmBApHsQeQRupHoeuCBghO7EIV6VuS4Oq6w64ZIWdH GyxOHg61+iZz442avOkHirMakFaXhoVCVaisBMEbVhbt4BJkJnC0xCM7DwtlUcVXy+5I Y+dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=HtuVKtBzoKt+jjbMVURehUv1VCPg1XF6D/AE8RGN56s=; b=SKCXlSWr+XPc5eBz+NK/IvwJDLb5rnBOoyY7rN584+Ob2MHF9O2WRtjI+i/vkp8AXp wfX0YCOEwGuiUlAxAhnaZuE97v4mNgVMuro4EcGnJuqqiwDEMmDlDW0ok13wWdwZI+iY DOG4dl4Q9A2TSFVNT8vctvRNpdYFVNYoagU+jwWAGv4QoJqMsJgmNRiplJDb9KP1tB/Y Sl4T+xymL2hzaeByWHsu14MelhYBwHyjoFEptpaJ+k3J52mDfNuHkmlYCRvZWK28x0NX jlDNS4wCKSnSxo29MRNNs/r4nc9lJVvlAVuCmDmSb+Rf2aVIap8sZ6jsWb4+zJYM7+WK a0cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a056402520f00b00442785a4226si20348726edd.258.2022.10.06.10.14.46; Thu, 06 Oct 2022 10:15:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbiJFRNa (ORCPT + 99 others); Thu, 6 Oct 2022 13:13:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231829AbiJFRNI (ORCPT ); Thu, 6 Oct 2022 13:13:08 -0400 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68908BBE12; Thu, 6 Oct 2022 10:12:50 -0700 (PDT) Received: by mail-oo1-f51.google.com with SMTP id q70-20020a4a3349000000b0047f9951ad3aso1314922ooq.7; Thu, 06 Oct 2022 10:12:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=HtuVKtBzoKt+jjbMVURehUv1VCPg1XF6D/AE8RGN56s=; b=LqNjXvS8jqmHA1KhM7v3sX2YNUvNNsUWLvJMigBpbVkVKRHWewXWsdk3LSKh+QdCL9 fEpvq9DF6paP7FlIwMoyzsVCm4sXEiWRq2PEEbRjQe3Q1LcdzD/y7Zqtk0NbkGWLAv9Y bZxuogNajNnMh7Awq91ab8D0F8PJ+C9kor3JUs3Apx+cHx0LQvO205N7sV7ob6uUkg+1 HFIq7i4KcgBFWWFjE9lAocSgSDBGx0lPEtxjZv8PLj15uKD348Dl3cLlLc7/xPnCVtiX dOstUM/4xY56J2hM0/D6JR7l4DpgHbDQgA7+VUdJOQLjZ7fW0PYWF3kxbVsPF+wwHRdS t0ig== X-Gm-Message-State: ACrzQf163HOeVONRNG91L+1WLghWezPZbwkP5icZouonBG6AT3BrAouB YrUy71nw2Hth3NIHskdFxEyayHnxS/0elWWKKyA= X-Received: by 2002:a05:6830:621a:b0:660:dd14:c2f4 with SMTP id cd26-20020a056830621a00b00660dd14c2f4mr408265otb.190.1665076370095; Thu, 06 Oct 2022 10:12:50 -0700 (PDT) MIME-Version: 1.0 References: <166434824149.401.4361243714612738808.tip-bot2@tip-bot2> <20221006160044.3397237-1-sumanthk@linux.ibm.com> In-Reply-To: <20221006160044.3397237-1-sumanthk@linux.ibm.com> From: Namhyung Kim Date: Thu, 6 Oct 2022 10:12:37 -0700 Message-ID: Subject: Re: [PATCH] Re: [tip: perf/core] perf: Use sample_flags for raw_data To: Sumanth Korikkar Cc: tip-bot2@linutronix.de, linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org, peterz@infradead.org, x86@kernel.org, iii@linux.ibm.com, gor@linux.ibm.com, hca@linux.ibm.com, svens@linux.ibm.com, tmricht@linux.ibm.com, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Thu, Oct 6, 2022 at 9:01 AM Sumanth Korikkar wrote: > > Hi, > > This causes segfaults. > > Steps to recreate: > * Run ./samples/bpf/trace_output > BUG pid 9 cookie 1001000000004 sized 4 > BUG pid 9 cookie 1001000000004 sized 4 > BUG pid 9 cookie 1001000000004 sized 4 > Segmentation fault (core dumped) > > Problem: > * The following commit sets data->raw to NULL, when the raw data is not filled > by PMU driver. This leads to stale data. > > * raw data could also be filled by bpf_perf_event_output(), bpf_event_output() > ... > 686 perf_sample_data_init(sd, 0, 0); > 687 sd->raw = &raw; > 688 > 689 err = __bpf_perf_event_output(regs, map, flags, sd); > ... > > * The below patch eliminates segfaults. However, contradicts with > the description mentioned in this commit (Filled by only PMU driver). Thank you for the fix. Don't worry about the description - it said it's usually filled by PMU drivers and it should be fine as long as you set the sample flags after filling the raw data. Acked-by: Namhyung Kim Thanks, Namhyung > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 49fb9ec8366d..1ed08967fb97 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map, > > perf_sample_data_init(sd, 0, 0); > sd->raw = &raw; > + sd->sample_flags |= PERF_SAMPLE_RAW; > > err = __bpf_perf_event_output(regs, map, flags, sd); > > @@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size, > perf_fetch_caller_regs(regs); > perf_sample_data_init(sd, 0, 0); > sd->raw = &raw; > + sd->sample_flags |= PERF_SAMPLE_RAW; > > ret = __bpf_perf_event_output(regs, map, flags, sd); > out: > > -- > Thanks, > Sumanth