From nobody Sat Feb 7 18:01:09 2026 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 146C223BCF7 for ; Wed, 28 Jan 2026 14:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769609515; cv=none; b=pCzbwRG6X60yIB9S+apeF/Fa80bE8MGZv1LSt6PZcrivYv9B2nb5mhYxuN/aYj0dWBs1bPOLOfLo7HkXhD3wNcFACjkG8YSQDMpeGEKyPGybh76mF0NLkASUYhUmr8IkOW2CvJ64cDjfJEOncnVPAdMK5ElplEfXY5hOYzUilGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769609515; c=relaxed/simple; bh=e4Y0gnq911FKNdWWWGAQnFXylREVdGWOawghZntWz9g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kogAnGIHjhnc9xmKa3WalPgAssnHR9CEsiyJLg3FTR1ZKxudLr25X6Lg8ZOz641sA5HQoSOrtpLJjmn/Mf3s8mNPT6X4ce572F1HzW7FPFDnLwqv6iFQ7iaUdIMXPtPMI7Dh40PNKb/3tNN6NzIc4EvqI9KOAYsnL/QKfIgVlSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QKbfaEi6; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QKbfaEi6" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-8c7199e7f79so32653685a.0 for ; Wed, 28 Jan 2026 06:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769609513; x=1770214313; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NvwAkydsJHGg+bpnKIjXBjgXWCnzFDla2aq6C1Z3aaY=; b=QKbfaEi6JTXTspYfmdrQ7Qi4jr0wqOK2Wo8De4keCtaC30NLAgVKmzG+UmH2xREQXp SRgWOo5a1bc+peNdvWVOePV+8ni0yuMhd1qyazlOvlFNDSdVUjxuDE0KiQLXJMUPqM9u E43siiaEVqdeqplGRFOr/VaWLP4XZr7hJzcyKLB5xK0lCusftjtCQXpr+D2uLiOLvRwA p6u9auE5kS7sq75G0uEx6LfPhnYh4hhPzq49iN/EgCWB78ICAu8KTMyMc8PqdjAZKt+o 1pYu1Ky+ZPHHA/MyYPQ1b7AageswNJMIsoVDNnrtbuq6cajMhZfJbc36iQUphqm5oXgM ozIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769609513; x=1770214313; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NvwAkydsJHGg+bpnKIjXBjgXWCnzFDla2aq6C1Z3aaY=; b=OFFmsHD1IabWU0T0DSyTLMVuWdLWEcgmC1OnMU8chxn3RUzQJzBBWt6ZKoboPtOuqm nZqyMQo0MvRALO8NFcUWKNCyFUcLbLGb6MMoH9edPnAnv4/De72Z7I/d89q2XcIQwVFm 08Ewbw2qUOB6SocjdLh4filovEDwjU8jisRib80u/rfcJYsDXkergufjHgPNruus91G5 e32pxKPWeIeRraFKQ++FWJlT69qN7AzHUrKkFcZqnhncfFWkVc/ytQYOQbIpieh9xbvS AphP3UcIG6F50VNCRNt5KV27JluOOcih8PpGWn11iWyLy8W2DzGVLUuIEFYmTAEaBr8C F67A== X-Forwarded-Encrypted: i=1; AJvYcCX/XHSNX/MCiXE/uxNHgReCYh2+1mZRzfB8c3xpZ6MEoXDLeSx/GjkFcWM+x36eILE1F7L99eaVj3f9+pg=@vger.kernel.org X-Gm-Message-State: AOJu0YzN0odvFrQBZRNcYb77jzudPQqWePZriK5XS8SkN6q5M5wm87BH C4/iGG/lvYEmUff+jT/LfAaYMgWZlHcLylg7Ri3dwvbxfG23+a9kRR9jBtZISaJA X-Gm-Gg: AZuq6aIWAeZLxis7pqNF6wNzHT+bLIxno51pt6ZhRBytYpwYpj87zPi6uDamCimStd1 xAumvsx2w2po6Akp6H0AMFe0V679bbREGLYMxBJ7X6jUzhcUvYAzd2O5HaXmu0L6GOehFEx+IcJ GqX5nwDltBJPcmtYVUf8zC30hLS7Onj+4NuhbQ0qE7CnlvmGjOdUQ5BrfN99f/macxE26ULYZr7 8egoFa2kIxdz6e+EsnOPWVIdHBK0Doixp0xqaKMv5AFzMlJ7EVNQFnlSl0/C/paw6o6aCm0Hk/f Ln2+HFXMnIB9v/ZDCPkk7DjeS0EB5FC3FqgJzdIOe36t5HlloYOqbsXutifvVTHKHSzX4grKUIj BNaCl6akoqAF80UFc8Qfk4nz56G91I4cEg9JQWS8mA9nZvDgYPfN99vAinAfpgiXvZAtdlryZPA xZpjs= X-Received: by 2002:a05:7301:1698:b0:2b7:32fe:4bbb with SMTP id 5a478bee46e88-2b78d910144mr2963994eec.11.1769603031325; Wed, 28 Jan 2026 04:23:51 -0800 (PST) Received: from debian ([74.48.213.230]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b7a1abe57csm2783833eec.22.2026.01.28.04.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 04:23:50 -0800 (PST) From: Qiliang Yuan To: Andrew Morton , Li Huafei , Ingo Molnar , Jinchao Wang , Thorsten Blum , Yicong Yang Cc: linux-watchdog@vger.kernel.org, mm-commits@vger.kernel.org, Qiliang Yuan , Shouxin Sun , Junnan Zhang , Qiliang Yuan , Douglas Anderson , Song Liu , linux-kernel@vger.kernel.org Subject: [PATCH v8] watchdog/hardlockup: simplify perf event probe and remove per-cpu dependency Date: Wed, 28 Jan 2026 07:23:15 -0500 Message-ID: <20260128122330.1761777-1-realwujing@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify the hardlockup detector's probe path and remove its implicit dependency on pinned per-cpu execution. Refactor hardlockup_detector_event_create() to be stateless. Return the created perf_event pointer to the caller instead of directly modifying the per-cpu 'watchdog_ev' variable. This allows the probe path to safely manage a temporary event without the risk of leaving stale pointers should task migration occur. Signed-off-by: Shouxin Sun Signed-off-by: Junnan Zhang Signed-off-by: Qiliang Yuan Signed-off-by: Qiliang Yuan Cc: Douglas Anderson Cc: Song Liu Cc: Jinchao Wang --- v8: - Add Signed-off-by with work email. - v7 link: https://lore.kernel.org/all/20260128060833.1715622-1-realwujing@= gmail.com/ v7: - Update Signed-off-by to match author email. - Remove redundant cpu_hotplug_disable() in probe path. - v6 link: https://lore.kernel.org/all/20260128023136.1691973-1-realwujing@= gmail.com/ v6: - Change title to "simplify/cleanup" and remove "Fixes" tag since the issue is not reproducible on mainline. - Rewrite commit message in imperative mood. - Clarify that mainline is safe while this improves robustness. - v5 link: https://lore.kernel.org/all/20260127022238.1182079-1-realwujing@= gmail.com/ v5: - Refine description: clarify that the retry path uses worker threads without PF_PERCPU_THREAD (though mainline is safe due to system_percpu_wq= ). - v4 link: https://lore.kernel.org/all/20260124070814.806828-1-realwujing@g= mail.com/ v4: - Add cpu_hotplug_disable() in watchdog_hardlockup_probe() to stabilize the probe CPU. - Update description to explain the relevance of 4.19 logs. v3: - Refactor hardlockup_detector_event_create() to be stateless by returning the event pointer instead of directly assigning to per-cpu variables. - Restore PMU cycle fallback and unify the enable/probe paths. v2: - Add Cc: stable@vger.kernel.org. v1: - Avoid 'watchdog_ev' in probe path by manually creating and releasing a local perf event. kernel/watchdog_perf.c | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/kernel/watchdog_perf.c b/kernel/watchdog_perf.c index d3ca70e3c256..4a798443033b 100644 --- a/kernel/watchdog_perf.c +++ b/kernel/watchdog_perf.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 #include #include @@ -118,18 +119,11 @@ static void watchdog_overflow_callback(struct perf_ev= ent *event, watchdog_hardlockup_check(smp_processor_id(), regs); } =20 -static int hardlockup_detector_event_create(void) +static struct perf_event *hardlockup_detector_event_create(unsigned int cp= u) { - unsigned int cpu; struct perf_event_attr *wd_attr; struct perf_event *evt; =20 - /* - * Preemption is not disabled because memory will be allocated. - * Ensure CPU-locality by calling this in per-CPU kthread. - */ - WARN_ON(!is_percpu_thread()); - cpu =3D raw_smp_processor_id(); wd_attr =3D &wd_hw_attr; wd_attr->sample_period =3D hw_nmi_get_sample_period(watchdog_thresh); =20 @@ -143,14 +137,7 @@ static int hardlockup_detector_event_create(void) watchdog_overflow_callback, NULL); } =20 - if (IS_ERR(evt)) { - pr_debug("Perf event create on CPU %d failed with %ld\n", cpu, - PTR_ERR(evt)); - return PTR_ERR(evt); - } - WARN_ONCE(this_cpu_read(watchdog_ev), "unexpected watchdog_ev leak"); - this_cpu_write(watchdog_ev, evt); - return 0; + return evt; } =20 /** @@ -159,17 +146,26 @@ static int hardlockup_detector_event_create(void) */ void watchdog_hardlockup_enable(unsigned int cpu) { + struct perf_event *evt; + WARN_ON_ONCE(cpu !=3D smp_processor_id()); =20 - if (hardlockup_detector_event_create()) + evt =3D hardlockup_detector_event_create(cpu); + if (IS_ERR(evt)) { + pr_debug("Perf event create on CPU %d failed with %ld\n", cpu, + PTR_ERR(evt)); return; + } =20 /* use original value for check */ if (!atomic_fetch_inc(&watchdog_cpus)) pr_info("Enabled. Permanently consumes one hw-PMU counter.\n"); =20 + WARN_ONCE(this_cpu_read(watchdog_ev), "unexpected watchdog_ev leak"); + this_cpu_write(watchdog_ev, evt); + watchdog_init_timestamp(); - perf_event_enable(this_cpu_read(watchdog_ev)); + perf_event_enable(evt); } =20 /** @@ -263,19 +259,30 @@ bool __weak __init arch_perf_nmi_is_available(void) */ int __init watchdog_hardlockup_probe(void) { + struct perf_event *evt; + unsigned int cpu; int ret; =20 if (!arch_perf_nmi_is_available()) return -ENODEV; =20 - ret =3D hardlockup_detector_event_create(); + if (!hw_nmi_get_sample_period(watchdog_thresh)) + return -EINVAL; =20 - if (ret) { + /* + * Test hardware PMU availability by creating a temporary perf event. + * The event is released immediately. + */ + cpu =3D raw_smp_processor_id(); + evt =3D hardlockup_detector_event_create(cpu); + if (IS_ERR(evt)) { pr_info("Perf NMI watchdog permanently disabled\n"); + ret =3D PTR_ERR(evt); } else { - perf_event_release_kernel(this_cpu_read(watchdog_ev)); - this_cpu_write(watchdog_ev, NULL); + perf_event_release_kernel(evt); + ret =3D 0; } + return ret; } =20 --=20 2.51.0