Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Josh Hilke" <jrhilke@google.com>
Cc: linux-nvme@lists.infradead.org, kvm@vger.kernel.org
Subject: Re: [PATCH v2] vfio: selftests: Add NVMe driver
Date: Fri, 04 Dec 2026 02:15:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-248959@kernel.org> (raw)
In-Reply-To: <20261204015203.318020-1-jrhilke@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] vfio: selftests: unconditional VFIO_DEVICE_RESET in
  nvme_recover()
- [Low] vfio: selftests: unaligned on-disk hdr->size aborts
  nvme_claim_scratch()
- [Low] vfio: selftests: nvme_wait_rdy() ignores NVME_REG_CRTO ready
  timeout
--

commit 005bfc827495371f40d3d04303df45747c89d721
Author: Josh Hilke <jrhilke@google.com>

vfio: selftests: Add NVMe driver

This commit adds an NVMe driver to the VFIO selftests library,
implementing memcpy through logical blocks of the first active namespace
(with a 4 KiB scratch header to avoid overwriting existing data) and
MSI-X signaling via flush commands.

> diff --git a/tools/testing/selftests/vfio/lib/drivers/nvme/nvme.c b/tools/testing/selftests/vfio/lib/drivers/nvme/nvme.c
> new file mode 100644
> index 0000000000000..4ae07c2c9a301
> --- /dev/null
> +++ b/tools/testing/selftests/vfio/lib/drivers/nvme/nvme.c

[ ... ]

> +static int nvme_wait_rdy(struct vfio_pci_device *device, bool rdy)
> +{
> +	void *bar0 = device->bars[0].vaddr;
> +	int timeout_ms;
> +	u32 csts;
> +	u64 cap;
> +
> +	cap = readq(bar0 + NVME_REG_CAP);
> +	timeout_ms = max(NVME_TIMEOUT_MS,
> +			 NVME_CAP_TIMEOUT(cap) * NVME_CAP_TIMEOUT_UNIT_MS);

[Severity: Low]
Should nvme_wait_rdy() also check NVME_REG_CRTO when rdy is true and the
controller advertises NVME_CAP_CRMS_CRWMS?

nvme_enable_ctrl() enables the controller with CC.CRIME clear, while
CAP.TO saturates at 127.5 seconds.  On an NVMe 2.0+ controller taking
longer to assert CSTS.RDY (e.g. via kvm/irq_test.c with no outer timeout),
nvme_wait_rdy() times out early and fails the assertion.

Using max(CAP.TO, NVME_CRTO_CRWMT(crto)) when NVME_CAP_CRMS_CRWMS is set
matches drivers/nvme/host/core.c.

[ ... ]

> +static void nvme_recover(struct vfio_pci_device *device)
> +{
> +	nvme_disable_ctrl(device);
> +	vfio_pci_device_reset(device);
> +	vfio_pci_msix_reenable(device, 0, device->driver.msi + 1);
> +	nvme_enable_ctrl(device);
> +	nvme_create_io_queues(device);
> +}

[Severity: Low]
Can vfio_pci_device_reset() abort the test here if the NVMe function does
not advertise VFIO_DEVICE_FLAGS_RESET?

nvme_probe() binds without checking VFIO_DEVICE_FLAGS_RESET.  When
vdev->reset_works is false, VFIO_DEVICE_RESET returns -EINVAL and
vfio_pci_device_reset() aborts on any failed memcpy, including the
unmapped-IOVA tests.

Checking VFIO_DEVICE_FLAGS_RESET in nvme_probe(), or gating
vfio_pci_device_reset() and vfio_pci_msix_reenable() on it in
nvme_recover(), would avoid this abort.

[ ... ]

> +	if (!memcmp(hdr->magic, NVME_SCRATCH_MAGIC, sizeof(NVME_SCRATCH_MAGIC))) {
> +		if (le64_to_cpu(hdr->size) >= max_size)
> +			return;
> +
> +		start = NVME_SCRATCH_HDR_SIZE + le64_to_cpu(hdr->size);
> +	}
> +
> +	chunk = min_t(u64, NVME_SCRATCH_CHUNK, max_size);
> +	end = NVME_SCRATCH_HDR_SIZE + max_size;
> +	for (offset = start; offset < end; offset += size) {
> +		size = min_t(u64, end - offset, chunk);
> +
> +		ret = nvme_scratch_rw(device, nvme_cmd_read, offset, size);

[Severity: Low]
Can an unaligned on-disk hdr->size cause nvme_claim_scratch() to abort in
nvme_prep_rw_cmd()?

If a small backing image was claimed with 512-byte logical blocks at a
non-4-KiB-aligned size and is later grown and attached with 4 KiB blocks,
start is not aligned to 1ULL << state->lba_shift, tripping the
IS_ALIGNED() assertion in nvme_prep_rw_cmd().

Checking IS_ALIGNED(le64_to_cpu(hdr->size), 1ULL << state->lba_shift) or
rounding start down to an LBA boundary would handle this cleanly.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204015203.318020-1-jrhilke@google.com?part=1

      reply	other threads:[~2026-12-04  2:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:52 [PATCH v2] vfio: selftests: Add NVMe driver Josh Hilke
2026-12-04  2:15 ` sashiko-bot [this message]

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=sashiko-outbox-248959@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jrhilke@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox