[PATCH for 9.1 v9 00/11] hw/pci: SR-IOV related fixes and improvements

2024-03-14 Thread Akihiko Odaki
://patchew.org/QEMU/20231210-sriov-v2-0-b959e8a6d...@daynix.com/ Signed-off-by: Akihiko Odaki --- Changes in v9: - Rebased. - Restored '#include "qapi/error.h"' (Michael S. Tsirkin) - Added patch "pcie_sriov: Ensure VF function number does not overflow" to fix abortion with wrong P

[PATCH for 9.1 v9 02/11] pcie_sriov: Do not manually unrealize

2024-03-14 Thread Akihiko Odaki
A device gets automatically unrealized when being unparented. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 4 1 file changed, 4 deletions(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index e9b23221d713..499becd5273f 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci

[PATCH for 9.1 v9 01/11] hw/pci: Rename has_power to enabled

2024-03-14 Thread Akihiko Odaki
The renamed state will not only represent powering state of PFs, but also represent SR-IOV VF enablement in the future. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci.h| 7 ++- include/hw/pci/pci_device.h | 2 +- hw/pci/pci.c| 14 +++--- hw/pci

[PATCH for 9.1 v9 04/11] pcie_sriov: Reuse SR-IOV VF device instances

2024-03-14 Thread Akihiko Odaki
Disable SR-IOV VF devices by reusing code to power down PCI devices instead of removing them when the guest requests to disable VFs. This allows to realize devices and report VF realization errors at PF realization time. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci.h| 5

[PATCH for 9.1 v9 09/11] hw/pci: Use UINT32_MAX as a default value for rombar

2024-03-14 Thread Akihiko Odaki
ers to a different variable in qxl. It is only tested if the value is 0 or not in the other places. If a user explicitly set UINT32_MAX, we still cannot distinguish that from the implicit default. However, it is unlikely to be a problem as nobody would type literal UINT32_MAX (0xffff or 4294967295)

[PATCH for 9.1 v9 06/11] pcie_sriov: Remove num_vfs from PCIESriovPF

2024-03-14 Thread Akihiko Odaki
num_vfs is not migrated so use PCI_SRIOV_CTRL_VFE and PCI_SRIOV_NUM_VF instead. Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 1 - hw/pci/pcie_sriov.c | 28 hw/pci/trace-events | 2 +- 3 files changed, 21 insertions(+), 10

[PATCH for 9.1 v9 07/11] pcie_sriov: Register VFs after migration

2024-03-14 Thread Akihiko Odaki
pcie_sriov doesn't have code to restore its state after migration, but igb, which uses pcie_sriov, naively claimed its migration capability. Add code to register VFs after migration and fix igb migration. Fixes: 3a977deebe6b ("Intrdocue igb device emulation") Signed-off-by: Aki

[PATCH for 9.1 v9 05/11] pcie_sriov: Release VFs failed to realize

2024-03-14 Thread Akihiko Odaki
Release VFs failed to realize just as we do in unregister_vfs(). Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/pci/pcie_sriov.

[PATCH for 9.1 v9 10/11] hw/pci: Determine if rombar is explicitly enabled

2024-03-14 Thread Akihiko Odaki
. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 + hw/vfio/pci.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index ca151325085d..6be0f989ebe0 100644 --- a/include/hw/pci

[PATCH v7 08/16] pcie_sriov: Reuse SR-IOV VF device instances

2024-02-24 Thread Akihiko Odaki
Disable SR-IOV VF devices by reusing code to power down PCI devices instead of removing them when the guest requests to disable VFs. This allows to realize devices and report VF realization errors at PF realization time. Signed-off-by: Akihiko Odaki --- docs/pcie_sriov.txt | 8

[PATCH v7 14/16] hw/pci: Determine if rombar is explicitly enabled

2024-02-24 Thread Akihiko Odaki
vfio determines if rombar is explicitly enabled by inspecting QDict. Inspecting QDict is not nice because QDict is untyped and depends on the details on the external interface. Add an infrastructure to determine if rombar is explicitly enabled to hw/pci. Signed-off-by: Akihiko Odaki --- include

[PATCH v7 09/16] pcie_sriov: Release VFs failed to realize

2024-02-24 Thread Akihiko Odaki
Release VFs failed to realize just as we do in unregister_vfs(). Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/pci/pcie_sriov.

[PATCH v7 13/16] hw/pci: Use UINT32_MAX as a default value for rombar

2024-02-24 Thread Akihiko Odaki
owever, considering that its meaning was no different from 1 and typing a literal UINT32_MAX (0x or 4294967295) is more troublesome. Signed-off-by: Akihiko Odaki --- hw/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 84df07a2789b

[PATCH v7 01/16] hw/nvme: Use pcie_sriov_num_vfs()

2024-02-24 Thread Akihiko Odaki
ation Management command") Suggested-by: Michael S. Tsirkin Signed-off-by: Akihiko Odaki --- hw/nvme/ctrl.c | 26 -- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f026245d1e9e..7a56e7b79b4d 100644 --- a/hw/nvme/ct

[PATCH v7 02/16] pcie_sriov: Validate NumVFs

2024-02-24 Thread Akihiko Odaki
The guest may write NumVFs greater than TotalVFs and that can lead to buffer overflow in VF implementations. Cc: qemu-sta...@nongnu.org Fixes: CVE-2024-26327 Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki -

[PATCH v7 03/16] pcie_sriov: Reset SR-IOV extended capability

2024-02-24 Thread Akihiko Odaki
not only disable VFs but also resets the capability. Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 4 ++-- hw/net/igb.c| 2 +- hw/nvme/ctrl.c | 2 +- hw/pci/pcie_sriov.c | 26 ++ 4 files changed, 22 insertions(+), 12

[PATCH v7 10/16] pcie_sriov: Remove num_vfs from PCIESriovPF

2024-02-24 Thread Akihiko Odaki
num_vfs is not migrated so use PCI_SRIOV_CTRL_VFE and PCI_SRIOV_NUM_VF instead. Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 1 - hw/pci/pcie_sriov.c | 28 hw/pci/trace-events | 2 +- 3 files changed, 21 insertions(+), 10

[PATCH v7 15/16] vfio: Avoid inspecting option QDict for rombar

2024-02-24 Thread Akihiko Odaki
Use pci_rom_bar_explicitly_enabled() to determine if rombar is explicitly enabled. Signed-off-by: Akihiko Odaki --- hw/vfio/pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4fa387f0430d..647f15b2a060 100644 --- a/hw/vfio/pci.c +++ b

[PATCH v7 12/16] hw/pci: Replace -1 with UINT32_MAX for romsize

2024-02-24 Thread Akihiko Odaki
-off-by: Akihiko Odaki --- hw/pci/pci.c | 8 hw/xen/xen_pt_load_rom.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 54b375da2d26..84df07a2789b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -70,7 +70,7 @@ static bool

[PATCH v7 16/16] hw/qdev: Remove opts member

2024-02-24 Thread Akihiko Odaki
It is no longer used. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster --- include/hw/qdev-core.h | 4 hw/core/qdev.c | 1 - system/qdev-monitor.c | 12 +++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git

[PATCH v7 05/16] hw/pci: Always call pcie_sriov_pf_reset()

2024-02-24 Thread Akihiko Odaki
Call pcie_sriov_pf_reset() from pci_do_device_reset() just as we do for msi_reset() and msix_reset() to prevent duplicating code for each SR-IOV PF. Signed-off-by: Akihiko Odaki --- hw/net/igb.c | 2 -- hw/nvme/ctrl.c | 4 hw/pci/pci.c | 1 + 3 files changed, 1 insertion(+), 6

[PATCH v7 04/16] pcie_sriov: Do not reset NumVFs after disabling VFs

2024-02-24 Thread Akihiko Odaki
R/IOV)") Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 51b66d1bb342..e9b23221d713 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -215,7 +215,6 @@ s

