From nobody Thu Dec 26 01:57:47 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 1505132234857907.7864895723786; Mon, 11 Sep 2017 05:17:14 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B162521CEB0EA; Mon, 11 Sep 2017 05:14:16 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0073.outbound.protection.outlook.com [104.47.38.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7ABAC2095BB98 for ; Mon, 11 Sep 2017 05:14:15 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:08 +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=MpR5RcKBSm2mbrshc4QcF6KhR6etzb8b7Zdp4GuY7h0=; b=3tj7blApjZbN7HBbP7M6Sdp8Z0BR6mZRgX2RRottDDXyXckKBl9+Pbd6ShsOFBZ9aVasX4ZUpuCqKRDbkF02Eg/5/jO3htcGkZ9qvNfvkZd20YdbDx9w3/WN7JgpLdrAy+ti6jd2Ax7WqJN26nWd84rpMrLxghBjuU59YUdac5w= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:50 -0500 Message-Id: <20170911121657.34992-2-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4bb8f97-b704-43a5-d396-08d4f90f062e 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:ALoUPRZPC/wudyAjhK0bwKueCnEteNJK79oEgVYG06QQHe+DpW3t0Qp04ORPbQN18/NMtuCzrWErnPa48q6xn7N1B4y/DG7CSeMZ7u/9MX5lnRyNGUULEtx5cv3GqUSAp/lk2A84QtIFXJg/68hu+z3cq5rQ+SNE2YEvC9/sueiXXwba6IPJPqNKuGd2oUPaxWymkYWwwa0DF8mupQeI1gAc4Msp6mf27eyoE2rTcvB+h2rj+d2pcTW54nYMy7fJ; 25:xEarkUNekUqdfdAvneFddc+ZgIpA9DIeGRu0zC8fAsV/loGIcIjAk5lHpknNNfYLS90w4ThnVfCbni3gL8GabGY6R62LqSIkw/TLBB872/a793XT+reRgzM7U88noiyb92CBbahQWLNREwijH/4Sf5trCbOR/D3J0/esn0BYh5wfAWB0OSTn26FqnU/BMtgiG+8Wfw37SqhhpsH/8gGT+IxOLM8FutR2VgM2a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5/Cvs1Cxo63W4FMfbwiiCzEzd27mVt7xz0AKqYbmIdA9sjdrJmNruaBjEe6dntc1znfXiVF7HE3YpwQus7POdA7GP++wBAlRtqAGhLMyFswtRujPC6Vn02q92vj9ay3NU7iqSPCBCyBJVZKbvcKAd5WpF46+gYtsIEBFlrabZwoLUbJruwCrpqBy0nEbrsd6ebKYtI7Yqm7D4+kD8Q== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(575784001)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:7YGJhv6B0bvKoiEv6zt0krdRBWcXLXfTZACtf3jsM?= =?us-ascii?Q?w2oRytX+WuWIFtyAviTpiv5f/KyZuYO4zF2WLidOzUUTeNjiv0oMthsLyRTQ?= =?us-ascii?Q?mDJOtvJm01Z+OFXQd6I2P588d8GARNC5IQf/SSQBS9EhPsVzaCQ8nvmTDOKD?= =?us-ascii?Q?2Jp10SP+orGLib3tFmjzHVHujzuFEiOe2xI4AeWEMu5PPe0mnzM1zu2fE/LJ?= =?us-ascii?Q?t6QmANfexy7KEaWESha8e2nyt1fSjYNwHBhc5Swb30Wmdjnfr5ia6ZsyVSZH?= =?us-ascii?Q?rugpKmeR3OSgDujkcsKh4YNcquyBuulIjPr/KRsB+aCU0vHXBUi6FjrbzwWX?= =?us-ascii?Q?roeVysJiUsHYMK2mmnut13fo/RpATRRzl0VS03OoKsE/dugxBVgEKmt9HW+z?= =?us-ascii?Q?bRqSdIpr6Q5HvYEC/JGZLMJDK3fKl0s1MMJOOoyMcK9pSnnYyGe4Hcuk0Xid?= =?us-ascii?Q?KRVJZ0ZSeovLf5vuMzJIfN0VjR7S4xcWep3e1mg1Gn/xbmmWHBQvVXDqr8cm?= =?us-ascii?Q?IkVTefi8w9W0ieENtNwx9NQFgHcKDqgPnQH3bfNDknL0+DD4mTweh/PkTVKt?= =?us-ascii?Q?wl3UbpQ8ySdgc6bde7wmt6YsGfa4jQddm+kxwUuGhMt29jzvt32s4bXNR9fJ?= =?us-ascii?Q?jE+xf5AhNfsKRBh842Hru6OQfNA65gLqbhg4ZgizDolTUgVqm/YpL7/K1tBF?= =?us-ascii?Q?T+eWuwbHDL71jBLKc2c1BUpvrTHhDycbxoQbf3TrHRVIbDLTGpAjXzUc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GrZWDn7zB8GdZ2drY5AZvk=; 7:cElev+3rco+BtRWZmhYOhJ+RF55iYqx+gtRh0zg3bWczb6Wj7JPGsrzY1A26EJ7oHkdai7OY1XIubwJP84ylpfP9VokkEqPfCd5k6qTJcZUZIHxjuVxr5HBMBXgWzLUmkQBvsQA8b//8omdB6Kb3Mv51CGvOZkWPetQ1Bsu1nxLYBn958aRespaAjOjXJgJmc7ugz/Hddts0Dp+ptp/tD3T/3ZaHDlEys5QOvjlYaVo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:0FKuMI58tXnpL7fN7AH4q/54ywXKpS9NKGzucBEAotsbqn+NFiHfsGL+AeBb+Zq98CeQzZDV1/i1TpWpZIFwQdfn77QLBj0iFlwc6juKxDxhwz/0JyH46reJvAK5GX0+zJ+rWM5kPvSphyQhwTPBr+ccGkAxxJ9drGYzSUrrrmaKqvv2qT4V6gMxI3n+1wTV4qDrx2uezEG5hT/v5WkO5qekO/Jwh8jc0iM6h/AvINxbhM1InZpKs439SPchP09Y X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:08.5890 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 1/8] OvmfPkg/VirtioNetDxe: add helper VirtioNetUninitRing() 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 , Brijesh Singh , 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" Consolidate the virtio VRING resource cleanup into VirtioNetUninitRing(). 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/VirtioNet.h | 7 +++++++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 4 ++-- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 16 ++++++++++++++++ OvmfPkg/VirtioNetDxe/SnpShutdown.c | 4 ++-- OvmfPkg/VirtioNetDxe/TechNotes.txt | 5 +++-- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 710859bc6115..87a0f06e01a4 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -263,6 +263,13 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ); =20 +VOID +EFIAPI +VirtioNetUninitRing ( + IN OUT VNET_DEV *Dev, + IN OUT VRING *Ring + ); + // // event callbacks // diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 0ecfe044a977..637c978709fd 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -510,10 +510,10 @@ AbortDevice: Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); =20 ReleaseTxRing: - VirtioRingUninit (Dev->VirtIo, &Dev->TxRing); + VirtioNetUninitRing (Dev, &Dev->TxRing); =20 ReleaseRxRing: - VirtioRingUninit (Dev->VirtIo, &Dev->RxRing); + VirtioNetUninitRing (Dev, &Dev->RxRing); =20 DeviceFailed: // diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 9fedb72fdbd4..5b75eabc7a6b 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -51,3 +51,19 @@ VirtioNetShutdownTx ( { FreePool (Dev->TxFreeStack); } + +/** + Release TX and RX VRING resources. + + @param[in,out] Dev The VNET_DEV driver instance which was using the ri= ng. + @param[in,out] Ring The virtio ring to clean up. +*/ +VOID +EFIAPI +VirtioNetUninitRing ( + IN OUT VNET_DEV *Dev, + IN OUT VRING *Ring + ) +{ + VirtioRingUninit (Dev->VirtIo, Ring); +} diff --git a/OvmfPkg/VirtioNetDxe/SnpShutdown.c b/OvmfPkg/VirtioNetDxe/SnpS= hutdown.c index 5e84191fbbdd..432e0691d457 100644 --- a/OvmfPkg/VirtioNetDxe/SnpShutdown.c +++ b/OvmfPkg/VirtioNetDxe/SnpShutdown.c @@ -67,8 +67,8 @@ VirtioNetShutdown ( Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); VirtioNetShutdownRx (Dev); VirtioNetShutdownTx (Dev); - VirtioRingUninit (Dev->VirtIo, &Dev->TxRing); - VirtioRingUninit (Dev->VirtIo, &Dev->RxRing); + VirtioNetUninitRing (Dev, &Dev->TxRing); + VirtioNetUninitRing (Dev, &Dev->RxRing); =20 Dev->Snm.State =3D EfiSimpleNetworkStarted; Status =3D EFI_SUCCESS; diff --git a/OvmfPkg/VirtioNetDxe/TechNotes.txt b/OvmfPkg/VirtioNetDxe/Tech= Notes.txt index 9c1dfe6a773e..86b91f561495 100644 --- a/OvmfPkg/VirtioNetDxe/TechNotes.txt +++ b/OvmfPkg/VirtioNetDxe/TechNotes.txt @@ -70,8 +70,9 @@ faithfully indented) that implement the transition. VirtioNetInitialize | | VirtioNetShutdown VirtioNetInitRing {Rx, Tx} | | VirtioNetShutdownRx [SnpSharedHelper= s.c] VirtioRingInit | | VirtioNetShutdownTx [SnpSharedHelper= s.c] - VirtioNetInitTx | | VirtioRingUninit {Tx, Rx} - VirtioNetInitRx | | + VirtioNetInitTx | | VirtioNetUninitRing [SnpSharedHelper= s.c] + VirtioNetInitRx | | {Tx, Rx} + | | VirtioRingUninit v | +-----------------------------+ | EfiSimpleNetworkInitialized | --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132237638293.51326935048576; Mon, 11 Sep 2017 05:17:17 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F303121CEB0F2; Mon, 11 Sep 2017 05:14:16 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0073.outbound.protection.outlook.com [104.47.38.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D8C8C20958BEA for ; Mon, 11 Sep 2017 05:14:15 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:09 +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=gxRU5ilyH3afpym9iFEOlCHuxLNmQZ3iHspEUwKc7DY=; b=byTaDmC8ByDL2u8dB6h6skaSnjdFKAtDHQ+bklNPSYukBWApXzatJtnyKl5/DPcjarXhToFEb4YR6ETqv6UsKvYphlgleAq7dhj+MTQu7z1jPFUTvrHQ1WX1KmqC8e5nyw8RgfWrAJgA1NOsvENtZVm/8HUAZJuq3rSYjgpvxwY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:51 -0500 Message-Id: <20170911121657.34992-3-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b31f1b7-b0da-4388-93d5-08d4f90f0690 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:D3S8BcG/e4POuxhaiM7FzCJOfWrPhheNOYc3SHQ5OI2IyqjX5G2T8F+VyjORZqdJcWlx/knrAR4dOAY46oK9exTX3MTAMQJhUM+ZsFpCO6gtzP73pOluJDleuC0rTqPG2eZCIMj7e+X2zJB433uIroXwioRA8EXa0VQQJNE5lfA+eChwZgITD0fokeTHOUFg8sQtXg1YG9vkQWJAkeywA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5ckK8jiC8jIrehC8m6P6davcfrLWc0MDHJFXJiXWH8OM9bvcOPr7UzcGTtgAOmUOXkTAOkO9MpqRaTpUwAYePWszvj9NosUXfBRiofoRZF6dN92rDDJL3ryY5BnwOzxi; 4:R9TFRGpMb3rCbV9lFkI5PTDQxukxCu8I9k2gwNhxx+hOru8vQghzRhcCn/yDkTiLj/c6NSDny316eTt3V3Ml0zZmum5cW8Z8EYrqkqMMtIrrJ1fV90sxQ+CxBYWn5WGWTI2r1vfedNM2weN5kcKa55vCAJozziHL/JrvEZ0L1FdToACnJ1KQ4UdSdsiT1NqI1ERTt4I1kYmu7z3dtzu1eiCfetVMx2E807At1nBB55BC+FM1b1MC8dVtxNogN67zTY0DVjC4J4SdqmvZxOJbJQcVniFdO3cQM1nI+7PtDwFwycK5oeo5naZqSgMz/T1tnGV2/AfihIwIsUvJd+9kLzHTlRuum7l9sJ9VjOkp0DQ= 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(51234002)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(575784001)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:GJoGkYMSYUrE3JAxtRU1BQLJ/HuIanQf1Sxsz/csQ?= =?us-ascii?Q?l1q8OM0ajU23UXtC/bRjc692NELiw45pA70s1U+p8hrSjWF9uBkjfFT7ec7c?= =?us-ascii?Q?EfVW2sawITVacpUbyUbMGYaj+js9xD1cp2XaBjZzRfmiYrXKbAgR7vR/Fw5d?= =?us-ascii?Q?OeOURTnvOuVA6iCFgKrKJ3t8w1k4Z0kEYTR9LZWXiUrNqF+4SptRn+i6Ojvq?= =?us-ascii?Q?apwEmDWeM2ihfYmBM1C2p/gG/0LGECkL9zZuCvLSY1hD4cZ4D+h6qQ2OZg6A?= =?us-ascii?Q?e11VG7F1FoaqcgwhBFMR13i5Ktz1txH9bAOWsImLEsa7qp75Z9BC8cPHF32r?= =?us-ascii?Q?jDGEkL2QiMbK2GQFNUjAmh6f4TzMd7ILkDN4gnaPeDID+kFNjysy/DKki+wg?= =?us-ascii?Q?HqZQXTyckHSF9dUQeMM96SuQCHkz/qWf3IHj6EjQrG1BPvjjRY0uSQDilRYX?= =?us-ascii?Q?EiwmYE8Vphb8KYcgSUJFDp3/i+JGegbrOZgUuo+/vzExrdSurxmCbstD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lGZ2UFEqEyIUIBxEIcqM6AcaAUWa7tljRN42YqIiWdjDYX/3l5dfAy3TjWGsF0gUIxgV4Um2UF8QsFcQnzIzxhwPR9I8Q==; 5:SeiWj+IDZ9B7hM6/7LICkmEkDAhbTfYyjwxuchFCO2DVnAY6H4ToBuQtUwCvlB1szSj+U8kNy487rQXYYNbmh/hZNy4Hq2qb3hnzuIG+KyCo9KvZq1yeSfuzdSLxqsj/RdtqsnDA8mx64d3+JsKyKw==; 24:k+unxykSKTrttfxPu/75UrN+z/wFtNcLhUS8ggVckgYa6DJLE5FfNpwAaK5nl3lvg1QwSzB0EqemmVZojMQExl68T8MJqvvOtfnHX6HJ3v0=; 7:uXmhe3GmI1ckRPfKBisPYE3RTPFDRmAZIP0+s1z+PLrYJYm1DqL7x49Q2VVc3eeAr1SSd6twTEs37jTyDn9k/SxvYWoaJ4jLeDQL/w5xwittyHXL02ufeghUxj0kbF6yTN0yTG3LmFNt5JU90o/UTbhP6FoxyJt8ca6RSzaUIvx2sFj2AaZMEzHZnE9qo/gCJj940YLkBrSVcpTO0vb3EhByUYmHflR0OCsa/rYK9S8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:MD/tFYATvKaZiBvgxgeB4UNk+fAX/k9lPBEOVkVIosacBZqHHZz/3eAZxyh6ofC140VJQ3qTrJma13xHTdeOhgFbxTOiik/GJ6n8JCMpuEDV097lG92f69YwSQSaHXHojSNs+YQcPynCgDuF8wbwvxFjCn9zId5dRCN3ujAE2hpyL2kUeBkfo+ZlRg4Ypdvng9QbaVIAqPHDDKuU0B3F5JrIZ476xzrnS2iQFBOj2iT+Z+4juEuk1fHvMIO6SLUa X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:09.2296 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 2/8] OvmfPkg/VirtioNetDxe: map VRINGs 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 , Brijesh Singh , 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[es] to device address[es]. 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 | 7 ++- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 50 +++++++++++++++----- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 10 ++-- OvmfPkg/VirtioNetDxe/SnpShutdown.c | 4 +- OvmfPkg/VirtioNetDxe/TechNotes.txt | 1 + 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 87a0f06e01a4..6762fc9d1d6e 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -82,10 +82,14 @@ typedef struct { EFI_HANDLE MacHandle; // VirtioNetDriverBinding= Start =20 VRING RxRing; // VirtioNetInitRing + VOID *RxRingMap; // VirtioRingMap and + // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx =20 VRING TxRing; // VirtioNetInitRing + VOID *TxRingMap; // VirtioRingMap and + // VirtioNetInitRing UINT16 TxMaxPending; // VirtioNetInitTx UINT16 TxCurPending; // VirtioNetInitTx UINT16 *TxFreeStack; // VirtioNetInitTx @@ -267,7 +271,8 @@ VOID EFIAPI VirtioNetUninitRing ( IN OUT VNET_DEV *Dev, - IN OUT VRING *Ring + IN OUT VRING *Ring, + IN VOID *RingMap ); =20 // diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 637c978709fd..8eabdbff6f5e 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 resulting token to pass to VirtioNetUninitRin= g() =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,14 @@ 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; + VOID *MapInfo; =20 // // step 4b -- allocate selected queue @@ -80,29 +85,42 @@ VirtioNetInitRing ( } =20 // + // If anything fails from here on, we must release the ring resources. + // + Status =3D VirtioRingMap (Dev->VirtIo, Ring, &RingBaseShift, &MapInfo); + 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. + // size. If anything fails from here on, we must unmap the ring resource= s. // 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 + *Mapping =3D MapInfo; + return EFI_SUCCESS; =20 +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, MapInfo); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, Ring); =20 @@ -456,12 +474,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,10 +538,10 @@ AbortDevice: Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); =20 ReleaseTxRing: - VirtioNetUninitRing (Dev, &Dev->TxRing); + VirtioNetUninitRing (Dev, &Dev->TxRing, Dev->TxRingMap); =20 ReleaseRxRing: - VirtioNetUninitRing (Dev, &Dev->RxRing); + VirtioNetUninitRing (Dev, &Dev->RxRing, Dev->RxRingMap); =20 DeviceFailed: // diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 5b75eabc7a6b..57c7395848bd 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -55,15 +55,19 @@ VirtioNetShutdownTx ( /** Release TX and RX VRING resources. =20 - @param[in,out] Dev The VNET_DEV driver instance which was using the ri= ng. - @param[in,out] Ring The virtio ring to clean up. + @param[in,out] Dev The VNET_DEV driver instance which was using + the ring. + @param[in,out] Ring The virtio ring to clean up. + @param[in] RingMap A token return from the VirtioRingMap() */ VOID EFIAPI VirtioNetUninitRing ( IN OUT VNET_DEV *Dev, - IN OUT VRING *Ring + IN OUT VRING *Ring, + IN VOID *RingMap ) { + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, RingMap); VirtioRingUninit (Dev->VirtIo, Ring); } diff --git a/OvmfPkg/VirtioNetDxe/SnpShutdown.c b/OvmfPkg/VirtioNetDxe/SnpS= hutdown.c index 432e0691d457..d8c11f20de61 100644 --- a/OvmfPkg/VirtioNetDxe/SnpShutdown.c +++ b/OvmfPkg/VirtioNetDxe/SnpShutdown.c @@ -67,8 +67,8 @@ VirtioNetShutdown ( Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); VirtioNetShutdownRx (Dev); VirtioNetShutdownTx (Dev); - VirtioNetUninitRing (Dev, &Dev->TxRing); - VirtioNetUninitRing (Dev, &Dev->RxRing); + VirtioNetUninitRing (Dev, &Dev->TxRing, Dev->TxRingMap); + VirtioNetUninitRing (Dev, &Dev->RxRing, Dev->RxRingMap); =20 Dev->Snm.State =3D EfiSimpleNetworkStarted; Status =3D EFI_SUCCESS; diff --git a/OvmfPkg/VirtioNetDxe/TechNotes.txt b/OvmfPkg/VirtioNetDxe/Tech= Notes.txt index 86b91f561495..0891e8210489 100644 --- a/OvmfPkg/VirtioNetDxe/TechNotes.txt +++ b/OvmfPkg/VirtioNetDxe/TechNotes.txt @@ -72,6 +72,7 @@ faithfully indented) that implement the transition. VirtioRingInit | | VirtioNetShutdownTx [SnpSharedHelper= s.c] VirtioNetInitTx | | VirtioNetUninitRing [SnpSharedHelper= s.c] VirtioNetInitRx | | {Tx, Rx} + | | VirtIo->UnmapSharedBuffer | | VirtioRingUninit v | +-----------------------------+ --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132240684186.37636753412585; Mon, 11 Sep 2017 05:17:20 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4038F21CEB0FC; Mon, 11 Sep 2017 05:14:20 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0073.outbound.protection.outlook.com [104.47.38.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 311332095BB98 for ; Mon, 11 Sep 2017 05:14:16 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:09 +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=aFChEmc/BCfH4CvuPDeguLbTIvCkfeymCbNPSM7woII=; b=2YGW3HlSeDKxJ1FmqIdghPCTtJEdym9ZVZZqSixB3e2MjVDB6NuvZ+xO1VHJcfWyKuF2bZKxqJ06J7wNHo1KMqAga1DuK+0738cf1QzuSrUsShjfIutl3NNJk0ToaiBuv1jSzZiSY8bg70h4xblkhihdbeVScVZM7GiIenk9tDY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:52 -0500 Message-Id: <20170911121657.34992-4-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c22ade39-8ccb-4ec3-b675-08d4f90f06f4 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:DNpKp99kMnhD0PORWGezHlZnqPWqgjZASYoPskewEcONEibvBxUw4C4EIbuwQzGwtrBakvJ3fcZNioVTzJsKRrQjRgeNwMiPoNYZz+j6DFeftskKyVSKOFWJNO8JLY96sExuPwBJwXjGsWIjtRanGmqH+zX9uZ6fodqlWLD5noW0tMDcp8ERjtYID+d+q1pZmovfLb8ADxodCU3TfusYUwdrDUSb2k0xNYxTYMMlE6sn+4QMofZfjoP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YOhGWesK1iltLjkZKRfTReOVb812hvaOpgTXfig4g6FsCuACwKio+wrjMGxl7gDR1I660C73n5ijCKrpor/WZJa133cEbdZH5zPeKAEkWIoqPL0; 4:lWw8gw2s+DOGMEohZr5IDb90MDSavc3thuedEHVY0z2BnUQfZJEC09loUE8zet1kOPG9ivx+/YkClKq5A6E70LDiSq2xvF4rbALYFfNLiR0N4NuecDN4FIFFzKsNrO1eQrvUPtBbmv8vAYt309TF9ti8noABhoqGDqpkWXQsdIc2m9BUH+kL30VcAPVI9V4tn5KvNYsWJnUHX7MHAI2dBfz/kBA6i1FpodW9N4rQOV+giajHcQ5GO16yUouLePe0hMY9vXYsc/83w2bvP+vmYCyDVAqBv1OvvyBVlRv/5f7R/WX/ZncGy1HtxbDvJy2NM7Do440/R8rxzm6d0OaS4w== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6029001)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:AqsjEQhg5puoaJtatTWWUnTPWKf0qMJKtQhFyckxO?= =?us-ascii?Q?HspalbEzTjE3GFt2aYAEGrrDEp9rMGqm3vk0KD+rYPFAlw8qsQukvba+yylm?= =?us-ascii?Q?9WTrNA4x/gsnbU33R0YKYxj7nlZEAdULQLZz8jVAHlAqNOsvxIg677eaQApb?= =?us-ascii?Q?MgG7jsXTfu+D0hMbgSjGwwnI+MF4DM2GVnXvfLXGrYDZZxggWwrJx/9xsZBc?= =?us-ascii?Q?9IT0/7SCiLGOBI32tSKUJIt8VN/w+V0gbPWr4IUiNfmhyu3SVbg6pAFjphEc?= =?us-ascii?Q?l81pIagOWY7oQcBb9EEdOzcsF6iHijRI9q7k1M+FO3ljMqT1W1byeia1WF6G?= =?us-ascii?Q?dBc9HFOkD6fFJRYMBgKhcr8W8fksE2jKMCKTbyx5H6cInQXHrNxMeJz/WjDi?= =?us-ascii?Q?UGhBUrt8CXSBFZ7jlEPDX9keAfG/Tk/OaeRHDyNgb3pNyU88rEQ1N3nZoO+Y?= =?us-ascii?Q?ji6uZiOMtCxFNAhX+uFycZpb5LlegIxl0RUPG2M1Dba0btiSomCv21yRJa8U?= =?us-ascii?Q?Ms9aCtGp+Pmyy180X5RL4YOeM+kK2a3IYH9ms+BvUsxGOt6Cjd/uZSalrHzM?= =?us-ascii?Q?FKUYjT4DOYfezI1LP985UkUWWcGb8YnBt3D2L6TjyUFgxpCgycVpdAzkY17L?= =?us-ascii?Q?pU2GX4StjKJlZ8qcyeAN0eFIl+6OxgwbA7ZDmImUl9crn7xHCa+u6rNT5njx?= =?us-ascii?Q?EFgbdxqKb9Thlhm4+fOfwt6LbevXzucWkGfEBAmrn1i8tJKw7Nf175fwT/c9?= =?us-ascii?Q?8jg/dcmQisejt1QNWAa2TR95qt2AUoLUM0mq5HSeesFmP74nKVbArM+LrKyK?= =?us-ascii?Q?DIoLNYMg2RP4eUOoPqY+GsTCe4+vy4U7BnFd2F8dtOkcbiocI310RJCxyGri?= =?us-ascii?Q?/4yMgbJlbFpdq5PSquQ7h2QGHcneI5r4fqAyRTFcHcVfqWjvk23ippqANjo7?= =?us-ascii?Q?wnFpXLGcz9ZAKEruJnPMwVE1aNliEfjqr9LAylk2WxZ9ah9ObSaF7QjYq340?= =?us-ascii?Q?bv88wCYhke2fMvjK9vk1b/aQHHzUz5DPajYd5P64QCAnED8U6ibDsbvQ6fvh?= =?us-ascii?Q?raqdxplnEeSFHRsgCkWx3JTI25Daj1enszTbI3LZdiS7lp+ug=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 6:Z2RGysTxQm0JEeXoK0BZvWfZ7bRKEKlXwWevdJrU0fHZwMs1z+aOTChgGap8cnIeVcoHqxiO9FHppnlPRPOxfldImuVz/M5JDhIT0AhCg/zbPM/iyGwushqUbpR7zISLY06DtRPIa7hVtk6wG4UPfYKQ/7KJiSM72RKvthcIEtFjl14a5QSV7H22hTssJ0/ZxN5Hnnzlsi7sCe2Ul01tcsM8i46gi6x52ByxyWbOGPp79rzcW88O3PuKhZCtnC6BTFS2mhkuG4nSl7N8LPkxNnzknxNYzmgGiscCETbOTq82sW3pojqvi1mOnt+EiX8GEgtNujp57wqEESbecg3VIA==; 5:nHERXP+xIcJMc0gyQz0uXd8zgxitnyyj9F53oiOdSqbhPOYS8Mt6O7k0fvpwoDKCQkrrX+1XPaoHk4QjvvpiAAYxibNCn9yVKxesYgh4Nu/h75cbuGsTK6kZg6kPGNahtXKSurpqv9uD6DAhuFwQLQ==; 24:zngXmB8Nm9NAT7Exc9taVl9pndT4K1E1Zs2gWqB57TS/TO1vU1Aa/HBkHnqLKuyYxbeL5oJCwLipmLVV70BxFBaD1XPS/8CSbiyN7vRLDxY=; 7:3mDte/muUnVRw1OT+5pYxZF+HvP5/z5HDuEgkcu3ECtJEU4M1Ltwl5yTZjYJWztqfAT/86aJDoBmWngnSX4Tz/ErJh/1iOcKLdLfC6Dy6AWbN2Z9nDtGyGO4GFBi10nB+9RpWRdnmBmNoSTCi43ys6mcZPTEA+5CkYL/94i8OTPiPbcGSTcmLaOlEwP0xFINNBQKwbX9Ixs62rvGyDK0/nI6u7at4N5aX6//5899mvY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:NRgMJbEXr12HVrmzkUc9TXAx6UgWKe0lHnR0A5uZGBS/eQVUfCGBUePDOlxp5Tubjkbbe635hetgmG749KCLyJ0mWl5Pe1PCaPLQZkf4e0uTcNtLNMHsVyBTSomxs4saPdQgeOtaKDZKoF3uP6VOOxBzVyrsrnFc1u5fY23NRFIU/su7iLBqKuPdcIOq8gJjOA4VtOKcSyc91t00+Ekd6t3I/8+/0FFEbrCiHSpxVfxQYXR6/Jfm53RJkTPu2Mq4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:09.8859 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 3/8] 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 , Brijesh Singh , 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.AllocateSharedPages() to allocate the RxBuf and map with VirtioMapAllBytesInSharedBuffer() 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 | 4 + OvmfPkg/VirtioNetDxe/SnpInitialize.c | 77 +++++++++++++++----- OvmfPkg/VirtioNetDxe/SnpReceive.c | 5 +- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +- OvmfPkg/VirtioNetDxe/TechNotes.txt | 2 +- 5 files changed, 74 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 6762fc9d1d6e..7d5f33b01dc8 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 @@ -86,6 +87,8 @@ typedef struct { // VirtioNetInitRing UINT8 *RxBuf; // VirtioNetInitRx UINT16 RxLastUsed; // VirtioNetInitRx + UINTN RxBufNrPages; // VirtioNetInitRx + VOID *RxBufMap; // VirtioNetInitRx =20 VRING TxRing; // VirtioNetInitRing VOID *TxRingMap; // VirtioRingMap and @@ -95,6 +98,7 @@ typedef struct { UINT16 *TxFreeStack; // VirtioNetInitTx VIRTIO_1_0_NET_REQ TxSharedReq; // VirtioNetInitTx UINT16 TxLastUsed; // VirtioNetInitTx + EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx } VNET_DEV; =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 8eabdbff6f5e..54c808c501bf 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -242,8 +242,10 @@ 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. - @return Status codes from VIRTIO_CFG_WRITE(). + @retval EFI_OUT_OF_RESOURCES Failed to allocate or map RX destination a= rea. + @return Status codes from VIRTIO_CFG_WRITE() or + VIRTIO_DEVICE_PROTOCOL.AllocateSharedPages= or + VirtioMapAllBytesInSharedBuffer(). @retval EFI_SUCCESS RX setup successful. The device is live an= d may already be writing to the receive area. */ @@ -255,13 +257,15 @@ 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; + UINTN NumBytes; + EFI_PHYSICAL_ADDRESS RxBufDeviceAddress; + VOID *RxBuffer; =20 // // In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depend= s on @@ -286,11 +290,37 @@ 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) { - return EFI_OUT_OF_RESOURCES; + // + // 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->RxBufNrPages =3D EFI_SIZE_TO_PAGES (NumBytes); + Status =3D Dev->VirtIo->AllocateSharedPages ( + Dev->VirtIo, + Dev->RxBufNrPages, + &RxBuffer + ); + if (EFI_ERROR (Status)) { + return Status; } =20 + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + RxBuffer, + NumBytes, + &Dev->RxBufDeviceBase, + &Dev->RxBufMap + ); + if (EFI_ERROR (Status)) { + goto FreeSharedBuffer; + } + + Dev->RxBuf =3D RxBuffer; + // // virtio-0.9.5, 2.4.2 Receiving Used Buffers From the Device // @@ -310,7 +340,7 @@ VirtioNetInitRx ( // link each chain into (from) the available ring as well // DescIdx =3D 0; - RxPtr =3D Dev->RxBuf; + RxBufDeviceAddress =3D Dev->RxBufDeviceBase; for (PktIdx =3D 0; PktIdx < RxAlwaysPending; ++PktIdx) { // // virtio-0.9.5, 2.4.1.2 Updating the Available Ring @@ -321,16 +351,16 @@ 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 RxBufDeviceAddress; 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; + RxBufDeviceAddress +=3D Dev->RxRing.Desc[DescIdx++].Len; =20 - Dev->RxRing.Desc[DescIdx].Addr =3D (UINTN) RxPtr; + Dev->RxRing.Desc[DescIdx].Addr =3D RxBufDeviceAddress; 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; + RxBufDeviceAddress +=3D Dev->RxRing.Desc[DescIdx++].Len; } =20 // @@ -351,10 +381,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->RxBufNrPages, + RxBuffer + ); + return Status; } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpReceive.c b/OvmfPkg/VirtioNetDxe/SnpRe= ceive.c index 99abd7ebe454..c42489636ea0 100644 --- a/OvmfPkg/VirtioNetDxe/SnpReceive.c +++ b/OvmfPkg/VirtioNetDxe/SnpReceive.c @@ -82,6 +82,7 @@ VirtioNetReceive ( UINT8 *RxPtr; UINT16 AvailIdx; EFI_STATUS NotifyStatus; + UINTN RxBufOffset; =20 if (This =3D=3D NULL || BufferSize =3D=3D NULL || Buffer =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -143,7 +144,9 @@ VirtioNetReceive ( *HeaderSize =3D Dev->Snm.MediaHeaderSize; } =20 - RxPtr =3D (UINT8 *)(UINTN) Dev->RxRing.Desc[DescIdx + 1].Addr; + RxBufOffset =3D (UINTN)(Dev->RxRing.Desc[DescIdx + 1].Addr - + Dev->RxBufDeviceBase); + RxPtr =3D Dev->RxBuf + RxBufOffset; CopyMem (Buffer, RxPtr, RxLen); =20 if (DestAddr !=3D NULL) { diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 57c7395848bd..ee4f9ed36ecd 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->RxBufNrPages, + Dev->RxBuf + ); } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/TechNotes.txt b/OvmfPkg/VirtioNetDxe/Tech= Notes.txt index 0891e8210489..f39426fb13e4 100644 --- a/OvmfPkg/VirtioNetDxe/TechNotes.txt +++ b/OvmfPkg/VirtioNetDxe/TechNotes.txt @@ -247,7 +247,7 @@ In VirtioNetInitRx, the guest allocates the fixed size = Receive Destination Area, which accommodates all packets delivered asynchronously by the host.= To each packet, a slice of this area is dedicated; each slice is further subdivided into virtio-net request header and network packet data. The -(guest-physical) addresses of these sub-slices are denoted with A2, A3, A4= and +(device-physical) addresses of these sub-slices are denoted with A2, A3, A= 4 and so on. Importantly, an even-subscript "A" always belongs to a virtio-net request header, while an odd-subscript "A" always belongs to a packet sub-slice. --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132244037915.3733360356141; Mon, 11 Sep 2017 05:17:24 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8015D21CEB101; Mon, 11 Sep 2017 05:14:20 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0073.outbound.protection.outlook.com [104.47.38.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7D80E21CEB0E9 for ; Mon, 11 Sep 2017 05:14:16 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:10 +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=gnzz5afoT9y5J0eWXwd9Ci3lbBml+1NVVSJF/K7OjbU=; b=SlTzSksc92IEPAbP6c1/OSaby+JrkpCUKvka40U0dRYdUL8crge21YDPkFBNPIypW6BVFrbT4UxO7pv/Sd9/Z/s3gJk5bv6tOg1U/jhV6tv9K1LdCILovQgZiQw8L2utjzECNsnLlrZq2a8SHb9O+9UophFeU/7MWVcCkLi7eCo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:53 -0500 Message-Id: <20170911121657.34992-5-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 64e817e6-784b-4e96-d910-08d4f90f0758 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:8uvuBf5BBWaZ8H2vWwDx2N70eDpzu8L/Ye26pJcp+CPkcJUeKx3qgO5E8m2UQbY8UOlL9AfPRmqtQQKJ3b9/zt+edkZxmCtGL+kxNZnBXTsSkdlAa8iFO2mXIGfeDU/q2yegv2yo31FiQPe+YnkFRRFWbc1CRVYVqgc320Vwdg1q6BPLrzagHyELTe27qqu/EB+qXdxPOYXwrgHPNR/Q0GI7NmgrCXTCNEgp68J9DnE7Gf0R5ggd7vZNQvnCneCG; 25:OHy6vl5Z8GPhZ9Crw0aEMtBndbV82LJKiKDTXKp166s/vEnbvTjoeaJToAQXFfSNoIwY+P8+cdmy1i96TiM+9EPF0lo64ELswqfnv8armkIjhrop0bBZwxfDcodm9SKWSwSBzpAPSPZiO+HQ3ncIfXQrDMR/qiMC6G+tbrvflxlP5o/Yk6CnBL+9n7/CWFXFnJ11TAYTgZNdJ6SmBKvnARVDE+5qpxDVQcNxrFuy8aAMkRscbMjbJ6902SezFTxHqnam4xLteX9TRTbsOwSXHzyoLfZnzw7mm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FgGEwbQ5M6u4UxB+WSu+NqHdnoJa+WpjyypW/KxUyrAcfUJY9a9BQloxFYnGgYE20u6ZE80x1caf2Hy3QbO9KnStdGbd4WjF6Bwg7zpV6Hew2IbYwrgexBBQ+i8Bi2xk91omUbA/OI//AvA== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(51234002)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:Tagjmczn2S62/AFyqUh452cS3qVBfi2OoYqpt08C8?= =?us-ascii?Q?cPiIygZwT8DHRu8W0KOGR6MvZ4upIf61RxXU3omzgiNZW6vF/BXX95acjgc2?= =?us-ascii?Q?eKLCpZDlULYiJ+Qn80KlSjVmKor/iAQx+cQnc/IcLlOziy3En4T1ak3P1Zfa?= =?us-ascii?Q?bIKX18jI0gUHLG+KhEocvPEssZGT9FDbHA2OJ2dxqN9j4R+ktoDDWxlJWEcX?= =?us-ascii?Q?mV0FWVqGH/EZb9STLIbL1TTCZfk73niLeUM7+N1GrPlldi26yFO4RkQDWHic?= =?us-ascii?Q?uA46q5ljEL4CTFM+L6JPWBAOAuTX+Rs/mMNZlZUfCF5gFKESzsl6rs/KFiEb?= =?us-ascii?Q?uJ326SQtQhGZ5FCgaiCSHvmbs1jLqoIEH5WxlkM5k4F+Q7gP3YOYlyHaub7y?= =?us-ascii?Q?M/GAoSrHknQw+I4Nh0ExO6OQMBQ9us+qvSZIPhiQSYeDRRfgAiUW3Uim7pfI?= =?us-ascii?Q?O2Gnxg2bzMeaeCubiCGKryqI0C2G+ICG2IbhZp4H/LpOomWHkenLYVPw6BA3?= =?us-ascii?Q?X80fu+xxA/mI1bAX6GZn3LIFhU/5wb2GUdK/Uxp5rJJtGsXtO3/Z+R41LGip?= =?us-ascii?Q?OcwRmxyhG7lIDF0pofTlZpqLigb+h7nelMl+cOSj3h4rR95/pucb+2inNVt5?= =?us-ascii?Q?MPsc4N++UBF406vtR1Bs8FAJW9Aocr/215rOvjT6CPbeUUegoTyYfyItTFzc?= =?us-ascii?Q?jTnVIibcRpAJUDmRhfn6Dzbc6o1Y8es+lwYxbhSFI7eyNtrO7DVrHvbVuhCC?= =?us-ascii?Q?Yg+ULolOInV+sAw7Mlh46xCXmoN3MOmjzR+uOGq20IiTno48Ry/m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uLMVPOouOSh7cUQe/X/2DwPUbCII7OgISEO/sOm+QdJfVeKtcVwEt+VPRqA7QkxSq+rjXc0sGgqInceaEmMXVfhFWSmV64OMIyrcTvIPAzJaDlHsmRWtWBdnS925Ahm2ODWwCIefruc0c0/NX/4P3BKTJYbvSgJyQlLFWe1Y+YJRq4hHoXc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:2e49396xqa0qC6VbuuDiuiljnRgXq+ExCYuN4C8Ly0xcPPb/aUnmlfhxWy14qgWLkssXbUeGkROBnW9LuzPht7OmBK/oGnoikG/kwYKKWHMndy/huVvhr9vOGLYQtLXBNjJT/Up0TAnq31hJ4La2WbJyDLV3dS1UtsX1klrC2720wpGOe164cRMazse/QRy7Jmb0m+C8waX3O3pHDamVeZPl+dP/CJJiCUHH6a6dCenO5SFfftcsT36wQsdHvtYY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:10.5265 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 4/8] 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 , Brijesh Singh , 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" Each network packet is submitted for transmission by pushing the head descriptor of a two-part descriptor chain to the Available Ring of the TX queue. VirtioNetInitTx() sets up the the descriptor chains for all queueable packets in advance, and points all the head descriptors to the same shared, never modified, VIRTIO_1_0_NET_REQ header object (or its initial VIRTIO_NET_REQ sub-object, dependent on virtio version). VirtioNetInitTx() currently uses the header object's system physical address for populating the head descriptors. 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 map the header object for CommonBuffer operation because, in order to stick with the current code order, we populate the head descriptors with the header's device address first, and fill in the header itself second. 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/SnpInitialize.c | 64 +++++++++++++++++--- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 7 +++ 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 7d5f33b01dc8..3f48bcc6b67c 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -96,7 +96,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; // VirtioNetInitTx UINT16 TxLastUsed; // VirtioNetInitTx EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx } VNET_DEV; diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 54c808c501bf..6cedb406a172 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -18,6 +18,7 @@ **/ =20 #include +#include #include #include =20 @@ -147,6 +148,9 @@ ReleaseQueue: =20 @retval EFI_OUT_OF_RESOURCES Failed to allocate the stack to track the = heads of free descriptor chains. + @return Status codes from VIRTIO_DEVICE_PROTOCOL. + AllocateSharedPages() or + VirtioMapAllBytesInSharedBuffer() @retval EFI_SUCCESS TX setup successful. */ =20 @@ -157,8 +161,11 @@ VirtioNetInitTx ( IN OUT VNET_DEV *Dev ) { - UINTN TxSharedReqSize; - UINTN PktIdx; + UINTN TxSharedReqSize; + UINTN PktIdx; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *TxSharedReqBuffer; =20 Dev->TxMaxPending =3D (UINT16) MIN (Dev->TxRing.QueueSize / 2, VNET_MAX_PENDING); @@ -170,12 +177,42 @@ 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)) { + goto FreeTxFreeStack; + } + + ZeroMem (TxSharedReqBuffer, sizeof *Dev->TxSharedReq); + + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterCommonBuffer, + TxSharedReqBuffer, + sizeof *(Dev->TxSharedReq), + &DeviceAddress, + &Dev->TxSharedReqMap + ); + if (EFI_ERROR (Status)) { + goto FreeTxSharedReqBuffer; + } + + Dev->TxSharedReq =3D TxSharedReqBuffer; + + + // // 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; @@ -187,7 +224,7 @@ VirtioNetInitTx ( // 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 DeviceAddress; 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); @@ -202,13 +239,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 @@ -223,6 +260,17 @@ VirtioNetInitTx ( *Dev->TxRing.Avail.Flags =3D (UINT16) VRING_AVAIL_F_NO_INTERRUPT; =20 return EFI_SUCCESS; + +FreeTxSharedReqBuffer: + Dev->VirtIo->FreeSharedPages ( + Dev->VirtIo, + EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), + TxSharedReqBuffer + ); +FreeTxFreeStack: + FreePool (Dev->TxFreeStack); + + return Status; } =20 =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index ee4f9ed36ecd..2ec3dc385a9f 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -54,6 +54,13 @@ 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 --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132247541434.9771910214715; Mon, 11 Sep 2017 05:17:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BC05421CEB102; Mon, 11 Sep 2017 05:14:20 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0078.outbound.protection.outlook.com [104.47.38.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9DD5721CEB0F9 for ; Mon, 11 Sep 2017 05:14:17 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:11 +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=Ih2zQllWYEZ9QIVtzlqzNjUsavUDwzuWH+xZQwhBK7w=; b=rNv/jTX3KVFuHkLiR7z20ZHP+6pSymd+vCFysT8GIMCZDkThUxzkYR0fsgfn0SpnfaSRD6NenWsJVisU+gZiHFqDwsDRqoqH6qxOxsjGx6xCUyeKYHeMQAV5gQVjgy13xYsRfK9xy1234UQrMPONAJtPj1cpe4u6B7xL0KOVPxQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:54 -0500 Message-Id: <20170911121657.34992-6-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b041bab-960c-4980-8509-08d4f90f07c6 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:5PGW5nyII12851P14VMVZnihMu7IFPapHrz1TpznPXMgZbihk5kWX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rUZMqCOsex2NlS61z2Eve5AshFRnY7ynNYWOCsTiYRNExqNO/Rp5CvYLN3w9MlY8uUBd9wixzCceDn2eB8VF2ZziZfh5aB+lIxqd8HBEKjByCBnaqb81qmoU8g/sQJjIzQPfgWeJrUKBxMaDgWOz7Qjmne+UBh92pWEvAadkFs9c/fccRHYnGTAQKFjnnvV/Wnl69wjrqSc75OKiB445CbTu50RUYJS8dLNxrTelg/5NtWRY6fYTL5KzJl6T1HTPuT0OtQsqsCRo+FbCkn5u1JRmby/Sh78COrU+V+p1v8mfhfpzC; 4:7+CU/8xMEmMXyEo00AO4NDa7HLHLxR16Bmr/h9bylgS0QQcWVA0U31nFglKIVprd4iyqlQNCfxqMR6ZTf3Fph0SgAUnFEpLRIxE+G8Xm9kZcWX6KNEyWgwQuoZ6Y51Fa0NJcOTip0CHiGHwjh2Wvu0kMLgDx0Bqq1o/wQQq6qp7Rl52PM3V7pCRIp1AtxNnqnXP3eWHladK4EmJukh8yCLqQPP5LlXl74G0Cjs7OXHJqUS60npppBoqSGDUXuPS43MBNnnbiJ+Zjzg2Rvwj54fbEoDFHz4EovBYWiQiHJTCE0Au3g+MLaadYLVuc2iFRdUKbUXu1KoENE4QYWpqqlxm8fnXbrme4n4fXWFIsnHQ= 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(15650500001)(47776003)(86362001)(5003940100001)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:D6Hx3hCTqW7bS3MXKdpMBEp4TvzAfQC/M1lpiOzk5?= =?us-ascii?Q?/n/bA8lgJbEILkjsVusPbfPiTNPshdoMP1TBLZ9kcbBKE1BFmtibK2duKduL?= =?us-ascii?Q?MmZzfKk+zplC24t7XQ659cdn5HZiBpvbXMAtirQva0V5jK/BwxXRnrhwG2iy?= =?us-ascii?Q?zGYUFuN+xRzKA/Gnhh1GywzOY64g0e444VDDvQxkl1NQkQYYB7L+yJ8iw/Db?= =?us-ascii?Q?Z3tIuADIv3fiWVhw4untGtLcXCL3jb5fCGKjDTx7LWWMC4SfUavq5Zo6CMlu?= =?us-ascii?Q?IAfUOOPadzJTb584iQBtAXfC3NXQk9iUfx7Ey0FbrqzuCyvZ02Pq2VjNQBoN?= =?us-ascii?Q?HBihhj8sc32H3zICgCJadVU2R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9FTncRbehF+ghfGEsZt3rDALAgAraXtB/K0RO3KRTlmPupVsHDFqWwCVQwTgfBZgAjBhCTA+3BwuNfqawgc8uEmdJWBrFYEf6yQX+AxbIhgKerQHQCPZdn65PM0Cg+9yUOXesypVGnkZJRJbKymBfN4k8EEhvd8r+vSzSAGD67KTft42zfff6o70bX23bSnPKrLDraQ6sSoiH7S2nOmGzEh4crkMTegDOA==; 5:vhuKdg+hYuZcjoNHebwRa+4b5LplKIK2Sf2aUXK9QkP/XWqdrLKUnrgn74zxCOL+IHTLJ8ocAPcGch/7Qebia98a5ftgU9X2/1Nubzk/nSOqH8G/f9lEbj5klwJssOUedgn8k4r1DPEVKu+/P/BILQ==; 24:IchtIMuJxqVyy5VicpBtu12vIzyJvXiqpKLJb3TdNWpj46Uc1ABBhSF9zogLzSuhtNdwqLkI75TwuBR/+1p1R05vb5WOU5xQNol7H+AjYkM=; 7:+TL+rgJDP/V6CqdYnIUEqnqOU9Mfot0lPZ9AjE66fNdyXits3frKPIALD9cqkIzCIm8ABich/l0oh5s/qhBpwwM9f7fGn3O5wE+y5FiYVsMiA6+nP4+24U5iV0YeHIomVUCYjylYOjdv/HNg838bnA0M66e6CNhjX77RBpLvNUua4quSc6WGwBTvvHywiaioERhtM7mTh07J55MsZyH+jPZvgk713UdE3rNIzBV8n1E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:SxaC5Wzu9eZW80hTMnGmDJSP5mVnHNL9DR6vDtEDtxaNfQS13qonVTZd165yS2gg5aJzhFIwYjcmbXdvdVo/o9gSrnEPDZwLhBNBvgOixZ1iqgXY7Q/4e7BC1l7Up11JfYEk642OpK++z2L6BZBPkwi+fEMoS54hz4sAuXALrVwjz6kNCfJvZLb4yLTRic8phujlKLE/P7a+hfNNPnlVGrb3hZRk7t/V4sGU6QbrCjQr2h1ej4P24RevY0x59ZpI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:11.2452 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 5/8] OvmfPkg/VirtioNetDxe: update TechNotes 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 , Brijesh Singh , 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" In next patches we will update Virtio transmit to use the device-mapped address of the caller-supplied packet. The patch documents the new model. 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/TechNotes.txt | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/TechNotes.txt b/OvmfPkg/VirtioNetDxe/Tech= Notes.txt index f39426fb13e4..c6ca341ead15 100644 --- a/OvmfPkg/VirtioNetDxe/TechNotes.txt +++ b/OvmfPkg/VirtioNetDxe/TechNotes.txt @@ -312,10 +312,14 @@ in the following: that is shared by all of the head descriptors. This virtio-net request h= eader is never modified by the host. =20 -- Each tail descriptor is re-pointed to the caller-supplied packet buffer - whenever VirtioNetTransmit places the corresponding head descriptor on t= he - Available Ring. The caller is responsible to hang on to the unmodified b= uffer - until it is reported transmitted by VirtioNetGetStatus. +- Each tail descriptor is re-pointed to the device-mapped address of the + caller-supplied packet buffer whenever VirtioNetTransmit places the + corresponding head descriptor on the Available Ring. A reverse mapping, = from + the device-mapped address to the caller-supplied packet address, is save= d in + an associative data structure that belongs to the driver instance. + +- Per spec, the caller is responsible to hang on to the unmodified packet + buffer until it is reported transmitted by VirtioNetGetStatus. =20 Steps of packet transmission: =20 @@ -338,9 +342,11 @@ Steps of packet transmission: - Client code calls VirtioNetGetStatus. In case the Used Ring is empty, the function reports no Tx completion. Otherwise, a head descriptor's index = is consumed from the Used Ring and recycled to the private stack. The client - code's original packet buffer address is fetched from the tail descriptor - (where it has been stored at VirtioNetTransmit time) and returned to the - caller. + code's original packet buffer address is calculated by fetching the + device-mapped address from the tail descriptor (where it has been stored= at + VirtioNetTransmit time), and by looking up the device-mapped address in = the + associative data structure. The reverse-mapped packet buffer address is + returned to the caller. =20 - The Len field of the Used Ring Element is not checked. The host is assum= ed to have transmitted the entire packet -- VirtioNetTransmit had forced it be= low --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132250697733.7383350991066; Mon, 11 Sep 2017 05:17:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 047B621CEB106; Mon, 11 Sep 2017 05:14:21 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0078.outbound.protection.outlook.com [104.47.38.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 08DDD21CEB0FA for ; Mon, 11 Sep 2017 05:14:18 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:11 +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=K0ybQ/1VSDjBw10Xzmo/u+YkzbjobUSe/5Dzdol7AC4=; b=PJRkg/PdJw2/1nXXPzRlI5gTtcXLnsEgXlkHGQEDFiCiZjR25UK5dvixU+jQqrt77G13pnNIkc4wrVzeQ4HuH12qzkamTO88HdfJ0Uz7VgeYx4/BGBK22+DkXH9QwDM/dOnvBtMwcPsY1/aP3tHpjJZ3dQAYYD6n/6+cv/USA7A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:55 -0500 Message-Id: <20170911121657.34992-7-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0db7671f-824f-4842-0a00-08d4f90f082d 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:0OJeG6LH2B8USxezh25xzAkyr2EnEklFTlUG1syCaVXl9nHliBhIwln2E87WrLeF9Lc34lsFiBGgcgTdaCbPOB8KE0pXCiAbfZqvwRX4OMn3hQem0kgxXKGnJj6joiFzvqwU8OLBRSLANyyNhIg/oN2zCpzGcQe+6pImNGGmUHAKQ4l2fTC6M8a1gyNaYwiCUWBVdoPYYgC0A6AeahRTVt9mxuLEJ5zOWXb0ynDowllsv6AXxjz9kIahiyN/pEpO; 25:Cd72b5bpIZRQMEgTpSxm9PyZraIQRfBu3IOCh0kc+s7FwHgdP8bLfCCkN9DREPWVnXQPx4Hpw3DaCM6fvBJUwSqRpYz5gAS+08IY0X3Hv09MLhONl95tIlC1oXJWW5dP0XQMhlUzUE+2w2xdpMdRBtuj7r3DJU66tx1Mv22U/zZM2ii7HITRYKDh0uqOFjwEi8yCb553kF/Lqlq1FekBiPH8u1/LMEFV8oWqOuDAeibxXrs8hgvRCSYWeP0AJxgW+P+jMKSv6NlsxRwb8Bl0upkZFNfKdc3yUX8Sg2Lz7KBLws7eft1GvLoPb92BsW4qi5bVTwR5ptTR9yx/jqivYg==; 31:RyXQS5qHzhNRYVraiA+13nFoQB+0NkrePAxtvWjzj0jbCilpTRzg7EOS0xOcTRAvIGGbX7V63Zk1rluFQ8YsX6A44Mv4l2xLxuSt+ebHLNkxOvS/7krk8p7WAJ1/EEldYjONxjU9iuW7H8d18tUvLrKZ0bf+7zHQekmAuYCY4p5+idSypqlfLHzV7dm7ifR+UcXfv3/aAGB9SvRgvXzwfGp5ih2tOGSFRuHx6ne6SII= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:WPJdIqvT9ND20h6mmUUPqWDwsj5SkAOByl8d1vsCr1DrJlsBruAQvvd5SzDIy/o0HxX/5TnbmHDip/vwrLaGhljjvkRluEC0QsQ5+NroXYqN37oSM1PO3VazaLjpyDzl0exlTY0CbBFguCvXMIWbNtLqVBp3VZQ/MmSRAkx0CEiGmdB7vyWwzCIR3lKfnK5XMcLiRYtyJTShle9jMpJZML38ok3mgGsYo+Qhebdq1woSv6BuTKMi7ATTA8KuSedg0IQsO4zYJf1LqG/5LnbtdHP00crQd9Fz1O0nNfZFSNeVLk6JMMVVGc6zhfOnT1SyJbJ94+lpvqMDvgo8Vw+0UKOgCOzBKFGhk0yP6JJA1jRYu/CA0rKpABsfufZsnBxsG5Oakg0O/dhFPZSinruXL/Zbh2XVFqotQrqRuWWHxYN9eQ0YcG2i8oh9IVFMXDyKielPAOK04367OCfod3otyTd5QL3dMGIBJFbMIhgijhB3PEKfXs2TDSOSwYxXWb37; 4:9+DXScJ88e2RxfJXkyKrrTkE8sDejcXP3VenmtKzM3oQU03z52pGaFholOEcmRxSg+u6zvehAY2ypEbu7uJz1yO0MV1iOMXfS4RNiy5UEB/ONlkL8uUv120WiO3TRZBZlbPwObeRRUTd8kod27FzoZnRCen/R49FgQ6JK5xMY/dZKcTiQnegiXTbDxJD//tQmnXrvhcQ7BCpF5lhdil6OegBXoIWDsyz3+kjSq4y898PO0EDE0zmHs/dzF8ejLe2jZhh7/RSi+7FzgEZEs+odJNwEiXIHvWbdDcWoPYLty3wYpusk4GYEvQ0U+9IARodj0owU+fb0BJbze73gnkD6w== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:9Hx87qSvPoLnVqpiHzbT6BgQ+X0IZvCKgST9gYN7b?= =?us-ascii?Q?yi9TZHRb0HetM3Y5OsLQHiN4xLXbBQCEnByk1dADwPgQB/W5Gt5dZrqqPMz9?= =?us-ascii?Q?+EUuEoyeLXWQQNfOfr6RBTfUoTQPh84iTIYqGJH1p1W1umcFizYlx49TLOJS?= =?us-ascii?Q?MOoiYYpG9yTZ2ONAFzafGI4HdZGvBDTQE6G1zM0Ygwf+IFCU2imup0Q6cLWm?= =?us-ascii?Q?TMJKTag8JXarhvsQVxUHMCJdYjnXDF7Lnqrvjp4kLUsdZ59hikAhHQ5KjQ4g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rNjkL+0n6AG7LEmHqJLYaNgOlts/3sOWxa6GZ1a7PLrIcLOFcrgaQu57zT6UaP2WSo3qVx4BKXFMW+tKs7SVz9WkiV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:11.9171 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 6/8] OvmfPkg/VirtioNetDxe: add Tx packet map/unmap helper 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: , Cc: Jordan Justen , Tom Lendacky , Brijesh Singh , 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 IOMMU, driver is require to pass the device address of TxBuf in the Tx VRING. The patch adds helper functions and data structure to map and unmap the TxBuf system physical address to a device address. Since the TxBuf is returned back to caller from VirtioNetGetStatus() hence we use OrderedCollection interface to save the TxBuf system physical to device address mapping. After the TxBuf is succesfully transmitted VirtioNetUnmapTxBuf() does the reverse lookup in OrderedCollection data structure to get the system physical address of TxBuf for a given 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 | 32 ++++ OvmfPkg/VirtioNetDxe/SnpInitialize.c | 15 +- OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c | 188 ++++++++++++++++++++ 4 files changed, 235 insertions(+), 1 deletion(-) 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 @@ DebugLib DevicePathLib MemoryAllocationLib + OrderedCollectionLib UefiBootServicesTableLib UefiDriverEntryPoint UefiLib diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/Virtio= Net.h index 3f48bcc6b67c..906bec8e88f3 100644 --- a/OvmfPkg/VirtioNetDxe/VirtioNet.h +++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h @@ -26,6 +26,7 @@ #include #include #include +#include =20 #define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T') =20 @@ -100,6 +101,7 @@ typedef struct { VOID *TxSharedReqMap; // VirtioNetInitTx UINT16 TxLastUsed; // VirtioNetInitTx EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx + ORDERED_COLLECTION *TxBufMapInfoCollection; // VirtioNetInitTx } VNET_DEV; =20 =20 @@ -281,6 +283,36 @@ VirtioNetUninitRing ( ); =20 // +// utility functions to map caller-supplied Tx buffer system physical addr= ess +// to a device address and vice versa +// +EFI_STATUS +EFIAPI +VirtioNetMapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 DescIdx, + IN VOID *Buffer, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ); + +INTN +EFIAPI +VirtioNetTxMapInfoCompare ( + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ); + +EFI_STATUS +EFIAPI +VirtioNetUnmapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 DescIdx, + OUT VOID **Buffer, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ); + +// // event callbacks // VOID diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/Sn= pInitialize.c index 6cedb406a172..a8ffb9a8a7b1 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -176,6 +176,15 @@ VirtioNetInitTx ( return EFI_OUT_OF_RESOURCES; } =20 + Dev->TxBufMapInfoCollection =3D OrderedCollectionInit ( + VirtioNetTxMapInfoCompare, + VirtioNetTxMapInfoCompare + ); + if (Dev->TxBufMapInfoCollection =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeTxFreeStack; + } + // // Allocate TxSharedReq header and map with BusMasterCommonBuffer so tha= t it // can be accessed equally by both processor and device. @@ -186,7 +195,7 @@ VirtioNetInitTx ( &TxSharedReqBuffer ); if (EFI_ERROR (Status)) { - goto FreeTxFreeStack; + goto UninitMapInfoCollection; } =20 ZeroMem (TxSharedReqBuffer, sizeof *Dev->TxSharedReq); @@ -267,6 +276,10 @@ FreeTxSharedReqBuffer: EFI_SIZE_TO_PAGES (sizeof *(Dev->TxSharedReq)), TxSharedReqBuffer ); + +UninitMapInfoCollection: + OrderedCollectionUninit (Dev->TxBufMapInfoCollection); + FreeTxFreeStack: FreePool (Dev->TxFreeStack); =20 diff --git a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c b/OvmfPkg/VirtioNetDxe= /SnpSharedHelpers.c index 2ec3dc385a9f..dafb538b4b5a 100644 --- a/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c +++ b/OvmfPkg/VirtioNetDxe/SnpSharedHelpers.c @@ -18,6 +18,17 @@ =20 #include "VirtioNet.h" =20 +// +// The user structure for the ordered collection that will track the mappi= ng +// info of the packets queued in TxRing +// +typedef struct { + UINT16 DescIdx; + VOID *Buffer; + EFI_PHYSICAL_ADDRESS DeviceAddress; + VOID *BufMap; +} TX_BUF_MAP_INFO; + /** Release RX and TX resources on the boundary of the EfiSimpleNetworkInitialized state. @@ -54,6 +65,20 @@ VirtioNetShutdownTx ( IN OUT VNET_DEV *Dev ) { + ORDERED_COLLECTION_ENTRY *Entry, *Entry2; + TX_BUF_MAP_INFO *TxBufMapInfo; + + for (Entry =3D OrderedCollectionMin (Dev->TxBufMapInfoCollection); + Entry !=3D NULL; + Entry =3D Entry2) { + Entry2 =3D OrderedCollectionNext (Entry); + TxBufMapInfo =3D (TX_BUF_MAP_INFO *)Entry2; + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, TxBufMapInfo->BufMap); + FreePool (TxBufMapInfo); + OrderedCollectionDelete (Dev->TxBufMapInfoCollection, Entry, NULL); + } + OrderedCollectionUninit (Dev->TxBufMapInfoCollection); + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->TxSharedReqMap); Dev->VirtIo->FreeSharedPages ( Dev->VirtIo, @@ -83,3 +108,166 @@ VirtioNetUninitRing ( Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, RingMap); VirtioRingUninit (Dev->VirtIo, Ring); } + + +/** + Map Caller-supplied TxBuf buffer to the device-mapped address + + @param[in] Dev The VNET_DEV driver instance which wants= to + map the Tx packet. + @param[in] DescIdx VRING descriptor index which will point = to + the device address + @param[in] Buffer The system physical address of TxBuf + @param[in] NumberOfBytes Number of bytes to map + @param[out] DeviceAddress The resulting device address for the bus + master access. + + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to + a lack of resources. + @retval EFI_INVALID_PARAMETER The VRING descriptor index is already ma= pped. +*/ +EFI_STATUS +EFIAPI +VirtioNetMapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 DescIdx, + IN VOID *Buffer, + IN UINTN NumberOfBytes, + OUT EFI_PHYSICAL_ADDRESS *DeviceAddress + ) +{ + EFI_STATUS Status; + TX_BUF_MAP_INFO *TxBufMapInfo; + EFI_PHYSICAL_ADDRESS Address; + VOID *Mapping; + ORDERED_COLLECTION_ENTRY *Entry; + + TxBufMapInfo =3D AllocatePool (sizeof (*TxBufMapInfo)); + if (TxBufMapInfo =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D VirtioMapAllBytesInSharedBuffer ( + Dev->VirtIo, + VirtioOperationBusMasterRead, + Buffer, + NumberOfBytes, + &Address, + &Mapping + ); + if (EFI_ERROR (Status)) { + goto FreeTxBufMapInfo; + } + + TxBufMapInfo->DescIdx =3D DescIdx; + TxBufMapInfo->Buffer =3D Buffer; + TxBufMapInfo->DeviceAddress =3D Address; + TxBufMapInfo->BufMap =3D Mapping; + + Status =3D OrderedCollectionInsert ( + Dev->TxBufMapInfoCollection, + &Entry, + TxBufMapInfo + ); + switch (Status) { + case RETURN_OUT_OF_RESOURCES: + Status =3D EFI_OUT_OF_RESOURCES; + goto UnmapTxBufBuffer; + case RETURN_ALREADY_STARTED: + Status =3D EFI_INVALID_PARAMETER; + goto UnmapTxBufBuffer; + default: + ASSERT (Status =3D=3D RETURN_SUCCESS); + break; + } + + ASSERT (OrderedCollectionUserStruct (Entry) =3D=3D TxBufMapInfo); + + *DeviceAddress =3D Address; + + return EFI_SUCCESS; + +UnmapTxBufBuffer: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Mapping); + +FreeTxBufMapInfo: + FreePool (TxBufMapInfo); + return Status; +} + +/** + Unmap (aka reverse mapping) device mapped TxBuf buffer to the system + physical address + + @param[in] Dev The VNET_DEV driver instance which wants= to + map the Tx packet. + @param[in] DescIdx VRING descriptor index which point to + the device address + @param[out] Buffer The system physical address of TxBuf + @param[out] DeviceAddress The device address for the TxBuf + + @retval EFI_INVALID_PARAMETER The VRING descriptor index is not mapped +*/ +EFI_STATUS +EFIAPI +VirtioNetUnmapTxBuf ( + IN VNET_DEV *Dev, + IN UINT16 DescIdx, + OUT VOID **Buffer, + IN EFI_PHYSICAL_ADDRESS DeviceAddress + ) +{ + TX_BUF_MAP_INFO StandaloneKey; + ORDERED_COLLECTION_ENTRY *Entry; + TX_BUF_MAP_INFO *UserStruct; + VOID *Ptr; + EFI_STATUS Status; + + StandaloneKey.DescIdx =3D DescIdx; + Entry =3D OrderedCollectionFind (Dev->TxBufMapInfoCollection, &Standalon= eKey); + if (Entry =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + OrderedCollectionDelete (Dev->TxBufMapInfoCollection, Entry, &Ptr); + + UserStruct =3D Ptr; + ASSERT (UserStruct->DescIdx =3D=3D DescIdx); + + *Buffer =3D UserStruct->Buffer; + Status =3D Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, UserStruct->BufM= ap); + FreePool (UserStruct); + + return Status; +} + +/** + Comparator function for two user structures. + + @param[in] UserStruct1 Pointer to the first user structure. + + @param[in] UserStruct2 Pointer to the second user structure. + + @retval <0 If UserStruct1 compares less than UserStruct2. + + @retval 0 If UserStruct1 compares equal to UserStruct2. + + @retval >0 If UserStruct1 compares greater than UserStruct2. +*/ +INTN +EFIAPI +VirtioNetTxMapInfoCompare ( + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ) +{ + CONST TX_BUF_MAP_INFO *MapInfo1; + CONST TX_BUF_MAP_INFO *MapInfo2; + + MapInfo1 =3D UserStruct1; + MapInfo2 =3D UserStruct2; + + return MapInfo1->DescIdx < MapInfo2->DescIdx ? -1 : + MapInfo1->DescIdx > MapInfo2->DescIdx ? 1 : + 0; +} --=20 2.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132254385488.01236024896514; Mon, 11 Sep 2017 05:17:34 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3BDAC21CEB109; Mon, 11 Sep 2017 05:14:21 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0078.outbound.protection.outlook.com [104.47.38.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 67CA121CEB0F9 for ; Mon, 11 Sep 2017 05:14:18 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:12 +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=Kt4XxGZ+w58upGdj44Gp3O0quqDCk+Q28Xad2klqf4U=; b=2Ym9ZWcJaE9O/8rWpIMs0gG0s4gRSr6CFe1BajzOWkDQu8Olc5LUnWNk56LypwPWb6HXUW9q5c8uilNbcRb1eLhn09K9ZxMe3mfxWhp+JWZJ1vxCg3l4hb24GpawQRWcRU8HYxzjXw2Haloos5k1U1fK134+9gEhfrM9qp7uz2Q= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:56 -0500 Message-Id: <20170911121657.34992-8-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d5bd5e05-c264-43ef-2c95-08d4f90f0891 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:1l1EodOM4qeN067IX1TBu/dfS5OSAsmOWO00zJjYB3MmZGcJh/tIbWN0U+DNQmdV6fse+aicm0/ymesTI4iXOYq7IU/WNAcj4FTeRtR1UI0IyByS1GcSNmTxzUydTp6tifPCPUwnjY4nBm093uql3XvBy9obJ43toBfFoZbNRHiZsktE8v2er99V1C6YIgidSQQmuuzyBt3nmKHpWopbKZN69AV9MDNcoK1oXm2GfdHlHq+jodmXyM7DBtf6bWV/; 25:hWHssv+bEGZ/6c7GI/yQghfUcSRRt8I3XyViAbBHfgZp3kn0Xd6zYqxVj03EZGhs5BhlNuUN/VsWj1aiAjJKibHWa//d1fvMD2A3/DeGgB8scJvtXBmcSRlEnhnX5N09HNWpKyxO99IgNO46wV0ieV6Waz7Yz9SsMEFO1qvOm1aHSLDUneki2L2+SyQmJccvgXb7Uqib1SyHfI4DOposqPa5aQuG/tH+5ziyP1C0MU6jnSARs6lIfO4pthv8mfc6VrKVYyM6rJ6SHceA7Fub8dvNLB/CbUxw+Tx41kqjY0iPjPDNhPnyeWOnFGudTYWizOZ2Qmjgta9oDakgjOEKkw==; 31:Rxz8a3RhA53yW2Ken+RsQKvninvsKuQPGmhqtkxh2fxO2Z0E4rZFPGwFCCvBLwbf3izZif0EPUm7Evrz5s+9nVq1VQuOsoyoTyvl5/4F8pRxCg6OO+ESB/XDyh0SMC/QPZruVQf8uN3wdTencYM6H9H8wnJqbdUmhKFGJBap0Q1tNh3vvndzuMJQgh4C2V18YCgqcgk+t+2Rj4FszdXzAMlJP//iMZUi72m9zRGtfvE= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:wwLb3Pa+hABTDOjeXkLJy4nGAtFpV4e1lsfdGH6wMZBdPqUD5msfqawA/I4l7Th9ddRXCpBAJ1YlWxaW88S0gvHcmz+fD1d8bAaizScwtba6foxdXfEijR8ksjnA6o9KFNWI48xhY/IBB1v7w3uIgL4/dtdaREHvKyCQYk61jSyNE/NnLfT5OJwfAIz9eGJhapiPO2wXD9M1Td785BhFzg9fm1buum3oqjX/7Fnxexh9WKAqBYmLjh/cggPhg2vWdST9K6WghMkzeUWRGZXjtPdOof/SeZpICeBmz5pHYFw76vpfecC5hAwHYjRg1w4ogGR3WgV3gNKDzbw9chxAd97MREAjP0mqKySszZpYl83P7gZx6x4HpFBJKVCLsrbFjXVRzOqoZwINBNTkvS6IH9s10Hu0yECl/cUvInZLv9rnUB/cLY+bQfUvM+P68tMn0Ns4ZL8P3aA1vCPYIeMH356yFSrUODGFFLmf21guthNXZloYv6Bfx/rZfDfnKJNC; 4:xbdHjzyoXJFq5XsoeYlGzl3goRd8s62Z+2WvzfeMiVbwHTzPbZsj71j8/NvyC3VZz9vr7T6EbicuRSdu/B5CCMa10+aWGygyMC7JD1V4mGw9iwMzZyauc7KPJM8JPKSXm8c/cZCWG2GqVT/F4J847HI44QYazw3t3M6kRN+kvI/8FFGA4HXZhvQkaBT4JME0tjbZeJk0oFiTiQS2dV2+dON+4gNZccbjFWyz6h09HsMbbwH8d6x89iV2D0hzNRHb6jnAaMQMSPb18jZK730jraFOYyPGddkNmTESF2BwFhTjIQc45eQHwanYIJ51VW5RHXJM1kJF+ziHFftTSKnT7Q== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:wc+8eLZPFFcVfHi4M5256FukxnXGWBVVwC+CbsB2R?= =?us-ascii?Q?cJXDRzHUBwZmgKoXdRFw9nYCfE//fbJtzWAik6keOygnxYB5kgZk3Y3XI87n?= =?us-ascii?Q?HZpAHs/+4ZdrM0gc7DQL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?us-ascii?Q?e0TrUsELD3SYRp9/0kJo4f/9/HXM8CLC61b99msBJSxr6dyU10oyyk/A2lSC?= =?us-ascii?Q?5hyXlyl6uKhb4SbRojMoSa0LiYE?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 6:EW4W+gQUB7+AZPFoPMwEPwKpaO7+4eZDckMf1NwVLBamtTOk6jYAO1JPjDk3xsQfmQVaWRP73TC3ETcwP5APrBW1nTdamxfscR7umyOBHelrfQDzNUKONkdk4Hrm5BfHT+LVUmNTqpwBQeO+WUmP4ixPBoZrdPQ9hH6l8OphFcya2m4JMjWto2KS0VGxyyMLVcCbSyd5HtzBnd70Av7kqfPF7GiDwYfMOTrXnJpvV+974oV7Lw7HsSl+f/aNhC4J3Vmi284s8hU6lBDdwe1mUciKOfAtb/ClDegOD+qkazPM63dlVGyvc6NXB7dMKT69bI69BSIEBgEhWaITW8RJlQ==; 5:0KivdueDEW8ID/uKK9KFc/kQTNyEBf5B2cFliIPyC8IWV8vakcNgMZbAQwD66Yh0xSWhblzKM8TDIpvBj0lF+8gkNiatA8GxPXvFmxRVSDXOY58OpeXeJYUcfrQhnGNDFG94y8tMHabHA4YJExHdlg==; 24:9Uz9TEA79tdGsejzWlfO5A/zdSYTNhzmMPaV2YFusl1Hawxwpd1FrYwcD5FAzCQrEte2JYqJgem1lOd9TsktJw4T9PuS0cgbp0QAB9iFA0E=; 7:0NEGWrlTZHh9BSw1O3tTAhCATSQSV7q1CpSbatfKEid46S1Ulsqo9J6E7O5qTQ4amaXtCtHmbnbWxNrCn+aBhddA70VVvB+3trbz75iEcKMV+I0yOLc7j/n9QIvwwIIwVpPWIkmpLSEn/9Sk1u0rWqDq+gU0QspfvRPUIXOnY7zkZRk2Mmq196MhNhVYt46aYml9cfFVj5jVCDecll6htkvVymPn9cznjf/mjrdHUMA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:DFLxKKY1kMVJI/MUUJRMkOuvaM2k0kq8IQKks2Vxxc8bzdK+p6wttPJ0we5jdfj3qfaXIDHiQj4Zpqe/4+Ef+qiqnyknzuM97/6zN57HZbS7gTH07QClqPCjE/bQDmj4CHaqnNXHaLI/1ko+kO8UkkDjb07YnoVmLc2l4iWB6eo2feGzLLsSHUOsROWGsVG1gkDQtlz9m3kp4Uvk3DZkAm4p6ij4ISft3u8e+mPepBrXuej6/7MvqJiVL3UyD8Cz X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:12.5733 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 7/8] OvmfPkg/VirtioNetDxe: map caller-supplied Tx packet to device-address 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 , Brijesh Singh , 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 caller-supplied transmit buffer for the bus master operations. The patch uses VirtioNetMapTxBuf() to map caller-supplied Tx packet to a device-address and enqueue the device address in VRING for transfer and perform the reverse mapping when transfer is completed so that we can return the caller-supplied buffer. 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/SnpGetStatus.c | 30 +++++++++++++---- OvmfPkg/VirtioNetDxe/SnpTransmit.c | 34 ++++++++++++++++---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/Snp= GetStatus.c index 694940ea1d97..9bd62fbe8ec0 100644 --- a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c +++ b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c @@ -61,11 +61,12 @@ VirtioNetGetStatus ( OUT VOID **TxBuf OPTIONAL ) { - VNET_DEV *Dev; - EFI_TPL OldTpl; - EFI_STATUS Status; - UINT16 RxCurUsed; - UINT16 TxCurUsed; + VNET_DEV *Dev; + EFI_TPL OldTpl; + EFI_STATUS Status; + UINT16 RxCurUsed; + UINT16 TxCurUsed; + EFI_PHYSICAL_ADDRESS DeviceAddress; =20 if (This =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -141,9 +142,24 @@ VirtioNetGetStatus ( ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1)); =20 // - // report buffer address to caller that has been enqueued by caller + // get the device address to caller that has been enqueued by caller // - *TxBuf =3D (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr; + DeviceAddress =3D Dev->TxRing.Desc[DescIdx + 1].Addr; + + // + // Unmap the device address and perform the reverse mapping to find = the + // caller buffer address. + // + Status =3D VirtioNetUnmapTxBuf ( + Dev, + DescIdx + 1, + TxBuf, + DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + goto Exit; + } =20 // // now this descriptor can be used again to enqueue a transmit buffer diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpT= ransmit.c index 7ca40d5d0650..0be3243b4606 100644 --- a/OvmfPkg/VirtioNetDxe/SnpTransmit.c +++ b/OvmfPkg/VirtioNetDxe/SnpTransmit.c @@ -73,11 +73,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 +145,29 @@ VirtioNetTransmit ( } =20 // - // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device + // Get the free VRING 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 VirtioNetMapTxBuf ( + Dev, + DescIdx + 1, + 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.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 01:57:47 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 1505132257714398.06440982842173; Mon, 11 Sep 2017 05:17:37 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7501921CEB0ED; Mon, 11 Sep 2017 05:14:24 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0053.outbound.protection.outlook.com [104.47.38.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7B0BC21CEB0F8 for ; Mon, 11 Sep 2017 05:14:19 -0700 (PDT) Received: from ubuntu-010236106000.amd.com (165.204.78.1) by SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 11 Sep 2017 12:17:13 +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=Ws6upEF9ywhj2AWGMUI+5HYT4EfhHOy7VrsU+78UqvE=; b=VTt6gwSk+1TbsmWivnPMY4kGfIAo0BqE/95q3uq1f0DT4tTN7UjXOKXftIvjr74J0hMwcdQ7Cj/l1LDlyQplZ+A+KPn38WeJHIMbXf5Lpq7/jfZEIh3Mxwwx1LaThHgH11YCm5qHPSa6Gt4blkYdS5ytR4vGc3LBqN2FZDYg8e4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Mon, 11 Sep 2017 07:16:57 -0500 Message-Id: <20170911121657.34992-9-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170911121657.34992-1-brijesh.singh@amd.com> References: <20170911121657.34992-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0047.namprd12.prod.outlook.com (10.161.151.15) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ccc8a7f-a8a7-41ee-ecda-08d4f90f08f2 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:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:iARHBWImX0q/SbSUBIobupzu6PBPF8uxQVpE5x/Qr8ShPIRGM70vCxn2b8D9cxKjhT96d9/uoYuJwVuGO/HLRT0CVpCyioqhz15iz9S6NchxIkx6H2mxhsFi/XOhYHrUQniIqqdS0MRo4NK7bqOyOk8c7rezANsFl4uUwlMQjILFd4NcXkN7Iw6IL3uD9VaDpctqMQbC0LY3X8fdsZRi+/GE0gBxHcsjgwjBAIQyqsI/xwxX+IccUiMAC+I773tX; 25:jYMQh/qGX/jYKBABlqyH++9fbGbrPa5iv4gWdb8DE3Et3D1s2JuX1ovv+NPCMi5y768Smzm/Q/XPGu4vqLqGjn4L7rLx/aDGZfwQlYfZ+lcb4gNNMGBVqcIm0o0fWFByg0GG7EMSaGxFGx6grNXefRRmdFTu9ro3TaITx6cACMAcHimMHLsuy8i1u8rvheUDUGx58uV5VGrAhHMhb4ShvLZCqYDYrz631OpTC/ddcR/iOEQ9YgnxXN/BGknvns97EEjYlXy61ZPEYgvzDcp+00b25sp0Uyagpwp0W6Nkuuz75VjihdLIyLwnI4/1EBXDpJ8ZNVUi8PyI22w+JQRnIQ==; 31:Vk4/AYXAxbhtqXzABRuHSEyEg+iCACkpfl0rxgLc927tnVL63HVvGIfYD6MCoRVNeQZcAhAdA2nJk8NLemX0UUrWwIqXbo5gC1018ByxD7N/R33dvEHHWgkmtwDNo1PRCh8huq7fNCnaxCZbdSChwuWLVNRV4FuGsT0QgzX5U/ti+H5Fl46RdoxuoEH7hGgPT788sjdNDJJ4mKX4ABuuPZju6/VxWIWiQHIxHfOv8L0= X-MS-TrafficTypeDiagnostic: SN1PR12MB0158: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:8jeJKvry+NY4UzhMmFQyNR+28LMiXdKdabO6swr/Gd/EqnGPNygmyqdk5V3T85Ho2FCJRtTyDLXwSjh0JjXROZgKlagTLwjW8Ns/Ux7sEdqPR9dqANURnTqDtIVpcv2Tg/xNm8das9ALEz0Z0VeLpV2XF8St/H2AyLCG7xFP71ccpeZq8aMkbzHGz63/OXCgeqR48AvEwfX10I2gK7K9oSgMS4QAaQkjVqvO0tvhhlp/HN/SxWYH7DznRwnKOMghPyqg+zTIIXSgArEwECQnWAcDcSAPccj5I5Egzde4p20ROcgZDq3OOeBvNiM65K/HeimRjmdGzgUxYod4MXNr9XytmA+ON7jfRA4S5VDNuwbBSniwpLm0TrJdD15Z8d/8ytyxlF566WoaVfrfdiKMqTGqnUFuGTvNoxrNYOyKkcrlwx7THyEcgdqVz+BAPl1ci7hDGQ/eKL/V3vP0mxedA5sm2pKq7wM2d8vRvc754pF3Rw8HE2C4C+RNXmxSyq8V; 4:8AQm/MEwf3cMpJctkLQACh2XDr21dTGB25FGPOBCmpyuBuyfksSRpxwx9EiR0z9GqVnKMY2C3dY4G2xc8TVWXoHAxh+RmbTuZAD+wToa376qk9RWEK5fAKGSRf3LDtQteKFL5KGXxFkvRxtLsrGOkJXlawu7Vnubl4LeX+jIGC3MIjdEc46VU65tNe7TuY2r1sHhdSUof98iOfi2YLGTlTywBvp2koc0F+Z3oGV9lGDktE8NVhOPZMXzwFNeDE58JSfzsQZQ1ZoqY1sWNK1rK0jl2SJyoso95TfvsbAu6c8TsJxzHDMA9lC/YVk1QXI5+Or2bGvu/s1C8spp3t/F0A== 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)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR12MB0158; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR12MB0158; X-Forefront-PRVS: 04270EF89C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(110136004)(106356001)(7736002)(105586002)(101416001)(4326008)(53416004)(1076002)(2361001)(2906002)(305945005)(2351001)(5660300001)(189998001)(25786009)(33646002)(50986999)(76176999)(3846002)(6116002)(68736007)(8676002)(478600001)(81156014)(81166006)(42186005)(50466002)(54906002)(6666003)(50226002)(97736004)(48376002)(36756003)(6916009)(2950100002)(8936002)(66066001)(47776003)(86362001)(5003940100001)(6486002)(53936002)(344415003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; SN1PR12MB0158; 23:jl3Swse7Q5SXwJ877C/dGUxxWSwEcdJpenpDbs0WU?= =?us-ascii?Q?ZC5P1ANJ4qHkxJ+cHu3r/xbkXsNjqSAAeRDh8VRBX6uZ4K5lOwOaO1fH8Pu/?= =?us-ascii?Q?5oxcwKIhswfPTGUf6MVi3YDciIM1PNls0olI8ZNWkJQqsD1Djx7ugNU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FzOQmwR+MOo4c4QzLM+PPU243d5ZqA1F1EKyS7dDWnnUCC1/p?= =?us-ascii?Q?4H/zQU6UnpZqlAzXZ6m8oO2Z6FB9v2913AJZQhXUJn1SJmLww=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 6:NFikAyh+m/f62tj1pjNQ1JVWFme6f+R26SCzs8gPj/usDW/efFxreYsMmoQOhvtQ+0XXWwNU7IJPu1OTslhWd/fYF04CO3YnkV3M5aSxReU1UQmOFKxIx0VGZAgkG+nSryj8bA2/v16RhhitVMkVBIhOLStzPHSOrdvR5Qv73juuW0wqZjHlIZ7/crDN0MgVU6V6TITFroLfDqHnabwpisBCotcbC+h1LxVFGrEHAcX7b1wt1vwIdDNm/LrWc9fyRs9v8yhBctmVHBuzHgIGB/Mv6XyypRTjf0oXsu57rpLtkRMl5mGyw0havrBe7yb4wOdUVo/+VsXbV8wbjuuLeQ==; 5:64jKqb6MxU+u3SdtMaiYZRJ7jzb9sWoSMquMrY3/pdyEUYvm22ykebj5p8iAxYQkGx8+Hz4paSHjNYcSXldkJbE7GbgNW8zCt4kQX4209R+rxafXgzlfX8XkrZTakHVGf2gnGyrysTXNM8XrJIsSng==; 24:tzzygad3e2XtZd+KzCCrKEpniKWsSSaZFFD9ftJZKiFgace9FR7mWg4PcHrxVKXviZMoj6aYBwbdgnxq6CYYvqGlsQDP57fOWg6Paxhz6FU=; 7:U8AQ5dc1F0KVdqtv0gxdHLKd1U1LFNz7Y8RIqYbeC6djjHOmG+U/ZaTLd39M6IksbUu5A3mLcNx6H7LY8IQvUUlp9xjgqG1LZcVnESHfOdzBADgkQZg3S4BMKP7uFaiqt4+QSWlKGn+XpVkPdXq9Rz9tQlUkIUwdGgeHz/yxGNO+jsqW6IVt89Q0VXquZdnUvV/AOwlIlYSZFLj6100xAGnQLuKmA/8wdiE47drmvKA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:vLgoADEiDRXHXtTBJ9LhamVapxyN0eGADc9HrJ/y7W+504+NzfD8/PjToI/N96ykzuomDqnxzEXGsqNQFrLZloZy08Z547m1poB6Se0eCH7BzOWxttDmZRFGLKptoSSOrN8nMmIeAmt75pdG7Rbpmb/VNkvoXqxADJTOYuA9VxXERxYPYAw5nOSDfJEe5HgZNXzUZgH9T6XLHb56fsxeR2P4U6Nz5YQCR7MemN2gxPtj/qiXiVMmecLiUjgz1pZe X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2017 12:17:13.2296 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0158 Subject: [edk2] [PATCH v2 8/8] 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 , Brijesh Singh , 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 a8ffb9a8a7b1..4885aa73be15 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -560,7 +560,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 @@ -600,7 +601,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.9.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel