Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1508880ybk; Thu, 21 May 2020 08:31:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdWOGG3krIYwrRbUIysTspBtDskq9xTqMmcEaSA94F5Eid0IXykEwu1Dn/pMC58MtKyRw5 X-Received: by 2002:a17:906:d86:: with SMTP id m6mr4308320eji.434.1590075079942; Thu, 21 May 2020 08:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590075079; cv=none; d=google.com; s=arc-20160816; b=a5w637BcY5q8Q87/AMBHKOsVigROu09IRZD7IKktFfjU93/8YASb4hqNKqYcE3lLT8 Up7eQ2nw/0rV/OGfPmL1iSnfIiwpKl3mzRmze+lu+Seh59Zp4wfJc7ln5W/0oe/shit/ vOL1cfV+hMdOUkW/vhqZVDe0UUBcLlBlQb2Vcy57dwtZu2POUmdh+nm7c1EB4ULwx8R/ VhkQP6EKGnM/BnpeZEZA8gUbglTMmPbCZ0hCQ9xxBn8fzKCCGdJmdkwGLNNLjhIbLYuC O1F3mJK2xXZqaecVEmy5ohwE3xscrQxuA6kIDJ4ZhC5l5GdwaXj8XUbEpVop7S0flXBT teXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1UPi6KXD2ozzx7S9Xe0x0uwZY2PPL0bmxurLn/Vc5yE=; b=aI1Nz57+F65ezTagWIYIwj+poDgzGVaJxoDoAxbsPxlSRvnwwrvkLrlR0Svk8pat9n GPv8JcwsxqQdJ4Kx88zyQUuFvvSyihR96w9k6oFk0vdE7Gz9va/VYYBpDzBaXZ/lrhIu XzIET3TyxyeaaZT33FRMcPZ4eiWcyQv9v10iE3B0SAMhx2mvuSZXbJ6ABrt6/8kbuu+o zNzAhYZMswUv3H62tQukMmnB2XSgONweydqbL0bbfwi4w1NvelZmXTQkM6PpujJ4GgJW jD9gOaQ0efKQuSyiWeS/N/v3eDercqgE37Evl7I2VWfvEdRE3sboctma07NGnDrcPxYI i4nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hotm1BUK; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si3502653edi.386.2020.05.21.08.30.56; Thu, 21 May 2020 08:31:19 -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=@kernel.org header.s=default header.b=hotm1BUK; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730216AbgEUP0k (ORCPT + 99 others); Thu, 21 May 2020 11:26:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:34630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729934AbgEUP0i (ORCPT ); Thu, 21 May 2020 11:26:38 -0400 Received: from localhost.localdomain (unknown [157.51.235.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C5FE207D8; Thu, 21 May 2020 15:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590074798; bh=w4NzUuXGukrJVMcba8p1fzwvN0PIx7taxwBtf2rtRzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hotm1BUKJ3KMC/iW31PCN8MvJLumc0AS7/cqsrrxhGYP/EPfpq8H99EhOFyucZFaO lMeUcWwBySXpEFqwXeAEzk3wYQUg5b+JKAb2RPyaClLigM3qRbQebmijJ3LpSZ657R DUZx8YTxWw6up4urQuJn39zJckYIkOC2cVYeqrAc= From: mani@kernel.org To: gregkh@linuxfoundation.org Cc: hemantk@codeaurora.org, jhugo@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH 10/14] bus: mhi: core: Handle disable transitions in state worker Date: Thu, 21 May 2020 20:55:36 +0530 Message-Id: <20200521152540.17335-11-mani@kernel.org> X-Mailer: git-send-email 2.26.GIT In-Reply-To: <20200521152540.17335-1-mani@kernel.org> References: <20200521152540.17335-1-mani@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hemant Kumar Mission mode transition is handled by state worker thread but power off is not. There is a possibility while mission mode transition is in progress which calls MHI client driver probe, power off is issued by MHI controller. This results into client driver probe and remove running in parallel and causes use after free situation. By queuing disable transition work when mission mode is in progress prevents the race condition. Signed-off-by: Hemant Kumar Reviewed-by: Jeffrey Hugo Reviewed-by: Manivannan Sadhasivam Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/init.c | 1 + drivers/bus/mhi/core/internal.h | 1 + drivers/bus/mhi/core/pm.c | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index 3a853c5d2103..12207cc438aa 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -35,6 +35,7 @@ const char * const dev_state_tran_str[DEV_ST_TRANSITION_MAX] = { [DEV_ST_TRANSITION_SBL] = "SBL", [DEV_ST_TRANSITION_MISSION_MODE] = "MISSION_MODE", [DEV_ST_TRANSITION_SYS_ERR] = "SYS_ERR", + [DEV_ST_TRANSITION_DISABLE] = "DISABLE", }; const char * const mhi_state_str[MHI_STATE_MAX] = { diff --git a/drivers/bus/mhi/core/internal.h b/drivers/bus/mhi/core/internal.h index f01283b8a451..b1f640b75a94 100644 --- a/drivers/bus/mhi/core/internal.h +++ b/drivers/bus/mhi/core/internal.h @@ -387,6 +387,7 @@ enum dev_st_transition { DEV_ST_TRANSITION_SBL, DEV_ST_TRANSITION_MISSION_MODE, DEV_ST_TRANSITION_SYS_ERR, + DEV_ST_TRANSITION_DISABLE, DEV_ST_TRANSITION_MAX, }; diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c index 743b3207c390..a5d9973059c8 100644 --- a/drivers/bus/mhi/core/pm.c +++ b/drivers/bus/mhi/core/pm.c @@ -657,6 +657,10 @@ void mhi_pm_st_worker(struct work_struct *work) mhi_pm_disable_transition (mhi_cntrl, MHI_PM_SYS_ERR_PROCESS); break; + case DEV_ST_TRANSITION_DISABLE: + mhi_pm_disable_transition + (mhi_cntrl, MHI_PM_SHUTDOWN_PROCESS); + break; default: break; } @@ -868,7 +872,12 @@ void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful) to_mhi_pm_state_str(MHI_PM_LD_ERR_FATAL_DETECT), to_mhi_pm_state_str(mhi_cntrl->pm_state)); } - mhi_pm_disable_transition(mhi_cntrl, MHI_PM_SHUTDOWN_PROCESS); + + mhi_queue_state_transition(mhi_cntrl, DEV_ST_TRANSITION_DISABLE); + + /* Wait for shutdown to complete */ + flush_work(&mhi_cntrl->st_worker); + mhi_deinit_free_irq(mhi_cntrl); if (!mhi_cntrl->pre_init) { -- 2.26.GIT