git: 5d18a804737e - stable/14 - pass(4): Don't drop the periph lock before selrecord() in passpoll()

From: Kenneth D. Merry <ken_at_FreeBSD.org>
Date: Wed, 18 Nov 2026 18:02:55 UTC
The branch stable/14 has been updated by ken:

URL: https://cgit.FreeBSD.org/src/commit/?id=5d18a804737e7a8830daec423b576fa83ab39e4f

commit 5d18a804737e7a8830daec423b576fa83ab39e4f
Author:     Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-11 14:26:19 +0000
Commit:     Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-18 17:37:45 +0000

    pass(4): Don't drop the periph lock before selrecord() in passpoll()
    
    passpoll() checked the done queue while holding the peripheral lock,
    dropped the lock, and only then called selrecord().  A CCB completing
    in the window between the unlock and the selrecord() call sent its
    selwakeuppri() before the polling thread was on the selinfo list, so
    the wakeup was lost and select(2) or poll(2) slept until another
    completion arrived or the timeout expired.
    
    Call selrecord() before dropping the lock.  This lock order is
    already established: passdone() calls selwakeuppri(), which takes
    the selinfo lock, while holding the peripheral lock.
    
    kqueue is not affected, since the knlist is backed by the peripheral
    mutex.
    
    Reported by:    llm-postcr
    Fixes:          a9934668aa13
    MFC after:      1 week
    Sponsored by:   Spectra Logic
    Assisted-by:    Claude Fable 5 <noreply@anthropic.com>
    
    (cherry picked from commit 88c5709e91ad2cc6df51380673837f0ebd8a2d50)
---
 sys/cam/scsi/scsi_pass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c
index 3215b66454a1..1926ea40f6fd 100644
--- a/sys/cam/scsi/scsi_pass.c
+++ b/sys/cam/scsi/scsi_pass.c
@@ -2111,9 +2111,9 @@ passpoll(struct cdev *dev, int poll_events, struct thread *td)
 		if (!TAILQ_EMPTY(&softc->done_queue)) {
 			revents |= poll_events & (POLLIN | POLLRDNORM);
 		}
-		cam_periph_unlock(periph);
 		if (revents == 0)
 			selrecord(td, &softc->read_select);
+		cam_periph_unlock(periph);
 	}
 
 	return (revents);