block: Introduce zero-co:// and zero-aio://
PATCH 1/1 block: Introduce zero-co:// and zero-aio://
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
block/null.c +91 -0
@@ -76,6 +76,30 @@ static void null_aio_parse_filename(const char *filename, QDict *options, } } +static void zero_co_parse_filename (const char *filename,QDict *options, +Error **errp) +{ +/* This functions only exists so that a zero-co:// filename is accepted +* with the zero-co driver. */ +if (strcmp (filename,"zero-co://" )) { +error_setg (errp,"The only allowed filename for this driver is " +"'zero-co://'" ); +return ; + } +} + +static void zero_aio_parse_filename (const char *filename,QDict *options, +Error **errp) +{ +/* This functions only exists so that a zero-aio:// filename is accepted +* with the zero-aio driver. */ +if (strcmp (filename,"zero-aio://" )) { +error_setg (errp,"The only allowed filename for this driver is " +"'zero-aio://'" ); +return ; + } +} +static int null_file_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
@@ -99,6 +123,29 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,return ret; } +static int zero_file_open (BlockDriverState *bs,QDict *options,int flags, +Error **errp) +{ +QemuOpts *opts; +BDRVNullState *s = bs->opaque; +int ret =0 ; + + opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options, &error_abort); + s->length = +qemu_opt_get_size (opts,BLOCK_OPT_SIZE ,1 <<30 ); + s->latency_ns = +qemu_opt_get_number (opts,NULL_OPT_LATENCY ,0 ); +if (s->latency_ns <0 ) { +error_setg (errp,"latency-ns is invalid" ); + ret = -EINVAL ; + } + s->read_zeroes = true; +qemu_opts_del (opts); + bs->supported_write_flags =BDRV_REQ_FUA ; +return ret; +} +static int64_t null_getlength (BlockDriverState *bs) {BDRVNullState *s = bs->opaque;
@@ -316,10 +363,54 @@ static BlockDriver bdrv_null_aio = { .strong_runtime_opts = null_strong_runtime_opts, }; +static BlockDriver bdrv_zero_co = { + .format_name ="zero-co" , + .protocol_name ="zero-co" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = zero_file_open, + .bdrv_parse_filename = zero_co_parse_filename, + .bdrv_getlength = null_getlength, + .bdrv_get_allocated_file_size = null_allocated_file_size, + + .bdrv_co_preadv = null_co_preadv, + .bdrv_co_pwritev = null_co_pwritev, + .bdrv_co_flush_to_disk = null_co_flush, + .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_block_status = null_co_block_status, + + .bdrv_refresh_filename = null_refresh_filename, + .strong_runtime_opts = null_strong_runtime_opts, +}; + +static BlockDriver bdrv_zero_aio = { + .format_name ="zero-aio" , + .protocol_name ="zero-aio" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = zero_file_open, + .bdrv_parse_filename = zero_aio_parse_filename, + .bdrv_getlength = null_getlength, + .bdrv_get_allocated_file_size = null_allocated_file_size, + + .bdrv_aio_preadv = null_aio_preadv, + .bdrv_aio_pwritev = null_aio_pwritev, + .bdrv_aio_flush = null_aio_flush, + .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_block_status = null_co_block_status, + + .bdrv_refresh_filename = null_refresh_filename, + .strong_runtime_opts = null_strong_runtime_opts, +}; +static void bdrv_null_init (void ) {bdrv_register (&bdrv_null_co);bdrv_register (&bdrv_null_aio); +bdrv_register (&bdrv_zero_co); +bdrv_register (&bdrv_zero_aio); }block_init (bdrv_null_init);
Signature · 1 line
2.17.1
Quoted 10 lines · On 3/10/21 3:17 PM, [email protected] wrote:
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Thanks!
Quoted 7 lines
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)block/null.c +1
-0+static int zero_file_open(BlockDriverState *bs, QDict *options, int flags,
block/null.c static int null_file_open(BlockDriverState *bs, QDict *options, int flags, · line 136
Quoted 10 lines
block/null.c +10
-0+ Error **errp) +{ +QemuOpts *opts; +BDRVNullState *s = bs->opaque; +int ret =0 ; + + opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options, &error_abort); + s->length = +qemu_opt_get_size (opts,BLOCK_OPT_SIZE ,1 <<30 );
Please do not use this magic default value, let's always explicit the size.
s->length = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0);
if (s->length < 0) {
error_setg(errp, "%s is invalid", BLOCK_OPT_SIZE);
ret = -EINVAL;
}block/null.c static int null_file_open(BlockDriverState *bs, QDict *options, int flags, · line 147
Quoted 11 lines
block/null.c +11
-0+ s->latency_ns = +qemu_opt_get_number (opts,NULL_OPT_LATENCY ,0 ); +if (s->latency_ns <0 ) { +error_setg (errp,"latency-ns is invalid" ); + ret = -EINVAL ; + } + s->read_zeroes = true; +qemu_opts_del (opts); + bs->supported_write_flags =BDRV_REQ_FUA ; +return ret; +}
Otherwise LGTM :)
Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 10 lines · On 3/10/21 3:17 PM, [email protected] wrote:
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Thanks!
Quoted 7 lines
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)+static int zero_file_open(BlockDriverState *bs, QDict *options, int
flags,
block/null.c static int null_file_open(BlockDriverState *bs, QDict *options, int flags, · line 136
Quoted 10 lines
block/null.c +10
-0+ Error **errp) +{ +QemuOpts *opts; +BDRVNullState *s = bs->opaque; +int ret =0 ; + + opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options, &error_abort); + s->length = +qemu_opt_get_size (opts,BLOCK_OPT_SIZE ,1 <<30 );Please do not use this magic default value, let's always explicit the size.
Quoted 5 lines
s->length = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0);
if (s->length < 0) {
error_setg(errp, "%s is invalid", BLOCK_OPT_SIZE);
ret = -EINVAL;
}Doesn't that result in a bare
-blockdev zero-co://
would have 0 byte in size?
I'm copying what null-co:// does today, and it's convenient for tests. Why is a default size bad?
Fam
Quoted 18 lines
+
s->latency_ns=block/null.c static int null_file_open(BlockDriverState *bs, QDict *options, int flags, · line 147
Quoted 10 lines
block/null.c +10
-0+qemu_opt_get_number (opts,NULL_OPT_LATENCY ,0 ); +if (s->latency_ns <0 ) { +error_setg (errp,"latency-ns is invalid" ); + ret = -EINVAL ; + } + s->read_zeroes = true; +qemu_opts_del (opts); + bs->supported_write_flags =BDRV_REQ_FUA ; +return ret; +}Otherwise LGTM :)
Quoted 48 lines · Fam Zheng
On Wed, 10 Mar 2021 at 14:24, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 3/10/21 3:17 PM, [email protected] <mailto:[email protected]> wrote: > From: Fam Zheng <[email protected] <mailto:[email protected]>> > > null-co:// has a read-zeroes=off default, when used to in security > analysis, this can cause false positives because the driver doesn't > write to the read buffer. > > null-co:// has the highest possible performance as a block driver, so > let's keep it that way. This patch introduces zero-co:// and > zero-aio://, largely similar with null-*://, but have read-zeroes=on by > default, so it's more suitable in cases than null-co://. Thanks! > > Signed-off-by: Fam Zheng <[email protected] <mailto:[email protected]>> > --- > block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 91 insertions(+) > +static int zero_file_open(BlockDriverState *bs, QDict *options, int flags, > + Error **errp) > +{ > + QemuOpts *opts; > + BDRVNullState *s = bs->opaque; > + int ret = 0; > + > + opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); > + qemu_opts_absorb_qdict(opts, options, &error_abort); > + s->length = > + qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 1 << 30); Please do not use this magic default value, let's always explicit the size. s->length = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); if (s->length < 0) { error_setg(errp, "%s is invalid", BLOCK_OPT_SIZE); ret = -EINVAL; }
Quoted 5 lines
Doesn't that result in a bare
-blockdev zero-co://
would have 0 byte in size?
Yes, this will display an error.
Maybe better something like:
if (s->length == 0) {
error_append_hint(errp, "Usage: zero-co://,size=NUM");
error_setg(errp, "size must be specified");
ret = -EINVAL;
} else if (s->length < 0) {
error_setg(errp, "%s is invalid", BLOCK_OPT_SIZE);
ret = -EINVAL;
}Quoted 3 lines
I'm copying what null-co:// does today, and it's convenient for tests. Why is a default size bad?
We learned default are almost always bad because you can not get rid of them. Also because we have reports of errors when using floppy and another one (can't remember) with null-co because of invalid size and we have to explain "the default is 1GB, you have to explicit your size".
Phil.
Quoted 70 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Fam Zheng
On Wed, 10 Mar 2021 at 14:24, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 3/10/21 3:17 PM, [email protected] <mailto:[email protected]> wrote:
> From: Fam Zheng <[email protected] <mailto:[email protected]>> >
> null-co:// has a read-zeroes=off default, when used to in security > analysis, this can cause false positives because the driver doesn't > write to the read buffer.
>
> null-co:// has the highest possible performance as a block driver,so
Quoted 37 lines
Quoted 2 lines
let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have
read-zeroes=on by > default, so it's more suitable in cases than null-co://. Thanks! > > Signed-off-by: Fam Zheng <[email protected] <mailto:[email protected]>> > --- > block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 91 insertions(+) > +static int zero_file_open(BlockDriverState *bs, QDict *options, int flags, > + Error **errp) > +{ > + QemuOpts *opts; > + BDRVNullState *s = bs->opaque; > + int ret = 0; > + > + opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); > + qemu_opts_absorb_qdict(opts, options, &error_abort); > + s->length = > + qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 1 << 30); Please do not use this magic default value, let's always explicit the size. s->length = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); if (s->length < 0) { error_setg(errp, "%s is invalid", BLOCK_OPT_SIZE); ret = -EINVAL; }Quoted 5 lines
Doesn't that result in a bare
-blockdev zero-co://
would have 0 byte in size?
Yes, this will display an error.
Maybe better something like:
if (s->length == 0) { error_append_hint(errp, "Usage: zero-co://,size=NUM"); error_setg(errp, "size must be specified"); ret = -EINVAL; } else if (s->length < 0) { error_setg(errp, "%s is invalid", BLOCK_OPT_SIZE); ret = -EINVAL; }Quoted 1 line
Quoted 9 lines
Quoted 2 lines
I'm copying what null-co:// does today, and it's convenient for tests. Why is a default size bad?
We learned default are almost always bad because you can not get rid of them. Also because we have reports of errors when using floppy and another one (can't remember) with null-co because of invalid size and we have to explain "the default is 1GB, you have to explicit your size".
Yeah I think that makes sense. I'll revise.
Thanks,
Fam
Quoted 116 lines · 10.03.2021 17:17, [email protected] wrote:
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)block/null.c +78
-0@@ -76,6 +76,30 @@ static void null_aio_parse_filename(const char *filename, QDict *options, } } +static void zero_co_parse_filename (const char *filename,QDict *options, +Error **errp) +{ +/* This functions only exists so that a zero-co:// filename is accepted +* with the zero-co driver. */ +if (strcmp (filename,"zero-co://" )) { +error_setg (errp,"The only allowed filename for this driver is " +"'zero-co://'" ); +return ; + } +} + +static void zero_aio_parse_filename (const char *filename,QDict *options, +Error **errp) +{ +/* This functions only exists so that a zero-aio:// filename is accepted +* with the zero-aio driver. */ +if (strcmp (filename,"zero-aio://" )) { +error_setg (errp,"The only allowed filename for this driver is " +"'zero-aio://'" ); +return ; + } +} +static int null_file_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {@@ -99,6 +123,29 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,return ret; } +static int zero_file_open (BlockDriverState *bs,QDict *options,int flags, +Error **errp) +{ +QemuOpts *opts; +BDRVNullState *s = bs->opaque; +int ret =0 ; + + opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options, &error_abort); + s->length = +qemu_opt_get_size (opts,BLOCK_OPT_SIZE ,1 <<30 ); + s->latency_ns = +qemu_opt_get_number (opts,NULL_OPT_LATENCY ,0 ); +if (s->latency_ns <0 ) { +error_setg (errp,"latency-ns is invalid" ); + ret = -EINVAL ; + } + s->read_zeroes = true; +qemu_opts_del (opts); + bs->supported_write_flags =BDRV_REQ_FUA ; +return ret; +} +static int64_t null_getlength (BlockDriverState *bs) {BDRVNullState *s = bs->opaque;@@ -316,10 +363,54 @@ static BlockDriver bdrv_null_aio = { .strong_runtime_opts = null_strong_runtime_opts, }; +static BlockDriver bdrv_zero_co = { + .format_name ="zero-co" , + .protocol_name ="zero-co" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = zero_file_open, + .bdrv_parse_filename = zero_co_parse_filename, + .bdrv_getlength = null_getlength, + .bdrv_get_allocated_file_size = null_allocated_file_size, + + .bdrv_co_preadv = null_co_preadv, + .bdrv_co_pwritev = null_co_pwritev, + .bdrv_co_flush_to_disk = null_co_flush, + .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_block_status = null_co_block_status, + + .bdrv_refresh_filename = null_refresh_filename, + .strong_runtime_opts = null_strong_runtime_opts, +}; + +static BlockDriver bdrv_zero_aio = { + .format_name ="zero-aio" , + .protocol_name ="zero-aio" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = zero_file_open, + .bdrv_parse_filename = zero_aio_parse_filename, + .bdrv_getlength = null_getlength, + .bdrv_get_allocated_file_size = null_allocated_file_size, +
block/null.c static BlockDriver bdrv_null_aio = { · line 406
Quoted 10 lines
block/null.c +10
-0+ .bdrv_aio_preadv = null_aio_preadv, + .bdrv_aio_pwritev = null_aio_pwritev, + .bdrv_aio_flush = null_aio_flush, + .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_block_status = null_co_block_status, + + .bdrv_refresh_filename = null_refresh_filename, + .strong_runtime_opts = null_strong_runtime_opts, +};
I don't think we need separate zero-aio driver. What is the actual difference?
Probably zero-co is enough, and we can call it just zero. And then, maybe add null driver (same as null-co, but without read_zeroes option) and deprecate null-co and null-aio drivers. Thus we'll get two clean well defined things: null and zero drivers..
Quoted 11 lines
block/null.c +3
-0+static void bdrv_null_init (void ) {bdrv_register (&bdrv_null_co);bdrv_register (&bdrv_null_aio); +bdrv_register (&bdrv_zero_co); +bdrv_register (&bdrv_zero_aio); }block_init (bdrv_null_init);
Signature · 2 lines
Best regards, Vladimir
Quoted 138 lines · Vladimir Sementsov-Ogievskiy
block/null.c static void null_aio_parse_filename(const char
Quoted 21 lines · 10.03.2021 17:17, [email protected] wrote:
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)block/null.c +0
-0@@ -76,6 +76,30 @@ static void null_aio_parse_filename(const char*filename, QDict *options,
block/null.c static void null_aio_parse_filename(const char *filename, QDict *options,
Quoted 7 lines
block/null.c +4
-0} } +static void zero_co_parse_filename (const char *filename,QDict *options, +Error **errp) +{ +/* This functions only exists so that a zero-co:// filename is accepted
block/null.c static void null_aio_parse_filename(const char *filename, QDict *options,
Quoted 9 lines
block/null.c +9
-0+* with the zero-co driver. */ +if (strcmp (filename,"zero-co://" )) { +error_setg (errp,"The only allowed filename for this driver is " +"'zero-co://'" ); +return ; + } +} + +static void zero_aio_parse_filename(const char *filename, QDict*options,
block/null.c static void null_aio_parse_filename(const char *filename, QDict *options,
Quoted 3 lines
block/null.c +3
-0+ Error **errp) +{ +/* This functions only exists so that a zero-aio:// filename is accepted
block/null.c static void null_aio_parse_filename(const char *filename, QDict *options,
Quoted 9 lines
block/null.c +8
-0+* with the zero-aio driver. */ +if (strcmp (filename,"zero-aio://" )) { +error_setg (errp,"The only allowed filename for this driver is " +"'zero-aio://'" ); +return ; + } +} + static int null_file_open(BlockDriverState *bs, QDict *options, intflags,
block/null.c static int null_file_open(BlockDriverState *bs,
Quoted 3 lines
block/null.c +0
-0Error **errp) {@@ -99,6 +123,29 @@ static int null_file_open(BlockDriverState *bs,QDict *options, int flags,
block/null.c static int null_file_open(BlockDriverState *bs, QDict *options, int flags,
Quoted 4 lines
block/null.c +1
-0return ret; } +static int zero_file_open(BlockDriverState *bs, QDict *options, intflags,
Quoted 60 lines
block/null.c +53
-0+ Error **errp) +{ +QemuOpts *opts; +BDRVNullState *s = bs->opaque; +int ret =0 ; + + opts =qemu_opts_create (&runtime_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options, &error_abort); + s->length = +qemu_opt_get_size (opts,BLOCK_OPT_SIZE ,1 <<30 ); + s->latency_ns = +qemu_opt_get_number (opts,NULL_OPT_LATENCY ,0 ); +if (s->latency_ns <0 ) { +error_setg (errp,"latency-ns is invalid" ); + ret = -EINVAL ; + } + s->read_zeroes = true; +qemu_opts_del (opts); + bs->supported_write_flags =BDRV_REQ_FUA ; +return ret; +} +static int64_t null_getlength (BlockDriverState *bs) {BDRVNullState *s = bs->opaque;@@ -316,10 +363,54 @@ static BlockDriver bdrv_null_aio = { .strong_runtime_opts = null_strong_runtime_opts, }; +static BlockDriver bdrv_zero_co = { + .format_name ="zero-co" , + .protocol_name ="zero-co" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = zero_file_open, + .bdrv_parse_filename = zero_co_parse_filename, + .bdrv_getlength = null_getlength, + .bdrv_get_allocated_file_size = null_allocated_file_size, + + .bdrv_co_preadv = null_co_preadv, + .bdrv_co_pwritev = null_co_pwritev, + .bdrv_co_flush_to_disk = null_co_flush, + .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_block_status = null_co_block_status, + + .bdrv_refresh_filename = null_refresh_filename, + .strong_runtime_opts = null_strong_runtime_opts, +}; + +static BlockDriver bdrv_zero_aio = { + .format_name ="zero-aio" , + .protocol_name ="zero-aio" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = zero_file_open, + .bdrv_parse_filename = zero_aio_parse_filename, + .bdrv_getlength = null_getlength, + .bdrv_get_allocated_file_size = null_allocated_file_size, +block/null.c static BlockDriver bdrv_null_aio = { · line 406
Quoted 10 lines
block/null.c +10
-0+ .bdrv_aio_preadv = null_aio_preadv, + .bdrv_aio_pwritev = null_aio_pwritev, + .bdrv_aio_flush = null_aio_flush, + .bdrv_reopen_prepare = null_reopen_prepare, + + .bdrv_co_block_status = null_co_block_status, + + .bdrv_refresh_filename = null_refresh_filename, + .strong_runtime_opts = null_strong_runtime_opts, +};I don't think we need separate zero-aio driver. What is the actual difference?
Quoted 5 lines
Probably zero-co is enough, and we can call it just zero. And then, maybe add null driver (same as null-co, but without
read_zeroesoption) and deprecate null-co and null-aio drivers. Thus we'll get two clean well defined things: null and zero drivers..
Sounds good to me, I'll just call it zero:// for this patch and leave the null convergence and deprecation business for another patch.
Fam
Quoted 19 lines
block/null.c static BlockDriver bdrv_null_aio = { · line 416
Quoted 12 lines
block/null.c +3
-0+static void bdrv_null_init (void ) {bdrv_register (&bdrv_null_co);bdrv_register (&bdrv_null_aio); +bdrv_register (&bdrv_zero_co); +bdrv_register (&bdrv_zero_aio); }block_init (bdrv_null_init);--
Best regards,
Vladimir
Quoted 11 lines · On 10.03.21 15:17, [email protected] wrote:
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Quoted 4 lines
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
You’ll also need to make all tests that currently use null-{co,aio} use zero-{co,aio}, because none of those are performance tests (as far as I’m aware), so they all want a block driver that memset()s.
(And that’s basically my problem with this approach; nearly everyone who uses null-* right now probably wants read-zeroes=on, so keeping null-* as it is means all of those users should be changed. Sure, they were all wrong to not specify read-zeroes=on, but that’s how it is. So while technically this patch is a compatible change, in contrast to the one making read-zeroes=on the default, in practice it absolutely isn’t.)
Another problem arising from that is I can imagine that some distributions might have whitelisted null-co because many iotests implicitly depend on it, so the iotests will fail if they aren’t whitelisted. Now they’d need to whitelist zero-co, too. Not impossible, sure, but it’s work that would need to be done.
My problem is this: We have a not-really problem, namely “valgrind and other tools complain”. Philippe (and I guess me on IRC) proposed a simple solution whose only drawbacks (AFAIU) are:
(1) When writing performance tests, you’ll then need to explicitly specify read-zeroes=off. Existing performance tests using null-co will probably wrongly show degredation. (Are there such tests, though?)
(2) null will not quite conform to its name, strictly speaking. Frankly, I don’t know who’d care other than people who write those performance tests mentioned in (1). I know I don’t care.
(Technically: (3) We should look into all qemu tests that use null-co to see whether they test performance. In practice, they don’t, so we don’t need to.)
So AFAIU change the read-zeroes default would affect very few people, if any. I see you care about (2), and you’re the maintainer, so I can’t say that there is no problem. But it isn’t a practical one.
So on the practical front, we get a small benefit (tools won’t complain) for a small drawback (having to remember read-zeroes=off for performance tests).
Now you propose a change that has the following drawbacks, as I see it:
(1) All non-performance tests using null-* should be changed to zero-*. And those are quite a few tests, so this is some work.
(2) Distributions that have whitelisted null-co now should whitelist zero-co, too.
Not impossible, but I consider these much bigger practical drawbacks than making read-zeroes=on the default. It’s actual work that must be done. To me personally, these drawbacks far outweigh the benefit of having valgrind and other tools not complain.
I can’t stop you from updating this patch to do (1), but it doesn’t make sense to me from a practical perspective. It just doesn’t seem worth it to me.
Max
Quoted 74 lines · Max Reitz
Quoted 11 lines · On 10.03.21 15:17, [email protected] wrote:
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Quoted 4 lines
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)You’ll also need to make all tests that currently use null-{co,aio} use zero-{co,aio}, because none of those are performance tests (as far as I’m aware), so they all want a block driver that memset()s.
(And that’s basically my problem with this approach; nearly everyone who uses null-* right now probably wants read-zeroes=on, so keeping null-* as it is means all of those users should be changed. Sure, they were all wrong to not specify read-zeroes=on, but that’s how it is. So while technically this patch is a compatible change, in contrast to the one making read-zeroes=on the default, in practice it absolutely isn’t.)
Another problem arising from that is I can imagine that some distributions might have whitelisted null-co because many iotests implicitly depend on it, so the iotests will fail if they aren’t whitelisted. Now they’d need to whitelist zero-co, too. Not impossible, sure, but it’s work that would need to be done.
My problem is this: We have a not-really problem, namely “valgrind and other tools complain”. Philippe (and I guess me on IRC) proposed a simple solution whose only drawbacks (AFAIU) are:
(1) When writing performance tests, you’ll then need to explicitly specify read-zeroes=off. Existing performance tests using null-co will probably wrongly show degredation. (Are there such tests, though?)
(2) null will not quite conform to its name, strictly speaking. Frankly, I don’t know who’d care other than people who write those performance tests mentioned in (1). I know I don’t care.
(Technically: (3) We should look into all qemu tests that use null-co to see whether they test performance. In practice, they don’t, so we don’t need to.)
So AFAIU change the read-zeroes default would affect very few people, if any. I see you care about (2), and you’re the maintainer, so I can’t say that there is no problem. But it isn’t a practical one.
So on the practical front, we get a small benefit (tools won’t complain) for a small drawback (having to remember read-zeroes=off for performance tests).
Now you propose a change that has the following drawbacks, as I see it:
(1) All non-performance tests using null-* should be changed to zero-*. And those are quite a few tests, so this is some work.
(2) Distributions that have whitelisted null-co now should whitelist zero-co, too.
Not impossible, but I consider these much bigger practical drawbacks than making read-zeroes=on the default. It’s actual work that must be done. To me personally, these drawbacks far outweigh the benefit of having valgrind and other tools not complain.
Quoted 4 lines
I can’t stop you from updating this patch to do (1), but it doesn’t make sense to me from a practical perspective. It just doesn’t seem worth it to me.
But using null-co:// in tests is not wrong, the problem is the caller failed to initialize its buffer. IMO the valgrind issue should really be fixed like this:
hw/block/hd-geometry.c +0 -0
@@ -55,7 +55,7 @@ struct partition {
static int guess_disk_lchs(BlockBackend *blk,
int *pcylinders, int *pheads, int *psectors)
{
- uint8_t buf[BDRV_SECTOR_SIZE];
+ uint8_t buf[BDRV_SECTOR_SIZE] = {};
int i, heads, sectors, cylinders;
struct partition *p;
uint32_t nr_sects;Quoted 87 lines · Fam Zheng
On Wed, 10 Mar 2021 at 15:02, Max Reitz <[email protected] <mailto:[email protected]>> wrote:
On 10.03.21 15:17, [email protected] <mailto:[email protected]> wrote:
> From: Fam Zheng <[email protected] <mailto:[email protected]>> >
> null-co:// has a read-zeroes=off default, when used to in security > analysis, this can cause false positives because the driver doesn't > write to the read buffer.
>
> null-co:// has the highest possible performance as a block driver, so > let's keep it that way. This patch introduces zero-co:// and > zero-aio://, largely similar with null-*://, but have
read-zeroes=on by
> default, so it's more suitable in cases than null-co://. >
> Signed-off-by: Fam Zheng <[email protected] <mailto:[email protected]>> > ---
> block/null.c | 91
++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 91 insertions(+)You’ll also need to make all tests that currently use null-{co,aio} use zero-{co,aio}, because none of those are performance tests (as far as I’m aware), so they all want a block driver that memset()s.
(And that’s basically my problem with this approach; nearly everyone who
uses null-* right now probably wants read-zeroes=on, so keeping null-* as it is means all of those users should be changed. Sure, they were all wrong to not specify read-zeroes=on, but that’s how it is. So while
technically this patch is a compatible change, in contrast to the one making read-zeroes=on the default, in practice it absolutely isn’t.)Another problem arising from that is I can imagine that some distributions might have whitelisted null-co because many iotests implicitly depend on it, so the iotests will fail if they aren’t whitelisted. Now they’d need to whitelist zero-co, too. Not impossible, sure, but it’s work that would need to be done.
My problem is this: We have a not-really problem, namely “valgrind and other tools complain”. Philippe (and I guess me on IRC) proposed a simple solution whose only drawbacks (AFAIU) are:
(1) When writing performance tests, you’ll then need to explicitly specify read-zeroes=off. Existing performance tests using null-co will probably wrongly show degredation. (Are there such tests, though?)
(2) null will not quite conform to its name, strictly speaking. Frankly, I don’t know who’d care other than people who write those performance tests mentioned in (1). I know I don’t care.
(Technically: (3) We should look into all qemu tests that use null-co to
see whether they test performance. In practice, they don’t, so we don’t
need to.)So AFAIU change the read-zeroes default would affect very few people, if
any. I see you care about (2), and you’re the maintainer, so I can’t say that there is no problem. But it isn’t a practical one.So on the practical front, we get a small benefit (tools won’t complain)
for a small drawback (having to remember read-zeroes=off for performance
tests).Now you propose a change that has the following drawbacks, as I see it:
(1) All non-performance tests using null-* should be changed to zero-*. And those are quite a few tests, so this is some work.
(2) Distributions that have whitelisted null-co now should whitelist zero-co, too.
Not impossible, but I consider these much bigger practical drawbacks than making read-zeroes=on the default. It’s actual work that must be done. To me personally, these drawbacks far outweigh the benefit of having valgrind and other tools not complain.
Quoted 8 lines
I can’t stop you from updating this patch to do (1), but it doesn’t make
sense to me from a practical perspective. It just doesn’t seem worth it
to me.But using null-co:// in tests is not wrong, the problem is the caller failed to initialize its buffer.
Then I don’t see why we’d need zero-co://.
Max
Am 10.03.2021 um 15:17 hat [email protected] geschrieben:
Quoted 6 lines
From: Fam Zheng <[email protected]>
null-co:// has a read-zeroes=off default, when used to in security analysis, this can cause false positives because the driver doesn't write to the read buffer.
Quoted 8 lines
null-co:// has the highest possible performance as a block driver, so let's keep it that way. This patch introduces zero-co:// and zero-aio://, largely similar with null-*://, but have read-zeroes=on by default, so it's more suitable in cases than null-co://.
Signed-off-by Fam Zheng <[email protected]>--- block/null.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++
If we're adding new block drivers, there should certainly be some QAPI schema updates here.
Kevin