OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: "Denis V. Lunev" <den@openvz.org>, vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.2] dm-ploop: fix an ENOSPC endio arming the timer on a freed ploop
Date: Thu, 19 Nov 2026 09:00:19 +0100	[thread overview]
Message-ID: <9b47a3c4-0984-4e26-b21e-b5548e870907@virtuozzo.com> (raw)
In-Reply-To: <20261118190006.3573492-1-den@openvz.org>


On 11/18/26 20:00, Denis V. Lunev wrote:
> 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));

I'd move pr_err_once() out from under the lock, but it's not critical.

LGTM
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

> -	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;
>   }
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:00 Denis V. Lunev
2026-11-18 19:05 ` no-reply
2026-11-19  8:00 ` Alexander Ivanov [this message]
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=9b47a3c4-0984-4e26-b21e-b5548e870907@virtuozzo.com \
    --to=alexander.ivanov@virtuozzo.com \
    --cc=den@openvz.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox