Cleanup up to fix missing ERRP_GUARD() for error_prepend()
Subsystems (2)
v2 cover Cleanup up to fix missing ERRP_GUARD() for error_prepend()
From: Zhao Liu <[email protected]>
Hi,
This series is the v2 to add missing ERRP_GUARD() for error_prepend(), which collects the previous v1 part 1 [1] and v1 part 2 (and excludes the 4 patches that have already been merged).
The @errp's second restriction (in qapi/error) said:
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
With this series, all error_prepend() will follow the above usage rules.
In this series, 2 cases of error_prepend() with &error_fatal are recognized (patch 30 & patch 31).
And there are some remaining TODOs:
* follow-up cleanup for related @err use cases. (Suggested by Thomas)
* continue to cleanup error_append_hint().
The cleanup looks very trivial and thanks for your review!
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
Thanks and Best Regards,
Zhao
---
Zhao Liu (29):
error: Add error_vprepend() in comment of ERRP_GUARD() rules backends/iommufd: Fix missing ERRP_GUARD() for error_prepend()
block: Fix missing ERRP_GUARD() for error_prepend() block/copy-before-write: Fix missing ERRP_GUARD() for error_prepend() block/nbd: Fix missing ERRP_GUARD() for error_prepend() block/nvme: Fix missing ERRP_GUARD() for error_prepend() block/qcow2-bitmap: Fix missing ERRP_GUARD() for error_prepend() block/qcow2: Fix missing ERRP_GUARD() for error_prepend() block/qed: Fix missing ERRP_GUARD() for error_prepend() block/snapshot: Fix missing ERRP_GUARD() for error_prepend() block/vdi: Fix missing ERRP_GUARD() for error_prepend() block/vmdk: Fix missing ERRP_GUARD() for error_prepend() block/virtio-blk: Fix missing ERRP_GUARD() for error_prepend() hw/core/loader-fit: Fix missing ERRP_GUARD() for error_prepend() hw/core/qdev-properties-system: Fix missing ERRP_GUARD() for
error_prepend()
hw/misc/ivshmem: Fix missing ERRP_GUARD() for error_prepend() hw/scsi/vhost-scsi: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/ap: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/container: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/helpers: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/iommufd: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/pci-quirks: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/pci: Fix missing ERRP_GUARD() for error_prepend() hw/vfio/platform: Fix missing ERRP_GUARD() for error_prepend() hw/virtio/vhost-vsock: Fix missing ERRP_GUARD() for error_prepend() hw/virtio/vhost: Fix missing ERRP_GUARD() for error_prepend() migration/option: Fix missing ERRP_GUARD() for error_prepend() net/vhost-vdpa: Fix missing ERRP_GUARD() for error_prepend() target/s390x/cpu_models: Fix missing ERRP_GUARD() for error_prepend()
backends/iommufd.c | 1 + block.c | 4 ++++ block/copy-before-write.c | 1 + block/nbd.c | 1 + block/nvme.c | 3 +++ block/qcow2-bitmap.c | 1 + block/qcow2.c | 2 ++ block/qed.c | 1 + block/snapshot.c | 2 ++ block/vdi.c | 1 + block/vmdk.c | 1 + hw/block/virtio-blk.c | 1 + hw/core/loader-fit.c | 2 ++ hw/core/qdev-properties-system.c | 1 + hw/misc/ivshmem.c | 1 + hw/scsi/vhost-scsi.c | 1 + hw/vfio/ap.c | 1 + hw/vfio/container.c | 1 + hw/vfio/helpers.c | 3 +++ hw/vfio/iommufd.c | 1 + hw/vfio/pci-quirks.c | 2 ++ hw/vfio/pci.c | 2 ++ hw/vfio/platform.c | 1 + hw/virtio/vhost-vsock.c | 1 + hw/virtio/vhost.c | 2 ++ include/qapi/error.h | 2 +- migration/options.c | 2 ++ net/vhost-vdpa.c | 1 + target/s390x/cpu_models.c | 2 ++ 29 files changed, 44 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
PATCH v2 1/29 error: Add error_vprepend() in comment of ERRP_GUARD() rules
From: Zhao Liu <[email protected]>
The error_vprepend() should use ERRP_GUARD() just as the documentation of ERRP_GUARD() says:
Quoted 2 lines
It must be used when the function dereferences @errp or passes @errp to
error_prepend(),error_vprepend(), orerror_append_hint().
Considering that error_vprepend() is also an API provided in error.h, it is necessary to add it to the description of the rules for using ERRP_GUARD().
---
v2: Add a comma after error_vprepend(). (Markus)
--- include/qapi/error.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/qapi/error.h +1 -1
@@ -207,7 +207,7 @@* * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. -* - It should not be passed to error_prepend() or +* - It should not be passed to error_prepend(), error_vprepend(), or * error_append_hint(), because that doesn't work with &error_fatal. * ERRP_GUARD() lifts these restrictions. *
Signature · 1 line
2.34.1
PATCH v2 2/29 backends/iommufd: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The iommufd_backend_set_fd() passes @errp to error_prepend(), to avoid the above issue, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- backends/iommufd.c | 1 + 1 file changed, 1 insertion(+)
backends/iommufd.c +1 -0
@@ -43,6 +43,7 @@ static void iommufd_backend_finalize(Object *obj)static void iommufd_backend_set_fd (Object *obj,const char *str,Error **errp) { +ERRP_GUARD ();IOMMUFDBackend *be =IOMMUFD_BACKEND (obj);int fd =-1 ;
Signature · 1 line
2.34.1
Re: [PATCH v2 02/29] backends/iommufd: Fix missing ERRP_GUARD() for error_prepend()
Quoted 25 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].The
iommufd_backend_set_fd()passes @errp toerror_prepend(), to avoid the above issue, add missingERRP_GUARD()at the beginning of this function.
Quoted 8 lines
[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc Yi Liu <[email protected]>Cc Eric Auger <[email protected]>Cc Zhenzhong Duan <[email protected]>Signed-off-by Zhao Liu <[email protected]>Reviewed-by Zhenzhong Duan <[email protected]>
Eric
Quoted 16 lines
--- backends/iommufd.c | 1 + 1 file changed, 1 insertion(+)backends/iommufd.c +1
-0@@ -43,6 +43,7 @@ static void iommufd_backend_finalize(Object *obj)static void iommufd_backend_set_fd (Object *obj,const char *str,Error **errp) { +ERRP_GUARD ();IOMMUFDBackend *be =IOMMUFD_BACKEND (obj);int fd =-1 ;
PATCH v2 3/29 block: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In block.c, there are 4 functions passing @errp to error_prepend() without ERRP_GUARD():
- bdrv_co_create_opts_simple()
- parse_json_filename()
- bdrv_open_backing_file()
- bdrv_append_temp_snapshot()
bdrv_co_create_opts_simple(), is an implementation of BlockDriver.bdrv_co_create_opts(). There are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
Though the @errp parameters passed to parse_json_filename(), bdrv_open_backing_file() and bdrv_append_temp_snapshot() points to their callers' local_err, to follow the requirement of @errp, also add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2:
* Use Markus' sentence to polish commit message. (Markus)
* Fix typo. (Eric)
--- block.c | 4 ++++ 1 file changed, 4 insertions(+)
block.c +4 -0
@@ -633,6 +633,7 @@ int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv, QemuOpts *opts, Error **errp) { +ERRP_GUARD ();BlockBackend *blk;QDict *options;int64_t size =0 ;
@@ -1998,6 +1999,7 @@ fail_opts:static QDict *parse_json_filename (const char *filename,Error **errp) { +ERRP_GUARD ();QObject *options_obj;QDict *options;int ret;
@@ -3585,6 +3587,7 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,int bdrv_open_backing_file (BlockDriverState *bs,QDict *parent_options,const char *bdref_key,Error **errp) { +ERRP_GUARD ();char *backing_filename =NULL ;char *bdref_key_dot;const char *reference =NULL ;
@@ -3851,6 +3854,7 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs, QDict *snapshot_options, Error **errp) { +ERRP_GUARD (); g_autofree char *tmp_filename = NULL;int64_t total_size;QemuOpts *opts =NULL ;
Signature · 1 line
2.34.1
PATCH v2 4/29 block/copy-before-write: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The cbw_open() passes @errp to error_prepend() without ERRP_GUARD().
Though it is the BlockDriver.bdrv_open() method, and currently its @errp parameter only points to callers' local_err, to follow the requirement of @errp, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/copy-before-write.c | 1 + 1 file changed, 1 insertion(+)
block/copy-before-write.c +1 -0
@@ -407,6 +407,7 @@ out:static int cbw_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) { +ERRP_GUARD ();BDRVCopyBeforeWriteState *s = bs->opaque;BdrvDirtyBitmap *bitmap =NULL ;int64_t cluster_size;
Signature · 1 line
2.34.1
PATCH v2 5/29 block/nbd: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The nbd_co_do_receive_one_chunk() passes @errp to error_prepend() without ERRP_GUARD(), and though its @errp parameter points to its caller's local_err, to follow the requirement of @errp, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/nbd.c | 1 + 1 file changed, 1 insertion(+)
block/nbd.c +1 -0
@@ -852,6 +852,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( BDRVNBDState *s, uint64_t cookie, bool only_structured, int *request_ret, QEMUIOVector *qiov, void **payload, Error **errp) { +ERRP_GUARD ();int ret;int i =COOKIE_TO_INDEX (cookie);void *local_payload =NULL ;
Signature · 1 line
2.34.1
PATCH v2 6/29 block/nvme: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In nvme.c, there are 3 functions passing @errp to error_prepend() without ERRP_GUARD():
- nvme_init_queue()
- nvme_create_queue_pair()
- nvme_identify()
All these 3 functions take their @errp parameters from the nvme_file_open(), which is a BlockDriver.bdrv_nvme() method and its @errp points to its caller's local_err.
Though these 3 cases haven't trigger the issue like [1] said, to follow the requirement of @errp, add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/nvme.c | 3 +++ 1 file changed, 3 insertions(+)
block/nvme.c +3 -0
@@ -168,6 +168,7 @@ static QemuOptsList runtime_opts = {static bool nvme_init_queue (BDRVNVMeState *s,NVMeQueue *q,unsigned nentries,size_t entry_bytes,Error **errp) { +ERRP_GUARD ();size_t bytes;int r;
@@ -221,6 +222,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, unsigned idx, size_t size, Error **errp) { +ERRP_GUARD ();int i, r;NVMeQueuePair *q;uint64_t prp_list_iova;
@@ -535,6 +537,7 @@ static int nvme_admin_cmd_sync(BlockDriverState *bs, NvmeCmd *cmd)/* Returns true on success, false on failure. */ static bool nvme_identify (BlockDriverState *bs,int namespace,Error **errp) { +ERRP_GUARD ();BDRVNVMeState *s = bs->opaque;bool ret = false;QEMU_AUTO_VFREE union {
Signature · 1 line
2.34.1
PATCH v2 7/29 block/qcow2-bitmap: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The qcow2_co_can_store_new_dirty_bitmap() passes @errp to error_prepend(). As a BlockDriver.bdrv_co_can_store_new_dirty_bitmap method, it's called by bdrv_co_can_store_new_dirty_bitmap().
Its caller is not being called anywhere, but as the API in include/block/block-io.h, we can't ensure what kind of @errp future users will pass in.
To avoid potential issues as [1] said, add missing ERRP_GUARD() at the beginning of qcow2_co_can_store_new_dirty_bitmap().
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/qcow2-bitmap.c | 1 + 1 file changed, 1 insertion(+)
block/qcow2-bitmap.c +1 -0
@@ -1710,6 +1710,7 @@ bool coroutine_fn qcow2_co_can_store_new_dirty_bitmap(BlockDriverState *bs,uint32_t granularity, Error **errp) { +ERRP_GUARD ();BDRVQcow2State *s = bs->opaque;BdrvDirtyBitmap *bitmap;uint64_t bitmap_directory_size =0 ;
Signature · 1 line
2.34.1
PATCH v2 8/29 block/qcow2: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In block/qcow2.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- qcow2_co_create()
- qcow2_co_truncate()
There are too many possible callers to check the impact of the defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
Therefore, to avoid the issue like [1] said, add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2:
* Use Markus' sentence to polish commit message. (Markus)
* Fix typo. (Eric)
--- block/qcow2.c | 2 ++ 1 file changed, 2 insertions(+)
block/qcow2.c +2 -0
@@ -3483,6 +3483,7 @@ static uint64_t qcow2_opt_get_refcount_bits_del(QemuOpts *opts, int version, static int coroutine_fn GRAPH_UNLOCKEDqcow2_co_create (BlockdevCreateOptions *create_options,Error **errp) { +ERRP_GUARD ();BlockdevCreateOptionsQcow2 *qcow2_opts;QDict *options;
@@ -4283,6 +4284,7 @@ static int coroutine_fn GRAPH_RDLOCK qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) { +ERRP_GUARD ();BDRVQcow2State *s = bs->opaque;uint64_t old_length;int64_t new_l1_size;
Signature · 1 line
2.34.1
PATCH v2 9/29 block/qed: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The bdrv_qed_co_invalidate_cache() passes @errp to error_prepend() without ERRP_GUARD().
Though it is a BlockDriver.bdrv_co_invalidate_cache() method, and currently its @errp parameter only points to callers' local_err, to follow the requirement of @errp, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/qed.c | 1 + 1 file changed, 1 insertion(+)
block/qed.c +1 -0
@@ -1579,6 +1579,7 @@ bdrv_qed_co_change_backing_file(BlockDriverState *bs, const char *backing_file, static void coroutine_fn GRAPH_RDLOCKbdrv_qed_co_invalidate_cache (BlockDriverState *bs,Error **errp) { +ERRP_GUARD ();BDRVQEDState *s = bs->opaque;int ret;
Signature · 1 line
2.34.1
PATCH v2 10/29 block/snapshot: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In block/snapshot.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- bdrv_all_delete_snapshot()
- bdrv_all_goto_snapshot()
As the APIs exposed in include/block/snapshot.h, they could be called by other modules.
To avoid potential issues as [1] said, add missing ERRP_GUARD() at the beginning of these 2 functions.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/snapshot.c | 2 ++ 1 file changed, 2 insertions(+)
block/snapshot.c +2 -0
@@ -566,6 +566,7 @@ int bdrv_all_delete_snapshot(const char *name, bool has_devices, strList *devices, Error **errp) { +ERRP_GUARD ();g_autoptr (GList) bdrvs =NULL ;GList *iterbdrvs;
@@ -605,6 +606,7 @@ int bdrv_all_goto_snapshot(const char *name, bool has_devices, strList *devices, Error **errp) { +ERRP_GUARD ();g_autoptr (GList) bdrvs =NULL ;GList *iterbdrvs;int ret;
Signature · 1 line
2.34.1
Re: [PATCH v2 10/29] block/snapshot: Fix missing ERRP_GUARD() for error_prepend()
Quoted 56 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].In
block/snapshot.c, there are 2 functions passing @errp toerror_prepend()withoutERRP_GUARD():
-bdrv_all_delete_snapshot()
-bdrv_all_goto_snapshot()As the APIs exposed in
include/block/snapshot.h, they could be called by other modules.To avoid potential issues as [1] said, add missing
ERRP_GUARD()at the beginning of these 2 functions.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc Kevin Wolf <[email protected]>Cc Hanna Reitz <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- block/snapshot.c | 2 ++ 1 file changed, 2 insertions(+)block/snapshot.c +1
-0@@ -566,6 +566,7 @@ int bdrv_all_delete_snapshot(const char *name, bool has_devices, strList *devices, Error **errp) { +ERRP_GUARD ();g_autoptr (GList) bdrvs =NULL ;GList *iterbdrvs;
block/snapshot.c int bdrv_all_goto_snapshot(const char *name, · line 612
Quoted 7 lines
block/snapshot.c +1
-0@@ -605,6 +606,7 @@ int bdrv_all_goto_snapshot(const char *name, bool has_devices, strList *devices, Error **errp) { +ERRP_GUARD ();g_autoptr (GList) bdrvs =NULL ;GList *iterbdrvs;int ret;
PATCH v2 11/29 block/vdi: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vdi_co_do_create() passes @errp to error_prepend() without ERRP_GUARD(), and its @errp parameter is so widely sourced that it is necessary to protect it with ERRP_GUARD().
To avoid the potential issues as [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/vdi.c | 1 + 1 file changed, 1 insertion(+)
block/vdi.c +1 -0
@@ -738,6 +738,7 @@ static int coroutine_fn GRAPH_UNLOCKED vdi_co_do_create(BlockdevCreateOptions *create_options, size_t block_size, Error **errp) { +ERRP_GUARD ();BlockdevCreateOptionsVdi *vdi_opts;int ret =0 ;uint64_t bytes =0 ;
Signature · 1 line
2.34.1
Re: [PATCH v2 11/29] block/vdi: Fix missing ERRP_GUARD() for error_prepend()
Quoted 45 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].The
vdi_co_do_create()passes @errp toerror_prepend()withoutERRP_GUARD(), and its @errp parameter is so widely sourced that it is necessary to protect it withERRP_GUARD().To avoid the potential issues as [1] said, add missing
ERRP_GUARD()at the beginning of this function.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc Stefan Weil <[email protected]>Cc Kevin Wolf <[email protected]>Cc Hanna Reitz <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- block/vdi.c | 1 + 1 file changed, 1 insertion(+)block/vdi.c +0
-0
block/vdi.c static int coroutine_fn GRAPH_UNLOCKED · line 744
Quoted 7 lines
block/vdi.c +1
-0@@ -738,6 +738,7 @@ static int coroutine_fn GRAPH_UNLOCKED vdi_co_do_create(BlockdevCreateOptions *create_options, size_t block_size, Error **errp) { +ERRP_GUARD ();BlockdevCreateOptionsVdi *vdi_opts;int ret =0 ;uint64_t bytes =0 ;
PATCH v2 12/29 block/vmdk: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vmdk_parse_extents() passes @errp to error_prepend(), and its @errp is from vmdk_open().
Though, vmdk_open(), as a BlockDriver.bdrv_open(), gets the @errp parameter which is pointer of its caller's local_err, to follow the requirement of @errp, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- block/vmdk.c | 1 + 1 file changed, 1 insertion(+)
block/vmdk.c +1 -0
@@ -1147,6 +1147,7 @@ static int GRAPH_RDLOCK vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options, Error **errp) { +ERRP_GUARD ();int ret;int matches;char access[11 ];
Signature · 1 line
2.34.1
Re: [PATCH v2 12/29] block/vmdk: Fix missing ERRP_GUARD() for error_prepend()
Quoted 46 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].The
vmdk_parse_extents()passes @errp toerror_prepend(), and its @errp is fromvmdk_open().Though,
vmdk_open(), as aBlockDriver.bdrv_open(), gets the @errp parameter which is pointer of its caller'slocal_err, to follow the requirement of @errp, add missingERRP_GUARD()at the beginning of this function.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc Fam Zheng <[email protected]>Cc Kevin Wolf <[email protected]>Cc Hanna Reitz <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- block/vmdk.c | 1 + 1 file changed, 1 insertion(+)block/vmdk.c +0
-0
block/vmdk.c static int GRAPH_RDLOCK · line 1153
Quoted 7 lines
block/vmdk.c +1
-0@@ -1147,6 +1147,7 @@ static int GRAPH_RDLOCK vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options, Error **errp) { +ERRP_GUARD ();int ret;int matches;char access[11 ];
PATCH v2 13/29 block/virtio-blk: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The virtio_blk_vq_aio_context_init() passes @errp to error_prepend().
Though its @errp points its caller's local @err variable, to follow the requirement of @errp, add missing ERRP_GUARD() at the beginning of virtio_blk_vq_aio_context_init().
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- hw/block/virtio-blk.c | 1 + 1 file changed, 1 insertion(+)
hw/block/virtio-blk.c +1 -0
@@ -1682,6 +1682,7 @@ static bool apply_iothread_vq_mapping(/* Context: BQL held */ static bool virtio_blk_vq_aio_context_init (VirtIOBlock *s,Error **errp) { +ERRP_GUARD ();VirtIODevice *vdev =VIRTIO_DEVICE (s);VirtIOBlkConf *conf = &s->conf;BusState *qbus =BUS (qdev_get_parent_bus (DEVICE (vdev)));
Signature · 1 line
2.34.1
PATCH v2 14/29 hw/core/loader-fit: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In hw/core/loader-fit.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- fit_load_kernel()
- fit_load_fdt()
Their @errp parameters are both the pointers of the local @err virable in load_fit().
Though they don't cause the issue like [1] said, to follow the requirement of @errp, add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- hw/core/loader-fit.c | 2 ++ 1 file changed, 2 insertions(+)
hw/core/loader-fit.c +2 -0
@@ -120,6 +120,7 @@ static int fit_load_kernel(const struct fit_loader *ldr, const void *itb, int cfg, void *opaque, hwaddr *pend, Error **errp) { +ERRP_GUARD ();const char *name;const void *data;const void *load_data;
@@ -178,6 +179,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, int cfg, void *opaque, const void *match_data, hwaddr kernel_end, Error **errp) { +ERRP_GUARD ();Error *err =NULL ;const char *name;const void *data;
Signature · 1 line
2.34.1
PATCH v2 15/29 hw/core/qdev-properties-system: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The set_chr() passes @errp to error_prepend() without ERRP_GUARD().
As a PropertyInfo.set method, there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/core/qdev-properties-system.c | 1 + 1 file changed, 1 insertion(+)
hw/core/qdev-properties-system.c +1 -0
@@ -242,6 +242,7 @@ static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque,static void set_chr (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { +ERRP_GUARD ();Property *prop = opaque;CharBackend *be =object_field_prop_ptr (obj, prop);Chardev *s;
Signature · 1 line
2.34.1
PATCH v2 16/29 hw/misc/ivshmem: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The ivshmem_common_realize() passes @errp to error_prepend(), and as a DeviceClass.realize method, there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/misc/ivshmem.c | 1 + 1 file changed, 1 insertion(+)
hw/misc/ivshmem.c +1 -0
@@ -832,6 +832,7 @@ static void ivshmem_write_config(PCIDevice *pdev, uint32_t address,static void ivshmem_common_realize (PCIDevice *dev,Error **errp) { +ERRP_GUARD ();IVShmemState *s =IVSHMEM_COMMON (dev);Error *err =NULL ;uint8_t *pci_conf;
Signature · 1 line
2.34.1
PATCH v2 17/29 hw/scsi/vhost-scsi: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vhost_scsi_realize() passes @errp to error_prepend(), and as a VirtioDeviceClass.realize method, its @errp is from DeviceClass.realize so that there is no guarantee that the @errp won't point to @error_fatal.
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- hw/scsi/vhost-scsi.c | 1 + 1 file changed, 1 insertion(+)
hw/scsi/vhost-scsi.c +1 -0
@@ -220,6 +220,7 @@ static int vhost_scsi_set_workers(VHostSCSICommon *vsc, bool per_virtqueue)static void vhost_scsi_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (dev);VHostSCSICommon *vsc =VHOST_SCSI_COMMON (dev);Error *err =NULL ;
Signature · 1 line
2.34.1
Re: [PATCH v2 17/29] hw/scsi/vhost-scsi: Fix missing ERRP_GUARD() for error_prepend()
Quoted 45 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].The
vhost_scsi_realize()passes @errp toerror_prepend(), and as a VirtioDeviceClass.realize method, its @errp is from DeviceClass.realize so that there is no guarantee that the @errp won't point to @error_fatal.To avoid the issue like [1] said, add missing
ERRP_GUARD()at the beginning of this function.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc Paolo Bonzini <[email protected]>Cc Fam Zheng <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/scsi/vhost-scsi.c | 1 + 1 file changed, 1 insertion(+)hw/scsi/vhost-scsi.c +0
-0
hw/scsi/vhost-scsi.c static int vhost_scsi_set_workers(VHostSCSICommon *vsc, bool per_virtqueue) · line 226
Quoted 7 lines
hw/scsi/vhost-scsi.c +1
-0@@ -220,6 +220,7 @@ static int vhost_scsi_set_workers(VHostSCSICommon *vsc, bool per_virtqueue)static void vhost_scsi_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (dev);VHostSCSICommon *vsc =VHOST_SCSI_COMMON (dev);Error *err =NULL ;
PATCH v2 18/29 hw/vfio/ap: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vfio_ap_realize() passes @errp to error_prepend(), and as a DeviceClass.realize method, there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/vfio/ap.c | 1 + 1 file changed, 1 insertion(+)
hw/vfio/ap.c +1 -0
@@ -155,6 +155,7 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,static void vfio_ap_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();int ret;Error *err =NULL ;VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev);
Signature · 1 line
2.34.1
Re: [PATCH v2 18/29] hw/vfio/ap: Fix missing ERRP_GUARD() for error_prepend()
Quoted 32 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].The
vfio_ap_realize()passes @errp toerror_prepend(), and as a DeviceClass.realize method, there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp withERRP_GUARD().To avoid the issue like [1] said, add missing
ERRP_GUARD()at the beginning of this function.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").
Quoted 8 lines
Cc Alex Williamson <[email protected]>Cc "Cédric Le Goater" <[email protected]>Cc Tony Krowiak <[email protected]>Cc Halil Pasic <[email protected]>Cc Jason Herne <[email protected]>Cc Thomas Huth <[email protected]>Signed-off-by Zhao Liu <[email protected]>
Thanks,
C.
Quoted 18 lines
---
v2: Use Markus' sentence to polish commit message. (Markus)--- hw/vfio/ap.c | 1 + 1 file changed, 1 insertion(+)hw/vfio/ap.c +1
-0@@ -155,6 +155,7 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,static void vfio_ap_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();int ret;Error *err =NULL ;VFIOAPDevice *vapdev =VFIO_AP_DEVICE (dev);
PATCH v2 19/29 hw/vfio/container: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vfio_get_group() passes @errp to error_prepend(). Its @errp is from vfio_attach_device(), and there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/vfio/container.c | 1 + 1 file changed, 1 insertion(+)
hw/vfio/container.c +1 -0
@@ -719,6 +719,7 @@ static void vfio_disconnect_container(VFIOGroup *group)static VFIOGroup *vfio_get_group (int groupid,AddressSpace *as,Error **errp) { +ERRP_GUARD ();VFIOGroup *group;char path[32 ];struct vfio_group_status status = { .argsz =sizeof (status) };
Signature · 1 line
2.34.1
PATCH v2 20/29 hw/vfio/helpers: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In hw/vfio/helpers.c, there are 3 functions passing @errp to error_prepend() without ERRP_GUARD():
- vfio_set_irq_signaling()
- vfio_device_get_name()
- vfio_device_set_fd()
There are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect their @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/vfio/helpers.c | 3 +++ 1 file changed, 3 insertions(+)
hw/vfio/helpers.c +3 -0
@@ -110,6 +110,7 @@ static const char *index_to_str(VFIODevice *vbasedev, int index)int vfio_set_irq_signaling (VFIODevice *vbasedev,int index,int subindex,int action,int fd,Error **errp) { +ERRP_GUARD ();struct vfio_irq_set *irq_set;int argsz, ret =0 ;const char *name;
@@ -613,6 +614,7 @@ bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)int vfio_device_get_name (VFIODevice *vbasedev,Error **errp) { +ERRP_GUARD ();struct stat st;if (vbasedev->fd <0 ) {
@@ -644,6 +646,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp)void vfio_device_set_fd (VFIODevice *vbasedev,const char *str,Error **errp) { +ERRP_GUARD ();int fd =monitor_fd_param (monitor_cur (), str, errp);if (fd <0 ) {
Signature · 1 line
2.34.1
PATCH v2 21/29 hw/vfio/iommufd: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The iommufd_cdev_getfd() passes @errp to error_prepend(). Its @errp is from vfio_attach_device(), and there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/vfio/iommufd.c | 1 + 1 file changed, 1 insertion(+)
hw/vfio/iommufd.c +1 -0
@@ -116,6 +116,7 @@ static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev)static int iommufd_cdev_getfd (const char *sysfs_path,Error **errp) { +ERRP_GUARD ();long int ret = -ENOTTY ;char *path, *vfio_dev_path =NULL , *vfio_path =NULL ;DIR *dir =NULL ;
Signature · 1 line
2.34.1
PATCH v2 22/29 hw/vfio/pci-quirks: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In hw/vfio/pci-quirks.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- vfio_add_nv_gpudirect_cap()
- vfio_add_vmd_shadow_cap()
There are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect their @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/vfio/pci-quirks.c | 2 ++ 1 file changed, 2 insertions(+)
hw/vfio/pci-quirks.c +2 -0
@@ -1538,6 +1538,7 @@ static bool is_valid_std_cap_offset(uint8_t pos)static int vfio_add_nv_gpudirect_cap (VFIOPCIDevice *vdev,Error **errp) { +ERRP_GUARD ();PCIDevice *pdev = &vdev->pdev;int ret, pos;bool c8_conflict = false, d4_conflict = false;
@@ -1630,6 +1631,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)#define VMD_SHADOW_CAP_LEN 24static int vfio_add_vmd_shadow_cap (VFIOPCIDevice *vdev,Error **errp) { +ERRP_GUARD ();uint8_t membar_phys[16 ];int ret, pos =0xE8 ;
Signature · 1 line
2.34.1
PATCH v2 23/29 hw/vfio/pci: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In hw/vfio/pci.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- vfio_add_std_cap()
- vfio_realize()
The @errp of vfio_add_std_cap() is also from vfio_realize(). And vfio_realize(), as a PCIDeviceClass.realize method, its @errp is from DeviceClass.realize so that there is no guarantee that the @errp won't point to @error_fatal.
To avoid the issue like [1] said, add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- hw/vfio/pci.c | 2 ++ 1 file changed, 2 insertions(+)
hw/vfio/pci.c +2 -0
@@ -2136,6 +2136,7 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)static int vfio_add_std_cap (VFIOPCIDevice *vdev,uint8_t pos,Error **errp) { +ERRP_GUARD ();PCIDevice *pdev = &vdev->pdev;uint8_t cap_id, next, size;int ret;
@@ -2942,6 +2943,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)static void vfio_realize (PCIDevice *pdev,Error **errp) { +ERRP_GUARD ();VFIOPCIDevice *vdev =VFIO_PCI (pdev);VFIODevice *vbasedev = &vdev->vbasedev;char *tmp, *subsys;
Signature · 1 line
2.34.1
PATCH v2 24/29 hw/vfio/platform: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vfio_platform_realize() passes @errp to error_prepend(), and as a DeviceClass.realize method, there are too many possible callers to check the impact of this defect; it may or may not be harmless. Thus it is necessary to protect @errp with ERRP_GUARD().
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").---
v2: Use Markus' sentence to polish commit message. (Markus)
--- hw/vfio/platform.c | 1 + 1 file changed, 1 insertion(+)
hw/vfio/platform.c +1 -0
@@ -576,6 +576,7 @@ static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp)*/ static void vfio_platform_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();VFIOPlatformDevice *vdev =VFIO_PLATFORM_DEVICE (dev);SysBusDevice *sbdev =SYS_BUS_DEVICE (dev);VFIODevice *vbasedev = &vdev->vbasedev;
Signature · 1 line
2.34.1
PATCH v2 25/29 hw/virtio/vhost-vsock: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The vhost_vsock_device_realize() passes @errp to error_prepend(), and as a VirtioDeviceClass.realize method, its @errp is from DeviceClass.realize so that there is no guarantee that the @errp won't point to @error_fatal.
To avoid the issue like [1] said, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- hw/virtio/vhost-vsock.c | 1 + 1 file changed, 1 insertion(+)
hw/virtio/vhost-vsock.c +1 -0
@@ -121,6 +121,7 @@ static const VMStateDescription vmstate_virtio_vhost_vsock = {static void vhost_vsock_device_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();VHostVSockCommon *vvc =VHOST_VSOCK_COMMON (dev);VirtIODevice *vdev =VIRTIO_DEVICE (dev);VHostVSock *vsock =VHOST_VSOCK (dev);
Signature · 1 line
2.34.1
Re: [PATCH v2 25/29] hw/virtio/vhost-vsock: Fix missing ERRP_GUARD() for error_prepend()
Quoted 43 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].The
vhost_vsock_device_realize()passes @errp toerror_prepend(), and as a VirtioDeviceClass.realize method, its @errp is from DeviceClass.realize so that there is no guarantee that the @errp won't point to @error_fatal.To avoid the issue like [1] said, add missing
ERRP_GUARD()at the beginning of this function.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/virtio/vhost-vsock.c | 1 + 1 file changed, 1 insertion(+)hw/virtio/vhost-vsock.c +0
-0
hw/virtio/vhost-vsock.c static const VMStateDescription vmstate_virtio_vhost_vsock = { · line 127
Quoted 7 lines
hw/virtio/vhost-vsock.c +1
-0@@ -121,6 +121,7 @@ static const VMStateDescription vmstate_virtio_vhost_vsock = {static void vhost_vsock_device_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();VHostVSockCommon *vvc =VHOST_VSOCK_COMMON (dev);VirtIODevice *vdev =VIRTIO_DEVICE (dev);VHostVSock *vsock =VHOST_VSOCK (dev);
PATCH v2 26/29 hw/virtio/vhost: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In hw/virtio/vhost.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- vhost_save_backend_state()
- vhost_load_backend_state()
Their @errp both points to callers' @local_err. However, as the APIs defined in include/hw/virtio/vhost.h, it is necessary to protect their @errp with ERRP_GUARD().
To follow the requirement of @errp, add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- hw/virtio/vhost.c | 2 ++ 1 file changed, 2 insertions(+)
hw/virtio/vhost.c +2 -0
@@ -2199,6 +2199,7 @@ int vhost_check_device_state(struct vhost_dev *dev, Error **errp)int vhost_save_backend_state (struct vhost_dev *dev,QEMUFile *f,Error **errp) { +ERRP_GUARD ();/* Maximum chunk size in which to transfer the state */ const size_t chunk_size =1 *1024 *1024 ; g_autofree void *transfer_buf = NULL;
@@ -2291,6 +2292,7 @@ fail:int vhost_load_backend_state (struct vhost_dev *dev,QEMUFile *f,Error **errp) { +ERRP_GUARD ();size_t transfer_buf_size =0 ; g_autofree void *transfer_buf = NULL;g_autoptr (GError) g_err =NULL ;
Signature · 1 line
2.34.1
Re: [PATCH v2 26/29] hw/virtio/vhost: Fix missing ERRP_GUARD() for error_prepend()
Quoted 55 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].In
hw/virtio/vhost.c, there are 2 functions passing @errp toerror_prepend()withoutERRP_GUARD():
-vhost_save_backend_state()
-vhost_load_backend_state()Their @errp both points to callers' @local_err. However, as the APIs defined in
include/hw/virtio/vhost.h, it is necessary to protect their @errp withERRP_GUARD().To follow the requirement of @errp, add missing
ERRP_GUARD()at their beginning.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/virtio/vhost.c | 2 ++ 1 file changed, 2 insertions(+)hw/virtio/vhost.c +1
-0@@ -2199,6 +2199,7 @@ int vhost_check_device_state(struct vhost_dev *dev, Error **errp)int vhost_save_backend_state (struct vhost_dev *dev,QEMUFile *f,Error **errp) { +ERRP_GUARD ();/* Maximum chunk size in which to transfer the state */ const size_t chunk_size =1 *1024 *1024 ; g_autofree void *transfer_buf = NULL;
hw/virtio/vhost.c fail: · line 2298
Quoted 7 lines
hw/virtio/vhost.c +1
-0@@ -2291,6 +2292,7 @@ fail:int vhost_load_backend_state (struct vhost_dev *dev,QEMUFile *f,Error **errp) { +ERRP_GUARD ();size_t transfer_buf_size =0 ; g_autofree void *transfer_buf = NULL;g_autoptr (GError) g_err =NULL ;
PATCH v2 27/29 migration/option: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The migrate_params_check() passes @errp to error_prepend() without ERRP_GUARD(), and it could be called from migration_object_init(), where the passed @errp points to @error_fatal.
Therefore, the error message echoed in error_prepend() will be lost because of the above issue.
To fix this, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- migration/options.c | 2 ++ 1 file changed, 2 insertions(+)
migration/options.c +2 -0
@@ -1085,6 +1085,8 @@ void migrate_params_init(MigrationParameters *params)*/ bool migrate_params_check (MigrationParameters *params,Error **errp) { +ERRP_GUARD (); +if (params->has_compress_level && (params->compress_level >9 )) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
Signature · 1 line
2.34.1
PATCH v2 28/29 net/vhost-vdpa: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
The net_init_vhost_vdpa() passes @errp to error_prepend(), and as a member of net_client_init_fun[], it's called in net_client_init1() and gets @errp from this caller.
But because netdev_init_modern() passes &error_fatal to net_client_init1(), then @errp parameter of net_init_vhost_vdpa() would point to @error_fatal. This causes the error message in error_prepend() to be lost because of the above issue.
To fix this, add missing ERRP_GUARD() at the beginning of this function.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+)
net/vhost-vdpa.c +1 -0
@@ -1751,6 +1751,7 @@ static int vhost_vdpa_get_max_queue_pairs(int fd, uint64_t features,int net_init_vhost_vdpa (const Netdev *netdev,const char *name,NetClientState *peer,Error **errp) { +ERRP_GUARD ();const NetdevVhostVDPAOptions *opts;uint64_t features;int vdpa_device_fd;
Signature · 1 line
2.34.1
PATCH v2 29/29 target/s390x/cpu_models: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to error_prepend() requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed to error_prepend(), error_vprepend() or
* error_append_hint(), because that doesn't work with &error_fatal.
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
ERRP_GUARD() could avoid the case when @errp is &error_fatal, the user can't see this additional information, because exit() happens in error_setg earlier than information is added [1].
In target/s390x/cpu_models.c, there are 2 functions passing @errp to error_prepend() without ERRP_GUARD():
- check_compatibility()
- s390_realize_cpu_model()
Though both their @errp parameters point to their callers' local @err virables and don't cause the issue as [1] said, to follow the requirement of @errp, also add missing ERRP_GUARD() at their beginning.
[1]: Issue description in the commit message of commit ae7c80a7bd73
("error: New macro ERRP_GUARD()").--- target/s390x/cpu_models.c | 2 ++ 1 file changed, 2 insertions(+)
target/s390x/cpu_models.c +2 -0
@@ -503,6 +503,7 @@ static void error_prepend_missing_feat(const char *name, void *opaque)static void check_compatibility (const S390CPUModel *max_model,const S390CPUModel *model,Error **errp) { +ERRP_GUARD ();S390FeatBitmap missing;if (model->def->gen > max_model->def->gen) {
@@ -566,6 +567,7 @@ S390CPUModel *get_max_cpu_model(Error **errp)void s390_realize_cpu_model (CPUState *cs,Error **errp) { +ERRP_GUARD ();Error *err =NULL ;S390CPUClass *xcc =S390_CPU_GET_CLASS (cs);S390CPU *cpu =S390_CPU (cs);
Signature · 1 line
2.34.1
Re: [PATCH v2 29/29] target/s390x/cpu_models: Fix missing ERRP_GUARD() for error_prepend()
Quoted 33 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].In
target/s390x/cpu_models.c, there are 2 functions passing @errp toerror_prepend()withoutERRP_GUARD():
-check_compatibility()
-s390_realize_cpu_model()Though both their @errp parameters point to their callers' local @err virables and don't cause the issue as [1] said, to follow the requirement of @errp, also add missing
ERRP_GUARD()at their beginning.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").
Quoted 7 lines
Cc David Hildenbrand <[email protected]>Cc Thomas Huth <[email protected]>Cc Richard Henderson <[email protected]>Cc Ilya Leoshkevich <[email protected]>Signed-off-by Zhao Liu <[email protected]>---
Thanks,
C.
Re: [PATCH v2 29/29] target/s390x/cpu_models: Fix missing ERRP_GUARD() for error_prepend()
In reply to Zhao LiuQuoted 33 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As the comment in qapi/error, passing @errp to
error_prepend()requiresERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
...
* - It should not be passed toerror_prepend(),error_vprepend()or
*error_append_hint(), because that doesn't work with&error_fatal.
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
ERRP_GUARD()could avoid the case when @errp is&error_fatal, the user can't see this additional information, becauseexit()happens inerror_setgearlier than information is added [1].In
target/s390x/cpu_models.c, there are 2 functions passing @errp toerror_prepend()withoutERRP_GUARD():
-check_compatibility()
-s390_realize_cpu_model()Though both their @errp parameters point to their callers' local @err virables and don't cause the issue as [1] said, to follow the requirement of @errp, also add missing
ERRP_GUARD()at their beginning.[1]: Issue description in the commit message of commit
ae7c80a7bd73("error: New macro ERRP_GUARD()").
Quoted 7 lines
Cc David Hildenbrand <[email protected]>Cc Thomas Huth <[email protected]>Cc Richard Henderson <[email protected]>Cc Ilya Leoshkevich <[email protected]>Signed-off-by Zhao Liu <[email protected]>---
Thanks,
C.
Quoted 7 lines · Zhao Liu
---
Zhao Liu (29):hw/core/loader-fit: Fix missing
ERRP_GUARD()forerror_prepend()hw/core/qdev-properties-system: Fix missingERRP_GUARD()for
error_prepend()
hw/misc/ivshmem: Fix missingERRP_GUARD()forerror_prepend()
I'm queuing these 3 patches, thanks!
Hi Thomas/Markus/Michael,
For the remaing patches, could you please help me merge them next?
Many thanks!
Zhao
Quoted 16 lines · Philippe Mathieu-Daudé
Date: Tue, 12 Mar 2024 09:17:30 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v2 00/29] Cleanup up to fix missingERRP_GUARD()for
error_prepend()Quoted 7 lines · Zhao Liu
---
Zhao Liu (29):hw/core/loader-fit: Fix missing
ERRP_GUARD()forerror_prepend()hw/core/qdev-properties-system: Fix missingERRP_GUARD()for
error_prepend()
hw/misc/ivshmem: Fix missingERRP_GUARD()forerror_prepend()I'm queuing these 3 patches, thanks!
Quoted 5 lines · Zhao Liu
Hi Thomas/Markus/Michael,
For the remaing patches, could you please help me merge them next?
Many thanks!
Yes, I'm currently reviewing the ones that don't have a Reviewed-by yet. I can pick up the remaining patches if the other maintainers won't pick them up for the softfreeze today.
Thomas
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 16 lines
Date: Tue, 12 Mar 2024 09:17:30 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v2 00/29] Cleanup up to fix missingERRP_GUARD()for
error_prepend()Quoted 7 lines · Zhao Liu
---
Zhao Liu (29):hw/core/loader-fit: Fix missing
ERRP_GUARD()forerror_prepend()hw/core/qdev-properties-system: Fix missingERRP_GUARD()for
error_prepend()
hw/misc/ivshmem: Fix missingERRP_GUARD()forerror_prepend()I'm queuing these 3 patches, thanks!
Quoted 8 lines · Thomas Huth
Date: Tue, 12 Mar 2024 09:50:25 +0100
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH v2 00/29] Cleanup up to fix missingERRP_GUARD()for
error_prepend()Quoted 2 lines · Zhao Liu
Hi Thomas/Markus/Michael,
Quoted 8 lines
Quoted 3 lines
For the remaing patches, could you please help me merge them next?
Many thanks!
Yes, I'm currently reviewing the ones that don't have a Reviewed-by yet. I can pick up the remaining patches if the other maintainers won't pick them up for the softfreeze today.
Appreciate that you can help me get on the last train of releases.
If possible, could you please also help me pick up two other ERRP_GUARD() related cleanups (total 8 patches, both got r/b)? ;-)
My cleanup is too fragmented, I'll try to centralize my work to make it easier for maintainer to review and merge in the future!
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
Many thanks,
Zhao
Quoted 20 lines · Zhao Liu
Quoted 8 lines · Thomas Huth
Date: Tue, 12 Mar 2024 09:50:25 +0100
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH v2 00/29] Cleanup up to fix missingERRP_GUARD()for
error_prepend()Quoted 2 lines · Zhao Liu
Hi Thomas/Markus/Michael,
Quoted 8 lines
Quoted 3 lines
For the remaing patches, could you please help me merge them next?
Many thanks!
Yes, I'm currently reviewing the ones that don't have a Reviewed-by yet. I can pick up the remaining patches if the other maintainers won't pick them up for the softfreeze today.
Appreciate that you can help me get on the last train of releases.
Quoted 8 lines
If possible, could you please also help me pick up two other
ERRP_GUARD()related cleanups (total 8 patches, both got r/b)? ;-)My cleanup is too fragmented, I'll try to centralize my work to make it easier for maintainer to review and merge in the future!
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/qemu-devel/[email protected]/
I'll try to include them!
Thomas