Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4465047pxf; Tue, 16 Mar 2021 14:21:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytGS5D6VfHvZ2kVSZH+6pyfODO9pQ3gDw0927jweYsP7EAwSrRIi7Qau/WjdmQEb/MQkX/ X-Received: by 2002:a17:906:d0c3:: with SMTP id bq3mr31251679ejb.424.1615929663854; Tue, 16 Mar 2021 14:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615929663; cv=none; d=google.com; s=arc-20160816; b=Ty8iCRHCSYqrx9dWosTw51y+BlAFWvvgX/twdyqbg0xhqrt7axXCdGtgaH/62Nw3gk hmnFxtrPMmagDkVcZYEcrcAG6xr/w0tgNBygLUbozYSSK/Qno/xGA2W98zgX5VJasAGq ghdHx0EcNl8mnD404oVI75P5c3fKi37733IUR8NX8KFQL02GuXFPY5DmWpV/y/u5HZC5 IYxuJDkeblUtYaWtHKtHaPg9KIoyp9q2ScYV9fpqT8gqMjy5Vq6kPY/WAcEIXwfgQRuA 2zyHbXiWs5OGQx4rIohEeR/EA/Y+YcRgfZ3zzZh/fEori8ywmXbY0zRTX0RuV57JzqKE T6RQ== 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:dkim-signature; bh=Qx/er8fuhccr8BguU05iUFAp9XjYjtQPScA2OOEYemk=; b=qGDpr9EU18U08w62qdte7NWxoVv3zcL9CbGcfJTHnI4O4QigSVgBPT4r7yz4sE+Ta7 POLDR8x8+aRHDGVJUFL0a1efXIoE5rN1enuTa2PkxgM0uDQ64NuL4o7/sKr1hxsswQ8s NVxQBc0uOtlG+4Vvi57MMGTQ42XvgZXtd0+v4q3FqPDolT1CsUXoH+JIlOWFjpryjFDT 6yhEtiBquIxhrqNKsp1rDZkwO53jiXexHdneTCu+KniIRSEubrQ7o/z/7SCSHnqF+i2k rkvGYB565evTDXkP2ZKLOweSsc5PnN5TawgyKDu/Kx64PGS3IwKaCiyf+HCry/aOs8+k ZwUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W7nFX+hD; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de53si15136606ejc.358.2021.03.16.14.20.18; Tue, 16 Mar 2021 14:21:03 -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=@google.com header.s=20161025 header.b=W7nFX+hD; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240028AbhCPSfD (ORCPT + 99 others); Tue, 16 Mar 2021 14:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240044AbhCPSeg (ORCPT ); Tue, 16 Mar 2021 14:34:36 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88D6AC06174A for ; Tue, 16 Mar 2021 11:34:35 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id w203-20020a1c49d40000b029010c706d0642so4292956wma.0 for ; Tue, 16 Mar 2021 11:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Qx/er8fuhccr8BguU05iUFAp9XjYjtQPScA2OOEYemk=; b=W7nFX+hDSdd/0Gd1vIUso7G7eQ2pBaifnzTW/HFzXSIobmLXzfjj7sBaepS+Mkg+Hb OT+KJAc2fDar+48mhpa/WZv0NyOFbiB5H5YKGpWzRy8K2cDsLPjqhdtt7UWUglVWEglY aVhn/VAYwMVPreT1Y6+JncD4cpE+duPK1wIiZgiZrsbRKCwMIE1jOjacEIOr22F/POCR gMjd6NYaoJHFMZ0INDAfFWYEmh/XA3svo9gmma7FChxozGmF5HfmF+/Aye2l94pIPxwe ssH49uIMzv4J4jSsfFfXY4wGEyDdF70zxf2ffdlzzhGsBI9mM1Y24dfAjbtgAqJ2Zepw 2SpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Qx/er8fuhccr8BguU05iUFAp9XjYjtQPScA2OOEYemk=; b=YwEZh8iu/LHg/my80gYDTn/8W6vaskvSF6ju/uTGhUdWuHGRKHZYnDSi7LIXCmUXcu bgOxncVaHY7SPz5kq9ajWIDDqHH/2sMsZMU5ngatciZg74xL1tGh38WrLahZDYHe8rn+ bg3MIjEcVnTjUO9GQKGhI/elbinqtUuap+wofKVcPaIQYENs2ut8mGuVZq2auNbnvghC LiwmC3S83nKjAQ3OHhjHINFpX/cPYIJlzwTbu2R1j/YuH4ENlbe3r5exvzNgZ+xjvVeU qCQLX0Cp42aF7hnu4ufoD/O5M/oUzASzbDhmbjDFjQ46qtwYfIyO5reqzi+A27/QwoVx Tqqw== X-Gm-Message-State: AOAM531ig1r/rgOAMSp1/MOgjZFJngREnUYXAGXvN4fcInXAbn/EyvFy dehVUZlMG3rSVs3cd5Uw43RQARK2P78th7VQFhLDdg== X-Received: by 2002:a1c:3d46:: with SMTP id k67mr197595wma.188.1615919674161; Tue, 16 Mar 2021 11:34:34 -0700 (PDT) MIME-Version: 1.0 References: <1614778938-93092-1-git-send-email-kan.liang@linux.intel.com> <9484ab6e-a6e5-bb72-106f-ed904e50fc0c@linux.intel.com> In-Reply-To: From: Stephane Eranian Date: Tue, 16 Mar 2021 11:34:22 -0700 Message-ID: Subject: Re: [PATCH] Revert "perf/x86: Allow zero PEBS status with only single active event" To: "Liang, Kan" Cc: Namhyung Kim , Peter Zijlstra , Vince Weaver , Ingo Molnar , linux-kernel , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Andi Kleen , "stable # 4 . 5" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021 at 5:28 AM Liang, Kan wrote: > > > > On 3/16/2021 3:22 AM, Namhyung Kim wrote: > > Hi Peter and Kan, > > > > On Thu, Mar 4, 2021 at 5:22 AM Peter Zijlstra wrote: > >> > >> On Wed, Mar 03, 2021 at 02:53:00PM -0500, Liang, Kan wrote: > >>> On 3/3/2021 1:59 PM, Peter Zijlstra wrote: > >>>> On Wed, Mar 03, 2021 at 05:42:18AM -0800, kan.liang@linux.intel.com wrote: > >> > >>>>> +++ b/arch/x86/events/intel/ds.c > >>>>> @@ -2000,18 +2000,6 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d > >>>>> continue; > >>>>> } > >>>>> - /* > >>>>> - * On some CPUs the PEBS status can be zero when PEBS is > >>>>> - * racing with clearing of GLOBAL_STATUS. > >>>>> - * > >>>>> - * Normally we would drop that record, but in the > >>>>> - * case when there is only a single active PEBS event > >>>>> - * we can assume it's for that event. > >>>>> - */ > >>>>> - if (!pebs_status && cpuc->pebs_enabled && > >>>>> - !(cpuc->pebs_enabled & (cpuc->pebs_enabled-1))) > >>>>> - pebs_status = cpuc->pebs_enabled; > >>>> > >>>> Wouldn't something like: > >>>> > >>>> pebs_status = p->status = cpus->pebs_enabled; > >>>> > >>> > >>> I didn't consider it as a potential solution in this patch because I don't > >>> think it's a proper way that SW modifies the buffer, which is supposed to be > >>> manipulated by the HW. > >> > >> Right, but then HW was supposed to write sane values and it doesn't do > >> that either ;-) > >> > >>> It's just a personal preference. I don't see any issue here. We may try it. > >> > >> So I mostly agree with you, but I think it's a shame to unsupport such > >> chips, HSW is still a plenty useable chip today. > > > > I got a similar issue on ivybridge machines which caused kernel crash. > > My case it's related to the branch stack with PEBS events but I think > > it's the same issue. And I can confirm that the above approach of > > updating p->status fixed the problem. > > > > I've talked to Stephane about this, and he wants to make it more > > robust when we see stale (or invalid) PEBS records. I'll send the > > patch soon. > > > > Hi Namhyung, > > In case you didn't see it, I've already submitted a patch to fix the > issue last Friday. > https://lore.kernel.org/lkml/1615555298-140216-1-git-send-email-kan.liang@linux.intel.com/ > But if you have a more robust proposal, please feel free to submit it. > This fixes the problem on the older systems. The other problem we identified related to the PEBS sample processing code is that you can end up with uninitialized perf_sample_data struct passed to perf_event_overflow(): setup_pebs_fixed_sample_data(pebs, data) { if (!pebs) return; perf_sample_data_init(data); <<< must be moved before the if (!pebs) ... } __intel_pmu_pebs_event(pebs, data) { setup_sample(pebs, data) perf_event_overflow(data); ... } If there is any other reason to get a pebs = NULL in fix_sample_data() or adaptive_sample_data(), then you must call perf_sample_data_init(data) BEFORE you return otherwise you end up in perf_event_overflow() with uninitialized data and you may die as follows: [] ? perf_output_copy+0x4d/0xb0 [] perf_output_sample+0x561/0xab0 [] ? __perf_event_header__init_id+0x112/0x130 [] ? perf_prepare_sample+0x1b1/0x730 [] perf_event_output_forward+0x59/0x80 [] ? perf_event_update_userpage+0xf4/0x110 [] perf_event_overflow+0x88/0xe0 [] __intel_pmu_pebs_event+0x328/0x380 This all stems from get_next_pebs_record_by_bit() potentially returning NULL but the NULL is not handled correctly by the callers. This is what I'd like to see cleaned up in __intel_pmu_pebs_event() to avoid future problems. I have a patch that moves the perf_sample_data_init() and I can send it to LKML but it would also need the cleanup for get_next_pebs_record_by_bit() to be complete. Thanks.