Fix MSIx lost after PE reset
cover Fix MSIx lost after PE reset
The 2 patches fix MSIx lost after PE reset. Otherwise, the MSIx entries can't be restored successfully after PE reset and the EEH recovery fails on broadcom tg3 adapter (as tested) in guest.
Note: The patchset "EEH support for guest" isn't merged yet, those
2 patches are based on Alex Graf's "ppc-next" branch + the patchset supporting EEH for guest, which can be checked out from below link:
[email protected]:gwshan/qemu.git (branch: eeh)
Gavin Shan (2):
VFIO: Drop vfio_container_do_ioctl()
VFIO: Clear stale MSIx table during EEH reset
hw/misc/vfio.c | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-)
Signature · 1 line
1.8.3.2
RFC PATCH 1/2 VFIO: Drop vfio_container_do_ioctl()
The patch drops vfio_container_do_ioctl() and merges its logic to parent function call vfio_container_ioctl() so that the subsequent patches can reused the found VFIO group in vfio_container_ioctl().
--- hw/misc/vfio.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
hw/misc/vfio.c +15 -18
@@ -4419,8 +4419,8 @@ static void register_vfio_pci_dev_type(void)type_init (register_vfio_pci_dev_type) -static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, -int req,void *param) +int vfio_container_ioctl(AddressSpace *as, int32_t groupid, +int req,void *param) {VFIOGroup *group;VFIOContainer *container;
@@ -4433,22 +4433,11 @@ static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, } container = group->container; -if (group->container) { - ret =ioctl (container->fd, req, param); -if (ret <0 ) { -error_report ("vfio: failed to ioctl container: ret=%d, %s" , - ret,strerror (errno)); - } +if (!container) { +error_report ("vfio: no container for group %d\n" , groupid); + goto out; } -vfio_put_group (group); - -return ret; -} - -int vfio_container_ioctl (AddressSpace *as,int32_t groupid, -int req,void *param) -{/* We allow only certain ioctls to the container */ switch (req) {case VFIO_CHECK_EXTENSION :
@@ -4458,8 +4447,16 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,default :/* Return an error on unknown requests */ error_report ("vfio: unsupported ioctl %X" , req); -return -1 ; + goto out; } -return vfio_container_do_ioctl (as, groupid, req, param); + ret =ioctl (container->fd, req, param); +if (ret <0 ) { +error_report ("vfio: failed to ioctl container: ret=%d, %s" , + ret,strerror (errno)); + } + +out: +vfio_put_group (group); +return ret; }
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [RFC PATCH 1/2] VFIO: Drop vfio_container_do_ioctl()
Quoted 58 lines · Gavin Shan
The patch drops
vfio_container_do_ioctl()and merges its logic to parent function callvfio_container_ioctl()so that the subsequent patches can reused the found VFIO group invfio_container_ioctl().Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)hw/misc/vfio.c +6
-17@@ -4419,8 +4419,8 @@ static void register_vfio_pci_dev_type(void)type_init (register_vfio_pci_dev_type) -static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, -int req,void *param) +int vfio_container_ioctl(AddressSpace *as, int32_t groupid, +int req,void *param) {VFIOGroup *group;VFIOContainer *container;@@ -4433,22 +4433,11 @@ static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, } container = group->container; -if (group->container) { - ret =ioctl (container->fd, req, param); -if (ret <0 ) { -error_report ("vfio: failed to ioctl container: ret=%d, %s" , - ret,strerror (errno)); - } +if (!container) { +error_report ("vfio: no container for group %d\n" , groupid); + goto out; } -vfio_put_group (group); - -return ret; -} - -int vfio_container_ioctl (AddressSpace *as,int32_t groupid, -int req,void *param) -{/* We allow only certain ioctls to the container */ switch (req) {case VFIO_CHECK_EXTENSION :@@ -4458,8 +4447,16 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,default :/* Return an error on unknown requests */ error_report ("vfio: unsupported ioctl %X" , req); -return -1 ; + goto out; }
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4461
Quoted 10 lines
hw/misc/vfio.c +9
-1-return vfio_container_do_ioctl (as, groupid, req, param); + ret =ioctl (container->fd, req, param); +if (ret <0 ) { +error_report ("vfio: failed to ioctl container: ret=%d, %s" , + ret,strerror (errno)); + } + +out: +vfio_put_group (group); +return ret;
Nack. We specifically separated an ioctl-filtering function and actual code which does ioctl. I understand that you want to save on vfio_get_group() calls for the next EEH patch but this is not a hot path anyway.
Quoted 2 lines
hw/misc/vfio.c +0
-0}
Signature · 1 line
Alexey
Re: [Qemu-devel] [RFC PATCH 1/2] VFIO: Drop vfio_container_do_ioctl()
Quoted 59 lines · Alexey Kardashevskiy
Quoted 58 lines · Gavin Shan
The patch drops
vfio_container_do_ioctl()and merges its logic to parent function callvfio_container_ioctl()so that the subsequent patches can reused the found VFIO group invfio_container_ioctl().Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)hw/misc/vfio.c +6
-17@@ -4419,8 +4419,8 @@ static void register_vfio_pci_dev_type(void)type_init (register_vfio_pci_dev_type) -static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, -int req,void *param) +int vfio_container_ioctl(AddressSpace *as, int32_t groupid, +int req,void *param) {VFIOGroup *group;VFIOContainer *container;@@ -4433,22 +4433,11 @@ static int vfio_container_do_ioctl(AddressSpace *as, int32_t groupid, } container = group->container; -if (group->container) { - ret =ioctl (container->fd, req, param); -if (ret <0 ) { -error_report ("vfio: failed to ioctl container: ret=%d, %s" , - ret,strerror (errno)); - } +if (!container) { +error_report ("vfio: no container for group %d\n" , groupid); + goto out; } -vfio_put_group (group); - -return ret; -} - -int vfio_container_ioctl (AddressSpace *as,int32_t groupid, -int req,void *param) -{/* We allow only certain ioctls to the container */ switch (req) {case VFIO_CHECK_EXTENSION :@@ -4458,8 +4447,16 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,default :/* Return an error on unknown requests */ error_report ("vfio: unsupported ioctl %X" , req); -return -1 ; + goto out; }
Quoted 15 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4461
Quoted 10 lines
hw/misc/vfio.c +9
-1-return vfio_container_do_ioctl (as, groupid, req, param); + ret =ioctl (container->fd, req, param); +if (ret <0 ) { +error_report ("vfio: failed to ioctl container: ret=%d, %s" , + ret,strerror (errno)); + } + +out: +vfio_put_group (group); +return ret;Nack. We specifically separated an ioctl-filtering function and actual code which does ioctl. I understand that you want to save on
vfio_get_group()calls for the next EEH patch but this is not a hot path anyway.
I think the split was a result of a comment from me suggesting that a wrapper function might make the code flow better. As implemented, I don't think that result was every actually realized, but the code was functional, so I didn't push it any further. I don't have any issue with recombining it. Thanks,
Alex
RFC PATCH 2/2 VFIO: Clear stale MSIx table during EEH reset
In reply to Gavin ShanThe PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.
The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.
--- hw/misc/vfio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
hw/misc/vfio.c +24 -0
@@ -4424,6 +4424,8 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, {VFIOGroup *group;VFIOContainer *container; +VFIODevice *vdev; +struct vfio_eeh_pe_op *arg;int ret =-1 ; group =vfio_get_group (groupid, as);
@@ -4442,7 +4444,29 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,switch (req) {case VFIO_CHECK_EXTENSION :case VFIO_IOMMU_SPAPR_TCE_GET_INFO : +break ;case VFIO_EEH_PE_OP : + arg = (struct vfio_eeh_pe_op *)param; +switch (arg->op) { +case VFIO_EEH_PE_RESET_HOT : +case VFIO_EEH_PE_RESET_FUNDAMENTAL : +/* +* The MSIx table will be cleaned out by reset. We need +* disable it so that it can be reenabled properly. Also, +* the cached MSIx table should be cleared as it's not +* reflecting the contents in hardware. +*/ + QLIST_FOREACH(vdev, &group->device_list, next) { +if (msix_enabled (&vdev->pdev)) { +vfio_disable_msix (vdev); + } + +msix_reset (&vdev->pdev); + } + +break ; + } +break ;default :/* Return an error on unknown requests */
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [RFC PATCH 2/2] VFIO: Clear stale MSIx table during EEH reset
Quoted 43 lines · Gavin Shan
The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.
The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.
Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)hw/misc/vfio.c +13
-0@@ -4424,6 +4424,8 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, {VFIOGroup *group;VFIOContainer *container; +VFIODevice *vdev; +struct vfio_eeh_pe_op *arg;int ret =-1 ; group =vfio_get_group (groupid, as);@@ -4442,7 +4444,29 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,switch (req) {case VFIO_CHECK_EXTENSION :case VFIO_IOMMU_SPAPR_TCE_GET_INFO : +break ;case VFIO_EEH_PE_OP : + arg = (struct vfio_eeh_pe_op *)param; +switch (arg->op) { +case VFIO_EEH_PE_RESET_HOT : +case VFIO_EEH_PE_RESET_FUNDAMENTAL : +/* +* The MSIx table will be cleaned out by reset. We need +* disable it so that it can be reenabled properly. Also, +* the cached MSIx table should be cleared as it's not +* reflecting the contents in hardware. +*/
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4468
Quoted 10 lines
hw/misc/vfio.c +10
-0+ QLIST_FOREACH(vdev, &group->device_list, next) { +if (msix_enabled (&vdev->pdev)) { +vfio_disable_msix (vdev); + } + +msix_reset (&vdev->pdev); + } + +break ; + }
This has to be done in spapr_pci_vfio (but we do not have there access to vfio_disable_msix) or in the way that x86 would benefit from too but in this case yes, we need an opinion from Alex (Williamson)...
Quoted 5 lines
hw/misc/vfio.c +1
-0+break ;default :/* Return an error on unknown requests */
Signature · 1 line
Alexey
Re: [Qemu-devel] [RFC PATCH 2/2] VFIO: Clear stale MSIx table during EEH reset
In reply to Gavin ShanQuoted 19 lines · Gavin Shan
The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.
The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.
Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)hw/misc/vfio.c +0
-0
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4428
Quoted 5 lines
hw/misc/vfio.c +2
-0@@ -4424,6 +4424,8 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, {VFIOGroup *group;VFIOContainer *container; +VFIODevice *vdev; +struct vfio_eeh_pe_op *arg;
Define these within the scope of the case since they're not used outside of it.
Quoted 16 lines
hw/misc/vfio.c +8
-0int ret =-1 ; group =vfio_get_group (groupid, as);@@ -4442,7 +4444,29 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,switch (req) {case VFIO_CHECK_EXTENSION :case VFIO_IOMMU_SPAPR_TCE_GET_INFO : +break ;case VFIO_EEH_PE_OP : + arg = (struct vfio_eeh_pe_op *)param; +switch (arg->op) { +case VFIO_EEH_PE_RESET_HOT : +case VFIO_EEH_PE_RESET_FUNDAMENTAL : +/* +* The MSIx table will be cleaned out by reset. We need +* disable it so that it can be reenabled properly. Also,
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4465
Quoted 10 lines
hw/misc/vfio.c +10
-0+* the cached MSIx table should be cleared as it's not +* reflecting the contents in hardware. +*/ + QLIST_FOREACH(vdev, &group->device_list, next) { +if (msix_enabled (&vdev->pdev)) { +vfio_disable_msix (vdev); + } + +msix_reset (&vdev->pdev); + }
We already have vfio_disable_interrupts(), can't we use that (blindly)? Do we really need to call msix_reset()? If so, should vfio_disable_msix() call it?
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4467
Quoted 2 lines
hw/misc/vfio.c +2
-0+ +break ;
Extraneous break
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4472
Quoted 5 lines
hw/misc/vfio.c +2
-0+ } +break ;default :/* Return an error on unknown requests */
Thanks,
Alex
Re: [Qemu-devel] [RFC PATCH 2/2] VFIO: Clear stale MSIx table during EEH reset
Quoted 15 lines · Alex Williamson
Quoted 14 lines · Gavin Shan
The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.
The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.
Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
Quoted 14 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4428
Quoted 10 lines
hw/misc/vfio.c +2
-0@@ -4424,6 +4424,8 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, {VFIOGroup *group;VFIOContainer *container; +VFIODevice *vdev; +struct vfio_eeh_pe_op *arg;Define these within the scope of the case since they're not used outside of it.
Yes, I'll fix.
Quoted 22 lines
Quoted 22 lines
hw/misc/vfio.c +14
-0int ret =-1 ; group =vfio_get_group (groupid, as);@@ -4442,7 +4444,29 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,switch (req) {case VFIO_CHECK_EXTENSION :case VFIO_IOMMU_SPAPR_TCE_GET_INFO : +break ;case VFIO_EEH_PE_OP : + arg = (struct vfio_eeh_pe_op *)param; +switch (arg->op) { +case VFIO_EEH_PE_RESET_HOT : +case VFIO_EEH_PE_RESET_FUNDAMENTAL : +/* +* The MSIx table will be cleaned out by reset. We need +* disable it so that it can be reenabled properly. Also, +* the cached MSIx table should be cleared as it's not +* reflecting the contents in hardware. +*/ + QLIST_FOREACH(vdev, &group->device_list, next) { +if (msix_enabled (&vdev->pdev)) { +vfio_disable_msix (vdev);
Quoted 9 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4465
Quoted 4 lines
hw/misc/vfio.c +4
-0+ } + +msix_reset (&vdev->pdev); + }We already have
vfio_disable_interrupts(), can't we use that (blindly)? Do we really need to callmsix_reset()? If so, shouldvfio_disable_msix()call it?
Yes, vfio_disable_interrupts() would be better to be used here as it can covers all types of interrupt (INTx/MSI/MSIx).
vfio_disable_interrupts() needn't clear MSIx vectors. If you prefer calling msix_reset() in the function, I guess I have to add one more parameter to vfio_disable_interrupts() to indicate if we need clear MSI/MSIx vector:
static void vfio_disable_interrupts(VFIODevice *vdev, bool clr_vector)
Quoted 5 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4467
Quoted 2 lines
hw/misc/vfio.c +2
-0+ +break ;Extraneous break
Yep, I'll remove it.
Quoted 9 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4472
Quoted 5 lines
hw/misc/vfio.c +2
-0+ } +break ;default :/* Return an error on unknown requests */ Thanks,
Alex
Thanks,
Gavin
Re: [Qemu-devel] [RFC PATCH 2/2] VFIO: Clear stale MSIx table during EEH reset
Quoted 68 lines · Gavin Shan
Quoted 15 lines · Alex Williamson
Quoted 14 lines · Gavin Shan
The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.
The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.
Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)Quoted 14 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4428
Quoted 10 lines
hw/misc/vfio.c +2
-0@@ -4424,6 +4424,8 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, {VFIOGroup *group;VFIOContainer *container; +VFIODevice *vdev; +struct vfio_eeh_pe_op *arg;Define these within the scope of the case since they're not used outside of it.
Yes, I'll fix.
Quoted 22 lines
Quoted 22 lines
hw/misc/vfio.c +14
-0int ret =-1 ; group =vfio_get_group (groupid, as);@@ -4442,7 +4444,29 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,switch (req) {case VFIO_CHECK_EXTENSION :case VFIO_IOMMU_SPAPR_TCE_GET_INFO : +break ;case VFIO_EEH_PE_OP : + arg = (struct vfio_eeh_pe_op *)param; +switch (arg->op) { +case VFIO_EEH_PE_RESET_HOT : +case VFIO_EEH_PE_RESET_FUNDAMENTAL : +/* +* The MSIx table will be cleaned out by reset. We need +* disable it so that it can be reenabled properly. Also, +* the cached MSIx table should be cleared as it's not +* reflecting the contents in hardware. +*/ + QLIST_FOREACH(vdev, &group->device_list, next) { +if (msix_enabled (&vdev->pdev)) { +vfio_disable_msix (vdev);Quoted 9 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4465
Quoted 4 lines
hw/misc/vfio.c +4
-0+ } + +msix_reset (&vdev->pdev); + }We already have
vfio_disable_interrupts(), can't we use that (blindly)? Do we really need to callmsix_reset()? If so, shouldvfio_disable_msix()call it?Yes,
vfio_disable_interrupts()would be better to be used here as it can covers all types of interrupt (INTx/MSI/MSIx).
Quoted 6 lines
vfio_disable_interrupts()needn't clear MSIx vectors. If you prefer callingmsix_reset()in the function, I guess I have to add one more parameter tovfio_disable_interrupts()to indicate if we need clear MSI/MSIx vector:static void
vfio_disable_interrupts(VFIODevice *vdev, bool clr_vector)
How about just creating a vfio_reset_interrupts() that calls msix_reset() if the device supports MSIX? We could wrap vfio_disable_interrupts() and vfio_reset_interrupts() into a vfio_disable_and_reset_interrupts(), but I'm not sure it's worth it. The reset device path should also add the interrupt reset call. Thanks,
Alex
Quoted 21 lines
Quoted 5 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4467
Quoted 2 lines
hw/misc/vfio.c +2
-0+ +break ;Extraneous break
Yep, I'll remove it.
Quoted 9 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4472
Quoted 5 lines
hw/misc/vfio.c +2
-0+ } +break ;default :/* Return an error on unknown requests */ Thanks,
AlexThanks,
Gavin
Re: [Qemu-devel] [RFC PATCH 2/2] VFIO: Clear stale MSIx table during EEH reset
Quoted 74 lines · Alex Williamson
Quoted 73 lines · Gavin Shan
Quoted 15 lines · Alex Williamson
Quoted 14 lines · Gavin Shan
The PCI device MSIx table is cleaned out in hardware after EEH PE reset. However, we still hold the stale MSIx entries in QEMU, which should be cleared accordingly. Otherwise, we will run into another (recursive) EEH error and the PCI devices contained in the PE have to be offlined exceptionally.
The patch clears stale MSIx table before EEH PE reset so that MSIx table could be restored properly after EEH PE reset.
Signed-off-by Gavin Shan <[email protected]>--- hw/misc/vfio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)Quoted 14 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4428
Quoted 10 lines
hw/misc/vfio.c +2
-0@@ -4424,6 +4424,8 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, {VFIOGroup *group;VFIOContainer *container; +VFIODevice *vdev; +struct vfio_eeh_pe_op *arg;Define these within the scope of the case since they're not used outside of it.
Yes, I'll fix.
Quoted 22 lines
Quoted 22 lines
hw/misc/vfio.c +14
-0int ret =-1 ; group =vfio_get_group (groupid, as);@@ -4442,7 +4444,29 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid,switch (req) {case VFIO_CHECK_EXTENSION :case VFIO_IOMMU_SPAPR_TCE_GET_INFO : +break ;case VFIO_EEH_PE_OP : + arg = (struct vfio_eeh_pe_op *)param; +switch (arg->op) { +case VFIO_EEH_PE_RESET_HOT : +case VFIO_EEH_PE_RESET_FUNDAMENTAL : +/* +* The MSIx table will be cleaned out by reset. We need +* disable it so that it can be reenabled properly. Also, +* the cached MSIx table should be cleared as it's not +* reflecting the contents in hardware. +*/ + QLIST_FOREACH(vdev, &group->device_list, next) { +if (msix_enabled (&vdev->pdev)) { +vfio_disable_msix (vdev);Quoted 9 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4465
Quoted 4 lines
hw/misc/vfio.c +4
-0+ } + +msix_reset (&vdev->pdev); + }We already have
vfio_disable_interrupts(), can't we use that (blindly)? Do we really need to callmsix_reset()? If so, shouldvfio_disable_msix()call it?Yes,
vfio_disable_interrupts()would be better to be used here as it can covers all types of interrupt (INTx/MSI/MSIx).
vfio_disable_interrupts()needn't clear MSIx vectors. If you prefer callingmsix_reset()in the function, I guess I have to add one more parameter tovfio_disable_interrupts()to indicate if we need clear MSI/MSIx vector:
Quoted 8 lines
Quoted 1 line
static void
vfio_disable_interrupts(VFIODevice *vdev, bool clr_vector)How about just creating a
vfio_reset_interrupts()that callsmsix_reset()if the device supports MSIX? We could wrapvfio_disable_interrupts()andvfio_reset_interrupts()into avfio_disable_and_reset_interrupts(), but I'm not sure it's worth it. The reset device path should also add the interrupt reset call. Thanks,
Thanks, Alex. It sounds a better way. I'll refactor the code and send v2 out for your comments.
Thanks,
Gavin
Quoted 26 lines
Alex
Quoted 21 lines
Quoted 5 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4467
Quoted 2 lines
hw/misc/vfio.c +2
-0+ +break ;Extraneous break
Yep, I'll remove it.
Quoted 9 lines
hw/misc/vfio.c int vfio_container_ioctl(AddressSpace *as, int32_t groupid, · line 4472
Quoted 5 lines
hw/misc/vfio.c +2
-0+ } +break ;default :/* Return an error on unknown requests */ Thanks,
AlexThanks,
Gavin
Quoted 9 lines · Gavin Shan
The 2 patches fix MSIx lost after PE reset. Otherwise, the MSIx entries can't be restored successfully after PE reset and the EEH recovery fails on broadcom tg3 adapter (as tested) in guest.
Note: The patchset "EEH support for guest" isn't merged yet, those
2 patches are based on Alex Graf's "ppc-next" branch + the patchset supporting EEH for guest, which can be checked out from below link:
Quoted 9 lines
[email protected]:gwshan/qemu.git (branch: eeh)
Gavin Shan (2):
VFIO: Dropvfio_container_do_ioctl()
VFIO: Clear stale MSIx table during EEH reset
hw/misc/vfio.c| 57 +++++++++++++++++++++++++++++++++++++++------------------1 file changed, 39 insertions(+), 18 deletions(-)
Alex, any comments? :-)
Thanks,
Gavin