From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0070.outbound.protection.outlook.com [104.47.38.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CFB1421E3EA81 for ; Thu, 14 Sep 2017 14:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=h3v8vycHivgC4/w1PADHLrkPuoeb2TgbS2TuDxtCNbY=; b=k28ZaHqUdlHBGYbuft3QFxFZE7jrJp89Q/e04smZqReR+A8Zw2uuyaumo2dcNshEYE06uLVp8tLgs2jk4fhnVm91qZlRkyX7uPECcpfjB80EUNQRwcaIYdMp/FOnZgc1GLQv3EBzFAOcl9RkkAvPrNtcF3lbJAaIrgDvPJypnbc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from ubuntu-010236106000.amd.com (165.204.78.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Thu, 14 Sep 2017 21:23:00 +0000 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek Date: Thu, 14 Sep 2017 16:22:46 -0500 Message-Id: <20170914212247.124937-8-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170914212247.124937-1-brijesh.singh@amd.com> References: <20170914212247.124937-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR20CA0014.namprd20.prod.outlook.com (2603:10b6:3:93::24) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 217a70b7-1154-472e-045d-08d4fbb6c6ca 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:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:R8lOfhmE2lvOd3PtnlM6WFEUJ7MxpbVPEDyxP9yQCjTBEjS0kv6AFiZ3qk7aHuj1O+m5qHKQTZMX3759S/wU871YwYYAAFQh1o9pv+6cEcmhifL/krIjcfUa13sN4aldidVaA2jdvU4aX8BniN25WNVRHWinJn5g/Ohi+0MPUYh5RtRmJFekBrqLA6MPAAQTbo2J2cYEps4pHMqhaA/Zd6kf9/lNyJnI5kgUQZZ+AN0MYdXQKwDMgJZIGXGEQUKx; 25:NtDBPcpYkvFRuNfSMOtsjmkf00DN5PY7qyoXGdMRnKM77zGF23KkB428FeHFZVmEbsUoeIvL+bMzc4pA3jOOwjEPoPWA3Uhv7kS6JgT66IILSsR86Sv+xNir7g+4JXWjzavj24GH0TttFdbwGSxJd72epCFZN2gl4tr7Fw0osMt0Tyk+HOXjqdgQDYDaqd56G3JJh/XgA4xzOYQYoAjXcDHji1Sn1vRKsbFzYVg8Y5BqZ3RnqB7+/97Y3exgCGHE32kGZWUyKHLt3+5lb35rr/yWrQ0BI8qP+4hBMIzgi8/Y0mCHVu90nXhFsmy38oQlN9WcMlnlUiJGL95xr+87MA==; 31:DbvLnQlDDsYQf3/K86yRk34VZH1ju0YQXjV0ESqR3iW77LUQTlg4qSSW3KOIcECfwAHZTCzTK3Hobb6xMLNyBPatUv0CV0exdvrfuKf0gO0h9mzxMypXqec8G4cufDqwqiT1xOzgmABmRJc0UI337rYdiVy0PXdSVcsJOpgmjqGSfPQI73CGZGw4SB4hmM/3uQUBnqM1ghLxu1nzBOW3kKi5l+l6RaJuicYKOivzHNI= X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:9lDvGOhp4VStYN3OsKyWS5Ux37pKC1yE89p+pDDw0Q0Ru/QP7PNpRNZqkSSzAQ8HRNA8oNIjMQygj0PXW0wvWL2zpmoFGCu5YqR/6aJdfdj6kroqmE/6CYsbHwKuYMVFiHYVxTp8Pxxspp9FFeShktlDITyIST8RavXAJPm4iqNSka5fbr7ly4zck80lMTZ03ezKK5RsChICIKjh5J942OrKgRJvL3pDNAXY/MUecoDPVVXZT4HN4LK1Aworg6TRKnFdzhotPgA5KYSXeSTJ0T6um66XQI/hMcMVfvbeJ6cg+FbJNWgp+VT2e3tROpUIOOJxn7ksyH1lda8wfZ8ntWZJmETqh7pMlKGWdzbJMLBwQno5l7flclGN/UBG+duM7Hy6L9Y8UfwK1kyBKKaM2jqy+z6owh3KnIOotFzKskFPpXWJYA3tyqIdq0vAa+7r+D6MKk8tY/glU3Ffd3oojCtc4tAsI5/XzXL0o11Hl10S5EjOb46c/bjLwocb+xB7; 4:AngBwnCwZvErDOABGaYRDcCU4gWYzMNfZYA42eBYoNQ88xI6mOpq8DxdtYSvqF1lX9pdQN6ZP+sE/5pTStGnBulK1pe01U7w6i5o8BHpBFxMaQtjjjiKROgrWqICYO2L721n4yguq5Wrd24uVlBflIUT9O81TwS4SQnuRyrYx3kZHc/Cpq4uQkHEgJFQr18T1AlUDE7vFhOgR6SZHQRNgFUVdk8qWAg0bYqQrWgFzGZpPoWswfb24H2TpTIQD0swZgTUHdWz7TiJpQgx2K/Bc56hscVTaYHjpUHOJiAbRqwkAEqP2nsv6iefDT3fx2bTwggySEdEKYNSLq0NsHq4cA== 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)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6041248)(20161123555025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0155; X-Forefront-PRVS: 0430FA5CB7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(346002)(376002)(199003)(189002)(53936002)(4326008)(110136004)(50466002)(47776003)(50226002)(81156014)(81166006)(68736007)(54906002)(8676002)(2361001)(66066001)(2950100002)(6916009)(33646002)(2351001)(36756003)(106356001)(105586002)(53416004)(101416001)(48376002)(8936002)(25786009)(6486002)(97736004)(305945005)(7736002)(5660300001)(16526017)(16586007)(2906002)(5003940100001)(1076002)(6116002)(3846002)(316002)(50986999)(6666003)(76176999)(86362001)(478600001)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:ubuntu-010236106000.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0155; 23:I/SubH+prkYBlFELzcv1S+lrg8OHwetNdb7G4sclW?= =?us-ascii?Q?VrFIf8e/IM/2jFM3GtMxJVJYwvJAYN+xGfSWmBeuR+VDIquWRSZYZZ/2M1SM?= =?us-ascii?Q?OLWtVwomyIrcxtBeQa6allijjl1DdPzx/KXAOkqZuu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6EmwLxQz4w0EhPNU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 20:/KCFb+HOf48lIheuf9dQ55/0v4pnxJTiOvqBlXUnyhQNM0IQOL/CNZzIp+EbYYI+LLcg2+ueEgMwcf6vzu9Ewq/rH4Y7y6/VRKZDHJQXPV+uvl+tZc0z9WSKu6mJZPOL0Bz1ohUXM08qxaveZ5N8WeRFfVVMiaVnya8dFIHjtYYx/D1+juW6qtoYdBXSpsHxeobatBMt82+K2mOZb7pE21GEsgUE+7HyuLCSRNQ/s/ujWsVwbdWd4N9GIylZ+C4/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2017 21:23:00.1330 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [PATCH v4 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: , X-List-Received-Date: Thu, 14 Sep 2017 21:20:03 -0000 Content-Type: text/plain 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 | 35 ++++++++++++++++---- OvmfPkg/VirtioNetDxe/SnpTransmit.c | 27 +++++++++++---- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c index 694940ea1d97..9b1c352227b3 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; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -141,14 +142,34 @@ VirtioNetGetStatus ( ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1)); // - // report buffer address to caller that has been enqueued by caller + // get the device address that has been enqueued for the caller's + // transmit buffer // - *TxBuf = (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr; + DeviceAddress = Dev->TxRing.Desc[DescIdx + 1].Addr; // // now this descriptor can be used again to enqueue a transmit buffer // Dev->TxFreeStack[--Dev->TxCurPending] = (UINT16) DescIdx; + + // + // Unmap the device address and perform the reverse mapping to find the + // caller buffer address. + // + Status = VirtioNetUnmapTxBuf ( + Dev, + TxBuf, + DeviceAddress + ); + if (EFI_ERROR (Status)) { + // + // VirtioNetUnmapTxBuf should never fail, if we have reached here + // that means our internal state has been corrupted + // + ASSERT (FALSE); + Status = EFI_DEVICE_ERROR; + goto Exit; + } } } diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpTransmit.c index 7ca40d5d0650..b39226e138b9 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; if (This == NULL || BufferSize == 0 || Buffer == NULL) { return EFI_INVALID_PARAMETER; @@ -144,10 +145,24 @@ VirtioNetTransmit ( } // + // Map the transmit buffer system physical address to device address. + // + Status = VirtioNetMapTxBuf ( + Dev, + Buffer, + BufferSize, + &DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status = EFI_DEVICE_ERROR; + goto Exit; + } + + // // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device // DescIdx = Dev->TxFreeStack[Dev->TxCurPending++]; - Dev->TxRing.Desc[DescIdx + 1].Addr = (UINTN) Buffer; + Dev->TxRing.Desc[DescIdx + 1].Addr = DeviceAddress; Dev->TxRing.Desc[DescIdx + 1].Len = (UINT32) BufferSize; // -- 2.9.5