nvme small fix
cover nvme small fix
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(-)
Signature · 1 line
2.17.1
PATCH 1/3 nvme: use TYPE_NVME instead of constant string
--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +1 -1
@@ -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,
Signature · 1 line
2.17.1
PATCH 2/3 nvme: ensure the num_queues is not zero
In reply to Li QiangWhen 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--- hw/block/nvme.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/block/nvme.c +5 -0
@@ -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 ;
Signature · 1 line
2.17.1
PATCH 3/3 nvme: use pci_dev directly in nvme_realize
In reply to Li QiangThere is no need to make another reference.
--- hw/block/nvme.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/block/nvme.c +4 -4
@@ -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);
Signature · 1 line
2.17.1
Max Reitz
AppliedQuoted 12 lines · Li Qiang
This patchset contains small fix.
Change since v2:
For patch 2:
1. add nvme command
2. checknum_queuesfirstChange since v1:
1. drop the patch of checking return value of
msix_init_exclusive_bar
2. return when nvme'snum_queuesconfiguration is 0
Quoted 7 lines
Li Qiang (3):
nvme: useTYPE_NVMEinstead of constant string
nvme: ensure thenum_queuesis not zero
nvme: usepci_devdirectly innvme_realizehw/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