From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [62.140.7.102]) by mx.groups.io with SMTP id smtpd.web12.3047.1594176205885672848 for ; Tue, 07 Jul 2020 19:43:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=lHV9QIgz; spf=pass (domain: suse.com, ip: 62.140.7.102, mailfrom: glin@suse.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1594176204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lY56pAqls69BgMJwbv2UoO4hH3NOozYJeAx6eUKIZn0=; b=lHV9QIgzFgCNm9eHcP0ztnKsl8iKRpIiDgFThcZfpY2u9bk3fMxFwL8yY70SEV0u9tWysA O9Srtsh/2AbAyaQZoD/kyXN8OnI9E8Dvpw2sgRYQ0Sb/Fk7OfGeLoTTECveLJBcBhcF7Zc ogNHhW0EkpdcRuvaEEqbCu0rfqwV7xQ= Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03lp2058.outbound.protection.outlook.com [104.47.10.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-12-FyOGa6mkNouBaL9qQdV2PA-1; Wed, 08 Jul 2020 04:43:23 +0200 X-MC-Unique: FyOGa6mkNouBaL9qQdV2PA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RePrJqB9iiJ8t3184T6c4Hprk4Ib158NQ1A3SyheXJusE8Hr+ighitifKzORkUsioZ0rjxkRgslYkA9d5KUCHYMTJ07EsgPDtWplS9sFBv9fwKxRa270obevywkqysRhMIupj4jnU76iggR+bKs7JugQHwE4MD98x5rvTtC8mfqmUrWLlXaEQvVjwkJqPh3ZvBJThBUiluutcVnFwy0PiZaXa+zqbhwnIEEy16o5n3Js78K00kUrhCxM+SOH0knho4aJErLAhwufcnejdhkNdQEPDTfMNIE9B4rkSrehRUNRLedEItIFuhisTD9wyj26FjvgNsPECc7664WwgiJXMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lY56pAqls69BgMJwbv2UoO4hH3NOozYJeAx6eUKIZn0=; b=j7Swpej8YkVl+HPJsetiQ0zkSRmUa86MS7/Xv3iCKOa+UveeVKxfkWl1B9Lah97zs6uYGsV9Lk2bHyHhxVYW2QaDn/B2Wr679bGMlXs4tXkb+ik5IdE2gAENAy/QKX8CVbiZIO1xl/LDVi6/w0S9BxNOHuvGA5UxKl1l2cIG43mFEQLW16rwAfcq+hmoVsdY1fbBzxI1lSH5tbEfhPjmViSSbWHLNMt7kfZw06ccrtzPw69J/mT2rJ+IQyj81xg8B6dlf7ahU0G3Nbyq+ZxoyZr0ucx6rBCNNvq/2Y3fA+enZjUyD+7Y6NVJFRpwNNc8OB234kD8HxXsdaRFf0ViHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3824.eurprd04.prod.outlook.com (2603:10a6:803:22::18) by VI1PR0401MB2253.eurprd04.prod.outlook.com (2603:10a6:800:26::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.27; Wed, 8 Jul 2020 02:43:22 +0000 Received: from VI1PR0402MB3824.eurprd04.prod.outlook.com ([fe80::3854:92a5:f662:2def]) by VI1PR0402MB3824.eurprd04.prod.outlook.com ([fe80::3854:92a5:f662:2def%6]) with mapi id 15.20.3153.029; Wed, 8 Jul 2020 02:43:22 +0000 Date: Wed, 8 Jul 2020 10:43:13 +0800 From: "Gary Lin" To: Laszlo Ersek Cc: devel@edk2.groups.io, Jordan Justen , Ard Biesheuvel Subject: Re: [PATCH 09/11] OvmfPkg/LsiScsiDxe: Examine the incoming SCSI Request Packet Message-ID: <20200708024313.GS18504@GaryWorkstation> References: <20200701040448.14871-1-glin@suse.com> <20200701040448.14871-10-glin@suse.com> <7eb82ece-08fd-cb48-ddae-47a2069a3cd4@redhat.com> In-Reply-To: <7eb82ece-08fd-cb48-ddae-47a2069a3cd4@redhat.com> X-ClientProxiedBy: AM0PR04CA0136.eurprd04.prod.outlook.com (2603:10a6:208:55::41) To VI1PR0402MB3824.eurprd04.prod.outlook.com (2603:10a6:803:22::18) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation (60.251.47.115) by AM0PR04CA0136.eurprd04.prod.outlook.com (2603:10a6:208:55::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 02:43:20 +0000 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c616b2d9-247a-4bfc-df25-08d822e8adea X-MS-TrafficTypeDiagnostic: VI1PR0401MB2253: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 92TXPRkIcwAuzMH8atDUR/KmszW2FdWIsqS83rR0jW0KxRVUpSKUNs6ge+kUohx35DiIxLpK5B7eYk6HpK0YugbLHLHK3GI6Egd11MUl8yyCfucL6bxuG1e37yxunkZMXygPsfnoLhgA2l1vHB7uybkmnPTxtffiTYShQNOgrI3v/4QEmEbT7LEzCE0kBgEX0Az1Kh3KEemVl4c4fD8d9QZc9jL68H7SYzD4/FVm1WUYzhPoJElzzJzXI9xlNYwKddz61HpkuMGQmio+7LCrxg29mL0YAgocb3nQnW3aGrC7aVXtq5SQ1qbAy3Tqerhc3jF3rJa7nEBOoghvcM/pcQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3824.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(376002)(396003)(39850400004)(366004)(346002)(136003)(9686003)(54906003)(6916009)(316002)(1076003)(8676002)(6666004)(33656002)(5660300002)(2906002)(83380400001)(6496006)(66946007)(52116002)(16526019)(55236004)(53546011)(66556008)(66476007)(26005)(4326008)(186003)(8936002)(478600001)(55016002)(956004)(86362001)(33716001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rhkYX46C7z9KwoamjaEQxwcrb+iJoDP2PZtSPVHlARjxbIgPGpZ1KgEa1d8mj+Hy+tKTpxhUs9vDWJbLZ1JBeyFmAsZwayqZZPY99qwSL9bDmzdEJ4Zry9GVJNXSU2jMYH+aPtM4eQPxIxBgKfCH8YWH8MtDa/hl3o0vyDNLr94XsF9gv0t6UIDihEXffrgk2hykTm3uw2XiKpD2IAMrc9AmvWBuCstKn3v77hK2806EYA602iSWatLzZ1eIbPq6htIGZ6RW4N8kwmJxQkYYgggZduHec5PEmq1lXDU+TzNGje+DrzPXWFUzD4Z7Jj8UKi87Q3xhDmDAvN85JP8uRJbXnT2w6r4YhpowF9PVByhszoIOorCtd6N6fX37K7ZCnkGWmHw8IT4Ly/QBRdB50MGVPu1qg3u0hGkVQeLyjX3OswCbRm8u/AUB+SM9CIxPi4cTKjv7G230LoA2raMMm8Q9Kx4kCOXcCDIyDAYFlIc= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c616b2d9-247a-4bfc-df25-08d822e8adea X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3824.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 02:43:22.0055 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uaRReAhb5JDCgjOJg+NSB5SFpE6Rv2e2b7lrhALSqAXyMURF7Q+5ZRtKxKuXMKYc X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2253 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jul 07, 2020 at 12:17:21PM +0200, Laszlo Ersek wrote: > On 07/01/20 06:04, Gary Lin wrote: > > This is the first part of LsiScsiPassThru(). Before processing the SCSI > > Request packet, we have to make sure whether the packet is valid or not. > > > > Cc: Jordan Justen > > Cc: Laszlo Ersek > > Cc: Ard Biesheuvel > > Signed-off-by: Gary Lin > > --- > > OvmfPkg/LsiScsiDxe/LsiScsi.c | 100 ++++++++++++++++++++++++++++++++++- > > OvmfPkg/LsiScsiDxe/LsiScsi.h | 4 ++ > > 2 files changed, 103 insertions(+), 1 deletion(-) > > > > diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c > > index b728d18d51df..1bcebd92e455 100644 > > --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c > > +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c > > @@ -52,6 +52,95 @@ LsiScsiReset ( > > return Out8 (Dev, LSI_REG_ISTAT0, LSI_ISTAT0_SRST); > > } > > > > +STATIC > > +EFI_STATUS > > +ReportHostAdapterOverrunError ( > > + OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet > > + ) > > +{ > > + Packet->SenseDataLength = 0; > > + Packet->HostAdapterStatus = > > + EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OVERRUN_UNDERRUN; > > + Packet->TargetStatus = EFI_EXT_SCSI_STATUS_TARGET_GOOD; > > + return EFI_BAD_BUFFER_SIZE; > > +} > > + > > +/** > > + > > + Check the request packet from the Extended SCSI Pass Thru Protocol. The > > + request packet is modified, to be forwarded outwards by LsiScsiPassThru(), > > + if invalid or unsupported parameters are detected. > > + > > + @param[in] Dev The LSI 53C895A SCSI device the packet targets. > > + > > + @param[in] Target The SCSI target controlled by the LSI 53C895A SCSI > > + device. > > + > > + @param[in] Lun The Logical Unit Number under the SCSI target. > > + > > + @param[in out] Packet The Extended SCSI Pass Thru Protocol packet. > > + > > + > > + @retval EFI_SUCCESS The Extended SCSI Pass Thru Protocol packet was valid. > > + > > + @return Otherwise, invalid or unsupported parameters were > > + detected. Status codes are meant for direct forwarding > > + by the EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() > > + implementation. > > + > > + **/ > > +STATIC > > +EFI_STATUS > > +LsiScsiCheckRequest ( > > + IN LSI_SCSI_DEV *Dev, > > + IN UINT8 Target, > > + IN UINT64 Lun, > > + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet > > + ) > > +{ > > + if (Target > Dev->MaxTarget || Lun > Dev->MaxLun || > > + Packet->DataDirection > EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL || > > + // > > + // Trying to receive, but destination pointer is NULL, or contradicting > > + // transfer direction > > + // > > + (Packet->InTransferLength > 0 && > > + (Packet->InDataBuffer == NULL || > > + Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_WRITE > > + ) > > + ) || > > + > > + // > > + // Trying to send, but source pointer is NULL, or contradicting transfer > > + // direction > > + // > > + (Packet->OutTransferLength > 0 && > > + (Packet->OutDataBuffer == NULL || > > + Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_READ > > + ) > > + ) > > + ) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + if (Packet->DataDirection == EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL || > > + (Packet->InTransferLength > 0 && Packet->OutTransferLength > 0) || > > + Packet->CdbLength > sizeof Dev->Dma->Cdb) { > > + return EFI_UNSUPPORTED; > > + } > > + > > + if (Packet->InTransferLength > sizeof Dev->Dma->Data) { > > + Packet->InTransferLength = sizeof Dev->Dma->Data; > > + return ReportHostAdapterOverrunError (Packet); > > + } > > + if (Packet->OutTransferLength > sizeof Dev->Dma->Data) { > > + Packet->OutTransferLength = sizeof Dev->Dma->Data; > > + return ReportHostAdapterOverrunError (Packet); > > + } > > + > > + return EFI_SUCCESS; > > +} > > + > > // > > // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL > > // for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata C, > > @@ -70,7 +159,16 @@ LsiScsiPassThru ( > > IN EFI_EVENT Event OPTIONAL > > ) > > { > > - return EFI_UNSUPPORTED; > > + EFI_STATUS Status; > > + LSI_SCSI_DEV *Dev; > > + > > + Dev = LSI_SCSI_FROM_PASS_THRU (This); > > + Status = LsiScsiCheckRequest (Dev, *Target, Lun, Packet); > > + if (EFI_ERROR (Status)) { > > + return Status; > > + } > > + > > + return EFI_SUCCESS; > > } > > > > EFI_STATUS > > In this patch, we do not implement LsiScsiPassThru() completely yet. > Therefore we should not return EFI_SUCCESS, just because > LsiScsiCheckRequest() succeeds. > > (1) So please keep the EFI_UNSUPPORTED value for the last "return" > statement in the function, for now. > > EFI_UNSUPPORTED should be replaced with EFI_SUCCESS in "[PATCH 10/11] > OvmfPkg/LsiScsiDxe: Process the SCSI Request Packet". > Agree. EFI_UNSUPPORTED is more reasonable status for this half-implemented function. > With that update, for this patch: > > Reviewed-by: Laszlo Ersek > Will update this commit in v2. Thanks, Gary Lin > Thanks > Laszlo > > > diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h > > index 1e4bbc56f933..9272eb7506c7 100644 > > --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h > > +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h > > @@ -13,6 +13,10 @@ > > #define _LSI_SCSI_DXE_H_ > > > > typedef struct { > > + // > > + // The max size of CDB is 32. > > + // > > + UINT8 Cdb[32]; > > // > > // Allocate 64KB for read/write buffer. > > // > > >