From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0070.outbound.protection.outlook.com [104.47.36.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E254E2095BB85 for ; Wed, 30 Aug 2017 13:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8TPLJy9hunbfVjG8Dln5pVSIVO4TxqJb1NwqWSMnVYM=; b=s3DcHE/hC7TE4gZSkJbHV4IZt/JqN5O6L2nYAMcOgRtso/arB1vkE5hNU27eGZzQP2ZItuos9d5QsYPEI30aZVXHnbwiZZXTwgDB0JFfRiZHuPRbINrEUmDaNIShOQrfvfT8hCIIAsJFdYOVEgCid6SHtbBFV4lJiwu0WRgz/CQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from brijesh-build-machine.amd.com (165.204.77.1) by DM2PR12MB0154.namprd12.prod.outlook.com (2a01:111:e400:50ce::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Wed, 30 Aug 2017 20:45:17 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Wed, 30 Aug 2017 16:45:00 -0400 Message-Id: <1504125903-29816-2-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504125903-29816-1-git-send-email-brijesh.singh@amd.com> References: <1504125903-29816-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR2201CA0040.namprd22.prod.outlook.com (2603:10b6:301:16::14) To DM2PR12MB0154.namprd12.prod.outlook.com (2a01:111:e400:50ce::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aeb34b5c-28cd-4453-3107-08d4efe80623 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM2PR12MB0154; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0154; 3:ipHRrOynyXl487Ka+RpR1y2IuuxTLezDGcO7IWx8joXD/SjG6B3bHeLscpwLxnMAkm38OS63rcONpNB8rUPk5gQc8yVQjhjoUaiTl6GQ3WQovB7/R0AyElgbG22/msiLR1FpsR9jgppEMWY1RGvbctpcLjbBERxAVRtMd8TCSyuTuhY2Wx4spdbgUIRF+kjcHdn+hs3t/vy6V1vrzkMqAvbaMGvzxu4JZlMXTEP9+cyyTV/B3BhrQe9oqcb0twwZ; 25:Jfk+RDArfyDg1tuLrWQHVWXEKjNzmpdZ4lzI3DasB4rjaezpO5CWBO/qc9Q5hOkHYUHCg+7cJhuhmWAa4mLcDbfjgnsi4HFKkDiJOupsP62Qxxu6GDWq6KZpuR6qD/xSIp7yci8cU/RUa9upQ++lIGXbCed6Npci0IuJDq5BnOt6yHDUe8Yp73mmE7larK3tt4j1eq5l9C3xsrNVFZ+p3/CoxhE5tLYLDRuBPKxL96gEyVjnfeeMWBL1vP8NtiUrHAS9xASigG8WG+3gJUW0CNzbupFC7pINd+EZigX3S9wg3WYWFKFpJHL0LZ+/1rRRk06JeOVQ8k5CwhbQvD/+Ow==; 31:mdpHXBQAZAaAty4vonmJa6yh5QJ9crqqZX5iw9NtIlDwTvCD3fdewIVCVuj74QHRn97imSIjTxBX4skQjjzPWQCPVf+jbih/+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Test: UriScan:(767451399110)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123564025)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0154; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0154; X-Forefront-PRVS: 041517DFAB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(199003)(189002)(51234002)(50466002)(86362001)(53936002)(3846002)(6916009)(54906002)(2950100002)(6116002)(478600001)(7736002)(33646002)(68736007)(189998001)(2906002)(48376002)(66066001)(47776003)(4326008)(8676002)(81166006)(97736004)(2351001)(50986999)(25786009)(2361001)(8936002)(101416001)(106356001)(5003940100001)(50226002)(105586002)(6666003)(110136004)(81156014)(36756003)(305945005)(53416004)(6486002)(42186005)(5660300001)(76176999); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0154; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0154; 23:8tEKv04stusARSQWwYzUr8TPeSalfGOutBJQ5N4No?= =?us-ascii?Q?IR7MUfaDBY1ZbNzGIVM3r+sppJlj5Q/mnZS3PwviKqQvVXg6eh7Nbn270tpA?= =?us-ascii?Q?YdvbB3HF4DP1Xqzqff+Rj68qL0K5S2WpaPmMROA4k9mrwovRmo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154; 20:5NZI5AShK2wfqtMVZM2nOamhFdAKUmQtKJEBOyANNlWIMU8wY3Cx5ajAN+2eOhUJNcjhWfr6k+q57sbkS50yO+5KRxxXtK8OHinmty4VsE2XzmGGbW61IYAQv1ziEPjGUiKOVztr8P64bCoxBGjzUTPVV2doO67cMOVSBhAjU139vRLrvbRSeYn1K1m6lPgbA+YpxT021sE7nvYL+qx6M6xKeuoXERu2NG140Y8HR4QHaJoLz6Q6VlC3axfVKWed X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2017 20:45:17.3315 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0154 Subject: [PATCH v2 1/4] OvmfPkg/VirtioScsiDxe: map VRING using VirtioRingMap() 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: Wed, 30 Aug 2017 20:45:16 -0000 Content-Type: text/plain When device is behind the IOMMU then driver need to pass the device address when programing the bus master. The patch uses VirtioRingMap() to map the VRING system physical address to device address. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Laszlo Ersek Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioScsiDxe/VirtioScsi.h | 1 + OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 47 +++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h index 6d00567e8cb8..05a6bf567263 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h @@ -60,6 +60,7 @@ typedef struct { VRING Ring; // VirtioRingInit 2 EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; // VirtioScsiInit 1 EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; // VirtioScsiInit 1 + VOID *RingMap; // VirtioRingMap 2 } VSCSI_DEV; #define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \ diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c index a983b3df7b9c..5e72b1a24b59 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -707,7 +707,7 @@ VirtioScsiInit ( { UINT8 NextDevStat; EFI_STATUS Status; - + UINT64 RingBaseShift; UINT64 Features; UINT16 MaxChannel; // for validation only UINT32 NumQueues; // for validation only @@ -839,25 +839,42 @@ VirtioScsiInit ( } // + // If anything fails from here on, we must release the ring resources + // + Status = VirtioRingMap ( + Dev->VirtIo, + &Dev->Ring, + &RingBaseShift, + &Dev->RingMap + ); + if (EFI_ERROR (Status)) { + goto ReleaseQueue; + } + + // // Additional steps for MMIO: align the queue appropriately, and set the - // size. If anything fails from here on, we must release the ring resources. + // size. If anything fails from here on, we must unmap the ring resources. // Status = Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status = Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // // step 4c -- Report GPFN (guest-physical frame number) of queue. // - Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring, 0); + Status = Dev->VirtIo->SetQueueAddress ( + Dev->VirtIo, + &Dev->Ring, + RingBaseShift + ); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -867,7 +884,7 @@ VirtioScsiInit ( Features &= ~(UINT64)VIRTIO_F_VERSION_1; Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } } @@ -877,11 +894,11 @@ VirtioScsiInit ( // Status = VIRTIO_CFG_WRITE (Dev, CdbSize, VIRTIO_SCSI_CDB_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status = VIRTIO_CFG_WRITE (Dev, SenseSize, VIRTIO_SCSI_SENSE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -890,7 +907,7 @@ VirtioScsiInit ( NextDevStat |= VSTAT_DRIVER_OK; Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } // @@ -926,6 +943,9 @@ VirtioScsiInit ( return EFI_SUCCESS; +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, &Dev->Ring); @@ -965,6 +985,7 @@ VirtioScsiUninit ( Dev->MaxLun = 0; Dev->MaxSectors = 0; + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); VirtioRingUninit (Dev->VirtIo, &Dev->Ring); SetMem (&Dev->PassThru, sizeof Dev->PassThru, 0x00); @@ -995,6 +1016,12 @@ VirtioScsiExitBoot ( // Dev = Context; Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); + + // + // Unmap the ring buffer so that hypervisor will not be able to get + // readable data after device reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); } -- 2.7.4