qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] nvme small fix
@ 2019-01-20  5:55 Li Qiang
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 1/3] nvme: use TYPE_NVME instead of constant string Li Qiang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Li Qiang @ 2019-01-20  5:55 UTC (permalink / raw)
  To: keith.busch, kwolf, mreitz, philmd; +Cc: qemu-block, qemu-devel, Li Qiang

This patchset contains small fix.

Change since v2:
For patch 2:
1. add nvme command
2. check num_queues first

Change since v1: 

1. drop the patch of checking return value of msix_init_exclusive_bar
2. return when nvme's num_queues configuration is 0

Li Qiang (3):
  nvme: use TYPE_NVME instead of constant string
  nvme: ensure the num_queues is not zero
  nvme: use pci_dev directly in nvme_realize

 hw/block/nvme.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/3] nvme: use TYPE_NVME instead of constant string
  2019-01-20  5:55 [Qemu-devel] [PATCH 0/3] nvme small fix Li Qiang
@ 2019-01-20  5:55 ` Li Qiang
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 2/3] nvme: ensure the num_queues is not zero Li Qiang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Li Qiang @ 2019-01-20  5:55 UTC (permalink / raw)
  To: keith.busch, kwolf, mreitz, philmd; +Cc: qemu-block, qemu-devel, Li Qiang

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 644 bytes --]

Signed-off-by: Li Qiang <liq3ea@163.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 7c8c63e8f5..f206391e8e 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1381,7 +1381,7 @@ static void nvme_instance_init(Object *obj)
 }
 
 static const TypeInfo nvme_info = {
-    .name          = "nvme",
+    .name          = TYPE_NVME,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(NvmeCtrl),
     .class_init    = nvme_class_init,
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/3] nvme: ensure the num_queues is not zero
  2019-01-20  5:55 [Qemu-devel] [PATCH 0/3] nvme small fix Li Qiang
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 1/3] nvme: use TYPE_NVME instead of constant string Li Qiang
@ 2019-01-20  5:55 ` Li Qiang
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 3/3] nvme: use pci_dev directly in nvme_realize Li Qiang
  2019-01-21  0:10 ` [Qemu-devel] [PATCH 0/3] nvme small fix Max Reitz
  3 siblings, 0 replies; 5+ messages in thread
From: Li Qiang @ 2019-01-20  5:55 UTC (permalink / raw)
  To: keith.busch, kwolf, mreitz, philmd; +Cc: qemu-block, qemu-devel, Li Qiang

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3358 bytes --]

When it is zero, it causes segv.
Using following command:

"-drive file=//home/test/test1.img,if=none,id=id0
-device nvme,drive=id0,serial=test,num_queues=0"
causes following Backtrack:

Thread 4 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe9735700 (LWP 30952)]
0x0000555555a7a77c in nvme_start_ctrl (n=0x5555577473f0) at hw/block/nvme.c:825
825	    if (unlikely(n->cq[0])) {
(gdb) bt
0  0x0000555555a7a77c in nvme_start_ctrl (n=0x5555577473f0)
    at hw/block/nvme.c:825
1  0x0000555555a7af7f in nvme_write_bar (n=0x5555577473f0, offset=20,
    data=4587521, size=4) at hw/block/nvme.c:969
2  0x0000555555a7b81a in nvme_mmio_write (opaque=0x5555577473f0, addr=20,
    data=4587521, size=4) at hw/block/nvme.c:1163
3  0x0000555555869236 in memory_region_write_accessor (mr=0x555557747cd0,
    addr=20, value=0x7fffe97320f8, size=4, shift=0, mask=4294967295, attrs=...)
    at /home/test/qemu1/qemu/memory.c:502
4  0x0000555555869446 in access_with_adjusted_size (addr=20,
    value=0x7fffe97320f8, size=4, access_size_min=2, access_size_max=8,
    access_fn=0x55555586914d <memory_region_write_accessor>,
    mr=0x555557747cd0, attrs=...) at /home/test/qemu1/qemu/memory.c:568
5  0x000055555586c479 in memory_region_dispatch_write (mr=0x555557747cd0,
    addr=20, data=4587521, size=4, attrs=...)
    at /home/test/qemu1/qemu/memory.c:1499
6  0x00005555558030af in flatview_write_continue (fv=0x7fffe0061130,
    addr=4273930260, attrs=..., buf=0x7ffff7ff0028 "\001", len=4, addr1=20,
    l=4, mr=0x555557747cd0) at /home/test/qemu1/qemu/exec.c:3234
7  0x00005555558031f9 in flatview_write (fv=0x7fffe0061130, addr=4273930260,
    attrs=..., buf=0x7ffff7ff0028 "\001", len=4)
    at /home/test/qemu1/qemu/exec.c:3273
8  0x00005555558034ff in address_space_write (
---Type <return> to continue, or q <return> to quit---
    as=0x555556758480 <address_space_memory>, addr=4273930260, attrs=...,
    buf=0x7ffff7ff0028 "\001", len=4) at /home/test/qemu1/qemu/exec.c:3363
9  0x0000555555803550 in address_space_rw (
    as=0x555556758480 <address_space_memory>, addr=4273930260, attrs=...,
    buf=0x7ffff7ff0028 "\001", len=4, is_write=true)
    at /home/test/qemu1/qemu/exec.c:3374
10 0x00005555558884a1 in kvm_cpu_exec (cpu=0x555556920e40)
    at /home/test/qemu1/qemu/accel/kvm/kvm-all.c:2031
11 0x000055555584cd9d in qemu_kvm_cpu_thread_fn (arg=0x555556920e40)
    at /home/test/qemu1/qemu/cpus.c:1281
12 0x0000555555dbaf6d in qemu_thread_start (args=0x5555569438a0)
    at util/qemu-thread-posix.c:502
13 0x00007ffff5dc86db in start_thread (arg=0x7fffe9735700)
    at pthread_create.c:463
14 0x00007ffff5af188f in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Signed-off-by: Li Qiang <liq3ea@163.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/block/nvme.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index f206391e8e..0b77b49b36 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1208,6 +1208,11 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
     int64_t bs_size;
     uint8_t *pci_conf;
 
+    if (!n->num_queues) {
+        error_setg(errp, "num_queues can't be zero");
+        return;
+    }
+
     if (!n->conf.blk) {
         error_setg(errp, "drive property not set");
         return;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 3/3] nvme: use pci_dev directly in nvme_realize
  2019-01-20  5:55 [Qemu-devel] [PATCH 0/3] nvme small fix Li Qiang
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 1/3] nvme: use TYPE_NVME instead of constant string Li Qiang
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 2/3] nvme: ensure the num_queues is not zero Li Qiang
@ 2019-01-20  5:55 ` Li Qiang
  2019-01-21  0:10 ` [Qemu-devel] [PATCH 0/3] nvme small fix Max Reitz
  3 siblings, 0 replies; 5+ messages in thread
From: Li Qiang @ 2019-01-20  5:55 UTC (permalink / raw)
  To: keith.busch, kwolf, mreitz, philmd; +Cc: qemu-block, qemu-devel, Li Qiang

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 2076 bytes --]

There is no need to make another reference.

Signed-off-by: Li Qiang <liq3ea@163.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/block/nvme.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 0b77b49b36..8325b5e88a 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1238,7 +1238,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
     pci_conf[PCI_INTERRUPT_PIN] = 1;
     pci_config_set_prog_interface(pci_dev->config, 0x2);
     pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS);
-    pcie_endpoint_cap_init(&n->parent_obj, 0x80);
+    pcie_endpoint_cap_init(pci_dev, 0x80);
 
     n->num_namespaces = 1;
     n->reg_size = pow2ceil(0x1004 + 2 * (n->num_queues + 1) * 4);
@@ -1250,10 +1250,10 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
 
     memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n,
                           "nvme", n->reg_size);
-    pci_register_bar(&n->parent_obj, 0,
+    pci_register_bar(pci_dev, 0,
         PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64,
         &n->iomem);
-    msix_init_exclusive_bar(&n->parent_obj, n->num_queues, 4, NULL);
+    msix_init_exclusive_bar(pci_dev, n->num_queues, 4, NULL);
 
     id->vid = cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID));
     id->ssvid = cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID));
@@ -1308,7 +1308,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
         n->cmbuf = g_malloc0(NVME_CMBSZ_GETSIZE(n->bar.cmbsz));
         memory_region_init_io(&n->ctrl_mem, OBJECT(n), &nvme_cmb_ops, n,
                               "nvme-cmb", NVME_CMBSZ_GETSIZE(n->bar.cmbsz));
-        pci_register_bar(&n->parent_obj, NVME_CMBLOC_BIR(n->bar.cmbloc),
+        pci_register_bar(pci_dev, NVME_CMBLOC_BIR(n->bar.cmbloc),
             PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64 |
             PCI_BASE_ADDRESS_MEM_PREFETCH, &n->ctrl_mem);
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] nvme small fix
  2019-01-20  5:55 [Qemu-devel] [PATCH 0/3] nvme small fix Li Qiang
                   ` (2 preceding siblings ...)
  2019-01-20  5:55 ` [Qemu-devel] [PATCH 3/3] nvme: use pci_dev directly in nvme_realize Li Qiang
@ 2019-01-21  0:10 ` Max Reitz
  3 siblings, 0 replies; 5+ messages in thread
