From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0072.outbound.protection.outlook.com [104.47.40.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5A0E821D2E628 for ; Wed, 23 Aug 2017 05:20:26 -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=Zag7aUEmHsDKHdtOMXo+Nb57VvcBY1bwPWq3fa9ayX0=; b=xJoJddXhH/YwuzEiKO6qZdrH+pF+Kt7gVnSTBlm0kyAozeJcxbKRRnwYB/4uCM7e0GYCgC4sAjcJyshqPmlO93ubd6FCYiiHWa+8czrO/2X0FcaxELH0OouYPfUXETI6NdOj9iza85Ajer/Kiv+3pqphVmA5k2igSpKiM1e6xlE= 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 DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1362.18; Wed, 23 Aug 2017 12:22:57 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Wed, 23 Aug 2017 08:22:24 -0400 Message-Id: <1503490967-5559-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: DM5PR12CA0069.namprd12.prod.outlook.com (2603:10b6:3:103::31) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 163de5ae-eb24-4761-500e-08d4ea21b024 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:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:TOO0b7VccETDqLjJFxHikbZgoL/+tuKgd9j+pOyP2jrt2PsHthPFPsSv9URsPhsUs7KJfK+3zirheAMOil/lK94gnCD9JoaK6UJrlius1FeqhcAqQwwktn6NcF9Xfjc4X8rQHd7UM0rbdMHedwbmQf+tkvJefZNTaADtkHGUWUo2ncYaMdZSxod2Y9m6NjWvriqEUHblsJcAgSS2YRIjWdtW+skWaYYfQ1qSBTasunaXBmL/fzNfm4tBOB7O5FHB; 25:cnnsY7dQCtrYTQZCT7cHDTqOwsyMm4LFhaCEELjQgjD9Q2O4wZt42qR9U+ZNIONa/+u8lpifolbWJBtxU4AOFwkw55xCD6+RGRwY0fP/TiYrbi56S23zx9yAs0TmhaLfbm+q4a4LWrtN3SE2r044QZcX7Ev3xYaVDynxHbxXPT4QAzTiIWPE4+avl+4Uj7n2Hpj9Ov7Af163UEaHiPweVYKkjrGxsnhQ8phzD87E+6swz4ooocFwXvgpyDZY1PNVQ4FY90eoKfG4KLX/7jy711XwnLjWgDge3ErTySwYUQ2eCe/bAgT+0uE+3eSFgVDzprAUprjtdZta1vaRmLuO5A==; 31:RV4iJLSSYOpBSKYozB5zji6t5mBtEhPEWOY5wQez0HYtkgClCjZqUCb4F6vyvdvSBAyLQa5FJw/rXAhLqBLIR+5zKxF86U/R0iEenCT+hbS1PQKH6SqxLnRwiDDghUFeziV3K38qUBsDnv7uDxUCfHR79F0zU87rv1lQCDUCGIjNY6qhJc/6sUfZAS90vCMEmtDh5DV2sjT6Opl0YDh7MVb5XhaOm84P+nbhy9NoEkY= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:LIn2VUgKTBoswSPZS4qE+ma2EXpOu6RVMGc/FYhiQ6CUkmTIUa+zJC9942szW/ctF2fFTqsoa8ipL9TiVXmTZ6cVt2FLfzOMWRvO0YTaULBP1ZW7anJ4aWVw5aYJiQnF91XtBEk+7Wom0PJT99zu9KJEKp5ggn4SYKOed1asITygGnxw4qG7hHPrVosqzqr8JDSKzqFq805QLUAgJejhN3YlWGPFcsagavvrmnPzCLD2UoFLXw/PbZkupLxCxZqpSA80ubDt3wwljqPS/zZKtC86ajf7y46FuD+CKZBPUoNYTgeOtLWSnr6lbxc2AJ6qm/73uDa1SIqyZ74l2zY/xPYx1P9T06qCqkTZgob0XL0Wy4SWQFlpYvaSutif3v77SqtL/c+q8iDpKXLs9k/SfM4Wj7vqDKLQyBS+ip0UavLx5xf6D3+fGmVrgCmKnZDFI/H89uhX8UnxiOPpQIfwoSR0pvBb1HX4rJ5TJapST2bk2iAubDquOlSGVvrdlmT7; 4:SH/f/e77i+X+coK90L65HidpZBtg4efRw2CgPlrFpPkocF4Q1QzHJEleNHKO6r+bYkIb16pwYCAxhchDoK51Ph21ACODFcnfTfk9MVt4vESdrOm81ljfYfJ9SP4ATtsvSKQzQ6bqIuceEtgqkdzCaHYxtBVlbcObaXSYLSBadSxSoJrt82zHNG63GszMMNor5rwog3BC4AuykDJ3K9zatmMSfFERDmsUB6/l/CQYunhozOQzY6uz/jySDOI6MhSAZxo4wIwFFb55W1BFnATcBle/66dmjGSJ27MhhEusT3w4o1c3r9DWkuiUoHjry3VjmECVvp7AsSRGIKmu2J3Oi6znSVPNXTSqq4vmeXrPAyY= 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)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 040866B734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(189002)(199003)(305945005)(47776003)(97736004)(101416001)(110136004)(6666003)(189998001)(478600001)(7736002)(3846002)(66066001)(5003940100001)(6116002)(6486002)(966005)(48376002)(86362001)(105586002)(4326008)(106356001)(36756003)(6916009)(50466002)(2906002)(50226002)(42186005)(2351001)(33646002)(53416004)(25786009)(7350300001)(81156014)(5660300001)(68736007)(6306002)(54906002)(8676002)(53936002)(50986999)(81166006)(2361001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DM2PR12MB0155; 23:EpFrKyZvmKYo9X8TMWkNMWITTGP54kKmMx3AXChif?= =?us-ascii?Q?VaiLiTIMhGIbyIMhT4eRhrm8SGou9+ODMwtzUh0SEcEv+kAzNlVD2NFTSHH1?= =?us-ascii?Q?+Bai95k7R+YwTghcw3+oW/FY35T4W5BQ+6IWgGz3/baZoobmXWq3tFrtSt1q?= =?us-ascii?Q?gvq/6q05Q5Yig3AWvWFenyHWB4ybWSh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us-ascii?Q?ljh/SxypRQOZlRAkc9ka+n6lHVV09PveLC6eSY2hMp5kdNJfpm7TcMIk6iPf?= =?us-ascii?Q?TCaFIT7DqZFPnfrFUEGLVck2arpJ5YpXxvKLQXbpH6oO0gGoNXY9Q=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 6:ajuvnoDC5A7e0lbyKMs5XbAOYUZBCf+JxlhiVDfj1ewhvAOw+3aVLD7EWpfeobpPWsFKSfh4S0jnb4M/E0oAKTdwxsKDPayufpinziW4BdS7+cpCs0zOlic2GNWWyFONgfoag8O6ehaYYblFxvlaVHdojV/GA2i3D40uD3Qt4deE4MUnVDBAazdXOCE5UR4xNG2T50Hczh/t2m8dyJkqACDCuKZJR0bjn19ZoHff2o2CmhG7jL68YE0lkblDJfoVw3RM09UMXXf6SwrVzhs9pS5pYltpBJqeF+dO+587mDU3mOsanUq8sZzhvi5rdW9IMNaIvQXRfWw2L+l26lYZ4w==; 5:+3x1vQRFIJAkk9bs+krRcnYjCmm0B8b6ITnd+ftrnlsjJ3NbWHGQifrj6XBansw8uN2JqXNXj7TZgUKwk+o7k2MuHic0IDZP60rgFYmwb5z2de8uoX49uVJohbYlkfx9dkCkyf+WsKxD1ERxigojrA==; 24:h8lh6kJxPaVPEwBHj6levFtpP4ruULismqyFsX50Si62arDe0g0XGKZWnkmao0xxB0qfmpXLT66Kp5kguBmeF3CTkdp1+AqwLmNZ9RFQazQ=; 7:/aEDvqjdvOvXLbfCcE/MUsrTACsppbdw3zqYbgOCUp86kLq/8Ba0/nS9Oa25wpWzseWk0e1PNmmY/m7A3N7nH8wgmNy42YKsfYy0RjF2PPasAbLnZHGq7dBlni7roRDNJOHj/jpxsrzzrtDY2omZAV+jufMP1iXvVqTo6htAsQOrWVjtnVHKSzns6QLzylMs64szVpWfWoWAOjWUchmDoq7ygS9h26S7pOejII3u3fs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:Ppp9yxZZf/vQKBH6Qvh+qBut33pl1+5L0kCJ0IwuwQKDOKUafuyMbCStCKzKQwNIJm23pax3677jux1T35wkF6jAmEp8vPZU0mXqkICCehN2dfkZUVxXavPcmIYHBK+ZdFtcSDaI+EK/FWb8pyj8I2/q+78S0r+Z/WQqMI0rAVeA1sDEjFkE2DlU+ad12rvwSC/OPegcctBI1RHomb2ucrjSldt58ZsH3dVZg9/jOvvuxrQ4uEScxR9I6fOKkHZW X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2017 12:22:57.4353 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v3 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: Wed, 23 Aug 2017 12:20:26 -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 - 4: 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 5 - 12: Add some helper functions and allocate the vring using newly added member functions. Patch 13: 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 and also verified that /dev/hwrng get created after Linux guest boot Patch 14: 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 15: 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 16 - 19: 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 20 - 23: Add support for VIRTIO_F_IOMMU_FEATURE bit Repo: https://github.com/codomania/edk2 Branch: virtio-support-v3 Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek TODO: * add VirtioGpuDxe (i will take Laszlo's offer that he can help with this driver) * I did minimal test on aarch64 - I was running into some Linux bootup issues with Fedora aarch64 iso. The issue does not appear to be releated to virtio changes. If anyone can help doing additional test with their aarch images that will be great ! thanks Changes since v2: * changes to address v2 feedbacks * split the iommu_platform support into multiple patches Changes since v1: * changes to address v1 feedbacks * add VIRTIO_F_IOMMU_PLATFORM feature bit Brijesh Singh (23): OvmfPkg: 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/Virtio: take RingBaseShift in SetQueueAddress() OvmfPkg/Virtio10Dxe: add the RingBaseShift offset OvmfPkg/VirtioLib: add function to map VRING OvmfPkg/VirtioLib: alloc VRING buffer with AllocateSharedPages() OvmfPkg/VirtioLib: change the parameter of VirtioAppendDesc() to UINT64 OvmfPkg/VirtioRngDxe: map host address to device address OvmfPkg/VirtioBlkDxe: map host address to device address OvmfPkg/VirtioScsiDxe: map host address to device address 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/Virtio10: define VIRITO_F_IOMMU_PLATFORM feature bit OvmfPkg/VirtioRngDxe: negotiate VIRITO_F_IOMMU_PLATFORM OvmfPkg/VirtioBlkDxe: negotiate VIRITO_F_IOMMU_PLATFORM OvmfPkg/VirtioScsiDxe: negotiate VIRITO_F_IOMMU_PLATFORM OvmfPkg/VirtioNetDxe: negotiate VIRITO_F_IOMMU_PLATFORM OvmfPkg/Library/VirtioLib/VirtioLib.inf | 1 - OvmfPkg/Include/IndustryStandard/Virtio10.h | 4 +- OvmfPkg/Include/Library/VirtioLib.h | 132 +++++++++--- OvmfPkg/Include/Protocol/VirtioDevice.h | 162 +++++++++++++- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h | 39 +++- OvmfPkg/VirtioBlkDxe/VirtioBlk.h | 1 + OvmfPkg/VirtioNetDxe/VirtioNet.h | 25 ++- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h | 37 +++- OvmfPkg/VirtioRngDxe/VirtioRng.h | 1 + OvmfPkg/VirtioScsiDxe/VirtioScsi.h | 1 + OvmfPkg/Library/VirtioLib/VirtioLib.c | 204 +++++++++++++++--- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.c | 8 +- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c | 62 +++++- OvmfPkg/Virtio10Dxe/Virtio10.c | 128 ++++++++++- OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 213 ++++++++++++++++--- OvmfPkg/VirtioGpuDxe/Commands.c | 13 +- OvmfPkg/VirtioNetDxe/Events.c | 19 ++ OvmfPkg/VirtioNetDxe/SnpGetStatus.c | 29 ++- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 195 ++++++++++++++--- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 133 +++++++++++- OvmfPkg/VirtioNetDxe/SnpShutdown.c | 7 +- OvmfPkg/VirtioNetDxe/SnpTransmit.c | 30 ++- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.c | 7 +- OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c | 63 +++++- OvmfPkg/VirtioRngDxe/VirtioRng.c | 93 ++++++-- OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 222 +++++++++++++++++--- 26 files changed, 1635 insertions(+), 194 deletions(-) -- 2.7.4