From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by mx.groups.io with SMTP id smtpd.web10.11149.1674033246963268812 for ; Wed, 18 Jan 2023 01:14:07 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20210112 header.b=rNZhUKVx; spf=pass (domain: flex--yuanyu.bounces.google.com, ip: 209.85.214.201, mailfrom: 3xrjhywykbrmhdt6hdz77z4x.v75wxex4xw3l.za7d8b.17@flex--yuanyu.bounces.google.com) Received: by mail-pl1-f201.google.com with SMTP id m7-20020a170902db0700b00194bd3c810aso419640plx.23 for ; Wed, 18 Jan 2023 01:14:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IvT+Iynst+V6esglB90DxE+kLeZRCFaZ7/UPyGCFaVo=; b=rNZhUKVx7u+/06YzW9cVKSxDqbvN6zsHpCc7R8TLjiCN2hYXwje2i4OJ1vSvo0jlX+ sfbxfXe28V3MZFs71D3Qu1pz5PypUGqCBvfxlmOc3wVo/JSqf2TFjZzNNiw35aG83hy7 kdSPj5bPi+WR1dZVMKFxvHemcQpke3Qai1Md6Jiw5P20zdyIDQY7jQPAKs/VEbJlVsvn WLv6WHJukCDiJg9C4bngK++aiRX7v6l2Hd49i93rhV7OCV5WWRd2SMewQrmv179oEvhU 2IkYRmUWAs3kNCSXW5m4QVL+zj7IPka3szsiI4OXq08LbA3pHpkwU9BLVmtXwk7hge/v WJGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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; bh=IvT+Iynst+V6esglB90DxE+kLeZRCFaZ7/UPyGCFaVo=; b=wjyKzjOXujR2AQiANHkl9L4wgj3O5tlK0SEGSAQd5q+keA1WtXT95JJt2ciIG7ecW8 LBTUej1IP5vTgkmf2bSctkheY9bFDH042qURJBBCTgL0wJL7GBze6HGjewMQSNkZDL4K Fu0yEd76SZGpGXAI6B9BCEYvrw/HToWuqmgePjgnxpRJcqaZoGaoLN21GhmYke/LXqjR PW+iOQpmKwxD0YNCSQifLPiedAcGajadzsPaxVAiJlJfRYF7Ua8SyCou3S5+6vAOWHnN tf7SmK/z9weew863tN4LFFISJKGETHNoP/fQ/KU/yBn7DMrHof/utb87NG4X6StnpGBr laxA== X-Gm-Message-State: AFqh2kpaRJQKiCz74hI6LW0TvueGzH/9/vzbiSbyzhmozhqmvj4iI9pW ddo/+qp51M61c8iDAV12nDv/hpTcwnAgfl+ScNKdk0io743I5BFPAtZYswIHpTxwr41fkC8m8Xk fVdX/ZuT2ZootKMDWIHLg5VsKK6HNt2EuPlFO7xsSeoHiIrnN2w1D+xoRFa4= X-Google-Smtp-Source: AMrXdXvC9PAcT+HFL+4dNLXNB9DPa9bE0Tf+JCGy71b4Tw5w0M41/2XrBzPTvhHkJTtjYitQuP7sKiVQdMM= X-Received: from yuanyu.kir.corp.google.com ([2620:15c:29:204:1cbf:6a8c:60ac:298c]) (user=yuanyu job=sendgmr) by 2002:a17:902:8f82:b0:189:959a:84d8 with SMTP id z2-20020a1709028f8200b00189959a84d8mr641145plo.38.1674033246146; Wed, 18 Jan 2023 01:14:06 -0800 (PST) Date: Wed, 18 Jan 2023 01:14:01 -0800 In-Reply-To: <20230118091402.931498-1-yuanyu@google.com> Mime-Version: 1.0 References: <20230118091402.931498-1-yuanyu@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230118091402.931498-2-yuanyu@google.com> Subject: [PATCH v1 1/2] MdeModulePkg: Fix bug in ScsiBusDxe/ScsiBus.c From: "Yuan Yu" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Liming Gao , Hao A Wu , Ray Ni , Sivaparvathi chellaiah Content-Type: text/plain; charset="UTF-8" A while loop in SCSIBusDriverBindingStart() is supposed to scan all the possible Puns in the SCSI channel by calling ScsiScanCreateDevice() for each of them. Therefore, we should not abort the loop even when one of the Puns is disconnected. The following is one of the scenarios. SCSIBusDriverBindingStart() > ScsiScanCreateDevice() > DiscoverScsiDevice() > ScsiInquiryCommand() > ... > ParseResponse() When virtio-scsi returns VIRTIO_SCSI_S_BAD_TARGET, ParseResponse() in VirtioScsi.c will return EFI_TIMEOUT: case VIRTIO_SCSI_S_BAD_TARGET: // // This is non-intuitive but explicitly required by the // EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() specification for // disconnected (but otherwise valid) target / LUN addresses. // Packet->HostAdapterStatus = EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT_COMMAND; return EFI_TIMEOUT; This will eventually cause DiscoverScsiDevice() to return FALSE, which will cause ScsiScanCreateDevice() to return EFI_OUT_OF_RESOURCES: if (!DiscoverScsiDevice (ScsiIoDevice)) { Status = EFI_OUT_OF_RESOURCES; goto ErrorExit; } In sum, "disconnected (but otherwise valid) target / LUN addresses" can result in EFI_OUT_OF_RESOURCES and when this happens the while loop in SCSIBusDriverBindingStart() should continue, not abort. Without this fix, the loop can terminate prematurely with good devices not having a chance to be discovered. If this good device is the boot device, boot will fail. Cc: Ard Biesheuvel Cc: Liming Gao Cc: Hao A Wu Cc: Ray Ni Cc: Sivaparvathi chellaiah Signed-off-by: Yuan Yu --- MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c index fbe14c772496..2ed816da4abe 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c @@ -533,9 +533,6 @@ SCSIBusDriverBindingStart ( // then create handle and install scsi i/o protocol. // Status = ScsiScanCreateDevice (This, Controller, &ScsiTargetId, Lun, ScsiBusDev); - if (Status == EFI_OUT_OF_RESOURCES) { - goto ErrorExit; - } } return EFI_SUCCESS; -- 2.39.0.314.g84b9a713c41-goog