Skip to contentSkip to conversation

bootdev: avoid infinite probe loop

PATCH RESEND In review Caleb Connolly 4 participants 5 messages Jan 4, 2024 – Jan 19, 2024

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 bootdev: avoid infinite probe loop

Sometimes, when only one bootdev is available, and it fails to probe, we end up in an infinite loop calling probe() on the same device over and over. With only debug level log output.

Break the loop if we fail to probe the same device twice in a row, and promote the probe failure message to log_warning().

---
Resend, actually change log message to WARN loglevel.

---
 boot/bootdev-uclass.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
boot/bootdev-uclass.c +12 -2
index d01d603700d9..cd1c2bc06774 100644
@@ -636,7 +636,7 @@ int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp,
 
 int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp)
 {
-	struct udevice *dev = *devp;
+	struct udevice *dev = *devp, *last_dev = NULL;
 	bool found;
 	int ret;
 
@@ -686,9 +686,19 @@ int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp)
 			}
 		} else {
 			ret = device_probe(dev);
+			if (!ret)
+				last_dev = dev;
 			if (ret) {
-				log_debug("Device '%s' failed to probe\n",
+				log_warning("Device '%s' failed to probe\n",
 					  dev->name);
+				if (last_dev == dev) {
+					/*
+					 * We have already tried this device
+					 * and it failed to probe. Give up.
+					 */
+					return log_msg_ret("probe", ret);
+				}
+				last_dev = dev;
 				dev = NULL;
 			}
 		}
Signature · 1 line
2.42.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Caleb,

Quoted 8 lines · Caleb Connolly

Sometimes, when only one bootdev is available, and it fails to probe, we end up in an infinite loop calling probe() on the same device over and over. With only debug level log output.

Break the loop if we fail to probe the same device twice in a row, and promote the probe failure message to log_warning().

Quoted 7 lines

---
Resend, actually change log message to WARN loglevel.

---
 boot/bootdev-uclass.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Thanks for the fix. Is this something for which a test could be added? One that fails (hangs) now but works with your patch?

Regards,
Simon

#2 lore raw

Hi Simon,

Quoted 19 lines · Simon Glass

Hi Caleb,

Quoted 8 lines · Caleb Connolly

Sometimes, when only one bootdev is available, and it fails to probe, we end up in an infinite loop calling probe() on the same device over and over. With only debug level log output.

Break the loop if we fail to probe the same device twice in a row, and promote the probe failure message to log_warning().

Quoted 7 lines

---
Resend, actually change log message to WARN loglevel.

---
 boot/bootdev-uclass.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Quoted 4 lines

Thanks for the fix. Is this something for which a test could be added? One that fails (hangs) now but works with your patch?

I'm not sure, I'm not very familiar with the U-Boot testing infrastructure yet. I guess this should be testable without having to solve the halting problem :P but I don't know how best to go about writing one.

Quoted 3 lines

Regards,
Simon

Signature · 1 line
// Caleb (they/them)
Reviewed-by on v1 1/1
#3 lore raw
In reply to Caleb Connolly
Quoted 8 lines · Caleb Connolly

Sometimes, when only one bootdev is available, and it fails to probe, we end up in an infinite loop calling probe() on the same device over and over. With only debug level log output.

Break the loop if we fail to probe the same device twice in a row, and promote the probe failure message to log_warning().

Looks good to me.

Quoted 43 lines

---
Resend, actually change log message to WARN loglevel.

---
 boot/bootdev-uclass.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
boot/bootdev-uclass.c +1 -1
index d01d603700d9..cd1c2bc06774 100644
@@ -636,7 +636,7 @@ int bootdev_next_label(struct bootflow_iter *iter,
 struct udevice **devp,
 
 int bootdev_next_prio(struct bootflow_iter *iter, struct udevice 
 **devp)
 {
-	struct udevice *dev = *devp;
+	struct udevice *dev = *devp, *last_dev = NULL;
 	bool found;
boot/bootdev-uclass.c +11 -1
 	int ret;
@@ -686,9 +686,19 @@ int bootdev_next_prio(struct bootflow_iter *iter,
 struct udevice **devp)
 			}
 		} else {
 			ret = device_probe(dev);
+			if (!ret)
+				last_dev = dev;
 			if (ret) {
-				log_debug("Device '%s' failed to probe\n",
+				log_warning("Device '%s' failed to probe\n",
 					  dev->name);
+				if (last_dev == dev) {
+					/*
+					 * We have already tried this device
+					 * and it failed to probe. Give up.
+					 */
+					return log_msg_ret("probe", ret);
+				}
+				last_dev = dev;
 				dev = NULL;
 			}

}

#4 lore raw
In reply to Caleb Connolly
Quoted 10 lines · Caleb Connolly

Sometimes, when only one bootdev is available, and it fails to probe, we end up in an infinite loop calling probe() on the same device over and over. With only debug level log output.

Break the loop if we fail to probe the same device twice in a row, and promote the probe failure message to log_warning().

Applied to u-boot/master, thanks!

Signature · 1 line
Tom