All of lore.kernel.org
 help / color / mirror / Atom feed
* Patch : drivers/md/dm-verity-target.c
@ 2023-11-06  9:30 Aaditya Raj Barnwal (QUIC)
  2023-11-06 10:04 ` Mikulas Patocka
  0 siblings, 1 reply; 10+ messages in thread
From: Aaditya Raj Barnwal (QUIC) @ 2023-11-06  9:30 UTC (permalink / raw)
  To: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
	dm-devel@lists.linux.dev
  Cc: Akshay Rukmangad


[-- Attachment #1.1: Type: text/plain, Size: 886 bytes --]

Hi Developers,

I have attached the patch for file : drivers/md/dm-verity-target.c

Race condition with some eMMC devices where the early_probe
to dm-verity driver try to check access of data device
fails. As this error is going to impact the bootup and mount
of rootfs. As its impact bootup we make to wait for and
then do a bail-out .
adding the error which show the that dm-init already
ack "all device available " but dm-verity returned
error .
device-mapper: init: all devices available
device-mapper: table: 252:0: verity: Data device lookup failed
device-mapper: ioctl: error adding target to table

This patch is going to wait based on module parm if not passed it
will be 1sec max.

This patch is based on
https://lore.kernel.org/lkml/7442e695-654a-59c2-e3dd-710946e6cddd@seco.com/T/
which tries to do the same to dm-int level.


Thanks
Aaditya




[-- Attachment #1.2: Type: text/html, Size: 4935 bytes --]

[-- Attachment #2: 0001-md-dm-verity-target-Wait-data-devices-giving-time-to.patch --]
[-- Type: application/octet-stream, Size: 2750 bytes --]

From 0220b1b240d60a9433da5f72f6c109e098ad1bcf Mon Sep 17 00:00:00 2001
From: Aaditya Raj Barnwal <quic_abarnwal@quicinc.com>
Date: Mon, 6 Nov 2023 14:49:45 +0530
Subject: [PATCH] md: dm-verity-target: Wait data devices giving time to probe
 ack

Race condition with some devices where the early_probe
to dm-verity driver try to check access of data device
fails. As this error is going to impact the bootup and mount
of rootfs.  As its impact bootup  we make to wait for and
then do a bail-out .
adding the error which show the that dm-init already
ack "all device available " but dm-verity  returned
error .
 device-mapper: init: all devices available
 device-mapper: table: 252:0: verity: Data device lookup failed
 device-mapper: ioctl: error adding target to table

This patch is based on
https://lore.kernel.org/lkml/
7442e695-654a-59c2-e3dd-710946e6cddd@seco.com/T/

which tries to do the same to dm-int level.
---
 drivers/md/dm-verity-target.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 26adcfea0302..bbe027190487 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -22,6 +22,7 @@
 #include <linux/scatterlist.h>
 #include <linux/string.h>
 #include <linux/jump_label.h>
+#include <linux/delay.h>
 
 #define DM_MSG_PREFIX			"verity"
 
@@ -42,6 +43,9 @@
 #define DM_VERITY_OPTS_MAX		(4 + DM_VERITY_OPTS_FEC + \
 					 DM_VERITY_ROOT_HASH_VERIFICATION_OPTS)
 
+#define DM_DEFAULT_MAX_PROBE_DELAY_SEC 1
+#define DM_DEFAULT_PROBE_FACTOR 5
+
 static unsigned int dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE;
 
 module_param_named(prefetch_cluster, dm_verity_prefetch_cluster, uint, 0644);
@@ -1183,7 +1187,7 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	sector_t hash_position;
 	char dummy;
 	char *root_hash_digest_to_validate;
-
+	int loopcntr = DM_DEFAULT_MAX_PROBE_DELAY_SEC * 1000 / DM_DEFAULT_PROBE_FACTOR;
 	v = kzalloc(sizeof(struct dm_verity), GFP_KERNEL);
 	if (!v) {
 		ti->error = "Cannot allocate verity structure";
@@ -1225,7 +1229,17 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	}
 	v->version = num;
 
-	r = dm_get_device(ti, argv[1], BLK_OPEN_READ, &v->data_dev);
+	/*
+	 * Some time we see race condition of early_device probe to
+	 * dm_get_device() leading to failure leading to  mount
+	 * failure of data device specaially when data device is
+	 * eMMC devices (with rootfs)
+	 */
+
+	while ((r = dm_get_device(ti, argv[1], FMODE_READ, &v->data_dev)) && loopcntr) {
+		loopcntr--;
+		msleep_interruptible(5);
+	}
 	if (r) {
 		ti->error = "Data device lookup failed";
 		goto bad;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-11-15 18:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-06  9:30 Patch : drivers/md/dm-verity-target.c Aaditya Raj Barnwal (QUIC)
2023-11-06 10:04 ` Mikulas Patocka
     [not found]   ` <PH0PR02MB859987618E8647439950A053F6AAA@PH0PR02MB8599.namprd02.prod.outlook.com>
2023-11-06 11:55     ` Mikulas Patocka
2023-11-14  7:23       ` Aaditya Raj Barnwal (QUIC)
     [not found]       ` <1e9615ee3bf84ab7a3023152e3b94284@quicinc.com>
2023-11-14 14:37         ` Mikulas Patocka
2023-11-14 14:52           ` Mikulas Patocka
2023-11-15  7:01             ` Aaditya Raj Barnwal
2023-11-15 17:29               ` Mike Snitzer
2023-11-15 17:59                 ` Mikulas Patocka
2023-11-15  7:00           ` Aaditya Raj Barnwal (QUIC)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.