Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3417629pxf; Mon, 22 Mar 2021 06:07:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx34QHA9050TiqVz0MtHmaGykppws9HAx2Aw+O9YzW/veW8d/o7ggHoJLkqRYfzNO4+3cX/ X-Received: by 2002:a1c:c20a:: with SMTP id s10mr15994204wmf.144.1616418419591; Mon, 22 Mar 2021 06:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616418419; cv=none; d=google.com; s=arc-20160816; b=qgMsUCITrM1ANlnNlAzGMf5sO440YKD7YDihqQnJa+EHGDJBxJI8uiOd+VXlg50KFQ m38dloPKaTrj5QwYUBDWy1NivCIY3KJYw1pmaZYV47mkJrMg5Bakz/ydwcF2djIW4IYU sjYws8faYD1IuLwRpd5LCWvPOEVNweFNFV/RviSPPDNT6lxhZPP2HgHNKlSEffF/pZMq 9o4DJE1PLrxV+ZoPmmE8O4//pEDE2EfqdXTUNmlSl8Bi/l5RJS0SviyaWcOPV3y4r6cw acmWCIMcxSuE3mTHt9vW+Ary5prXrIyFSYmfNa6QZpxcMlfvCECSoPnGKMZ0oghN0vg7 JWYQ== 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=AEAP7cBy8NKvLcjTT3N2HaS2Z+4RqKAoJH5UgbyS3x0=; b=B/lCbXHDzHIOMkiqyQm2jbLEezZTdC75k07YlsXZXzWgXXVtI/wzbmvCM8meQ2wflu Lls7k701/uOKinhqmKE6pLB7h6Cp03YqQtuXNf/u6yLFA4O49zkkDaiViyWXX+IC30H/ HlR6FG6E7hlsveojtkc1Y61XQQ6mKYdLS97V8i/H1NImvcuKUpFel40zPUhRFpqlaV1a vkX25zKWZn3VHMyPKVmD3M8gNxSMtozTr5H/2GHYUBszoDFnK/ZMYI18xa+7XXUzpsQu oVBmWeY/WRUHaZxqf5YEkPKUrAVo67xB7NU5QmvsMDDPLtIBcRvEeTSa1qDlNFezwJ68 +hLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2a9sly0n; 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 n1si11158858edd.229.2021.03.22.06.06.36; Mon, 22 Mar 2021 06:06:59 -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=2a9sly0n; 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 S230223AbhCVNDR (ORCPT + 99 others); Mon, 22 Mar 2021 09:03:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:40966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231559AbhCVMtn (ORCPT ); Mon, 22 Mar 2021 08:49:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C095A619FD; Mon, 22 Mar 2021 12:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616417121; bh=3mUy8Ax1y39CkTTXTWR8sP+mEdhZzGcJaMddrkPsuFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2a9sly0nttP134yL4kJsj+uKrnc518WL7ojtan2SprzVFXMgy1klByUkFCY03VFYQ 4oRikwpkX81Sh5StOZc2Iu/wgOkMnEyKp+ANwrHbXPHLY+MBKJTb2bNXwLd+qUd96g S3XIt+fYs9oFqStj4SwyfqMIws75p0MNULdt8IEE= 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 4.19 34/43] perf/x86/intel: Fix a crash caused by zero PEBS status Date: Mon, 22 Mar 2021 13:28:48 +0100 Message-Id: <20210322121921.007117489@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121919.936671417@linuxfoundation.org> References: <20210322121919.936671417@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 @@ -1557,7 +1557,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);