From patchwork Mon Nov 8 12:08:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 12608325 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 229D6C433EF for ; Mon, 8 Nov 2021 12:08:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBEC961288 for ; Mon, 8 Nov 2021 12:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237547AbhKHMLa (ORCPT ); Mon, 8 Nov 2021 07:11:30 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:36512 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239392AbhKHMLS (ORCPT ); Mon, 8 Nov 2021 07:11:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1636373314; x=1667909314; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=y9dAdITeyho9JZ1fdEyHwV0AKFYcnTmIurhlclr4oDg=; b=PbaHruflHsnWHQjwahcPdNSoP3o37y0QX4p79/Fpn5nmvdwiwr3sGq7T ec7hu3Vh6yku5miVvPCRO4JemJqFL1gGRh7I84gCXq7zMcaNoZDpzhfMf bMjgWuX50DLQbbtrR+ikUcSH34+Aq/VxgFeL44UA2+UcRvmsS296ni9nQ EdsWZ3fzCVySWSLB0TJbrOYkpYSQCtyCy3dfASijfH+5ibsw05MtYY3du fINRsfxK/qdyL2IIZ+JJSwcAtHoQoQWuHA4FXD8jOrLjDWWW/EublcTeU xPN0r5vffwr1soPPcVexILduxkD5I7wm7EiqMzqWNSwurSX97aGkEaBV/ g==; X-IronPort-AV: E=Sophos;i="5.87,218,1631548800"; d="scan'208";a="288933027" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Nov 2021 20:08:31 +0800 IronPort-SDR: 58FB5O1OXNrfzMxLS45F6d15rZ/Pn7Zxp01iXaoVZdkurvYu84sANDH4ZYLT1hyVUhfXRWCrzt 4ty7uKDT8J1P8klWD+Vxy1qFJHYIhoz+i/PMVhGfYiY3b86mjXkzsoot0aua7O2DUKU3bsS3sW 0diYsY6ggTtue8wqULB1SnIRZb6IWcPAqg6AdJ5S+If+E/QCBoAbtmamEbJ+aFe0n1O4Ykw3aL JCRyk6hMahB/9pCRxp+3HmW+EywfVQKyLamvprof5kF4lCUeJIyoGMmTUvkmpFY7QsM/aM9raT j7M1x2qLKMl2KNAsPcL9dz3a Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2021 03:42:11 -0800 IronPort-SDR: 7CebQx7aIiRd3kBjxMLuIyQ7jqLicBpcCK/Oa92jA5UZiX2kpJ4sik+PDxevCw3jUFw3894Gs8 D69oKov6mxdAoj/4CclV78Vhm/CGJAwZujNtJT5Gt6xW6s178AGQ2EYCDXQTuMh7v0doGIvLMD BvB578mzM3BJEyiC3RXHv8V33H6DJCEuGyjmwuhgQIWE0lddSTqVapbUQUFkPhF+8vkbLDlBuS ZCmUX2ZWuMKagZNs9XR3IMkhf8PkxEAwEkzwa4vyloUy6fa7lj0DagtQzYMSpfzG8vW7FUeVtK 0PA= WDCIronportException: Internal Received: from c8jqy33.ad.shared (HELO BXYGM33.ad.shared) ([10.225.32.157]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Nov 2021 04:08:28 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Adrian Hunter , Avri Altman Subject: [PATCH 1/2] scsi: ufs: Inline eh-in-progress states Date: Mon, 8 Nov 2021 14:08:03 +0200 Message-Id: <20211108120804.10405-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211108120804.10405-1-avri.altman@wdc.com> References: <20211108120804.10405-1-avri.altman@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Improve the static type checking. while at it, do not allow user-space access if eh-in-progress. Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshcd.c | 12 ------------ drivers/scsi/ufs/ufshcd.h | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 470affdec426..3869bb57769b 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -140,11 +140,6 @@ static const char *const ufshcd_state_name[] = { [UFSHCD_STATE_EH_SCHEDULED_NON_FATAL] = "eh_non_fatal", }; -/* UFSHCD error handling flags */ -enum { - UFSHCD_EH_IN_PROGRESS = (1 << 0), -}; - /* UFSHCD UIC layer error flags */ enum { UFSHCD_UIC_DL_PA_INIT_ERROR = (1 << 0), /* Data link layer error */ @@ -156,13 +151,6 @@ enum { UFSHCD_UIC_PA_GENERIC_ERROR = (1 << 6), /* Generic PA error */ }; -#define ufshcd_set_eh_in_progress(h) \ - ((h)->eh_flags |= UFSHCD_EH_IN_PROGRESS) -#define ufshcd_eh_in_progress(h) \ - ((h)->eh_flags & UFSHCD_EH_IN_PROGRESS) -#define ufshcd_clear_eh_in_progress(h) \ - ((h)->eh_flags &= ~UFSHCD_EH_IN_PROGRESS) - struct ufs_pm_lvl_states ufs_pm_lvl_states[] = { [UFS_PM_LVL_0] = {UFS_ACTIVE_PWR_MODE, UIC_LINK_ACTIVE_STATE}, [UFS_PM_LVL_1] = {UFS_ACTIVE_PWR_MODE, UIC_LINK_HIBERN8_STATE}, diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 4ceb3c7e65b4..c5d98052a20a 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -992,9 +992,33 @@ static inline bool ufshcd_is_wb_allowed(struct ufs_hba *hba) return hba->caps & UFSHCD_CAP_WB_EN; } +/* UFSHCD error handling flags */ +enum { + UFSHCD_EH_IN_PROGRESS = (1 << 0), +}; + +static inline void ufshcd_set_eh_in_progress(struct ufs_hba *hba) +{ + lockdep_assert_held(hba->host->host_lock); + + hba->eh_flags |= UFSHCD_EH_IN_PROGRESS; +} + +static inline void ufshcd_clear_eh_in_progress(struct ufs_hba *hba) +{ + lockdep_assert_held(hba->host->host_lock); + + hba->eh_flags &= ~UFSHCD_EH_IN_PROGRESS; +} + +static inline bool ufshcd_eh_in_progress(struct ufs_hba *hba) +{ + return hba->eh_flags & UFSHCD_EH_IN_PROGRESS; +} + static inline bool ufshcd_is_user_access_allowed(struct ufs_hba *hba) { - return !hba->shutting_down; + return !hba->shutting_down && !ufshcd_eh_in_progress(hba); } #define ufshcd_writel(hba, val, reg) \ From patchwork Mon Nov 8 12:08:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 12608327 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71ECBC433FE for ; Mon, 8 Nov 2021 12:08:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DCF16120D for ; Mon, 8 Nov 2021 12:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239406AbhKHMLb (ORCPT ); Mon, 8 Nov 2021 07:11:31 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:18555 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239397AbhKHML1 (ORCPT ); Mon, 8 Nov 2021 07:11:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1636373324; x=1667909324; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=UgIeZhHhFCvWkz7a2C4s/pc1I+RA/IV4MdJK1v7cpyo=; b=CC3BYbznMZVClTnKHFLBgHiWwl3wH2qwNmDQGIfba6Xhh6YW/W+pr0iB 3To/03IE4Dchce5F0+EL8YghSWe+AXaA015+jFzcOhUq6GTkURvN5dja/ 2Vmi3BkMBAu1aKEtZpK0yKR4zEau2HkW9N0wXRosWoXrpNdR25/UB9h2S voWu9kjUpXwc5Y8MNswcAOXk7MaTVOZdcoithHgrhloGimkcw94fqWdek 6Jn5KW6j/IiwAuyBBgLY3P9lbsHJIJzuUp4QrQ5E0yXyN0l8iuwhiM+gm BovB44/2N0xhVKR5QSR6biRJj7K/h8MqHgP2TQJV4AXk/v/DkZsIjg2s/ g==; X-IronPort-AV: E=Sophos;i="5.87,218,1631548800"; d="scan'208";a="186004981" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Nov 2021 20:08:44 +0800 IronPort-SDR: OSnO3e4Di7GTuCxTFQs0R0ZF+aWXP8ZtQgr40N8UbkV+YbLgwPG+mVjfkPTKCkVLR8N2Wv8hBe FLzLrhV8eRLVgV/H74V54Df03wevdHe378DgI4hGrRN84ni+qFcCZFTIQwSMsUQe2lpghbIPre 7uMmuY2HJkFcXjLOAydPQYjgfEQNEH2qjkFxs0etkV8a3NW040NBaKY38Z9rCp8q6VHNk7dpjh mY5oZ9rR8ccrzNAaZ6FuSI7Yg7pfCNdaoiutZdcXjVMxqjhwVxrqCFXIWf6InEDUl68YfGJDPS K4aYvkfj+1lJt7Y8b+YK/TJY Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2021 03:43:57 -0800 IronPort-SDR: FMwohQDm909k9GAVDcLncd0NHveJjNrD2kiB7t2wfqC5sYwwGfgQvZj/6o3Ge1jHZqWlguP/Bk y8IrVulXrUu6KN2dzTKtgeWYXyq/UpQsn1gRGO3yqLoCHxz+ffS63VR9/CHm5GNCP0SAnn05Wu LxtHkgvHY/ex9HpxFmkS0VMOdzqNe9UzGRw7ARyZdc7KiiQ4wJ6RZdZbxnAPHidT1OoJXelFF/ PuwOT21YDE1MJQm53mvGQyG1YjNtTHNotN2RhDI9k5ODsfIG6NfYE4IzecoFrOZSi/kaAM025X Vu0= WDCIronportException: Internal Received: from c8jqy33.ad.shared (HELO BXYGM33.ad.shared) ([10.225.32.157]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Nov 2021 04:08:40 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Adrian Hunter , Avri Altman Subject: [PATCH 2/2] scsi: ufs: Return a bsg request immediatley if eh-in-progress Date: Mon, 8 Nov 2021 14:08:04 +0200 Message-Id: <20211108120804.10405-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211108120804.10405-1-avri.altman@wdc.com> References: <20211108120804.10405-1-avri.altman@wdc.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org ufs-bsg is attempting to access the device from user-space, and it is unaware of the internal driver flows, specifically if error handling is currently ongoing. Fixes: 5e0a86eed846 (scsi: ufs: Add API to execute raw upiu commands) Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshcd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 3869bb57769b..828061c05909 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -6830,6 +6830,9 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, enum utp_ocs ocs_value; u8 tm_f = be32_to_cpu(req_upiu->header.dword_1) >> 16 & MASK_TM_FUNC; + if (!ufshcd_is_user_access_allowed(hba)) + return -EBUSY; + switch (msgcode) { case UPIU_TRANSACTION_NOP_OUT: cmd_type = DEV_CMD_TYPE_NOP;