From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794460559; b=ts0znb4rLXNZwql8UQ1gH10ISgMNO50loZ23DN3vfJmZNNtvvekFOeHEhoiwZS7sVOd0 7GDPqO1u1ofR2GwMzUujZC1wryfTXUAbz8TgdOJlu6SbzhgaXlC1pKi4aRwr82A0RsIFH eOIZM8sjcgMVr8Pk8QJ47OaYn8ZSHl7yD/IgwBsn7TQEx1OtkMJHqBsECJA5r05yS0NAC IjJ1/bLMgxfBzLYjElKjj2E+aloV+VLvju+CcJyWdt3ABV2HvAzsLndhhK1nwcsVIBcxq puhCxwo5Sx1dQKLa4GBMlxF/qksycET4MF26wFm6SfDtyzFEO62YpGvcyH73zi+1Eyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794460559; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=N+HgnkkymV/qrktUNyVm3RT+UUMj6FmudRG62GmKRrY=; b=OddklV+FELUR1bXx/nAyfro7JiQjrTMfYHoBN/MlsCKJE0Nz60SJV9HtV6SC+9rHSFao cIouR9KCaIKWoHwhylscNOZgjMkSSE/JOpCUU1n1HijIDfh9PEBR0BdNjW4eFq8AiSp1u RE8HI4P7g3GeR/Fskyy1RHZoU496seSj2SU7omnCgGN8P69qSUTZJ/nfMvUxvh9ppqUWL lhW/AH3/AJ7WVO4PMKu2LuEoU5CoGhsQ2aQIRpr1iDonDp6ndhijpZL7aGANWgz4rw/Vj CaUIkgvDfA6WFVdAaQnNcFKe52mdJ0Qww7ypKYOfYz+J/NopMLxC3fL1mm7b9fxPEcA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--stanleyjhu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=d4BkTQ4R; arc=none smtp.remote-ip=209.85.210.197 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC69C60A2610 for ; Thu, 12 Nov 2026 05:15:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC69C60A2610 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--stanleyjhu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=d4BkTQ4R Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8b847ab3fd3so5046663b3a.2 for ; Wed, 11 Nov 2026 21:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1794460558; x=1795065358; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=N+HgnkkymV/qrktUNyVm3RT+UUMj6FmudRG62GmKRrY=; b=d4BkTQ4RObiVbBdQXjh7UURMch9jnhUrXWq6ZWWvVjbiKCXzumVMhfg8thdReRkhlR naHFtBrwjte4sGfml9TbgNWZ5Zh355GptcK+7qXzj8PY5hb4C0v6pwtgSuPjfgJwW1SC 5y7fKAfmyvKXd63uysJl3QcqRwlX//FpZxOqnBXcFET4kZymQJ4pG81zUb9bzxZVqWd/ xN7pSponFzaYsPHUUSDNQ8s0MZzDRRn8YjgVfzeb0viJFLN3/eGYjUe0mDV70bW3Y9Vh GbBzJ/am3ea526oN5QnLlALl7tc7pDI5mw9owhlFcexTpP3IFf74BJjY5E42Ycx3Iycc XH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794460558; x=1795065358; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=N+HgnkkymV/qrktUNyVm3RT+UUMj6FmudRG62GmKRrY=; b=qHyzhD0Yhl0hG0dx3GFu8IHedBflX6N+qSw2AE/JDO/jHuxc0bBOCebjMhH/VJCS83 xA6IQdG2DJT6BpTu0zqIlFZkZZXHXKy7XrZk0Oi8qtgw9y8Tze0a+RwXxPQEHfE0wkea F1DnrcfauWIiQ7qbHWAasNX14xyDdMjX9agAcrW/3bRMrRbzTfsj+Xyls316JhLuP0xn rlxJ6NFiU/s5OgrM3P3ouBuqTE62nuvIoJwwouBrALAcN09d1OS51W6BQKg1rQpnX/CN ipG53A/3jFp3rOHHiggmxAV+PaUYnsxuQkg89isJCrtPlknNsfoU/5lQnaU9Qn3ZJnMs zTHA== X-Forwarded-Encrypted: i=1; AL+hErGXLV3CGpS6r3senYQmNq2VhEKsJZ6mwQSG0ewGMkp3ndmL6QdhLvGylAH2oX8vuKqkmPvPllT19ovf7mw=@vger.kernel.org X-Gm-Message-State: APuU4Z+dcoKRoM+tZMgcIF5klVW+B3bshGnKy9D0GOWA1+UiuNNZ5VaY lDvSp6xOYBUNVigGeOJbPtLXnTXY+xU3WVkV8cGWUcS/us4LWuD7LbZjmKu1gAqJuisKRtHy5uP haRkNNZ2j4w2Ni1UQXFElkw== X-Received: from pfbk10.prod.google.com ([2002:a05:6a00:b00a:b0:8b6:3f11:2ac5]) (user=stanleyjhu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4148:b0:89d:7d72:3433 with SMTP id d2e1a72fcca58-8bc1bae9a10mr4699352b3a.21.1794460557863; Wed, 11 Nov 2026 21:15:57 -0800 (PST) Date: Thu, 12 Nov 2026 13:15:38 +0800 In-Reply-To: <20261112051542.1539779-1-stanleyjhu@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261112051542.1539779-1-stanleyjhu@google.com> X-Mailer: git-send-email 2.56.0.567.gdb80ae8cd5-goog Message-ID: <20261112051542.1539779-6-stanleyjhu@google.com> Subject: [PATCH 5/9] scsi: ufs: core: Disable W-LUN runtime PM in ufshcd_err_handling_prepare() From: Stanley Jhu To: linux-scsi@vger.kernel.org, "Martin K. Petersen" Cc: "James E.J. Bottomley" , Bart Van Assche , Alim Akhtar , Avri Altman , Bean Huo , Peter Wang , Stanley Chu , Can Guo , "Bao D. Nguyen" , Asutosh Das , Hongjie Fang , Praveen Talari , HOYOUNG SEO , Brian Kao , Jens Axboe , "Rafael J. Wysocki" , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" ufshcd_err_handling_prepare() calls ufshcd_rpm_get_sync() to power up the host. Since commit eef1d74bf88f ("PM: runtime: Only set runtime_error on suspend callback failures"), a failed W-LUN resume no longer sets runtime_error, so this call runs the W-LUN resume again: 1. A request to a runtime-suspended logical unit resumes its W-LUN supplier, and __ufshcd_wl_resume() sends START STOP UNIT. 2. A fatal error sets UFSHCD_STATE_EH_SCHEDULED_FATAL, and ufshcd_queuecommand() fails START STOP UNIT with DID_BAD_TARGET. 3. sdev_runtime_resume() fails and clears pm_only on the W-LUN queue while rpm_resume() leaves the W-LUN RPM_SUSPENDED. 4. ufshcd_err_handling_prepare() calls ufshcd_rpm_get_sync() while the state is still UFSHCD_STATE_EH_SCHEDULED_FATAL. START STOP UNIT fails the same way, and blk_clear_pm_only() underflows pm_only to -1. Instead, have the error handler power up the host itself by taking ufshcd_rpm_get_noresume() and disabling W-LUN runtime PM in ufshcd_err_handling_prepare(), then re-enabling it in ufshcd_err_handling_unprepare(). Not resuming the W-LUN in ufshcd_err_handling_prepare() needs two more changes. First, force a host reset when the W-LUN is runtime suspended. On a non-fatal UIC error with the link active in runtime suspend, a logical unit resuming during error handling ignores the disabled W-LUN. Skipping reset then leaves the device asleep, and I/O after unquiesce fails with NOT READY. Second, block non-W-LUN commands before blk_mq_quiesce_tagset() freezes the queues. Once W-LUN runtime PM is disabled, another logical unit resuming in that gap ignores the disabled W-LUN and sends commands that hit a sleeping device or fail with DID_BAD_TARGET. Add UFSHCD_EH_WLUN_FENCE to return SCSI_MLQUEUE_HOST_BUSY for non-W-LUN commands while letting in-flight W-LUN PM commands finish. Fixes: eef1d74bf88f ("PM: runtime: Only set runtime_error on suspend callback failures") Cc: stable@vger.kernel.org # 7.3.x Signed-off-by: Stanley Jhu --- drivers/ufs/core/ufshcd.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 5563d28ef92e..7e3f9abc7e7c 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -215,6 +215,7 @@ static const char *const ufshcd_state_name[] = { /* UFSHCD error handling flags */ enum { UFSHCD_EH_IN_PROGRESS = (1 << 0), + UFSHCD_EH_WLUN_FENCE = (1 << 1), }; /* UFSHCD UIC layer error flags */ @@ -235,6 +236,13 @@ enum { #define ufshcd_clear_eh_in_progress(h) \ ((h)->eh_flags &= ~UFSHCD_EH_IN_PROGRESS) +#define ufshcd_set_eh_wlun_fence(h) \ + ((h)->eh_flags |= UFSHCD_EH_WLUN_FENCE) +#define ufshcd_eh_wlun_fence(h) \ + ((h)->eh_flags & UFSHCD_EH_WLUN_FENCE) +#define ufshcd_clear_eh_wlun_fence(h) \ + ((h)->eh_flags &= ~UFSHCD_EH_WLUN_FENCE) + const 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}, @@ -3134,12 +3142,19 @@ static enum scsi_qc_status ufshcd_queuecommand(struct Scsi_Host *host, * UFSHCD_STATE_EH_SCHEDULED_NON_FATAL. Prevent requests * being issued in that case. */ - if (ufshcd_eh_in_progress(hba)) { + if (ufshcd_eh_in_progress(hba) || + (ufshcd_eh_wlun_fence(hba) && + cmd->device != hba->ufs_device_wlun)) { err = SCSI_MLQUEUE_HOST_BUSY; goto out; } break; case UFSHCD_STATE_EH_SCHEDULED_FATAL: + if (ufshcd_eh_wlun_fence(hba) && + cmd->device != hba->ufs_device_wlun) { + err = SCSI_MLQUEUE_HOST_BUSY; + goto out; + } /* * pm_runtime_get_sync() is used at error handling preparation * stage. If a scsi cmd, e.g. the SSU cmd, is sent from hba's @@ -6899,7 +6914,8 @@ static void ufshcd_err_handling_prepare(struct ufs_hba *hba) * runtime suspended, so take an extra reference on hba->dev. */ pm_runtime_get_sync(hba->dev); - ufshcd_rpm_get_sync(hba); + ufshcd_rpm_get_noresume(hba); + __pm_runtime_disable(&hba->ufs_device_wlun->sdev_gendev, false); if (pm_runtime_status_suspended(&hba->ufs_device_wlun->sdev_gendev) || hba->is_sys_suspended) { enum ufs_pm_op pm_op; @@ -6943,6 +6959,7 @@ static void ufshcd_err_handling_unprepare(struct ufs_hba *hba) ufshcd_release(hba); if (ufshcd_is_clkscaling_supported(hba)) ufshcd_clk_scaling_suspend(hba, false); + pm_runtime_enable(&hba->ufs_device_wlun->sdev_gendev); ufshcd_rpm_put(hba); pm_runtime_put(hba->dev); } @@ -7146,6 +7163,7 @@ static void ufshcd_err_handler(struct work_struct *work) up(&hba->host_sem); return; } + ufshcd_set_eh_wlun_fence(hba); spin_unlock_irqrestore(&hba->host->host_lock, flags); ufshcd_err_handling_prepare(hba); @@ -7166,6 +7184,8 @@ static void ufshcd_err_handler(struct work_struct *work) if (hba->ufshcd_state != UFSHCD_STATE_ERROR) hba->ufshcd_state = UFSHCD_STATE_RESET; + if (pm_runtime_status_suspended(&hba->ufs_device_wlun->sdev_gendev)) + hba->force_reset = true; /* * A full reset and restore might have happened after preparation * is finished, double check whether we should stop. @@ -7295,6 +7315,7 @@ static void ufshcd_err_handler(struct work_struct *work) goto again; hba->ufshcd_state = UFSHCD_STATE_ERROR; } + ufshcd_clear_eh_wlun_fence(hba); ufshcd_clear_eh_in_progress(hba); spin_unlock_irqrestore(&hba->host->host_lock, flags); ufshcd_err_handling_unprepare(hba); -- 2.56.0.567.gdb80ae8cd5-goog