From patchwork Thu Feb 22 16:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weitao Wang X-Patchwork-Id: 204625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp118097dyb; Thu, 22 Feb 2024 00:55:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVTogYOESbs39sEoxOUcsPkQ2VWPEbhUfgehXtFx9A0NaWYtL/3NaARq5npVxqQWs6ZY8vEQdnqyyNPsUdi+hCmzg75mg== X-Google-Smtp-Source: AGHT+IGKHbSS+WSzK1hQoYSeyPpLHkXNJDTIhQvvYNJoWKOKUE4a/eDQTxkNduFTbi/fIwv5ZQWK X-Received: by 2002:a17:906:1392:b0:a3f:1afa:115f with SMTP id f18-20020a170906139200b00a3f1afa115fmr3971908ejc.31.1708592109939; Thu, 22 Feb 2024 00:55:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708592109; cv=pass; d=google.com; s=arc-20160816; b=b8vkPsg8hjhnp7eCX0bCMWuHBv3sowVPwAPbKPJfIx8crfcOJj5nl2kEznOCEJifT0 C0cZLT4HFc2hK6cEl83kHhDF7PbR/6L4fKuBVvBwd9tNwN3vjDkX2M4yoOtkZBZl+FS3 YoiLJSCKjstfQcAWHieHKrc1/62xaNHylp8eOtP+F0F2zNuU1rZ79ldeqhjluRpRZRLn 99GYtVqFRo8h9gKf4u6AKdY2zitRf9UKeLqQT5sU8IzTGBa1SLRQIMPx/q91OLYHdiFW 191AXzdioXbAIZvQY4TSVRZjFz/aXov/nRwDPqpkyESOwXc5XzYWkv/+wH0vFNRJsbxW iJnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=sGu4DzXq2KilnzaBxCY05MKDFmi+Wv/XxnQwY5874hU=; fh=bjqTkrDGAG5dUTe66+BL0cPu+qBvgRFd2kua/wKfhAI=; b=q1KLkjPtTG6od3iplfa6B3jeoPh2CoApaX3E1lntiymNsCgVrD/tTV1WtjAUz2kAr0 DMxbksw9tJEEgUfadssd0VyBp42vNQnpb7ikhHZLbkzYOh5SepgIh0UOZ7HqvFLZtABd hCy+s06Civ7+atJj7nzps7bfeskYl8S0LNWra1pWUpCyTq5GkD3k5zivvXvLpxe5UAWe WHZQEPFJpcIjutTiHX2XYEAwxY4kqkLHI6C1YpbXMh9ScUc301CmqAkDzX1OgGHgXGoU bFY78vwn0h+24RySD9EqSxosvI72Wz+slVf89TSElUiKEPja1QsDC/woZ3fK+RthY9LO lvQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zhaoxin.com); spf=pass (google.com: domain of linux-kernel+bounces-76152-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76152-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id k19-20020a170906055300b00a3ee5d31f7fsi2670444eja.248.2024.02.22.00.55.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:55:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76152-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zhaoxin.com); spf=pass (google.com: domain of linux-kernel+bounces-76152-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76152-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 630B51F2353D for ; Thu, 22 Feb 2024 08:55:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7B8E37157; Thu, 22 Feb 2024 08:54:48 +0000 (UTC) Received: from mx2.zhaoxin.com (mx2.zhaoxin.com [203.110.167.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65CFB2BD1C for ; Thu, 22 Feb 2024 08:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.110.167.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592087; cv=none; b=TTj3ztONC/HLVKvjOksBFCjEV+r1Z9AzDlyubxOmGI4tdLCw9KOW6KuB0AQaokeRybniHH89QyLWNJFtGKIoAU1xxtcWaMMrSaRofMiAqG5gsh3DrOOFhYbFip6ive+4rfFcIhlgph3kAIZrQAdu7LMH5wlBA2/3S/PvskDcr/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708592087; c=relaxed/simple; bh=Q09ggyJX4LTHC+Qx+tTl+VcdUVE6MRDSmOxeTtRF1M0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=L9XAD8C/xALgOTaT9Bl24YIaF9zFEF0URjn4e/6+iw4Wnhu1KtkHUNCrMdKsPlFEVJEyHSw/TgmsPFLipa+NQ+zPfZFuicA+uGggxPMofW0z2s5dJ3psZ2mQP3116FaYTmUDU77btc0u1hsFaOznRtJ+Psfyj7Ezy0cdbY/knzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=203.110.167.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1708592081-1eb14e0c7c45a80001-xx1T2L Received: from ZXSHMBX2.zhaoxin.com (ZXSHMBX2.zhaoxin.com [10.28.252.164]) by mx2.zhaoxin.com with ESMTP id IHwyCNpP3iJxhYfP (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 22 Feb 2024 16:54:42 +0800 (CST) X-Barracuda-Envelope-From: WeitaoWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX2.zhaoxin.com (10.28.252.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 22 Feb 2024 16:54:41 +0800 Received: from L440.zhaoxin.com (10.29.8.21) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 22 Feb 2024 16:54:41 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 From: Weitao Wang X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: , , , , , , CC: Subject: [PATCH] USB:UAS:return ENODEV when submit urbs fail with device not attached. Date: Fri, 23 Feb 2024 00:54:41 +0800 X-ASG-Orig-Subj: [PATCH] USB:UAS:return ENODEV when submit urbs fail with device not attached. Message-ID: <20240222165441.6148-1-WeitaoWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.32.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX2.zhaoxin.com[10.28.252.164] X-Barracuda-Start-Time: 1708592081 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.36:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 4195 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: 1.09 X-Barracuda-Spam-Status: No, SCORE=1.09 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests=DATE_IN_FUTURE_06_12, DATE_IN_FUTURE_06_12_2 X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.121168 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.01 DATE_IN_FUTURE_06_12 Date: is 6 to 12 hours after Received: date 3.10 DATE_IN_FUTURE_06_12_2 DATE_IN_FUTURE_06_12_2 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791588680123302509 X-GMAIL-MSGID: 1791588680123302509 In the scenario of entering hibernation with udisk in the system, if the udisk was gone or resume fail in the thaw phase of hibernation. Its state will be set to NOTATTACHED. However, usb_hub_wq was already freezed and can't not handle disconnect event. Then, sync cache SCSI command will be sent to this udisk on the poweroff phase of hibernation, that will cause uas_submit_urbs to be called to submit URB to sense/data/cmd pipe. Then, usb_submit_urb return value -ENODEV when device was set to NOTATTACHED state. However, uas_submit_urbs always return "SCSI_MLQUEUE_DEVICE_BUSY" regardless of the reason for submission failure.That will lead the SCSI layer go into an ugly loop and system fail to go into hibernation. To fix this issue, let uas_submit_urbs function to return real error -ENODEV when submit URB with device in the NOTATTACHED state. In the error checking inside of function uas_queuecommand_lck, reporting DID_ERROR will cause device poweroff fail and system shutdown instead of entering hibernation. So,replace DID_ERROR with DID_NO_CONNECT to report to SCSI upper layer. Signed-off-by: Weitao Wang --- drivers/usb/storage/uas.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 9707f53cfda9..967f18db525a 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -533,7 +533,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, * daft to me. */ -static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) +static int uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) { struct uas_dev_info *devinfo = cmnd->device->hostdata; struct urb *urb; @@ -541,16 +541,15 @@ static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) urb = uas_alloc_sense_urb(devinfo, gfp, cmnd); if (!urb) - return NULL; + return -ENOMEM; usb_anchor_urb(urb, &devinfo->sense_urbs); err = usb_submit_urb(urb, gfp); if (err) { usb_unanchor_urb(urb); uas_log_cmd_state(cmnd, "sense submit err", err); usb_free_urb(urb); - return NULL; } - return urb; + return err; } static int uas_submit_urbs(struct scsi_cmnd *cmnd, @@ -562,9 +561,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, lockdep_assert_held(&devinfo->lock); if (cmdinfo->state & SUBMIT_STATUS_URB) { - urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); - if (!urb) - return SCSI_MLQUEUE_DEVICE_BUSY; + err = uas_submit_sense_urb(cmnd, GFP_ATOMIC); + if (err) + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; cmdinfo->state &= ~SUBMIT_STATUS_URB; } @@ -582,7 +581,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_in_urb); uas_log_cmd_state(cmnd, "data in submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->state &= ~SUBMIT_DATA_IN_URB; cmdinfo->state |= DATA_IN_URB_INFLIGHT; @@ -602,7 +601,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->data_out_urb); uas_log_cmd_state(cmnd, "data out submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; cmdinfo->state |= DATA_OUT_URB_INFLIGHT; @@ -621,7 +620,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, if (err) { usb_unanchor_urb(cmdinfo->cmd_urb); uas_log_cmd_state(cmnd, "cmd submit err", err); - return SCSI_MLQUEUE_DEVICE_BUSY; + return (err == -ENODEV) ? -ENODEV : SCSI_MLQUEUE_DEVICE_BUSY; } cmdinfo->cmd_urb = NULL; cmdinfo->state &= ~SUBMIT_CMD_URB; @@ -698,7 +697,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd) * of queueing, no matter how fatal the error */ if (err == -ENODEV) { - set_host_byte(cmnd, DID_ERROR); + set_host_byte(cmnd, DID_NO_CONNECT); scsi_done(cmnd); goto zombie; }