Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1465321pxu; Tue, 24 Nov 2020 00:23:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7tlx8+AvmoHKF1EBI4nZqUW+hhyShnYhU2QmOnSCxr6WEVOPMZ2SGvfq3ZUHJPOxGWSAl X-Received: by 2002:a17:906:614a:: with SMTP id p10mr3092792ejl.312.1606206207890; Tue, 24 Nov 2020 00:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606206207; cv=none; d=google.com; s=arc-20160816; b=E25bc0Ys7Y04gQT03ghf/xTlRDlhduNRpOwiRyVfyA9LifYn4KSg4AbSFs68wJZdSB nzgnFz96/plGb5rPk4Af4im1jfhRYrwr15zixeKwdUsEds0sbZo6tcpBl0ViTax9HW81 3DW7uvEj/+kqNEcyolMdcCueVDbq2kISRfGlhdcrG8M6AE6CgZBKmJujjpEwP6g/A8KA qNozor3/v1mqua4IpUCY1tzjvEh9/MUxr5DxVRhoHpQc/7x1XxNXHc8DifcFrSgXrK+/ vkuoo0uIneDUmhqOvbn7prb2n8AXi5YuFa4WtdAdoLoWMU0ywYJTAN9kKAmZ2B8CjGbc w8wg== 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=K3xcx/XNvUUEkkmaeMwDoHzUGPahNqFhDIslBuRSBVM=; b=lXeJc6EzhuNMhwScr03km7Pw55LLfEPXa8CiKsD5AIpPqAoBMuMJJ5rCa3JLMn1hik QWgiFhiKJUEuVpF8cGcQTPA5qibNovjhbpHeMvIHoF3BTp3MqtW3OCXv6qqEt9T5+F8l LnNC2Yoin32XcUVGlcx4kRIPR+aGCNqKPi/vy2ejC9YdEmWIZAiVk9FtdiPUeX4oY3pw 97bIVaf3eGhapeZNOdK4ien+EpAukLoa4mi01V+TWKjf2Lci/ajNXq37s98Jpd7m3omC axwW4k0j+Q9SOFznYqK4zveBPck4EMsbnwZ3G+gYY0kt4YjEEh/nvmArIvCZBUMeU92g xnkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HU5h4FoT; 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 bx12si8409834edb.10.2020.11.24.00.23.04; Tue, 24 Nov 2020 00:23:27 -0800 (PST) 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=HU5h4FoT; 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 S1730423AbgKXITr (ORCPT + 99 others); Tue, 24 Nov 2020 03:19:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730248AbgKXITr (ORCPT ); Tue, 24 Nov 2020 03:19:47 -0500 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC1B8C0613CF for ; Tue, 24 Nov 2020 00:19:46 -0800 (PST) Received: by mail-yb1-xb32.google.com with SMTP id v92so18513191ybi.4 for ; Tue, 24 Nov 2020 00:19:46 -0800 (PST) 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=K3xcx/XNvUUEkkmaeMwDoHzUGPahNqFhDIslBuRSBVM=; b=HU5h4FoTU5Rf/b1LZ7w6tJY1r25Jjt3sn4biy8QhE2DKhC7iFKJRIs5VCCaLXaN4Yc 4UzPVloq754+B+K2VlRUclv8vQSp+qg9brJYKBgUjOmyEv7/rTlcG3pqQqXMXQ8Au3+v BlT+d7Yw7uFm36PspPOxSTtO6qlv+e6wf/0YLJFE3VKwVPtGDX9F3x2TNICHWEMYF61e PaMUURfE4/FJG1d7KyGal0kxnAatqnV5SIQkQiTSYfEx/ffV/MDa2oalX3/PZ++98YAT 38BwTxDUklW8VfqT4xD374cajoDRLRa9V74ze2gZbR1HaOt11qkOISy1j2ls0mP3xck2 UCGA== 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=K3xcx/XNvUUEkkmaeMwDoHzUGPahNqFhDIslBuRSBVM=; b=RiHwUKQ8Kn4NspPTf6+J4q7ocAW1cyb5jKFHWqVgWPZNM8OMSJzyOR+maw725RrByW GfIeRTJeyZj66gDW3nuzgwjPYYjfE4ijFRdHlMKv+HT1Lmew8wv5WE2nLw9XxuReAwEq 3AuAZVskQ7+OCwR0dDe44mFN7QTDBk7mX2FZEj3SIkV0grm9InTcJnl0QS2V00/SZaV0 sb0laJIm9kBF+C33DkgOsFvBfiUi+Yz9pJkbIXYBBDn5eN5zGkeM5myUsH97P2qR3vAr 3uW+J5o5HPIa5jfAeRnw1ZjYSMj/oJN14dK/Vs1rL8yvlK7zHe2wGwI7mfZo9EI8emdh yaAg== X-Gm-Message-State: AOAM530PhKCAF6LhBKg5Icq782esOsccWGFxCIHSfEyFQtbYzjp9uyN7 YLSapuFsB+Yi3gRAhqKgptIh3GO3hzGcgV7Kpy+z1WH2ruQHiA== X-Received: by 2002:a25:20d5:: with SMTP id g204mr4012344ybg.136.1606205985906; Tue, 24 Nov 2020 00:19:45 -0800 (PST) MIME-Version: 1.0 References: <20201121025011.227781-1-namhyung@kernel.org> <20201123142321.GP3021@hirez.programming.kicks-ass.net> <20201124080951.GE2414@hirez.programming.kicks-ass.net> In-Reply-To: <20201124080951.GE2414@hirez.programming.kicks-ass.net> From: Stephane Eranian Date: Tue, 24 Nov 2020 00:19:34 -0800 Message-ID: Subject: Re: [RFC] perf/x86: Fix a warning on x86_pmu_stop() To: Peter Zijlstra Cc: Namhyung Kim , Ingo Molnar , Borislav Petkov , Thomas Gleixner , "H. Peter Anvin" , x86 , LKML , Kan Liang , John Sperbeck , "Lendacky, Thomas" , Andi Kleen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Another remark on the PEBS drainage code, it seems to me like a test is not quite correct: intel_pmu_drain_pebs_nhm() { ... if (p->status != (1ULL << bit)) { for_each_set_bit(i, (unsigned long *)&pebs_status, size) error[i]++; continue; } The kernel cannot disambiguate when 2+ PEBS counters overflow at the same time. This is what the comment for this code suggests. However, I see the comparison is done with the unfiltered p->status which is a copy of IA32_PERF_GLOBAL_STATUS at the time of the sample. This register contains more than the PEBS counter overflow bits. It also includes many other bits which could also be set. Shouldn't this test use pebs_status instead (which covers only the PEBS counters)? if (pebs_status != (1ULL << bit)) { } Or am I missing something? Thanks. On Tue, Nov 24, 2020 at 12:09 AM Peter Zijlstra wrote: > > On Tue, Nov 24, 2020 at 02:01:39PM +0900, Namhyung Kim wrote: > > > Yes, it's not about __intel_pmu_pebs_event(). I'm looking at > > intel_pmu_drain_pebs_nhm() specifically. There's code like > > > > /* log dropped samples number */ > > if (error[bit]) { > > perf_log_lost_samples(event, error[bit]); > > > > if (perf_event_account_interrupt(event)) > > x86_pmu_stop(event, 0); > > } > > > > if (counts[bit]) { > > __intel_pmu_pebs_event(event, iregs, base, > > top, bit, counts[bit], > > setup_pebs_fixed_sample_data); > > } > > > > There's a path to x86_pmu_stop() when an error bit is on. > > That would seem to suggest you try something like this: > > diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c > index 31b9e58b03fe..8c6ee8be8b6e 100644 > --- a/arch/x86/events/intel/ds.c > +++ b/arch/x86/events/intel/ds.c > @@ -1945,7 +1945,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d > if (error[bit]) { > perf_log_lost_samples(event, error[bit]); > > - if (perf_event_account_interrupt(event)) > + if (iregs && perf_event_account_interrupt(event)) > x86_pmu_stop(event, 0); > } >