All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Alexander Mikhalitsyn <alexander@mihalicyn.com>
Cc: qemu-devel@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
	qemu-block@nongnu.org, "Fam Zheng" <fam@euphon.net>,
	"Stéphane Graber" <stgraber@stgraber.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Jesper Devantier" <foss@defmacro.it>,
	"Klaus Jensen" <its@irrelevant.dk>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Zhao Liu" <zhao1.liu@intel.com>,
	"Keith Busch" <kbusch@kernel.org>, "Peter Xu" <peterx@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Alexander Mikhalitsyn" <aleksandr.mikhalitsyn@futurfusion.io>
Subject: Re: [PATCH v6 8/8] tests/qtest/nvme-test: add migration test with full CQ
Date: Mon, 27 Apr 2026 16:00:04 -0400	[thread overview]
Message-ID: <20260427200004.GF218226@fedora> (raw)
In-Reply-To: <20260419130139.15554-9-alexander@mihalicyn.com>

[-- Attachment #1: Type: text/plain, Size: 3018 bytes --]

On Sun, Apr 19, 2026 at 03:01:39PM +0200, Alexander Mikhalitsyn wrote:
> +static void test_migrate_check_nvme(nvme_ctrl *ctrl, test_migrate_req *reqs, int num)
> +{
> +    int i;
> +
> +    for (i = 0; i < num; i++) {
> +        NvmeCqe cqe;
> +
> +        if (reqs[i].handle_cqe) {
> +            continue;
> +        }
> +
> +        cqe = nvme_wait(&ctrl->admin_sq);
> +        g_assert(nvme_is_cqe_success(&cqe));
> +
> +        g_assert_cmpint(cqe.cid, ==, reqs[i].cid);

Please check the endianness in this patch. I don't see an le16_to_cpu()
call here.

Maybe other NVMe DMA structures or registers are also not converted
to/from little endian. This test must pass on both big-endian and
little-endian hosts.

> +
> +        #define GUEST_MEM_READB(field) \
> +                            qtest_readb(ctrl->pdev->bus->qts, (uint64_t)&(field))
> +
> +        g_assert_cmpint(GUEST_MEM_READB(reqs[i].phys_identify->ieee[0]), ==, 0x0);

I was trying to figure out why phys_identify has a pointer type although
it is a guest memory address that cannot be dereferenced in C code. I
guess the reason is so that the GUEST_MEM_READB() macro can use the
address-of operator instead of explicitly calculating the offset of
ieee[0], ieee[1], etc? I found this confusing and potentially dangerous
(the compiler won't stop the pointer from being dereferenced if someone
does it by mistake).

It took more time to review the pointer trick than the straightforward
approach would have taken. I'd avoid it, but it's a question of coding
style and up to you.

> +        g_assert_cmpint(GUEST_MEM_READB(reqs[i].phys_identify->ieee[1]), ==, 0x54);
> +        g_assert_cmpint(GUEST_MEM_READB(reqs[i].phys_identify->ieee[2]), ==, 0x52);
> +
> +        #undef GUEST_MEM_READB
> +
> +        guest_free(ctrl->alloc, (uint64_t)reqs[i].phys_identify);
> +    }
> +}
> +
> +static void test_migrate(void *obj, void *data, QGuestAllocator *alloc)
> +{
> +    g_autofree gchar *tmpfs = NULL;
> +    GError *err = NULL;
> +    g_autofree gchar *mig_path;
> +    g_autofree gchar *uri;
> +    GString *dest_cmdline;
> +    QTestState *to;
> +    QDict *rsp;
> +    QNvme *nvme = obj;
> +    QPCIDevice *pdev = &nvme->dev;
> +    nvme_ctrl *ctrl;
> +    test_migrate_req test_reqs[] = {
> +        { 123, true },
> +        { 456, false },
> +        { 300, false },
> +        { 333, false }
> +    };
> +
> +    /* create temporary dir and prepare unix socket path for migration */
> +    tmpfs = g_dir_make_tmp("nvme-test-XXXXXX", &err);
> +    if (!tmpfs) {
> +        g_test_message("Can't create temporary directory in %s: %s",
> +                       g_get_tmp_dir(), err->message);
> +        g_error_free(err);
> +    }
> +    g_assert(tmpfs);
> +
> +    mig_path = g_strdup_printf("%s/socket.mig", tmpfs);
> +    uri = g_strdup_printf("unix:%s", mig_path);
> +
> +    /* enable NVMe PCI device */
> +    qpci_device_enable(pdev);
> +
> +    ctrl = g_malloc0(sizeof(*ctrl));

I don't see a g_free() call for ctrl. Use g_autofree?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-04-27 20:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 13:01 [PATCH v6 0/8] hw/nvme: add basic live migration support Alexander Mikhalitsyn
2026-04-19 13:01 ` [PATCH v6 1/8] tests/functional/migration: add VM launch/configure hooks Alexander Mikhalitsyn
2026-04-19 13:01 ` [PATCH v6 2/8] hw/nvme: add migration blockers for non-supported cases Alexander Mikhalitsyn
2026-04-19 13:01 ` [PATCH v6 3/8] hw/nvme: split nvme_init_sq/nvme_init_cq into helpers Alexander Mikhalitsyn
2026-04-29  6:20   ` Klaus Jensen
2026-04-19 13:01 ` [PATCH v6 4/8] hw/nvme: set CQE.sq_id earlier in nvme_process_sq Alexander Mikhalitsyn
2026-04-29  6:18   ` Klaus Jensen
2026-04-19 13:01 ` [PATCH v6 5/8] hw/nvme: unmap req->sg earlier in nvme_enqueue_req_completion Alexander Mikhalitsyn
2026-04-29  6:19   ` Klaus Jensen
2026-04-19 13:01 ` [PATCH v6 6/8] hw/nvme: add basic live migration support Alexander Mikhalitsyn
2026-04-27 21:03   ` Stefan Hajnoczi
2026-04-28 15:38     ` Alexander Mikhalitsyn
2026-04-19 13:01 ` [PATCH v6 7/8] tests/functional/x86_64: add migration test for NVMe device Alexander Mikhalitsyn
2026-04-19 13:01 ` [PATCH v6 8/8] tests/qtest/nvme-test: add migration test with full CQ Alexander Mikhalitsyn
2026-04-27 20:00   ` Stefan Hajnoczi [this message]
2026-04-28 15:55     ` Alexander Mikhalitsyn
2026-04-28 16:13       ` 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=20260427200004.GF218226@fedora \
    --to=stefanha@redhat.com \
    --cc=aleksandr.mikhalitsyn@futurfusion.io \
    --cc=alexander@mihalicyn.com \
    --cc=fam@euphon.net \
    --cc=farosas@suse.de \
    --cc=foss@defmacro.it \
    --cc=hreitz@redhat.com \
    --cc=its@irrelevant.dk \
    --cc=kbusch@kernel.org \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stgraber@stgraber.org \
    --cc=zhao1.liu@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 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.