Skip to content

Commit

Permalink
hw/nvme: separate 'serial' property for VFs
Browse files Browse the repository at this point in the history
Currently, when a VF is created, it uses the 'params' object of the PF
as it is. In other words, the 'params.serial' string memory area is also
shared. In this situation, if the VF is removed from the system, the
PF's 'params.serial' object is released with object_finalize() followed
by object_property_del_all() which release the memory for 'serial'
property. If that happens, the next VF created will inherit a serial
from a corrupted memory area.

If this happens, an error will occur when comparing subsys->serial and
n->params.serial in the nvme_subsys_register_ctrl() function.

Cc: qemu-stable@nongnu.org
Fixes: 44c2c09 ("hw/nvme: Add support for SR-IOV")
Signed-off-by: Minwoo Im <minwoo.im@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
(cherry picked from commit 4f0a4a3)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
minwooim authored and Michael Tokarev committed Mar 13, 2024
1 parent 35ca0f7 commit 2d281e0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hw/nvme/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8309,9 +8309,15 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
if (pci_is_vf(pci_dev)) {
/*
* VFs derive settings from the parent. PF's lifespan exceeds
* that of VF's, so it's safe to share params.serial.
* that of VF's.
*/
memcpy(&n->params, &pn->params, sizeof(NvmeParams));

/*
* Set PF's serial value to a new string memory to prevent 'serial'
* property object release of PF when a VF is removed from the system.
*/
n->params.serial = g_strdup(pn->params.serial);
n->subsys = pn->subsys;
}

Expand Down

0 comments on commit 2d281e0

Please sign in to comment.