OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Konstantin Khorenko <khorenko@virtuozzo.com>,
	Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v6 5/7] block/blk-cbt: walk cbt_list under SRCU
Date: Tue, 27 Oct 2026 16:58:07 +0000	[thread overview]
Message-ID: <010701a17e4c39e9-78125d53-d461-4ea5-b2f4-e538d98cf15d-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261027-ptikhomirov-vstor-149268-cbt-account-at-rq-start-v6-5-f9870cf5c7eb@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] block/blk-cbt: blk_cbt_update_size() iterator reads ->next of a cbt already queued for call_srcu() free
--

commit b854cacb9d00c0de28510b3f76417083233caa38
Author: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

block/blk-cbt: walk cbt_list under SRCU

This patch converts the q->cbt_list walk in blk_cbt_bio_queue() from
plain RCU to SRCU, so that cbt_page_alloc() no longer drops the read
lock around its sleeping allocation. It also switches the deferred
frees of a cbt from call_rcu() to call_srcu().

Link: https://virtuozzo.atlassian.net/browse/VSTOR-149268

> diff --git a/block/blk-cbt.c b/block/blk-cbt.c
> --- a/block/blk-cbt.c
> +++ b/block/blk-cbt.c

[ ... ]

> @@ -608,7 +610,7 @@ static void blk_cbt_update_cbt_size(struct cbt_info *cbt, loff_t new_sz)
>  	in_use = cbt->count;
>  	spin_unlock_irq(&cbt->lock);
>  	if (!in_use)
> -		call_rcu(&cbt->rcu, &cbt_release_callback);
> +		call_srcu(&cbt_srcu, &cbt->rcu, &cbt_release_callback);
>  }
>  
>  void blk_cbt_update_size(struct block_device *bdev)

[Severity: Medium]
This problem wasn't introduced by this patch, but the patch touches the
call site involved. Can blk_cbt_update_size() read the ->next pointer of
a cbt that has already been freed?

blk_cbt_update_size() walks the list with a plain iterator, holding only
cbt_mutex:

    mutex_lock(&cbt_mutex);
    list_for_each_entry(cbt, &q->cbt_list, list)
        blk_cbt_update_cbt_size(cbt, bdev_nr_bytes(bdev));

For each cbt, blk_cbt_update_cbt_size() can replace it in the list and
queue the old one for freeing:

    list_replace_rcu(&cbt->list, &new->list);
    in_use = cbt->count;
    ...
    if (!in_use)
        call_srcu(&cbt_srcu, &cbt->rcu, &cbt_release_callback);

When the callee returns, the loop advances through the old cbt's
->list.next. The caller holds no SRCU read lock and no reference on that
cbt. cbt_mutex does not keep an SRCU grace period from completing.

If the task is preempted between call_srcu() and the advance for a full
grace period, cbt_release_callback() can free the cbt before the read.
The window is narrow, but it looks reachable on a preemptible kernel.

Would list_for_each_entry_safe() be appropriate here, since it loads the
next pointer before the callee runs? Alternatively, could the loop be
wrapped in an SRCU read-side section?

[ ... ]

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261027-ptikhomirov-vstor-149268-cbt-account-at-rq-start-v6-0-f9870cf5c7eb@virtuozzo.com?part=5

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

  reply	other threads:[~2026-10-27 16:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 16:48 [Devel] [PATCH hci-8.1 v6 0/7] block/blk-cbt: don't lose writes held across a dm suspend Pavel Tikhomirov
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 1/7] block/blk-cbt: shift the block size as unsigned Pavel Tikhomirov
2026-10-27 16:53   ` no-reply
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 2/7] block/blk-throttle: account a throttled write in CBT Pavel Tikhomirov
2026-10-27 16:53   ` no-reply
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 3/7] block/blk-cbt: read a map slot once, publish a map page with release Pavel Tikhomirov
2026-10-27 16:55   ` no-reply
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 4/7] block/blk-cbt: don't overwrite a map page with CBT_PAGE_MISSED Pavel Tikhomirov
2026-10-27 16:54   ` no-reply
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 5/7] block/blk-cbt: walk cbt_list under SRCU Pavel Tikhomirov
2026-10-27 16:58   ` no-reply [this message]
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 6/7] block/blk-cbt: don't sleep in CBT for a REQ_NOWAIT write Pavel Tikhomirov
2026-10-27 16:57   ` no-reply
2026-10-27 16:48 ` [Devel] [PATCH hci-8.1 v6 7/7] block/blk-cbt: account a write request also when dm starts it Pavel Tikhomirov

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=010701a17e4c39e9-78125d53-d461-4ea5-b2f4-e538d98cf15d-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=ptikhomirov@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