From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DB783ED3B3; Tue, 30 Jun 2026 09:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782812900; cv=none; b=OIqbmCiZfqSkGSIsi0qRP6oP1L0iSCNBhXd6UcLWYCz+TGhRtJs1ExOLsUX1UGArfHccxbh+x7n31OPoNVV1dNLTY1bHw7OsKtStkKN9LGStnzElagqLmYc/a8HWj5DMMrwlvdE5cUVAK1/EESXdbe58cINIkqfS3iTqFCGe1XA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782812900; c=relaxed/simple; bh=4hOYZnk/1/Tmp9sDKD0Kj0VNEsVhryj8dUY3ZefPuog=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=LuF+udGgC+hGNDruSWFmoNT37T0GNtR55zkFIzv1PSgfGEsN+Bqzz1CXhG8Z1IEgUxvDkipBPgCmdfPBDDinYAjU+/DXjrF0DGT9LAf9MFuyIpumZlmsjssXndfwX/v6qhKJkPiayinOsY66TrG6ibm+9KxUvRR+v13Sk/wnbhs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0faVUtS8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=REM1r0Aj; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0faVUtS8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="REM1r0Aj" Date: Tue, 30 Jun 2026 09:48:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1782812897; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1b4fj0K/SVAUcDzZ1KYfrjJ+GhGELAn9GoY7RHqrbic=; b=0faVUtS8JPICg/B75e+4ERG5beTYzEHDHE5I3//lywPK4RevuWMOahVPNG5H5tisE9czmZ 3CShAYnvtBvsdu2L8h+mZQWcIAEeCwXLVRXo62vHgbMqY1vIqQDrJlgcpiUxck01dcSVC5 b0oJggKjw9CSMTf+6pVue2kP6PfMp9+SFyTglX6tqAZ+7vPsSPPUboLllnVUclPtVsbpJW pg7E73LqSQQzl6mDME0poGApg5aV3Imp1Sjzfk8X2jxGaME7n/4uTnsiHAQkswEauB+YVQ qrPhHc/Lb74JrnSKWWi+9XVAe4r0fdwsukEKMu4M41aD8YlbgUczrhDFHeJ/4A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1782812897; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1b4fj0K/SVAUcDzZ1KYfrjJ+GhGELAn9GoY7RHqrbic=; b=REM1r0AjIV5sxE6E1MFdX4WDjgNa/Ks4k5dMk0trjsvJdZV244CWlZxLNtF6wMq1G4GEFL KUS7KT6NfbtkUsBg== From: "tip-bot2 for Dapeng Mi" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel: Validate the return value of intel_pmu_init_hybrid() Cc: Dapeng Mi , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260616044654.3468742-6-dapeng1.mi@linux.intel.com> References: <20260616044654.3468742-6-dapeng1.mi@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178281289560.3843924.15292968264710865125.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the perf/core branch of tip: Commit-ID: 01c153956b4436ead05a529dae56abc0ef58beac Gitweb: https://git.kernel.org/tip/01c153956b4436ead05a529dae56abc0ef5= 8beac Author: Dapeng Mi AuthorDate: Tue, 16 Jun 2026 12:46:51 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 30 Jun 2026 11:46:07 +02:00 perf/x86/intel: Validate the return value of intel_pmu_init_hybrid() The intel_pmu_init_hybrid() function allocates memory for the x86_pmu.hybrid_pmu[] array. If this allocation fails under memory pressure, hybrid PMU initialization will fail. Currently, the caller does not check the return value of intel_pmu_init_hybrid(). This can lead to a null-pointer dereference or invalid memory access when attempting to use the uninitialized array, potentially triggering a system panic. Fix this by validating the return value of intel_pmu_init_hybrid(). Additionally, reset x86_pmu.num_hybrid_pmus to 0 on failure, and defer intel_pmu_arch_lbr_init() until after hybrid PMU initialization succeeds. This reordering avoids the need to explicitly destroy the kmem cache if the memory allocation fails. Signed-off-by: Dapeng Mi Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260616044654.3468742-6-dapeng1.mi@linux.inte= l.com --- arch/x86/events/intel/core.c | 44 +++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 5116b15..b39c6ce 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -7679,8 +7679,10 @@ static __always_inline int intel_pmu_init_hybrid(enum = hybrid_pmu_type pmus) x86_pmu.num_hybrid_pmus =3D hweight_long(pmus_mask); x86_pmu.hybrid_pmu =3D kzalloc_objs(struct x86_hybrid_pmu, x86_pmu.num_hybrid_pmus); - if (!x86_pmu.hybrid_pmu) + if (!x86_pmu.hybrid_pmu) { + x86_pmu.num_hybrid_pmus =3D 0; return -ENOMEM; + } =20 static_branch_enable(&perf_is_hybrid); x86_pmu.filter =3D intel_pmu_filter; @@ -7863,14 +7865,14 @@ __init int intel_pmu_init(void) struct attribute **td_attr =3D &empty_attrs; struct attribute **mem_attr =3D &empty_attrs; struct attribute **tsx_attr =3D &empty_attrs; + struct x86_hybrid_pmu *pmu; + unsigned int fixed_mask; union cpuid10_edx edx; union cpuid10_eax eax; union cpuid10_ebx ebx; - unsigned int fixed_mask; + int version, i, ret; bool pmem =3D false; - int version, i; char *name; - struct x86_hybrid_pmu *pmu; =20 /* Architectural Perfmon was introduced starting with Core "Yonah" */ if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { @@ -7940,9 +7942,6 @@ __init int intel_pmu_init(void) x86_pmu.lbr_read =3D intel_pmu_lbr_read_32; } =20 - if (boot_cpu_has(X86_FEATURE_ARCH_LBR)) - intel_pmu_arch_lbr_init(); - intel_pebs_init(); =20 x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */ @@ -8540,7 +8539,9 @@ __init int intel_pmu_init(void) * * Initialize the common PerfMon capabilities here. */ - intel_pmu_init_hybrid(hybrid_big_small); + ret =3D intel_pmu_init_hybrid(hybrid_big_small); + if (ret) + return ret; =20 x86_pmu.pebs_latency_data =3D grt_latency_data; x86_pmu.get_event_constraints =3D adl_get_event_constraints; @@ -8598,7 +8599,9 @@ __init int intel_pmu_init(void) case INTEL_METEORLAKE: case INTEL_METEORLAKE_L: case INTEL_ARROWLAKE_U: - intel_pmu_init_hybrid(hybrid_big_small); + ret =3D intel_pmu_init_hybrid(hybrid_big_small); + if (ret) + return ret; =20 x86_pmu.pebs_latency_data =3D cmt_latency_data; x86_pmu.get_event_constraints =3D mtl_get_event_constraints; @@ -8629,7 +8632,9 @@ __init int intel_pmu_init(void) pr_cont("Pantherlake Hybrid events, "); name =3D "pantherlake_hybrid"; =20 - intel_pmu_init_hybrid(hybrid_big_small); + ret =3D intel_pmu_init_hybrid(hybrid_big_small); + if (ret) + return ret; =20 /* Initialize big core specific PerfMon capabilities.*/ pmu =3D &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX]; @@ -8644,7 +8649,9 @@ __init int intel_pmu_init(void) pr_cont("Arrowlake Hybrid events, "); name =3D "arrowlake_hybrid"; =20 - intel_pmu_init_hybrid(hybrid_big_small); + ret =3D intel_pmu_init_hybrid(hybrid_big_small); + if (ret) + return ret; =20 /* Initialize big core specific PerfMon capabilities.*/ pmu =3D &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX]; @@ -8661,7 +8668,9 @@ __init int intel_pmu_init(void) pr_cont("Lunarlake Hybrid events, "); name =3D "lunarlake_hybrid"; =20 - intel_pmu_init_hybrid(hybrid_big_small); + ret =3D intel_pmu_init_hybrid(hybrid_big_small); + if (ret) + return ret; =20 /* Initialize big core specific PerfMon capabilities.*/ pmu =3D &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX]; @@ -8686,7 +8695,9 @@ __init int intel_pmu_init(void) break; =20 case INTEL_ARROWLAKE_H: - intel_pmu_init_hybrid(hybrid_big_small_tiny); + ret =3D intel_pmu_init_hybrid(hybrid_big_small_tiny); + if (ret) + return ret; =20 x86_pmu.pebs_latency_data =3D arl_h_latency_data; x86_pmu.get_event_constraints =3D arl_h_get_event_constraints; @@ -8721,7 +8732,9 @@ __init int intel_pmu_init(void) case INTEL_NOVALAKE_L: pr_cont("Novalake Hybrid events, "); name =3D "novalake_hybrid"; - intel_pmu_init_hybrid(hybrid_big_small); + ret =3D intel_pmu_init_hybrid(hybrid_big_small); + if (ret) + return ret; =20 x86_pmu.pebs_latency_data =3D nvl_latency_data; x86_pmu.get_event_constraints =3D mtl_get_event_constraints; @@ -8828,6 +8841,9 @@ __init int intel_pmu_init(void) pr_cont("AnyThread deprecated, "); } =20 + if (boot_cpu_has(X86_FEATURE_ARCH_LBR)) + intel_pmu_arch_lbr_init(); + intel_pmu_check_event_constraints_all(NULL); =20 /*