From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0078.outbound.protection.outlook.com [104.47.40.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 02F4421E3EA9E for ; Thu, 14 Sep 2017 04:05:44 -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=BYSsOhxPQoC3U/obmo+gGVGMlIdFQlQimbPyT+HxunI=; b=M1AG20EQg8U5l4lESgm9m1vGC4EvywYu5uK8UKmC49y/tGWd0PDbRyyRal8eOpT4PGsmEiEBS/bEksOF6z7P/KWqyr6NXhFf5IhB5pTKG6S0KfYDu+H7mzK3o9wwIlMBIBsWG8LmgJOCbEWYVF7NlCJNt+slNid1nqxUJvwhtqw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; Received: from ubuntu-010236106000.amd.com (165.204.78.1) by DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) 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 11:08:41 +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 06:08:21 -0500 Message-Id: <20170914110822.112540-8-brijesh.singh@amd.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170914110822.112540-1-brijesh.singh@amd.com> References: <20170914110822.112540-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: BN6PR08CA0083.namprd08.prod.outlook.com (2603:10b6:404:b6::21) To DM2PR12MB0156.namprd12.prod.outlook.com (2a01:111:e400:50ce::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a0d7cd39-7057-42ab-d249-08d4fb60f551 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:DM2PR12MB0156; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 3:MoZB/Ll42VHb61xyPbuXx16CQYH+K0EA4QwvKbDWvZkHcHZ3R596SB0UkbImSjslGIx1p0HNg8WhW+jomaBFOHOEZnco/V3IQoXQiVOZ5fmsDZZAWGQFVy7sLXjwjf+u6O9pucDze6Ws5oZF/Cqvg5YO6hcNpG4JmlDNOKfsPrFfhM2GvK7/4iOu0YEiH52GZCUGBjdRJJxjf0ILYk8mdqQBRdCyVUukw69qaFonT37ywxWzc6LbU9UmTLim2PIJ; 25:FsN+hXw99/Xd4wGtXu7HvpJ1g8VEuDl10ZKtPVlEmoHivTOY1bJvuBpvk4NQqOR+oUEK7Ss2PrJ6e/f/08Dn41wQhieILJfYdorgZr2SLACA4D007LuZEXcZjPNn47oe1PGv5pVbl6mGCRXVyFGD4r2Nw9eW5mZkl72CkSbSEe2d7sQ9x5Yvk8j+OVFOQEpiWt/Qj7L9VXvcah8aNPa0uGQcEFjubJAk24LNgjBIgEtnhesI9/fOafsOg+2W9k4IX7jiOQlPQ6CFCyv36isEJw7H52GqsjtcH02yK9eTLpKvSFMrM7i2i6tEmIvvyjZn9GAqg2roMeZzmoXMvs3bng==; 31:ooXGrxgZ5C4rVEkO8nb24yKFyuIGiT6ECSf36hDBsT7JQ3qdcYhlV9bTdfFy0maa4vST0YQshe1NjxsNA/u8COXsbDgFcSJT12J4OdXiJvJhmcKCu6TRJbnYvepL0Psx3prgV2nnqAnzZ0UKRcpFreH++4hnMjP/4B/rr61u85yK1s8w7JSal3xNdxfVfuC3MXc1S0brUbk+8LPTbX9qqiw8xEAJRoXbjbuLbsz5Lp0= X-MS-TrafficTypeDiagnostic: DM2PR12MB0156: X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:kwiKRcaOzrlqK03TTxwFpr8yjFFAZJay5l/13ZahQDnQssBxy1v1JToIWCz0NFL7yLevGlK2APOStv9nGu58nBRQydkUwzoyr/YB0OYSVjl7KhigXocujLMwk6AgJMbSveReGVHYrTjyrUF5uPirHYJYHLJSOJbhpIYYrPvKmGjDaYdXnDzoRQOzD2gdh9qba53Y53VIfB+yia6vO3jbWagWdGgwrStN2Z+9qkyv6AusPmQz1YrkBPkTPGaoDrHzjpyfx6xtb+vtYXRQFnTAFIa//tZCmBeFj6WoXZ0FVHEuzY49Anw3NWrIXnPufF05L/alzjeybWkXk12sDAG4H665clwkA4ycfSDgiNE3Cb4t6kgiHPcF3WTs00iiupbBlFq5wVvaILewdULY9cJdI7RIRvgHKRZQdQUtM9/XKwsmoK2EfuYQJYRJJ0S8Na7T42n0epWRskhsbfZyIv0vm/5lXR0OOm4MEn01JqhErth9GFT2Z7ASNpz0HFItJ0+N; 4:elCwjV8Qp3TffLUDvTzXHCIXzs/6s5bqm8Mdw/YCn2Ip6X1AjDyfSdafY2UShrn7Y0R8r1Eo4M0vJfSarY9cqpBRZkLPJ6HXDPYWqbifC0eJVDf89X3ULts42TK00u5x3pnZF+F9ZBVgkBhUDvbYzVr5vA2LeAW6gxs/GJOBLfBcREhmTxv0prcrYheilkGpxkuRzu5j1KC/i9SadCQcHBdbXNhEY1+Po2dJo6hprcmNCXkvABXNuTyXwEyn+Sag7yptqlNdpKiYpsG5ASlHqFkRIKLRK9Ai9sSiSkXBxBOM6lhIohMhZy19HwuakAsuQO675P/Eu7OCG52p1/7H2w== 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)(10201501046)(93006095)(93001095)(3002001)(100000703101)(100105400095)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(20161123564025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM2PR12MB0156; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM2PR12MB0156; X-Forefront-PRVS: 0430FA5CB7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(39860400002)(189002)(199003)(189998001)(50986999)(76176999)(105586002)(106356001)(33646002)(2361001)(2351001)(5660300001)(6666003)(6916009)(2950100002)(6116002)(25786009)(36756003)(1076002)(101416001)(68736007)(3846002)(53416004)(16586007)(6486002)(478600001)(97736004)(50226002)(110136004)(81156014)(47776003)(48376002)(16526017)(81166006)(54906002)(8676002)(8936002)(7736002)(316002)(305945005)(2906002)(4326008)(53936002)(86362001)(5003940100001)(50466002)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0156; 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; DM2PR12MB0156; 23:OfsKccVk6gqmmi1Bj6gEkytgt0UeNg8dUJIuORtHB?= =?us-ascii?Q?CQu2/DXRr96rY7fED0Cp4bEHULA7RcBCUk9dTUR4I79emAsxaZgpvT6kkjHo?= =?us-ascii?Q?b9K5a4DUIVs0Lhw03N7ZyCQNCufZr/pVQ/b8Al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x3HwkiRn0cCEYm5KpV+cHgj8YGs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0156; 20:ON4cLo5YYg1Pnu0S1YCHh2GVn82GWB/aEX7rt5swtW6XniCNE+VhtpZqHlpF73H/htH0wxXz/9bJbRM9SnsMKhrS70sKgLehG20RcUmsuaeyrT4IE1/7RPUdPgyOg0bF21KWgBckMZ9iSMyzk4A4nXVy18Y7bY1KYRygwX7l5bL0Prw3abv7HaArjnEOBDzscU950FQNdmFzcO3vd3CCIoGXRg2J8VxBB6jOH/uLsizDOrWBQFuj4UIATejAc4gx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2017 11:08:41.1044 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0156 Subject: [PATCH v3 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 11:05:44 -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 | 41 +++++++++++++++----- OvmfPkg/VirtioNetDxe/SnpTransmit.c | 27 ++++++++++--- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c index 694940ea1d97..f817b98801fa 100644 --- a/OvmfPkg/VirtioNetDxe/SnpGetStatus.c +++ b/OvmfPkg/VirtioNetDxe/SnpGetStatus.c @@ -61,11 +61,15 @@ 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; + UINT32 LocalInterruptStatus; + + LocalInterruptStatus = *InterruptStatus; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -113,11 +117,11 @@ VirtioNetGetStatus ( // *InterruptStatus = 0; if (Dev->RxLastUsed != RxCurUsed) { - *InterruptStatus |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; + LocalInterruptStatus |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; } if (Dev->TxLastUsed != TxCurUsed) { ASSERT (Dev->TxCurPending > 0); - *InterruptStatus |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; + LocalInterruptStatus |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; } } @@ -141,17 +145,36 @@ 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); + } } } + *InterruptStatus = LocalInterruptStatus; Status = EFI_SUCCESS; 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