From nobody Fri Dec 27 01:55:39 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 1503880510703743.4209235843217; Sun, 27 Aug 2017 17:35:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 756CF21E47D67; Sun, 27 Aug 2017 17:32:27 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0084.outbound.protection.outlook.com [104.47.38.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5E63721E47D58 for ; Sun, 27 Aug 2017 17:32:25 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by CY1PR12MB0152.namprd12.prod.outlook.com (10.161.173.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1385.9; Mon, 28 Aug 2017 00:35:00 +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=3kKQidZ603+thjiE+LTjT18yhcsMXrpW8XGgap3AgG0=; b=UC7qKoOuff9ZSpUUPKOBV6KSCnscDR2JCTsQkU0hvTQ887My9ue64QdA2TKyQ2LnHOZFsXtgkCKNEjbq/GD9Xowbgtt/cwRaIA9eXkzSS+T/UcQAAeLufo94yWeSzC+wD2IrWLrj+fWbzx7Ctq6DBoS8COcmFsdcOamO2JD02IM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=brijesh.singh@amd.com; From: Brijesh Singh To: edk2-devel@lists.01.org Date: Sun, 27 Aug 2017 20:34:27 -0400 Message-Id: <1503880469-15999-2-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503880469-15999-1-git-send-email-brijesh.singh@amd.com> References: <1503880469-15999-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR2001CA0024.namprd20.prod.outlook.com (10.172.112.162) To CY1PR12MB0152.namprd12.prod.outlook.com (10.161.173.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ef78601-fb26-49e7-6b5a-08d4edac9e94 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(48565401081)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:CY1PR12MB0152; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0152; 3:tNPQDrVUDzHm9NRnooUPbFkLVDkwAQ+W7jxN5RYZuect1BCZCxYdr0QpTJaPH+aDgRK6vC5OmPwT65qsttghc06F9fhPNGUqtOZCtboBdcZzda5NSulWu92SzkXkbFZ22ZvtuBHUIyiPe27ppaV3Bj/b8FsiPYo47DXoN3BZwqIMX5ClVQtwfGRlWBRRuyJ5qfixmQeAoUw59ESURX2usUJwOloYIT/xqmMzUqZfhhMnbg8gI69ac1yJjgUMbI8s; 25:00q6bIgQwdr2pMQY1qaAHDTbyE+2l+nwRnMU743LKkhXp4DIY1qdchz/3xXj2GWserw+XCOGgWrZBUH5SJXr1XphIu2SGnJDCV/afaf/Ak9JgokLaT8SVC8quWW0+sc3OKZM9xQjxCbF60GSdcuEiQuWMybIDPH3b4gzbeAtAMiMPwp5KJzoHQ+yT/IgZ0yH77AJhbrj6XausYu/I/Iwp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11mO80eM3ZVX/6XZOwXI/2+cxVpFgcC31TWjJndBcXlw64C7jFwXXzgg4+G+94PSnbuZMywT+w7aCWsA4UHxBUqE0JNT2vNcJlK5lDu061aiIfodWJUqUUhqcsZrv3WIjqVsDGIzpB7mMLcZlkAlTMtpRFsyx11KExXqQTSnIXQx83B3b0S43yC3ivaCBfERQEHSQxUo3pe/2X2EP60T0eS51fMQbAI/IyCqG7m2dJ0lA== 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)(8121501046)(5005006)(10201501046)(100000703101)(100105400095)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123564025)(20161123555025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY1PR12MB0152; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY1PR12MB0152; X-Forefront-PRVS: 0413C9F1ED X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(189002)(51234002)(199003)(2906002)(53936002)(6666003)(25786009)(7350300001)(478600001)(36756003)(2950100002)(76176999)(66066001)(47776003)(6116002)(97736004)(4326008)(6486002)(81166006)(8676002)(54906002)(81156014)(48376002)(110136004)(5003940100001)(50466002)(305945005)(6916009)(53416004)(68736007)(42186005)(2351001)(575784001)(189998001)(7736002)(2361001)(50986999)(86362001)(3846002)(33646002)(105586002)(101416001)(50226002)(106356001)(5660300001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0152; H:brijesh-build-machine.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; CY1PR12MB0152; 23:aZULCmRIRkeRi75zkJPEk/HB5z5Emi+iyvxlKqKyi?= =?us-ascii?Q?MIjIYUBKg51iY0DsoF8GbFYF1pbKxKxhDY2cqlVJMgqxjIrpU2NIgA2LkuWl?= =?us-ascii?Q?tly6qNvRHS5H0GV0QlV9L+Twb5xJxMqWCTdUkSG842HUA237nfOExALJaCAm?= =?us-ascii?Q?tme2u7sm6HOb7mlIE/HsLpTahnN69iC/NTLA71CxRob9D5roQcC1azArki2s?= =?us-ascii?Q?noQlBGreg1uieGcX3oDLdGhZe4KkPFQS4h/yTSuNg4ddnUsl08tTI/RO9+fi?= =?us-ascii?Q?hRtGRxb3HBuPrwONuMODjOl6lE9/NsNWnUlSFJCBLDZcmQfaJhJM8eTbNmpu?= =?us-ascii?Q?0roS4vqw7jBehGLxofyR/t4BqLqqoVsa/R1RCVBFPqWsUPhneM5oJZxZfoUg?= =?us-ascii?Q?G8HCTWA6lWHhrWhfu+tfK6gz2dBzLB6ZpZOvNr/fryyi6n36eJ/fYn9aNsAy?= =?us-ascii?Q?AMo1qYFaawcBDfr+ngcbdU2nDRMqXxAc4VvE5BniTN2MlUsXb9vPmPOfVYhT?= =?us-ascii?Q?0Fl9RQ7onpLxTq6XmMJ+AQP3y1tuhheM2bH4CjDcpW12z2KLKrikuYcv87Qw?= =?us-ascii?Q?V5YXAOAWaco2ik8YWp2uoYsNCLImZgBuGSgKYTU0QZ5b/auYsBAPFiRHw7xZ?= =?us-ascii?Q?nM3MAbYVdrFjQcyme06KdF1AGVJ4K4XFEE7EPD4PKmL5jItKuyVp7ROAqItC?= =?us-ascii?Q?5FAFT2ytpm/LKd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QfMSeY4hLD6+9e1YSH0IWQergxOvy5/tsI7bMdw9R/ygzP1NGDVFwFya9xdV+4ggy03i2Q==; 24:CzVIxlAbzy/Xo2flKgfMTMvMl/JpHUF95DV/l/DbTCd2PD2MKI6mEax2RfpS3x3hciRh6drGXVRa1CTYAvsH+DQ4xI7ac2pr65TP3q0uZAQ=; 7:i92Lg5JZJRwOi6g54faE8uOgHCR0/ZOZv0y8qK/MIsBhiukm1y3/qtVYE5LkrdHsEGihjlIVmnlc1zF9Rnt9jK96/zk1h167X8zJhOyZUwDLIMn+9yPhGUGPtDZFHxiiDKWLtHqRLADRM4iSePoK6wP3leLgfNGTZNPHYkmNHwRSYEsgGD4Ext22bOECm6LOjA3nzC1L9BejDS5N48FJKFLJ3/j/3iCTokPMKh/e6L8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0152; 20:zx5E3/Tic+E3tZtdh5iXNopVW+Zfs81nt4xYX5Jilp2t3XGtRTDwr3a+3IWJqQyXknurRU4LaJjc/oslZlaUZfVu7zpz6yjy1W1bpNzJ8l/uXgkj5+M68ytTNznJjTNAmCYncniDMYqoNJ590d/XruOHzlF7QL74hfi5g0VQU0R5ZN2ldKTIE/eNRZmUVHuG28xpQo/6FIBfyXRxK97IpGLBBCeklnXc5F6ZWYuqIQRtpUeLKSkBDM7ajrfeFwxA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2017 00:35:00.9579 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0152 Subject: [edk2] [PATCH v2 1/3] OvmfPkg/VirtioBlkDxe: 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 Signed-off-by: Brijesh Singh Reviewed-by: Laszlo Ersek --- OvmfPkg/VirtioBlkDxe/VirtioBlk.h | 1 + OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 45 ++++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.h b/OvmfPkg/VirtioBlkDxe/Virtio= Blk.h index 6c402ca88ea4..9ec0b956b818 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.h +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.h @@ -41,6 +41,7 @@ typedef struct { VRING Ring; // VirtioRingInit 2 EFI_BLOCK_IO_PROTOCOL BlockIo; // VirtioBlkInit 1 EFI_BLOCK_IO_MEDIA BlockIoMedia; // VirtioBlkInit 1 + VOID *RingMap; // VirtioRingMap 2 } VBLK_DEV; =20 #define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \ diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/Virtio= Blk.c index bff15fe3add1..663ba281ab73 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c @@ -580,7 +580,8 @@ VirtioBlkDriverBindingSupported ( virtio-blk attributes the host provides. =20 @return Error codes from VirtioRingInit() or - VIRTIO_CFG_READ() / VIRTIO_CFG_WRITE(). + VIRTIO_CFG_READ() / VIRTIO_CFG_WRITE or + VirtioRingMap(). =20 **/ =20 @@ -601,6 +602,7 @@ VirtioBlkInit ( UINT8 AlignmentOffset; UINT32 OptIoSize; UINT16 QueueSize; + UINT64 RingBaseShift; =20 PhysicalBlockExp =3D 0; AlignmentOffset =3D 0; @@ -729,25 +731,42 @@ VirtioBlkInit ( } =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 =20 @@ -758,7 +777,7 @@ VirtioBlkInit ( Features &=3D ~(UINT64)VIRTIO_F_VERSION_1; Status =3D Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } } =20 @@ -768,7 +787,7 @@ VirtioBlkInit ( NextDevStat |=3D VSTAT_DRIVER_OK; Status =3D Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat); if (EFI_ERROR (Status)) { - goto ReleaseQueue; + goto UnmapQueue; } =20 // @@ -811,6 +830,9 @@ VirtioBlkInit ( } return EFI_SUCCESS; =20 +UnmapQueue: + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); + ReleaseQueue: VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 @@ -849,6 +871,7 @@ VirtioBlkUninit ( // Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0); =20 + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); VirtioRingUninit (Dev->VirtIo, &Dev->Ring); =20 SetMem (&Dev->BlockIo, sizeof Dev->BlockIo, 0x00); @@ -885,6 +908,12 @@ VirtioBlkExitBoot ( // 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 is reset. + // + Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap); } =20 /** --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel