From nobody Tue Dec 16 19:54:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F30DA19005E for ; Sat, 8 Nov 2025 13:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762607291; cv=none; b=Ss6iyXOpLzmnI+j8nfWZcvm6QciMYIxBYGbEv2c09LJkLm8mcT5yR1qOY8lNEedi72mfqjZo+0VEGqA02OXCOLh3JN3DXDrIr/cgcxIUrio+s2nUKadIvlTPwPtRjloxzqQd4vXSJ5MlD6ZdOElVTZ0LotOWmk/iP5TcjhP/jJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762607291; c=relaxed/simple; bh=OQni4Y657hkwe/ivscLuJNRMjj9kfBkHaqK7Whu40Zs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=rl2hhrQwtU7XP0GhPTu+YOR0BhgOMj1JR5kO8sXR5hlGXBMadkyWfh8k7e6aTHyrFTHvsy4X51SW10Cjdgehvioyth5Lxnsd7k8Cx26GwwBQUjRDbKCMWFiAuHFL9h+asQo5CzX14Sg+k1RotHYf4JpMAbRO/qjGnBKwuWtGtxk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cf6BGuuW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cf6BGuuW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03824C116C6; Sat, 8 Nov 2025 13:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1762607290; bh=OQni4Y657hkwe/ivscLuJNRMjj9kfBkHaqK7Whu40Zs=; h=Date:From:To:Cc:Subject:From; b=Cf6BGuuWpZVM7Sr/7oRDoJAo5AcYgUBA6G53T4/U5okkpy1mgd7LEu3rtOTyzJmsg ohnxdjHuT3ssp3YG8vRGLC6RxwqdVJxKsTeUdqPDcDRBxM839HT9R7LZBdIR7nzou3 C3U+qJZpkTZF/3YeKkbyU7SGyz5eyrh4OF4EUEzrIj8VJlIZcYIB2ha6YqNbTmGq5n Eyrx8E752ktJA+33QSBZZ9cprQrdlgnBGNzdZbN4Vnf3pVzWkowV5cWn7vRhFr4yZg 9CaxORydrFefvAPG+3w9Rlksh768EQhPTTPoBKqbCEgfH+VACx7ueHHVsLN4bAS4W5 zZ1XpuJ/+tk8g== Date: Sat, 8 Nov 2025 14:07:58 +0100 From: Ingo Molnar To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Mark Rutland , Namhyung Kim , Andrew Morton , Kan Liang , Borislav Petkov Subject: [GIT PULL] perf events fix Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Linus, Please pull the latest perf/urgent Git tree from: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-20= 25-11-08 # HEAD: eb3182ef0405ff2f6668fd3e5ff9883f60ce8801 perf/core: Fix system h= ang caused by cpu-clock usage Fix a system hang caused by cpu-clock events. Thanks, Ingo ------------------> Dapeng Mi (1): perf/core: Fix system hang caused by cpu-clock usage kernel/events/core.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 177e57c1a362..1fd347da9026 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -11773,7 +11773,8 @@ static enum hrtimer_restart perf_swevent_hrtimer(st= ruct hrtimer *hrtimer) =20 event =3D container_of(hrtimer, struct perf_event, hw.hrtimer); =20 - if (event->state !=3D PERF_EVENT_STATE_ACTIVE) + if (event->state !=3D PERF_EVENT_STATE_ACTIVE || + event->hw.state & PERF_HES_STOPPED) return HRTIMER_NORESTART; =20 event->pmu->read(event); @@ -11819,15 +11820,20 @@ static void perf_swevent_cancel_hrtimer(struct pe= rf_event *event) struct hw_perf_event *hwc =3D &event->hw; =20 /* - * The throttle can be triggered in the hrtimer handler. - * The HRTIMER_NORESTART should be used to stop the timer, - * rather than hrtimer_cancel(). See perf_swevent_hrtimer() + * Careful: this function can be triggered in the hrtimer handler, + * for cpu-clock events, so hrtimer_cancel() would cause a + * deadlock. + * + * So use hrtimer_try_to_cancel() to try to stop the hrtimer, + * and the cpu-clock handler also sets the PERF_HES_STOPPED flag, + * which guarantees that perf_swevent_hrtimer() will stop the + * hrtimer once it sees the PERF_HES_STOPPED flag. */ if (is_sampling_event(event) && (hwc->interrupts !=3D MAX_INTERRUPTS)) { ktime_t remaining =3D hrtimer_get_remaining(&hwc->hrtimer); local64_set(&hwc->period_left, ktime_to_ns(remaining)); =20 - hrtimer_cancel(&hwc->hrtimer); + hrtimer_try_to_cancel(&hwc->hrtimer); } } =20 @@ -11871,12 +11877,14 @@ static void cpu_clock_event_update(struct perf_ev= ent *event) =20 static void cpu_clock_event_start(struct perf_event *event, int flags) { + event->hw.state =3D 0; local64_set(&event->hw.prev_count, local_clock()); perf_swevent_start_hrtimer(event); } =20 static void cpu_clock_event_stop(struct perf_event *event, int flags) { + event->hw.state =3D PERF_HES_STOPPED; perf_swevent_cancel_hrtimer(event); if (flags & PERF_EF_UPDATE) cpu_clock_event_update(event); @@ -11950,12 +11958,14 @@ static void task_clock_event_update(struct perf_e= vent *event, u64 now) =20 static void task_clock_event_start(struct perf_event *event, int flags) { + event->hw.state =3D 0; local64_set(&event->hw.prev_count, event->ctx->time); perf_swevent_start_hrtimer(event); } =20 static void task_clock_event_stop(struct perf_event *event, int flags) { + event->hw.state =3D PERF_HES_STOPPED; perf_swevent_cancel_hrtimer(event); if (flags & PERF_EF_UPDATE) task_clock_event_update(event, event->ctx->time);