From nobody Mon Jun 8 22:50:46 2026 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (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 5FF8D37AA6C for ; Mon, 25 May 2026 19:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779738588; cv=none; b=DGFChu8Bmiq83CTIwwR7nA5QzUaV9ea9wTU93d0wd5oVlmzIwUc6kt2nZ+4qtEqtUteaN4qQWeWsfjDsXNi3P6qM9ZLRwM1CrgDDzMMI7DOHDrV7uDRG3oZWm2ed6jpYHDMw8T/zAN9IGrIg19zhoBYrjv3Peu08RaoL2ZY2j5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779738588; c=relaxed/simple; bh=KN32dTtmfpBUCNjjKsDJ87Yez5+okt9F+j5uevGUbbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SEqBMpeezboOFjh1B4rQi4HC0nIw70kRDhR+AC6QUbKCsYTT9LJRHEa3yR8ymVzynBV4VN59nSxQJB3NsvNtEsNQfQK+68e7sR1kttL+V2ye1xyeO29A2+4pAuHOKe+PSdwbMWAVw66WicFTtQJLgvS+lejNvf42hGtnytbbeKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org; spf=pass smtp.mailfrom=wbinvd.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b=X2dyz4+H; arc=none smtp.client-ip=74.125.82.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b="X2dyz4+H" Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-30246cfd41aso1976828eec.1 for ; Mon, 25 May 2026 12:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wbinvd.org; s=wbinvd; t=1779738586; x=1780343386; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HR4DFF79sz18rq0F3+mr/LSyfi6B2biymk9ahV0bWd4=; b=X2dyz4+HM8parXb5OHeYHh/RCXn2sNF2TDMxYGsQOsGC4P9wx29/5nAwmI6kgM1lcx iyLItnoumxjduI4T5bG4gqeqUxuXAddLM8aSNfYLZRpGcASZepKceIoe3/c3sLebk+iT SSf3sSjU0dUhwkN67eVg+HHthSeX5lj+A/sBzNU4WgBRclnxptX+2Hrq5FCwITQx8oLt emp2QXnrLKFSIssuqp/nx75ZpbTjv5LljwPKeObYRMOr1r2z7TBfFmS61hS2N4AJJF4i KUrkXT3Mdwd15yGh3QxBWA9VsKVh2RSuXE8cktxQnUmtQt3I467ntO6giY1xaUGo1PoD 0isw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779738586; x=1780343386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HR4DFF79sz18rq0F3+mr/LSyfi6B2biymk9ahV0bWd4=; b=nV37v8y9iRGJrcFGLzv1EXpHoShzh5FhX4UXfGYMrl4GP8QS1hTwlR47RGom4ghQeY HLz48u+g3pK/Cx/U3VvPpqUdXyCh2pnJsEBu95TI6geze2CCl2tbJeM62SMjqi52uXVQ +QlMHRgrbnK4d63fuLydVQv9oYmeqKG2SUwyyMVivKk9OYQlKTX6iln51eIXR/14ZgN1 ZRTInVhFV4sZIv6/XDhznQIplFPZL0Y/cCVZA0Q67YBMmI6t/QB6qqaO7YddzWeQd0UL nPZ7ib/9JuPHJMxFkAEA6gtsewXcxkGg6fb+OAdm3w0Fw3nK3Rp8DBApfceexPEp2XQg p7kg== X-Gm-Message-State: AOJu0YwqnlMnRVjdPCZcO8zrKPfkHZMJKz7hBL/Jm7rk/7hski0j0mzW dGUpUVQUg6CCi7GO3LHCbOaycpTjgxNTNl0CgpDUMG0t2o/ZwLAEFv9DtUy4mLyHP8+EuHnFR8q Cq9Yq X-Gm-Gg: Acq92OHKXP5JBUv883/rvHL/OGGyLFXqO3cFl5DopoRxmGPPpN4x6xGQmmDpffWG6ti xDvWcitppnez4Drj3A8vU3yPHsKwsfdqA7EpRwGjlGQkpbgBxAkyY/eZc01QaqodwKvB58mHjEZ 6dZ64r4bHlLGOBPqe78/AVmq/LHenkZ8T3a+lqKWeVF0zkkIGMoZ+pXdCCK9VWiLJMp0/X+pVJZ 1CjmRMLAaTcrDz5q2Xp6BqOwzLjhRbuhY8ujh129YSupYvg3V4jPvl0F884RaiUApUBsaC6q/TO FGA2RGJ4N7ylJYiFpxwK7ANgnPic2gNA+JphTL8fKLZZ4UPlvy057h8fNTDTJOsLSkLYROU9dNc d2bXUEGLrLOgzRS6kmaREYo9RLPogboyMv/JYnWxvL47zEVkIrr2zn5RoRHr7MPzjHzdZ/dtiOj v2bOJwuQtYiGUEmQfhFnwiMCOk30UZo5thbo9w X-Received: by 2002:a05:7300:509:b0:304:6782:d5a4 with SMTP id 5a478bee46e88-3046782e5edmr5137811eec.5.1779738586400; Mon, 25 May 2026 12:49:46 -0700 (PDT) Received: from mozart.vkv.me ([2001:5a8:468b:d015:2feb:307b:ed4b:5f1d]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30452230dddsm11032141eec.17.2026.05.25.12.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 12:49:46 -0700 (PDT) From: Calvin Owens To: linux-kernel@vger.kernel.org Cc: Rodolfo Giometti , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Thomas Gleixner , Ingo Molnar , Greg Kroah-Hartman , Michael Byczkowski , Eliav Farber , linux-rt-devel@lists.linux.dev, David Laight Subject: [PATCH v6 1/3] pps: pps-gpio: split IRQ handler into hardirq timestamper + threaded handler Date: Mon, 25 May 2026 12:49:30 -0700 Message-ID: <106de17aabedc07c3550a2297c1659ef97f28c41.1779733602.git.calvin@wbinvd.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: 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" From: Michael Byczkowski Split the pps-gpio interrupt handler into a primary (hardirq) handler that captures the PPS timestamp at interrupt entry, and a threaded handler that processes the event. This produces the same two-part handler structure on both PREEMPT_RT and non-RT kernels. On non-RT kernels the threaded portion runs immediately after the primary, with no behavioral change compared to the previous single-handler implementation. On PREEMPT_RT, where interrupt handlers are force-threaded by default, the previous single-handler implementation captured the timestamp inside the threaded portion, after IRQ-thread scheduling delay. With the split, the timestamp is captured in true hardirq context as it is on non-RT kernels, eliminating a significant source of PPS jitter on RT systems. Tested-by: Michael Byczkowski Tested-by: Calvin Owens Acked-by: Rodolfo Giometti Signed-off-by: Michael Byczkowski Signed-off-by: Calvin Owens --- drivers/pps/clients/pps-gpio.c | 37 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c index 935da68610c7..f37398fd6b10 100644 --- a/drivers/pps/clients/pps-gpio.c +++ b/drivers/pps/clients/pps-gpio.c @@ -35,33 +35,44 @@ struct pps_gpio_device_data { bool capture_clear; unsigned int echo_active_ms; /* PPS echo active duration */ unsigned long echo_timeout; /* timer timeout value in jiffies */ + struct pps_event_time ts; /* timestamp captured in hardirq */ }; =20 /* * Report the PPS event */ =20 -static irqreturn_t pps_gpio_irq_handler(int irq, void *data) +/* + * Primary hardirq handler - runs in hardirq context even on PREEMPT_RT. + * Only captures the timestamp; all other work is deferred to the thread. + */ +static irqreturn_t pps_gpio_irq_hardirq(int irq, void *data) { - const struct pps_gpio_device_data *info; - struct pps_event_time ts; - int rising_edge; + struct pps_gpio_device_data *info =3D data; + + pps_get_ts(&info->ts); =20 - /* Get the time stamp first */ - pps_get_ts(&ts); + return IRQ_WAKE_THREAD; +} =20 - info =3D data; +/* + * Threaded handler - processes the PPS event using the timestamp + * captured in hardirq context above. + */ +static irqreturn_t pps_gpio_irq_thread(int irq, void *data) +{ + struct pps_gpio_device_data *info =3D data; + int rising_edge; =20 - /* Small trick to bypass the check on edge's direction when capture_clear= is unset */ rising_edge =3D info->capture_clear ? gpiod_get_value(info->gpio_pin) : !info->assert_falling_edge; if ((rising_edge && !info->assert_falling_edge) || (!rising_edge && info->assert_falling_edge)) - pps_event(info->pps, &ts, PPS_CAPTUREASSERT, data); + pps_event(info->pps, &info->ts, PPS_CAPTUREASSERT, data); else if (info->capture_clear && ((rising_edge && info->assert_falling_edge) || (!rising_edge && !info->assert_falling_edge))) - pps_event(info->pps, &ts, PPS_CAPTURECLEAR, data); + pps_event(info->pps, &info->ts, PPS_CAPTURECLEAR, data); else dev_warn_ratelimited(&info->pps->dev, "IRQ did not trigger any PPS event= \n"); =20 @@ -210,8 +221,10 @@ static int pps_gpio_probe(struct platform_device *pdev) } =20 /* register IRQ interrupt handler */ - ret =3D request_irq(data->irq, pps_gpio_irq_handler, - get_irqf_trigger_flags(data), data->info.name, data); + ret =3D request_threaded_irq(data->irq, + pps_gpio_irq_hardirq, pps_gpio_irq_thread, + get_irqf_trigger_flags(data) | IRQF_ONESHOT, + data->info.name, data); if (ret) { pps_unregister_source(data->pps); dev_err(dev, "failed to acquire IRQ %d\n", data->irq); --=20 2.47.3 From nobody Mon Jun 8 22:50:46 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 D4F89386562 for ; Mon, 25 May 2026 19:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779738590; cv=none; b=UkN/r9KTY1nSrkMzCDk9uzdRuUh5jmIjUSI+jVY3UxXnmGNIZZzass94gGHkQpOtC4xYgGqgIFNVWEb29CAvZ1RPrjnS8KSLY9ZPjAPc4shRgMA6Nu7mPWmFwQa3PMhWynB6pmKmDKN1SiEBztu7e/V9wvYJF1Vg8i3sFyt7S4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779738590; c=relaxed/simple; bh=8FsckFIh/hQkogKq/cihPf0hnOfUQi6qvPh7dz/ckjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LwjqVAZYXEA4tLhXbtcQaRVfC4hmiwxwZVkSZfQ9qWtZTKaHoHObfJ3Yc9ut/exSdf5vtP9OBTF5WlOsKZmVe6/wDA9VVmctDMD1Olz+mIu416SjU0hL/phcbyJstTdqIKLcBIjhTEBqgH2i5+i7kbFeaoPfVm4rfbOM98ixQ6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org; spf=pass smtp.mailfrom=wbinvd.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b=fe85hH/9; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b="fe85hH/9" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-2f7020a928eso14361120eec.1 for ; Mon, 25 May 2026 12:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wbinvd.org; s=wbinvd; t=1779738588; x=1780343388; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pb3DZIwxIy7De4Nzc/EChnZm9vuGaoBDU44qBc/YnTE=; b=fe85hH/9wKZDf7JVzZYz3k9GCrdBBd9V+3efGFVgAZEu60h97K0SdFCTHQMMzSxTuK ej2o5glBChrYTWZcr+yelf94q4SCSiPqm9+c64C6bB+DCKtQLbyaOqfVpEPj21id6ulv 4ybIWBhjfJ75b3VrXbdAe79ucZGZ7YXt/XZjsOsPPUfLlYgHlvYE4od1KuwERA4ypR3I mhFdFgL4mJkhYQZv3hQYn4Zk866B8HtrWEOVTXAe71pAamituhD+aDTvnZcDWORYQ9WD 18M5CzvMJrHy0VmLpvd4qpBlXzxUJRfOGaqKN71Un2uDAc0YbqiAYE4wHjAKuNSI9XNu 4VSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779738588; x=1780343388; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=pb3DZIwxIy7De4Nzc/EChnZm9vuGaoBDU44qBc/YnTE=; b=fDVV4cAWQ0afRYIXukBTqDWfa2iY+l+ZVeLf5T+1P47HG61NoaVTjY8loXBJvVerLg lnwshOkKcyx+6IQ5h8M7IltLm10J1zQ3jBX/kW4xxmDtSrtuopAUpNcyVn7qmYnx81lV cFXPFUnRyaHUOL9F+8GZE1xEZQsnYDyvh0rjaRUttlUeCpa+CRUlBMbXJw4JzcR2168r om01OiP1wBL0DdG+zPT6H/wTjaAwgQrT3091imp+0TgNEtug25NKynw8p2FuWEu8fY59 +KgWvhuEgZtlZoB4avVtAsMYvWf+eOpfg2NywjtY117VMW5DLErObtpCycY3totkMp2p +NeQ== X-Gm-Message-State: AOJu0YzPKsVxx1D6tOEUh2CtJnidAHGPcjMFoNMQM2b5WHbKmF17sg2G 7DT7LL/F48Kq63g3wetYxifZjglrB1+NRD4JEvZMphdplysE2mbtdSP+aBVixG86MRP55XT399X bXwp+ X-Gm-Gg: Acq92OFllckVJ8fwffLBKhAZL8khFY0QNu+CvxbHNPgoPHNmUJ/Qdoid3CsbGjW7Pcd ho0yNULGetyr4O6LLGz443LtrLeTeBGT6B0YIJXMlUBa1iQgqCHaBWEW7XQCNdLNhaq2EOt0pOt nyuT2gETn4Lw3MlkuJg7dZm3YtjM1E+JjTOppMOKXEPAqawqWmKlmUH+JN+2lK907E/eDyNd8Qr yxtEB+SMAizn3Bhcne0VfAtsG4alLccUACm77qo5JrQyYV+T+2YB397Zq75/jBMVGkl2jnM0GUy 6h/aVHrpQtaPXDn7cbK6eAb0Fd0AuyPmxT1EsLRhQVcRKIjT7hk5QF8hXhK/M989FwAxIUEROLn WFDHVLHOxGrbe1w9VWgUMOroGXUQwKGOZOS4uNRhECGaWZQF9+B0lV2vX8z7JgsWTXdPH59FZVD nFNivNwsvq26oXMT1Sx0NTKGHyLzYrB/Zj/VOT X-Received: by 2002:a05:7300:df49:b0:304:9b48:53da with SMTP id 5a478bee46e88-3049b4857dbmr960345eec.26.1779738587878; Mon, 25 May 2026 12:49:47 -0700 (PDT) Received: from mozart.vkv.me ([2001:5a8:468b:d015:2feb:307b:ed4b:5f1d]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30452230dddsm11032141eec.17.2026.05.25.12.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 12:49:47 -0700 (PDT) From: Calvin Owens To: linux-kernel@vger.kernel.org Cc: Rodolfo Giometti , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Thomas Gleixner , Ingo Molnar , Greg Kroah-Hartman , Michael Byczkowski , Eliav Farber , linux-rt-devel@lists.linux.dev, David Laight Subject: [PATCH v6 2/3] pps: kc: convert pps_kc_hardpps_lock to raw_spinlock_t Date: Mon, 25 May 2026 12:49:31 -0700 Message-ID: X-Mailer: git-send-email 2.47.3 In-Reply-To: References: 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" From: Michael Byczkowski pps_kc_hardpps_lock is held in pps_kc_event(), which calls hardpps(). hardpps() takes tk_core.lock, which is already a raw_spinlock_t -- and nesting a sleeping lock (PREEMPT_RT's spinlock_t) over a raw_spinlock_t is invalid. Convert pps_kc_hardpps_lock and its call sites in kc.c to raw_spinlock_t to make the nesting valid on PREEMPT_RT. While here, refactor pps_kc_bind() and pps_kc_remove() to use guard(raw_spinlock_irq) for scope-based lock release. This eliminates four duplicated unlock call sites in pps_kc_bind() and the ambiguous bracket structure that resulted from them. Behavior is unchanged. No functional change on non-RT kernels. Tested-by: Michael Byczkowski Tested-by: Calvin Owens Acked-by: Rodolfo Giometti Signed-off-by: Michael Byczkowski Signed-off-by: Calvin Owens --- drivers/pps/kc.c | 67 ++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/drivers/pps/kc.c b/drivers/pps/kc.c index fbd23295afd7..715b775e9679 100644 --- a/drivers/pps/kc.c +++ b/drivers/pps/kc.c @@ -21,7 +21,7 @@ */ =20 /* state variables to bind kernel consumer */ -static DEFINE_SPINLOCK(pps_kc_hardpps_lock); +static DEFINE_RAW_SPINLOCK(pps_kc_hardpps_lock); /* PPS API (RFC 2783): current source and mode for kernel consumer */ static struct pps_device *pps_kc_hardpps_dev; /* unique pointer to device = */ static int pps_kc_hardpps_mode; /* mode bits for kernel consumer */ @@ -36,35 +36,31 @@ static int pps_kc_hardpps_mode; /* mode bits for kerne= l consumer */ int pps_kc_bind(struct pps_device *pps, struct pps_bind_args *bind_args) { /* Check if another consumer is already bound */ - spin_lock_irq(&pps_kc_hardpps_lock); + guard(raw_spinlock_irq)(&pps_kc_hardpps_lock); =20 - if (bind_args->edge =3D=3D 0) - if (pps_kc_hardpps_dev =3D=3D pps) { - pps_kc_hardpps_mode =3D 0; - pps_kc_hardpps_dev =3D NULL; - spin_unlock_irq(&pps_kc_hardpps_lock); - dev_info(&pps->dev, "unbound kernel" - " consumer\n"); - } else { - spin_unlock_irq(&pps_kc_hardpps_lock); - dev_err(&pps->dev, "selected kernel consumer" - " is not bound\n"); + if (bind_args->edge =3D=3D 0) { + /* Unbind request */ + if (pps_kc_hardpps_dev !=3D pps) { + dev_err(&pps->dev, + "selected kernel consumer is not bound\n"); return -EINVAL; } - else - if (pps_kc_hardpps_dev =3D=3D NULL || - pps_kc_hardpps_dev =3D=3D pps) { - pps_kc_hardpps_mode =3D bind_args->edge; - pps_kc_hardpps_dev =3D pps; - spin_unlock_irq(&pps_kc_hardpps_lock); - dev_info(&pps->dev, "bound kernel consumer: " - "edge=3D0x%x\n", bind_args->edge); - } else { - spin_unlock_irq(&pps_kc_hardpps_lock); - dev_err(&pps->dev, "another kernel consumer" - " is already bound\n"); + pps_kc_hardpps_mode =3D 0; + pps_kc_hardpps_dev =3D NULL; + dev_info(&pps->dev, "unbound kernel consumer\n"); + } else { + /* Bind request */ + if (pps_kc_hardpps_dev && pps_kc_hardpps_dev !=3D pps) { + dev_err(&pps->dev, + "another kernel consumer is already bound\n"); return -EINVAL; } + pps_kc_hardpps_mode =3D bind_args->edge; + pps_kc_hardpps_dev =3D pps; + dev_info(&pps->dev, + "bound kernel consumer: edge=3D0x%x\n", + bind_args->edge); + } =20 return 0; } @@ -78,15 +74,14 @@ int pps_kc_bind(struct pps_device *pps, struct pps_bind= _args *bind_args) */ void pps_kc_remove(struct pps_device *pps) { - spin_lock_irq(&pps_kc_hardpps_lock); - if (pps =3D=3D pps_kc_hardpps_dev) { - pps_kc_hardpps_mode =3D 0; - pps_kc_hardpps_dev =3D NULL; - spin_unlock_irq(&pps_kc_hardpps_lock); - dev_info(&pps->dev, "unbound kernel consumer" - " on device removal\n"); - } else - spin_unlock_irq(&pps_kc_hardpps_lock); + guard(raw_spinlock_irq)(&pps_kc_hardpps_lock); + + if (pps !=3D pps_kc_hardpps_dev) + return; + + pps_kc_hardpps_mode =3D 0; + pps_kc_hardpps_dev =3D NULL; + dev_info(&pps->dev, "unbound kernel consumer on device removal\n"); } =20 /* pps_kc_event - call hardpps() on PPS event @@ -102,8 +97,8 @@ void pps_kc_event(struct pps_device *pps, struct pps_eve= nt_time *ts, unsigned long flags; =20 /* Pass some events to kernel consumer if activated */ - spin_lock_irqsave(&pps_kc_hardpps_lock, flags); + raw_spin_lock_irqsave(&pps_kc_hardpps_lock, flags); if (pps =3D=3D pps_kc_hardpps_dev && event & pps_kc_hardpps_mode) hardpps(&ts->ts_real, &ts->ts_raw); - spin_unlock_irqrestore(&pps_kc_hardpps_lock, flags); + raw_spin_unlock_irqrestore(&pps_kc_hardpps_lock, flags); } --=20 2.47.3 From nobody Mon Jun 8 22:50:46 2026 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 729BB3939A6 for ; Mon, 25 May 2026 19:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779738592; cv=none; b=XTCfmDoBeYE/xqfuExh6fvujsnfAcfXCC344zUbO+YyNzSwpEpIOarPv1EjcVR7LLgeIUAcn8rQFPjoRt/0+zGM6nORdSZFXjOMJ8MloxNBOfMx1fWKDy5M6KIbi0QjUDxOGDkxBmNMkpveB/Dm/cZXDaERpAB/At7Kd7e0L+4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779738592; c=relaxed/simple; bh=I8j2swgsdkC+/ibyO5t4yrHfPjhEcHCtqWfaWFfel7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bvZfFMCq6si2mrqgz9aB1kiWsrtAh/lNIW1ntTioL8k8W1L+m/1y/KX6ZbhsKqy+X+BrXxXogqcIgYlmiMZSDjpwyAKE/7c7F3chx3YLwIRscHaROnHUP04PfQTeWbOGIbwLrLoityAxHVHmP1SRSHXCVen6tGAgFlHP6OEZuNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org; spf=pass smtp.mailfrom=wbinvd.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b=WEZlaCzU; arc=none smtp.client-ip=74.125.82.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wbinvd.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wbinvd.org header.i=@wbinvd.org header.b="WEZlaCzU" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-2f7020a928eso14361146eec.1 for ; Mon, 25 May 2026 12:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wbinvd.org; s=wbinvd; t=1779738589; x=1780343389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xTL+d3d84GaCTUSVSRN0Nbz2eetQdKxRxbxMPmywTIA=; b=WEZlaCzUMVujjT+2tf90Iu4NpkZEYSmfAShuraKcQ0TNVBVO3SD+2dP4sWr5oJXa/9 FCpsE6AuyJa976jbipGYSrDF15PhePD8wE5p1kCnLSXlRVU28lBm9fxuNkL4xFi1HnWB Klh8l7aKFSm3G8Pb1gfxbCS/FTWhCGB/g9SyW6qdxkKRnNyorxGjVey/PKFcnxlCpI22 oYupKl5LYb1E0H445TFGymyNfv7x0sOCunEEHBVHk5TR/TSW+iKt99YGMC1XGasOC0oi OacOdzsmiHyUXw1MKt3xajf0jFXzaStZK7yFWEcuV5jl2HbKMUmVfyWwGuTBiBAS1/mf Vtsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779738589; x=1780343389; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xTL+d3d84GaCTUSVSRN0Nbz2eetQdKxRxbxMPmywTIA=; b=RqAzsPk2/7b5Q3DZ5KLkQDx5r+FBi58g5a99iWTJJgLm9qZzLGWgj0BSWsN/xVGQH0 RBwXZxf5vF1au926YoZXW8zHek/Cr8eC7l5WQF6RMGXXmH2geK7RUVHxlgcX4VIctLAY nWbN9K54hSQdBPDhoErCwaW82OQmv7Awa2MYHgL+Psls3LGK33eZZpid9sU1qClc9J5P lsVynrlKmSGVpotxDFAST8CNi8Ftt46TEZ2WIKLyuluosfVx8WaZs427tyWzbz5YCiDI 8RjOY0dHpxTfgPgkVIZ1uyEYCCZNDDurS0FGoA+vgbeKGN0HGFvkxWWm7Ueeow90eq9s vsDA== X-Gm-Message-State: AOJu0Yx1EilSBFxU9XMqYD/q/N7PwW5ATgXbOr4n4AhCzKmURFl+QsYT MHdHYZoJDtbRHvdijTI9QG8bRYcb5CwDxpHBFSnrOM3WjYpLBjnKDVrbLbCkmUjF5kufz9E7soC OLjNE X-Gm-Gg: Acq92OERJjJIKVIPpr+/XUlawEhfmp5YCWmo1svuhbuPWBv7Y711DqmYvM9XCHN+5HR qn/sIfPeCWpSzqBjSSuDaWvb5qr6UJutjvpyx/9af7TZis8+b13UTHCQLiBtZ6+c2BIJ6cji+sP Em/MMPEuJizFNg/J2ZtnEYGFFFqiTYXL0Q+PRBOxziS09pu3CWcUsJ4xrvt4MJPqUCcBJhLEIZP wNU1eiHarUozUYycgTvBR9apH+rraaWbIzxv4GkdB6I8WlIpePKTDie+X6xwmtGWGw2gwZIt1dJ lgJQSYzqwghq4nOLxoEw/mzUa3b8Rv9yhrwBn7OZj3906GoVQGdNZ87eFzaqnBlFy5iogSSwg8u ZtRHQDWYTdvBzAtyZHXH6Gu4Gfk45rDKkjDkOaMq6pArZPiSFfqqvsNUJH9u6T3n0uEmMvf0djT AHiM1wbr3wVHv+ljwbDQ0tNQ4pSw== X-Received: by 2002:a05:7301:2a24:b0:2de:aafb:feff with SMTP id 5a478bee46e88-3044904e1dbmr6826873eec.2.1779738589495; Mon, 25 May 2026 12:49:49 -0700 (PDT) Received: from mozart.vkv.me ([2001:5a8:468b:d015:2feb:307b:ed4b:5f1d]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30452230dddsm11032141eec.17.2026.05.25.12.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 12:49:49 -0700 (PDT) From: Calvin Owens To: linux-kernel@vger.kernel.org Cc: Rodolfo Giometti , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Thomas Gleixner , Ingo Molnar , Greg Kroah-Hartman , Michael Byczkowski , Eliav Farber , linux-rt-devel@lists.linux.dev, David Laight Subject: [PATCH v6 3/3] pps: convert pps_device.lock to raw_spinlock_t Date: Mon, 25 May 2026 12:49:32 -0700 Message-ID: <3fa6ae908b37681ec6857b413179b67a7655c753.1779733602.git.calvin@wbinvd.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: 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" From: Michael Byczkowski pps_device.lock is acquired from the PPS hardirq path (pps_event() and friends). On PREEMPT_RT, spinlock_t becomes a sleeping rt_mutex, so taking it in hardirq context produces "BUG: scheduling while atomic" splats and breaks PPS event delivery entirely. Convert pps_device.lock to raw_spinlock_t, which remains a true spinning lock on RT, and update all call sites in kapi.c and pps.c to use raw_spin_lock_irqsave() / raw_spin_unlock_irqrestore() (and the _irq variants where appropriate). The critical sections are short and deterministic, so raw_spinlock_t semantics are appropriate. No functional change on non-RT kernels. Tested-by: Michael Byczkowski Acked-by: Rodolfo Giometti Signed-off-by: Michael Byczkowski Tested-by: Calvin Owens Signed-off-by: Calvin Owens --- drivers/pps/kapi.c | 6 +++--- drivers/pps/pps.c | 16 ++++++++-------- include/linux/pps_kernel.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c index 1bf0335a1b41..dc7fac75ec27 100644 --- a/drivers/pps/kapi.c +++ b/drivers/pps/kapi.c @@ -102,7 +102,7 @@ struct pps_device *pps_register_source(struct pps_sourc= e_info *info, pps->info.echo =3D pps_echo_client_default; =20 init_waitqueue_head(&pps->queue); - spin_lock_init(&pps->lock); + raw_spin_lock_init(&pps->lock); =20 /* Create the char device */ err =3D pps_register_cdev(pps); @@ -167,7 +167,7 @@ void pps_event(struct pps_device *pps, struct pps_event= _time *ts, int event, =20 timespec_to_pps_ktime(&ts_real, ts->ts_real); =20 - spin_lock_irqsave(&pps->lock, flags); + raw_spin_lock_irqsave(&pps->lock, flags); =20 /* Must call the echo function? */ if ((pps->params.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR))) @@ -214,6 +214,6 @@ void pps_event(struct pps_device *pps, struct pps_event= _time *ts, int event, kill_fasync(&pps->async_queue, SIGIO, POLL_IN); } =20 - spin_unlock_irqrestore(&pps->lock, flags); + raw_spin_unlock_irqrestore(&pps->lock, flags); } EXPORT_SYMBOL(pps_event); diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index de1122bb69ea..75eb7973e37c 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -106,12 +106,12 @@ static long pps_cdev_ioctl(struct file *file, case PPS_GETPARAMS: dev_dbg(&pps->dev, "PPS_GETPARAMS\n"); =20 - spin_lock_irq(&pps->lock); + raw_spin_lock_irq(&pps->lock); =20 /* Get the current parameters */ params =3D pps->params; =20 - spin_unlock_irq(&pps->lock); + raw_spin_unlock_irq(&pps->lock); =20 err =3D copy_to_user(uarg, ¶ms, sizeof(struct pps_kparams)); if (err) @@ -142,7 +142,7 @@ static long pps_cdev_ioctl(struct file *file, return -EINVAL; } =20 - spin_lock_irq(&pps->lock); + raw_spin_lock_irq(&pps->lock); =20 /* Save the new parameters */ pps->params =3D params; @@ -166,7 +166,7 @@ static long pps_cdev_ioctl(struct file *file, pps->params.assert_off_tu.flags =3D 0; pps->params.clear_off_tu.flags =3D 0; =20 - spin_unlock_irq(&pps->lock); + raw_spin_unlock_irq(&pps->lock); =20 break; =20 @@ -193,7 +193,7 @@ static long pps_cdev_ioctl(struct file *file, return err; =20 /* Return the fetched timestamp and save last fetched event */ - spin_lock_irq(&pps->lock); + raw_spin_lock_irq(&pps->lock); =20 pps->last_fetched_ev =3D pps->last_ev; =20 @@ -203,7 +203,7 @@ static long pps_cdev_ioctl(struct file *file, fdata.info.clear_tu =3D pps->clear_tu; fdata.info.current_mode =3D pps->current_mode; =20 - spin_unlock_irq(&pps->lock); + raw_spin_unlock_irq(&pps->lock); =20 err =3D copy_to_user(uarg, &fdata, sizeof(struct pps_fdata)); if (err) @@ -281,7 +281,7 @@ static long pps_cdev_compat_ioctl(struct file *file, return err; =20 /* Return the fetched timestamp and save last fetched event */ - spin_lock_irq(&pps->lock); + raw_spin_lock_irq(&pps->lock); =20 pps->last_fetched_ev =3D pps->last_ev; =20 @@ -294,7 +294,7 @@ static long pps_cdev_compat_ioctl(struct file *file, memcpy(&compat.info.clear_tu, &pps->clear_tu, sizeof(struct pps_ktime_compat)); =20 - spin_unlock_irq(&pps->lock); + raw_spin_unlock_irq(&pps->lock); =20 return copy_to_user(uarg, &compat, sizeof(struct pps_fdata_compat)) ? -EFAULT : 0; diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h index aab0aebb529e..f2fe504071ed 100644 --- a/include/linux/pps_kernel.h +++ b/include/linux/pps_kernel.h @@ -59,7 +59,7 @@ struct pps_device { void const *lookup_cookie; /* For pps_lookup_dev() only */ struct device dev; struct fasync_struct *async_queue; /* fasync method */ - spinlock_t lock; + raw_spinlock_t lock; }; =20 /* --=20 2.47.3