git: 70693a45381b - main - cxgbe tom: Restore support for zerocopy TCP receive for aio_read()

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 11 Dec 2024 02:24:10 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=70693a45381b687e40ea30710aa38cb9f24b6b02

commit 70693a45381b687e40ea30710aa38cb9f24b6b02
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-12-11 02:13:51 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-12-11 02:23:47 +0000

    cxgbe tom: Restore support for zerocopy TCP receive for aio_read()
    
    The commit to introduce TCP_USE_DDP support had a couple of bugs that
    broke support for zerocopy receive via aio_read().  First, the length
    and offset arguments to mk_update_tcb_for_ddp() were reversed which
    prevented DDP from working.  Second, the AIO state in the toep was
    initialized too late when the first aio_read() request was queued.
    
    Reported by:    Harshavardhan Tanneru @ Chelsio
    Fixes:          eba13bbc37ab cxgbe: Support TCP_USE_DDP on offloaded TOE connections
    MFC after:      1 week
    Sponsored by:   Chelsio Communications
---
 sys/dev/cxgbe/tom/t4_ddp.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/sys/dev/cxgbe/tom/t4_ddp.c b/sys/dev/cxgbe/tom/t4_ddp.c
index 529fc2a5b825..2fee8fa91dac 100644
--- a/sys/dev/cxgbe/tom/t4_ddp.c
+++ b/sys/dev/cxgbe/tom/t4_ddp.c
@@ -2653,8 +2653,8 @@ sbcopy:
 	 * which will keep it open and keep the TCP PCB attached until
 	 * after the job is completed.
 	 */
-	wr = mk_update_tcb_for_ddp(sc, toep, db_idx, &ps->prsv, ps->len,
-	    job->aio_received, ddp_flags, ddp_flags_mask);
+	wr = mk_update_tcb_for_ddp(sc, toep, db_idx, &ps->prsv,
+	    job->aio_received, ps->len, ddp_flags, ddp_flags_mask);
 	if (wr == NULL) {
 		recycle_pageset(toep, ps);
 		aio_ddp_requeue_one(toep, job);
@@ -2820,6 +2820,14 @@ t4_aio_queue_ddp(struct socket *so, struct kaiocb *job)
 		return (EOPNOTSUPP);
 	}
 
+	if ((toep->ddp.flags & DDP_AIO) == 0) {
+		toep->ddp.flags |= DDP_AIO;
+		TAILQ_INIT(&toep->ddp.cached_pagesets);
+		TAILQ_INIT(&toep->ddp.aiojobq);
+		TASK_INIT(&toep->ddp.requeue_task, 0, aio_ddp_requeue_task,
+		    toep);
+	}
+
 	/*
 	 * XXX: Think about possibly returning errors for ENOTCONN,
 	 * etc.  Perhaps the caller would only queue the request
@@ -2834,14 +2842,6 @@ t4_aio_queue_ddp(struct socket *so, struct kaiocb *job)
 	TAILQ_INSERT_TAIL(&toep->ddp.aiojobq, job, list);
 	toep->ddp.waiting_count++;
 
-	if ((toep->ddp.flags & DDP_AIO) == 0) {
-		toep->ddp.flags |= DDP_AIO;
-		TAILQ_INIT(&toep->ddp.cached_pagesets);
-		TAILQ_INIT(&toep->ddp.aiojobq);
-		TASK_INIT(&toep->ddp.requeue_task, 0, aio_ddp_requeue_task,
-		    toep);
-	}
-
 	/*
 	 * Try to handle this request synchronously.  If this has
 	 * to block because the task is running, it will just bail