From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 B45503DB62D for ; Mon, 20 Jul 2026 10:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784544041; cv=none; b=IATuFrrNoXp8nzOyK+3TOiyxcxppfRXVdbgVJmTJ/hDOg/xphBDnpkJkgs0JmNFESf9tCC3XvcU9VTopLqqmY/8R0ih/GeBxKgDpPpEPiYM+6k9BONuxTXLXJe4MdFb8fBE0IaCCmCpWlZjkytMH1NBLFIPelfB29MX7uxVQY/8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784544041; c=relaxed/simple; bh=PRHUXV6tls2F/eyT19L26E36CgR4Jha3qL9Co67zKX0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kVyDf/uHTGgmAMAqrjzDZbWmRMc6Q2zIOJIdyiVWcPMxSyWdOv4fsgvPn1AaJIRHR+y30WgmZh8/2JCtzTemxQQx/DRa7b5wLcRaLZpPQqdEHEtv/qZbgUuxfwaq2NH/UHnklStrI6jj6YTfcNiZfiwNC2HuWbxOqE8j63ZFV+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2ce98cb8165so37141185ad.1 for ; Mon, 20 Jul 2026 03:40:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784544039; x=1785148839; 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:content-type; bh=2COBYw4BWPBdbvvAp87MLasINrhEHK6G1ompJUFtwUI=; b=T7r+PLMqsqwtsIRT2R1CWAgxejsmLkHOreIi66kpsFI4gjwcb/l5qtTE3+ksOfoAuY JRqhGsUz/Wn/OAovnkBljMZ2dMkEOgQLIwp/f2L0CyfLTwQmTF/gPWucSx6dTEEcQ/TP 1x22qHyl/PGkVBJ2NfG9jOSHdxM5bGu1yYWMWbeMC+VvoInCKSTf4DWrAgFlLMYMwXtl UhHQ7CyTMut00QSOf2LisZ/26AUL6P7crCiezhufazDYlgBHlykR9CXBphl6FDsKVsgw /v8K3AHZr5+lwmNeoOfFAP9qbH6q860awh3vHhMM0ziYdikMi6gaCeiR++tvHj8EQ538 EhpA== X-Forwarded-Encrypted: i=1; AHgh+RpuRB5R34X9eNqBnqsV4o+Ovhg/yFrr7XMo+fg1lmDMYTJTgB3Pic8AqlHIbhZVbadiZS1hHWUlF+dC6mw=@vger.kernel.org X-Gm-Message-State: AOJu0YxE3vO+ox9HX9bGxBkFX5gVtOlhTka3kgVD7iatda0P9L8Zxu91 Vd9YwxBQGnX7aPuYvmvrIp63ZTh5ML6QxsqyR/u1zM0iESJijlPpKbg= X-Gm-Gg: AR+sD13Dbw+346C0J9CMeqxTK9PmQVt/vrULFesLkEqNA0C8WWZiA5LGYBPfHvdukiR +YImKOcnno55RXtM5TdLha9ZgeReRaOjCdlOPL6HPuM+5uYuQkr24NyR0VmlznXXXmj5S7Kf3nc 4v8FjU3PEYuY7wm+BM9hBIsWgmJTCmTPOk5qbqfhuG/8vb3UFIWhXmvW0B2n4t/kOG7Org26pWT bC0359rD1Q8R8ZEj7WyRT2BIjAYnPUx8rgo3d9+ZdDnHHnWPrIUHicTzhGWgqnu3Jv89Dy+Mqf7 h1BbKgOjtkR1ZIjxo5dKMcGTfeYR7g5H3n6a5pjb4OnygYyD5eaQZ3PDDv0zY38jxYHRGG3Ob0N T+MqCVvmaHfC3hemveRCvGER2hwgvBA+F6nuJn3yJzDx3svuZ/F8lh5aZ0KvwhwxdD3Dw78wtAx XOS9E8/FXVqTw2dU7ErJkhgcmK5mOyFeuOvez50tBW+0hh/VT5lsH9w6fjQZnAEnGhDKen11Wkp qz2Yp0j1E3CwVbJTQ== X-Received: by 2002:a17:903:1986:b0:2cf:18e5:1d18 with SMTP id d9443c01a7336-2cf1f5d7491mr198894955ad.29.1784544038972; Mon, 20 Jul 2026 03:40:38 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-16-100.dynamic-ip.hinet.net. [61.228.16.100]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf344f61ffsm54900325ad.33.2026.07.20.03.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 03:40:38 -0700 (PDT) From: Shih-Yuan Lee To: Mark Brown Cc: Andy Shevchenko , Daniel Mack , Haojian Zhuang , Robert Jarzmik , linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Shih-Yuan Lee Subject: [PATCH v15 2/7] spi: pxa2xx: introduce suspended flag for interrupt synchronization Date: Mon, 20 Jul 2026 18:40:24 +0800 Message-Id: <20260720104029.13740-3-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260720104029.13740-1-fourdollars@debian.org> References: <20260720104029.13740-1-fourdollars@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When a shared interrupt line is used, the interrupt handler ssp_int() can be triggered by other devices sharing the line. The handler must ensure it does not access the SSP controller registers via MMIO when the device is powered down or when its clock is gated; otherwise, it will cause PCIe Completion Timeouts and system hangs. Currently, ssp_int() guards MMIO access using: if (pm_runtime_suspended(drv_data->ssp->dev)) return IRQ_NONE; However, during PM transitions (such as system suspend or runtime PM autosuspend), device callbacks execute to disable the hardware and gate the clock, but the PM state machine does not mark the device as RPM_SUSPENDED until after the suspend callback returns. During this transitional state (RPM_SUSPENDING), pm_runtime_suspended() returns false. If a shared interrupt fires after the clock has been gated but before the PM state has transitioned, ssp_int() will execute, attempt MMIO reads on the unclocked register space, and hang the system. Formal verification using Spin/PROMELA confirms that a scheduling window exists where the interrupt thread accesses MMIO when clk_enabled is false, violating safety properties. Introduce a custom 'suspended' boolean flag in struct driver_data to track the device's suspended state across all PM transitions. Check both 'drv_data->suspended' and '!drv_data->clk_enabled' in ssp_int() to return IRQ_NONE immediately before any MMIO access is attempted. This closes the state transition race condition and mathematically guarantees deadlock-free, safe shared interrupt handling during power transitions. Signed-off-by: Shih-Yuan Lee --- drivers/spi/spi-pxa2xx.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index d50152aad348..d4a9a48c2624 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -743,12 +743,12 @@ static irqreturn_t ssp_int(int irq, void *dev_id) u32 status; /* - * The IRQ might be shared with other peripherals so we must first - * check that are we RPM suspended or not. If we are we assume that - * the IRQ was not for us (we shouldn't be RPM suspended when the - * interrupt is enabled). + * The IRQ might be shared with other peripherals or trigger during + * power state transitions. First check if device is suspended or if + * clock is disabled; if so, return IRQ_NONE immediately to avoid + * unclocked MMIO reads. */ - if (pm_runtime_suspended(drv_data->ssp->dev)) + if (drv_data->suspended || !drv_data->clk_enabled) return IRQ_NONE; /* @@ -1310,6 +1310,7 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp, drv_data->controller = controller; drv_data->controller_info = platform_info; drv_data->ssp = ssp; + drv_data->suspended = true; /* The spi->mode bits understood by this driver: */ controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; @@ -1352,11 +1353,6 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp, | SSSR_ROR | SSSR_TUR; } - status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev), - drv_data); - if (status < 0) - return dev_err_probe(dev, status, "cannot get IRQ %d\n", ssp->irq); - /* Setup DMA if requested */ if (platform_info->enable_dma) { status = pxa2xx_spi_dma_setup(drv_data); @@ -1376,7 +1372,16 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp, /* Enable SOC clock */ status = pxa2xx_spi_clk_enable(drv_data); if (status) - goto out_error_dma_irq_alloc; + goto out_error_dma_alloc; + + drv_data->suspended = false; + + status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev), + drv_data); + if (status < 0) { + status = dev_err_probe(dev, status, "cannot get IRQ %d\n", ssp->irq); + goto out_error_clock_enabled; + } controller->max_speed_hz = clk_get_rate(ssp->clk); /* @@ -1456,7 +1461,7 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp, "ready", GPIOD_OUT_LOW); if (IS_ERR(drv_data->gpiod_ready)) { status = PTR_ERR(drv_data->gpiod_ready); - goto out_error_clock_enabled; + goto out_error_irq_alloc; } } @@ -1465,17 +1470,19 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp, status = spi_register_controller(controller); if (status) { dev_err_probe(dev, status, "problem registering SPI controller\n"); - goto out_error_clock_enabled; + goto out_error_irq_alloc; } return status; +out_error_irq_alloc: + free_irq(ssp->irq, drv_data); + out_error_clock_enabled: pxa2xx_spi_clk_disable(drv_data); -out_error_dma_irq_alloc: +out_error_dma_alloc: pxa2xx_spi_dma_release(drv_data); - free_irq(ssp->irq, drv_data); return status; } -- 2.39.5