hw/accel: Use RCU_READ macros
cover hw/accel: Use RCU_READ macros
Use RCU_READ_LOCK_GUARD and WITH_RCU_READ_LOCK_GUARD to replace the manual rcu_read_(un)lock calls.
Philippe Mathieu-Daudé (6):
accel/tcg/cpu-exec: Use RCU_READ macro hw/9pfs/9p-synth: Use RCU_READ macro hw/display/virtio-gpu-udmabuf: Use RCU_READ macro hw/scsi/virtio-scsi: Use RCU_READ macro hw/vfio/common: Use RCU_READ macros hw/virtio/vhost: Use RCU_READ macro
accel/tcg/cpu-exec.c | 24 +++++++++++------------ hw/9pfs/9p-synth.c | 24 +++++++++++------------ hw/display/virtio-gpu-udmabuf.c | 6 +++--- hw/scsi/virtio-scsi.c | 12 ++++++------ hw/vfio/common.c | 34 ++++++++++++++++----------------- hw/virtio/vhost.c | 6 +++--- 6 files changed, 52 insertions(+), 54 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/6 accel/tcg/cpu-exec: Use RCU_READ macro
Replace the manual rcu_read_(un)lock calls by the WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba "docs/style: call out the use of GUARD macros").
--- accel/tcg/cpu-exec.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
accel/tcg/cpu-exec.c +12 -12
@@ -1070,21 +1070,21 @@ int cpu_exec(CPUState *cpu)return EXCP_HALTED ; } -rcu_read_lock (); -cpu_exec_enter (cpu); + WITH_RCU_READ_LOCK_GUARD() { +cpu_exec_enter (cpu); -/* -* Calculate difference between guest clock and host clock. -* This delay includes the delay of the last cycle, so -* what we have to do is sleep until it is 0. As for the -* advance/delay we gain here, we try to fix it next time. -*/ -init_delay_params (&sc, cpu); +/* +* Calculate difference between guest clock and host clock. +* This delay includes the delay of the last cycle, so +* what we have to do is sleep until it is 0. As for the +* advance/delay we gain here, we try to fix it next time. +*/ +init_delay_params (&sc, cpu); - ret =cpu_exec_setjmp (cpu, &sc); + ret =cpu_exec_setjmp (cpu, &sc); -cpu_exec_exit (cpu); -rcu_read_unlock (); +cpu_exec_exit (cpu); + };return ret; }
Signature · 1 line
2.41.0
Re: [PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro
Quoted 50 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
accel/tcg/cpu-exec.c| 24 ++++++++++++------------1 file changed, 12 insertions(+), 12 deletions(-)accel/tcg/cpu-exec.c +12
-12@@ -1070,21 +1070,21 @@ int cpu_exec(CPUState *cpu)return EXCP_HALTED ; } -rcu_read_lock (); -cpu_exec_enter (cpu); + WITH_RCU_READ_LOCK_GUARD() { +cpu_exec_enter (cpu); -/* -* Calculate difference between guest clock and host clock. -* This delay includes the delay of the last cycle, so -* what we have to do is sleep until it is 0. As for the -* advance/delay we gain here, we try to fix it next time. -*/ -init_delay_params (&sc, cpu); +/* +* Calculate difference between guest clock and host clock. +* This delay includes the delay of the last cycle, so +* what we have to do is sleep until it is 0. As for the +* advance/delay we gain here, we try to fix it next time. +*/ +init_delay_params (&sc, cpu); - ret =cpu_exec_setjmp (cpu, &sc); + ret =cpu_exec_setjmp (cpu, &sc); -cpu_exec_exit (cpu); -rcu_read_unlock (); +cpu_exec_exit (cpu); + };return ret; }Signature · 1 line
2.41.0
Re: [PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cpu-exec.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Quoted 1 line
+ };
Stray ;
r~
Re: [PATCH 1/6] accel/tcg/cpu-exec: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéQuoted 37 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cpu-exec.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)accel/tcg/cpu-exec.c +9
-9@@ -1070,21 +1070,21 @@ int cpu_exec(CPUState *cpu)return EXCP_HALTED ; } -rcu_read_lock (); -cpu_exec_enter (cpu); + WITH_RCU_READ_LOCK_GUARD() { +cpu_exec_enter (cpu); -/* -* Calculate difference between guest clock and host clock. -* This delay includes the delay of the last cycle, so -* what we have to do is sleep until it is 0. As for the -* advance/delay we gain here, we try to fix it next time. -*/ -init_delay_params (&sc, cpu); +/* +* Calculate difference between guest clock and host clock. +* This delay includes the delay of the last cycle, so +* what we have to do is sleep until it is 0. As for the +* advance/delay we gain here, we try to fix it next time. +*/ +init_delay_params (&sc, cpu);
accel/tcg/cpu-exec.c int cpu_exec(CPUState *cpu) · line 1090
Quoted 10 lines
accel/tcg/cpu-exec.c +3
-3- ret =cpu_exec_setjmp (cpu, &sc); + ret =cpu_exec_setjmp (cpu, &sc); -cpu_exec_exit (cpu); -rcu_read_unlock (); +cpu_exec_exit (cpu); + };return ret; }
I've tweaked this to use RCU_READ_LOCK_GUARD instead -- there's little point
in excluding the return from the block, and thus avoid the re-indent -- and queued this one patch to tcg-next.
r~
PATCH 2/6 hw/9pfs/9p-synth: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéReplace the manual rcu_read_(un)lock calls by the WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba "docs/style: call out the use of GUARD macros").
--- hw/9pfs/9p-synth.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
hw/9pfs/9p-synth.c +12 -12
@@ -241,15 +241,15 @@ static struct dirent *synth_get_dentry(V9fsSynthNode *dir,int i =0 ;V9fsSynthNode *node; -rcu_read_lock (); - QLIST_FOREACH(node, &dir->child, sibling) { -/* This is the off child of the directory */ -if (i == off) { -break ; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH(node, &dir->child, sibling) { +/* This is the off child of the directory */ +if (i == off) { +break ; + } + i++; } - i++; } -rcu_read_unlock ();if (!node) {/* end of directory */ return NULL ;
@@ -494,13 +494,13 @@ static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path, goto out; }/* search for the name in the children */ -rcu_read_lock (); - QLIST_FOREACH(node, &dir_node->child, sibling) { -if (!strcmp (node->name, name)) { -break ; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH(node, &dir_node->child, sibling) { +if (!strcmp (node->name, name)) { +break ; + } } } -rcu_read_unlock ();if (!node) { errno =ENOENT ;
Signature · 1 line
2.41.0
Re: [PATCH 2/6] hw/9pfs/9p-synth: Use RCU_READ macro
Quoted 9 lines · On Wed, 24 Jan 2024 08:41:57 +0100 Philippe Mathieu-Daudé <[email protected]>…
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/9pfs/9p-synth.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Quoted 46 lines
hw/9pfs/9p-synth.c +12
-12@@ -241,15 +241,15 @@ static struct dirent *synth_get_dentry(V9fsSynthNode *dir,int i =0 ;V9fsSynthNode *node; -rcu_read_lock (); - QLIST_FOREACH(node, &dir->child, sibling) { -/* This is the off child of the directory */ -if (i == off) { -break ; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH(node, &dir->child, sibling) { +/* This is the off child of the directory */ +if (i == off) { +break ; + } + i++; } - i++; } -rcu_read_unlock ();if (!node) {/* end of directory */ return NULL ;@@ -494,13 +494,13 @@ static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path, goto out; }/* search for the name in the children */ -rcu_read_lock (); - QLIST_FOREACH(node, &dir_node->child, sibling) { -if (!strcmp (node->name, name)) { -break ; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH(node, &dir_node->child, sibling) { +if (!strcmp (node->name, name)) { +break ; + } } } -rcu_read_unlock ();if (!node) { errno =ENOENT ;
Signature · 1 line
Greg
Re: [PATCH 2/6] hw/9pfs/9p-synth: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéQuoted 6 lines · CET Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 50 lines
hw/9pfs/9p-synth.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)hw/9pfs/9p-synth.c +12
-12@@ -241,15 +241,15 @@ static struct dirent *synth_get_dentry(V9fsSynthNode *dir,int i =0 ;V9fsSynthNode *node; -rcu_read_lock (); - QLIST_FOREACH(node, &dir->child, sibling) { -/* This is the off child of the directory */ -if (i == off) { -break ; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH(node, &dir->child, sibling) { +/* This is the off child of the directory */ +if (i == off) { +break ; + } + i++; } - i++; } -rcu_read_unlock ();if (!node) {/* end of directory */ return NULL ;@@ -494,13 +494,13 @@ static int synth_name_to_path(FsContext *ctx, V9fsPath *dir_path, goto out; }/* search for the name in the children */ -rcu_read_lock (); - QLIST_FOREACH(node, &dir_node->child, sibling) { -if (!strcmp (node->name, name)) { -break ; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH(node, &dir_node->child, sibling) { +if (!strcmp (node->name, name)) { +break ; + } } } -rcu_read_unlock ();if (!node) { errno =ENOENT ;
PATCH 3/6 hw/display/virtio-gpu-udmabuf: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéReplace the manual rcu_read_(un)lock calls by the WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba "docs/style: call out the use of GUARD macros").
--- hw/display/virtio-gpu-udmabuf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/virtio-gpu-udmabuf.c +3 -3
@@ -42,9 +42,9 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *res) sizeof(struct udmabuf_create_item) * res->iov_cnt);for (i =0 ; i < res->iov_cnt; i++) { -rcu_read_lock (); - rb =qemu_ram_block_from_host (res->iov[i].iov_base, false, &offset); -rcu_read_unlock (); + WITH_RCU_READ_LOCK_GUARD() { + rb =qemu_ram_block_from_host (res->iov[i].iov_base, false, &offset); + }if (!rb || rb->fd <0 ) {g_free (list);
Signature · 1 line
2.41.0
Re: [PATCH 3/6] hw/display/virtio-gpu-udmabuf: Use RCU_READ macro
Quoted 28 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/display/virtio-gpu-udmabuf.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)hw/display/virtio-gpu-udmabuf.c +3
-3@@ -42,9 +42,9 @@ static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *res) sizeof(struct udmabuf_create_item) * res->iov_cnt);for (i =0 ; i < res->iov_cnt; i++) { -rcu_read_lock (); - rb =qemu_ram_block_from_host (res->iov[i].iov_base, false, &offset); -rcu_read_unlock (); + WITH_RCU_READ_LOCK_GUARD() { + rb =qemu_ram_block_from_host (res->iov[i].iov_base, false, &offset); + }if (!rb || rb->fd <0 ) {g_free (list);Signature · 1 line
2.41.0
PATCH 4/6 hw/scsi/virtio-scsi: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéReplace the manual rcu_read_(un)lock calls by the WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba "docs/style: call out the use of GUARD macros").
--- hw/scsi/virtio-scsi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/scsi/virtio-scsi.c +6 -6
@@ -343,14 +343,14 @@ static void virtio_scsi_do_one_tmf_bh(VirtIOSCSIReq *req) target = req->req.tmf.lun[1 ];qatomic_inc (&s->resetting); -rcu_read_lock (); - QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { -SCSIDevice *d1 =SCSI_DEVICE (kid->child); -if (d1->channel ==0 && d1->id == target) { -device_cold_reset (&d1->qdev); + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { +SCSIDevice *d1 =SCSI_DEVICE (kid->child); +if (d1->channel ==0 && d1->id == target) { +device_cold_reset (&d1->qdev); + } } } -rcu_read_unlock ();qatomic_dec (&s->resetting);break ;
Signature · 1 line
2.41.0
Re: [PATCH 4/6] hw/scsi/virtio-scsi: Use RCU_READ macro
Quoted 37 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/scsi/virtio-scsi.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)hw/scsi/virtio-scsi.c +6
-6@@ -343,14 +343,14 @@ static void virtio_scsi_do_one_tmf_bh(VirtIOSCSIReq *req) target = req->req.tmf.lun[1 ];qatomic_inc (&s->resetting); -rcu_read_lock (); - QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { -SCSIDevice *d1 =SCSI_DEVICE (kid->child); -if (d1->channel ==0 && d1->id == target) { -device_cold_reset (&d1->qdev); + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { +SCSIDevice *d1 =SCSI_DEVICE (kid->child); +if (d1->channel ==0 && d1->id == target) { +device_cold_reset (&d1->qdev); + } } } -rcu_read_unlock ();qatomic_dec (&s->resetting);break ;Signature · 1 line
2.41.0
Unrelated to your patch: I just noticed in hw/scsi/virtio-scsi.c, s->resetting is used to flag whether the bus is resetting; but there's no check if a resetting is taking place before starting another. Is this single threaded code so it's not necessary?
As for the patch:
Re: [PATCH 4/6] hw/scsi/virtio-scsi: Use RCU_READ macro
Quoted 11 lines · Manos Pitsidianakis
Quoted 8 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/scsi/virtio-scsi.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)Unrelated to your patch: I just noticed in
hw/scsi/virtio-scsi.c,s->resettingis used to flag whether the bus is resetting; but there's no check if a resetting is taking place before starting another. Is this single threaded code so it's not necessary?
No clue about this device, I'll let the maintainers answer you :)
PATCH 5/6 hw/vfio/common: Use RCU_READ macros
In reply to Philippe Mathieu-DaudéReplace the manual rcu_read_(un)lock calls by the *RCU_READ_LOCK_GUARD macros (See commit ef46ae67ba "docs/style: call out the use of GUARD macros").
--- hw/vfio/common.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
hw/vfio/common.c +16 -18
@@ -308,13 +308,13 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)return ; } -rcu_read_lock (); +RCU_READ_LOCK_GUARD ();if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only;if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only)) { - goto out; +return ; }/* * vaddr is only valid until rcu_read_unlock(). But after
@@ -343,8 +343,6 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)vfio_set_migration_error (ret); } } -out: -rcu_read_unlock (); } static void vfio_ram_discard_notify_discard(RamDiscardListener *rdl,
@@ -1223,23 +1221,23 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if (iotlb->target_as != &address_space_memory) {error_report ("Wrong target AS \"%s\", only system memory is allowed" , iotlb->target_as->name ? iotlb->target_as->name :"none" ); - goto out; - } - -rcu_read_lock (); -if (vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { - ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , - translated_addr); -if (ret) { -error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " -"0x%" HWADDR_PRIx") = %d (%s)" , - bcontainer, iova, iotlb->addr_mask +1 , ret, -strerror (-ret)); + }else { + WITH_RCU_READ_LOCK_GUARD() { +if (vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { + ret =vfio_get_dirty_bitmap (bcontainer, iova, + iotlb->addr_mask +1 , + translated_addr); +if (ret) { +error_report ("vfio_iommu_map_dirty_notify(%p," +" 0x%" HWADDR_PRIx +", 0x%" HWADDR_PRIx") = %d (%s)" , + bcontainer, iova, iotlb->addr_mask +1 , ret, +strerror (-ret)); + } + } } } -rcu_read_unlock (); -out:if (ret) {vfio_set_migration_error (ret); }
Signature · 1 line
2.41.0
Re: [PATCH 5/6] hw/vfio/common: Use RCU_READ macros
Quoted 16 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
*RCU_READ_LOCK_GUARDmacros (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/vfio/common.c| 34 ++++++++++++++++------------------1 file changed, 16 insertions(+), 18 deletions(-)hw/vfio/common.c +0
-0@@ -308,13 +308,13 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)return ; }
hw/vfio/common.c static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) · line 317
Quoted 10 lines
hw/vfio/common.c +2
-2-rcu_read_lock (); +RCU_READ_LOCK_GUARD ();if ((iotlb->perm &IOMMU_RW ) !=IOMMU_NONE ) {bool read_only;if (!vfio_get_xlat_addr (iotlb, &vaddr,NULL , &read_only)) { - goto out; +return ;
Since this is the only early return, we could alternatively do:
- if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) {
+ if (vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) {
remove the goto/return, and wrap the rest of the codeflow in this if's brackets. And then we could use WITH_RCU_READ_LOCK_GUARD instead. That'd increase the code indentation however.
Quoted 53 lines
hw/vfio/common.c +14
-16}/* * vaddr is only valid until rcu_read_unlock(). But after @@ -343,8 +343,6 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)vfio_set_migration_error (ret); } } -out: -rcu_read_unlock (); } static void vfio_ram_discard_notify_discard(RamDiscardListener *rdl,@@ -1223,23 +1221,23 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)if (iotlb->target_as != &address_space_memory) {error_report ("Wrong target AS \"%s\", only system memory is allowed" , iotlb->target_as->name ? iotlb->target_as->name :"none" ); - goto out; - } - -rcu_read_lock (); -if (vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { - ret =vfio_get_dirty_bitmap (bcontainer, iova, iotlb->addr_mask +1 , - translated_addr); -if (ret) { -error_report ("vfio_iommu_map_dirty_notify(%p, 0x%" HWADDR_PRIx", " -"0x%" HWADDR_PRIx") = %d (%s)" , - bcontainer, iova, iotlb->addr_mask +1 , ret, -strerror (-ret)); + }else { + WITH_RCU_READ_LOCK_GUARD() { +if (vfio_get_xlat_addr (iotlb,NULL , &translated_addr,NULL )) { + ret =vfio_get_dirty_bitmap (bcontainer, iova, + iotlb->addr_mask +1 , + translated_addr); +if (ret) { +error_report ("vfio_iommu_map_dirty_notify(%p," +" 0x%" HWADDR_PRIx +", 0x%" HWADDR_PRIx") = %d (%s)" , + bcontainer, iova, iotlb->addr_mask +1 , ret, +strerror (-ret)); + } + } } } -rcu_read_unlock (); -out:if (ret) {vfio_set_migration_error (ret); }Signature · 1 line
2.41.0
Re: [PATCH 5/6] hw/vfio/common: Use RCU_READ macros
Quoted 31 lines · Manos Pitsidianakis
Quoted 17 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
*RCU_READ_LOCK_GUARDmacros (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/vfio/common.c| 34 ++++++++++++++++------------------1 file changed, 16 insertions(+), 18 deletions(-)hw/vfio/common.c +0
-0@@ -308,13 +308,13 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) return; }hw/vfio/common.c static void vfio_iommu_map_notify(IOMMUNotifier · line 318
Quoted 10 lines
hw/vfio/common.c +2
-2- rcu_read_lock(); + RCU_READ_LOCK_GUARD(); if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) { bool read_only; if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) { - goto out; + return;Since this is the only early return, we could alternatively do:
Quoted 4 lines
- if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL,
&read_only)) { + if (vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) {remove the goto/return, and wrap the rest of the codeflow in this if's brackets. And then we could use
WITH_RCU_READ_LOCK_GUARDinstead. That'd increase the code indentation however.
If the maintainer agrees with the style & code churn, I don't mind respining.
Quoted 14 lines
hw/vfio/common.c static void vfio_iommu_map_notify(IOMMUNotifier · line 347
Quoted 12 lines
hw/vfio/common.c +0
-0} /** vaddr is only valid until
rcu_read_unlock(). But afterhw/vfio/common.c +0
-2@@ -343,8 +343,6 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) vfio_set_migration_error(ret); } } -out: - rcu_read_unlock(); }Reviewed-by Manos Pitsidianakis <[email protected]>
Thanks!
Re: [PATCH 5/6] hw/vfio/common: Use RCU_READ macros
Quoted 32 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Manos Pitsidianakis
Quoted 17 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
*RCU_READ_LOCK_GUARDmacros (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/vfio/common.c| 34 ++++++++++++++++------------------1 file changed, 16 insertions(+), 18 deletions(-)hw/vfio/common.c +0
-0@@ -308,13 +308,13 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) return; }hw/vfio/common.c static void vfio_iommu_map_notify(IOMMUNotifier · line 318
Quoted 10 lines
hw/vfio/common.c +2
-2- rcu_read_lock(); + RCU_READ_LOCK_GUARD(); if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) { bool read_only; if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) { - goto out; + return;Since this is the only early return, we could alternatively do:
Quoted 7 lines
Quoted 4 lines
- if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL,
&read_only)) { + if (vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) {remove the goto/return, and wrap the rest of the codeflow in this if's brackets. And then we could use
WITH_RCU_READ_LOCK_GUARDinstead. That'd increase the code indentation however.If the maintainer agrees with the style & code churn, I don't mind respining.
Alex, Cédric, any preference?
Quoted 17 lines
Quoted 15 lines
hw/vfio/common.c static void vfio_iommu_map_notify(IOMMUNotifier · line 347
Quoted 13 lines
hw/vfio/common.c +0
-0} /** vaddr is only valid until
rcu_read_unlock(). But afterhw/vfio/common.c +0
-2@@ -343,8 +343,6 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) vfio_set_migration_error(ret); } } -out: - rcu_read_unlock(); }Reviewed-by Manos Pitsidianakis <[email protected]>Thanks!
Re: [PATCH 5/6] hw/vfio/common: Use RCU_READ macros
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 33 lines · Manos Pitsidianakis
Quoted 16 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
*RCU_READ_LOCK_GUARDmacros (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/vfio/common.c| 34 ++++++++++++++++------------------1 file changed, 16 insertions(+), 18 deletions(-)hw/vfio/common.c +0
-0@@ -308,13 +308,13 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) return; }hw/vfio/common.c static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb) · line 317
Quoted 10 lines
hw/vfio/common.c +2
-2- rcu_read_lock(); + RCU_READ_LOCK_GUARD(); if ((iotlb->perm & IOMMU_RW) != IOMMU_NONE) { bool read_only; if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) { - goto out; + return;Since this is the only early return, we could alternatively do:
- if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL,
&read_only)) { + if (vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) {
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
remove the goto/return, and wrap the rest of the codeflow in this if's brackets. And then we could use
WITH_RCU_READ_LOCK_GUARDinstead. That'd increase the code indentation however.If the maintainer agrees with the style & code churn, I don't mind respining.
Alex, Cédric, any preference?
my choice would be to keep the 'goto' statement and protect the vfio_get_xlat_addr() call with :
+ WITH_RCU_READ_LOCK_GUARD() {
+ if (vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) {
+ ret = vfio_get_dirty_bitmap(bcontainer, iova,
+ iotlb->addr_mask + 1,
+ translated_addr);
+ if (ret) {
+ error_report("vfio_iommu_map_dirty_notify(%p,"
+ " 0x%"HWADDR_PRIx
+ ", 0x%"HWADDR_PRIx") = %d (%s)",
+ bcontainer, iova, iotlb->addr_mask + 1, ret,
+ strerror(-ret));
+ }
+ }
}Thanks,
C.
PATCH 6/6 hw/virtio/vhost: Use RCU_READ macro
In reply to Philippe Mathieu-DaudéReplace the manual rcu_read_(un)lock calls by the WITH_RCU_READ_LOCK_GUARD macro (See commit ef46ae67ba "docs/style: call out the use of GUARD macros").
--- hw/virtio/vhost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/virtio/vhost.c +3 -3
@@ -186,12 +186,12 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *dev,hwaddr phys, s, offset;while (used_size) { -rcu_read_lock (); - iotlb =address_space_get_iotlb_entry (dev->vdev->dma_as, + WITH_RCU_READ_LOCK_GUARD() { + iotlb =address_space_get_iotlb_entry (dev->vdev->dma_as, used_phys, true,MEMTXATTRS_UNSPECIFIED ); -rcu_read_unlock (); + }if (!iotlb.target_as) { qemu_log_mask(LOG_GUEST_ERROR, "translation "
Signature · 1 line
2.41.0
Re: [PATCH 6/6] hw/virtio/vhost: Use RCU_READ macro
Quoted 32 lines · Philippe Mathieu-Daudé
Replace the manual rcu_read_(un)lock calls by the
WITH_RCU_READ_LOCK_GUARDmacro (See commitef46ae67ba"docs/style: call out the use of GUARD macros").Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/virtio/vhost.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)hw/virtio/vhost.c +3
-3@@ -186,12 +186,12 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev *dev,hwaddr phys, s, offset;while (used_size) { -rcu_read_lock (); - iotlb =address_space_get_iotlb_entry (dev->vdev->dma_as, + WITH_RCU_READ_LOCK_GUARD() { + iotlb =address_space_get_iotlb_entry (dev->vdev->dma_as, used_phys, true,MEMTXATTRS_UNSPECIFIED ); -rcu_read_unlock (); + }if (!iotlb.target_as) { qemu_log_mask(LOG_GUEST_ERROR, "translation "Signature · 1 line
2.41.0