From: sashiko-bot@kernel.org
To: "Alexander Graf" <graf@amazon.com>
Cc: dri-devel@lists.freedesktop.org, nvdimm@lists.linux.dev
Subject: Re: [RFC PATCH 11/12] virtio: expose device memory buffer occupancy over debugfs
Date: Sun, 09 Aug 2026 18:44:52 +0000 [thread overview]
Message-ID: <20260809184453.14B9B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260809182010.32931-12-graf@amazon.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] `virtio_dmb_hiwater_set` contains a TOCTOU race with `virtio_dmb_inc_used` that can cause the high-water mark to be permanently set lower than the current total usage.
--
--- Patch [11]: [RFC PATCH 11/12] virtio: expose device memory buffer occupancy over debugfs ---
commit 821ee4cbeac917d62e62a95c88f58236d2f6db9c
Author: Alexander Graf <graf@amazon.com>
virtio: expose device memory buffer occupancy over debugfs
This commit adds debugfs files to expose the memory occupancy of virtio
device memory buffers when CONFIG_VIRTIO_DEBUG is enabled. It introduces
counters for total allocated pages, allocation failures, and a high-water
mark to track peak usage.
> diff --git a/drivers/virtio/virtio_dmb.c b/drivers/virtio/virtio_dmb.c
> index 42126f928bc06..fe556d585f244 100644
> --- a/drivers/virtio/virtio_dmb.c
> +++ b/drivers/virtio/virtio_dmb.c
[ ... ]
> +static int virtio_dmb_hiwater_set(void *data, u64 val)
> +{
> + struct virtio_dmb *dmb = data;
> +
> + /* Restarting the measurement is the only meaningful write. */
> + if (val)
> + return -EINVAL;
> +
> + /*
> + * Restart from what is allocated now rather than from zero, so that
> + * the file never reports a peak below the occupancy it is read
> + * alongside.
> + */
> + atomic_long_set(&dmb->used_hiwater,
> + atomic_long_read(&dmb->total_used));
[Severity: Medium]
Can this sequence result in the high-water mark being set lower than the
current total usage due to a race condition?
If a write to the debugfs used_pages_hiwater file occurs concurrently with
new allocations, could we see the following sequence:
Thread A reads total_used (e.g., 10) in virtio_dmb_hiwater_set().
Thread B allocates memory in virtio_dmb_inc_used(), increasing both
total_used and used_hiwater (e.g., to 110).
Thread A then blindly overwrites used_hiwater with the stale value (10)
using atomic_long_set().
This seems to contradict the comment above it, leaving used_hiwater
substantially lower than total_used. Is there a way to safely read and
update this to avoid a time-of-check to time-of-use race?
> +
> + return 0;
> +}
> +DEFINE_DEBUGFS_ATTRIBUTE(virtio_dmb_hiwater_fops, virtio_dmb_hiwater_get,
> + virtio_dmb_hiwater_set, "%llu\n");
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260809182010.32931-1-graf@amazon.com?part=11
next prev parent reply other threads:[~2026-08-09 18:44 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 18:19 [RFC PATCH 00/12] virtio: support devices that own their virtqueue memory Alexander Graf
2026-08-09 18:19 ` [RFC PATCH 01/12] vdpa: correct the VIRTIO_DEVICE_F_MASK example value Alexander Graf
2026-08-09 22:42 ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 02/12] virtio_ring: validate premapped addresses through the device's map Alexander Graf
2026-08-09 22:48 ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 03/12] virtio: add the VIRTIO_F_DMB feature bit Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 04/12] virtio_pci: read the device memory buffer shared memory id Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 05/12] virtio_pci: create virtqueues with the device's mapping token Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 06/12] virtio: add a device memory buffer region allocator Alexander Graf
2026-08-09 22:06 ` Michael S. Tsirkin
2026-08-09 22:38 ` Michael S. Tsirkin
2026-08-10 7:57 ` Graf (AWS), Alexander
2026-08-10 8:07 ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 07/12] virtio: locate the device memory buffer after feature negotiation Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 08/12] virtio_pci: support VIRTIO_F_DMB Alexander Graf
2026-08-09 22:14 ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 09/12] Documentation: virtio: describe the device memory buffer Alexander Graf
2026-08-09 22:09 ` Michael S. Tsirkin
2026-08-09 18:20 ` [RFC PATCH 10/12] virtio_ring: report a bounded pool's exhaustion as -ENOSPC Alexander Graf
2026-08-09 18:20 ` [RFC PATCH 11/12] virtio: expose device memory buffer occupancy over debugfs Alexander Graf
2026-08-09 18:44 ` sashiko-bot [this message]
2026-08-09 18:20 ` [RFC PATCH 12/12] virtio: guarantee a virtqueue can publish its first descriptor chain Alexander Graf
2026-08-09 22:41 ` Michael S. Tsirkin
2026-08-09 23:15 ` Randy Dunlap
2026-08-10 6:23 ` [RFC PATCH 00/12] virtio: support devices that own their virtqueue memory Michael S. Tsirkin
2026-08-10 7:39 ` Graf (AWS), Alexander
2026-08-10 8:04 ` Michael S. Tsirkin
2026-08-10 8:25 ` Graf (AWS), Alexander
2026-08-10 19:14 ` Graf (AWS), Alexander
2026-08-10 21:42 ` Michael S. Tsirkin
2026-08-10 20:39 ` Stefan Hajnoczi
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=20260809184453.14B9B1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=graf@amazon.com \
--cc=nvdimm@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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.