[PATCH v7 06/16] hw/pci: Rename has_power to enabled

2024-02-24 Thread Akihiko Odaki
The renamed state will not only represent powering state of PFs, but also represent SR-IOV VF enablement in the future. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci.h| 7 ++- include/hw/pci/pci_device.h | 2 +- hw/pci/pci.c| 14 +++--- hw/pci

[PATCH v7 07/16] pcie_sriov: Do not manually unrealize

2024-02-24 Thread Akihiko Odaki
A device gets automatically unrealized when being unparented. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 5 - 1 file changed, 5 deletions(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index e9b23221d713..8b1fd2a89ad7 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci

[PATCH v7 11/16] pcie_sriov: Register VFs after migration

2024-02-24 Thread Akihiko Odaki
pcie_sriov doesn't have code to restore its state after migration, but igb, which uses pcie_sriov, naively claimed its migration capability. Add code to register VFs after migration and fix igb migration. Fixes: 3a977deebe6b ("Intrdocue igb device emulation") Signed-off-by: Aki

[PATCH v7 00/16] hw/pci: SR-IOV related fixes and improvements

2024-02-24 Thread Akihiko Odaki
://patchew.org/QEMU/20231210-sriov-v2-0-b959e8a6d...@daynix.com/ Signed-off-by: Akihiko Odaki --- Changes in v7: - Replaced -1 with UINT32_MAX when expressing uint32_t. (Markus Armbruster) - Added patch "hw/pci: Replace -1 with UINT32_MAX for romsize". - Link to v6: https://lore.kernel.org/

[PATCH v8 11/15] pcie_sriov: Register VFs after migration

2024-02-28 Thread Akihiko Odaki
pcie_sriov doesn't have code to restore its state after migration, but igb, which uses pcie_sriov, naively claimed its migration capability. Add code to register VFs after migration and fix igb migration. Fixes: 3a977deebe6b ("Intrdocue igb device emulation") Signed-off-by: Aki

[PATCH v8 03/15] pcie_sriov: Reset SR-IOV extended capability

2024-02-28 Thread Akihiko Odaki
not only disable VFs but also resets the capability. Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 4 ++-- hw/net/igb.c| 2 +- hw/nvme/ctrl.c | 2 +- hw/pci/pcie_sriov.c | 26 ++ 4 files changed, 22 insertions(+), 12

[PATCH v8 01/15] hw/nvme: Use pcie_sriov_num_vfs()

2024-02-28 Thread Akihiko Odaki
ation Management command") Suggested-by: Michael S. Tsirkin Signed-off-by: Akihiko Odaki --- hw/nvme/ctrl.c | 26 -- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f026245d1e9e..7a56e7b79b4d 100644 --- a/hw/nvme/ct

[PATCH v8 05/15] hw/pci: Always call pcie_sriov_pf_reset()

2024-02-28 Thread Akihiko Odaki
Call pcie_sriov_pf_reset() from pci_do_device_reset() just as we do for msi_reset() and msix_reset() to prevent duplicating code for each SR-IOV PF. Signed-off-by: Akihiko Odaki --- hw/net/igb.c | 2 -- hw/nvme/ctrl.c | 4 hw/pci/pci.c | 1 + 3 files changed, 1 insertion(+), 6

[PATCH v8 06/15] hw/pci: Rename has_power to enabled

2024-02-28 Thread Akihiko Odaki
The renamed state will not only represent powering state of PFs, but also represent SR-IOV VF enablement in the future. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci.h| 7 ++- include/hw/pci/pci_device.h | 2 +- hw/pci/pci.c| 14 +++--- hw/pci

[PATCH v8 08/15] pcie_sriov: Reuse SR-IOV VF device instances

2024-02-28 Thread Akihiko Odaki
Disable SR-IOV VF devices by reusing code to power down PCI devices instead of removing them when the guest requests to disable VFs. This allows to realize devices and report VF realization errors at PF realization time. Signed-off-by: Akihiko Odaki --- docs/pcie_sriov.txt | 8

[PATCH v8 12/15] hw/pci: Replace -1 with UINT32_MAX for romsize

2024-02-28 Thread Akihiko Odaki
and prevent potential breakage. Signed-off-by: Akihiko Odaki Reviewed-by: Markus Armbruster --- hw/pci/pci.c | 8 hw/xen/xen_pt_load_rom.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 54b375da2d26..84df07a2789b 100644

[PATCH v8 07/15] pcie_sriov: Do not manually unrealize

2024-02-28 Thread Akihiko Odaki
A device gets automatically unrealized when being unparented. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 5 - 1 file changed, 5 deletions(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index e9b23221d713..8b1fd2a89ad7 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci

[PATCH v8 00/15] hw/pci: SR-IOV related fixes and improvements

2024-02-28 Thread Akihiko Odaki
://patchew.org/QEMU/20231210-sriov-v2-0-b959e8a6d...@daynix.com/ Signed-off-by: Akihiko Odaki --- Changes in v8: - Clarified that "hw/pci: Replace -1 with UINT32_MAX for romsize" is not a bug fix. (Markus Armbruster) - Squashed patch "vfio: Avoid inspecting option QDict for rombar&

[PATCH v8 10/15] pcie_sriov: Remove num_vfs from PCIESriovPF

2024-02-28 Thread Akihiko Odaki
num_vfs is not migrated so use PCI_SRIOV_CTRL_VFE and PCI_SRIOV_NUM_VF instead. Signed-off-by: Akihiko Odaki --- include/hw/pci/pcie_sriov.h | 1 - hw/pci/pcie_sriov.c | 28 hw/pci/trace-events | 2 +- 3 files changed, 21 insertions(+), 10

[PATCH v8 09/15] pcie_sriov: Release VFs failed to realize

2024-02-28 Thread Akihiko Odaki
Release VFs failed to realize just as we do in unregister_vfs(). Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/pci/pcie_sriov.

[PATCH v8 14/15] hw/pci: Determine if rombar is explicitly enabled

2024-02-28 Thread Akihiko Odaki
. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 + hw/vfio/pci.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index ca151325085d..6be0f989ebe0 100644 --- a/include/hw/pci

[PATCH v8 02/15] pcie_sriov: Validate NumVFs

2024-02-28 Thread Akihiko Odaki
The guest may write NumVFs greater than TotalVFs and that can lead to buffer overflow in VF implementations. Cc: qemu-sta...@nongnu.org Fixes: CVE-2024-26327 Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)") Signed-off-by: Akihiko Odaki -

[PATCH v8 04/15] pcie_sriov: Do not reset NumVFs after disabling VFs

2024-02-28 Thread Akihiko Odaki
R/IOV)") Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 51b66d1bb342..e9b23221d713 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -215,7 +215,6 @@ s

[PATCH v8 15/15] hw/qdev: Remove opts member

2024-02-28 Thread Akihiko Odaki
It is no longer used. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Markus Armbruster --- include/hw/qdev-core.h | 4 hw/core/qdev.c | 1 - system/qdev-monitor.c | 12 +++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git

[PATCH v8 13/15] hw/pci: Use UINT32_MAX as a default value for rombar

2024-02-28 Thread Akihiko Odaki
ers to a different variable in qxl. It is only tested if the value is 0 or not in the other places. If a user explicitly set UINT32_MAX, we still cannot distinguish that from the implicit default. However, it is unlikely to be a problem as nobody would type literal UINT32_MAX (0xffff or 4294967295)

Re: [PATCH v8 03/15] pcie_sriov: Reset SR-IOV extended capability

2024-02-28 Thread Akihiko Odaki
On 2024/02/29 1:23, Sriram Yagnaraman wrote: -Original Message- From: Akihiko Odaki Sent: Wednesday, 28 February 2024 12:33 To: Philippe Mathieu-Daudé ; Michael S. Tsirkin ; Marcel Apfelbaum ; Alex Williamson ; Cédric Le Goater ; Paolo Bonzini ; Daniel P. Berrangé ; Eduardo Habkost

[PATCH RFC v3 1/6] hw/pci: Do not add ROM BAR for SR-IOV VF

