Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4720807pxb; Thu, 14 Oct 2021 10:35:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5sa/7lpBYcqNpXAae9qZXlvnQkeNkhIo7XoKD2KdgKwPEp3f4hxWLurVWqew7SxW0kINu X-Received: by 2002:a17:906:2757:: with SMTP id a23mr402769ejd.230.1634232922250; Thu, 14 Oct 2021 10:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634232922; cv=none; d=google.com; s=arc-20160816; b=bj53hLZvmjzNVCEooLO7Ve2brFid0XmM2Cmn4soTBbH4NIe6Rbxegk2of4t/qOSPO6 tCG5ogl0DE635QA4Skuoa9MpnJ7R386eTcSrgXW9iULqLXLysDEtYTpagxWJ6gje9YQX lTz+2rR4MLkComhuuTEUfybAeuqBXgoF8w5tH5uqNzhaGnEvtek8B9J3/xRB1FZS/czc iOhGvS0qDXZxZGrTArT+hinf8krpaYTb0RQeb6TozSxYfFu6K/bH3oWyHjcj4Pvs3jMz 8Bb9d7bssN/yvx1bNdHWo6QpACAVgEA2YMOstD3A9vQ6sBaIp7oZ1kTFIIXFZgRhA6LS ggnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eqZ/eFBPoyE3z55shy3L5sKNohqg9VhWNHENJpNS31k=; b=qWG9f1oBdza6WJuHaUwAivKJeV4wGDubQGZhPPPu9F8EXn6lK+VUF2TtPO/o2RW2ap PkBcvF393DI7FzXV1iaAsvttIDLwYnjJljug/wMI2RtinvPPK6KSlWNH05vYI/x6arWL XqVXxBbcP5ZHQnX4X0zatVQT4+g3yvZCXMhnO0bb6aHSwROP+dgxkdie1/Ai4rtNsGd2 3D446m1MskaHv2NOjIJBbxNjI3p/mOcoVkskuyuoVb6xSZon4c5HA65Uqt3DG5EknWX3 Xqa2HLXMMbtH2MGelZl4wr8TnqunM/0YUcZKO7ZC0rNdn4vFBKVMTmkACLEOBt4Pe42I ctdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sOqllu7b; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si4493979ejc.553.2021.10.14.10.34.58; Thu, 14 Oct 2021 10:35:22 -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=@linuxfoundation.org header.s=korg header.b=sOqllu7b; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbhJNPBH (ORCPT + 99 others); Thu, 14 Oct 2021 11:01:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:44512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbhJNO7u (ORCPT ); Thu, 14 Oct 2021 10:59:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 81FE660F36; Thu, 14 Oct 2021 14:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223465; bh=OV28USTbFV4LVGdsw2VzhGzNPJU0Mb1hB9FWzQjHLgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sOqllu7bPuxT1fFqbrlA0BqVhXf/W2INaL7VkgfxRp6gI+uaZLRDWWoFSV7TwrVnA lRqzjFkl+HZPK1pyATyMfkGE7CNHAahUwJkE+U5Y6sq8gjHPR79rYo0YaReqV1fmRg nq3tCLpjKRb68a4Tgsphc0GI1KQvXkPaFaIyGVaQ= 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.14 32/33] perf/x86: Reset destroy callback on event init failure Date: Thu, 14 Oct 2021 16:54:04 +0200 Message-Id: <20211014145209.868048595@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145208.775270267@linuxfoundation.org> References: <20211014145208.775270267@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 c1f7b3cb84a9..39c298afa2ea 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2094,6 +2094,7 @@ static int x86_pmu_event_init(struct perf_event *event) if (err) { if (event->destroy) event->destroy(event); + event->destroy = NULL; } if (ACCESS_ONCE(x86_pmu.attr_rdpmc)) -- 2.33.0