From: Max Reitz @ 2019-01-21  0:10 UTC (permalink / raw)
  To: Li Qiang, keith.busch, kwolf, philmd; +Cc: qemu-block, qemu-devel

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

On 20.01.19 06:55, Li Qiang wrote:
> This patchset contains small fix.
> 
> Change since v2:
> For patch 2:
> 1. add nvme command
> 2. check num_queues first
> 
> Change since v1: 
> 
> 1. drop the patch of checking return value of msix_init_exclusive_bar
> 2. return when nvme's num_queues configuration is 0
> 
> Li Qiang (3):
>   nvme: use TYPE_NVME instead of constant string
>   nvme: ensure the num_queues is not zero
>   nvme: use pci_dev directly in nvme_realize
> 
>  hw/block/nvme.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)

Thanks, applied to my block branch:

https://git.xanclic.moe/XanClic/qemu/commits/branch/block

Max


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-21  0:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-20  5:55 [Qemu-devel] [PATCH 0/3] nvme small fix Li Qiang
2019-01-20  5:55 ` [Qemu-devel] [PATCH 1/3] nvme: use TYPE_NVME instead of constant string Li Qiang
2019-01-20  5:55 ` [Qemu-devel] [PATCH 2/3] nvme: ensure the num_queues is not zero Li Qiang
2019-01-20  5:55 ` [Qemu-devel] [PATCH 3/3] nvme: use pci_dev directly in nvme_realize Li Qiang
2019-01-21  0:10 ` [Qemu-devel] [PATCH 0/3] nvme small fix Max Reitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).