2024-03-05 Thread Akihiko Odaki
A SR-IOV VF cannot have a ROM BAR. Co-developed-by: Yui Washizu Signed-off-by: Akihiko Odaki --- hw/pci/pci.c | 8 1 file changed, 8 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index cb5ac46e9f27..201ff64e11cc 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2359,6

[PATCH RFC v3 2/6] pcie_sriov: Ensure PF and VF are mutually exclusive

2024-03-05 Thread Akihiko Odaki
A device cannot be a SR-IOV PF and a VF at the same time. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 5 + 1 file changed, 5 insertions(+) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index 09a53ed30027..aac12e70f122 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci

[PATCH RFC v3 5/6] virtio-pci: Implement SR-IOV PF

2024-03-05 Thread Akihiko Odaki
Allow user to attach SR-IOV VF to a virtio-pci PF. Signed-off-by: Akihiko Odaki --- hw/virtio/virtio-pci.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1a7039fb0c68..f6a2dbb3b5e2 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw

[PATCH RFC v3 6/6] virtio-net: Implement SR-IOV VF

2024-03-05 Thread Akihiko Odaki
A virtio-net device can be added as a SR-IOV VF to another virtio-pci device that will be the PF. Signed-off-by: Akihiko Odaki --- hw/virtio/virtio-net-pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c index e03543a70a75

[PATCH RFC v3 4/6] pcie_sriov: Allow user to create SR-IOV device

2024-03-05 Thread Akihiko Odaki
-creatable VFs can be attached calls pcie_sriov_pf_init_from_user_created_vfs() during realization and pcie_sriov_pf_exit() when exiting. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 6 +- include/hw/pci/pcie_sriov.h | 19 +++ hw/pci/pci.c| 62 ++ hw/pci

[PATCH RFC v3 0/6] virtio-net: add support for SR-IOV emulation

2024-03-05 Thread Akihiko Odaki
1808-3009-1-git-send-email-yui.wash...@gmail.com/ [2] https://lore.kernel.org/all/5d46f455-f530-4e5e-9ae7-13a2297d4...@daynix.com/ Co-developed-by: Yui Washizu Signed-off-by: Akihiko Odaki --- Changes in v3: - Rebased. - Link to v2: https://lore.kernel.org/r/20231210-sriov-v2-0-b959e8a6d...

[PATCH RFC v3 3/6] pcie_sriov: Check PCI Express for SR-IOV PF

2024-03-05 Thread Akihiko Odaki
SR-IOV requires PCI Express. Signed-off-by: Akihiko Odaki --- hw/pci/pcie_sriov.c | 5 + 1 file changed, 5 insertions(+) diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c index aac12e70f122..c449ddd0ac39 100644 --- a/hw/pci/pcie_sriov.c +++ b/hw/pci/pcie_sriov.c @@ -41,6 +41,11

<    1   2   3   4   5