From nobody Thu Dec 26 12:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504265072973163.1309593288555; Fri, 1 Sep 2017 04:24:32 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A88F221E74914; Fri, 1 Sep 2017 04:21:44 -0700 (PDT) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0056.outbound.protection.outlook.com [104.47.34.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 316AC21E74908 for ; Fri, 1 Sep 2017 04:21:43 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Fri, 1 Sep 2017 11:24:25 +0000 X-Original-To: edk2-devel@lists.01.org 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=1eR5Bss++9cx7HXkM6a8hT31EUO1cnGJz7AXLgG9c5w=; b=kbicl35WBDoNb2E8nJg0eHOKGiqQ809DfEv+kcCSIKHfJL1t3XT4GnZg0rgxRBjP2jBaEisHlu+4Qv0myyhUIxicFA/TxO+50LPJ2rE8dYat9iW1Ni94ryd7IWwKYd5YeY001ymd0ffojTTNOa5kMJABxaHpp6zMJLm9r9UPuyQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Fri, 1 Sep 2017 07:24:01 -0400 Message-Id: <1504265045-19008-2-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> References: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0012.namprd03.prod.outlook.com (10.168.230.150) To BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 567cfaa8-fa07-46ec-22c0-08d4f12c0128 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:BY2PR12MB0146; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 3:mRlglqth+2+9uREySTVvytxU2cjLC6Q1aMppJKjZSTBPe5V8R+4y+e+4JeMh873qE4AlNmZPr1hb0xUo1qs88WpxzR+T4tzFlttmOPKU38qBA/2hLtI2ysLGMjvtqqMWT+KHhbI51gfnst55bH7v6o/qR23AJyFbgoQ2sCaR9Ko/fQlgLLVxn9whmYxelhYldv1JDYSmCEDpYsFy5BfHMCMYN3Rn2wS/+oefCwWKwIvaLTIe0Z/XEKvB5sSpIWn6; 25:Km2CNebBWcLsJwYfs/U5uAC9feBzBAipGde5gaKhQxroLyxqm/B/Np6DNroWCUkQ8SpU3hmR1LOM6GKDmfUS5IlpUVIReAYGzpTtcckXbNTOQXD6oVmrLcius5F0dECJ1v08ZYwguTm+pXy2FPd/oO2caw2/PY6+vqaNLvgV1OuB2b7COqKmGYWDyK6JGesnMc94bYc371/DIPewaPwt6Zk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eQqv5sK56vkLI1Nd9nKqYXBLnGFPWAEal1G8uLEbmEWDe55Bwquamzm33EsJWchDcvPt6fTU2nE5dKr3HcHuKtb+DP1b/DC1vqms1yXDN9Y2zGhnEXBdKdCaQwTLjC+ZwRVX5W/wZ2PjUrGDtsN+XcmqMRuhrUAuePp8s7PlgbLlAhjRGy96f14818+GmCT3PRTHqK4qutBCC3Ja123UoLopsfx9m1bRl9RmVqS2rPUhh0UjvmpFtdw= X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699)(17755550239193); 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)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0146; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0146; X-Forefront-PRVS: 0417A3FFD2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(6009001)(39860400002)(199003)(51234002)(189002)(50466002)(54906002)(6666003)(8936002)(66066001)(4326008)(50226002)(48376002)(47776003)(53936002)(478600001)(25786009)(110136004)(189998001)(76176999)(42186005)(53416004)(5003940100001)(2351001)(68736007)(106356001)(105586002)(3846002)(6116002)(2950100002)(6916009)(2361001)(305945005)(36756003)(50986999)(5660300001)(33646002)(2906002)(101416001)(7736002)(97736004)(81166006)(6486002)(8676002)(81156014)(86362001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0146; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0146; 23:eAIGSz2uwBSVjLSm9r5LIOpAMyWk4La+b8tMFbCQ9?= =?us-ascii?Q?QMwcUKKG3GuNa9puOpQ2OQZ4sbiURYDqO3fxIT8WiCY0BEmulBf+qmSVBqXP?= =?us-ascii?Q?dvIy2SqsfQvr9EP5wDVJJATXUzT5U2E8RD4QnFIdIzZgNEhO9SS9dDxRVmry?= =?us-ascii?Q?q7a8OZ6nm1k1fWiyXS1wHoYBp4qaoCL0bxLafgruFZgt56tzlN+sleuizKvt?= =?us-ascii?Q?Vt9cauRSOaaArJelTdsWU4jNBkDvybgulbzF8qyN9OTbeF437bnZDiU903af?= =?us-ascii?Q?/MqX44q+TJ2on04a8YOw31LLFeNIrDhzsWCuqEBy7gUtjKii1NBvBeMQjTsV?= =?us-ascii?Q?OA+uy4Aist8XUifUisbJZLut0jyquA5YlQk+Xtzz9PZl3PH0Rr3oxO7L3Nf5?= =?us-ascii?Q?tVYpMEDtsl2vSJi/FrkcEavhJJR4dpAukLDeUElU65gYtdaHS8KDcPXpEInb?= =?us-ascii?Q?IA2h+cCWI7SElY+BGLAhRfprZElfaITzQaOKzc4rzDzFqKgyRhQHlT/T2DWq?= =?us-ascii?Q?3D0hYYpjFXdol++aCfbrZFdrG0/ylbemZpzYjVOOf80WSpWX/w06UcYg6A/B?= =?us-ascii?Q?GV8s4j5WQSK6yh+iWeXTfesKWrFKR+7T6DoMBSXLdAAzdLo2ZcCPZWFyJ0eg?= =?us-ascii?Q?mlcobydjQuT1T6yRh3cglP6BmqIKVPcSo1furzNeZt4PdeEgyyFVX9bVwg+A?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Elzt4SrJpsaKtjnmAmwTLnTRy3PAQDOHIDi4//9fEvZpnKTzVDSW/znXwTwOwghHTkO/sd06c+AJC9UHcDkix86Q04nBiYKGQTgKsSGh1A==; 24:c6tyKqbDSDgh+38hfJUtc8Y9PpPO2uBez014wWTskWGvtVwS6eG70vQEgKuhCjnGda12PAyTmlRfH+grQMf9Z6iuxCRgUNzkQANFp7PEVCY=; 7:7qmNJNal1m3gpbEKyip5hf59N9uxFLOjxGMk0bGb4ItjoHtiTPJxsdsCsPkeVCmw0yK5WeKfZkuX3bgs+Bhvri2SaEmAucAd6Jlbokm6gdVZdNAD0mWWdm5pGxqBnmx7EJ9ZBs1A1QtYHl9zYBcYOwsA8lv+0FxJkwHygckHKHHPdaCBg8tCuDbnAAywYpYwLiYw2ct04NlIqxeF2AqTKyoDmoaU4xrxuQM/LNDP8TM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 20:pOJBTEiM3fx4vt2/Y31peeVrI1kY8AQvLOUArZ4w+VLwjGnW8PrxXjsfQrPxVagVZD9FIgZCFa8VE1dQD0PJ6I4klTom1pjceZiKtleOrtNASLg1YzypjgP2hkD8G/a+k4ZXIvmJ73TUA2KTIW1hIQfMIP2CHRNpt7/AtuuPMPCuZb+ZyRXYM0yT0lY567ZNhqE3UPcxTiZTY66q38X/zWvnr0qYhiVN0FBVa8hY5ShQ5e0T7WQ2BIHzGP6DdWHu X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2017 11:24:25.7144 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0146 Subject: [edk2] [PATCH 1/5] OvmfPkg/VirtioNetDxe: 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: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioNetDxe/VirtioNet.h | 2 + OvmfPkg/VirtioNetDxe/Events.c | 7 ++++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 40 ++++++++++++++++---- OvmfPkg/VirtioNetDxe/SnpShutdown.c | 2 + 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 710859bc6115..d80d441b50a4 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -82,10 +82,12 @@ typedef struct { EFI_HANDLE MacHandle; // VirtioNetDriverBinding= Start =20 VRING RxRing; // VirtioNetInitRing + VOID *RxRingMap; // VirtioRingMap UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx =20 VRING TxRing; // VirtioNetInitRing + VOID *TxRingMap; // VirtioRingMap UINT16 TxMaxPending; // VirtioNetInitTx UINT16 TxCurPending; // VirtioNetInitTx UINT16 *TxFreeStack; // VirtioNetInitTx diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 5be1af6ffbee..6950c4d56df1 100644 --- a/OvmfPkg/VirtioNetDxe/Events.c +++ b/OvmfPkg/VirtioNetDxe/Events.c @@ -88,4 +88,11 @@ VirtioNetExitBoot ( if (Dev->Snm.State =3D=3D EfiSimpleNetworkInitialized) { Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); } + + // + // Unmap Tx and Rx rings so that hypervisor will not be able get readabl= e data + // after device is reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); } diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 0ecfe044a977..803a38bd4239 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -35,11 +35,13 @@ the network device. @param[out] Ring The virtio-ring inside the VNET_DEV structure, corresponding to Selector. + @param[out] Mapping A token return from the VirtioRingMap(). =20 @retval EFI_UNSUPPORTED The queue size reported by the virtio-net devic= e is too small. @return Status codes from VIRTIO_CFG_WRITE(), - VIRTIO_CFG_READ() and VirtioRingInit(). + VIRTIO_CFG_READ(), VirtioRingInit() and + VirtioRingMap(). @retval EFI_SUCCESS Ring initialized. */ =20 @@ -49,11 +51,13 @@ EFIAPI VirtioNetInitRing ( IN OUT VNET_DEV *Dev, IN UINT16 Selector, - OUT VRING *Ring + OUT VRING *Ring, + OUT VOID **Mapping ) { EFI_STATUS Status; UINT16 QueueSize; + UINT64 RingBaseShift; =20 // // step 4b -- allocate selected queue @@ -79,30 +83,38 @@ VirtioNetInitRing ( return Status; } =20 + Status =3D VirtioRingMap (Dev->VirtIo, Ring, &RingBaseShift, Mapping); + 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 resour= ces. // Status =3D Dev->VirtIo->SetQueueNum (Dev->VirtIo, QueueSize); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 Status =3D Dev->VirtIo->SetQueueAlign (Dev->VirtIo, EFI_PAGE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // // step 4c -- report GPFN (guest-physical frame number) of queue // - Status =3D Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring, 0); + Status =3D Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring, RingBaseShif= t); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 return EFI_SUCCESS; =20 +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, Ring); =20 @@ -456,12 +468,22 @@ VirtioNetInitialize ( // // step 4b, 4c -- allocate and report virtqueues // - Status =3D VirtioNetInitRing (Dev, VIRTIO_NET_Q_RX, &Dev->RxRing); + Status =3D VirtioNetInitRing ( + Dev, + VIRTIO_NET_Q_RX, + &Dev->RxRing, + &Dev->RxRingMap + ); if (EFI_ERROR (Status)) { goto DeviceFailed; } =20 - Status =3D VirtioNetInitRing (Dev, VIRTIO_NET_Q_TX, &Dev->TxRing); + Status =3D VirtioNetInitRing ( + Dev, + VIRTIO_NET_Q_TX, + &Dev->TxRing, + &Dev->TxRingMap + ); if (EFI_ERROR (Status)) { goto ReleaseRxRing; } @@ -510,9 +532,11 @@ AbortDevice: Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); =20 ReleaseTxRing: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->TxRing); =20 ReleaseRxRing: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->RxRing); =20 DeviceFailed: diff --git a/OvmfPkg/VirtioNetDxe/SnpShutdown.c b/OvmfPkg/VirtioNetDxe/SnpS= hutdown.c index 5e84191fbbdd..36f3253e77ad 100644 --- a/OvmfPkg/VirtioNetDxe/SnpShutdown.c +++ b/OvmfPkg/VirtioNetDxe/SnpShutdown.c @@ -67,7 +67,9 @@ VirtioNetShutdown ( Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); VirtioNetShutdownRx (Dev); VirtioNetShutdownTx (Dev); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->TxRing); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); VirtioRingUninit (Dev->VirtIo, &Dev->RxRing); =20 Dev->Snm.State =3D EfiSimpleNetworkStarted; --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 12:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504265076640626.6581150401798; Fri, 1 Sep 2017 04:24:36 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 11A2921E7491F; Fri, 1 Sep 2017 04:21:46 -0700 (PDT) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0042.outbound.protection.outlook.com [104.47.40.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 96A9A21E7490F for ; Fri, 1 Sep 2017 04:21:44 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Fri, 1 Sep 2017 11:24:26 +0000 X-Original-To: edk2-devel@lists.01.org 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=MSFLSsxVZQvsBM0cTJi7jarW1mUfjMmBCh4kQKHnYYA=; b=hhRgEjsioRTYT9coCPKO2BeVVrT/GIpgfUQRFZ3rbut+gwVInLTcJSy4X0AKkd6ZgM4DcZ528yxv13jsf8qBvGsI+forgUbxY9tI5/QBnBOOzGTiM50WakV6J+rOwU0S35f0WB/UxqeNQwI6z0DW0WlZ0oD/wN7xiFxwTckFXjg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Fri, 1 Sep 2017 07:24:02 -0400 Message-Id: <1504265045-19008-3-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> References: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0012.namprd03.prod.outlook.com (10.168.230.150) To BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6d9a5051-36dc-4034-a3d4-08d4f12c01eb 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:BY2PR12MB0146; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 3:LflHfRHWE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1Ak6mUzUK70cWgvYaTUyToh78qweAHUxxrHNhYWkOVY0q+jDc8Gmm/Sawnli3QG1FXFc/wV94bXcjmYQgRAz4ZxzLSUVk9/wUuODUPEf9qWxfSusy4bcTV9tw6Y0O23jg3fEWj63M4IsJtUnLrIGpL01P0y1xlM0zv49tgzfSVHTdZxOHyV8Sa0FnAMrATqcn2fDXmuFBJ96vc975KWtIBjnsal8uEC09M4KuGqtjav9phodN61BxJPPw5IT74Alfb/BY0yQ4w45wvySEM03/GgXbzmoeUGvlfipZf08eJ3Tr/JOnaxmAQdh2ZZZyT9c2muab/PYL72wTKlVFY45Oc2CkE; 4:DDCdLEYsABROlDHpqLHYs9dVn4GpMwEljHIHyEPk2+fRW8bPUHu5WFbj24whk3av1CK7KMkl3udcoJieVg0OIMycBaxULTFinAHj7ZJ2vpkMe/NfkbiICQLXuvIgvYpxEQEBHBMjGEc+blN081qANesMngoqqxviOKDhd7rl0DVTKXuha22BzMXWfIOa7zgffFhdp/i93TJzocd/TLU/YQDF71GfH3QxrPxw8AUPdd7KdTxWnB1qCEAFZX7ug2d9PCRqJ4bkxX6Xs1UPBjVP1XbK5Z273N6lmkf8Qd3wjXCjvePIXKxNxC+UxYGa8gZsTNwjxEjfRWVXFUzmDbAJMg== X-Exchange-Antispam-Report-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)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0146; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0146; X-Forefront-PRVS: 0417A3FFD2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6029001)(6009001)(39860400002)(199003)(189002)(50466002)(54906002)(6666003)(8936002)(66066001)(4326008)(50226002)(48376002)(47776003)(53936002)(478600001)(25786009)(110136004)(189998001)(76176999)(42186005)(53416004)(5003940100001)(2351001)(68736007)(106356001)(105586002)(3846002)(6116002)(2950100002)(6916009)(2361001)(305945005)(36756003)(50986999)(5660300001)(33646002)(2906002)(101416001)(7736002)(97736004)(81166006)(6486002)(8676002)(81156014)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0146; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0146; 23:Bgjkvcyj8jcpUcW96iZYp/9zLFa2jX2v8Rjk3C7jo?= =?us-ascii?Q?fYkaxTm0Jn7WQ0fa1kiE92Bplf+vWHOPVkkjuZO1fxVruI0ydywJfMqzznMz?= =?us-ascii?Q?4e/bt5aG9w2Q1j0XqAdLjVVyQG7AtzwLX4eMyThgclPscdTUclCVasXPX25b?= =?us-ascii?Q?TnpaW8u/yqbbXNgmBQc0StorUW/DvTBM/IwLT7LoR5eLNXdyMg4C1Sbq7cqF?= =?us-ascii?Q?mVseb7daRVlfAAasv6Rlhi9tSzXJtEPqF1uBifkjUaDduckOyMxkx6izj49z?= =?us-ascii?Q?ZQ8VkUHhRXv30XXKGr1zQbjngd3ibP8TaSuqGAX1WC1M7t3xZ5ZDuT5ZbGo/?= =?us-ascii?Q?VuVsQlM4XWHJO4NQa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ctgN X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2017 11:24:26.9782 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0146 Subject: [edk2] [PATCH 2/5] OvmfPkg/VirtioNetDxe: alloc RxBuf using AllocateSharedPages() 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: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When device is behind the IOMMU, VirtioNetDxe is required to use the device address in bus master operations. RxBuf is allocated using AllocatePool() which returns the system physical address. The patch uses VIRTIO_DEVICE_PROTOCOL.AllocateSharedPage() to allocate the RxBuf and map with BusMasterCommonBuffer so that we can obtain the device address for RxBuf. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioNetDxe/VirtioNet.h | 3 + OvmfPkg/VirtioNetDxe/Events.c | 6 ++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 75 ++++++++++++++++---- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +- 4 files changed, 77 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index d80d441b50a4..7df51bd044f5 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -4,6 +4,7 @@ Protocol instances for virtio-net devices. =20 Copyright (C) 2013, Red Hat, Inc. + Copyright (c) 2017, AMD Inc, All rights reserved.
=20 This program and the accompanying materials are licensed and made availa= ble under the terms and conditions of the BSD License which accompanies this @@ -85,6 +86,8 @@ typedef struct { VOID *RxRingMap; // VirtioRingMap UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx + UINTN RxBufNoPages; // VirtioNetInitRx + VOID *RxBufMap; // VirtioMapSharedBuffer =20 VRING TxRing; // VirtioNetInitRing VOID *TxRingMap; // VirtioRingMap diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 6950c4d56df1..0586a82cdf09 100644 --- a/OvmfPkg/VirtioNetDxe/Events.c +++ b/OvmfPkg/VirtioNetDxe/Events.c @@ -95,4 +95,10 @@ VirtioNetExitBoot ( // Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxRingMap); Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxRingMap); + + // + // Unmap Rx buffer so that hypervisor will not be able get readable data= after + // device is reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); } diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 803a38bd4239..6052d40fc6cb 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -236,7 +236,7 @@ VirtioNetInitTx ( @param[in,out] Dev The VNET_DEV driver instance about to enter the EfiSimpleNetworkInitialized state. =20 - @retval EFI_OUT_OF_RESOURCES Failed to allocate RX destination area. + @retval EFI_OUT_OF_RESOURCES Failed to allocate or map RX destination a= rea. @return Status codes from VIRTIO_CFG_WRITE(). @retval EFI_SUCCESS RX setup successful. The device is live an= d may already be writing to the receive area. @@ -249,13 +249,17 @@ VirtioNetInitRx ( IN OUT VNET_DEV *Dev ) { - EFI_STATUS Status; - UINTN VirtioNetReqSize; - UINTN RxBufSize; - UINT16 RxAlwaysPending; - UINTN PktIdx; - UINT16 DescIdx; - UINT8 *RxPtr; + EFI_STATUS Status; + UINTN VirtioNetReqSize; + UINTN RxBufSize; + UINT16 RxAlwaysPending; + UINTN PktIdx; + UINT16 DescIdx; + UINT8 *RxPtr; + UINTN NumBytes; + EFI_PHYSICAL_ADDRESS RxBufDeviceAddress; + UINT64 BufBaseShift; + VOID *RxBuffer; =20 // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depend= s on @@ -280,11 +284,40 @@ VirtioNetInitRx ( // RxAlwaysPending =3D (UINT16) MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PE= NDING); =20 - Dev->RxBuf =3D AllocatePool (RxAlwaysPending * RxBufSize); - if (Dev->RxBuf =3D=3D NULL) { + // + // The RxBuf is shared between guest and hypervisor, use + // AllocateSharedPages() to allocate this memory region and map it with + // BusMasterCommonBuffer so that it can be accessed by both guest and + // hypervisor. + // + NumBytes =3D RxAlwaysPending * RxBufSize; + Dev->RxBufNoPages =3D EFI_SIZE_TO_PAGES (NumBytes); + Status =3D Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + Dev->RxBufNoPages, + &RxBuffer + ); + if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } =20 + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + RxBuffer, + NumBytes, + &RxBufDeviceAddress, + &Dev->RxBufMap + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeSharedBuffer; + } + + Dev->RxBuf =3D RxBuffer; + + BufBaseShift =3D (UINT64) (UINTN)Dev->RxBuf - (UINT64) RxBufDeviceAddres= s; + // // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device // @@ -306,6 +339,11 @@ VirtioNetInitRx ( DescIdx =3D 0; RxPtr =3D Dev->RxBuf; for (PktIdx =3D 0; PktIdx < RxAlwaysPending; ++PktIdx) { + UINT64 Address; + + Address =3D (UINTN) RxPtr; + Address +=3D BufBaseShift; + // // virtio-0.9.5, 2.4.1.2 Updating the Available Ring // invisible to the host until we update the Index Field @@ -315,13 +353,13 @@ VirtioNetInitRx ( // // virtio-0.9.5, 2.4.1.1 Placing Buffers into the Descriptor Table // - Dev->RxRing.Desc[DescIdx].Addr =3D (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr =3D Address; Dev->RxRing.Desc[DescIdx].Len =3D (UINT32) VirtioNetReqSize; Dev->RxRing.Desc[DescIdx].Flags =3D VRING_DESC_F_WRITE | VRING_DESC_F_= NEXT; Dev->RxRing.Desc[DescIdx].Next =3D (UINT16) (DescIdx + 1); RxPtr +=3D Dev->RxRing.Desc[DescIdx++].Len; =20 - Dev->RxRing.Desc[DescIdx].Addr =3D (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr =3D Address; Dev->RxRing.Desc[DescIdx].Len =3D (UINT32) (RxBufSize - VirtioNetReq= Size); Dev->RxRing.Desc[DescIdx].Flags =3D VRING_DESC_F_WRITE; RxPtr +=3D Dev->RxRing.Desc[DescIdx++].Len; @@ -345,10 +383,21 @@ VirtioNetInitRx ( Status =3D Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX); if (EFI_ERROR (Status)) { Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); - FreePool (Dev->RxBuf); + goto UnmapSharedBuffer; } =20 return Status; + +UnmapSharedBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + +FreeSharedBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + Dev->RxBufNoPages, + (VOID *) Dev->RxBuf + ); + return Status; } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 9fedb72fdbd4..4c9d9ece0790 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -39,7 +39,12 @@ VirtioNetShutdownRx ( IN OUT VNET_DEV *Dev ) { - FreePool (Dev->RxBuf); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + Dev->RxBufNoPages, + (VOID *) Dev->RxBuf + ); } =20 =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 12:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 150426507965812.61003496679848; Fri, 1 Sep 2017 04:24:39 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5016C21E74908; Fri, 1 Sep 2017 04:21:47 -0700 (PDT) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0075.outbound.protection.outlook.com [104.47.34.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BB28421E7491D for ; Fri, 1 Sep 2017 04:21:45 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Fri, 1 Sep 2017 11:24:28 +0000 X-Original-To: edk2-devel@lists.01.org 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=BRUHN2+GDOktaHMqYoyJxmO4rI+iJUOgD6Xq6DvWUvY=; b=2n3st5tabPQrhbazLzttqxD9KIFo0LG9K7dEhW+zKMsDGqAvQPh/+/jjeyqs2OhZSg0swCcEPf+zLQwbUuw3dl4r4Iw+5+2kJIwT58lRhHeTO5hZQ6rJ8DTARfEDUvLILg7miTVZdvLhbCO/m7SefJ6//ueppkOg5YJRJdVQ4bU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Fri, 1 Sep 2017 07:24:03 -0400 Message-Id: <1504265045-19008-4-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> References: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0012.namprd03.prod.outlook.com (10.168.230.150) To BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15e6ebdf-3a8d-451e-e992-08d4f12c02b3 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:BY2PR12MB0146; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 3:1V0ug/3EZY9jhSCBItp4sCFkej3jicGfSE0LShtEjJi2iE0YAqYJZ+ojdg8gMmWLlqL09cq+0vBTOCotkc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q+aoCG2GY2kxfRlyJ9qCf9rqgPXxVR8Jxi1+gs+tbQHiGibR5IsxFpj3auQLAQa7wlLCqDlBEC+IHsqgs14lmKNh1WL14HpvvSI7XK86DuvuNwOVid3R/Z6AZ/C2kAPJXbDBZDhN+Uen2EvnG6YIAiewtLlAdnxdmZKUKNF8lCb6miq2DuFn6JNIGXTYA3x9GBkN3jReGQhR594Ag1L/OOxvnWsT9cEjtPQ4DIGwFQsxgFSdGeZ0p75tbHTCsJ44; 4:o0/sgmS7DZv+n5X/GtWfPowmoOTpexeI69CjSLSLOCYvRh6sOmlmeg8YEThGebdV1OHc7b8oCx4YGw2drCz2+0GmLbpNPcJaG124AJG/7r8ESCeuKjEGk8SvUbOnYViA/sFa1rRmK4812UBV/Jt2LbYPKwYFWG2ks4jv7OKQYpdogVge85ah+YtMic+oyRT5DKm7p1k6QfkBrdoSx1uaHSPi8rA0+To24TdFPN4KNyDq2fL4NMCZrMK+jOD3LdcBJTSsj9HM93jNGdMOkwf7F6STjACqTKUy5pzlYK17qix7sCkjzg2avIE00IV6f7FbDNFLSNFGEfC6+iSgkN8ViA== X-Exchange-Antispam-Report-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)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0146; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0146; X-Forefront-PRVS: 0417A3FFD2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(199003)(189002)(50466002)(54906002)(6666003)(8936002)(66066001)(4326008)(50226002)(48376002)(47776003)(53936002)(478600001)(25786009)(110136004)(189998001)(76176999)(42186005)(53416004)(5003940100001)(2351001)(68736007)(106356001)(105586002)(3846002)(6116002)(2950100002)(6916009)(2361001)(305945005)(36756003)(50986999)(5660300001)(33646002)(2906002)(101416001)(7736002)(97736004)(81166006)(6486002)(8676002)(81156014)(575784001)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0146; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0146; 23:luSgLZSuFPEdJdwVNJaKRV6h1jdORhVtp4F56SDtl?= =?us-ascii?Q?wHtH2p4QkvKQj9LEU+z8hdjQUXEv4MgVQqBkveZGr1Dl/r6G1sUQCIOiU5WA?= =?us-ascii?Q?i4M/H/Q6y9OS5baG73e+3N9w/O7UgRUhTNuZC5iwnHcS7V6KRm2i5VAQlD/b?= =?us-ascii?Q?oBYfd3tU+HgIyKMjR7SMUExUdUaUJX19OlyCnEI+zMOnyDXjHUzVehbXecUf?= =?us-ascii?Q?pOl1b/nlBkc8PtBbE7l60ow9QRxlNuTNXeBikQrYgY1zjUzreB9a+gnbEK94?= =?us-ascii?Q?yTbdp/zR4QoEXWWM7LcmJ3ItEfBNfS06Qf+i+x9QHRrqTmzYpTPEKAbaYZ+k?= =?us-ascii?Q?nLPuAFVIm4k/R/F+N8xz25zQNGZSYNSYIyExihwh612Ho/5AV8Wu8v9/SiLg?= =?us-ascii?Q?NgvAFSSWF7j2aLHbfNHMen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fcERwW2KB9FPfLiczY4/Gyk/uXXsYUV9s4r9+4q5jAUU+SkpcUghnzHl+d3WdFchBZRFR3OqXoRhnF6dC1KhUkNbnyXJ3P0B5ZQufKNCp+SO3VaMOo+sAYA4BAOXwxh/eGPlzrpA8KcS7iRuaUkoDSslPPw/YyAs51vafPj8oK2X+FwuY6bJzAjdZQY8g==; 5:iDEz3Qb9P73OJB3JyGOWOXn/lEFyEX55q3WlI4WBy1IE+vUH/fCnGfygB7BWnSLjskTNaWxoxQ2Sn7wVfv+AjE3kvB2VfjvAk3p4k8mQso12oKLufAPckLAUgsWHup2Up6HrDOKSYMx2lkfT4P99qg==; 24:JKPDnYR2o+9ThhPm+OIwECaCOQLSs3ScEkopQ4RoOwq+W71CQzU4fl3hKWHOItoU2ca6MK362B1GOjVDCW+m93DDE8VIozPICKCWczvmRVA=; 7:rOT/Cqbc0jXd8773QpYeFlT35ThGoqyKCsfodgRwSqLutM+f4KZzAmLLIipNUxxDdApuqdQS3rfHU3bJ8SOyVAczLGjl7EfHpO8yXgfDU36hQjlJKyrSV26EgYlbfeD9iwoqQimIAG3N1jBx2TmSE5hlpednO9fizhW6Yvy33iR3fMt5xA98f5ljY3C7mEDSDnHe1v611rP+OYsPjxApc1nBM951RW5eqSkWcPKj21k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 20:hB03j9bma1xWzUIIhnlQmaSLm5aDbYgtX+3a/m59SMQ4uiN4y+8j5QWtheaEdAOSGWFtx6taKhDmU57KVOOPp0kXFlRx7qsXXA7BUAt6ygTTWssM/IbaB61o6kwREA8Kb0tlRYplxJePCKDqQy1ZMeaV7PFQeBLbSQY/1m09sqAi/UIJQ5IyWK+Q48TFf9FFcyaiiH+Sk85ucaEqi42QL0Ux9Xv6hEuke/EiDrisUHGAad7OoepN01twTAO1zsDW X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2017 11:24:28.2907 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0146 Subject: [edk2] [PATCH 3/5] OvmfPkg/VirtioNetDxe: dynamically alloc transmit header 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: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A network packets are transmitted by placing them into a transmit queue, each packet is preceded by a VIRTIO_1_0_NET_REQ header. VirtioNetInitTx(), builds the header once and fills the vring descriptors with the system physical address of the VIRTIO_1_0_NET_REQ header. When device is behind the IOMMU, VirtioNet driver is required to provide the device address of VIRTIO_1_0_NET_REQ header. In this patch we dynamically allocate the header using AllocateSharedPages() and map with BusMasterCommonBuffer so that header can be accessed by both processor and the device. We could map it with BusMasterRead but since the header pointer is used after it was added into vring hence I choose to dynamically allocate and map it with BusMasterCommonBuffer to avoid the code complexity. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioNetDxe/VirtioNet.h | 3 +- OvmfPkg/VirtioNetDxe/Events.c | 6 ++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 65 +++++++++++++++++--- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +++ 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 7df51bd044f5..3efe95a735d8 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -94,7 +94,8 @@ typedef struct { UINT16 TxMaxPending; // VirtioNetInitTx UINT16 TxCurPending; // VirtioNetInitTx UINT16 *TxFreeStack; // VirtioNetInitTx - VIRTIO_1_0_NET_REQ TxSharedReq; // VirtioNetInitTx + VIRTIO_1_0_NET_REQ *TxSharedReq; // VirtioNetInitTx + VOID *TxSharedReqMap; // VirtioMapSharedBuffer UINT16 TxLastUsed; // VirtioNetInitTx } VNET_DEV; =20 diff --git a/OvmfPkg/VirtioNetDxe/Events.c b/OvmfPkg/VirtioNetDxe/Events.c index 0586a82cdf09..9366aa00a1b3 100644 --- a/OvmfPkg/VirtioNetDxe/Events.c +++ b/OvmfPkg/VirtioNetDxe/Events.c @@ -101,4 +101,10 @@ VirtioNetExitBoot ( // device is reset. // Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RxBufMap); + + // + // Unmap shared Tx request mapping so that hypervisor will not be able t= o get + // readable data after device is reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap); } diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 6052d40fc6cb..551820e30f36 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -18,6 +18,7 @@ **/ =20 #include +#include #include #include =20 @@ -151,8 +152,12 @@ VirtioNetInitTx ( IN OUT VNET_DEV *Dev ) { - UINTN TxSharedReqSize; - UINTN PktIdx; + UINTN TxSharedReqSize; + UINTN PktIdx; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS DeviceAddress; + UINT64 BufBaseShift; + VOID *TxSharedReqBuffer; =20 Dev->TxMaxPending =3D (UINT16) MIN (Dev->TxRing.QueueSize / 2, VNET_MAX_PENDING); @@ -164,24 +169,60 @@ VirtioNetInitTx ( } =20 // + // Allocate TxSharedReq header and map with BusMasterCommonBuffer so tha= t it + // can be accessed equally by both processor and device. + // + Status =3D Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + &TxSharedReqBuffer + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + TxSharedReqBuffer, + sizeof *(Dev->TxSharedReq), + &DeviceAddress, + &Dev->TxSharedReqMap + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeBuffer; + } + + Dev->TxSharedReq =3D TxSharedReqBuffer; + + BufBaseShift =3D (UINT64) (UINTN)Dev->TxSharedReq - (UINT64) DeviceAddre= ss; + + ZeroMem ((VOID *) Dev->TxSharedReq, sizeof *(Dev->TxSharedReq)); + + // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depend= s on // VIRTIO_NET_F_MRG_RXBUF, which we never negotiate. // TxSharedReqSize =3D (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0,= 0)) ? - sizeof Dev->TxSharedReq.V0_9_5 : - sizeof Dev->TxSharedReq; + sizeof ((Dev->TxSharedReq)->V0_9_5) : + sizeof *(Dev->TxSharedReq); =20 for (PktIdx =3D 0; PktIdx < Dev->TxMaxPending; ++PktIdx) { UINT16 DescIdx; + UINT64 Address; =20 DescIdx =3D (UINT16) (2 * PktIdx); Dev->TxFreeStack[PktIdx] =3D DescIdx; =20 + Address =3D (UINTN) Dev->TxSharedReq; + Address +=3D BufBaseShift; + // // For each possibly pending packet, lay out the descriptor for the co= mmon // (unmodified by the host) virtio-net request header. // - Dev->TxRing.Desc[DescIdx].Addr =3D (UINTN) &Dev->TxSharedReq; + Dev->TxRing.Desc[DescIdx].Addr =3D Address; Dev->TxRing.Desc[DescIdx].Len =3D (UINT32) TxSharedReqSize; Dev->TxRing.Desc[DescIdx].Flags =3D VRING_DESC_F_NEXT; Dev->TxRing.Desc[DescIdx].Next =3D (UINT16) (DescIdx + 1); @@ -196,13 +237,13 @@ VirtioNetInitTx ( // // virtio-0.9.5, Appendix C, Packet Transmission // - Dev->TxSharedReq.V0_9_5.Flags =3D 0; - Dev->TxSharedReq.V0_9_5.GsoType =3D VIRTIO_NET_HDR_GSO_NONE; + Dev->TxSharedReq->V0_9_5.Flags =3D 0; + Dev->TxSharedReq->V0_9_5.GsoType =3D VIRTIO_NET_HDR_GSO_NONE; =20 // // For VirtIo 1.0 only -- the field exists, but it is unused // - Dev->TxSharedReq.NumBuffers =3D 0; + Dev->TxSharedReq->NumBuffers =3D 0; =20 // // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device @@ -217,6 +258,14 @@ VirtioNetInitTx ( *Dev->TxRing.Avail.Flags =3D (UINT16) VRING_AVAIL_F_NO_INTERRUPT; =20 return EFI_SUCCESS; + +FreeBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + (VOID *) Dev->TxSharedReq + ); + return Status; } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 4c9d9ece0790..aeb9e6605f0d 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -54,5 +54,12 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap); + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + (VOID *) Dev->TxSharedReq + ); + FreePool (Dev->TxFreeStack); } --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 12:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504265082752271.8081755092188; Fri, 1 Sep 2017 04:24:42 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8883B21E7492D; Fri, 1 Sep 2017 04:21:48 -0700 (PDT) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0076.outbound.protection.outlook.com [104.47.40.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0980E21E62BBE for ; Fri, 1 Sep 2017 04:21:47 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Fri, 1 Sep 2017 11:24:29 +0000 X-Original-To: edk2-devel@lists.01.org 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=ubVfET7lFhfzEyhKst/snPd4ceW9zaXge4P0+2g6rGk=; b=RfgRtXOTiT653kWmIA7r3A8bIIHC0m/ivmYyNmpenaXGo19KbmG06jv1EL6FBLXCPT6TubWBmZ1RUqadML7uaYKLirzh+dLjRnsm492hS0hQQ1rP/LktKm/lZp8sMq4EigzaVph6/FG5FmM2e0V1oZUHTk0I8FdkzTbJSxXEr8s= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Fri, 1 Sep 2017 07:24:04 -0400 Message-Id: <1504265045-19008-5-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> References: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0012.namprd03.prod.outlook.com (10.168.230.150) To BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab6c561d-af9d-4b10-4394-08d4f12c0370 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:BY2PR12MB0146; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 3:Y/yCSXUymMMJEKXoDGGIVPIRpSqT/53yhlnSF7Ip5xgkm8dlyeeLVEtcq5H3Lw4EwaEaP1CkZeXD1yxH1numlxq6eNE8hYMKXQh+tCWGd9fqgbBuVF0za2E/kXGwxeSaAEaiq+DIYk82lKUP7QxZwd8cb/uHqpQfah5s/0iwly/ALR86cz43b28aAIWHrxSVY6kfUDOK8D/qMCVFVntWDBJpiCp2hzVrWXuQbKXLgr4YondER8NtugKsfrQfoBku; 25:bf9CeKEtFPCKFfVCkwxu48jIwUceMIneDPPSNHO0MBdbc3cLa6fx52ohspGsR+z4126eArhMw5tTJcyrnZBjOJV6CL+ty+sHrrY8Pzix7YQBe6tc/SrwdV/siacRWeQofLro+wjIdCA5rX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uyVbD06FU1in9VplsMTQHtJTjcDhsXq53mAmZjgyVtkgxDAQEHsPKNuHFN8A3T8M1qmL61dkshLO4B+/asTzOi+XHTEF2Rqc0VxDvlDTpWgWN6ned+J8fRW8GYfvTmsG2qJsxIeJLKTS0HkX9aCa0eQemdHtwamP6/WKdz0CLlVvmpPFJl/3BHT8JQPLCKd9Y3/RKgCLboqHDFkBEl2BYutr439MQfxXJoFRoyFagufmYhWpv1Ve1Ky8pzSQUkOq+o0Mo06ZxqI8TzlOv8u0o4vF1i+YqOTiYxmybSRLww= X-Exchange-Antispam-Report-Test: UriScan:(20558992708506)(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)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0146; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0146; X-Forefront-PRVS: 0417A3FFD2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(199003)(189002)(50466002)(54906002)(6666003)(8936002)(66066001)(4326008)(50226002)(48376002)(47776003)(53936002)(478600001)(25786009)(110136004)(189998001)(76176999)(42186005)(53416004)(5003940100001)(2351001)(68736007)(106356001)(105586002)(3846002)(6116002)(2950100002)(6916009)(2361001)(305945005)(36756003)(50986999)(5660300001)(33646002)(2906002)(101416001)(7736002)(97736004)(81166006)(6486002)(8676002)(81156014)(575784001)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0146; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0146; 23:adHX4Ttk14t2gQQRrgBn4rXFyA+444Dd3rIZ+c1fH?= =?us-ascii?Q?P5Z8b/lEw6/MbvoZ8exedL2BGjXYHs7V3kBa5k/9lGU82KaiSPSLjojzzVn6?= =?us-ascii?Q?nirpRlcAAtkah4ZBvKyflf6cDtOuiF1J2JK1YqR2TwilivmSRbUPBjHHSprg?= =?us-ascii?Q?oYgjd/yn8WseBzmCVTKYF4QmXKKCp90uo5omdvNX02NdfEmTS2w5d6Q1PAKj?= =?us-ascii?Q?gOYBJ7GssSUVOkwn36z+TwAQ4qqaRJS3WiK6MxWrYz4tNXuIWq+iJbmrHz2T?= =?us-ascii?Q?wl2+e8O/QJkTqhPPGdyDf0bKz5pyAzqu5aQ04aweGPzqY0efn3TtexuroC2h?= =?us-ascii?Q?JWn3rl0vjRlzqact58asolH5oP4/nV6L+mZFEpdVmWmuTU8a3vxDUH3g7OvS?= =?us-ascii?Q?o0vm5SZvg/2mxTJtiOk0lFDAplYv9rnDuJ4ziDebCvnSK9mMKktXIgKeST6X?= =?us-ascii?Q?z48ydt76Dqmc3FBEVsb7SNfNnn/Es4Qj7HFnvPT/rt5ZXws2oGEAMWbIlEFW?= =?us-ascii?Q?uXDTYDavsDDD3GoSaoVo+Rnhpxn3lqxPuTgy4ypXc/maOs3K8IZ3AmemUue9?= =?us-ascii?Q?hp6gtmEu5foN1a6RxiLWL7+c1LsuREQg4TIFreo0CVXB8Y4Ovwgk4K8ltn20?= =?us-ascii?Q?MRkFLD/YZWdXZtSeLA99YglkScHM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elAA3TXK79+RQrw9qhShRfK3dw==; 24:Ds93nu+69fC6rWG9Gee4FvJ3OCeK1YMjnUWqwia3irgHiHzOLER2w4+fDd8qjOKjonhE4SocEqabxx59I9T8SNfQLHgyJU4GxsvKCvmTxf4=; 7:59js3gJP6yqeFqp3pL2FYP6lP3XRX1rNUvJdxd3PuWNVZeNpJszHbp0vNglfI6YWw05EEeafGFuS1QJENsh5nf9EMYPc2iUGcUxAekCFkBrMwK/cQPIq/jr5pw+fQCCODl7yc/sEJpojcHqHfg5wF5PEFHzIQ5I38pHAjDyWyWBi7uTBkBa++oL9s4qVZeisOXvvW1V/TZlnzMDI1XS6vLIhs1y6CYvH3tJ4/lWDcf8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0146; 20:7NUsR4bHvEZ17XmCAQa439Z0gbpZUpEJvBYMT7iUA6a8nYr7LRWft92jnM7RbfU+Kly7mtq1mSjeAHNlMPts0censEmO5wWs36ZyToLKtiQIjA0sRKcBet3ifMPS4FnN0tH5kSum+VB1fkS4VHrKU/FhMyd72A3SytLyY75USO1eEZtMzKwIPfxMdeM8LWXilm3BHZOAGC0oXsQn4DeGF42NTd5a/QckkHPSSXjPHu4E2o8/UpzM7T8TCSjyXF6c X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2017 11:24:29.5407 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0146 Subject: [edk2] [PATCH 4/5] OvmfPkg/VirtioNetDxe: map virtio-net transmit request buffer 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: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When device is behind the IOMMU, driver is require to pass the device address of transmit buffer for the bus master operations. The patch uses VirtioMapAllBytesInSharedBuffer() to map transmit buffer system physical address to the device address. Since the transmit buffers are returned back to caller in VirtioNetGetStatus() hence we use OrderCollection library interface to save the host to device address mapping. After the buffer is succesfully transmited we do reverse lookup in OrderCollection data structure to get the host address for the transmitted device address. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioNetDxe/VirtioNet.inf | 1 + OvmfPkg/VirtioNetDxe/VirtioNet.h | 19 +++ OvmfPkg/VirtioNetDxe/SnpGetStatus.c | 30 +++- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 157 ++++++++++++++++++++ OvmfPkg/VirtioNetDxe/SnpTransmit.c | 37 ++++- 5 files changed, 232 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.inf b/OvmfPkg/VirtioNetDxe/Virt= ioNet.inf index a855ad4ac154..9ff6d87e6190 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.inf +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.inf @@ -49,6 +49,7 @@ [LibraryClasses] DebugLib DevicePathLib MemoryAllocationLib + OrderedCollectionLib UefiBootServicesTableLib UefiDriverEntryPoint UefiLib diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 3efe95a735d8..d931969af795 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -269,6 +269,25 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ); =20 +EFI_STATUS +EFIAPI +VirtioMapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 Index, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ); + +EFI_STATUS +EFIAPI +VirtioUnmapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 Index, + OUT EFI_PHYSICAL_ADDRESS *HostAddress, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ); + // // event callbacks // diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/Snp= GetStatus.c index 694940ea1d97..10ca26de6d7a 100644 --- a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c +++ b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c @@ -5,6 +5,7 @@ =20 Copyright (C) 2013, Red Hat, Inc. Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2017, AMD Inc, All rights reserved.
=20 This program and the accompanying materials are licensed and made availa= ble under the terms and conditions of the BSD License which accompanies this @@ -47,7 +48,8 @@ @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value. @retval EFI_DEVICE_ERROR The command could not be sent to the netwo= rk - interface. + interface or failed to map TxBuf to bus ma= ster + address. @retval EFI_UNSUPPORTED This function is not supported by the netw= ork interface. =20 @@ -126,8 +128,10 @@ VirtioNetGetStatus ( *TxBuf =3D NULL; } else { - UINT16 UsedElemIdx; - UINT32 DescIdx; + UINT16 UsedElemIdx; + UINT32 DescIdx; + EFI_PHYSICAL_ADDRESS BufferAddress; + EFI_PHYSICAL_ADDRESS DeviceAddress; =20 // // fetch the first descriptor among those that the hypervisor reports @@ -141,9 +145,27 @@ VirtioNetGetStatus ( ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1)); =20 // + // Ring descriptor contains the device address for the caller buffer. + // Lets unmap the device address and find its corresponding system + // physical address. + // + DeviceAddress =3D Dev->TxRing.Desc[DescIdx + 1].Addr; + Status =3D VirtioUnmapTxBuf ( + Dev, + DescIdx + 1, + &BufferAddress, + DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto Exit; + } + + // + // // report buffer address to caller that has been enqueued by caller // - *TxBuf =3D (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr; + *TxBuf =3D (VOID *)(UINTN) BufferAddress; =20 // // now this descriptor can be used again to enqueue a transmit buffer diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index aeb9e6605f0d..b91ddd3e4ede 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -14,10 +14,25 @@ =20 **/ =20 +#include #include +#include =20 #include "VirtioNet.h" =20 +typedef struct { + UINT16 Value; +} USER_KEY; + +typedef struct { + USER_KEY Key; + EFI_PHYSICAL_ADDRESS HostAddress; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *BufMap; +} USER_STRUCT; + +STATIC ORDERED_COLLECTION *Collection; + /** Release RX and TX resources on the boundary of the EfiSimpleNetworkInitialized state. @@ -63,3 +78,145 @@ VirtioNetShutdownTx ( =20 FreePool (Dev->TxFreeStack); } + +STATIC +INTN +EFIAPI +KeyCompare ( + IN CONST VOID *StandaloneKey, + IN CONST VOID *UserStruct + ) +{ + CONST USER_KEY *CmpKey; + CONST USER_STRUCT *CmpStruct; + + CmpKey =3D StandaloneKey; + CmpStruct =3D UserStruct; + + return CmpKey->Value < CmpStruct->Key.Value ? -1 : + CmpKey->Value > CmpStruct->Key.Value ? 1 : + 0; +} + +STATIC +INTN +EFIAPI +UserStructCompare ( + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ) +{ + CONST USER_STRUCT *CmpStruct1; + + CmpStruct1 =3D UserStruct1; + + return KeyCompare (&CmpStruct1->Key, UserStruct2); +} + +EFI_STATUS +EFIAPI +VirtioMapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 Index, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ) +{ + EFI_STATUS Status; + ORDERED_COLLECTION_ENTRY *Entry; + USER_STRUCT *UserStruct; + EFI_PHYSICAL_ADDRESS Address; + VOID *Mapping; + + // + // If ordered collection is not initialized then initialize it. + // + if (Collection =3D=3D NULL) { + Collection =3D OrderedCollectionInit (UserStructCompare, KeyCompare); + if (Collection =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + } + + UserStruct =3D AllocatePool (sizeof (*UserStruct)); + if (UserStruct =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + (VOID *) (UINTN) HostAddress, + NumberOfBytes, + &Address, + &Mapping + ); + if (EFI_ERROR (Status)) { + goto ReleaseUserStruct; + } + + UserStruct->Key.Value =3D Index; + UserStruct->HostAddress =3D HostAddress; + UserStruct->DeviceAddress =3D Address; + UserStruct->BufMap =3D Mapping; + + Status =3D OrderedCollectionInsert (Collection, &Entry, UserStruct); + switch (Status) { + case RETURN_OUT_OF_RESOURCES: + Status =3D EFI_OUT_OF_RESOURCES; + goto UnmapBuffer; + case RETURN_ALREADY_STARTED: + Status =3D EFI_INVALID_PARAMETER; + goto UnmapBuffer; + default: + ASSERT (Status =3D=3D RETURN_SUCCESS); + break; + } + + ASSERT (OrderedCollectionUserStruct (Entry) =3D=3D UserStruct); + + *DeviceAddress =3D Address; + return EFI_SUCCESS; + +UnmapBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping); + +ReleaseUserStruct: + FreePool (UserStruct); + return Status; +} + +EFI_STATUS +EFIAPI +VirtioUnmapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 Index, + OUT EFI_PHYSICAL_ADDRESS *HostAddress, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ) +{ + USER_KEY StandaloneKey; + ORDERED_COLLECTION_ENTRY *Entry; + USER_STRUCT *UserStruct; + VOID *Ptr; + EFI_STATUS Status; + + StandaloneKey.Value =3D Index; + Entry =3D OrderedCollectionFind (Collection, &StandaloneKey); + if (Entry =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + OrderedCollectionDelete (Collection, Entry, &Ptr); + + UserStruct =3D Ptr; + ASSERT (UserStruct->DeviceAddress =3D=3D DeviceAddress); + ASSERT (UserStruct->Key.Value =3D=3D Index); + + *HostAddress =3D UserStruct->HostAddress; + Status =3D Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, UserStruct->BufM= ap); + FreePool (UserStruct); + + return Status; +} diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpT= ransmit.c index 7ca40d5d0650..1bd6e0d70d7c 100644 --- a/OvmfPkg/VirtioNetDxe/SnpTransmit.c +++ b/OvmfPkg/VirtioNetDxe/SnpTransmit.c @@ -55,7 +55,8 @@ @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value. @retval EFI_DEVICE_ERROR The command could not be sent to the netwo= rk - interface. + interface or failed to map the Buffer to + bus master address. @retval EFI_UNSUPPORTED This function is not supported by the netw= ork interface. =20 @@ -73,11 +74,12 @@ VirtioNetTransmit ( IN UINT16 *Protocol OPTIONAL ) { - VNET_DEV *Dev; - EFI_TPL OldTpl; - EFI_STATUS Status; - UINT16 DescIdx; - UINT16 AvailIdx; + VNET_DEV *Dev; + EFI_TPL OldTpl; + EFI_STATUS Status; + UINT16 DescIdx; + UINT16 AvailIdx; + EFI_PHYSICAL_ADDRESS DeviceAddress; =20 if (This =3D=3D NULL || BufferSize =3D=3D 0 || Buffer =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -144,10 +146,29 @@ VirtioNetTransmit ( } =20 // - // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device + // Get the available descriptor // DescIdx =3D Dev->TxFreeStack[Dev->TxCurPending++]; - Dev->TxRing.Desc[DescIdx + 1].Addr =3D (UINTN) Buffer; + + // + // Map the transmit buffer system physical address to device address. + // + Status =3D VirtioMapTxBuf ( + Dev, + DescIdx + 1, + (EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, + BufferSize, + &DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto Exit; + } + + // + // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device + // + Dev->TxRing.Desc[DescIdx + 1].Addr =3D DeviceAddress; Dev->TxRing.Desc[DescIdx + 1].Len =3D (UINT32) BufferSize; =20 // --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 12:07:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1504265085768986.3446460833671; Fri, 1 Sep 2017 04:24:45 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C1AAB21E7493B; Fri, 1 Sep 2017 04:21:48 -0700 (PDT) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0046.outbound.protection.outlook.com [104.47.34.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 0592421E7492D for ; Fri, 1 Sep 2017 04:21:48 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Fri, 1 Sep 2017 11:24:30 +0000 X-Original-To: edk2-devel@lists.01.org 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=BeqRE7ZmS0syXPzrI2D8bJdZxBd3ewkOXDaytC+2O+g=; b=GOXCbYueRnujM4eLThWYKCVGOId7RRGt58nfI/uBDKgoSl9t0G3dXmYXV3n09gaiah7JIKBkYzr1uf4y6s5Sy0CtZRUViAcQU4h/2ebh90wzPBTBbrW7WpmZldGQ5fJaWJLqL3/MB3yvD6QpI5kaWffzXezebs2e2RUpr3gD7TA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Fri, 1 Sep 2017 07:24:05 -0400 Message-Id: <1504265045-19008-6-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> References: <1504265045-19008-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR03CA0012.namprd03.prod.outlook.com (10.168.230.150) To BY2PR12MB0146.namprd12.prod.outlook.com (10.162.82.19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b2029ce-053e-4ca7-ffed-08d4f12c042e 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:BY2PR12MB0146; X-Microsoft-Exchange-Diagnostics: 1;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b0quyvkx8SW9nP7UGdIkOjiiBc1OsFgs5M2Bz0NwWXItqfjrnI/8t1AhVbZFSExunxgmNMxz9jHIZL+kVQSfrmcJ433l1SWuo4n2YCU1Di2JetNUa+Xf7/t17XbhA91U1dMh/XAgkhtJVpdhxusSaD+Df1g5l7rrT5D/MNkJxb4Kg2ZY+48XQDW2opBd2w3K/bQ00zPyZXRxWsvrFk7fezw1Y8n1tO+jiTKjV9ug7uajWL/f4vlYTXAh9BIObZgzjYPkK6rRfXDPtAchcfiFSRFCLDx2nQjwRckiyofijYYdBBwGq8g0bfcIr7M/EvTgoBxV5VNBLeyBxCjUyz0XHeYXnJKAxyLHviABBUFoLLkq/FITb3VTW4BB98W7YYPjfWQICS; 4:he6akHbfngXxS7/fBuapdGWH67ffAAK3a4wLBlhh5RtT0S20NrbSgFpE85ULGxS91WJpovY0Kj9LBXsd5dwempG//k1sLHCesCafCzCWWsWCLL2eZAQcilCzg3o6UeAO8jHuOmo3/VUHhv7prITyx0vBQTThBjCxFSBhqS1kvxu6mbGBC9034vvzdSRccq6teCqXB098RbshS8/GW8+Ms5QGL5nBRUyrRpDajlKmFiNeFeOvT0bcXHYcPaA93JO5lK8lVDAkJ2q2bUSe4fuY++tZnxcx8gi/U4AcC1F8OnQmRjetnHMkCWfPGfKTjO2upOrPevExgNy2UToyF/6dhQ== X-Exchange-Antispam-Report-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)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123560025)(20161123562025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BY2PR12MB0146; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BY2PR12MB0146; X-Forefront-PRVS: 0417A3FFD2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(199003)(189002)(50466002)(54906002)(6666003)(8936002)(66066001)(4326008)(50226002)(48376002)(47776003)(53936002)(478600001)(25786009)(110136004)(189998001)(76176999)(42186005)(53416004)(5003940100001)(2351001)(68736007)(106356001)(105586002)(3846002)(6116002)(2950100002)(6916009)(2361001)(305945005)(36756003)(50986999)(5660300001)(33646002)(2906002)(101416001)(7736002)(97736004)(81166006)(6486002)(8676002)(81156014)(86362001)(344415003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0146; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0146; 23:jQuZLtyhKnt3HE20BM7W7RBxttiu8RX3J7/sMO/kW?= =?us-ascii?Q?saT/4c+XXxMiT0i7WPVUGSztYigYjpkm9DTPJDJxt6sMH3cgl8DfiTP1d+Gy?= =?us-ascii?Q?pQsUn7T2EbpvrVRaohURweWsl1jsMu71JOrjZbiCDqHyAFlmRHYq1KTDp/C1?= =?us-ascii?Q?J1ZFpxs4coAYZ7aQiHSZCmDga1av1+OBI2rd9JtgDwxwZQ2mLIMyC12IYgyz?= =?us-ascii?Q?303HKwbtNZLbk1lk2K9V9ZQSioDCnQ0TtxAdfUmEdZCZ9wvcrZAfLUy/gbW4?= =?us-ascii?Q?XtAjYk3xVxTcbeplqUOdZBxmL6TWjIVWL3cVVMxH8qAmcTFkff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BjeJIwLRqBRpfij7IldwvC4uwZqugYQY9ghdokT/Vqttv/YTOtXJBH5zbIQRuKkSc2hNNzYjuTTPq7FdVh/mVep+AY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2017 11:24:30.7907 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0146 Subject: [edk2] [PATCH 5/5] OvmfPkg/VirtioNetDxe: negotiate VIRTIO_F_IOMMU_PLATFORM 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: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" VirtioNetDxe driver has been updated to use IOMMU-like member functions from VIRTIO_DEVICE_PROTOCOL to translate the system physical address to device address. We do not need to do anything special when VIRTIO_F_IOMMU_PLATFORM bit is present hence treat it in parallel with VIRTIO_F_VERSION_1. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Brijesh Singh Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 551820e30f36..dded19b25dd2 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -550,7 +550,8 @@ VirtioNetInitialize ( ASSERT (Dev->Snm.MediaPresentSupported =3D=3D !!(Features & VIRTIO_NET_F_STATUS)); =20 - Features &=3D VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS | VIRTIO_F_VERSION_= 1; + Features &=3D VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS | VIRTIO_F_VERSION_= 1 | + VIRTIO_F_IOMMU_PLATFORM; =20 // // In virtio-1.0, feature negotiation is expected to complete before que= ue @@ -590,7 +591,7 @@ VirtioNetInitialize ( // step 5 -- keep only the features we want // if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) { - Features &=3D ~(UINT64)VIRTIO_F_VERSION_1; + Features &=3D ~(UINT64)(VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM); Status =3D Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { goto ReleaseTxRing; --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel