Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2563391lkm; Mon, 20 Sep 2021 18:48:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeZW+gOCFuXmhRTk7Q1JsGSuIh8SP3pc/THr1S23FwL5Vd273AvmQdNKqE7tpP3TcBUsYb X-Received: by 2002:a05:6e02:1d0c:: with SMTP id i12mr20517088ila.209.1632188822437; Mon, 20 Sep 2021 18:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188822; cv=none; d=google.com; s=arc-20160816; b=h+rZP6vSKH5aZNoY55RSTzUqTiDpdXYmzefXVusTJLtX+lWcOxPfiMYryqdcvjC6wf 06KyscHp4RGiHHa7z/RNy7hlBIV2Ul37Yj2lE6aoQiI8W6jfDkxcOs173hZ1jD/vTkdu 2RzPxh5+TaxX0jVC0xcdZdKy8rAx9UFa2qrWFo8phEX8R1cPGthF7use4GIf3/FyGmgu 9X3pVy+W7WxGwLe86bq8jeF1gvbxNygQKapYDPKoNsfAVoabhM8IFfjEoiwp8kHh1Uo4 UGhNPB5hFL9nVS6B264MmZspMVs7iDIoTxSDhYlFv33xceFAd4BeUINFZFRQIeNf+sNX +F4g== 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=7jrbWqkLScrlk2fL0QXCFbgLixfKnRzKFZAAk/yUPgg=; b=sHAW2d+W0bluraX/UkkIluQC9X5RBFrEMUUBMEpJ5n03AJzoqBgJ08IxL3i2aKe4bb SYDXdbyVrT3v3/sHqJdQCi/xXZro9Rksm1ICzxYJ0FY6NSrK0q4wmfeJek2jPGrtUK0C YZWkW7EA4nilBh8NhOH6jOcjdZQgDRpziqwtZHPmrFW0TOXEmYkJpv9app09PGF+nphj +u/+TcKJ9f8K48jhrrGoe96Yjv7uSU0Vk2qQO2hmjpmeSsyh7uyVHLZcaJU2+yya8jm4 KyE9c0cq1YrT8dXfdOp1dueGI8ETihSp1jEp93JDE0Y3ShI1ZpmG0pHxcnXWYdA6AOXo L+uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dX89HFcz; 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 w7si17598427jad.86.2021.09.20.18.46.51; Mon, 20 Sep 2021 18:47:02 -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=dX89HFcz; 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 S244159AbhITRRo (ORCPT + 99 others); Mon, 20 Sep 2021 13:17:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:42490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345840AbhITRPf (ORCPT ); Mon, 20 Sep 2021 13:15:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EA482613B3; Mon, 20 Sep 2021 16:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157120; bh=BLj3GZcIkNnuaVMECh7rOuTP0dIwv6QQNrOzkFYmVik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dX89HFczNER+nWbjopdM50wY6vUtVfXCtNVXPjiqypyDAqaPzuK0lbLKbtkva3UR2 P7HjuISmYlGdmlfLytxkWjgryAj2ZyRv99lJBzSh0QnIV1V6uuRKpWam8jDiaBlk9w nGwlGXBBMIP8816HPl6cYoo4vY+9QDXkPknCd4gk= 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 4.14 062/217] soc: qcom: smsm: Fix missed interrupts if state changes while masked Date: Mon, 20 Sep 2021 18:41:23 +0200 Message-Id: <20210920163926.726787504@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163924.591371269@linuxfoundation.org> References: <20210920163924.591371269@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 50214b620865..2b49d2c212da 100644 --- a/drivers/soc/qcom/smsm.c +++ b/drivers/soc/qcom/smsm.c @@ -117,7 +117,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; @@ -212,8 +212,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))) @@ -274,6 +273,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