From patchwork Tue Nov 23 00:15:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 12633235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 270CFC433F5 for ; Tue, 23 Nov 2021 00:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231602AbhKWATM (ORCPT ); Mon, 22 Nov 2021 19:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231474AbhKWATI (ORCPT ); Mon, 22 Nov 2021 19:19:08 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F016C06173E for ; Mon, 22 Nov 2021 16:16:01 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id k1so19898049ilo.7 for ; Mon, 22 Nov 2021 16:16:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NEmK1QJjfjflHiuyd2o6AMF3Twm1DpzXXEWoKNGwee8=; b=cF9QCO6hMB+TOyzPzIroWKvCvYWL19i/hyRd6RWujnH9zJ/N7RDYfiIFFzoRFDVV2E JC2k5G+HyprQ+M4/sj081jLaUf7oJ/rPE2CDNYJShpxt5qQwmtlZrzNXMa4z45m4e/OW 9ZaoPbW1v/BkeYAKvc9OSUMJQPDiYpKCGyDNdNpHS7DLukNWjwIlN6dsY2ZbI0T+9JKQ EsTdsTu/DPyxetba9ggN3gqUYZ5m0D/+Td4lp1XFZUTr0kCstriuy0PIUkmQv8SJ1grq tBQ2IOWU/YZihmXjLMBaP77FY8IZJ+g+tX3GbBAR5ljBXoqBmcC1anCWAjrM3Hem12KM B8GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NEmK1QJjfjflHiuyd2o6AMF3Twm1DpzXXEWoKNGwee8=; b=HWxvCgqZRC7Elof1LJGyOF/gwavWXy6kQpDT148U7HdaAJCT+CG6C2H6jAKQFhebnk tYYdO8WyXSLDz74MnnCpMbQhGTOOA0N28oPIWldVKiUEu535ZKMOaMiWcD+jR0g1Ytz0 iAjUsI2oWgkFm37KMztIoyaydM8F/NVDqpdppwYL3Ai+yiaBBebZsiKOCTsgbSasxnwu LQWYv66DOIg0ElJ5FUXcLo+Ui99Dt8MBpobJ/zO72l7DNApZF56NgLUGajI0Zq66O+xC vYHa13r6QVqtY4pt0+RRczwimKJEynL7NSy/yzccKn3ZyHaHlqLtvNdbnRVjrpgfKIF3 MwBw== X-Gm-Message-State: AOAM533hV/Umkh+Cmdb/EbuXSAiPn6zJh8xWxkHOJWYKf9QVgBIc4hvK LxU6qbwFXW+ooU2Qt7HC4KN/ng== X-Google-Smtp-Source: ABdhPJxEDc29IJ20qLK4pEwFK1cSr14nwHGLSsqw0iXT6BZqEPd7cqhgRy4CxEkfNKYeNpD4vxtBog== X-Received: by 2002:a05:6e02:156b:: with SMTP id k11mr1127886ilu.77.1637626560968; Mon, 22 Nov 2021 16:16:00 -0800 (PST) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id u4sm7040094ilv.81.2021.11.22.16.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 16:16:00 -0800 (PST) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: pkurapat@codeaurora.org, avuyyuru@codeaurora.org, bjorn.andersson@linaro.org, cpratapa@codeaurora.org, subashab@codeaurora.org, evgreen@chromium.org, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 1/2] net: ipa: directly disable ipa-setup-ready interrupt Date: Mon, 22 Nov 2021 18:15:54 -0600 Message-Id: <20211123001555.505546-2-elder@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123001555.505546-1-elder@linaro.org> References: <20211123001555.505546-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org We currently maintain a "disabled" Boolean flag to determine whether the "ipa-setup-ready" SMP2P IRQ handler does anything. That flag must be accessed under protection of a mutex. Instead, disable the SMP2P interrupt when requested, which prevents the interrupt handler from ever being called. More importantly, it synchronizes a thread disabling the interrupt with the completion of the interrupt handler in case they run concurrently. Use the IPA setup_complete flag rather than the disabled flag in the handler to determine whether to ignore any interrupts arriving after the first. Rename the "disabled" flag to be "setup_disabled", to be specific about its purpose. Fixes: 530f9216a953 ("soc: qcom: ipa: AP/modem communications") Signed-off-by: Alex Elder Reviewed-by: Matthias Kaehlcke --- drivers/net/ipa/ipa_smp2p.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/net/ipa/ipa_smp2p.c b/drivers/net/ipa/ipa_smp2p.c index df7639c39d716..24bc112a072c6 100644 --- a/drivers/net/ipa/ipa_smp2p.c +++ b/drivers/net/ipa/ipa_smp2p.c @@ -53,7 +53,7 @@ * @setup_ready_irq: IPA interrupt triggered by modem to signal GSI ready * @power_on: Whether IPA power is on * @notified: Whether modem has been notified of power state - * @disabled: Whether setup ready interrupt handling is disabled + * @setup_disabled: Whether setup ready interrupt handler is disabled * @mutex: Mutex protecting ready-interrupt/shutdown interlock * @panic_notifier: Panic notifier structure */ @@ -67,7 +67,7 @@ struct ipa_smp2p { u32 setup_ready_irq; bool power_on; bool notified; - bool disabled; + bool setup_disabled; struct mutex mutex; struct notifier_block panic_notifier; }; @@ -155,11 +155,9 @@ static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id) struct device *dev; int ret; - mutex_lock(&smp2p->mutex); - - if (smp2p->disabled) - goto out_mutex_unlock; - smp2p->disabled = true; /* If any others arrive, ignore them */ + /* Ignore any (spurious) interrupts received after the first */ + if (smp2p->ipa->setup_complete) + return IRQ_HANDLED; /* Power needs to be active for setup */ dev = &smp2p->ipa->pdev->dev; @@ -176,8 +174,6 @@ static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id) out_power_put: pm_runtime_mark_last_busy(dev); (void)pm_runtime_put_autosuspend(dev); -out_mutex_unlock: - mutex_unlock(&smp2p->mutex); return IRQ_HANDLED; } @@ -322,7 +318,10 @@ void ipa_smp2p_disable(struct ipa *ipa) mutex_lock(&smp2p->mutex); - smp2p->disabled = true; + if (!smp2p->setup_disabled) { + disable_irq(smp2p->setup_ready_irq); + smp2p->setup_disabled = true; + } mutex_unlock(&smp2p->mutex); } From patchwork Tue Nov 23 00:15:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 12633237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52072C433FE for ; Tue, 23 Nov 2021 00:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbhKWATN (ORCPT ); Mon, 22 Nov 2021 19:19:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231543AbhKWATK (ORCPT ); Mon, 22 Nov 2021 19:19:10 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F05F2C061746 for ; Mon, 22 Nov 2021 16:16:02 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id w22so25731509ioa.1 for ; Mon, 22 Nov 2021 16:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9JVWY8yzmiqkBLTZjcNhBamJOTABdufJw37vUHv4h5U=; b=Qa6zmSYsbGal3jJYf4MQ/2OZDTrNt0woF1yUot91QrIXnQ29i8S+libhyQF98zL9g/ QDdga4Ct244Ni571saW/SKBMRU6ipaH9i7PjhuI7f7yQjfJtg8LA1o6p32kFKlWAltDX aAFzmX9la45XuLap2fVhDJ2HM4G0Kai5zHg16FAZQuBv8pm2loNPUiw3u8bpZqlUXacR 1tlslKXXkADWg54+ZkJY+a54HHFUeASnZFE9EGN0Rw1+6U8brXsZ2dJmZu30YU9I3rIJ bDPISUepdrzrmCzu69FY9NxLQ/AdDDQFVgq/zyQvE3T0fyyARqolTVaSoUz+O1gfhc6x MUvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9JVWY8yzmiqkBLTZjcNhBamJOTABdufJw37vUHv4h5U=; b=q+G1q5xUFgM+Y9aLaR1eMmO/M5e/XSnJ2noqpJDbz9V3bp+7cYHmEpcLe92Trgsv+1 98rNdjBywksZo0A5qtGaVS0G19JQDWytqdLgo4VZWx2CJdphsMrK6EyCe0228lP/2eK0 c/s55Qsu5GJXIewi0RUy0a4JIVfeQMACTcfybsdhgnOUnDKvsuYYzzA9gz2eOm16QIJU vDq6XTTrvKwyoxtC/f4G2w3a4osyLW5VPIKuiXIoRPn/JG5KpvBAJEGRQR4U843g547D KRFsbO8oqIcPqts+BhKzehb24IPky57jp9hFdAWfn3WPBG7cAlliuYK6lmcc37k1wUUr j31g== X-Gm-Message-State: AOAM533O1vvRcb1dwHorGGUVWiq2ugF56khtHQs9giUmD6eDnTZEAHDc LCgYfOlLiNJ1hGiAl2QnR2T8iQ== X-Google-Smtp-Source: ABdhPJyowziwsrYTNOPpw8QYCA84ADW6AroUKr6Emgq23VChEoplQt9v1VLY9U+rh5jEPQECMomtxg== X-Received: by 2002:a05:6602:2e03:: with SMTP id o3mr1207862iow.14.1637626562356; Mon, 22 Nov 2021 16:16:02 -0800 (PST) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id u4sm7040094ilv.81.2021.11.22.16.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 16:16:01 -0800 (PST) From: Alex Elder To: davem@davemloft.net, kuba@kernel.org Cc: pkurapat@codeaurora.org, avuyyuru@codeaurora.org, bjorn.andersson@linaro.org, cpratapa@codeaurora.org, subashab@codeaurora.org, evgreen@chromium.org, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 2/2] net: ipa: separate disabling setup from modem stop Date: Mon, 22 Nov 2021 18:15:55 -0600 Message-Id: <20211123001555.505546-3-elder@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123001555.505546-1-elder@linaro.org> References: <20211123001555.505546-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The IPA setup_complete flag is set at the end of ipa_setup(), when the setup phase of initialization has completed successfully. This occurs as part of driver probe processing, or (if "modem-init" is specified in the DTS file) it is triggered by the "ipa-setup-ready" SMP2P interrupt generated by the modem. In the latter case, it's possible for driver shutdown (or remove) to begin while setup processing is underway, and this can't be allowed. The problem is that the setup_complete flag is not adequate to signal that setup is underway. If setup_complete is set, it will never be un-set, so that case is not a problem. But if setup_complete is false, there's a chance setup is underway. Because setup is triggered by an interrupt on a "modem-init" system, there is a simple way to ensure the value of setup_complete is safe to read. The threaded handler--if it is executing--will complete as part of a request to disable the "ipa-modem-ready" interrupt. This means that ipa_setup() (which is called from the handler) will run to completion if it was underway, or will never be called otherwise. The request to disable the "ipa-setup-ready" interrupt is currently made within ipa_modem_stop(). Instead, disable the interrupt outside that function in the two places it's called. In the case of ipa_remove(), this ensures the setup_complete flag is safe to read before we read it. Rename ipa_smp2p_disable() to be ipa_smp2p_irq_disable_setup(), to be more specific about its effect. Fixes: 530f9216a953 ("soc: qcom: ipa: AP/modem communications") Signed-off-by: Alex Elder --- drivers/net/ipa/ipa_main.c | 6 ++++++ drivers/net/ipa/ipa_modem.c | 6 +++--- drivers/net/ipa/ipa_smp2p.c | 2 +- drivers/net/ipa/ipa_smp2p.h | 7 +++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c index cdfa98a76e1f4..a448ec198bee1 100644 --- a/drivers/net/ipa/ipa_main.c +++ b/drivers/net/ipa/ipa_main.c @@ -28,6 +28,7 @@ #include "ipa_reg.h" #include "ipa_mem.h" #include "ipa_table.h" +#include "ipa_smp2p.h" #include "ipa_modem.h" #include "ipa_uc.h" #include "ipa_interrupt.h" @@ -801,6 +802,11 @@ static int ipa_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; int ret; + /* Prevent the modem from triggering a call to ipa_setup(). This + * also ensures a modem-initiated setup that's underway completes. + */ + ipa_smp2p_irq_disable_setup(ipa); + ret = pm_runtime_get_sync(dev); if (WARN_ON(ret < 0)) goto out_power_put; diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c index ad116bcc0580e..d0ab4d70c303b 100644 --- a/drivers/net/ipa/ipa_modem.c +++ b/drivers/net/ipa/ipa_modem.c @@ -339,9 +339,6 @@ int ipa_modem_stop(struct ipa *ipa) if (state != IPA_MODEM_STATE_RUNNING) return -EBUSY; - /* Prevent the modem from triggering a call to ipa_setup() */ - ipa_smp2p_disable(ipa); - /* Clean up the netdev and endpoints if it was started */ if (netdev) { struct ipa_priv *priv = netdev_priv(netdev); @@ -369,6 +366,9 @@ static void ipa_modem_crashed(struct ipa *ipa) struct device *dev = &ipa->pdev->dev; int ret; + /* Prevent the modem from triggering a call to ipa_setup() */ + ipa_smp2p_irq_disable_setup(ipa); + ret = pm_runtime_get_sync(dev); if (ret < 0) { dev_err(dev, "error %d getting power to handle crash\n", ret); diff --git a/drivers/net/ipa/ipa_smp2p.c b/drivers/net/ipa/ipa_smp2p.c index 24bc112a072c6..2112336120391 100644 --- a/drivers/net/ipa/ipa_smp2p.c +++ b/drivers/net/ipa/ipa_smp2p.c @@ -309,7 +309,7 @@ void ipa_smp2p_exit(struct ipa *ipa) kfree(smp2p); } -void ipa_smp2p_disable(struct ipa *ipa) +void ipa_smp2p_irq_disable_setup(struct ipa *ipa) { struct ipa_smp2p *smp2p = ipa->smp2p; diff --git a/drivers/net/ipa/ipa_smp2p.h b/drivers/net/ipa/ipa_smp2p.h index 99a9567896388..59cee31a73836 100644 --- a/drivers/net/ipa/ipa_smp2p.h +++ b/drivers/net/ipa/ipa_smp2p.h @@ -27,13 +27,12 @@ int ipa_smp2p_init(struct ipa *ipa, bool modem_init); void ipa_smp2p_exit(struct ipa *ipa); /** - * ipa_smp2p_disable() - Prevent "ipa-setup-ready" interrupt handling + * ipa_smp2p_irq_disable_setup() - Disable the "setup ready" interrupt * @ipa: IPA pointer * - * Prevent handling of the "setup ready" interrupt from the modem. - * This is used before initiating shutdown of the driver. + * Disable the "ipa-setup-ready" interrupt from the modem. */ -void ipa_smp2p_disable(struct ipa *ipa); +void ipa_smp2p_irq_disable_setup(struct ipa *ipa); /** * ipa_smp2p_notify_reset() - Reset modem notification state