From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.42]) by mx.groups.io with SMTP id smtpd.web12.64.1631311893425720120 for ; Fri, 10 Sep 2021 15:11:33 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=OUCRYeik; 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.223.42, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eEk4ohSAYL0PBjGXidJg3M2C5gnqWF1wMmUBPJgvuuIpikajI7imU8DNobc8liivEdiV9BiVYgcpPKpM4BjeyK+Kr5q47FO6mSSMRLRwSNlpCzec6mHg8COGy1DpMSI7/P5E47Htts0xh195iHSqH/vjppWXTEjAG6pP+ioOUKmZLSkpAHpkZuzGHHpUs/7RZvBtZ5/QLDytY3DanJZN8HwsmGQ3Tc9XXUH3EXHNNDODwh1WnRuLaQigTy9l0hg373qEyNQmnhx/4YRsNi063vjzcoWyNtKKEYLZI5iqIfhMCgYkJHGsAznBU3KmgQzf3HdeIYPRmL2PhPSf/yN2SA== 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=VlMlp77t03RusEQCklH2SFeFCKSXYzdex+iWtVb1ooo=; b=e3Lb3dnmp+QOUJVDOk28LjIqI2HcsazbVnFBI69zVs7Y7FjjiDr5KqdBqGvhXOzT58IHaxxyqbTHqUNQVDVvDwEaBts29JaNKedRKOUa8VZD2Xz+s56K8S27adEhOzngSTsK96NQL4pnp4Lx4Pn52oJEpWgqIrhT+ajhRNzj3njtCYEPi9EhdR8gqjp0sZNYAk7DM40i+z/D0B1OG8jd8tIsJH8ZCAbQMXmOkOYD6/Zj+oA8UrA8AlQXyr4EqZfYE6Kw4fdJ8o+4z8EAIihmyzynlLWAkj3RRTQRNaIcrAxVFPQeGAe5idlY7kBT4z/6vX7slDgLUwDtGRRnZoFRxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=edk2.groups.io 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=VlMlp77t03RusEQCklH2SFeFCKSXYzdex+iWtVb1ooo=; b=OUCRYeikSMKUDOsHUx6rDRD+uXp9ldLPoBrlh0CxKLd6xxnyQSC4D9xWQP6kNBWiXp2n636XvzOUlTWpYBHpDhD46I5evV22VICXpr//ErHTiWzVRj3xRh/ch7OPJ8QdDewOZTvpvNUSWSWm5o+va0Siufu5LTuuoWFCzGKf3hHPftfiyv8qnJRnqSqO/oTyDhyL4JSufhwrSQEF8xn9IAJI7patMuAd5XdGjNE2qyo1LmZvAdZS/dhqIHsaFfntNStRllvxglcYzSMyo1IbJFHscpV1wW3EitQ5L/XS7mcf0+JLpVNeGIWmkysdqDwRR7wYWKIEPgBUqrrR5zXy3A== Received: from MW2PR2101CA0026.namprd21.prod.outlook.com (2603:10b6:302:1::39) by BN9PR12MB5209.namprd12.prod.outlook.com (2603:10b6:408:11a::22) 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 22:11:32 +0000 Received: from CO1NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::22) by MW2PR2101CA0026.outlook.office365.com (2603:10b6:302:1::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.0 via Frontend Transport; Fri, 10 Sep 2021 22:11:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT063.mail.protection.outlook.com (10.13.175.37) 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 22:11:31 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 10 Sep 2021 22:11:31 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 10 Sep 2021 22:11:30 +0000 Received: from build-jbrasen-20210819T103534360.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 10 Sep 2021 15:11:30 -0700 From: "Jeff Brasen" To: CC: , Jeff Brasen Subject: [PATCH v3 1/2] Ext4Pkg: Improve Ext4IsBindingSupported() behavior Date: Fri, 10 Sep 2021 22:11:27 +0000 Message-ID: <7631e4dcf3c01613ca24d3acd9b4bd5d09fa8126.1631311760.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: 2540866b-fa01-4264-a58d-08d974a7f1f4 X-MS-TrafficTypeDiagnostic: BN9PR12MB5209: 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: kYQCklEnwl190MF6iPoKQ1LD6t9Y2wwqYropAVPsdUhwlGz4HdkWtaQE62eWEB2C4PMNYvDR4CrSEDlrKb5iPRpWALBJ0jz6Eln3lllM0i6JMBjkMpLPfSoeo/JHyI6HSv/0ml1p4zEHvubO9OZN0T5QppTZpWahxAoAEEE13USz6nGWp2Vn20dIcoueCsWAi/BZw1bsSyOqVnXss8LbESkvasHobO+hgv7KPqquGuuXw2s4Z4NzJIISVDMsAR8LLHZY2KgMiG+Mvxdst6aGyiTAj19pZwMepmPnemuvkHs5XirbMQPNJdORTc7uSygx2ewzoyuFVDx7tFK15o6VucdQfkTg1PFV+6G5wfh4ao4nv92aF6o2kghsEO8frkp0OfXiBawLwkfAqFGF2rXBhGdFvzFIDCycpvg7U4OdJpKgONBUYzLDfCGjen8rd49B2tQiAWj9kElX/3MxpteBTwQwVo4M7z396I1zOAQ27WWktge/dDnG2/Q0htDBZJSQvSeZ59OOBrCdhFiynBmCEY2gWVyMYqwlyrn0O5+zMTARYYP/HQ65e9+9vFs5GWCYLFcSKfBwRJghtj+OAX0sh6u5botXpEHTUv2tVeNrqIWR6fr6L7jpmolbbwNcOh7AWSHk7hte2Fvtnb8UOQ1h3GGsma0y1fBIgLVwWAqIM1sFd2TJZ6CpXbySOHGRQyYiUoVYTEfLnod9XFdRIs2s2Seyr6cQ6+hC1QUoAofV49w= X-Forefront-Antispam-Report: CIP:216.228.112.35;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid02.nvidia.com;CAT:NONE;SFS:(6029001)(4636009)(136003)(396003)(39860400002)(376002)(346002)(46966006)(36840700001)(26005)(8936002)(478600001)(70586007)(316002)(8676002)(4326008)(2906002)(70206006)(82740400003)(5660300002)(6916009)(19627235002)(426003)(107886003)(47076005)(83380400001)(54906003)(86362001)(36906005)(356005)(2616005)(36756003)(7636003)(82310400003)(6666004)(186003)(36860700001)(7696005)(336012)(32563001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2021 22:11:31.6199 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2540866b-fa01-4264-a58d-08d974a7f1f4 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.35];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5209 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 | 54 +++++++++++++++++++++------ Features/Ext4Pkg/Ext4Dxe/Superblock.c | 35 +++++++++++++++++ 3 files changed, 92 insertions(+), 11 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 64eab455db..a9b932ed52 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. + + @returns Whether the partition has a valid EXT4 superblock magic value. +**/ +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..d9fbe9ea78 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,65 @@ 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; } - + // + // 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)) { + if (!Ext4SuperblockCheckMagic (DiskIo, BlockIo)) { + Status =3D EFI_UNSUPPORTED; + } + } + + // + // 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..0c965415c5 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 the superblock's magic value. + + @param[in] DiskIo Pointer to the DiskIo. + @param[in] BlockIo Pointer to the BlockIo. + + @returns Whether the partition has a valid EXT4 superblock magic value. +**/ +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