All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v5 3/6] block/blk-cbt: don't overwrite a map page with CBT_PAGE_MISSED
Date: Tue, 27 Oct 2026 14:30:02 +0000	[thread overview]
Message-ID: <010701a17dc4a9e2-b30e9aa4-5fa0-43e4-b06d-e0c475b98fdd-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261027-ptikhomirov-vstor-149268-cbt-account-at-rq-start-v5-3-88dccc74b48b@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] blk-cbt: spinlock_t cbt->lock taken in on_each_cpu() IPI callback, invalid wait context
--

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

block/blk-cbt: don't overwrite a map page with CBT_PAGE_MISSED

This patch changes __blk_cbt_set() so that the CBT_PAGE_MISSED marker is stored under cbt->lock. If a map page was installed in the meantime, the bits are set in that page instead. The aim is to stop the cache flush from overwriting, and leaking, a page installed by cbt_page_alloc().

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

> diff --git a/block/blk-cbt.c b/block/blk-cbt.c
> index 1066b6a33b6b..01114362bb2b 100644
> --- a/block/blk-cbt.c
> +++ b/block/blk-cbt.c

[ ... ]

> @@ -194,10 +194,19 @@ static int __blk_cbt_set(struct cbt_info  *cbt, blkcnt_t block,
>  			block += len;
>  			continue;
>  		} else if (pages_missed) {
> +			bool installed;
> +
> +			/* Don't overwrite a page installed meanwhile */
> +			spin_lock_irqsave(&cbt->lock, flags);

[Severity: Medium]
Is it safe to take cbt->lock here? The pages_missed branch of __blk_cbt_set() is reached from the IPI callback:

cbt_flush_cache()
  on_each_cpu(__cbt_flush_cpu_cache, &ctx, 1)
    __cbt_flush_cpu_cache()
      __blk_cbt_set(..., &ctx->pages_missed, ...)

On remote CPUs this runs in hardirq context.

cbt->lock is declared in struct cbt_info as a plain spinlock_t, not a raw_spinlock_t. A spinlock_t is a sleeping lock on PREEMPT_RT. It is also an invalid wait context in hardirq under CONFIG_PROVE_RAW_LOCK_NESTING.

The previous code stored the marker without taking any lock. With this change, kernels built with CONFIG_PROVE_LOCKING and CONFIG_PROVE_RAW_LOCK_NESTING (as in the shipped debug config) could report an "Invalid wait context" splat whenever a flush finds a missing map page. On a PREEMPT_RT build this would be a sleeping lock taken in hardirq context.

Would it be better to make cbt->lock a raw_spinlock_t? Alternatively, the IPI path could install the marker lock-free, for example with cmpxchg(&cbt->map[idx], NULL, CBT_PAGE_MISSED).

> +			installed = CBT_PAGE(cbt, idx);
> +			if (!installed)
> +				cbt->map[idx] = CBT_PAGE_MISSED;
> +			spin_unlock_irqrestore(&cbt->lock, flags);
> +			if (installed)
> +				continue;
>  			(*pages_missed)++;
>  			if (!*idx_first)
>  				*idx_first = idx;
> -			cbt->map[idx] = CBT_PAGE_MISSED;
>  			count -= len;
>  			block += len;
>  			continue;

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

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

  reply	other threads:[~2026-10-27 14:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 14:23 [Devel] [PATCH hci-8.1 v5 0/6] block/blk-cbt: don't lose writes held across a dm suspend Pavel Tikhomirov
2026-10-27 14:23 ` [Devel] [PATCH hci-8.1 v5 1/6] block/blk-cbt: shift the block size as unsigned Pavel Tikhomirov
2026-10-27 14:27   ` no-reply
2026-10-27 14:23 ` [Devel] [PATCH hci-8.1 v5 2/6] block/blk-throttle: account a throttled write in CBT Pavel Tikhomirov
2026-10-27 14:27   ` no-reply
2026-10-27 14:23 ` [Devel] [PATCH hci-8.1 v5 3/6] block/blk-cbt: don't overwrite a map page with CBT_PAGE_MISSED Pavel Tikhomirov
2026-10-27 14:30   ` no-reply [this message]
2026-10-27 14:23 ` [Devel] [PATCH hci-8.1 v5 4/6] block/blk-cbt: walk cbt_list under SRCU Pavel Tikhomirov
2026-10-27 14:29   ` no-reply
2026-10-27 14:23 ` [Devel] [PATCH hci-8.1 v5 5/6] block/blk-cbt: don't sleep in CBT for a REQ_NOWAIT write Pavel Tikhomirov
2026-10-27 14:33   ` no-reply
2026-10-27 14:23 ` [Devel] [PATCH hci-8.1 v5 6/6] block/blk-cbt: account a write request also when dm starts it Pavel Tikhomirov
2026-10-27 14:33   ` no-reply

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=010701a17dc4a9e2-b30e9aa4-5fa0-43e4-b06d-e0c475b98fdd-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 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.