Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3398426pxf; Mon, 22 Mar 2021 05:39:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiknvMQtJm46F1lkqLaLefJ8tMFQnef8D9hT+g5rPoFMK80Rkvtf7QfDvTY6eNNlLlHf1j X-Received: by 2002:aa7:dbd3:: with SMTP id v19mr25202290edt.314.1616416755725; Mon, 22 Mar 2021 05:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616416755; cv=none; d=google.com; s=arc-20160816; b=bASMYvD6sdNq5D1Hn2/N7I7LPePZfxca/VRY7s9WJK+Pb9YVcjJY1lcXOXfXKFnxLH J0K2IJ3XEJcy7TWj3JfmqWCQbc5q17ImNKfjrzPxxQtbF1Q8SbrLs+86HUe+0pS/Hm8y VPu+PuemI/CEe9ERk3OoKS398+gURceCIbHubTgcSGIqnIHxh1Mmo6LTQjhR/gbCtLUK TAt0nwtvw7DKDCKU20H+42QBLODku7qrwe6lq3Ol5RQMjT+WCV7Of/0EtLg2rzJffVIV Gz0dUfnUuit235KU4/Htzi9lto9Z6KCR0KfCXppUzCwmW0keLrSLXzkxSlvYuyhcJ5Ol bSUA== 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=mNk+oOHShLZmFIfgG/osQYquk2Tz3dPGC6VaYaswrNI=; b=zlhFsyksaTUD9qRAlB/PI7n/P/vtsiNej38UTJ2TOI3ZsfjZ1c5RJEXBN1z6IDCNk0 Ilance7y3ugpLc8/U4NBzeR9hFrY/8yB9lvSIxNtcP4bDy1oAvO7r3OvXPcXRFnQy3pa iTKOmjmoyVG1we+GPlAa///+mK9kjEhSmGEq4Zaou7aCPWxj/9ly6h8uGwJ5bFs2ORjZ CRadPL/K2LHmRLVUclIxMaq7bkKUWsqwuQvMu/NQDQDuPMrqCLlUs3fZ/sMLj4Fd8qcN WGLZd/TqlDWQlSB6bZ9TdJQ7DmE2s0IQWRz2zV06xTX6Pj4/Xv4Hme8ZLjj11igU/d5g jajQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f6vo3hFg; 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 n23si11398947ejr.458.2021.03.22.05.38.53; Mon, 22 Mar 2021 05:39:15 -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=f6vo3hFg; 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 S231464AbhCVMhs (ORCPT + 99 others); Mon, 22 Mar 2021 08:37:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:56846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231520AbhCVMdo (ORCPT ); Mon, 22 Mar 2021 08:33:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B46606191A; Mon, 22 Mar 2021 12:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416424; bh=RINJgfpY2cUuzh8bos89TiJ6HYODYBuZH2vaLibdF+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f6vo3hFg/Sqtuy0Yb4skw9gEvsNTpCGNJwmqsKi25wqGinruvwtjHK/ixGmaNSGCD IMv3xikX2HLUPtennTfFOXn9cyDeea1DUJ+nMhwsloTVvirz7QBX3WY2+nrPsUL44A 8DgIEu4OHP7tXQPf6isF8yFRSUhQpqz0o9svsNDU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vince Weaver , "Peter Zijlstra (Intel)" , Kan Liang Subject: [PATCH 5.11 100/120] perf/x86/intel: Fix a crash caused by zero PEBS status Date: Mon, 22 Mar 2021 13:28:03 +0100 Message-Id: <20210322121933.023993099@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121929.669628946@linuxfoundation.org> References: <20210322121929.669628946@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: Kan Liang commit d88d05a9e0b6d9356e97129d4ff9942d765f46ea upstream. A repeatable crash can be triggered by the perf_fuzzer on some Haswell system. https://lore.kernel.org/lkml/7170d3b-c17f-1ded-52aa-cc6d9ae999f4@maine.edu/ For some old CPUs (HSW and earlier), the PEBS status in a PEBS record may be mistakenly set to 0. To minimize the impact of the defect, the commit was introduced to try to avoid dropping the PEBS record for some cases. It adds a check in the intel_pmu_drain_pebs_nhm(), and updates the local pebs_status accordingly. However, it doesn't correct the PEBS status in the PEBS record, which may trigger the crash, especially for the large PEBS. It's possible that all the PEBS records in a large PEBS have the PEBS status 0. If so, the first get_next_pebs_record_by_bit() in the __intel_pmu_pebs_event() returns NULL. The at = NULL. Since it's a large PEBS, the 'count' parameter must > 1. The second get_next_pebs_record_by_bit() will crash. Besides the local pebs_status, correct the PEBS status in the PEBS record as well. Fixes: 01330d7288e0 ("perf/x86: Allow zero PEBS status with only single active event") Reported-by: Vince Weaver Suggested-by: Peter Zijlstra (Intel) Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/1615555298-140216-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/ds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1899,7 +1899,7 @@ static void intel_pmu_drain_pebs_nhm(str */ if (!pebs_status && cpuc->pebs_enabled && !(cpuc->pebs_enabled & (cpuc->pebs_enabled-1))) - pebs_status = cpuc->pebs_enabled; + pebs_status = p->status = cpuc->pebs_enabled; bit = find_first_bit((unsigned long *)&pebs_status, x86_pmu.max_pebs_events);