git: 8dab6aba5f6e - stable/12 - CAM: Keep periph_links when restoring CCB in camperiphdone().

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Wed, 04 May 2022 01:02:10 UTC
The branch stable/12 has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=8dab6aba5f6ee635e4ff3f313d0209af718ea42f

commit 8dab6aba5f6ee635e4ff3f313d0209af718ea42f
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-04-28 01:39:50 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-05-04 01:02:00 +0000

    CAM: Keep periph_links when restoring CCB in camperiphdone().
    
    While recovery command executed, some other commands from the periph
    may complete, that may affect periph_links of this CCB.  So restoring
    original CCB we must keep current periph_links as more up to date.
    
    I've found this triggering assertions with debug kernel and suspect
    some memory corruptions otherwise when spun down disk receives two
    or sometimes more concurrent requests.
    
    MFC after:      1 week
    Sponsored by:   iXsystems, Inc.
    
    (cherry picked from commit 404f001161b975164d8b52d9f404d07ac7584027)
---
 sys/cam/cam_periph.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
index 2744541097dd..125e7e60cac7 100644
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -1441,6 +1441,7 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
 	 * and the result will be the final one returned to the CCB owher.
 	 */
 	saved_ccb = (union ccb *)done_ccb->ccb_h.saved_ccb_ptr;
+	saved_ccb->ccb_h.periph_links = done_ccb->ccb_h.periph_links;
 	bcopy(saved_ccb, done_ccb, sizeof(*done_ccb));
 	xpt_free_ccb(saved_ccb);
 	if (done_ccb->ccb_h.cbfcnp != camperiphdone)