Linux block layer
 help / color / mirror / Atom feed
From: Stian Halseth <stian@itx.no>
To: axboe@kernel.dk
Cc: Stian Halseth <stian@itx.no>,
	linux-block@vger.kernel.org, sparclinux@vger.kernel.org,
	linux-kernel@vger.kernel.org, andreas@gaisler.com,
	davem@davemloft.net, glaubitz@physik.fu-berlin.de,
	regressions@lists.linux.dev
Subject: [PATCH 1/2] sunvdc: unmap LDC cookies when the descriptor send fails
Date: Tue,  1 Sep 2026 19:39:45 +0200	[thread overview]
Message-ID: <20260901173947.3292110-2-stian@itx.no> (raw)
In-Reply-To: <20260901173947.3292110-1-stian@itx.no>

__send_request() maps the request's pages into the LDC channel's map
table (ldc_map_sg()), fills in the descriptor and marks it
VIO_DESC_READY before ringing the doorbell via __vdc_tx_trigger().
When the trigger fails, the error path only prints a message: the
descriptor stays READY and the cookies are never unmapped. The
mapping is normally released in vdc_end_one() when the peer completes
the descriptor - but a descriptor whose doorbell was never sent will
never complete, and since dr->prod is not advanced on failure, the
reset path (vdc_requeue_inflight(), which walks [cons, prod)) never
visits it either. The map table entries are leaked permanently.

Since commit a11f6ca9aef9 ("sunvdc: Do not spin in an infinite loop
when vio_ldc_send() returns EAGAIN") trigger failures occur in
practice under load, so every resulting I/O error also leaks one
request's worth of entries from the fixed-size (8192 entries per
channel) map table. Because the allocator hands out contiguous
ranges, fragmentation makes large multi-segment requests fail first
as the table drains, until ldc_map_sg() fails permanently and the
disk is dead until reboot.

It also makes any retry-based recovery unusable: requeuing the
request on -EAGAIN remaps the pages on every attempt, overwriting
desc->cookies and orphaning the previous mapping, so the table
drains at the retry rate. This is the memory exhaustion observed
when the requeue approach was first tested in October 2025.

Roll back on failure: unmap the cookies, mark the descriptor FREE
again and clear the request entry. If the trigger failed with
-ENOTCONN, __vdc_tx_trigger() has already reset the port, which
tears down and reallocates both the dring and the LDC channel
including its map table - nothing to roll back, and the stale
descriptor must not be touched.

Fixes: a11f6ca9aef9 ("sunvdc: Do not spin in an infinite loop when vio_ldc_send() returns EAGAIN")
Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Link: https://github.com/sparclinux/issues/issues/2
Signed-off-by: Stian Halseth <stian@itx.no>
---
 drivers/block/sunvdc.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -525,6 +525,23 @@
 	err = __vdc_tx_trigger(port);
 	if (err < 0) {
 		printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err);
+		/*
+		 * If the port was reset (-ENOTCONN), the dring and the
+		 * LDC channel including all of its mappings are already
+		 * torn down and reallocated - there is nothing to undo
+		 * and @desc must not be touched.
+		 *
+		 * For any other failure the descriptor was never handed
+		 * to the peer: unmap the cookies and free the descriptor
+		 * again, so that a later retry of the request does not
+		 * leak LDC map table entries.
+		 */
+		if (err != -ENOTCONN) {
+			ldc_unmap(port->vio.lp, desc->cookies,
+				  desc->ncookies);
+			desc->hdr.state = VIO_DESC_FREE;
+			rqe->req = NULL;
+		}
 	} else {
 		port->req_id++;
 		dr->prod = vio_dring_next(dr, dr->prod);
--
2.53.0

  reply	other threads:[~2026-09-01 17:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 10:02 [PATCH v2] Revert "sunvdc: Do not spin in an infinite loop when vio_ldc_send() returns EAGAIN" John Paul Adrian Glaubitz
2025-10-06 12:48 ` Jens Axboe
2025-10-06 13:00   ` John Paul Adrian Glaubitz
2025-10-06 13:03     ` John Paul Adrian Glaubitz
2025-10-06 13:19     ` Jens Axboe
2025-10-06 13:34       ` John Paul Adrian Glaubitz
2025-10-06 13:46         ` Jens Axboe
2025-10-06 13:56           ` John Paul Adrian Glaubitz
2025-10-06 14:03             ` Jens Axboe
2025-10-06 14:12               ` John Paul Adrian Glaubitz
2025-10-06 14:27                 ` Jens Axboe
2025-10-06 14:48                   ` John Paul Adrian Glaubitz
2025-10-06 14:52                     ` Jens Axboe
2026-09-01 17:39                       ` [PATCH 0/2] sunvdc: fix silent data loss under LDC congestion Stian Halseth
2026-09-01 17:39                         ` Stian Halseth [this message]
2026-09-01 17:39                         ` [PATCH 2/2] sunvdc: fix -EIO issue due to lack of retries Stian Halseth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260901173947.3292110-2-stian@itx.no \
    --to=stian@itx.no \
    --cc=andreas@gaisler.com \
    --cc=axboe@kernel.dk \
    --cc=davem@davemloft.net \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=regressions@lists.linux.dev \
    --cc=sparclinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox