All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
Date: Wed, 18 Nov 2026 20:00:06 +0100	[thread overview]
Message-ID: <20261118190006.3573492-1-den@openvz.org> (raw)

From: Denis V. Lunev <den@openvz.org>

ploop_try_delay_enospc() tests wants_suspend and adds the pio to
enospc_pios without deferred_lock, then arms enospc_timer and queues
event_work. Nothing keeps the struct ploop alive once the pio is on the
list. An endio that stalls after llist_add() can see ploop_presuspend()
set wants_suspend and resubmit the pio, the retry fail and complete the
request, and the device go away. The endio then calls mod_timer() and
schedule_work() on the freed struct ploop. timer_shutdown_sync() and
cancel_work_sync() in ploop_destroy() cannot close that, as the endio
writes into the freed memory itself.

Hold deferred_lock from the wants_suspend test through schedule_work().
ploop_presuspend() sets wants_suspend under the same lock, so either it
finds the pio on enospc_pios with the timer and the work already armed,
or the endio sees wants_suspend and leaves the request to its caller to
complete. The endio does not touch the struct ploop after the unlock.

https://virtuozzo.atlassian.net/browse/VSTOR-154847

Fixes: 6ddad5a4d226 ("dm-ploop: Add ploop target driver")
Feature: dm-ploop: ploop target driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---
Tested with an injected delay after llist_add() and the device
suspended and removed while the endio is held: the stock module oopses
in lock_timer_base() on the poisoned timer, the patched one makes the
suspend wait for the lock and stays clean.

 drivers/md/dm-ploop-map.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 58d1c7092602..c62b414862b1 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -182,7 +182,9 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
 	struct ploop *ploop = pio->ploop;
 	unsigned long flags;
 
+	spin_lock_irqsave(&ploop->deferred_lock, flags);
 	if (unlikely(ploop->wants_suspend)) {
+		spin_unlock_irqrestore(&ploop->deferred_lock, flags);
 		PL_WARN("dropping pio enospc\n");
 		return false;
 	}
@@ -191,13 +193,12 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
 
 	pr_err_once(PL_FMT("underlying disk is almost full"),
 		ploop_device_name(ploop));
-	spin_lock_irqsave(&ploop->deferred_lock, flags);
 	ploop->event_enospc = true;
-	spin_unlock_irqrestore(&ploop->deferred_lock, flags);
 	llist_add((struct llist_node *)(&pio->list), &ploop->enospc_pios);
 
 	mod_timer(&ploop->enospc_timer, jiffies + PLOOP_ENOSPC_TIMEOUT);
 	schedule_work(&ploop->event_work);
+	spin_unlock_irqrestore(&ploop->deferred_lock, flags);
 
 	return true;
 }
-- 
2.55.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

             reply	other threads:[~2026-11-18 19:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:00 Denis V. Lunev [this message]
2026-11-18 19:05 ` no-reply
2026-11-19  8:00 ` Alexander Ivanov
2026-11-19 16:19 ` Konstantin Khorenko
2026-11-19 16:20 ` Konstantin Khorenko

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=20261118190006.3573492-1-den@openvz.org \
    --to=den@openvz.org \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=vasileios.almpanis@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.