From: Li Chen <me@linux.beauty>
To: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
virtualization@lists.linux.dev, nvdimm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH V2 0/4] nvdimm: virtio_pmem: fix request lifetime and converge broken queue failures
Date: Thu, 25 Dec 2025 12:29:08 +0800 [thread overview]
Message-ID: <20251225042915.334117-1-me@linux.beauty> (raw)
Hi,
The virtio-pmem flush path uses a virtqueue cookie/token to carry a
per-request context through completion. Under broken virtqueue / notify
failure conditions, the submitter can return and free the request object
while the host/backend may still complete the published request. The IRQ
completion handler then dereferences freed memory when waking waiters,
which is reported by KASAN as a slab-use-after-free and may manifest as
lock corruption (e.g. "BUG: spinlock already unlocked") without KASAN.
In addition, the flush path has two wait sites: one for virtqueue
descriptor availability (-ENOSPC from virtqueue_add_sgs()) and one for
request completion. If the virtqueue becomes broken, forward progress is
no longer guaranteed and these waiters may sleep indefinitely unless the
driver converges the failure and wakes all wait sites.
This series addresses both issues:
1/5 nvdimm: virtio_pmem: always wake -ENOSPC waiters
Wake one -ENOSPC waiter for each reclaimed used buffer, decoupled
from token completion, and use READ_ONCE()/WRITE_ONCE() for wait
flags.
2/5 nvdimm: virtio_pmem: refcount requests for token lifetime
Refcount request objects so the token lifetime spans the window
where it is reachable through the virtqueue until completion/drain
drops the virtqueue reference.
3/5 nvdimm: virtio_pmem: converge broken virtqueue to -EIO
Track a device-level broken state to converge broken/notify
failures to -EIO: wake all waiters and drain/detach outstanding
requests to complete them with an error, and fail-fast new
requests.
4/5 nvdimm: virtio_pmem: drain requests in freeze
Drain outstanding requests in freeze() before tearing down
virtqueues so waiters do not sleep indefinitely.
5/5 nvdimm: nd_virtio: export virtio_pmem_mark_broken_and_drain
Export symbol to fix compile issue.
Testing was done on QEMU x86_64 with a virtio-pmem device exported as
/dev/pmem0, formatted with ext4 (-O fast_commit), mounted with DAX, and
stressed with fsync-heavy workloads.
Changelog:
v1->v2: add patch 5 to fix compile issue.
v1: https://www.spinics.net/lists/kernel/msg5974818.html
Thanks,
Li Chen
Li Chen (5):
nvdimm: virtio_pmem: always wake -ENOSPC waiters
nvdimm: virtio_pmem: refcount requests for token lifetime
nvdimm: virtio_pmem: converge broken virtqueue to -EIO
nvdimm: virtio_pmem: drain requests in freeze
nvdimm: nd_virtio: export virtio_pmem_mark_broken_and_drain
drivers/nvdimm/nd_virtio.c | 135 +++++++++++++++++++++++++++++------
drivers/nvdimm/virtio_pmem.c | 14 ++++
drivers/nvdimm/virtio_pmem.h | 6 ++
3 files changed, 134 insertions(+), 21 deletions(-)
--
2.52.0
next reply other threads:[~2025-12-25 4:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-25 4:29 Li Chen [this message]
2025-12-25 4:29 ` [PATCH V2 1/5] nvdimm: virtio_pmem: always wake -ENOSPC waiters Li Chen
2026-01-02 12:29 ` Pankaj Gupta
2026-02-25 11:48 ` Li Chen
2025-12-25 4:29 ` [PATCH V2 2/5] nvdimm: virtio_pmem: refcount requests for token lifetime Li Chen
2025-12-25 4:29 ` [PATCH V2 3/5] nvdimm: virtio_pmem: converge broken virtqueue to -EIO Li Chen
2025-12-25 4:29 ` [PATCH V2 4/5] nvdimm: virtio_pmem: drain requests in freeze Li Chen
2025-12-25 4:29 ` [PATCH 5/5] nvdimm: nd_virtio: export virtio_pmem_mark_broken_and_drain Li Chen
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=20251225042915.334117-1-me@linux.beauty \
--to=me@linux.beauty \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=pankaj.gupta.linux@gmail.com \
--cc=virtualization@lists.linux.dev \
--cc=vishal.l.verma@intel.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