From nobody Tue Dec 16 16:38:45 2025 Received: from lgeamrelo12.lge.com (lgeamrelo12.lge.com [156.147.23.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C123D18C933 for ; Thu, 11 Dec 2025 08:05:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.23.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765440307; cv=none; b=pCVMzVMAFSCt7jQ0MTyeQ2RveYB5OeEIkWoRLTwtTjqW8bD3JjzLumFkBj/QihGYKlurr0tJkjIVuRk1m1CgaXr1jZ5HVkcvpB5UfNdZ0SKdSWFIQvkWRTPPcz5pMMzbNCstK2+ZIvHY0SY39ekrpsnLsDYtITjjpF4BbXwAp1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765440307; c=relaxed/simple; bh=6cFsSnDGBIDrdRq5Hk9Lnc9beDhoR8leOw5S9+oXdB8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ZvPFXbDJ/OVfvw1hTECpojhB2A1q7762wtKVA9wY9QaiQRh06ommeaJHdMEwWbHLi43oXyqN9FYX9mR+CPzDN6e2ISfWP05CN1B+JG+FNDWPaRrdiRGJZ4cxYo5GUIi6DuTFT2msboV8qRt96lM+jHYkxUUSKoA3YJDtdPSTJDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.23.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.52 with ESMTP; 11 Dec 2025 16:35:02 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: jaeyuel.im@lge.com Received: from unknown (HELO jaeyuelim-three.bee-live.svc.cluster.local) (10.185.60.88) by 156.147.1.121 with ESMTP; 11 Dec 2025 16:35:02 +0900 X-Original-SENDERIP: 10.185.60.88 X-Original-MAILFROM: jaeyuel.im@lge.com From: jaeyuel.im@lge.com To: Alasdair Kergon , Mike Snitzer , Mikulas Patocka Cc: dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org, "jaeyuel.im" Subject: [PATCH] dm init: ensure block device is ready before creating mapped device Date: Thu, 11 Dec 2025 07:34:26 +0000 Message-Id: <20251211073426.123026-1-jaeyuel.im@lge.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "jaeyuel.im" The current implementation of dm_init_init() uses early_lookup_bdev() to wait for the device node to appear. However, early_lookup_bdev() only verifies that the device node exists and returns the dev_t. It does not guarantee that the underlying block device structure is fully initialized and ready for I/O operations or to be opened. On certain platforms (e.g., embedded systems with specific storage drivers), this can lead to a race condition where dm_early_create() attempts to open the device immediately after early_lookup_bdev() returns, but fails because the device is not yet fully ready. This results in boot failures as the mapped device cannot be created. This patch adds an additional check using blkdev_get_no_open() after early_lookup_bdev() returns. This ensures that the struct block_device is actually available and the device is ready to be opened, effectively preventing the race condition. Signed-off-by: jaeyuel.im --- drivers/md/dm-init.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c index ff9420f06483..76b84ca39906 100644 --- a/drivers/md/dm-init.c +++ b/drivers/md/dm-init.c @@ -299,10 +299,24 @@ static int __init dm_init_init(void) for (i =3D 0; i < ARRAY_SIZE(waitfor); i++) { if (waitfor[i]) { dev_t dev; + struct block_device *bdev; =20 DMINFO("waiting for device %s ...", waitfor[i]); while (early_lookup_bdev(waitfor[i], &dev)) fsleep(5000); + + /* + * early_lookup_bdev() only checks if the device node exists and + * returns the dev_t. It does not guarantee that the underlying + * block device is fully initialized and ready to be opened. On + * some platforms, this can lead to a race condition where + * dm_early_create() fails because the device is not yet ready. + * Ensure the block device is truly available by attempting to + * get it. + */ + while (!(bdev =3D blkdev_get_no_open(dev))) + fsleep(5000); + blkdev_put_no_open(bdev); } } =20 --=20 2.34.1