From nobody Fri Dec 27 01:47:36 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 1504191695165986.6717731880572; Thu, 31 Aug 2017 08:01:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 729662095BB8C; Thu, 31 Aug 2017 07:58:49 -0700 (PDT) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0072.outbound.protection.outlook.com [104.47.37.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C0FB521EB529A for ; Thu, 31 Aug 2017 07:58:46 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.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.1.1385.9; Thu, 31 Aug 2017 15:01:27 +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=8TPLJy9hunbfVjG8Dln5pVSIVO4TxqJb1NwqWSMnVYM=; b=vKRWaPCPqqItzdZFwUYWiXEGPzdilWAcMd42EPekSMkia7p9EgGGV5cE5UWEI2UKT5wJEyg0HB0vNVPrl6qTvt3LWSz0WYUCpzoOsaAYNW/pTcFACWWK0k/+HCVK5WSzNX3mvaU+VlYY3R1PHxXKs8wryISNC7ddT4zM94GbVIk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Thu, 31 Aug 2017 11:01:11 -0400 Message-Id: <1504191674-3949-2-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504191674-3949-1-git-send-email-brijesh.singh@amd.com> References: <1504191674-3949-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: MWHPR08CA0056.namprd08.prod.outlook.com (10.173.236.30) To SN1PR12MB0158.namprd12.prod.outlook.com (10.162.3.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 672ecd67-b034-4fdf-62e8-08d4f0812861 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:SN1PR12MB0158; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 3:92gGUaE1de+9WZTnuk6R1GWeXLHtBV4JRpJbSQHoXaEy8HfeDtNorsX7zlBb/KmZ1oXiQLb8URLvBgpm+g2r/QpEQaScaF84HoKqIYr6OBNKUHU2wbJtQoQO0ih99Hm0YfEyrPFXEzmUZx3MI85Er2v1UsZi1jUUEbFIeam7LSExFdCJR/VNSQytLTXhtPmLVKSZzszqcZezHDrxEAXMrVmwMsgoj4xONqzpDjk2lS2NtM26F1gzj8zhl2KM+mm1; 25:sxS+bq4LfbzGVUehEyGcuAOJXh+NdlAgOSRj7/MSR04AucUK76v+plDt5IUm5vTOl0mixek5XZ6tYAmndZ4Nza1jFYmnZk0fLkw+rWIkpDKbeUxsPBMMUqEF6pLN6pPdWIV6H4JBZTguin6CRdVeD31KWJk47tcQ/BEuxDRquDzqNrVR3MaFnXtdDHXSQZRWe3bDPLwVkHL48sY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WhE6LTXlEnALBiovTLQLJEu/skL9TLgQCV2+DiBu0F/h3BbE+RZC0o7z4zxxOZ9OTDHXH6U4iWTihbf2fcvXSdbtxQvvA5+fCI/GjblVFxoEAMvalrN+jK58cC9yCdNTcgR9ZtSR+/diicLy8G4sN2+S2yPKe4lTrDbp+NsR/RXWS/iuDOyp1bJaV19WirA2W/TkVghgaFPXWTSAA== X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123555025)(20161123564025)(20161123562025)(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: 04163EF38A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(51234002)(199003)(189002)(81156014)(8676002)(478600001)(81166006)(5003940100001)(50226002)(76176999)(8936002)(4326008)(50986999)(2361001)(110136004)(2906002)(2351001)(189998001)(66066001)(106356001)(105586002)(7736002)(42186005)(53416004)(54906002)(47776003)(25786009)(97736004)(53936002)(33646002)(101416001)(305945005)(6486002)(6916009)(2950100002)(48376002)(3846002)(6116002)(36756003)(6666003)(5660300001)(86362001)(50466002)(68736007); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0158; H:brijesh-build-machine.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0158; 23:P4E4t/5idi9vt/Y1Ab/3KOy1WDqEp1g0uZTz7l2He?= =?us-ascii?Q?nb/bpjnwgxFGoTgV3YWvLEbAtjE6qrNR4+X46AjogSgodOOmGCpU+QwlBlF3?= =?us-ascii?Q?aEB8qe61Am2r509KLOVmrF+C8ZnfL+JiWOaH79fE7LRfkzsJRFlNgKgGGrc8?= =?us-ascii?Q?ebBgL3NiETXs7QGUU+HQtr/5e+gGEHs2JIcVHMOGDX4lGm5vzN00BJRi0oOC?= =?us-ascii?Q?ROKE7HU6hFjD5cHxDMS7vu+AWS6Q1+QxAsvrzXU1jI/yDeA+MgSDcxFl+ZEN?= =?us-ascii?Q?6xO3QnTjvfbYw1BuP5SQp9lF0qyhnbIh5fwy0bHrnrJLNmoJJuymyGORtp7x?= =?us-ascii?Q?3fMvP3EZMxEctNe16/gxJjWEIfAY1FhOn/I4U1yRR5EAEFlYmvMsfV5sU51S?= =?us-ascii?Q?Tu3Xy/KxUreUcCT/SFB0HbHLL9uSIB03O61/4SX/q+v4vVsytogFRfFZeTgR?= =?us-ascii?Q?D80zfa3LUn6k3b/c1DrqgGBrHMIB5D/GMnXLkvBqvmxBSB4lBfBcAm4OrLAJ?= =?us-ascii?Q?7Nz2hSNSpd+ziCFhviR/5IrqFAVhhMNseYpaSxOHbUx0qm4qJVkB9ruQ3p22?= =?us-ascii?Q?ynyjVAwqHsAEdPu7fLYOJ9r4KX1zObx5mN5yMIqNiOpjsHyYeBg+TnlC9GUa?= =?us-ascii?Q?XpXw+zFg9ov+taKztzTkdTFrhQ6aqCuarfG7r6n1ier5G/2fTXO/FMYglrAb?= =?us-ascii?Q?EMtPZ7xT6rYcN48j0gfuDeoN66Dy8u1fERKuqW8b2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ZuNeU9nzbTHnK4mYpNybMbW2jv5FfLlceqk04qe+Z5TrYWb1rHTZsRNCdWak42lQyvik=; 7:u3hDJfitqwakYZn07MWLWlYfuVedS4HZx1xvXzf5Wi0K9mVWjhIXXxpqgRevMIE/2hrUXuDSrO04sRHZXfN5pfWrSA4aW2y/GOc1n6CUoJ4RNJL90q2jg0X9AGSGrqCaQ4TkF8HekuJNDc3OEtQxZuSLliQl12+s2TwmyuLyzsincakwGK2nSTC/Ax49J22wBVzzjZHrS62k0CxMXeRkK3nEHvDJRckK2iflMYMt6AM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0158; 20:fxhi6EImPdMKpVWKBQG9Xlz8X2mLe0Ao42SnqI6lrPMOjrp+MGrr3bcjCj7ybbWSQwzKs3Fubu0NjI6H5EwQfJuHCcjl5hCCQysT1ictLd6hoYhulcw01gE2ZtWfjH24tD6LMEPGTyJvNs5riczaub///G6si6GWSvj7HavDc7uyW3JUpSxQpX2NkaEvUwHvGotvPw2AOuS2EHGPKMVTItcbXhXNYAwnsbZ8KNe2uZnkAqZMTXeRk2Q3YfksyUdo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2017 15:01:27.7188 (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 v3 1/4] OvmfPkg/VirtioScsiDxe: map VRING using VirtioRingMap() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Tom Lendacky , Laszlo Ersek , Ard Biesheuvel Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When device is behind the IOMMU then driver need to pass the device address when programing the bus master. The patch uses VirtioRingMap() to map the VRING system physical address to device address. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Tom Lendacky Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Laszlo Ersek Signed-off-by: Brijesh Singh --- OvmfPkg/VirtioScsiDxe/VirtioScsi.h | 1 + OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 47 +++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h b/OvmfPkg/VirtioScsiDxe/Vir= tioScsi.h index 6d00567e8cb8..05a6bf567263 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.h +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.h @@ -60,6 +60,7 @@ typedef struct { VRING Ring; // VirtioRingInit 2 EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; // VirtioScsiInit 1 EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; // VirtioScsiInit 1 + VOID *RingMap; // VirtioRingMap 2 } VSCSI_DEV; =20 #define VIRTIO_SCSI_FROM_PASS_THRU(PassThruPointer) \ diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/Vir= tioScsi.c index a983b3df7b9c..5e72b1a24b59 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -707,7 +707,7 @@ VirtioScsiInit ( { UINT8 NextDevStat; EFI_STATUS Status; - + UINT64 RingBaseShift; UINT64 Features; UINT16 MaxChannel; // for validation only UINT32 NumQueues; // for validation only @@ -839,25 +839,42 @@ VirtioScsiInit ( } =20 // + // If anything fails from here on, we must release the ring resources + // + Status =3D VirtioRingMap ( + Dev->VirtIo, + &Dev->Ring, + &RingBaseShift, + &Dev->RingMap + ); + 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, &Dev->Ring, 0); + Status =3D Dev->VirtIo->SetQueueAddress ( + Dev->VirtIo, + &Dev->Ring, + RingBaseShift + ); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -867,7 +884,7 @@ VirtioScsiInit ( Features &=3D ~(UINT64)VIRTIO_F_VERSION_1; Status =3D Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } } =20 @@ -877,11 +894,11 @@ VirtioScsiInit ( // Status =3D VIRTIO_CFG_WRITE (Dev, CdbSize, VIRTIO_SCSI_CDB_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } Status =3D VIRTIO_CFG_WRITE (Dev, SenseSize, VIRTIO_SCSI_SENSE_SIZE); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -890,7 +907,7 @@ VirtioScsiInit ( NextDevStat |=3D VSTAT_DRIVER_OK; Status =3D Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -926,6 +943,9 @@ VirtioScsiInit ( =20 return EFI_SUCCESS; =20 +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 @@ -965,6 +985,7 @@ VirtioScsiUninit ( Dev->MaxLun =3D 0; Dev->MaxSectors =3D 0; =20 + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 SetMem (&Dev->PassThru, sizeof Dev->PassThru, 0x00); @@ -995,6 +1016,12 @@ VirtioScsiExitBoot ( // Dev =3D Context; Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); + + // + // Unmap the ring buffer so that hypervisor will not be able to get + // readable data after device reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); } =20 =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel