git: 9462353bf065 - stable/15 - ufshci: fix the WLUN peripheral lookup timeout

From: Jaeyoon Choi <jaeyoon_at_FreeBSD.org>
Date: Mon, 02 Nov 2026 02:28:49 UTC
The branch stable/15 has been updated by jaeyoon:

URL: https://cgit.FreeBSD.org/src/commit/?id=9462353bf06584126ff85f50f958b61da51bdcf4

commit 9462353bf06584126ff85f50f958b61da51bdcf4
Author:     Denis Lemire <denis@lemire.name>
AuthorDate: 2026-10-29 06:14:18 +0000
Commit:     Jaeyoon Choi <jaeyoon@FreeBSD.org>
CommitDate: 2026-11-02 02:24:53 +0000

    ufshci: fix the WLUN peripheral lookup timeout
    
    The timeout in ufshci_sim_find_periph() is uint64_t, making the
    comparison of timeout - ticks with zero always false. If the requested
    peripheral does not become available, the lookup can wait indefinitely.
    
    Use an sbintime_t deadline based on sbinuptime() and mstosbt(), and
    compare the current uptime directly with the deadline. Preserve the
    successful lookup path and existing timeout cleanup.
    
    On an HP 15-fd0118ca with Intel N150 and Samsung UFS 3.1 storage, a
    kernel built from stable/15 revision 84aa3cb3204d with this change
    logged the missing-WLUN timeout, attached da0 and mounted root in two
    boot trials.
    
    Signed-off-by:  Denis Lemire <denis@lemire.name>
    Reviewed by:    jaeyoon
    Fixes:          31407551c3d4 ("ufshci: Add a check for WLUN during driver initialization")
    MFC after:      3 days
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2520
    
    (cherry picked from commit 8721f68642c392afa0413eafa3cefde66d65b6eb)
---
 sys/dev/ufshci/ufshci_sim.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys/dev/ufshci/ufshci_sim.c b/sys/dev/ufshci/ufshci_sim.c
index d9ea84961879..dc5198ae6f35 100644
--- a/sys/dev/ufshci/ufshci_sim.c
+++ b/sys/dev/ufshci/ufshci_sim.c
@@ -452,7 +452,7 @@ ufshci_sim_find_periph(struct ufshci_controller *ctrlr, uint8_t wlun)
 	struct cam_path *path;
 	struct cam_periph *periph = NULL;
 	uint64_t scsi_lun;
-	uint64_t timeout;
+	sbintime_t timeout;
 
 	/* The reset path can get here before the SIM is attached. */
 	if (ctrlr->ufshci_sim == NULL)
@@ -466,7 +466,7 @@ ufshci_sim_find_periph(struct ufshci_controller *ctrlr, uint8_t wlun)
 	}
 
 	/* Wait for the perip device to be found */
-	timeout = ticks + MSEC_2_TICKS(ctrlr->device_init_timeout_in_ms);
+	timeout = sbinuptime() + mstosbt(ctrlr->device_init_timeout_in_ms);
 
 	while (1) {
 		xpt_path_lock(path);
@@ -478,7 +478,7 @@ ufshci_sim_find_periph(struct ufshci_controller *ctrlr, uint8_t wlun)
 		if (periph)
 			break;
 
-		if (timeout - ticks < 0) {
+		if (sbinuptime() >= timeout) {
 			ufshci_printf(ctrlr,
 			    "Failed to find the Well known LUN(0x%x)\n", wlun);
 			break;