Misc QEMU 7.1 fixes for 2002-08-08
The following changes since commit 3916603e0c1d909e14e09d5ebcbdaa9c9e21adf3:
Merge tag 'pull-la-20220729' of https://gitlab.com/rth7680/qemu into staging (2022-07-29 17:39:17 -0700)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to f6a5f380627ab2af384bf2f2940d29386dea11ff:
tests/qtest: add scenario for -readconfig handling (2022-08-08 14:54:56 +0200)
----------------------------------------------------------------
* Fix and tests for -readconfig
* Fixes for changeable block size
----------------------------------------------------------------
Daniel P. Berrangé (1):
tests/qtest: add scenario for -readconfig handling
Mark Cave-Ayland (2):
scsi-disk: fix overflow when block size is not a multiple of BDRV_SECTOR_SIZE
scsi-disk: ensure block size is non-zero and changes limited to bits 8-15
Paolo Bonzini (2):
vl: fix [memory] section with -readconfig
vl: remove dead code in parse_memory_options()
hw/scsi/scsi-disk.c | 25 ++++-- softmmu/vl.c | 32 ++++--- tests/qtest/meson.build | 1 + tests/qtest/readconfig-test.c | 195 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 24 deletions(-) create mode 100644 tests/qtest/readconfig-test.c
Signature · 1 line
2.37.1
[PULL 1/5] scsi-disk: fix overflow when block size is not a multiple of BDRV_SECTOR_SIZE
From: Mark Cave-Ayland <[email protected]>
In scsi_disk_emulate_write_same() the number of host sectors to transfer is calculated as (s->qdev.blocksize / BDRV_SECTOR_SIZE) which is then used to copy data in block size chunks to the iov buffer.
Since the loop copying the data to the iov buffer uses a fixed increment of s->qdev.blocksize then using a block size that isn't a multiple of BDRV_SECTOR_SIZE introduces a rounding error in the iov buffer size calculation such that the iov buffer copy overflows the space allocated.
Update the iov buffer copy for() loop so that it will use the smallest of either the current block size or the remaining transfer count to prevent the overflow.
Message-Id: <[email protected]>
--- hw/scsi/scsi-disk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/scsi/scsi-disk.c +4 -3
@@ -1849,7 +1849,7 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)uint32_t nb_sectors =scsi_data_cdb_xfer (r->req.cmd.buf);WriteSameCBData *data;uint8_t *buf; -int i; +int i, l;/* Fail if PBDATA=1 or LBDATA=1 or ANCHOR=1. */ if (nb_sectors ==0 || (req->cmd.buf[1 ] &0x16 )) {
@@ -1891,8 +1891,9 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf) data->iov.iov_len);qemu_iovec_init_external (&data->qiov, &data->iov,1 ); -for (i =0 ; i < data->iov.iov_len; i += s->qdev.blocksize) { -memcpy (&buf[i], inbuf, s->qdev.blocksize); +for (i =0 ; i < data->iov.iov_len; i += l) { + l =MIN (s->qdev.blocksize, data->iov.iov_len - i); +memcpy (&buf[i], inbuf, l); }scsi_req_ref (&r->req);
Signature · 1 line
2.37.1
[PULL 2/5] scsi-disk: ensure block size is non-zero and changes limited to bits 8-15
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
The existing code assumes that the block size can be generated from p[1] << 8 in multiple places which ignores the top and bottom 8 bits. If the block size is allowed to be set to an arbitrary value then this causes a mismatch between the value written by the guest in the block descriptor and the value subsequently read back using READ CAPACITY causing the guest to generate requests that can crash QEMU.
For now restrict block size changes to bits 8-15 and also ignore requests to set the block size to 0 which causes the SCSI emulation to crash in at least one place with a divide by zero error.
Message-Id: <[email protected]>
--- hw/scsi/scsi-disk.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
hw/scsi/scsi-disk.c +14 -4
@@ -1591,7 +1591,7 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, uint8_t *inbuf)int cmd = r->req.cmd.buf[0 ];int len = r->req.cmd.xfer;int hdr_len = (cmd ==MODE_SELECT ?4 :8 ); -int bd_len; +int bd_len, bs;int pass;if ((r->req.cmd.buf[1 ] &0x11 ) !=0x10 ) {
@@ -1617,9 +1617,19 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, uint8_t *inbuf) }/* Allow changing the block size */ -if (bd_len && p[6 ] != (s->qdev.blocksize >>8 )) { - s->qdev.blocksize = p[6 ] <<8 ; -trace_scsi_disk_mode_select_set_blocksize (s->qdev.blocksize); +if (bd_len) { + bs = p[5 ] <<16 | p[6 ] <<8 | p[7 ]; + +/* +* Since the existing code only checks/updates bits 8-15 of the block +* size, restrict ourselves to the same requirement for now to ensure +* that a block size set by a block descriptor and then read back by +* a subsequent SCSI command will be the same +*/ +if (bs && !(bs & ~0xff00 ) && bs != s->qdev.blocksize) { + s->qdev.blocksize = bs; +trace_scsi_disk_mode_select_set_blocksize (s->qdev.blocksize); + } } len -= bd_len;
Signature · 1 line
2.37.1
[PULL 3/5] vl: fix [memory] section with -readconfig
In reply to Paolo BonziniThe -M memory.* options do not have magic applied to them like the -m option, namely no "M" (for mebibytes) is tacked at the end of a suffixless value for "-M memory.size".
This magic is performed by parse_memory_options, and we have to do it for both "-m" and the [memory] section of a config file. Storing [memory] sections directly to machine_opts_dict changed the meaning of
[memory]
size = "1024"in a -readconfig file from 1024MiB to 8KiB (1024 Bytes rounded up to 8KiB silently). To avoid this, the [memory] section has to be changed back to QemuOpts (combining [memory] and "-m" will work fine thanks to .merge_lists being true).
Change parse_memory_options() so that, similar to the older function set_memory_options(), it operates after command line parsing is done; and also call it where set_memory_options() used to be.
Note, the parsing code uses exit(1) instead of exit(EXIT_FAILURE) to match neighboring code.
--- softmmu/vl.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
softmmu/vl.c +14 -11
@@ -1947,16 +1947,15 @@ static void qemu_resolve_machine_memdev(void) } } -static void parse_memory_options (const char *arg) +static void parse_memory_options (void ) { -QemuOpts *opts; +QemuOpts *opts =qemu_find_opts_singleton ("memory" );QDict *dict, *prop;const char *mem_str; +Location loc; - opts =qemu_opts_parse_noisily (qemu_find_opts ("memory" ), arg, true); -if (!opts) { -exit (EXIT_FAILURE ); - } +loc_push_none (&loc); +qemu_opts_loc_restore (opts); prop =qdict_new ();
@@ -1987,6 +1986,7 @@ static void parse_memory_options(const char *arg)qdict_put (dict,"memory" , prop);keyval_merge (machine_opts_dict, dict, &error_fatal);qobject_unref (dict); +loc_pop (&loc); }static void qemu_create_machine (QDict *qdict)
@@ -2053,8 +2053,7 @@ static bool is_qemuopts_group(const char *group)if (g_str_equal (group,"object" ) ||g_str_equal (group,"machine" ) ||g_str_equal (group,"smp-opts" ) || -g_str_equal (group,"boot-opts" ) || -g_str_equal (group,"memory" )) { +g_str_equal (group,"boot-opts" )) {return false; }return true;
@@ -2078,8 +2077,6 @@ static void qemu_record_config_group(const char *group, QDict *dict,machine_merge_property ("smp" , dict, &error_fatal); }else if (g_str_equal (group,"boot-opts" )) {machine_merge_property ("boot" , dict, &error_fatal); - }else if (g_str_equal (group,"memory" )) { -machine_merge_property ("memory" , dict, &error_fatal); }else {abort (); }
@@ -2882,7 +2879,10 @@ void qemu_init(int argc, char **argv, char **envp)exit (0 );break ;case QEMU_OPTION_m: -parse_memory_options (optarg); + opts =qemu_opts_parse_noisily (qemu_find_opts ("memory" ), optarg, true); +if (opts ==NULL ) { +exit (1 ); + }break ;#ifdef CONFIG_TPM case QEMU_OPTION_tpmdev:
@@ -3515,6 +3515,9 @@ void qemu_init(int argc, char **argv, char **envp)configure_rtc (qemu_find_opts_singleton ("rtc" )); +/* Transfer QemuOpts options into machine options */ +parse_memory_options (); +qemu_create_machine (machine_opts_dict);suspend_mux_open ();
Signature · 1 line
2.37.1
[PULL 5/5] tests/qtest: add scenario for -readconfig handling
In reply to Paolo BonziniFrom: Daniel P. Berrangé <[email protected]>
This test of -readconfig validates the last three regressions we have fixed with -readconfig:
* Interpretation of memory size units as MiB not bytes
* Allow use of [spice]
* Allow use of [object]
Message-Id: <[email protected]>
--- tests/qtest/meson.build | 1 + tests/qtest/readconfig-test.c | 195 ++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 tests/qtest/readconfig-test.c
tests/qtest/meson.build +1 -0
@@ -26,6 +26,7 @@ qtests_generic = [ 'qom-test', 'test-hmp', 'qos-test', + 'readconfig-test', ] if config_host.has_key('CONFIG_MODULES') qtests_generic += [ 'modules-test' ]
tests/qtest/readconfig-test.c new file +195 -0
195 lines not on this page · raw message
Signature · 1 line
2.37.1
[PULL 4/5] vl: remove dead code in parse_memory_options()
In reply to Paolo Bonzinimem_str will never be an empty string, because qemu_opt_get_size() fails if it encounters one:
$ ./qemu-system-x86_64 -m size= qemu-system-x86_64: -m size=: Parameter size expects a non-negative number below 2^64 Optional suffix k, M, G, T, P or E means kilo-, mega-, giga-, tera-, peta- and exabytes, respectively.
--- softmmu/vl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
softmmu/vl.c +1 -6
@@ -1960,13 +1960,8 @@ static void parse_memory_options(void) prop =qdict_new ();if (qemu_opt_get_size (opts,"size" ,0 ) !=0 ) { - mem_str =qemu_opt_get (opts,"size" ); -if (!*mem_str) { -error_report ("missing 'size' option value" ); -exit (EXIT_FAILURE ); - } -/* Fix up legacy suffix-less format */ + mem_str =qemu_opt_get (opts,"size" );if (g_ascii_isdigit (mem_str[strlen (mem_str) -1 ])) { g_autofree char *mib_str = g_strdup_printf("%sM", mem_str);qdict_put_str (prop,"size" , mib_str);
Signature · 1 line
2.37.1
Quoted 12 lines · Paolo Bonzini
The following changes since commit
3916603e0c1d909e14e09d5ebcbdaa9c9e21adf3:Merge tag 'pull-la-20220729' of https://gitlab.com/rth7680/qemu into staging (2022-07-29 17:39:17 -0700)are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to
f6a5f380627ab2af384bf2f2940d29386dea11ff:tests/qtest: add scenario for -readconfig handling (2022-08-08 14:54:56 +0200)
Quoted 7 lines
----------------------------------------------------------------
* Fix and tests for -readconfig
* Fixes for changeable block size----------------------------------------------------------------
Daniel P. Berrangé (1):
tests/qtest: add scenario for -readconfig handling
I still had some questions wrt to Daniel's patch, especially there seems to be a bug ("spcie" instead of "spice"), see:
https://lists.gnu.org/archive/html/qemu-devel/2022-08/msg01153.html
I doubt that this test is working if spice is enabled...
(which leads us to the next question: if the CI did not fail for you, are we missing a build with spice enabled there?)
Thomas
Quoted 21 lines · Thomas Huth
Quoted 12 lines · Paolo Bonzini
The following changes since commit
3916603e0c1d909e14e09d5ebcbdaa9c9e21adf3:Merge tag 'pull-la-20220729' of https://gitlab.com/rth7680/qemu into staging (2022-07-29 17:39:17 -0700)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to
f6a5f380627ab2af384bf2f2940d29386dea11ff:tests/qtest: add scenario for -readconfig handling (2022-08-08 14:54:56 +0200)
Quoted 7 lines
----------------------------------------------------------------
* Fix and tests for -readconfig
* Fixes for changeable block size----------------------------------------------------------------
Daniel P. Berrangé (1):
tests/qtest: add scenario for -readconfig handling
Quoted 6 lines
I still had some questions wrt to Daniel's patch, especially there seems to be a bug ("spcie" instead of "spice"), see:
https://lists.gnu.org/archive/html/qemu-devel/2022-08/msg01153.html
I doubt that this test is working if spice is enabled...
(which leads us to the next question: if the CI did not fail for you, are we missing a build with spice enabled there?)
Arg. I didn't notice this until after I'd done the push to master.
I see from Daniel's reply that the string with the typo doesn't seem to be used, but please do let's fix this asap.
r~
Quoted 7 lines · Thomas Huth
I still had some questions wrt to Daniel's patch, especially there seems to be a bug ("spcie" instead of "spice"), see:
https://lists.gnu.org/archive/html/qemu-devel/2022-08/msg01153.html
I doubt that this test is working if spice is enabled...
(which leads us to the next question: if the CI did not fail for you, are we missing a build with spice enabled there?)
Fortunately the typo is not an issue; the top item of the visit does not have a key and therefore the name passed to the toplevel visit_type_* call is not used.
Paolo
Richard Henderson
AppliedQuoted 8 lines · Paolo Bonzini
The following changes since commit
3916603e0c1d909e14e09d5ebcbdaa9c9e21adf3:Merge tag 'pull-la-20220729' of https://gitlab.com/rth7680/qemu into staging (2022-07-29 17:39:17 -0700)are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
Quoted 7 lines
for you to fetch changes up to
f6a5f380627ab2af384bf2f2940d29386dea11ff:tests/qtest: add scenario for -readconfig handling (2022-08-08 14:54:56 +0200)----------------------------------------------------------------
* Fix and tests for -readconfig
* Fixes for changeable block size
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.
r~
Quoted 19 lines
----------------------------------------------------------------
Daniel P. Berrangé (1):
tests/qtest: add scenario for -readconfig handlingMark Cave-Ayland (2):
scsi-disk: fix overflow when block size is not a multiple ofBDRV_SECTOR_SIZE
scsi-disk: ensure block size is non-zero and changes limited to bits 8-15Paolo Bonzini (2):
vl: fix [memory] section with -readconfig
vl: remove dead code inparse_memory_options()hw/scsi/scsi-disk.c | 25 ++++-- softmmu/vl.c | 32 ++++--- tests/qtest/meson.build | 1 + tests/qtest/readconfig-test.c | 195 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 24 deletions(-)create mode 100644
tests/qtest/readconfig-test.c