From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF14BC433FE for ; Thu, 14 Oct 2021 15:00:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D12B061252 for ; Thu, 14 Oct 2021 15:00:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232964AbhJNPCL (ORCPT ); Thu, 14 Oct 2021 11:02:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:45236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbhJNPAi (ORCPT ); Thu, 14 Oct 2021 11:00:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46DA460E97; Thu, 14 Oct 2021 14:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223499; bh=+FS+DSaHvBRFdlV+bPs/nEteGcnyp+XRRGXvxcq8A4Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fs80OoJK7zKj7vBIloP1Yrm0ms/SUIbK6WwN3rO4PT3tKRhwX+EaN3JolH5/5OIDf Jtb+GoUX3fgcw2XN3x/i+1Z3HeKaPB6vgEFpCUKYh+yszH4ra1xLlnNuxJgyDy4Q7N m8EBXy+8DSLWJg8z5tKrto1GIYQ/1ZjuSUDUPFPs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand K Mistry , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 4.19 11/12] perf/x86: Reset destroy callback on event init failure Date: Thu, 14 Oct 2021 16:54:11 +0200 Message-Id: <20211014145206.919696580@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145206.566123760@linuxfoundation.org> References: <20211014145206.566123760@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anand K Mistry [ Upstream commit 02d029a41dc986e2d5a77ecca45803857b346829 ] perf_init_event tries multiple init callbacks and does not reset the event state between tries. When x86_pmu_event_init runs, it unconditionally sets the destroy callback to hw_perf_event_destroy. On the next init attempt after x86_pmu_event_init, in perf_try_init_event, if the pmu's capabilities includes PERF_PMU_CAP_NO_EXCLUDE, the destroy callback will be run. However, if the next init didn't set the destroy callback, hw_perf_event_destroy will be run (since the callback wasn't reset). Looking at other pmu init functions, the common pattern is to only set the destroy callback on a successful init. Resetting the callback on failure tries to replicate that pattern. This was discovered after commit f11dd0d80555 ("perf/x86/amd/ibs: Extend PERF_PMU_CAP_NO_EXCLUDE to IBS Op") when the second (and only second) run of the perf tool after a reboot results in 0 samples being generated. The extra run of hw_perf_event_destroy results in active_events having an extra decrement on each perf run. The second run has active_events == 0 and every subsequent run has active_events < 0. When active_events == 0, the NMI handler will early-out and not record any samples. Signed-off-by: Anand K Mistry Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20210929170405.1.I078b98ee7727f9ae9d6df8262bad7e325e40faf0@changeid Signed-off-by: Sasha Levin --- arch/x86/events/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 429389489eed..f612eb1cc818 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2096,6 +2096,7 @@ static int x86_pmu_event_init(struct perf_event *event) if (err) { if (event->destroy) event->destroy(event); + event->destroy = NULL; } if (READ_ONCE(x86_pmu.attr_rdpmc) && -- 2.33.0