From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.56]) by mx.groups.io with SMTP id smtpd.web10.11092.1631289527009156787 for ; Fri, 10 Sep 2021 08:58:47 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=R8NADrDy; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.236.56, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NNHW4VQ7MTUsMqvl05IfaSg2XeNSQckixRMtU+bFkn3Tgrtb+9fyXX7kHPjyCRyBYh9R8WTddf+7+U9Sxoai/0BYO6JtgsuvaTg8E7PLmaCeRFRU9Z16Fm9tI1YE0xvck6BIxMJj1h91LVQ3YOJ72wa9PBi24jQttPdcjaHk34c9Q82ejMHqFy8nwAKjO6hDIoF2RaUEX9XB/qG36ih0uPPecENviQOTi1sVELp/DpJvcXkl1ldq/gnQ7+LFegGxyixXwDADmABp4LCXAQRyy6PAZi4ERWVITgVMhOMkA6F3qqmguuI2Qsk68g3vl54wvgDgyLOAAfUQylBSIDQAFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3OR8is0bQAhuWYqB0in8YKrNMXgZavkwSPY9Ne5gf7E=; b=dh9UGASoXHfFyR6tvpTcL5V7qf0dU1/Ypeu9YqLauOp73LRbiozhxaBhP3GNKerOKg8atZdaZgRBA9tWiw+teBoBgZJQiYHeH63NTER4SlrPSiRS3w9unLYORqGVzeGMv154Jhf42XKhfRQFYiyqMZ9O4nULieEkekN08myxx4O2/IJ9hZav2M4gTtNqXR+3vAiuguG3Lg402qjS/J4ycxRcijP3G/u/hINOAwm2I2ceTGIXOEafkTH4MIU/gqNXpCgUJvW/XPCnMU0nwxSsDMcx8dy0Qj0AZ9vo/1cMF5IO3KC9gQ3V3d5CtzM48lt+SUHKn8qi1kG+u8QJ4jRnCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=gmail.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3OR8is0bQAhuWYqB0in8YKrNMXgZavkwSPY9Ne5gf7E=; b=R8NADrDy8tBvIVSmnNKI+FI9MLhba7yac4tkkeAiLZpsK3b37vKHrLR9BuEA/Ow7eUS3TDB767qosLabIxbGLC6QBzxgps32w/V9DRsmdThAAUdo8rABIZW2EoTt5BjDbWwcTa69zg0rK7ciGPNoPa0u4wvRL4zTEh0XV0ZDxqzYPheQtZQdHFi2iz4vk4aDf+FzEOksY0zG+x55RbkYX9E+7u3sK1SuHPGOP2NtutTKzBWJHid/GUXV/r8V3Z1HLZCyid+glh4LKQfdS2RZHwIm6CrapSZWEKal2LkOJ6jB7r9k3+vK3KQipJFuHyEy+1XX9nbejPOJ3DCdYqV2dA== Received: from BN6PR13CA0044.namprd13.prod.outlook.com (2603:10b6:404:13e::30) by DM6PR12MB3834.namprd12.prod.outlook.com (2603:10b6:5:14a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Fri, 10 Sep 2021 15:58:45 +0000 Received: from BN8NAM11FT067.eop-nam11.prod.protection.outlook.com (2603:10b6:404:13e:cafe::11) by BN6PR13CA0044.outlook.office365.com (2603:10b6:404:13e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.8 via Frontend Transport; Fri, 10 Sep 2021 15:58:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT067.mail.protection.outlook.com (10.13.177.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4500.14 via Frontend Transport; Fri, 10 Sep 2021 15:58:44 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 10 Sep 2021 08:58:43 -0700 Received: from build-jbrasen-20210819T103534360.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 10 Sep 2021 15:58:43 +0000 From: "Jeff Brasen" To: CC: , Jeff Brasen Subject: [PATCH v2 1/2] Ext4Pkg: Improve Ext4IsBindingSupported() behavior Date: Fri, 10 Sep 2021 15:58:38 +0000 Message-ID: <00f58fdf6a9bce566ad5d145b0449ef3e6fdd94e.1631289393.git.jbrasen@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 In-Reply-To: References: X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6ae94518-77f9-48a3-3476-08d97473de18 X-MS-TrafficTypeDiagnostic: DM6PR12MB3834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:486; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5DS/qxnfdy1gVptY2gL+hnI+xNuI/TRRsEHi/4GJ3Zwi6WS2Kf1u4g/grP+b4xo7iv9D53N9gz7J8AmokQrFY5xmkYJLbK/Gek7J05jroUS08o2XDd4lCn6vr5b7KNVgXdc0OJOZNXImcuOqxb2RYiZUQzs15C7y21ipnLpsiRPTXOclmtH+SEs3Y9oPjzGJ7woBNhp0kke+/DMlAhuAE8zfwW9umzTa5thqlTuOiteDHnEJP+ag44AjCoKzwQ/Lg1fke+pCVwaa7AK8/QLYobDn6fRQJZEaqNSprRr8oSg3xZFM7DtaxbQtVHM9WrLEg/ZRG8uvcwmua07fL3n92Yapl6Sh6t36kfRH0HOZ4SflPE0V9Hbw6/4T/qyYKzRCZdChWAVh8MRsgLNbN8dpD8VvFITXiJXlJSNs6Xgd4c1HikJGrXbj1BCpN0+oeCISPaGIhJG/ljpS1QUZ1kZdda2APPplR3QZBnE2grXyf5fByMhXAAFs9UtzlgRm27vYVhrQ19r746mQqNpEl9Wx6eErNIUOSWAlWoRB8tnnQBxZx1XDUxCmV7QYIOUTWVxiDoCZSyzUk7E58NTEqYGvAOf9cK1LeXY3UjQD0NYOlrvwO401WHY/ltvsy7cTT8gSJImYPurKvITkSge0fFaMrEoN7CIPBPB7R3sij0jqtIOg+9utKKc3gacTrYs0leXVFeVfrgsPbOe2/PhYqzOd7nAA+56RlzcrIafr2wNOs0E= X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(6029001)(4636009)(136003)(376002)(39860400002)(346002)(396003)(46966006)(36840700001)(47076005)(7636003)(5660300002)(6666004)(356005)(26005)(7696005)(19627235002)(54906003)(8676002)(478600001)(70206006)(107886003)(4326008)(82740400003)(186003)(426003)(6916009)(336012)(83380400001)(36756003)(2616005)(8936002)(316002)(70586007)(86362001)(2906002)(36860700001)(82310400003)(32563001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2021 15:58:44.4066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ae94518-77f9-48a3-3476-08d97473de18 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT067.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3834 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain A couple of improvements to improve performance. Add check to return ACCESS_DENIED if already connected Add check to verify superblock magic during supported to reduce start calls Signed-off-by: Jeff Brasen --- Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 14 +++++++ Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c | 58 +++++++++++++++++++++------ Features/Ext4Pkg/Ext4Dxe/Superblock.c | 35 ++++++++++++++++ 3 files changed, 95 insertions(+), 12 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 64eab455db..5c60860894 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -1117,4 +1117,18 @@ Ext4GetVolumeName ( OUT UINTN *VolNameLen ); =20 +/** + Checks the superblock's magic value. + + @param[in] DiskIo Pointer to the DiskIo. + @param[in] BlockIo Pointer to the BlockIo. + + @return TRUE if a valid ext4 superblock, else FALSE. +**/ +BOOLEAN +Ext4SuperblockCheckMagic ( + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_BLOCK_IO_PROTOCOL *BlockIo + ); + #endif diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.c index ea2e048d77..5ae93d0484 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.c @@ -631,7 +631,6 @@ Ext4Unload ( @retval EFI_ACCESS_DENIED The device specified by ControllerHandl= e and RemainingDevicePath is already being ma= naged by a different driver or an application that requires = exclusive access. - Currently not implemented. @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e and RemainingDevicePath is not supported by= the driver specified by This. **/ @@ -643,32 +642,67 @@ Ext4IsBindingSupported ( IN EFI_DEVICE_PATH *RemainingDevicePath OPTIONAL ) { - // Note to self: EFI_OPEN_PROTOCOL_TEST_PROTOCOL lets us not close the - // protocol and ignore the output argument entirely + EFI_STATUS Status; + EFI_DISK_IO_PROTOCOL *DiskIo; + EFI_BLOCK_IO_PROTOCOL *BlockIo; =20 - EFI_STATUS Status; + DiskIo =3D NULL; + BlockIo =3D NULL; =20 + // + // Open the IO Abstraction(s) needed to perform the supported test + // Status =3D gBS->OpenProtocol ( ControllerHandle, &gEfiDiskIoProtocolGuid, - NULL, - BindingProtocol->ImageHandle, + (VOID **) &DiskIo, + BindingProtocol->DriverBindingHandle, ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL + EFI_OPEN_PROTOCOL_BY_DRIVER ); =20 if (EFI_ERROR (Status)) { - return Status; + goto Exit; } - + // + // Open the IO Abstraction(s) needed to perform the supported test + // Status =3D gBS->OpenProtocol ( ControllerHandle, &gEfiBlockIoProtocolGuid, - NULL, - BindingProtocol->ImageHandle, + (VOID **) &BlockIo, + BindingProtocol->DriverBindingHandle, ControllerHandle, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL + EFI_OPEN_PROTOCOL_GET_PROTOCOL ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + if (!Ext4SuperblockCheckMagic (DiskIo, BlockIo)) { + Status =3D EFI_UNSUPPORTED; + } + +Exit: + // + // Close the I/O Abstraction(s) used to perform the supported test + // + if (DiskIo !=3D NULL) { + gBS->CloseProtocol ( + ControllerHandle, + &gEfiDiskIoProtocolGuid, + BindingProtocol->DriverBindingHandle, + ControllerHandle + ); + } + if (BlockIo !=3D NULL) { + gBS->CloseProtocol ( + ControllerHandle, + &gEfiBlockIoProtocolGuid, + BindingProtocol->DriverBindingHandle, + ControllerHandle + ); + } return Status; } =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4D= xe/Superblock.c index c321d8c3d8..1ceb0d5cbb 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c @@ -34,6 +34,41 @@ STATIC CONST UINT32 gSupportedIncompatFeat =3D // this is desired, it's fairly trivial to look for EFI_VOLUME_CORRUPTED // references and add some Ext4SignalCorruption function + function call. =20 +/** + Checks only superblock magic value. + + @param[in] DiskIo Pointer to the DiskIo. + @param[in] BlockIo Pointer to the BlockIo. + + @return TRUE if a valid ext4 superblock, else FALSE. +**/ +BOOLEAN +Ext4SuperblockCheckMagic ( + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_BLOCK_IO_PROTOCOL *BlockIo + ) +{ + UINT16 Magic; + EFI_STATUS Status; + + Status =3D DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + EXT4_SUPERBLOCK_OFFSET + OFFSET_OF (EXT4_SUPERBLOCK, = s_magic), + sizeof (Magic), + &Magic + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + if (Magic !=3D EXT4_SIGNATURE) { + return FALSE; + } + + return TRUE; +} + /** Does brief validation of the ext4 superblock. =20 --=20 2.17.1