From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web10.14133.1585425549698059737 for ; Sat, 28 Mar 2020 12:59:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=bl2urgE1; spf=pass (domain: oracle.com, ip: 156.151.31.85, mailfrom: liran.alon@oracle.com) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02SJmRmd032626; Sat, 28 Mar 2020 19:59:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=zB3pbVZT3rdXlASdqscLkLwWxyqN03xyQeiFQXJL9C4=; b=bl2urgE1LBwuGT4YTY2ee9vBWmsQJ3dBzQFf9ZAu982ohN8XaUxoHI/Nd32rk6li3bJC ZYn6kVnIqcwNPVqxp8YXvhRvQQvPmueatFdUYbqbdDPU64F54X5sHwCAomVly1qnFHis TZI7NxLBqPhVc4j+K0nYth6NnCx52BfZqlDc0seBaJZ45AubX3aI5CjDX7JaZHOowT4/ CYNoHEM+4w+XR17K2UXwNGp553NZ99wW1gygokMrZuMTaB1JtXm+VY9HDL0+3EFBUh+r WXCcRDtJ/fIobexp6laKUp5y5r+BAL4B8NQUi8dIWhJ028fe9VZTTSTZPCa1ja9G8LD9 lw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 301y7mhf90-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 28 Mar 2020 19:59:09 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02SJo8rZ031560; Sat, 28 Mar 2020 19:59:08 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 301vm90q9n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 28 Mar 2020 19:59:08 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 02SJx87L025087; Sat, 28 Mar 2020 19:59:08 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 28 Mar 2020 12:59:07 -0700 From: "Liran Alon" To: devel@edk2.groups.io, lersek@redhat.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, Liran Alon Subject: [PATCH v3 14/17] OvmfPkg/PvScsiDxe: Introduce DMA communication buffer Date: Sat, 28 Mar 2020 23:00:57 +0300 Message-Id: <20200328200100.60786-15-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200328200100.60786-1-liran.alon@oracle.com> References: <20200328200100.60786-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9574 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003280189 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9574 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003280189 Content-Transfer-Encoding: 8bit In case device is constrained by IOMMU or guest is running under AMD SEV, input/output buffers provided to device (DataBuffer and SenseData) needs to be explicitly mapped to device by PciIo->Map(). To avoid the overhead of mapping/unmapping the DataBuffer and SenseData to the device for every SCSI requst (and to simplify code), introduce a single DMA communication buffer that will be mapped to device on initialization. When a SCSI request needs to be sent to device, the DataBuffer and SenseData will be copied from/to the DMA communication buffer as required. This will be done by the following commits. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 Signed-off-by: Liran Alon --- OvmfPkg/PvScsiDxe/PvScsi.c | 60 ++++++++++++++++++++++++++++++-------- OvmfPkg/PvScsiDxe/PvScsi.h | 20 +++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index c7d367e83a2d..6e350bb2d6e0 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -677,6 +677,19 @@ PvScsiInit ( goto RestorePciAttributes; } + // + // Allocate DMA communication buffer + // + Status = PvScsiAllocateSharedPages ( + Dev, + EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)), + (VOID **)&Dev->DmaBuf, + &Dev->DmaBufDmaDesc + ); + if (EFI_ERROR (Status)) { + goto FreeRings; + } + // // Populate the exported interface's attributes // @@ -708,18 +721,7 @@ PvScsiInit ( return EFI_SUCCESS; -RestorePciAttributes: - PvScsiRestorePciAttributes (Dev); - - return Status; -} - -STATIC -VOID -PvScsiUninit ( - IN OUT PVSCSI_DEV *Dev - ) -{ +FreeRings: // // Reset device to stop device usage of the rings. // This is required to safely free the rings. @@ -728,6 +730,40 @@ PvScsiUninit ( PvScsiFreeRings (Dev); +RestorePciAttributes: + PvScsiRestorePciAttributes (Dev); + + return Status; +} + +STATIC +VOID +PvScsiUninit ( + IN OUT PVSCSI_DEV *Dev + ) +{ + // + // Reset device to: + // - Make device stop processing all requests. + // - Stop device usage of the rings. + // + // This is required to safely free the DMA communication buffer + // and the rings. + // + PvScsiResetAdapter (Dev); + + // + // Free DMA communication buffer + // + PvScsiFreeSharedPages ( + Dev, + EFI_SIZE_TO_PAGES (sizeof (*Dev->DmaBuf)), + Dev->DmaBuf, + &Dev->DmaBufDmaDesc + ); + + PvScsiFreeRings (Dev); + PvScsiRestorePciAttributes (Dev); } diff --git a/OvmfPkg/PvScsiDxe/PvScsi.h b/OvmfPkg/PvScsiDxe/PvScsi.h index 6d23b6e1eccf..fff12146dc75 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.h +++ b/OvmfPkg/PvScsiDxe/PvScsi.h @@ -31,6 +31,21 @@ typedef struct { PVSCSI_DMA_DESC RingCmpsDmaDesc; } PVSCSI_RING_DESC; +typedef struct { + // + // As EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET.SenseDataLength is defined + // as UINT8, defining here SenseData size to MAX_UINT8 will guarantee it + // cannot overflow when passed to device. + // + UINT8 SenseData[MAX_UINT8]; + // + // This size of the data is arbitrarily chosen. + // It seems to be sufficient for all I/O requests sent through + // EFI_SCSI_PASS_THRU_PROTOCOL.PassThru() for common boot scenarios. + // + UINT8 Data[0x2000]; +} PVSCSI_DMA_BUFFER; + #define PVSCSI_SIG SIGNATURE_32 ('P', 'S', 'C', 'S') typedef struct { @@ -38,6 +53,8 @@ typedef struct { EFI_PCI_IO_PROTOCOL *PciIo; UINT64 OriginalPciAttributes; PVSCSI_RING_DESC RingDesc; + PVSCSI_DMA_BUFFER *DmaBuf; + PVSCSI_DMA_DESC DmaBufDmaDesc; UINT8 MaxTarget; UINT8 MaxLun; EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; @@ -47,4 +64,7 @@ typedef struct { #define PVSCSI_FROM_PASS_THRU(PassThruPointer) \ CR (PassThruPointer, PVSCSI_DEV, PassThru, PVSCSI_SIG) +#define PVSCSI_DMA_BUF_DEV_ADDR(Dev, MemberName) \ + (Dev->DmaBufDmaDesc.DeviceAddress + OFFSET_OF(PVSCSI_DMA_BUFFER, MemberName)) + #endif // __PVSCSI_DXE_H_ -- 2.20.1