hw/vfio/common: Trace in which mode a IOMMU is opened
PATCH 1/1 hw/vfio/common: Trace in which mode a IOMMU is opened
One might want to check which IOMMU version the host kernel provide. Add a trace event to see in which mode we opened our container.
--- hw/vfio/common.c | 19 ++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 15 insertions(+), 5 deletions(-)
hw/vfio/common.c +14 -5
@@ -1157,15 +1157,24 @@ static void vfio_put_address_space(VFIOAddressSpace *space)static int vfio_get_iommu_type (VFIOContainer *container,Error **errp) { -int iommu_types[] = { VFIO_TYPE1v2_IOMMU,VFIO_TYPE1_IOMMU , - VFIO_SPAPR_TCE_v2_IOMMU,VFIO_SPAPR_TCE_IOMMU }; +static const struct { +int type; +const char *name; + } iommu[] = { + {VFIO_TYPE1v2_IOMMU,"Type1 (v2)" }, + {VFIO_TYPE1_IOMMU ,"Type1 (v1)" }, + {VFIO_SPAPR_TCE_v2_IOMMU,"sPAPR TCE (v2)" }, + {VFIO_SPAPR_TCE_IOMMU ,"sPAPR TCE (v1)" } + };int i; -for (i =0 ; i <ARRAY_SIZE (iommu_types); i++) { -if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu_types[i])) { -return iommu_types[i]; +for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name); +return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );error_setg (errp,"No available IOMMU models" );return -EINVAL ; }
hw/vfio/trace-events +1 -0
@@ -115,6 +115,7 @@ vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_get_iommu_type(int iommu_type, const char *iommu_name) "IOMMU type %d (%s)" # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"
Signature · 1 line
2.21.3
Quoted 9 lines · On Tue, 26 May 2020 19:35:42 +0200 Philippe Mathieu-Daudé <[email protected]>…
One might want to check which IOMMU version the host kernel provide. Add a trace event to see in which mode we opened our container.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/vfio/common.c | 19 ++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 15 insertions(+), 5 deletions(-)
Hi Philippe,
Quoted 27 lines · Philippe Mathieu-Daudé
One might want to check which IOMMU version the host kernel provide. Add a trace event to see in which mode we opened our container.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/vfio/common.c | 19 ++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 15 insertions(+), 5 deletions(-)hw/vfio/common.c +7
-2@@ -1157,15 +1157,24 @@ static void vfio_put_address_space(VFIOAddressSpace *space)static int vfio_get_iommu_type (VFIOContainer *container,Error **errp) { -int iommu_types[] = { VFIO_TYPE1v2_IOMMU,VFIO_TYPE1_IOMMU , - VFIO_SPAPR_TCE_v2_IOMMU,VFIO_SPAPR_TCE_IOMMU }; +static const struct { +int type; +const char *name; + } iommu[] = { + {VFIO_TYPE1v2_IOMMU,"Type1 (v2)" }, + {VFIO_TYPE1_IOMMU ,"Type1 (v1)" }, + {VFIO_SPAPR_TCE_v2_IOMMU,"sPAPR TCE (v2)" },
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1173
Quoted 10 lines
hw/vfio/common.c +5
-3+ {VFIO_SPAPR_TCE_IOMMU, "sPAPR TCE (v1)"} + };int i; -for (i =0 ; i <ARRAY_SIZE (iommu_types); i++) { -if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu_types[i])) { -return iommu_types[i]; +for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name);
Just wondering why you want to trace the type as you now have the name string.
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1177
Quoted 4 lines
hw/vfio/common.c +2
-0+return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );
nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
Thanks
Eric
Quoted 16 lines
hw/vfio/common.c +0
-0error_setg (errp,"No available IOMMU models" );return -EINVAL ; }hw/vfio/trace-events +1
-0@@ -115,6 +115,7 @@ vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_get_iommu_type(int iommu_type, const char *iommu_name) "IOMMU type %d (%s)" # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"
Quoted 34 lines · Auger Eric
Hi Philippe,
Quoted 31 lines · Philippe Mathieu-Daudé
One might want to check which IOMMU version the host kernel provide. Add a trace event to see in which mode we opened our container.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/vfio/common.c | 19 ++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 15 insertions(+), 5 deletions(-)hw/vfio/common.c +9
-2@@ -1157,15 +1157,24 @@ static void vfio_put_address_space(VFIOAddressSpace *space)static int vfio_get_iommu_type (VFIOContainer *container,Error **errp) { -int iommu_types[] = { VFIO_TYPE1v2_IOMMU,VFIO_TYPE1_IOMMU , - VFIO_SPAPR_TCE_v2_IOMMU,VFIO_SPAPR_TCE_IOMMU }; +static const struct { +int type; +const char *name; + } iommu[] = { + {VFIO_TYPE1v2_IOMMU,"Type1 (v2)" }, + {VFIO_TYPE1_IOMMU ,"Type1 (v1)" }, + {VFIO_SPAPR_TCE_v2_IOMMU,"sPAPR TCE (v2)" }, + {VFIO_SPAPR_TCE_IOMMU ,"sPAPR TCE (v1)" } + };int i;
Quoted 8 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1173
Quoted 6 lines
hw/vfio/common.c +3
-3-for (i =0 ; i <ARRAY_SIZE (iommu_types); i++) { -if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu_types[i])) { -return iommu_types[i]; +for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
You are right :)
Quoted 7 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1177
Quoted 4 lines
hw/vfio/common.c +2
-0+return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
Indeed.
Thanks for the review!
Quoted 21 lines
Thanks
Eric
Quoted 16 lines
hw/vfio/common.c +0
-0error_setg (errp,"No available IOMMU models" );return -EINVAL ; }hw/vfio/trace-events +1
-0@@ -115,6 +115,7 @@ vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_get_iommu_type(int iommu_type, const char *iommu_name) "IOMMU type %d (%s)" # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"
Quoted 44 lines · Philippe Mathieu-Daudé
Quoted 34 lines · Auger Eric
Hi Philippe,
Quoted 31 lines · Philippe Mathieu-Daudé
One might want to check which IOMMU version the host kernel provide. Add a trace event to see in which mode we opened our container.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/vfio/common.c | 19 ++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 15 insertions(+), 5 deletions(-)hw/vfio/common.c +9
-2@@ -1157,15 +1157,24 @@ static void vfio_put_address_space(VFIOAddressSpace *space)static int vfio_get_iommu_type (VFIOContainer *container,Error **errp) { -int iommu_types[] = { VFIO_TYPE1v2_IOMMU,VFIO_TYPE1_IOMMU , - VFIO_SPAPR_TCE_v2_IOMMU,VFIO_SPAPR_TCE_IOMMU }; +static const struct { +int type; +const char *name; + } iommu[] = { + {VFIO_TYPE1v2_IOMMU,"Type1 (v2)" }, + {VFIO_TYPE1_IOMMU ,"Type1 (v1)" }, + {VFIO_SPAPR_TCE_v2_IOMMU,"sPAPR TCE (v2)" }, + {VFIO_SPAPR_TCE_IOMMU ,"sPAPR TCE (v1)" } + };int i;Quoted 8 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1173
Quoted 6 lines
hw/vfio/common.c +3
-3-for (i =0 ; i <ARRAY_SIZE (iommu_types); i++) { -if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu_types[i])) { -return iommu_types[i]; +for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
Quoted 9 lines
You are right :)
Quoted 7 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1177
Quoted 4 lines
hw/vfio/common.c +2
-0+return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
But you can reach this for example using No-IOMMU. If you don't mind, I find having this information in the trace log clearer.
Quoted 27 lines
Indeed.
Thanks for the review!
Quoted 21 lines
Thanks
Eric
Quoted 16 lines
hw/vfio/common.c +0
-0error_setg (errp,"No available IOMMU models" );return -EINVAL ; }hw/vfio/trace-events +1
-0@@ -115,6 +115,7 @@ vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_get_iommu_type(int iommu_type, const char *iommu_name) "IOMMU type %d (%s)" # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 12 lines
Quoted 5 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1173
Quoted 3 lines
hw/vfio/common.c +3
-0+for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
You are right :)
Quoted 4 lines
Quoted 4 lines
hw/vfio/common.c +2
-0+return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
But you can reach this for example using No-IOMMU. If you don't mind, I find having this information in the trace log clearer.
I kinda agree with Eric - AFAICT QEMU vfio-pci don't work with no-iommu, then it seems meaningless to trace it...
I'm not sure whether this trace is extremely helpful because syscalls like this could be easily traced by things like strace or bpftrace as general tools (and this information should be a one-time thing rather than dynamically changing), no strong opinion though. Also, if we want to dump something, maybe it's better to do in vfio_init_container() after vfio_get_iommu_type() succeeded, so we dump which container is enabled with what type of iommu.
Thanks,
Signature · 1 line
Peter Xu
Quoted 23 lines · Peter Xu
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 12 lines
Quoted 5 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1173
Quoted 3 lines
hw/vfio/common.c +3
-0+for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
You are right :)
Quoted 4 lines
Quoted 4 lines
hw/vfio/common.c +2
-0+return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
But you can reach this for example using No-IOMMU. If you don't mind, I find having this information in the trace log clearer.
I kinda agree with Eric - AFAICT QEMU vfio-pci don't work with no-iommu, then it seems meaningless to trace it...
Quoted 6 lines
I'm not sure whether this trace is extremely helpful because syscalls like this could be easily traced by things like strace or bpftrace as general tools (and this information should be a one-time thing rather than dynamically changing), no strong opinion though. Also, if we want to dump something, maybe it's better to do in
vfio_init_container()aftervfio_get_iommu_type()succeeded, so we dump which container is enabled with what type of iommu.
OK. I'm a recent VFIO user so maybe I am not using the good information.
This trace helps me while working on a new device feature, I didn't thought about gathering it in a production because there I'd expect things to work.
Now in my case what I want is to know is if I'm using a v1 or v2 type. Maybe this information is already available in /proc or /sys and we don't need this patch...
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Peter Xu
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 12 lines
Quoted 5 lines
hw/vfio/common.c static void vfio_put_address_space(VFIOAddressSpace *space) · line 1173
Quoted 3 lines
hw/vfio/common.c +3
-0+for (i =0 ; i <ARRAY_SIZE (iommu); i++) { +if (ioctl (container->fd,VFIO_CHECK_EXTENSION , iommu[i].type)) { +trace_vfio_get_iommu_type (iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
You are right :)
Quoted 4 lines
Quoted 4 lines
hw/vfio/common.c +2
-0+return iommu[i].type; } } +trace_vfio_get_iommu_type (-1 ,"Not available or not supported" );Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
But you can reach this for example using No-IOMMU. If you don't mind, I find having this information in the trace log clearer.
I kinda agree with Eric - AFAICT QEMU vfio-pci don't work with no-iommu, then it seems meaningless to trace it...
Quoted 6 lines
I'm not sure whether this trace is extremely helpful because syscalls like this could be easily traced by things like strace or bpftrace as general tools (and this information should be a one-time thing rather than dynamically changing), no strong opinion though. Also, if we want to dump something, maybe it's better to do in
vfio_init_container()aftervfio_get_iommu_type()succeeded, so we dump which container is enabled with what type of iommu.OK. I'm a recent VFIO user so maybe I am not using the good information.
Quoted 7 lines
This trace helps me while working on a new device feature, I didn't thought about gathering it in a production because there I'd expect things to work.
Now in my case what I want is to know is if I'm using a v1 or v2 type. Maybe this information is already available in /proc or /sys and we don't need this patch...
I don't know such /proc or /sys, so maybe it's still useful. I guess Alex would have the best judgement. The strace/bpftrace things are not really reasons I found to nak this patch, but just something I thought first that could be easier when any of us wants to peak at those information, probably something just FYI. :-)
Thanks,
Signature · 1 line
Peter Xu
Quoted 42 lines · On Wed, 27 May 2020 12:53:30 -0400 Peter Xu <[email protected]> wrote:
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Peter Xu
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 12 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ for (i = 0; i < ARRAY_SIZE(iommu); i++) { + if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu[i].type)) { + trace_vfio_get_iommu_type(iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
You are right :)
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+ return iommu[i].type; } } + trace_vfio_get_iommu_type(-1, "Not available or not supported");Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
But you can reach this for example using No-IOMMU. If you don't mind, I find having this information in the trace log clearer.
I kinda agree with Eric - AFAICT QEMU vfio-pci don't work with no-iommu, then it seems meaningless to trace it...
Quoted 6 lines
I'm not sure whether this trace is extremely helpful because syscalls like this could be easily traced by things like strace or bpftrace as general tools (and this information should be a one-time thing rather than dynamically changing), no strong opinion though. Also, if we want to dump something, maybe it's better to do in
vfio_init_container()aftervfio_get_iommu_type()succeeded, so we dump which container is enabled with what type of iommu.OK. I'm a recent VFIO user so maybe I am not using the good information.
Quoted 7 lines
This trace helps me while working on a new device feature, I didn't thought about gathering it in a production because there I'd expect things to work.
Now in my case what I want is to know is if I'm using a v1 or v2 type. Maybe this information is already available in /proc or /sys and we don't need this patch...
Quoted 5 lines
I don't know such /proc or /sys, so maybe it's still useful. I guess Alex would have the best judgement. The strace/bpftrace things are not really reasons I found to nak this patch, but just something I thought first that could be easier when any of us wants to peak at those information, probably something just FYI. :-)
Personally, I find traces to be quite handy, and it's nice if you can just enable more of them if they are in your debugging workflow anyway. Probably boils down to a matter of preference :)
Quoted 3 lines · Cornelia Huck
Personally, I find traces to be quite handy, and it's nice if you can just enable more of them if they are in your debugging workflow anyway. Probably boils down to a matter of preference :)
Totally agree. I am actually a heavy user of QEMU tracing system, just like the rest of the tracing tools all over the world... :)
IMHO the difference between a tracepoint and a manual printf() is majorly the reusablility part - if a debugging printf() is likely to be reused in the future, then it is a good tracepoint candidate.
Thanks,
Signature · 1 line
Peter Xu
Quoted 34 lines · On Wed, 27 May 2020 12:53:30 -0400 Peter Xu <[email protected]> wrote:
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Peter Xu
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 12 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ for (i = 0; i < ARRAY_SIZE(iommu); i++) { + if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu[i].type)) { + trace_vfio_get_iommu_type(iommu[i].type, iommu[i].name);Just wondering why you want to trace the type as you now have the name string.
You are right :)
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+ return iommu[i].type; } } + trace_vfio_get_iommu_type(-1, "Not available or not supported");Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
nit: from a debugging pov, this may be not needed as vfio_get_group/vfio_connect_container() fails and this leads to an error output.
But you can reach this for example using No-IOMMU. If you don't mind, I find having this information in the trace log clearer.
I kinda agree with Eric - AFAICT QEMU vfio-pci don't work with no-iommu, then it seems meaningless to trace it...
Quoted 6 lines
I'm not sure whether this trace is extremely helpful because syscalls like this could be easily traced by things like strace or bpftrace as general tools (and this information should be a one-time thing rather than dynamically changing), no strong opinion though. Also, if we want to dump something, maybe it's better to do in
vfio_init_container()aftervfio_get_iommu_type()succeeded, so we dump which container is enabled with what type of iommu.OK. I'm a recent VFIO user so maybe I am not using the good information.
Quoted 7 lines
Quoted 7 lines
This trace helps me while working on a new device feature, I didn't thought about gathering it in a production because there I'd expect things to work.
Now in my case what I want is to know is if I'm using a v1 or v2 type. Maybe this information is already available in /proc or /sys and we don't need this patch...
You're using v2 unless you're on a very old kernel.
Quoted 5 lines
I don't know such /proc or /sys, so maybe it's still useful. I guess Alex would have the best judgement. The strace/bpftrace things are not really reasons I found to nak this patch, but just something I thought first that could be easier when any of us wants to peak at those information, probably something just FYI. :-)
I appreciate good trace code, but I don't appreciate code bloat for the sake of tracing, which is what I'd consider the name fields here. Do it in the trace-event or require that the user needs to cross reference the header to turn the integer type into a name themselves. Thanks,
Alex