From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) 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; 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 From: Brijesh Singh To: edk2-devel@lists.01.org Cc: Brijesh Singh , Ard Biesheuvel , Jordan Justen , Tom Lendacky , Laszlo Ersek 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 (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/+4ZdrM0gc7DQLkKKuj/BqUeHyzVqEmlgRrb56Qd/JehezNIK2HQzi?= =?us-ascii?Q?7HfLQK20UwnldyAwBp7tI2kUySvyle977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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: [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: , X-List-Received-Date: Mon, 11 Sep 2017 12:14:18 -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 | 30 +++++++++++++---- OvmfPkg/VirtioNetDxe/SnpTransmit.c | 34 ++++++++++++++++---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/SnpGetStatus.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; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -141,9 +142,24 @@ VirtioNetGetStatus ( ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1)); // - // report buffer address to caller that has been enqueued by caller + // get the device address to caller that has been enqueued by caller // - *TxBuf = (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr; + DeviceAddress = Dev->TxRing.Desc[DescIdx + 1].Addr; + + // + // Unmap the device address and perform the reverse mapping to find the + // caller buffer address. + // + Status = VirtioNetUnmapTxBuf ( + Dev, + DescIdx + 1, + TxBuf, + DeviceAddress + ); + if (EFI_ERROR (Status)) { + Status = EFI_DEVICE_ERROR; + goto Exit; + } // // now this descriptor can be used again to enqueue a transmit buffer diff --git a/OvmfPkg/VirtioNetDxe/SnpTransmit.c b/OvmfPkg/VirtioNetDxe/SnpTransmit.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; if (This == NULL || BufferSize == 0 || Buffer == NULL) { return EFI_INVALID_PARAMETER; @@ -144,10 +145,29 @@ VirtioNetTransmit ( } // - // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device + // Get the free VRING descriptor // DescIdx = Dev->TxFreeStack[Dev->TxCurPending++]; - Dev->TxRing.Desc[DescIdx + 1].Addr = (UINTN) Buffer; + + // + // Map the transmit buffer system physical address to device address. + // + Status = VirtioNetMapTxBuf ( + Dev, + DescIdx + 1, + 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 + // + Dev->TxRing.Desc[DescIdx + 1].Addr = DeviceAddress; Dev->TxRing.Desc[DescIdx + 1].Len = (UINT32) BufferSize; // -- 2.9.4