From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0046.outbound.protection.outlook.com [104.47.40.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A4A1D21D18256 for ; Mon, 14 Aug 2017 04:34:45 -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=YJLZuBKsc8bkQOXKA/9KO6nurOx/p2s9nUnwLteSqRA=; b=QfvUuCdKLA2U2GEN1YUl2Vf43QroHgj+mu5Z1avi+uGOr6HA3cGtWaw2bmamCIYVztAs1OVIRH32bVocBcz/pfktE+qz53wD/ftVY6wWx/HZSloev8sjQQPcYDFmCE7FFAYd3f8cetb6NdhWV8MUbOlpQfA9JxKbMmVaYbirnLM= 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 BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1341.21; Mon, 14 Aug 2017 11:37:04 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Mon, 14 Aug 2017 07:36:22 -0400 Message-Id: <1502710605-8058-1-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR15CA0043.namprd15.prod.outlook.com (10.173.226.157) To BY2PR12MB0145.namprd12.prod.outlook.com (10.162.82.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bda35793-bbec-4ef4-9ba5-08d4e308c9d8 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)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:BY2PR12MB0145; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 3:3qaOJjxfTEIdoNWKcVxtKPNtmHT7NFYcdDPLza41g/8NTITV9rEU3e5POuxUM1/mKlThTGUaqO8y9IB1HInmdNUBWVcYFRSanO6wgFlP2gD92RBr1kDlPDfL1MgyQA7DAThncTfUeACEx7AQeQfk18uBoAxkNXvG9IBdpZ8TkvxIM+wOPlLDrbivdh7sPniYxk+Czl1GgvJq9Y983GIkzvnEu0jhsJQw+i2jC/Z45GB1vR+gl00HaveM0vmdTd2e; 25:pnVXdZnWmMvtOCXjRofsd+RdN+qbkqfTGe3zw93zwanEXL6f9nR+vM6l5CXhGcvqjumC0hucX7/8KprM/ov1DAHBOOwUWR+HznZ8GAanDzP1bprGHH/lDJunBKDJAnrTNNfplCnTrWJBXWLr41/8/tXYRhuh0Ejs59f8clE1htF9YTO0zqpSHXt8HL4JOqMM6mPoD3LiizzBbhPTVtZM9zA5AEx8f3jAb3tR7QkTrCLMsECOnp0kiTIQpuTA0ongczBEOnAXOmhDhTirt9mNMdNqW2erFuXdoXGu90VK5HCM29iSY+w+ysEtvULCkuBycSOx20ADUbQIzQOpruNDJQ==; 31:z0xEOnTyX+xUvEq286T0hALEXXXq7ypDeXwv+ng4AOhTgvBVz6kHcvJTxCQirH140iIblm45r0Dga1pPT0Fjbtef0LmgcpOmrSlBlbxID0o8IhjZBbUAdNo90CEEACogeb/SMCdydMmw0vNti3C2P2wDqxq6H6suodK43GGbUfSypA+47fix4ro6v4Id0lsTcLn20Kt4UNDeTfpKFy7MWY6iqPVhCZ1SmpL5j0SBDZg= X-MS-TrafficTypeDiagnostic: BY2PR12MB0145: X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:ZFrw+4VcmFmwloC40X08ryJ8sXsGDqXijxqNHCf1MR86ynsv/BUCwupy++42x0se1BctQKEEX2M2xW8tYDJqHue0M0ysp/II29Ke+2alFkXWFXVmoP3eruiHVNmvKhZ53+jLEAoR74gimVoqEZVJkzYGXjYnOwZo7Q3HfJwNYxQO/HcWwC7l3kjjtYemCej/CDui9ePBFSDvZrskKJ5KcgVeasmD+p8IyfMjXgrBw5l/d69Bi1sqaSR3lmjLhjmDUEgydeOWt8IOpqqNdliFb/1wNemsY59J9YKPAHE8LZklr/O+bftddG1iKDfRepaiZvVyWaQdhX2Vc9vwSWujBs8PIRr0ZXBhLwcvz36QEnsKurKvPptLvaDuwecoDAoEeOR5WGWRHHFhuhM5P/K/40JBxiptKhlDkY5gVAYajZrQpdjD2ZVKWXAKadNRdDbtqdVGs7z7R5BnlNcbua51jQLDfDkyhCesLxVVn1lEppqSZSC9pD38YL3FqkyPJX0n; 4:uUvIjA+mjygKHsnT+k2cYceDd413S1hRJERBRayR07eL+CFFaV+Sc0itbyUTlwDKnDYSRiVc1b1nJWUUJhJ5A1axjuCN2XglVkw7kRbWTQBlw0EOQJF4CUpwk097f1eq7RuXSdKmtN7sPAMRt5biUB7+b6toJeRUZ8O5X7eIe6KVTUkil9x60tFMb8vU6zRjQ8HfrVWEV+VckXX13PSxRtTMXuWZhtv01duS8wfs+d7yAPo2VCM0eT50BrfYeDvHEdkxxc3rxN/I7Llig9NsWOjdA1e5VMJq63cMPM2IXGwpgzDCBbmoWb64veuC3XBs4QTLm2ucIsjhA2/xDZr5/ZTW6zcItD3PRfq7O3J4cVs= X-Exchange-Antispam-Report-Test: UriScan:(166708455590820)(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)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0145; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0145; X-Forefront-PRVS: 039975700A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(199003)(189002)(54906002)(5003940100001)(6116002)(3846002)(53936002)(97736004)(86362001)(36756003)(81156014)(81166006)(110136004)(8676002)(6306002)(189998001)(50986999)(966005)(5660300001)(2361001)(25786009)(2351001)(50226002)(4326008)(7350300001)(33646002)(478600001)(53416004)(42186005)(2906002)(105586002)(7736002)(305945005)(106356001)(48376002)(50466002)(47776003)(66066001)(6486002)(6916009)(6666003)(68736007)(101416001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0145; 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; BY2PR12MB0145; 23:ysrnagGhUge7Xayx3GGSD4Yf/No6dsAcvLIst6dOo?= =?us-ascii?Q?jx4+OmmtLnXzka3p9bLZQwmRuYqufX5bML0fcn0UF08vA9EW/2f2tLTZrPCf?= =?us-ascii?Q?UFqflh9RBQ49jZTpf4owLNsssv2oQOr57wMba57pxxtgiuVe/mz/FJ4FHcqk?= =?us-ascii?Q?NEFTi2K9ELJUO7AtwWeE4Y76afZy5tdnxb+HF+9jxZkZfRW1HQkPF1E7FwYz?= =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bjPPPJNn3RC?= =?us-ascii?Q?TvBtawArGra7rECDG/YGhQuj/MIj0qfntMxhdrlA3bZd/Utb2km+A=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 6:FSh+Wha+E6r56BShr/sr2Hml1lMyeSk+CGGCixX2dr1z5QaNbdtGh+M3TssgLOkS0677Wq8BsGazNittg0xs/AcTUlehdApyRnHM/urtMyywX047flrkJ9ds5EH2WWaK4Ppmm3SWl1U+gNlnKhb4j2YeIHdOgfvu9aqSA0zF81gJGI2epNjEQ6x82e2WmQUQKJcJi+Co5qUmEZ3hk6JDV2w5lG19Do74mfKwv9I6CIjHPsgznisllhhLGY+QO3BnfyjRuZ/NNhgCo+YDDgEfI4s3kpGGF2LVK3F9tGZrGEqfq5W5Ouljj0e9t5yBjPj2wIi4xwXRnJ7H7d7Li7+ufQ==; 5:fZnkcaaSq2GIQCvsH2d0RD+AqsI7OYgU3JAPggV4637KBca7kFX1i6GjrMu5I5CM8NBPwAPHZ/37TByZalG+BmErc/UXHblkQjgVS3wdntzO6qIpOKGxxGK+38AUg0KBCpny91D1CarT5PriXuG8dQ==; 24:mYGU8LTUouYaYrBAoKo89xmA42jYsIp4ICr8oIFLuFlSDFOuTVCVmxSvlqroqL/mS1R88hfcusFZOZGRT2hCu6z586MOD72O5tw+AQ/as9Q=; 7:EoQJqdERf5CS4me0u3ASrCAMKANVx+TRuYg1ht5VB6TNHM351qP3TC3eJ3HdyUp1pbUYK8RzSwvPQfLOn/PjtQNwPtxNyn2C8IOZBQ+fKrJuPWWInSUiP2uJFdwtWbiJ0/cuSrIF+PEJZOpU2VriZWHKpo+XEQDZyC62LcgKdB+Ye470GpePZ0MDY/6lahevuZ43PnC+sMTUNcaPqOxY74dw4vXCA03PiSWdnNkpRCc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0145; 20:16Sj5zaI3RHChajhLga1vWjHL/e2NSSlCXGiiEnX7G8znp61f8mUhnV7baDCG9loNUVzkTyIj6bfP1O78CkAMl7zVMarq6h1WWqg2BROBWAZ4nf9orfTGDMVrrDQh01Z+zTuj/TO3L7JUwETtUvHxEW8P/uZBqGQ+EwNxxlvG79vNcc42199UjIODX6T25MaVBHmTS1tJ4P7Hn3xRMf0kcc5whP0zRfKSw5N4yf4tIB2TgMx9dTjuik3YlGvL27x X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 11:37:04.5804 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0145 Subject: [PATCH v2 00/21] OvmfPkg/Virtio: introduce IOMMU-like member functions 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: Mon, 14 Aug 2017 11:34:45 -0000 Content-Type: text/plain Currently, virtio drivers provides the system physical address to the device. However, some systems may feature an IOMMU that requires the drivers to pass the device addresses to the device - which are then translated by the IOMMU into physical addresses in memory. The patch series introduces new member functions in VIRTIO_DEVICE_PROTOCOL which can be used for mapping a system physical address to device address. The approach that this patch series takes is to maps the system physical address to device address for buffers (including rings, device specifc request and response pointed by vring descriptor, and any further memory reference by those request and response). Patch 1 - 5: miscellaneous fixes Patch 6 - 9: Defines and implements new member functions to map a system physical address to device address. The patch implements Laszlo's suggestion [1]. [1] http://mid.mail-archive.com/841bec5f-6f6e-8b1f-25ba-0fd37a915b72@redhat.com Patch 10 - 16: Add some helper functions and allocate the vring using newly added member functions. Patch 17: Update the virtio-rng driver to use newly added member functions to map the addresses. Verified using the following qemu cli # $QEMU \ -device virtio-rng-pci # $QEMU \ -device virtio-rng-pci,disable-legacy=on # $QEMU \ -device virtio-rng-pci,disable-legacy=on,iommu_platform=true And succesfully ran RngTest.efi from SecurityPkg/Application Patch 18: Update the virtio-blk driver to use newly added member functions to map the addresses. Verified using the following qemu cli # $QEMU \ -drive file=${IMAGE},if=none,id=disk0 \ -device virtio-blk-pci,drive=disk0 # $QEMU \ -drive file=${IMAGE},if=none,id=disk0 \ -device virtio-blk-pci,drive=disk0,disable-legacy=on # $QEMU \ -drive file=${IMAGE},if=none,id=disk0 \ -device virtio-blk-pci,drive=disk0,disable-legacy=on,iommu_platform=true Patch 19: Update the virtio-scsi driver to use newly added member functions to map the addresses. Verified using the following qemu cli # $QEMU \ -drive file=${IMAGE},if=none,id=disk0 \ -device scsi-hd,drive=disk0 \ -device virtio-scsi-pci,id=scsi # $QEMU \ -drive file=${IMAGE},if=none,id=disk0 \ -device scsi-hd,drive=disk0 \ -device virtio-scsi-pci,id=scsi,disable-legacy=on # $QEMU \ -drive file=${IMAGE},if=none,id=disk0 \ -device scsi-hd,drive=disk0 \ -device virtio-scsi-pci,id=scsi,disable-legacy=on,iommu_platform=true Patch 20 - 22: Update the virtio-net driver to use newly added member functions to map the addresses. Verified using the following qemu cli # $QEMU \ -netdev type=tap,id=net0 \ -device virtio-net-pci,netdev=net0,romfile= # $QEMU \ -netdev type=tap,id=net0 \ -device virtio-net-pci,netdev=net0,disable-legacy=on,romfile= # $QEMU \ -netdev type=tap,id=net0 \ -device virtio-net-pci,netdev=net0,disable-legacy=on,iommu_platform=true,romfile= Patch 23: Add support for VIRTIO_F_IOMMU_FEATURE bit Repo: https://github.com/codomania/edk2 Branch: virtio-support-v2 Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek TODO: * Update VirtioGpuDxe * Runtime test on aarch64 Changes since v1: * changes to address v2 feedbacks * add VIRTIO_F_IOMMU_PLATFORM feature bit Brijesh Singh (23): OvmfPkg/VirtioPciDeviceDxe: supply missing BUS_MASTER attribute OvmfPkg/Virtio10Dxe: supply missing BUS_MASTER attribute OvmfPkg/VirtioPciDeviceDxe: add missing IN and OUT decoration OvmfPkg/VirtioMmioDeviceLib: add missing IN and OUT decoration OvmfPkg/Virtio: fix comment style OvmfPkg/Virtio: introduce IOMMU-like member functions to VIRTIO_DEVICE_PROTOCOL OvmfPkg/Virtio10Dxe: implement IOMMU-like member functions OvmfPkg/VirtioPciDeviceDxe: implement IOMMU-like member functions OvmfPkg/VirtioMmioDeviceLib: implement IOMMU-like member functions OvmfPkg/VirtioLib: add VirtioMapAllBytesInSharedBuffer() helper function OvmfPkg/VirtioLib: take VirtIo instance in VirtioRingInit/VirtioRingUninit OvmfPkg/VirtioLib: add functions to map/unmap VRING OvmfPkg/Virtio: take RingBaseShift in VirtioSetQueueAddress() OvmfPkg/Virtio10Dxe: add the RingBaseShift offset OvmfPkg/VirtioLib: alloc vring buffer with AllocateSharedPages() OvmfPkg/VirtioRngDxe: map host address to device address OvmfPkg/VirtioBlkDxe: map host address to device address OvmfPkg/VirtioScsiDxe: Use DeviceAddresses in vring descriptors OvmfPkg/VirtioNetDxe: alloc Tx and Rx rings using AllocateSharedPage() OvmfPkg/VirtioNetDxe: alloc RxBuf using AllocateSharedPages() OvmfPkg/VirtioNetDxe: dynamically alloc transmit header OvmfPkg/VirtioNetDxe: map transmit buffer host address to device address OvmfPkg/Virtio: define VIRITO_F_IOMMU_PLATFORM feature bit OvmfPkg/Include/IndustryStandard/Virtio10.h | 5 + OvmfPkg/Include/Library/VirtioLib.h | 83 +++++++++- OvmfPkg/Include/Protocol/VirtioDevice.h | 170 ++++++++++++++++++-- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h | 65 ++++++-- OvmfPkg/VirtioBlkDxe/VirtioBlk.h | 1 + OvmfPkg/VirtioNetDxe/VirtioNet.h | 25 ++- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h | 61 +++++-- OvmfPkg/VirtioRngDxe/VirtioRng.h | 1 + OvmfPkg/VirtioScsiDxe/VirtioScsi.h | 1 + OvmfPkg/Library/VirtioLib/VirtioLib.c | 150 ++++++++++++++++- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c | 92 +++++++++-- OvmfPkg/Virtio10Dxe/Virtio10.c | 127 ++++++++++++++- OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 131 +++++++++++++-- OvmfPkg/VirtioGpuDxe/Commands.c | 10 +- OvmfPkg/VirtioNetDxe/Events.c | 19 +++ OvmfPkg/VirtioNetDxe/SnpGetStatus.c | 19 ++- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 168 +++++++++++++++---- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 127 ++++++++++++++- OvmfPkg/VirtioNetDxe/SnpShutdown.c | 5 +- OvmfPkg/VirtioNetDxe/SnpTransmit.c | 26 ++- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c | 11 +- OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c | 87 ++++++++-- OvmfPkg/VirtioRngDxe/VirtioRng.c | 74 +++++++-- OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 160 +++++++++++++++--- 24 files changed, 1437 insertions(+), 181 deletions(-) -- 2.7.4