From b910e7e3252081033edb0a51c927a49aa99063f9 Mon Sep 17 00:00:00 2001 From: Will McVicker Date: Thu, 23 Dec 2021 12:23:39 -0800 Subject: [PATCH] MetadataCrypt: fix timeout due to missing userdata dm device We need to load the partition table before we can wait on the userdata dm device because the kernel (as of [1] doesn't send the KOBJ_ADD uevent until after the partition table is loaded. The new flow needs to be: CreateDevice() -> ioctl(DM_DEV_CREATE) LoadTableAndActivate() -> ioctl(DM_TABLE_LOAD) WaitForDevice() This patch updates create_crypto_blk_dev() to first call LoadTableAndActivate() before WaitForDevice(). [1] https://lore.kernel.org/all/20210804094147.459763-8-hch@lst.de/ Fixes: 156d9d229378 ("Pre-create userdata metadata encryption device.") Bug: 210737958 Test: manually test booting raven with android13-5.15 Change-Id: Iab2214a62d44ba7e53b57f2cf0f08ac06c77b4fd --- MetadataCrypt.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp index 0bd6100..6550be4 100644 --- a/MetadataCrypt.cpp +++ b/MetadataCrypt.cpp @@ -187,15 +187,14 @@ static bool create_crypto_blk_dev(const std::string& dm_name, const std::string& auto& dm = DeviceMapper::Instance(); if (dm_name == kDmNameUserdata && dm.GetState(dm_name) == DmDeviceState::SUSPENDED) { // The device was created in advance, populate it now. - std::string path; - if (!dm.WaitForDevice(dm_name, 5s, crypto_blkdev)) { - LOG(ERROR) << "Failed to wait for default-key device " << dm_name; - return false; - } if (!dm.LoadTableAndActivate(dm_name, table)) { LOG(ERROR) << "Failed to populate default-key device " << dm_name; return false; } + if (!dm.WaitForDevice(dm_name, 5s, crypto_blkdev)) { + LOG(ERROR) << "Failed to wait for default-key device " << dm_name; + return false; + } } else if (!dm.CreateDevice(dm_name, table, crypto_blkdev, 5s)) { LOG(ERROR) << "Could not create default-key device " << dm_name; return false;