From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 801BC21E79033 for ; Thu, 17 Aug 2017 20:35:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1F39356E1; Fri, 18 Aug 2017 03:38:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E1F39356E1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-49.phx2.redhat.com [10.3.116.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3AF660FB6; Fri, 18 Aug 2017 03:38:01 +0000 (UTC) From: Laszlo Ersek To: edk2-devel-01 Cc: Eric Dong , Feng Tian , Hannes Reinecke , Paolo Bonzini , Star Zeng Date: Fri, 18 Aug 2017 05:37:55 +0200 Message-Id: <20170818033757.16153-2-lersek@redhat.com> In-Reply-To: <20170818033757.16153-1-lersek@redhat.com> References: <20170818033757.16153-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Aug 2017 03:38:04 +0000 (UTC) Subject: [PATCH 1/3] MdeModulePkg/ScsiBusDxe: don't produce ScsiIo for nonexistent LUNs, part 1 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Aug 2017 03:35:36 -0000 The SPC-4 spec says about the INQUIRY data, in "Table 138 -- Peripheral qualifier": > Qualifier = 011b The device server is not capable of supporting a > peripheral device on this logical unit. For this > peripheral qualifier the peripheral device type shall > be set to 1Fh. All other peripheral device type values > are reserved for this peripheral qualifier. Accordingly, the DiscoverScsiDevice() function returns FALSE if Peripheral_Qualifier is 3 decimal, but Peripheral_Type differs from 1Fh. This is a valid sanity check -- such combinations are reserved. When Peripheral_Qualifier is 3, and Peripheral_Type is 1Fh, then DiscoverScsiDevice() returns TRUE. While this combination is not reserved, returning TRUE for it is incorrect: Peripheral_Type 1Fh stands for "Unknown or no device type", and this combination is returned in particular when the INQUIRY command was directed to a nonexistent LUN. Quoting the spec: > In response to an INQUIRY command received by an incorrect logical unit, > the SCSI target device shall return the INQUIRY data with the peripheral > qualifier set to the value defined in 6.4.2. [...] > > [...] > > The PERIPHERAL QUALIFIER field and PERIPHERAL DEVICE TYPE field identify > the peripheral device connected to the logical unit. If the SCSI target > device is not capable of supporting a peripheral device connected to > this logical unit, the device server shall set these fields to 7Fh > (i.e., PERIPHERAL QUALIFIER field set to 011b and PERIPHERAL DEVICE TYPE > field set to 1Fh). The consequence of this bug is that for each nonexistent Target/LUN pair, we produce a useless ScsiIo protocol interface. The internal "ScsiIoDevice->ScsiDeviceType" field will be set to 0x1f, and it will be returned to higher-level SCSI drivers when they call ScsiIo->GetDeviceType(). Given that 0x1f means "Unknown or no device type", no higher-level driver can ever support it, so these ScsiIo protocol interfaces are useless. The fix is to return FALSE for the (Peripheral_Qualifier=3, Peripheral_Type=0x1f) combination. With that however we reject the whole Peripheral_Qualifier=3 space (justifiedly -- see the definition above), which lets us simplify the code. Cc: Eric Dong Cc: Feng Tian Cc: Hannes Reinecke Cc: Paolo Bonzini Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c index 0802b617268f..72e3da8967b2 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c @@ -1348,21 +1348,13 @@ DiscoverScsiDevice ( // // Retrieved inquiry data successfully // - if ((InquiryData->Peripheral_Qualifier != 0) && - (InquiryData->Peripheral_Qualifier != 3)) { + if (InquiryData->Peripheral_Qualifier != 0) { ScsiDeviceFound = FALSE; goto Done; } - if (InquiryData->Peripheral_Qualifier == 3) { - if (InquiryData->Peripheral_Type != 0x1f) { - ScsiDeviceFound = FALSE; - goto Done; - } - } - if (0x1e >= InquiryData->Peripheral_Type && InquiryData->Peripheral_Type >= 0xa) { ScsiDeviceFound = FALSE; goto Done; } -- 2.14.1.3.gb7cf6e02401b