From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202526; b=vvIWxPXCCHNR+xEFTnkLPPB3g2nWORLV9oxbbecrHGOBxFCWQbgynaTcFwrzvZgrXAb4 XyytSjsdG8Qg/jIKhWvvBqU9riEze1V3Gdl9dmGPD+boQgd2RRTeunY7gbWbZ2RohMQ0B PNzUTbRrZD/nQJRTJ/NyzOj/NZqcET3yx4TA3pRQGtIf61NZs51PS0hoLZeyM/SXhGOV2 0p9VTYt82q7p0UbkQ8Js++R55G5qK3lrcxbOMBZHAlfTedNveCFgUjm3kuxWn3T7Rp29v fboKSr1utYj5aXayhGk4Sqc5p9eS0m9UWwOwpr341RlFOEMvRmisqBoTe64Q6wxTH6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202526; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=R2AtWBYRI9QBHwbHAsxh1Dw51DjT6kVClMbQxEVGoX0=; b=JxaE8AWy0q0bfdfbcLQSbSX4ZaR1wl2TXmMpgz7l1NiA4yRpuI2qHnZHf54sYrjDhKiZ /N/Y3GVzNP6e4CPLtQAAPnyv4j+CzxWo2LisQX6VPRMLTxEhJXFMGJfsr31s2CKBTY6uG wT22kZK8M0GQzKjnD39tIlfTtPstYH3JuY3+TXWAiESAiT/KHUXUwMmhc3AxL87yiq62a LQD5CFvElgGuGIUZIxKmfw9Ov67wpDchcHY4rKPbmrNxFPpwN2ovSCz6kXEmYElaNhqhp 22SovK52y3jM40mS8HLTcrpaw92XrtAQA3rj0RLRC02ZhVx1T+Y0WrOd0AE2+Jb5Ryg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=TaidIf9t; arc=none smtp.remote-ip=192.198.163.19 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0C7F606A325; Wed, 2 Dec 2026 09:08:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0C7F606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=TaidIf9t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796202526; x=1827738526; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R2AtWBYRI9QBHwbHAsxh1Dw51DjT6kVClMbQxEVGoX0=; b=TaidIf9tillhK03Ut3Z03/Z28n5suxC8nhM/b2ji9pIqUmFGBd8GHS2F LzPJbiDZinszBuse3WNOkGEcmyk8W8DoqNnJq3praCsnKmCMHXBSzOOSJ GzSJDZ+jR9A6hNrnsd+RghcxN+icvMmRLPBUUspL2iT6lk/c4gpOv58n+ 3ZK4kqW69Cim9lKtKJNp8WgNTz1TfFk7qkaYbi4GHjNVgdLVflWlVDxJz sYHbxGTJPnFzGY0R3sW9LNzMAxAUrfqkKEcqb/nUByupSj3Q6s0iRKRST LGgckInHOrJCXhGngtSImEnaDdLjhRDikUAkSuKmaSsD7W7WYHKG/DAXy w==; X-CSE-ConnectionGUID: T7oRqQ4eTianZBPp51ihfQ== X-CSE-MsgGUID: F3mCewPGQO+KPO/44SnFFw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5133610" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5133610" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 01:08:46 -0800 X-CSE-ConnectionGUID: ic8SMfT6RnSwo9t9EA7ToA== X-CSE-MsgGUID: rFdh9/KPRUixKS2QgnQmTA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13989189" Received: from faizal-nuc12wski7.png.intel.com ([10.107.255.69]) by fmviesa001.fm.intel.com with ESMTP; 02 Dec 2026 01:08:43 -0800 From: KhaiWenTan To: Rodolfo Giometti , Greg Kroah-Hartman , Jonathan Corbet Cc: Thomas Gleixner , Andy Shevchenko , david.zage@intel.com, weifeng.voon@intel.com, hong.aun.looi@intel.com, christopher.s.hall@intel.com, khai.wen.tan@intel.com, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH 2/4] pps: generators: cancel TIO timer outside spinlock Date: Thu, 3 Dec 2026 01:21:56 +0800 Message-ID: <20261202172254.1188109-3-khai.wen.tan@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202172254.1188109-1-khai.wen.tan@linux.intel.com> References: <20261202172254.1188109-1-khai.wen.tan@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Voon Weifeng Move hrtimer_cancel() out of the spinlocked section. The timer callback takes the same lock, so cancelling while holding it can deadlock. Serialize enable, disable and removal with a mutex. Fixes: c89755d1111f ("pps: generators: Add PPS Generator TIO Driver") Signed-off-by: Voon Weifeng Signed-off-by: KhaiWenTan --- drivers/pps/generators/pps_gen_tio.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c index c6d41fb2105f..9e3142041269 100644 --- a/drivers/pps/generators/pps_gen_tio.c +++ b/drivers/pps/generators/pps_gen_tio.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ struct pps_tio { struct hrtimer timer; void __iomem *base; u32 prev_count; + struct mutex mutex; spinlock_t lock; struct device *dev; }; @@ -167,22 +169,31 @@ static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) static int pps_tio_gen_enable(struct pps_gen_device *pps_gen, bool enable) { struct pps_tio *tio = container_of(pps_gen->info, struct pps_tio, gen_info); + unsigned long flags; + int ret = 0; + mutex_lock(&tio->mutex); if (!timekeeping_clocksource_has_base(CSID_X86_ART)) { dev_err_once(tio->dev, "PPS cannot be used as clock is not related to ART"); - return -ENODEV; + ret = -ENODEV; + goto out_mutex; } - guard(spinlock_irqsave)(&tio->lock); + if (!enable) + hrtimer_cancel(&tio->timer); + + spin_lock_irqsave(&tio->lock, flags); if (enable && !pps_gen->enabled) { pps_tio_direction_output(tio); hrtimer_start(&tio->timer, first_event(tio), HRTIMER_MODE_ABS); } else if (!enable && pps_gen->enabled) { - hrtimer_cancel(&tio->timer); pps_tio_disable(tio); } + spin_unlock_irqrestore(&tio->lock, flags); - return 0; +out_mutex: + mutex_unlock(&tio->mutex); + return ret; } static int pps_tio_get_time(struct pps_gen_device *pps_gen, @@ -206,6 +217,7 @@ static int pps_gen_tio_probe(struct platform_device *pdev) tio = devm_kzalloc_obj(dev, *tio); if (!tio) return -ENOMEM; + mutex_init(&tio->mutex); tio->gen_info.use_system_clock = true; tio->gen_info.enable = pps_tio_gen_enable; @@ -233,9 +245,14 @@ static int pps_gen_tio_probe(struct platform_device *pdev) static void pps_gen_tio_remove(struct platform_device *pdev) { struct pps_tio *tio = platform_get_drvdata(pdev); + unsigned long flags; + mutex_lock(&tio->mutex); hrtimer_cancel(&tio->timer); + spin_lock_irqsave(&tio->lock, flags); pps_tio_disable(tio); + spin_unlock_irqrestore(&tio->lock, flags); + mutex_unlock(&tio->mutex); pps_gen_unregister_source(tio->pps_gen); } -- 2.43.0