From nobody Sun Nov 9 22:28:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551982244328508.89681702227347; Thu, 7 Mar 2019 10:10:44 -0800 (PST) Received: from localhost ([127.0.0.1]:56661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xTa-0002YX-PV for importer@patchew.org; Thu, 07 Mar 2019 13:10:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wrJ-0003oU-Qb for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wrI-00008y-P3 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:05 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:35321) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wrI-00008R-EX for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:31:04 -0500 Received: by mail-wr1-x444.google.com with SMTP id t18so18425811wrx.2 for ; Thu, 07 Mar 2019 09:31:04 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.31.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ksqwWLcmi6STx+NL/mUX2ilS3SHd59BXFkubnB4B4kM=; b=Ns4/MrYmITdGzV+qwv+goXAVRaBCmFNbtr86ZbEW+0bDg0zf0c1Vul7TZbEwT29rTH xseCqhOdnILh1Sonf/vfkBuxWLnPppnO+JOhmwZjy17qwW2R+GfnIxrSIWkjJN4sUqaC GwE/9W+fCl/cAyEAEDROq6uj0PIPB7hTF7k+rxvdzjm6kpdRD+o8E1Kk2lHIIGUfxqE5 pTBs7R15EDgIKnGJnzpG1B7jcrszHhlATHyGyeyOivWPTl6SyBit5IJUzKP1b8+1h2hZ xj7KDVJiV6JL1oAr1tjQEMGorQKa2WEa8NbsvlYhWDvGlorRbg8gKcjNe9Lec6dg65CI abNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ksqwWLcmi6STx+NL/mUX2ilS3SHd59BXFkubnB4B4kM=; b=n8fzJjonqG46kHx/c9VVIjNAyEboCoJ+kIiQ2wRJaSooOXH5j/4EJ1H9pV3k63w2WG rz4ueGEuIS7Fltfd9fFeAm9Dw6xtngYDKc8xyP03Gnv0kRk+cmY0GnDlexRVWyoqCqBF 9NRc0ZoYh7qWd8gYj5ZEW3RGCm+1qQRXmNqb4Vc0bfZxPG/14gf0R+W2C7HmhGLpRHsO L3EdB6oAA23FaJI88jE6DNTxV7NLWgk3vieO8aDlELrmSfqPUCngCkux2ZhlI/76n20M MgpQ7D8MEKWO0H1TjIHVLsVU5nmFMO8TtzFzm6ybBnWq+W4v9u/F1PQsbcJc608Z9/hO 5hwA== X-Gm-Message-State: APjAAAXcpyEPrAFlkiQbXdBCvSfyalMu1UfgZWbPpbzP+pW9o3sOBMet jxREQUbjUOcv8nyxVW585ngCEakv X-Google-Smtp-Source: APXvYqzWLmvo/skejfH9fB6nBa87kl3brkm8EEYAr0KPrGb/p5/EiKh+RmrhAU2aRzuFh8UI8P5G9g== X-Received: by 2002:adf:ed11:: with SMTP id a17mr7734551wro.283.1551979863024; Thu, 07 Mar 2019 09:31:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:56 +0100 Message-Id: <1551979804-6060-50-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PULL 49/57] qos-test: nvme test node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Convert tests/nvme-test to a driver node; the code to discover the PCI device is replaced by generic qgraph code, therefore we're not placing it i= n tests/libqos. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 3 +- tests/nvme-test.c | 78 +++++++++++++++++++++++++++-------------------= ---- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 0d06490..46f8c34 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -155,7 +155,6 @@ check-qtest-pci-y +=3D tests/e1000-test$(EXESUF) check-qtest-pci-$(CONFIG_RTL8139_PCI) +=3D tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_PCNET_PCI) +=3D tests/pcnet-test$(EXESUF) check-qtest-pci-$(CONFIG_EEPRO100_PCI) +=3D tests/eepro100-test$(EXESUF) -check-qtest-pci-$(CONFIG_NVME_PCI) +=3D tests/nvme-test$(EXESUF) check-qtest-pci-$(CONFIG_ES1370) +=3D tests/es1370-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) +=3D tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) +=3D tests/intel-hda-test$(EXESUF) @@ -753,6 +752,7 @@ qos-test-obj-y +=3D tests/ac97-test.o qos-test-obj-y +=3D tests/e1000e-test.o qos-test-obj-y +=3D tests/ipoctal232-test.o qos-test-obj-y +=3D tests/ne2000-test.o +qos-test-obj-y +=3D tests/nvme-test.o qos-test-obj-y +=3D tests/pci-test.o qos-test-obj-y +=3D tests/sdhci-test.o qos-test-obj-$(CONFIG_VHOST_NET_USER) +=3D tests/vhost-user-test.o $(chard= ev-obj-y) $(test-io-obj-y) @@ -814,7 +814,6 @@ tests/test-hmp$(EXESUF): tests/test-hmp.o tests/machine-none-test$(EXESUF): tests/machine-none-test.o tests/device-plug-test$(EXESUF): tests/device-plug-test.o tests/drive_del-test$(EXESUF): tests/drive_del-test.o -tests/nvme-test$(EXESUF): tests/nvme-test.o $(libqos-pc-obj-y) tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o tests/i82801b11-test$(EXESUF): tests/i82801b11-test.o tests/es1370-test$(EXESUF): tests/es1370-test.o diff --git a/tests/nvme-test.c b/tests/nvme-test.c index 2700ba8..b48d3a2 100644 --- a/tests/nvme-test.c +++ b/tests/nvme-test.c @@ -10,49 +10,47 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "libqtest.h" -#include "libqos/libqos-pc.h" +#include "libqos/qgraph.h" +#include "libqos/pci.h" =20 -static QOSState *qnvme_start(const char *extra_opts) +typedef struct QNvme QNvme; + +struct QNvme { + QOSGraphObject obj; + QPCIDevice dev; +}; + +static void *nvme_get_driver(void *obj, const char *interface) { - QOSState *qs; - const char *arch =3D qtest_get_arch(); - const char *cmd =3D "-drive id=3Ddrv0,if=3Dnone,file=3Dnull-co://,form= at=3Draw " - "-device nvme,addr=3D0x4.0,serial=3Dfoo,drive=3Ddrv0= %s"; - - if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { - qs =3D qtest_pc_boot(cmd, extra_opts ? : ""); - global_qtest =3D qs->qts; - return qs; + QNvme *nvme =3D obj; + + if (!g_strcmp0(interface, "pci-device")) { + return &nvme->dev; } =20 - g_printerr("nvme tests are only available on x86\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "%s not present in nvme\n", interface); + g_assert_not_reached(); } =20 -static void qnvme_stop(QOSState *qs) +static void *nvme_create(void *pci_bus, QGuestAllocator *alloc, void *addr) { - qtest_shutdown(qs); -} + QNvme *nvme =3D g_new0(QNvme, 1); + QPCIBus *bus =3D pci_bus; =20 -static void nop(void) -{ - QOSState *qs; + qpci_device_init(&nvme->dev, bus, addr); + nvme->obj.get_driver =3D nvme_get_driver; =20 - qs =3D qnvme_start(NULL); - qnvme_stop(qs); + return &nvme->obj; } =20 -static void nvmetest_cmb_test(void) +/* This used to cause a NULL pointer dereference. */ +static void nvmetest_oob_cmb_test(void *obj, void *data, QGuestAllocator *= alloc) { const int cmb_bar_size =3D 2 * MiB; - QOSState *qs; - QPCIDevice *pdev; + QNvme *nvme =3D obj; + QPCIDevice *pdev =3D &nvme->dev; QPCIBar bar; =20 - qs =3D qnvme_start("-global nvme.cmb_size_mb=3D2"); - pdev =3D qpci_device_find(qs->pcibus, QPCI_DEVFN(4,0)); - g_assert(pdev !=3D NULL); - qpci_device_enable(pdev); bar =3D qpci_iomap(pdev, 2, NULL); =20 @@ -65,16 +63,24 @@ static void nvmetest_cmb_test(void) g_assert_cmpint(qpci_io_readb(pdev, bar, cmb_bar_size - 1), =3D=3D, 0x= 11); g_assert_cmpint(qpci_io_readw(pdev, bar, cmb_bar_size - 1), !=3D, 0x22= 11); g_assert_cmpint(qpci_io_readl(pdev, bar, cmb_bar_size - 1), !=3D, 0x44= 332211); - g_free(pdev); - - qnvme_stop(qs); } =20 -int main(int argc, char **argv) +static void nvme_register_nodes(void) { - g_test_init(&argc, &argv, NULL); - qtest_add_func("/nvme/nop", nop); - qtest_add_func("/nvme/cmb_test", nvmetest_cmb_test); + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D04.0,drive=3Ddrv0,serial=3Dfoo", + .before_cmd_line =3D "-drive id=3Ddrv0,if=3Dnone,file=3Dnull-co://= ,format=3Draw", + }; + + add_qpci_address(&opts, &(QPCIAddress) { .devfn =3D QPCI_DEVFN(4, 0) }= ); =20 - return g_test_run(); + qos_node_create_driver("nvme", nvme_create); + qos_node_consumes("nvme", "pci-bus", &opts); + qos_node_produces("nvme", "pci-device"); + + qos_add_test("oob-cmb-access", "nvme", nvmetest_oob_cmb_test, &(QOSGra= phTestOptions) { + .edge.extra_device_opts =3D "cmb_size_mb=3D2" + }); } + +libqos_init(nvme_register_nodes); --=20 1.8.3.1