Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp17880pxb; Mon, 13 Sep 2021 11:45:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6rhvx/OOi6EIH5dmbM8w7ewBf76KVWfpZqQ5HJhyV22M3UqLpwawT8D5Edic1qEMyusHj X-Received: by 2002:a6b:5911:: with SMTP id n17mr10253797iob.180.1631558739624; Mon, 13 Sep 2021 11:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631558739; cv=none; d=google.com; s=arc-20160816; b=fa9YC8FN+nkKOpn6vDY4pFdnACkisONCw/y/wIdJBt1yyfurh9apNgJXg9j821Bukb e+HuwVMBpGlDvWj9ER0mdo+jU9z82wbT1r9ubhgBzgLMbAl+EgKIOOaTXerZLJaWg6Bz vqLMe4uAwDKGJG3kLL8S/ePd0d1bhY5nLR4EOSzzs8GsLUSffKzU0JycVjoKyZFj/Z9z E1qD627RWISv+ih4i8TCmSnl4BBfmKNuVRu5SXShGYe2lrrVE5TvUM1PZD44A9/w985c za+KOf0nkhVojIRYjDNsfeDzflGSjTh5FT4o8DOvvqCbfZwdDetRVm45zxNiSHUh/J4k Ok7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DzYnGSGPOqFHiEiafhgCihRRo8fRBJdq8vL8cGsp+e4=; b=oaVQSrJfXOVEj/fGO41CWxh1vhcUaugqtZGSNzeF4u0MtBAj4cWpwkJfZZst2Iynw+ qgDIDLeNIaBbntu9Ave9bUTlC+41RlKNCEZZx4RtyX41F0ar9zVyWilNdRXPteUIIEB2 vjxUlee4RXmlTXevXKvaEgHJ6tSkxeFNtUuv87B8YI/mwX2JtZQS33YeQIz6VH79JdIm jJV1mfTHYdo07qHe8+UunKYpXy7PnabMjIdTb4DfPwlXOTmW8IXLMkPNodJRkSkAHKvG 8rGNOrcb2FAIRNkH30txm5Iutb0AdFqzyaAzV/qrryDwq1SQU9C7ZLwLc8qcZ0GuHPkj zaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wCfafu/W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q17si7455044ilj.164.2021.09.13.11.45.27; Mon, 13 Sep 2021 11:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wCfafu/W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240855AbhIMNXM (ORCPT + 99 others); Mon, 13 Sep 2021 09:23:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:34848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240631AbhIMNVW (ORCPT ); Mon, 13 Sep 2021 09:21:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92766610CC; Mon, 13 Sep 2021 13:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539202; bh=68J+BQWmQsJqIu3OXB9QcfN9zA7ylUU1onZUfpipXd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wCfafu/WKci+2WxDRkHIU/7GLyoxZnTRCqIilb6uFo0BhbGGms/+D47jNdH/vQHwn /xDWEfK1QKA5q8h59Cxf/aZj1i9wE16iARPl5Vo1a9WIfFHIpQpUl7GzeTUDSiJ4JN mnT2RhFw6iACfDUyZkODJeMRkflvGwrV0jhlB4UU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephan Gerhold , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.4 079/144] soc: qcom: smsm: Fix missed interrupts if state changes while masked Date: Mon, 13 Sep 2021 15:14:20 +0200 Message-Id: <20210913131050.608126748@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephan Gerhold [ Upstream commit e3d4571955050736bbf3eda0a9538a09d9fcfce8 ] The SMSM driver detects interrupt edges by tracking the last state it has seen (and has triggered the interrupt handler for). This works fine, but only if the interrupt does not change state while masked. For example, if an interrupt is unmasked while the state is HIGH, the stored last_value for that interrupt might still be LOW. Then, when the remote processor triggers smsm_intr() we assume that nothing has changed, even though the state might have changed from HIGH to LOW. Attempt to fix this by checking the current remote state before unmasking an IRQ. Use atomic operations to avoid the interrupt handler from interfering with the unmask function. This fixes modem crashes in some edge cases with the BAM-DMUX driver. Specifically, the BAM-DMUX interrupt handler is not called for the HIGH -> LOW smsm state transition if the BAM-DMUX driver is loaded (and therefore unmasks the interrupt) after the modem was already started: qcom-q6v5-mss 4080000.remoteproc: fatal error received: a2_task.c:3188: Assert FALSE failed: A2 DL PER deadlock timer expired waiting for Apps ACK Fixes: c97c4090ff72 ("soc: qcom: smsm: Add driver for Qualcomm SMSM") Signed-off-by: Stephan Gerhold Link: https://lore.kernel.org/r/20210712135703.324748-2-stephan@gerhold.net Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/soc/qcom/smsm.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/soc/qcom/smsm.c b/drivers/soc/qcom/smsm.c index 70c3c90b997c..c428d0f78816 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -109,7 +109,7 @@ struct smsm_entry { DECLARE_BITMAP(irq_enabled, 32); DECLARE_BITMAP(irq_rising, 32); DECLARE_BITMAP(irq_falling, 32); - u32 last_value; + unsigned long last_value; u32 *remote_state; u32 *subscription; @@ -204,8 +204,7 @@ static irqreturn_t smsm_intr(int irq, void *data) u32 val; val = readl(entry->remote_state); - changed = val ^ entry->last_value; - entry->last_value = val; + changed = val ^ xchg(&entry->last_value, val); for_each_set_bit(i, entry->irq_enabled, 32) { if (!(changed & BIT(i))) @@ -266,6 +265,12 @@ static void smsm_unmask_irq(struct irq_data *irqd) struct qcom_smsm *smsm = entry->smsm; u32 val; + /* Make sure our last cached state is up-to-date */ + if (readl(entry->remote_state) & BIT(irq)) + set_bit(irq, &entry->last_value); + else + clear_bit(irq, &entry->last_value); + set_bit(irq, entry->irq_enabled); if (entry->subscription) { -- 2.30.2