Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3639432pxb; Mon, 24 Jan 2022 14:09:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjeGCRgblnwew2E2jvuyFnJ4iqITPm6FkfTOJlNis6EgBPJwtk7CjIY3croAfFFwfsKNeV X-Received: by 2002:a17:902:7287:b0:14a:b594:7fa1 with SMTP id d7-20020a170902728700b0014ab5947fa1mr15698166pll.117.1643062162891; Mon, 24 Jan 2022 14:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062162; cv=none; d=google.com; s=arc-20160816; b=FBKOfTxKmPh/S/4T3ZI8Hp+Z30CR7RX01G/8YwIhy0eUK/Gdpt46VIG+Q9tZ31HPO+ otjhbVFoKXq8f1mrafu3S/5H8D9QIFAsrGY7gIBsXzFyRfU9ReJpwrW7TdfOnxQqJcds axL19yk4ppmYGx+NqlX5tWLZW+oh3h1DEciareyRdH8aut5wQq+kIa9BQTZWXShXCkT+ 86DzaTJUe5FAY8a0drRxlmFW4abMk1T7HUv+OPGEh9HSDsvytjOmx5b0p/D5OaDIwIwj TEzb87yzukVjI72bKgBt3fFP72pCQ930LywBNyg/EBQuInEstQXZVwkQaUWVnVTBnkf4 c7JA== 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=nOjZpm5/4ehGkn8J3oq+CIXe3K2gCLD6KxsIFu6/oAI=; b=xSM+pmZp1cRBnRVEpNdzSA1JWyj2u7yKA+gj3XvxvErKyruljScZR/IZ/eWVejHOO9 c2OsO03q6LInt3jnUus/nNQuU3pT0PmYv/tMnQbPEzw4HvIBiTNeP0p8ykCuyMJf/H20 nGYVzX8zE+EvsTBvLpW2AIvyQmq71HxYfgljnDgDbj4b183AadndHJvU6D7+iRpEG32u VdSk9JlK5R40IqPG6zqCWx8LKNDdj5NqE1Q1Aqrc5yn0jiRdmVQuHp9aVkwfNL7iITFk ccJ1YrB6zgQls0vN/JN6/jZTbNuhjCmPrYd8p75EY4eW6b9C/mQZ0AoT6GHwbcl8Glhu GsyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1xY+v5GQ; 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 m9si1717022pll.287.2022.01.24.14.09.10; Mon, 24 Jan 2022 14:09:22 -0800 (PST) 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=1xY+v5GQ; 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 S1576540AbiAXVzM (ORCPT + 99 others); Mon, 24 Jan 2022 16:55:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1449975AbiAXVRk (ORCPT ); Mon, 24 Jan 2022 16:17:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17819C067A6A; Mon, 24 Jan 2022 12:12:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9AEDD61368; Mon, 24 Jan 2022 20:12:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 816CBC340ED; Mon, 24 Jan 2022 20:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055160; bh=XmunwkHp3uSTDer0TGSDoR8vFkcsn6YyKg9JSHU7/wM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1xY+v5GQ2+PqgpBj+pJ9VOu5qeITENCzswVp6t0sP16a/T8MlNHuvOzfiRH2uhjpu bLAvbhesBj3nbkIW4frL7s8KrA+JfBDfmrQ2NTjVry2c70SZ6xkKYvV73Stz05o5F+ LDt3Aq0mG6j2gD36lOuSyxyChUVUysNI2cYPcAdo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aleksander Morgado , Thomas Perrot , Manivannan Sadhasivam Subject: [PATCH 5.15 060/846] bus: mhi: core: Fix race while handling SYS_ERR at power up Date: Mon, 24 Jan 2022 19:32:57 +0100 Message-Id: <20220124184103.036530225@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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: Manivannan Sadhasivam commit d651ce8e917fa1bf6cfab8dca74c512edffc35d3 upstream. During SYS_ERR condition, as a response to the MHI_RESET from host, some devices tend to issue BHI interrupt without clearing the SYS_ERR state in the device. This creates a race condition and causes a failure in booting up the device. The issue is seen on the Sierra Wireless EM9191 modem during SYS_ERR handling in mhi_async_power_up(). Once the host detects that the device is in SYS_ERR state, it issues MHI_RESET and waits for the device to process the reset request. During this time, the device triggers the BHI interrupt to the host without clearing SYS_ERR condition. So the host starts handling the SYS_ERR condition again. To fix this issue, let's register the IRQ handler only after handling the SYS_ERR check to avoid getting spurious IRQs from the device. Fixes: e18d4e9fa79b ("bus: mhi: core: Handle syserr during power_up") Cc: stable@vger.kernel.org Reported-by: Aleksander Morgado Tested-by: Aleksander Morgado Tested-by: Thomas Perrot Signed-off-by: Manivannan Sadhasivam Link: https://lore.kernel.org/r/20211216081227.237749-8-manivannan.sadhasivam@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/bus/mhi/core/pm.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) --- a/drivers/bus/mhi/core/pm.c +++ b/drivers/bus/mhi/core/pm.c @@ -1053,7 +1053,7 @@ int mhi_async_power_up(struct mhi_contro enum mhi_ee_type current_ee; enum dev_st_transition next_state; struct device *dev = &mhi_cntrl->mhi_dev->dev; - u32 val; + u32 interval_us = 25000; /* poll register field every 25 milliseconds */ int ret; dev_info(dev, "Requested to power ON\n"); @@ -1070,10 +1070,6 @@ int mhi_async_power_up(struct mhi_contro mutex_lock(&mhi_cntrl->pm_mutex); mhi_cntrl->pm_state = MHI_PM_DISABLE; - ret = mhi_init_irq_setup(mhi_cntrl); - if (ret) - goto error_setup_irq; - /* Setup BHI INTVEC */ write_lock_irq(&mhi_cntrl->pm_lock); mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0); @@ -1087,7 +1083,7 @@ int mhi_async_power_up(struct mhi_contro dev_err(dev, "%s is not a valid EE for power on\n", TO_MHI_EXEC_STR(current_ee)); ret = -EIO; - goto error_async_power_up; + goto error_exit; } state = mhi_get_mhi_state(mhi_cntrl); @@ -1096,20 +1092,12 @@ int mhi_async_power_up(struct mhi_contro if (state == MHI_STATE_SYS_ERR) { mhi_set_mhi_state(mhi_cntrl, MHI_STATE_RESET); - ret = wait_event_timeout(mhi_cntrl->state_event, - MHI_PM_IN_FATAL_STATE(mhi_cntrl->pm_state) || - mhi_read_reg_field(mhi_cntrl, - mhi_cntrl->regs, - MHICTRL, - MHICTRL_RESET_MASK, - MHICTRL_RESET_SHIFT, - &val) || - !val, - msecs_to_jiffies(mhi_cntrl->timeout_ms)); - if (!ret) { - ret = -EIO; + ret = mhi_poll_reg_field(mhi_cntrl, mhi_cntrl->regs, MHICTRL, + MHICTRL_RESET_MASK, MHICTRL_RESET_SHIFT, 0, + interval_us); + if (ret) { dev_info(dev, "Failed to reset MHI due to syserr state\n"); - goto error_async_power_up; + goto error_exit; } /* @@ -1119,6 +1107,10 @@ int mhi_async_power_up(struct mhi_contro mhi_write_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_INTVEC, 0); } + ret = mhi_init_irq_setup(mhi_cntrl); + if (ret) + goto error_exit; + /* Transition to next state */ next_state = MHI_IN_PBL(current_ee) ? DEV_ST_TRANSITION_PBL : DEV_ST_TRANSITION_READY; @@ -1131,10 +1123,7 @@ int mhi_async_power_up(struct mhi_contro return 0; -error_async_power_up: - mhi_deinit_free_irq(mhi_cntrl); - -error_setup_irq: +error_exit: mhi_cntrl->pm_state = MHI_PM_DISABLE; mutex_unlock(&mhi_cntrl->pm_mutex);