Patch Round-up for stable 2.0.1, freeze on 2014-08-12
Subsystems (2)
PATCH 1/108 hw/net/stellaris_enet: Restructure tx_fifo code to avoid buffer overrun
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The current tx_fifo code has a corner case where the guest can overrun the fifo buffer: if automatic CRCs are disabled we allow the guest to write the CRC word even if there isn't actually space for it in the FIFO. The datasheet is unclear about exactly how the hardware deals with this situation; the most plausible answer seems to be that the CRC word is just lost.
Implement this fix by separating the "can we stuff another word in the FIFO" logic from the "should we transmit the packet now" check. This also moves us closer to the real hardware, which has a number of ways it can be configured to trigger sending the packet, some of which we don't implement.
--- hw/net/stellaris_enet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
hw/net/stellaris_enet.c +6 -4
@@ -253,10 +253,12 @@ static void stellaris_enet_write(void *opaque, hwaddr offset, s->tx_fifo[s->tx_fifo_len++] = value >>24 ; } }else { - s->tx_fifo[s->tx_fifo_len++] = value; - s->tx_fifo[s->tx_fifo_len++] = value >>8 ; - s->tx_fifo[s->tx_fifo_len++] = value >>16 ; - s->tx_fifo[s->tx_fifo_len++] = value >>24 ; +if (s->tx_fifo_len +4 <=ARRAY_SIZE (s->tx_fifo)) { + s->tx_fifo[s->tx_fifo_len++] = value; + s->tx_fifo[s->tx_fifo_len++] = value >>8 ; + s->tx_fifo[s->tx_fifo_len++] = value >>16 ; + s->tx_fifo[s->tx_fifo_len++] = value >>24 ; + }if (s->tx_fifo_len >= s->tx_frame_len) {/* We don't implement explicit CRC, so just chop it off. */ if ((s->tctl &SE_TCTL_CRC ) ==0 )
Signature · 1 line
1.9.1
PATCH 3/108 vmstate: reduce code duplication
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
move size offset and number of elements math out
to functions, to reduce code duplication.
--- vmstate.c | 100 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 52 insertions(+), 48 deletions(-)
vmstate.c +52 -48
@@ -10,6 +10,50 @@ static void vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd,void *opaque); +static int vmstate_n_elems (void *opaque,VMStateField *field) +{ +int n_elems =1 ; + +if (field->flags &VMS_ARRAY ) { + n_elems = field->num; + }else if (field->flags &VMS_VARRAY_INT32 ) { + n_elems = *(int32_t *)(opaque+field->num_offset); + }else if (field->flags &VMS_VARRAY_UINT32 ) { + n_elems = *(uint32_t *)(opaque+field->num_offset); + }else if (field->flags &VMS_VARRAY_UINT16 ) { + n_elems = *(uint16_t *)(opaque+field->num_offset); + }else if (field->flags &VMS_VARRAY_UINT8 ) { + n_elems = *(uint8_t *)(opaque+field->num_offset); + } + +return n_elems; +} + +static int vmstate_size (void *opaque,VMStateField *field) +{ +int size = field->size; + +if (field->flags &VMS_VBUFFER ) { + size = *(int32_t *)(opaque+field->size_offset); +if (field->flags &VMS_MULTIPLY ) { + size *= field->size; + } + } + +return size; +} + +static void *vmstate_base_addr (void *opaque,VMStateField *field) +{ +void *base_addr = opaque + field->offset; + +if (field->flags &VMS_POINTER ) { + base_addr = *(void **)base_addr + field->start; + } + +return base_addr; +} +int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,int version_id) {
@@ -36,30 +80,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, field->field_exists(opaque, version_id)) || (!field->field_exists && field->version_id <= version_id)) { - void *base_addr = opaque + field->offset; -int i, n_elems =1 ; -int size = field->size; - -if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } - } -if (field->flags &VMS_ARRAY ) { - n_elems = field->num; - }else if (field->flags &VMS_VARRAY_INT32 ) { - n_elems = *(int32_t *)(opaque+field->num_offset); - }else if (field->flags &VMS_VARRAY_UINT32 ) { - n_elems = *(uint32_t *)(opaque+field->num_offset); - }else if (field->flags &VMS_VARRAY_UINT16 ) { - n_elems = *(uint16_t *)(opaque+field->num_offset); - }else if (field->flags &VMS_VARRAY_UINT8 ) { - n_elems = *(uint8_t *)(opaque+field->num_offset); - } -if (field->flags &VMS_POINTER ) { - base_addr = *(void **)base_addr + field->start; - } + void *base_addr = vmstate_base_addr(opaque, field); +int i, n_elems =vmstate_n_elems (opaque, field); +int size =vmstate_size (opaque, field); +for (i =0 ; i < n_elems; i++) {void *addr = base_addr + size * i;
@@ -102,30 +126,10 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,while (field->name) {if (!field->field_exists || field->field_exists (opaque, vmsd->version_id)) { -void *base_addr = opaque + field->offset; -int i, n_elems =1 ; -int size = field->size; - -if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } - } -if (field->flags &VMS_ARRAY ) { - n_elems = field->num; - }else if (field->flags &VMS_VARRAY_INT32 ) { - n_elems = *(int32_t *)(opaque+field->num_offset); - }else if (field->flags &VMS_VARRAY_UINT32 ) { - n_elems = *(uint32_t *)(opaque+field->num_offset); - }else if (field->flags &VMS_VARRAY_UINT16 ) { - n_elems = *(uint16_t *)(opaque+field->num_offset); - }else if (field->flags &VMS_VARRAY_UINT8 ) { - n_elems = *(uint8_t *)(opaque+field->num_offset); - } -if (field->flags &VMS_POINTER ) { - base_addr = *(void **)base_addr + field->start; - } +void *base_addr =vmstate_base_addr (opaque, field); +int i, n_elems =vmstate_n_elems (opaque, field); +int size =vmstate_size (opaque, field); +for (i =0 ; i < n_elems; i++) {void *addr = base_addr + size * i;
Signature · 1 line
1.9.1
PATCH 2/108 hw/net/stellaris_enet: Correct handling of packet padding
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The PADEN bit in the transmit control register enables padding of short data packets out to the required minimum length. However a typo here meant we were adjusting tx_fifo_len rather than tx_frame_len, so the padding didn't actually happen. Fix this bug.
--- hw/net/stellaris_enet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/stellaris_enet.c +1 -1
@@ -265,7 +265,7 @@ static void stellaris_enet_write(void *opaque, hwaddr offset, s->tx_frame_len -=4 ;if ((s->tctl &SE_TCTL_PADEN ) && s->tx_frame_len <60 ) {memset (&s->tx_fifo[s->tx_frame_len],0 ,60 - s->tx_frame_len); - s->tx_fifo_len =60 ; + s->tx_frame_len =60 ; }qemu_send_packet (qemu_get_queue (s->nic), s->tx_fifo, s->tx_frame_len);
Signature · 1 line
1.9.1
PATCH 4/108 vmstate: add VMS_MUST_EXIST
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
Can be used to verify a required field exists or validate state in some other way.
--- include/migration/vmstate.h | 1 + vmstate.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
include/migration/vmstate.h +1 -0
@@ -100,6 +100,7 @@ enum VMStateFlags {VMS_MULTIPLY =0x200 ,/* multiply "size" field by field_size */ VMS_VARRAY_UINT8 =0x400 ,/* Array with size in uint8_t field*/ VMS_VARRAY_UINT32 =0x800 ,/* Array with size in uint32_t field*/ + VMS_MUST_EXIST = 0x1000, /* Field must exist in input */ }; typedef struct {
vmstate.c +10 -0
@@ -102,6 +102,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,return ret; } } + }else if (field->flags &VMS_MUST_EXIST ) { +fprintf (stderr,"Input validation failed: %s/%s\n" , + vmsd->name, field->name); +return -1 ; } field++; }
@@ -142,6 +146,12 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, field->info->put (f, addr, size); } } + }else { +if (field->flags &VMS_MUST_EXIST ) { +fprintf (stderr,"Output state validation failed: %s/%s\n" , + vmsd->name, field->name); +assert (!(field->flags &VMS_MUST_EXIST )); + } } field++; }
Signature · 1 line
1.9.1
PATCH 5/108 vmstate: add VMSTATE_VALIDATE
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
Validate state using VMS_ARRAY with num = 0 and VMS_MUST_EXIST
--- include/migration/vmstate.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/migration/vmstate.h +8 -0
@@ -204,6 +204,14 @@ extern const VMStateInfo vmstate_info_bitmap; .offset = vmstate_offset_value(_state, _field, _type), \ } +/* Validate state using a boolean predicate. */ +#define VMSTATE_VALIDATE (_name, _test) { \ + .name = (_name), \ + .field_exists = (_test), \ + .flags = VMS_ARRAY | VMS_MUST_EXIST, \ + .num = 0,/* 0 elements: no data, only run _test */ \ +} +#define VMSTATE_POINTER (_field, _state, _version, _info, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \
Signature · 1 line
1.9.1
PATCH 8/108 virtio-net: out-of-bounds buffer write on load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4149 QEMU 1.3.0 out-of-bounds buffer write in virtio_net_load()@hw/net/virtio-net.c
Quoted 2 lines
} else if (n->mac_table.in_use) {
uint8_t *buf = g_malloc0(n->mac_table.in_use);We are allocating buffer of size n->mac_table.in_use
Quoted 1 line
qemu_get_buffer(f, buf, n->mac_table.in_use * ETH_ALEN);
and read to the n->mac_table.in_use size buffer n->mac_table.in_use * ETH_ALEN bytes, corrupting memory.
If adversary controls state then memory written there is controlled by adversary.
--- hw/net/virtio-net.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +11 -4
@@ -1362,10 +1362,17 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)if (n->mac_table.in_use <=MAC_TABLE_ENTRIES ) {qemu_get_buffer (f, n->mac_table.macs, n->mac_table.in_use *ETH_ALEN ); - }else if (n->mac_table.in_use) { -uint8_t *buf =g_malloc0 (n->mac_table.in_use); -qemu_get_buffer (f, buf, n->mac_table.in_use *ETH_ALEN ); -g_free (buf); + }else { +int64_t i; + +/* Overflow detected - can happen if source has a larger MAC table. +* We simply set overflow flag so there's no need to maintain the +* table of addresses, discard them all. +* Note: 64 bit math to avoid integer overflow. +*/ +for (i =0 ; i < (int64_t )n->mac_table.in_use *ETH_ALEN ; ++i) { +qemu_get_byte (f); + } n->mac_table.multi_overflow = n->mac_table.uni_overflow =1 ; n->mac_table.in_use =0 ; }
Signature · 1 line
1.9.1
PATCH 6/108 virtio-net: fix buffer overflow on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4148 QEMU 1.0 integer conversion in
virtio_net_load()@hw/net/virtio-net.c
Deals with loading a corrupted savevm image.
Quoted 1 line
n->mac_table.in_use = qemu_get_be32(f);
in_use is int so it can get negative when assigned 32bit unsigned value.
Quoted 2 lines
/* MAC_TABLE_ENTRIES may be different from the saved image */
if (n->mac_table.in_use <= MAC_TABLE_ENTRIES) {passing this check ^^^
Quoted 2 lines
qemu_get_buffer(f, n->mac_table.macs,
n->mac_table.in_use * ETH_ALEN);with good in_use value, "n->mac_table.in_use * ETH_ALEN" can get positive and bigger than mac_table.macs. For example 0x81000000 satisfies this condition when ETH_ALEN is 6.
Fix it by making the value unsigned.
For consistency, change first_multi as well.
Note: all call sites were audited to confirm that
making them unsigned didn't cause any issues:
it turns out we actually never do math on them,
so it's easy to validate because both values are
always <= MAC_TABLE_ENTRIES.
--- include/hw/virtio/virtio-net.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/hw/virtio/virtio-net.h +2 -2
@@ -176,8 +176,8 @@ typedef struct VirtIONet {uint8_t nobcast;uint8_t vhost_started;struct { -int in_use; -int first_multi; +uint32_t in_use; +uint32_t first_multi;uint8_t multi_overflow;uint8_t uni_overflow;uint8_t *macs;
Signature · 1 line
1.9.1
PATCH 9/108 ahci: fix buffer overrun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4526
Within hw/ide/ahci.c, VARRAY refers to ports which is also loaded. So we use the old version of ports to read the array but then allow any value for ports. This can cause the code to overflow.
There's no reason to migrate ports - it never changes. So just make sure it matches.
--- hw/ide/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/ahci.c +1 -1
@@ -1293,7 +1293,7 @@ const VMStateDescription vmstate_ahci = { VMSTATE_UINT32(control_regs.impl, AHCIState), VMSTATE_UINT32(control_regs.version, AHCIState), VMSTATE_UINT32(idp_index, AHCIState), - VMSTATE_INT32(ports, AHCIState), + VMSTATE_INT32_EQUAL(ports, AHCIState),VMSTATE_END_OF_LIST () }, };
Signature · 1 line
1.9.1
PATCH 7/108 virtio-net: out-of-bounds buffer write on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4150 QEMU 1.5.0 out-of-bounds buffer write in virtio_net_load()@hw/net/virtio-net.c
This code is in hw/net/virtio-net.c:
if (n->max_queues > 1) {
if (n->max_queues != qemu_get_be16(f)) {
error_report("virtio-net: different max_queues ");
return -1;
}
n->curr_queues = qemu_get_be16(f);
for (i = 1; i < n->curr_queues; i++) {
n->vqs[i].tx_waiting = qemu_get_be32(f);
}
}Number of vqs is max_queues, so if we get invalid input here, for example if max_queues = 2, curr_queues = 3, we get write beyond end of the buffer, with data that comes from wire.
This might be used to corrupt qemu memory in hard to predict ways. Since we have lots of function pointers around, RCE might be possible.
--- hw/net/virtio-net.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/net/virtio-net.c +5 -0
@@ -1407,6 +1407,11 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) } n->curr_queues =qemu_get_be16 (f); +if (n->curr_queues > n->max_queues) { +error_report ("virtio-net: curr_queues %x > max_queues %x" , + n->curr_queues, n->max_queues); +return -1 ; + }for (i =1 ; i < n->curr_queues; i++) { n->vqs[i].tx_waiting =qemu_get_be32 (f); }
Signature · 1 line
1.9.1
PATCH 11/108 hw/pci/pcie_aer.c: fix buffer overruns on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
4) CVE-2013-4529hw/pci/pcie_aer.c pcie aer log can overrun the buffer if log_num is
too large
There are two issues in this file:
1. log_max from remote can be larger than on local then buffer will overrun with data coming from state file.
2. log_num can be larger then we get data corruption again with an overflow but not adversary controlled.
Fix both issues.
--- hw/pci/pcie_aer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
hw/pci/pcie_aer.c +9 -1
@@ -795,6 +795,13 @@ static const VMStateDescription vmstate_pcie_aer_err = { } }; +static bool pcie_aer_state_log_num_valid (void *opaque,int version_id) +{ +PCIEAERLog *s = opaque; + +return s->log_num <= s->log_max; +} +const VMStateDescription vmstate_pcie_aer_log = { .name ="PCIE_AER_ERROR_LOG" , .version_id =1 ,
@@ -802,7 +809,8 @@ const VMStateDescription vmstate_pcie_aer_log = { .minimum_version_id_old = 1, .fields = (VMStateField []) {VMSTATE_UINT16 (log_num, PCIEAERLog), -VMSTATE_UINT16 (log_max, PCIEAERLog), +VMSTATE_UINT16_EQUAL (log_max, PCIEAERLog), +VMSTATE_VALIDATE ("log_num <= log_max" , pcie_aer_state_log_num_valid),VMSTATE_STRUCT_VARRAY_POINTER_UINT16 (log, PCIEAERLog, log_num, vmstate_pcie_aer_err, PCIEAERErr),VMSTATE_END_OF_LIST ()
Signature · 1 line
1.9.1
PATCH 10/108 hpet: fix buffer overrun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4527 hw/timer/hpet.c buffer overrun
hpet is a VARRAY with a uint8 size but static array of 32
To fix, make sure num_timers is valid using VMSTATE_VALID hook.
--- hw/timer/hpet.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/timer/hpet.c +13 -0
@@ -239,6 +239,18 @@ static int hpet_pre_load(void *opaque)return 0 ; } +static bool hpet_validate_num_timers (void *opaque,int version_id) +{ +HPETState *s = opaque; + +if (s->num_timers <HPET_MIN_TIMERS ) { +return false; + }else if (s->num_timers >HPET_MAX_TIMERS ) { +return false; + } +return true; +} +static int hpet_post_load (void *opaque,int version_id) {HPETState *s = opaque;
@@ -307,6 +319,7 @@ static const VMStateDescription vmstate_hpet = {VMSTATE_UINT64 (isr, HPETState),VMSTATE_UINT64 (hpet_counter, HPETState),VMSTATE_UINT8_V (num_timers, HPETState,2 ), +VMSTATE_VALIDATE ("num_timers in range" , hpet_validate_num_timers),VMSTATE_STRUCT_VARRAY_UINT8 (timer, HPETState, num_timers,0 , vmstate_hpet_timer, HPETTimer),VMSTATE_END_OF_LIST ()
Signature · 1 line
1.9.1
PATCH 12/108 pl022: fix buffer overun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4530
pl022.c did not bounds check tx_fifo_head andrx_fifo_head after loading them from file and
before they are used to dereference array.
--- hw/ssi/pl022.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
hw/ssi/pl022.c +14 -0
@@ -240,11 +240,25 @@ static const MemoryRegionOps pl022_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int pl022_post_load (void *opaque,int version_id) +{ +PL022State *s = opaque; + +if (s->tx_fifo_head <0 || + s->tx_fifo_head >=ARRAY_SIZE (s->tx_fifo) || + s->rx_fifo_head <0 || + s->rx_fifo_head >=ARRAY_SIZE (s->rx_fifo)) { +return -1 ; + } +return 0 ; +} +static const VMStateDescription vmstate_pl022 = { .name ="pl022_ssp" , .version_id =1 , .minimum_version_id =1 , .minimum_version_id_old =1 , + .post_load = pl022_post_load, .fields = (VMStateField []) {VMSTATE_UINT32 (cr0, PL022State),VMSTATE_UINT32 (cr1, PL022State),
Signature · 1 line
1.9.1
PATCH 13/108 vmstate: fix buffer overflow in target-arm/machine.c
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4531
cpreg_vmstate_indexes is a VARRAY_INT32. A negative value for cpreg_vmstate_array_len will cause a buffer overflow.
VMSTATE_INT32_LE was supposed to protect against this but doesn't because it doesn't validate that input is non-negative.
Fix this macro to valide the value appropriately.
The only other user of VMSTATE_INT32_LE doesn't
ever use negative numbers so it doesn't care.
--- vmstate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
vmstate.c +4 -3
@@ -337,8 +337,9 @@ const VMStateInfo vmstate_info_int32_equal = { .put = put_int32, }; -/* 32 bit int. Check that the received value is less than or equal to -the one in the field */ +/* 32 bit int. Check that the received value is non-negative +* and less than or equal to the one in the field. +*/ static int get_int32_le (QEMUFile *f,void *pv,size_t size) {
@@ -346,7 +347,7 @@ static int get_int32_le(QEMUFile *f, void *pv, size_t size)int32_t loaded;qemu_get_sbe32s (f, &loaded); -if (loaded <= *cur) { +if (loaded >=0 && loaded <= *cur) { *cur = loaded;return 0 ; }
Signature · 1 line
1.9.1
cover Patch Round-up for stable 2.0.1, freeze on 2014-08-12
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
http://wiki.qemu.org/Planning/2.0
Please respond here or CC [email protected] on any patches you think should be included in the release.
Due to delays, this is the final planned release for the 2.0.0 series. We will return to the standard 2-release cycle for 2.1 (one midway during 2.2 development cycle, one immediately following 2.2 release)
Testing/feedback is greatly appreciated.
Thanks!
----------------------------------------------------------------
Alex Bennée (1):
target-arm: A64: fix unallocated test of scalar SQXTUN
Alexander Graf (2):
KVM: Fix GSI number space limit
virtio-serial: don't migrate the config space
Alexey Kardashevskiy (1):
spapr_pci: Fix number of returned vectors in ibm, change-msi
Amos Kong (1):
qdev: Fix crash by validating the object type
Andreas Färber (2):
sdhci: Fix misuse of qemu_free_irqs()
hw: Fix qemu_allocate_irqs() leaks
Andrew Oates (1):
input (curses): mask keycodes to remove modifier bits
Benoît Canet (1):
block: Prevent coroutine stack overflow when recursing in bdrv_open_backing_file.
Chen Gang (2):
arch_init: Be sure of only one exit entry with DPRINTF() for ram_load()
kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL
ChenLiang (1):
migration: remove duplicate code
Christian Borntraeger (1):
s390x/kvm: rework KVM synchronize to tracing for some ONEREGS
Cornelia Huck (1):
s390x/css: handle emw correctly for tsch
Cédric Le Goater (1):
virtio-net: byteswap virtio-net header
David Hildenbrand (1):
s390x: empty function stubs in preparation for __KVM_HAVE_GUEST_DEBUG
Don Slutz (1):
pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout
Dr. David Alan Gilbert (1):
Allow mismatched virtio config-len
Edgar E. Iglesias (2):
target-arm: A64: Handle blr lr
target-arm: Make vbar_write 64bit friendly on 32bit hosts
Eduardo Habkost (3):
q35: Use PC_Q35_COMPAT_1_4 on pc-q35-1.4 compat_props
target-i386: Make TCG feature filtering more readable
target-i386: Filter FEAT_7_0_EBX TCG features too
Gabriel L. Somlo (1):
SMBIOS: Rename symbols to better reflect future use
Gonglei (1):
qga: Fix handle fd leak in acquire_privilege()
Hani Benhabiles (5):
usb: Fix usb-bt-dongle initialization.
nbd: Don't export a block device with no medium.
nbd: Don't validate from and len in NBD_CMD_DISC.
nbd: Close socket on negotiation failure.
nbd: Shutdown socket before closing.
Hannes Reinecke (1):
megasas: Implement LD_LIST_QUERY
Jason J. Herne (1):
s390x/kvm: synchronize guest floating point registers
KONRAD Frederic (1):
cadence_uart: check for serial backend before using it.
Kevin Wolf (5):
qcow1: Make padding in the header explicit
qcow1: Check maximum cluster size
qcow1: Validate L2 table size (CVE-2014-0222)
qcow1: Validate image size (CVE-2014-0223)
qcow1: Stricter backing file length check
Laszlo Ersek (1):
vmstate_xhci_event: fix unterminated field list
Le Tan (1):
pci: assign devfn to pci_dev before calling pci_device_iommu_address_space()
Markus Armbruster (12):
virtio-scsi: Plug memory leak on virtio_scsi_push_event() error path
qemu-img: Plug memory leak in convert command block/sheepdog: Plug memory leak in sd_snapshot_create() block/vvfat: Plug memory leak in read_directory() block/vvfat: Plug memory leak in check_directory_consistency() block/qapi: Plug memory leak in dump_qobject() case QTYPE_QERROR
blockdev: Plug memory leak in drive_init()
blockdev: Plug memory leak in blockdev_init()
qemu-io: Plug memory leak in open command
block: Plug memory leak on brv_open_image() error path
qcow2: Plug memory leak on qcow2_invalidate_cache() error paths
hw: Consistently name Error ** objects errp, and not err
Max Filippov (2):
target-xtensa: fix cross-page jumps/calls at the end of TB hw/xtensa/xtfpga: fix FLASH mapping to boot region for KC705
Michael R. Hines (1):
rdma: bug fixes
Michael Roth (2):
virtio: avoid buffer overrun on incoming migration
openpic: avoid buffer overrun on incoming migration
Michael S. Tsirkin (26):
vmstate: reduce code duplication
vmstate: add VMS_MUST_EXIST
vmstate: add VMSTATE_VALIDATE
virtio-net: fix buffer overflow on invalid state load
virtio-net: out-of-bounds buffer write on invalid state load
virtio-net: out-of-bounds buffer write on load
ahci: fix buffer overrun on invalid state load
hpet: fix buffer overrun on invalid state load hw/pci/pcie_aer.c: fix buffer overruns on invalid state load
pl022: fix buffer overun on invalid state load
vmstate: fix buffer overflow in target-arm/machine.c
virtio: validate num_sg when mapping
pxa2xx: avoid buffer overrun on incoming migration
ssi-sd: fix buffer overrun on invalid state load
ssd0323: fix buffer overun on invalid state load
tsc210x: fix buffer overrun on invalid state load
zaurus: fix buffer overrun on invalid state load
usb: sanity check setup_index+setup_len in post_load
virtio-scsi: fix buffer overrun on invalid state load
acpi: fix tables for no-hpet configuration
stellaris_enet: block migration
pci-assign: limit # of msix vectors
virtio: allow mapping up to max queue size
vhost: fix resource leak in error handling
virtio: out-of-bounds buffer write on invalid state load
virtio: validate config_len on load
Michael Tokarev (2):
po/Makefile: fix $SRC_PATH reference
configure: remove bashism
Ming Lei (1):
virtio-scsi: define dummy handle_output for vhost-scsi vqs
Paolo Bonzini (4):
target-i386: fix set of registers zeroed on reset
qdev: reorganize error reporting in bus_set_realized
qdev: recursively unrealize devices when unrealizing bus
mc146818rtc: register the clock reset notifier on the right clock
Peter Crosthwaite (1):
arm: translate.c: Fix smlald Instruction
Peter Lieven (2):
Revert "qapi: Clean up superfluous null check in qapi_dealloc_type_str()"
migration: catch unknown flags in ram_load
Peter Maydell (10):
hw/net/stellaris_enet: Restructure tx_fifo code to avoid buffer overrun hw/net/stellaris_enet: Correct handling of packet padding linux-user/elfload.c: Fix incorrect ARM HWCAP bits linux-user/elfload.c: Update ARM HWCAP bits linux-user/elfload.c: Fix A64 code which was incorrectly acting like A32
linux-user: Don't overrun guest buffer in sched_getaffinity
target-arm: Fix errors in writes to generic timer control registers coroutine-win32.c: Add noinline attribute to work around gcc bug hw/misc/imx_ccm.c: Add missing VMState list terminator hw/arm/boot: Set PC correctly when loading AArch64 ELF files
Richard Henderson (1):
tcg-i386: Fix win64 qemu store
Stefan Hajnoczi (1):
aio: fix qemu_bh_schedule() bh->ctx race condition
Stefan Weil (1):
cputlb: Fix regression with TCG interpreter (bug 1310324)
Stefano Stabellini (1):
disas/libvixl: prepend the include path of libvixl header files
Ulrich Obergfell (1):
scsi-disk: fix bug in scsi_block_new_request() introduced by commit 137745c
arch_init.c | 110 +++++++++++++++++++++------------------- async.c | 14 ++++-- block.c | 34 +++++++------ block/qapi.c | 1 + block/qcow.c | 44 +++++++++++++--- block/qcow2.c | 3 +- block/sheepdog.c | 4 +- block/vvfat.c | 6 ++- blockdev-nbd.c | 9 +++- blockdev.c | 7 ++- configure | 2 +- coroutine-win32.c | 13 ++++- cputlb.c | 6 ++- disas/Makefile.objs | 2 +- disas/libvixl/Makefile.objs | 2 +- hw/arm/boot.c | 8 ++- hw/arm/omap1.c | 14 +++--- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 12 +++-- hw/arm/spitz.c | 4 +- hw/arm/z2.c | 2 +- hw/char/cadence_uart.c | 15 ++++-- hw/char/virtio-serial-bus.c | 16 +++--- hw/core/irq.c | 4 +- hw/core/qdev.c | 45 +++++++++-------- hw/display/ssd0323.c | 24 +++++++++ hw/dma/omap_dma.c | 4 +- hw/gpio/zaurus.c | 10 ++++ hw/i386/acpi-build.c | 7 +-- hw/i386/kvm/pci-assign.c | 12 ++--- hw/i386/pc.c | 2 +- hw/i386/pc_piix.c | 20 +++++--- hw/i386/pc_q35.c | 12 ++--- hw/i386/smbios.c | 18 ++++--- hw/ide/ahci.c | 2 +- hw/ide/microdrive.c | 2 +- hw/input/tsc210x.c | 12 +++++ hw/intc/i8259.c | 4 +- hw/intc/openpic.c | 16 +++++- hw/misc/cbus.c | 6 +-- hw/misc/imx_ccm.c | 1 + hw/net/stellaris_enet.c | 23 ++++++--- hw/net/virtio-net.c | 37 ++++++++++++-- hw/pci/pci.c | 2 +- hw/pci/pcie_aer.c | 10 +++- hw/pcmcia/pxa2xx.c | 2 +- hw/ppc/spapr_pci.c | 15 ++++++ hw/s390x/css.c | 24 +++++++-- hw/scsi/megasas.c | 17 +++++++ hw/scsi/mfi.h | 9 ++++ hw/scsi/scsi-disk.c | 2 +- hw/scsi/vhost-scsi.c | 8 ++- hw/scsi/virtio-scsi.c | 26 +++++++--- hw/sd/omap_mmc.c | 2 +- hw/sd/sdhci.c | 8 +-- hw/sd/ssi-sd.c | 9 ++++ hw/sh4/sh7750.c | 3 +- hw/ssi/pl022.c | 14 ++++++ hw/timer/hpet.c | 13 +++++ hw/timer/i8254.c | 4 +- hw/timer/mc146818rtc.c | 2 +- hw/timer/omap_gptimer.c | 4 +- hw/usb/bus.c | 4 +- hw/usb/dev-bluetooth.c | 24 ++++++--- hw/usb/hcd-xhci.c | 1 + hw/virtio/vhost.c | 10 ++-- hw/virtio/virtio.c | 33 ++++++++++-- hw/xtensa/xtensa_lx60.c | 8 +-- include/hw/i386/smbios.h | 6 +-- include/hw/virtio/virtio-net.h | 4 +- include/hw/virtio/virtio-scsi.h | 7 ++- include/migration/vmstate.h | 9 ++++ kvm-all.c | 7 +-- linux-user/elfload.c | 117 +++++++++++++++++++++++++++++++++++------- linux-user/syscall.c | 16 ++++++ migration-rdma.c | 20 ++++---- migration.c | 2 +- nbd.c | 7 +-- po/Makefile | 4 +- qapi/qapi-dealloc-visitor.c | 4 +- qdev-monitor.c | 2 +- qemu-img.c | 2 +- qemu-io.c | 2 + qemu-nbd.c | 5 +- qga/commands-win32.c | 6 ++- target-arm/helper.c | 8 +-- target-arm/translate-a64.c | 5 +- target-arm/translate.c | 34 +++++++++---- target-i386/cpu.c | 22 ++++---- target-i386/cpu.h | 11 ++-- target-s390x/kvm.c | 190 +++++++++++++++++++++++++++++++++++++++++---------------------------- target-xtensa/translate.c | 4 +- tcg/i386/tcg-target.c | 3 +- tests/qemu-iotests/092 | 98 ++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/092.out | 38 ++++++++++++++ tests/qemu-iotests/group | 1 + trace-events | 5 ++ ui/curses.c | 4 +- vmstate.c | 117 +++++++++++++++++++++++------------------- 99 files changed, 1147 insertions(+), 458 deletions(-) create mode 100755 tests/qemu-iotests/092 create mode 100644 tests/qemu-iotests/092.out
PATCH 15/108 virtio: validate num_sg when mapping
From: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4535
CVE-2013-4536
Both virtio-block and virtio-serial read, VirtQueueElements are read in as buffers, and passed to virtqueue_map_sg(), where num_sg is taken from the wire and can force writes to indicies beyond VIRTQUEUE_MAX_SIZE.
To fix, validate num_sg.
--- hw/virtio/virtio.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/virtio/virtio.c +6 -0
@@ -430,6 +430,12 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,unsigned int i;hwaddr len; +if (num_sg >=VIRTQUEUE_MAX_SIZE ) { +error_report ("virtio: map attempt out of bounds: %zd > %d" , + num_sg,VIRTQUEUE_MAX_SIZE ); +exit (1 ); + } +for (i =0 ; i < num_sg; i++) { len = sg[i].iov_len; sg[i].iov_base =cpu_physical_memory_map (addr[i], &len, is_write);
Signature · 1 line
1.9.1
PATCH 17/108 pxa2xx: avoid buffer overrun on incoming migration
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4533
s->rx_level is read from the wire and used to determine how many bytes to subsequently read into s->rx_fifo[]. If s->rx_level exceeds the length of s->rx_fifo[] the buffer can be overrun with arbitrary data from the wire.
Fix this by validating rx_level against the size of s->rx_fifo.
--- hw/arm/pxa2xx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/pxa2xx.c +6 -2
@@ -732,7 +732,7 @@ static void pxa2xx_ssp_save(QEMUFile *f, void *opaque)static int pxa2xx_ssp_load (QEMUFile *f,void *opaque,int version_id) {PXA2xxSSPState *s = (PXA2xxSSPState *) opaque; -int i; +int i, v; s->enable =qemu_get_be32 (f);
@@ -746,7 +746,11 @@ static int pxa2xx_ssp_load(QEMUFile *f, void *opaque, int version_id)qemu_get_8s (f, &s->ssrsa);qemu_get_8s (f, &s->ssacd); - s->rx_level =qemu_get_byte (f); + v =qemu_get_byte (f); +if (v <0 || v >ARRAY_SIZE (s->rx_fifo)) { +return -EINVAL ; + } + s->rx_level = v; s->rx_start =0 ;for (i =0 ; i < s->rx_level; i ++) s->rx_fifo[i] =qemu_get_byte (f);
Signature · 1 line
1.9.1
PATCH 19/108 ssd0323: fix buffer overun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4538
s->cmd_len used as index in ssd0323_transfer() to store 32-bit field. Possible this field might then be supplied by guest to overwrite a return addr somewhere. Same for row/col fields, which are indicies into framebuffer array.
To fix validate after load.
Additionally, validate that the row/col_start/end are within bounds; otherwise the guest can provoke an overrun by either setting the _end field so large that the row++ increments just walk off the end of the array, or by setting the _start value to something bogus and then letting the "we hit end of row" logic reset row to row_start.
For completeness, validate mode as well.
--- hw/display/ssd0323.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
hw/display/ssd0323.c +24 -0
@@ -312,18 +312,42 @@ static int ssd0323_load(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; s->cmd_len =qemu_get_be32 (f); +if (s->cmd_len <0 || s->cmd_len >ARRAY_SIZE (s->cmd_data)) { +return -EINVAL ; + } s->cmd =qemu_get_be32 (f);for (i =0 ; i <8 ; i++) s->cmd_data[i] =qemu_get_be32 (f); s->row =qemu_get_be32 (f); +if (s->row <0 || s->row >=80 ) { +return -EINVAL ; + } s->row_start =qemu_get_be32 (f); +if (s->row_start <0 || s->row_start >=80 ) { +return -EINVAL ; + } s->row_end =qemu_get_be32 (f); +if (s->row_end <0 || s->row_end >=80 ) { +return -EINVAL ; + } s->col =qemu_get_be32 (f); +if (s->col <0 || s->col >=64 ) { +return -EINVAL ; + } s->col_start =qemu_get_be32 (f); +if (s->col_start <0 || s->col_start >=64 ) { +return -EINVAL ; + } s->col_end =qemu_get_be32 (f); +if (s->col_end <0 || s->col_end >=64 ) { +return -EINVAL ; + } s->redraw =qemu_get_be32 (f); s->remap =qemu_get_be32 (f); s->mode =qemu_get_be32 (f); +if (s->mode !=SSD0323_CMD && s->mode !=SSD0323_DATA ) { +return -EINVAL ; + }qemu_get_buffer (f, s->framebuffer,sizeof (s->framebuffer)); ss->cs =qemu_get_be32 (f);
Signature · 1 line
1.9.1
PATCH 18/108 ssi-sd: fix buffer overrun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4537
s->arglen is taken from wire and used as idx
in ssi_sd_transfer().
Validate it before access.
--- hw/sd/ssi-sd.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/sd/ssi-sd.c +9 -0
@@ -230,8 +230,17 @@ static int ssi_sd_load(QEMUFile *f, void *opaque, int version_id)for (i =0 ; i <5 ; i++) s->response[i] =qemu_get_be32 (f); s->arglen =qemu_get_be32 (f); +if (s->mode ==SSI_SD_CMDARG && + (s->arglen <0 || s->arglen >=ARRAY_SIZE (s->cmdarg))) { +return -EINVAL ; + } s->response_pos =qemu_get_be32 (f); s->stopping =qemu_get_be32 (f); +if (s->mode ==SSI_SD_RESPONSE && + (s->response_pos <0 || s->response_pos >=ARRAY_SIZE (s->response) || + (!s->stopping && s->arglen >ARRAY_SIZE (s->response)))) { +return -EINVAL ; + } ss->cs =qemu_get_be32 (f);
Signature · 1 line
1.9.1
PATCH 20/108 tsc210x: fix buffer overrun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4539
s->precision, nextprecision, function and nextfunction come from wire and are used
as idx into resolution[] in TSC_CUT_RESOLUTION.
Validate after load to avoid buffer overrun.
--- hw/input/tsc210x.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/input/tsc210x.c +12 -0
@@ -1070,9 +1070,21 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int version_id) s->enabled =qemu_get_byte (f); s->host_mode =qemu_get_byte (f); s->function =qemu_get_byte (f); +if (s->function <0 || s->function >=ARRAY_SIZE (mode_regs)) { +return -EINVAL ; + } s->nextfunction =qemu_get_byte (f); +if (s->nextfunction <0 || s->nextfunction >=ARRAY_SIZE (mode_regs)) { +return -EINVAL ; + } s->precision =qemu_get_byte (f); +if (s->precision <0 || s->precision >=ARRAY_SIZE (resolution)) { +return -EINVAL ; + } s->nextprecision =qemu_get_byte (f); +if (s->nextprecision <0 || s->nextprecision >=ARRAY_SIZE (resolution)) { +return -EINVAL ; + } s->filter =qemu_get_byte (f); s->pin_func =qemu_get_byte (f); s->ref =qemu_get_byte (f);
Signature · 1 line
1.9.1
PATCH 24/108 target-arm: A64: fix unallocated test of scalar SQXTUN
In reply to Michael RothFrom: Alex Bennée <[email protected]>
The test for the U bit was incorrectly inverted in the scalar case of SQXTUN. This doesn't affect the vector case as the U bit is used to select XTN(2).
--- target-arm/translate-a64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-arm/translate-a64.c +1 -1
@@ -7455,7 +7455,7 @@ static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn) }break ;case 0x12 :/* SQXTUN */ -if (u) { +if (!u) {unallocated_encoding (s);return ; }
Signature · 1 line
1.9.1
PATCH 23/108 virtio-scsi: fix buffer overrun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4542
hw/scsi/scsi-bus.c invokes load_request.
virtio_scsi_load_request does:
qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
this probably can make elem invalid, for example,
make in_num or out_num huge, then:
virtio_scsi_parse_req(s, vs->cmd_vqs[n], req);
will do:
if (req->elem.out_num > 1) {
qemu_sgl_init_external(req, &req->elem.out_sg[1],
&req->elem.out_addr[1],
req->elem.out_num - 1);
} else {
qemu_sgl_init_external(req, &req->elem.in_sg[1],
&req->elem.in_addr[1],
req->elem.in_num - 1);
}and this will access out of array bounds.
Note: this adds security checks within assert calls since SCSIBusInfo's load_request cannot fail.
For now simply disable builds with NDEBUG - there seems to be little value in supporting these.
--- hw/scsi/virtio-scsi.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/scsi/virtio-scsi.c +9 -0
@@ -147,6 +147,15 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)qemu_get_be32s (f, &n);assert (n < vs->conf.num_queues);qemu_get_buffer (f, (unsigned char *)&req->elem,sizeof (req->elem)); +/* TODO: add a way for SCSIBusInfo's load_request to fail, +* and fail migration instead of asserting here. +* When we do, we might be able to re-enable NDEBUG below. +*/ +#ifdef NDEBUG +#error building with NDEBUG is not supported +#endif +assert (req->elem.in_num <=ARRAY_SIZE (req->elem.in_sg)); +assert (req->elem.out_num <=ARRAY_SIZE (req->elem.out_sg));virtio_scsi_parse_req (s, vs->cmd_vqs[n], req);scsi_req_ref (sreq);
Signature · 1 line
1.9.1
PATCH 21/108 zaurus: fix buffer overrun on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4540
Within scoop_gpio_handler_update, if prev_level has a high bit set, then we get bit > 16 and that causes a buffer overrun.
Since prev_level comes from wire indirectly, this can happen on invalid state load.
Similarly for gpio_level and gpio_dir.
To fix, limit to 16 bit.
--- hw/gpio/zaurus.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/gpio/zaurus.c +10 -0
@@ -203,6 +203,15 @@ static bool is_version_0 (void *opaque, int version_id)return version_id ==0 ; } +static bool vmstate_scoop_validate (void *opaque,int version_id) +{ +ScoopInfo *s = opaque; + +return !(s->prev_level &0xffff0000 ) && + !(s->gpio_level &0xffff0000 ) && + !(s->gpio_dir &0xffff0000 ); +} +static const VMStateDescription vmstate_scoop_regs = { .name ="scoop" , .version_id =1 ,
@@ -215,6 +224,7 @@ static const VMStateDescription vmstate_scoop_regs = {VMSTATE_UINT32 (gpio_level, ScoopInfo),VMSTATE_UINT32 (gpio_dir, ScoopInfo),VMSTATE_UINT32 (prev_level, ScoopInfo), +VMSTATE_VALIDATE ("irq levels are 16 bit" , vmstate_scoop_validate),VMSTATE_UINT16 (mcr, ScoopInfo),VMSTATE_UINT16 (cdr, ScoopInfo), VMSTATE_UINT16(ccr, ScoopInfo),
Signature · 1 line
1.9.1
PATCH 22/108 usb: sanity check setup_index+setup_len in post_load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4541
s->setup_len and s->setup_index are fed into usb_packet_copy as size/offset into s->data_buf, it's possible for invalid state to exploit this to load arbitrary data.
setup_len and setup_index should be checked to make sure they are not negative.
--- hw/usb/bus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/usb/bus.c +3 -1
@@ -49,7 +49,9 @@ static int usb_device_post_load(void *opaque, int version_id) }else { dev->attached =1 ; } -if (dev->setup_index >=sizeof (dev->data_buf) || +if (dev->setup_index <0 || + dev->setup_len <0 || + dev->setup_index >=sizeof (dev->data_buf) || dev->setup_len >=sizeof (dev->data_buf)) {return -EINVAL ; }
Signature · 1 line
1.9.1
PATCH 25/108 megasas: Implement LD_LIST_QUERY
In reply to Michael RothFrom: Hannes Reinecke <[email protected]>
Newer firmware implement a LD_LIST_QUERY command, and due to a driver issue no drives might be detected if this command isn't supported. So add emulation for this command, too.
--- hw/scsi/megasas.c | 17 +++++++++++++++++ hw/scsi/mfi.h | 9 +++++++++ trace-events | 1 + 3 files changed, 27 insertions(+)
hw/scsi/megasas.c +17 -0
@@ -1106,6 +1106,21 @@ static int megasas_dcmd_ld_get_list(MegasasState *s, MegasasCmd *cmd)return MFI_STAT_OK ; } +static int megasas_dcmd_ld_list_query (MegasasState *s,MegasasCmd *cmd) +{ +uint16_t flags; + +/* mbox0 contains flags */ + flags =le16_to_cpu (cmd->frame->dcmd.mbox[0 ]); +trace_megasas_dcmd_ld_list_query (cmd->index, flags); +if (flags ==MR_LD_QUERY_TYPE_ALL || + flags ==MR_LD_QUERY_TYPE_EXPOSED_TO_HOST ) { +return megasas_dcmd_ld_get_list (s, cmd); + } + +return MFI_STAT_OK ; +} +static int megasas_ld_get_info_submit (SCSIDevice *sdev,int lun,MegasasCmd *cmd) {
@@ -1409,6 +1424,8 @@ static const struct dcmd_cmd_tbl_t { megasas_dcmd_dummy }, {MFI_DCMD_LD_GET_LIST ,"LD_GET_LIST" , megasas_dcmd_ld_get_list}, + { MFI_DCMD_LD_LIST_QUERY, "LD_LIST_QUERY", + megasas_dcmd_ld_list_query }, { MFI_DCMD_LD_GET_INFO, "LD_GET_INFO", megasas_dcmd_ld_get_info }, { MFI_DCMD_LD_GET_PROP, "LD_GET_PROP",
hw/scsi/mfi.h +9 -0
@@ -164,6 +164,7 @@ typedef enum {MFI_DCMD_PD_BLINK =0x02070100 ,MFI_DCMD_PD_UNBLINK =0x02070200 ,MFI_DCMD_LD_GET_LIST =0x03010000 , +MFI_DCMD_LD_LIST_QUERY =0x03010100 ,MFI_DCMD_LD_GET_INFO =0x03020000 ,MFI_DCMD_LD_GET_PROP =0x03030000 , MFI_DCMD_LD_SET_PROP = 0x03040000,
@@ -411,6 +412,14 @@ typedef enum {MR_PD_QUERY_TYPE_EXPOSED_TO_HOST =5 ,/*query for system drives */ } mfi_pd_query_type; +typedef enum { +MR_LD_QUERY_TYPE_ALL =0 , +MR_LD_QUERY_TYPE_EXPOSED_TO_HOST =1 , +MR_LD_QUERY_TYPE_USED_TGT_IDS =2 , +MR_LD_QUERY_TYPE_CLUSTER_ACCESS =3 , +MR_LD_QUERY_TYPE_CLUSTER_LOCALE =4 , +}mfi_ld_query_type ; +/* * Other propertities and definitions */
trace-events +1 -0
@@ -664,6 +664,7 @@ megasas_dcmd_ld_get_list(int cmd, int num, int max) "scmd %d: DCMD LD get list: megasas_dcmd_ld_get_info(int cmd, int ld_id) "scmd %d: DCMD LD get info for dev %d" megasas_dcmd_pd_get_info(int cmd, int pd_id) "scmd %d: DCMD PD get info for dev %d" megasas_dcmd_pd_list_query(int cmd, int flags) "scmd %d: DCMD PD list query flags %x" +megasas_dcmd_ld_list_query(int cmd, int flags) "scmd %d: DCMD LD list query flags %x" megasas_dcmd_unsupported(int cmd, unsigned long size) "scmd %d: set properties len %ld" megasas_abort_frame(int cmd, int abort_cmd) "scmd %d: aborting frame %x" megasas_abort_no_cmd(int cmd, uint64_t context) "scmd %d: no active command for frame context %" PRIx64 ""
Signature · 1 line
1.9.1
PATCH 14/108 virtio: avoid buffer overrun on incoming migration
In reply to Michael RothCVE-2013-6399
vdev->queue_sel is read from the wire, and later used in the emulation code as an index into vdev->vq[]. If the value of vdev->queue_sel exceeds the length of vdev->vq[], currently allocated to be VIRTIO_PCI_QUEUE_MAX elements, subsequent PIO operations such as VIRTIO_PCI_QUEUE_PFN can be used to overrun the buffer with arbitrary data originating from the source.
Fix this by failing migration if the value from the wire exceeds VIRTIO_PCI_QUEUE_MAX.
--- hw/virtio/virtio.c | 3 +++ 1 file changed, 3 insertions(+)
hw/virtio/virtio.c +3 -0
@@ -906,6 +906,9 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)qemu_get_8s (f, &vdev->status);qemu_get_8s (f, &vdev->isr);qemu_get_be16s (f, &vdev->queue_sel); +if (vdev->queue_sel >=VIRTIO_PCI_QUEUE_MAX ) { +return -1 ; + }qemu_get_be32s (f, &features);if (virtio_set_features (vdev, features) <0 ) {
Signature · 1 line
1.9.1
PATCH 29/108 po/Makefile: fix $SRC_PATH reference
In reply to Michael RothFrom: Michael Tokarev <[email protected]>
The rule for messages.po appears to be slightly wrong. Move the `cd' command within parens.
--- po/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
po/Makefile +2 -2
@@ -37,8 +37,8 @@ install: $(OBJS) $(call quiet-command, msgfmt -o $@ $<, " GEN $@") $(PO_PATH)/messages.po: $(SRC_PATH)/ui/gtk.c - $(call quiet-command, cd $(SRC_PATH) && \ - (xgettext -o - --from-code=UTF-8 --foreign-user \ + $(call quiet-command, ( cd $(SRC_PATH) && \ + xgettext -o - --from-code=UTF-8 --foreign-user \ --package-name=QEMU --package-version=$(VERSION) \ [email protected] -k_ -C ui/gtk.c | \ sed -e s/CHARSET/UTF-8/) >$@, " GEN $@")
Signature · 1 line
1.9.1
PATCH 27/108 block: Prevent coroutine stack overflow when recursing in bdrv_open_backing_file.
In reply to Michael RothFrom: Benoît Canet <[email protected]>
In 1.7.1 qcow2_create2 reopen the file for flushing without the BDRV_O_NO_BACKING flags.
As a consequence the code would recursively open the whole backing chain.
These three stack arrays would pile up through the recursion and lead to a coroutine stack overflow.
Convert these array to malloced buffers in order to streamline the coroutine footprint.
Symptoms where freezes or segfaults on production machines while taking QMP externals snapshots. The overflow disturbed coroutine switching.
[Resolved conflicts on qemu.git/master since the patch was against v1.7.1 --Stefan]
--- block.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
block.c +18 -15
@@ -1058,14 +1058,14 @@ fail:*/ int bdrv_open_backing_file (BlockDriverState *bs,QDict *options,Error **errp) { -char backing_filename[PATH_MAX ]; -int back_flags, ret; +char *backing_filename =g_malloc0 (PATH_MAX ); +int back_flags, ret =0 ;BlockDriver *back_drv =NULL ;Error *local_err =NULL ;if (bs->backing_hd !=NULL ) {QDECREF (options); -return 0 ; + goto free_exit; }/* NULL means an empty set of options */
@@ -1078,10 +1078,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) backing_filename[0 ] ='\0' ; }else if (bs->backing_file[0 ] =='\0' &&qdict_size (options) ==0 ) {QDECREF (options); -return 0 ; + goto free_exit; }else { -bdrv_get_full_backing_filename (bs, backing_filename, -sizeof (backing_filename)); +bdrv_get_full_backing_filename (bs, backing_filename,PATH_MAX ); }if (bs->backing_format[0 ] !='\0' ) {
@@ -1102,7 +1101,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)error_setg (errp,"Could not open backing file: %s" ,error_get_pretty (local_err));error_free (local_err); -return ret; + goto free_exit; }if (bs->backing_hd->file) {
@@ -1113,7 +1112,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)/* Recalculate the BlockLimits with the backing file */ bdrv_refresh_limits (bs); -return 0 ; +free_exit: +g_free (backing_filename); +return ret; }/*
@@ -1170,8 +1171,7 @@ done:void bdrv_append_temp_snapshot (BlockDriverState *bs,Error **errp) {/* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */ -char tmp_filename[PATH_MAX +1 ]; - +char *tmp_filename =g_malloc0 (PATH_MAX +1 );int64_t total_size;BlockDriver *bdrv_qcow2;QEMUOptionParameter *create_options;
@@ -1187,15 +1187,15 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp) total_size =bdrv_getlength (bs);if (total_size <0 ) {error_setg_errno (errp, -total_size,"Could not get image size" ); -return ; + goto out; } total_size &=BDRV_SECTOR_MASK ;/* Create the temporary image */ - ret =get_tmp_filename (tmp_filename,sizeof (tmp_filename)); + ret =get_tmp_filename (tmp_filename,PATH_MAX +1 );if (ret <0 ) {error_setg_errno (errp, -ret,"Could not get temporary filename" ); -return ; + goto out; } bdrv_qcow2 =bdrv_find_format ("qcow2" );
@@ -1211,7 +1211,7 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp)"'%s': %s" , tmp_filename, error_get_pretty(local_err));error_free (local_err); -return ; + goto out; }/* Prepare a new options QDict for the temporary file */
@@ -1228,10 +1228,13 @@ void bdrv_append_temp_snapshot(BlockDriverState *bs, Error **errp) bs->open_flags & ~BDRV_O_SNAPSHOT, bdrv_qcow2, &local_err);if (ret <0 ) {error_propagate (errp, local_err); -return ; + goto out; }bdrv_append (bs_snapshot, bs); + +out: +g_free (tmp_filename); }/*
Signature · 1 line
1.9.1
PATCH 28/108 s390x: empty function stubs in preparation for __KVM_HAVE_GUEST_DEBUG
In reply to Michael RothFrom: David Hildenbrand <[email protected]>
This patch creates empty function stubs (used by the gdbserver) in preparation for the hw debugging support by kvm on s390, which will enable the __KVM_HAVE_GUEST_DEBUG define in the linux headers and require these methods on the qemu side.
--- target-s390x/kvm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
target-s390x/kvm.c +28 -0
@@ -383,6 +383,26 @@ int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)return 0 ; } +int kvm_arch_insert_hw_breakpoint (target_ulong addr, +target_ulong len,int type) +{ +return -ENOSYS ; +} + +int kvm_arch_remove_hw_breakpoint (target_ulong addr, +target_ulong len,int type) +{ +return -ENOSYS ; +} + +void kvm_arch_remove_all_hw_breakpoints (void ) +{ +} + +void kvm_arch_update_guest_debug (CPUState *cpu,struct kvm_guest_debug *dbg) +{ +} +void kvm_arch_pre_run (CPUState *cpu,struct kvm_run *run) { }
@@ -844,6 +864,11 @@ static int handle_tsch(S390CPU *cpu)return ret; } +static int kvm_arch_handle_debug_exit (S390CPU *cpu) +{ +return -ENOSYS ; +} +int kvm_arch_handle_exit (CPUState *cs,struct kvm_run *run) {S390CPU *cpu =S390_CPU (cs);
@@ -859,6 +884,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)case KVM_EXIT_S390_TSCH : ret =handle_tsch (cpu);break ; +case KVM_EXIT_DEBUG : + ret =kvm_arch_handle_debug_exit (cpu); +break ;default :fprintf (stderr,"Unknown KVM exit: %d\n" , run->exit_reason);break ;
Signature · 1 line
1.9.1
PATCH 16/108 openpic: avoid buffer overrun on incoming migration
In reply to Michael RothCVE-2013-4534
opp->nb_cpus is read from the wire and used to determine how many IRQDest elements to read into opp->dst[]. If the value exceeds the length of opp->dst[], MAX_CPU, opp->dst[] can be overrun with arbitrary data from the wire.
Fix this by failing migration if the value read from the wire exceeds MAX_CPU.
--- hw/intc/openpic.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
hw/intc/openpic.c +14 -2
@@ -41,6 +41,7 @@#include "hw/sysbus.h" #include "hw/pci/msi.h" #include "qemu/bitops.h" +#include "qapi/qmp/qerror.h" //#define DEBUG_OPENPIC
@@ -1416,7 +1417,7 @@ static void openpic_load_IRQ_queue(QEMUFile* f, IRQQueue *q)static int openpic_load (QEMUFile * f,void *opaque,int version_id) {OpenPICState *opp = (OpenPICState *)opaque; -unsigned int i; +unsigned int i, nb_cpus;if (version_id !=1 ) {return -EINVAL ;
@@ -1428,7 +1429,11 @@ static int openpic_load(QEMUFile* f, void *opaque, int version_id)qemu_get_be32s (f, &opp->spve);qemu_get_be32s (f, &opp->tfrr); -qemu_get_be32s (f, &opp->nb_cpus); +qemu_get_be32s (f, &nb_cpus); +if (opp->nb_cpus != nb_cpus) { +return -EINVAL ; + } +assert (nb_cpus >0 && nb_cpus <=MAX_CPU );for (i =0 ; i < opp->nb_cpus; i++) {qemu_get_sbe32s (f, &opp->dst[i].ctpr);
@@ -1567,6 +1572,13 @@ static void openpic_realize(DeviceState *dev, Error **errp) {NULL} }; +if (opp->nb_cpus >MAX_CPU ) { +error_set (errp,QERR_PROPERTY_VALUE_OUT_OF_RANGE , +TYPE_OPENPIC ,"nb_cpus" , (uint64_t )opp->nb_cpus, + (uint64_t )0 , (uint64_t )MAX_CPU ); +return ; + } +switch (opp->model) {case OPENPIC_MODEL_FSL_MPIC_20 :default :
Signature · 1 line
1.9.1
PATCH 30/108 acpi: fix tables for no-hpet configuration
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
acpi build tried to add offset of hpet table to rsdt even when hpet was disabled. If no tables follow hpet, this could lead to a malformed rsdt.
Fix it up.
To avoid such errors in the future, rearrange code slightly to make it clear that acpi_add_table stores the offset of the following table - not of the previous one.
--- hw/i386/acpi-build.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +4 -3
@@ -1410,15 +1410,16 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)/* ACPI tables pointed to by RSDT */ acpi_add_table (table_offsets, tables->table_data);build_fadt (tables->table_data, tables->linker, &pm, facs, dsdt); -acpi_add_table (table_offsets, tables->table_data); +acpi_add_table (table_offsets, tables->table_data);build_ssdt (tables->table_data, tables->linker, &cpu, &pm, &misc, &pci, guest_info); -acpi_add_table (table_offsets, tables->table_data); -build_madt (tables->table_data, tables->linker, &cpu, guest_info);acpi_add_table (table_offsets, tables->table_data); +build_madt (tables->table_data, tables->linker, &cpu, guest_info); +if (misc.has_hpet) { +acpi_add_table (table_offsets, tables->table_data);build_hpet (tables->table_data, tables->linker); }if (guest_info->numa_nodes) {
Signature · 1 line
1.9.1
PATCH 31/108 stellaris_enet: block migration
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
Incoming migration with stellaris_enet is unsafe. It's being reworked, but for now, simply block it since noone is using it anyway.
Block outgoing migration for good measure.
CVE-2013-4532
--- hw/net/stellaris_enet.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
hw/net/stellaris_enet.c +10 -1
@@ -8,6 +8,7 @@*/ #include "hw/sysbus.h" #include "net/net.h" +#include "migration/migration.h" #include <zlib.h> //#define DEBUG_STELLARIS_ENET 1
@@ -75,6 +76,7 @@ typedef struct {NICConf conf;qemu_irq irq;MemoryRegion mmio; +Error *migration_blocker; } stellaris_enet_state;static void stellaris_enet_update (stellaris_enet_state *s)
@@ -362,7 +364,7 @@ static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id)stellaris_enet_state *s = (stellaris_enet_state *)opaque;int i; -if (version_id !=1 ) +if (1 )return -EINVAL ; s->ris =qemu_get_be32 (f);
@@ -423,6 +425,10 @@ static int stellaris_enet_init(SysBusDevice *sbd)stellaris_enet_reset (s);register_savevm (dev,"stellaris_enet" ,-1 ,1 , stellaris_enet_save, stellaris_enet_load, s); + +error_setg (&s->migration_blocker, +"stellaris_enet does not support migration" ); +migrate_add_blocker (s->migration_blocker);return 0 ; }
@@ -430,6 +436,9 @@ static void stellaris_enet_unrealize(DeviceState *dev, Error **errp) {stellaris_enet_state *s =STELLARIS_ENET (dev); +migrate_del_blocker (s->migration_blocker); +error_free (s->migration_blocker); +unregister_savevm (DEVICE (s),"stellaris_enet" , s);memory_region_destroy (&s->mmio);
Signature · 1 line
1.9.1
PATCH 33/108 target-i386: fix set of registers zeroed on reset
In reply to Michael RothFrom: Paolo Bonzini <[email protected]>
BND0-3, BNDCFGU, BNDCFGS, BNDSTATUS were not zeroed on reset, but they should be (Intel Instruction Set Extensions Programming Reference 319433-015, pages 9-4 and 9-6). Same for YMM.
XCR0 should be reset to 1.
TSC and TSC_RESET were zeroed already by the memset, remove the explicit assignments.
--- target-i386/cpu.c | 3 +-- target-i386/cpu.h | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-)
target-i386/cpu.c +1 -2
@@ -2476,8 +2476,7 @@ static void x86_cpu_reset(CPUState *s)cpu_breakpoint_remove_all (s,BP_CPU );cpu_watchpoint_remove_all (s,BP_CPU ); - env->tsc_adjust =0 ; - env->tsc =0 ; + env->xcr0 =1 ;#if !defined(CONFIG_USER_ONLY )/* We hard-wire the BSP to the first CPU. */
target-i386/cpu.h +6 -5
@@ -797,6 +797,10 @@ typedef struct CPUX86State {target_ulong cr[5 ];/* NOTE: cr1 is unused */ int32_t a20_mask; +BNDReg bnd_regs[4 ]; +BNDCSReg bndcs_regs; +uint64_t msr_bndcfgs; +/* FPU state */ unsigned int fpstt;/* top of stack index */ uint16_t fpus;
@@ -819,6 +823,8 @@ typedef struct CPUX86State {XMMReg xmm_t0;MMXReg mmx_t0; +XMMReg ymmh_regs[CPU_NB_REGS ]; +/* sysenter registers */ uint32_t sysenter_cs;target_ulong sysenter_esp;
@@ -928,12 +934,7 @@ typedef struct CPUX86State {uint16_t fpus_vmstate;uint16_t fptag_vmstate;uint16_t fpregs_format_vmstate; -uint64_t xstate_bv; -XMMReg ymmh_regs[CPU_NB_REGS ]; -BNDReg bnd_regs[4 ]; -BNDCSReg bndcs_regs; -uint64_t msr_bndcfgs;uint64_t xcr0;
Signature · 1 line
1.9.1
PATCH 32/108 s390x/kvm: rework KVM synchronize to tracing for some ONEREGS
In reply to Michael RothFrom: Christian Borntraeger <[email protected]>
Some ONE_REGS on s390 are not protected by a capability. Older kernels might not provide those and return an error. Fortunately these registers are only critical for the migration path. There is no need to error out on reset and normal runtime. Furthermore, these kernels don't provide a proper dirty bitmap anyway, so let's use tracing for those errors.
Also provide generic one reg helper to simplify the code.
--- target-s390x/kvm.c | 143 ++++++++++++++++++++++++----------------------------- trace-events | 4 ++ 2 files changed, 69 insertions(+), 78 deletions(-)
target-s390x/kvm.c +65 -78
@@ -36,6 +36,7 @@#include "sysemu/device_tree.h" #include "qapi/qmp/qjson.h" #include "monitor/monitor.h" +#include "trace.h" /* #define DEBUG_KVM */
@@ -128,14 +129,42 @@ void kvm_arch_reset_vcpu(CPUState *cpu) } } +static int kvm_set_one_reg (CPUState *cs,uint64_t id,void *source) +{ +struct kvm_one_reg reg; +int r; + + reg.id = id; + reg.addr = (uint64_t ) source; + r =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); +if (r) { +trace_kvm_failed_reg_set (id,strerror (errno)); + } +return r; +} + +static int kvm_get_one_reg (CPUState *cs,uint64_t id,void *target) +{ +struct kvm_one_reg reg; +int r; + + reg.id = id; + reg.addr = (uint64_t ) target; + r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); +if (r) { +trace_kvm_failed_reg_get (id,strerror (errno)); + } +return r; +} + +int kvm_arch_put_registers (CPUState *cs,int level) {S390CPU *cpu =S390_CPU (cs);CPUS390XState *env = &cpu->env; -struct kvm_one_reg reg;struct kvm_sregs sregs;struct kvm_regs regs; -int ret; +int r;int i;/* always save the PSW and the GPRS*/
@@ -151,9 +180,9 @@ int kvm_arch_put_registers(CPUState *cs, int level)for (i =0 ; i <16 ; i++) { regs.gprs[i] = env->regs[i]; } - ret =kvm_vcpu_ioctl (cs,KVM_SET_REGS , ®s); -if (ret <0 ) { -return ret; + r =kvm_vcpu_ioctl (cs,KVM_SET_REGS , ®s); +if (r <0 ) { +return r; } }
@@ -162,47 +191,27 @@ int kvm_arch_put_registers(CPUState *cs, int level)return 0 ; } - reg.id =KVM_REG_S390_CPU_TIMER ; - reg.addr = (__u64)&(env->cputm); - ret =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); -if (ret <0 ) { -return ret; - } - - reg.id =KVM_REG_S390_CLOCK_COMP ; - reg.addr = (__u64)&(env->ckc); - ret =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); -if (ret <0 ) { -return ret; - } - - reg.id =KVM_REG_S390_TODPR ; - reg.addr = (__u64)&(env->todpr); - ret =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); -if (ret <0 ) { -return ret; - } +/* +* These ONE_REGS are not protected by a capability. As they are only +* necessary for migration we just trace a possible error, but don't +* return with an error return code. +*/ +kvm_set_one_reg (cs,KVM_REG_S390_CPU_TIMER , &env->cputm); +kvm_set_one_reg (cs,KVM_REG_S390_CLOCK_COMP , &env->ckc); +kvm_set_one_reg (cs,KVM_REG_S390_TODPR , &env->todpr);if (cap_async_pf) { - reg.id =KVM_REG_S390_PFTOKEN ; - reg.addr = (__u64)&(env->pfault_token); - ret =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); -if (ret <0 ) { -return ret; + r =kvm_set_one_reg (cs,KVM_REG_S390_PFTOKEN , &env->pfault_token); +if (r <0 ) { +return r; } - - reg.id =KVM_REG_S390_PFCOMPARE ; - reg.addr = (__u64)&(env->pfault_compare); - ret =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); -if (ret <0 ) { -return ret; + r =kvm_set_one_reg (cs,KVM_REG_S390_PFCOMPARE , &env->pfault_compare); +if (r <0 ) { +return r; } - - reg.id =KVM_REG_S390_PFSELECT ; - reg.addr = (__u64)&(env->pfault_select); - ret =kvm_vcpu_ioctl (cs,KVM_SET_ONE_REG , ®); -if (ret <0 ) { -return ret; + r =kvm_set_one_reg (cs,KVM_REG_S390_PFSELECT , &env->pfault_select); +if (r <0 ) { +return r; } }
@@ -220,9 +229,9 @@ int kvm_arch_put_registers(CPUState *cs, int level) sregs.acrs[i] = env->aregs[i]; sregs.crs[i] = env->cregs[i]; } - ret =kvm_vcpu_ioctl (cs,KVM_SET_SREGS , &sregs); -if (ret <0 ) { -return ret; + r =kvm_vcpu_ioctl (cs,KVM_SET_SREGS , &sregs); +if (r <0 ) { +return r; } }
@@ -240,7 +249,6 @@ int kvm_arch_get_registers(CPUState *cs) {S390CPU *cpu =S390_CPU (cs);CPUS390XState *env = &cpu->env; -struct kvm_one_reg reg;struct kvm_sregs sregs;struct kvm_regs regs;int i, r;
@@ -288,46 +296,25 @@ int kvm_arch_get_registers(CPUState *cs) env->psa = cs->kvm_run->s.regs.prefix; } -/* One Regs */ - reg.id =KVM_REG_S390_CPU_TIMER ; - reg.addr = (__u64)&(env->cputm); - r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); -if (r <0 ) { -return r; - } - - reg.id =KVM_REG_S390_CLOCK_COMP ; - reg.addr = (__u64)&(env->ckc); - r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); -if (r <0 ) { -return r; - } - - reg.id =KVM_REG_S390_TODPR ; - reg.addr = (__u64)&(env->todpr); - r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); -if (r <0 ) { -return r; - } +/* +* These ONE_REGS are not protected by a capability. As they are only +* necessary for migration we just trace a possible error, but don't +* return with an error return code. +*/ +kvm_get_one_reg (cs,KVM_REG_S390_CPU_TIMER , &env->cputm); +kvm_get_one_reg (cs,KVM_REG_S390_CLOCK_COMP , &env->ckc); +kvm_get_one_reg (cs,KVM_REG_S390_TODPR , &env->todpr);if (cap_async_pf) { - reg.id =KVM_REG_S390_PFTOKEN ; - reg.addr = (__u64)&(env->pfault_token); - r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); + r =kvm_get_one_reg (cs,KVM_REG_S390_PFTOKEN , &env->pfault_token);if (r <0 ) {return r; } - - reg.id =KVM_REG_S390_PFCOMPARE ; - reg.addr = (__u64)&(env->pfault_compare); - r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); + r =kvm_get_one_reg (cs,KVM_REG_S390_PFCOMPARE , &env->pfault_compare);if (r <0 ) {return r; } - - reg.id =KVM_REG_S390_PFSELECT ; - reg.addr = (__u64)&(env->pfault_select); - r =kvm_vcpu_ioctl (cs,KVM_GET_ONE_REG , ®); + r =kvm_get_one_reg (cs,KVM_REG_S390_PFSELECT , &env->pfault_select);if (r <0 ) {return r; }
trace-events +4 -0
@@ -1223,3 +1223,7 @@ xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO space (ad # hw/pci/pci_host.c pci_cfg_read(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x -> 0x%x" pci_cfg_write(const char *dev, unsigned devid, unsigned fnid, unsigned offs, unsigned val) "%s %02u:%u @0x%x <- 0x%x" + +# target-s390/kvm.c +kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s" +kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
Signature · 1 line
1.9.1
PATCH 36/108 target-arm: Make vbar_write 64bit friendly on 32bit hosts
In reply to Michael RothFrom: "Edgar E. Iglesias" <[email protected]>
Message-id: [email protected]
--- target-arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-arm/helper.c +1 -1
@@ -632,7 +632,7 @@ static void vbar_write(CPUARMState *env, const ARMCPRegInfo *ri,* contexts. (ARMv8 would permit us to do no masking at all, but ARMv7 * requires the bottom five bits to be RAZ/WI because they're UNK/SBZP.) */ - env->cp15.c12_vbar = value & ~0x1Ful ; + env->cp15.c12_vbar = value & ~0x1FULL ; }static uint64_t ccsidr_read (CPUARMState *env,const ARMCPRegInfo *ri)
Signature · 1 line
1.9.1
PATCH 37/108 linux-user/elfload.c: Fix incorrect ARM HWCAP bits
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The ELF HWCAP bits for ARM features THUMBEE, NEON, VFPv3 and VFPv3D16 are all off by one compared to the kernel definitions. Fix this discrepancy and add in the missing CRUNCH bit which was the cause of the off-by-one error. (We don't emulate any of the CPUs which have that weird hardware, so it's otherwise uninteresting to us.)
--- linux-user/elfload.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
linux-user/elfload.c +5 -4
@@ -346,10 +346,11 @@ enumARM_HWCAP_ARM_EDSP =1 <<7 ,ARM_HWCAP_ARM_JAVA =1 <<8 ,ARM_HWCAP_ARM_IWMMXT =1 <<9 , -ARM_HWCAP_ARM_THUMBEE =1 <<10 , -ARM_HWCAP_ARM_NEON =1 <<11 , - ARM_HWCAP_ARM_VFPv3 =1 <<12 , - ARM_HWCAP_ARM_VFPv3D16 = 1 << 13, +ARM_HWCAP_ARM_CRUNCH =1 <<10 , +ARM_HWCAP_ARM_THUMBEE =1 <<11 , +ARM_HWCAP_ARM_NEON =1 <<12 , + ARM_HWCAP_ARM_VFPv3 =1 <<13 , + ARM_HWCAP_ARM_VFPv3D16 = 1 << 14, };#ifndef TARGET_AARCH64
Signature · 1 line
1.9.1
PATCH 40/108 spapr_pci: Fix number of returned vectors in ibm, change-msi
In reply to Michael RothFrom: Alexey Kardashevskiy <[email protected]>
Current guest kernels try allocating as many vectors as the quota is. For example, in the case of virtio-net (which has just 3 vectors) the guest requests 4 vectors (that is the quota in the test) and the existing ibm,change-msi handler returns 4. But before it returns, it calls msix_set_message() in a loop and corrupts memory behind the end of msix_table.
This limits the number of vectors returned by ibm,change-msi to the maximum supported by the actual device.
--- hw/ppc/spapr_pci.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
hw/ppc/spapr_pci.c +15 -0
@@ -343,6 +343,21 @@ static void rtas_ibm_change_msi(PowerPCCPU *cpu, sPAPREnvironment *spapr,/* There is no cached config, allocate MSIs */ if (!phb->msi_table[ndev].nvec) { +int max_irqs =0 ; +if (ret_intr_type ==RTAS_TYPE_MSI ) { + max_irqs =msi_nr_vectors_allocated (pdev); + }else if (ret_intr_type ==RTAS_TYPE_MSIX ) { + max_irqs = pdev->msix_entries_nr; + } +if (!max_irqs) { +error_report ("Requested interrupt type %d is not enabled for device#%d" , + ret_intr_type, ndev); +rtas_st (rets,0 ,-1 );/* Hardware error */ +return ; + } +if (req_num > max_irqs) { + req_num = max_irqs; + } irq =spapr_allocate_irq_block (req_num, false, ret_intr_type ==RTAS_TYPE_MSI );if (irq <0 ) {
Signature · 1 line
1.9.1
PATCH 38/108 linux-user/elfload.c: Update ARM HWCAP bits
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The kernel has added support for a number of new ARM HWCAP bits; add them to QEMU, including support for setting them where we have a corresponding CPU feature bit.
We were also incorrectly setting the VFPv3D16 HWCAP -- this means "only 16 D registers", not "supports 16-bit floating point format"; since QEMU always has 32 D registers for VFPv3, we can just remove the line that incorrectly set this bit.
The kernel does not set the HWCAP_FPA even if it is providing FPA emulation via nwfpe, so don't set this bit in QEMU either.
--- linux-user/elfload.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
linux-user/elfload.c +20 -2
@@ -351,6 +351,13 @@ enumARM_HWCAP_ARM_NEON =1 <<12 , ARM_HWCAP_ARM_VFPv3 =1 <<13 , ARM_HWCAP_ARM_VFPv3D16 =1 <<14 , +ARM_HWCAP_ARM_TLS =1 <<15 , + ARM_HWCAP_ARM_VFPv4 =1 <<16 , +ARM_HWCAP_ARM_IDIVA =1 <<17 , +ARM_HWCAP_ARM_IDIVT =1 <<18 , +ARM_HWCAP_ARM_VFPD32 =1 <<19 , +ARM_HWCAP_ARM_LPAE =1 <<20 , + ARM_HWCAP_ARM_EVTSTRM = 1 << 21, };#ifndef TARGET_AARCH64
@@ -428,17 +435,28 @@ static uint32_t get_elf_hwcap(void) hwcaps |=ARM_HWCAP_ARM_HALF ; hwcaps |=ARM_HWCAP_ARM_THUMB ; hwcaps |=ARM_HWCAP_ARM_FAST_MULT ; - hwcaps |=ARM_HWCAP_ARM_FPA ;/* probe for the extra features */ #define GET_FEATURE (feat, hwcap) \ do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) +/* EDSP is in v5TE and above, but all our v5 CPUs are v5TE */ +GET_FEATURE (ARM_FEATURE_V5 ,ARM_HWCAP_ARM_EDSP );GET_FEATURE (ARM_FEATURE_VFP ,ARM_HWCAP_ARM_VFP );GET_FEATURE (ARM_FEATURE_IWMMXT ,ARM_HWCAP_ARM_IWMMXT );GET_FEATURE (ARM_FEATURE_THUMB2EE ,ARM_HWCAP_ARM_THUMBEE );GET_FEATURE (ARM_FEATURE_NEON ,ARM_HWCAP_ARM_NEON );GET_FEATURE (ARM_FEATURE_VFP3 , ARM_HWCAP_ARM_VFPv3); -GET_FEATURE (ARM_FEATURE_VFP_FP16 , ARM_HWCAP_ARM_VFPv3D16); +GET_FEATURE (ARM_FEATURE_V6K ,ARM_HWCAP_ARM_TLS ); +GET_FEATURE (ARM_FEATURE_VFP4 , ARM_HWCAP_ARM_VFPv4); +GET_FEATURE (ARM_FEATURE_ARM_DIV ,ARM_HWCAP_ARM_IDIVA ); +GET_FEATURE (ARM_FEATURE_THUMB_DIV ,ARM_HWCAP_ARM_IDIVT ); +/* All QEMU's VFPv3 CPUs have 32 registers, see VFP_DREG in translate.c. +* Note that the ARM_HWCAP_ARM_VFPv3D16 bit is always the inverse of +* ARM_HWCAP_ARM_VFPD32 (and so always clear for QEMU); it is unrelated +* to our VFP_FP16 feature bit. +*/ +GET_FEATURE (ARM_FEATURE_VFP3 ,ARM_HWCAP_ARM_VFPD32 ); +GET_FEATURE (ARM_FEATURE_LPAE ,ARM_HWCAP_ARM_LPAE );#undef GET_FEATUREreturn hwcaps;
Signature · 1 line
1.9.1
PATCH 35/108 target-arm: A64: Handle blr lr
In reply to Michael RothFrom: "Edgar E. Iglesias" <[email protected]>
For linked branches, updates to the link register happen conceptually after the read of the branch target register.
Message-id: [email protected]
--- target-arm/translate-a64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +2 -1
@@ -1432,8 +1432,10 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)switch (opc) {case 0 :/* BR */ case 2 :/* RET */ +tcg_gen_mov_i64 (cpu_pc,cpu_reg (s, rn));break ;case 1 :/* BLR */ +tcg_gen_mov_i64 (cpu_pc,cpu_reg (s, rn));tcg_gen_movi_i64 (cpu_reg (s,30 ), s->pc);break ;case 4 :/* ERET */
@@ -1449,7 +1451,6 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)return ; } -tcg_gen_mov_i64 (cpu_pc,cpu_reg (s, rn)); s->is_jmp =DISAS_JUMP ; }
Signature · 1 line
1.9.1
PATCH 39/108 linux-user/elfload.c: Fix A64 code which was incorrectly acting like A32
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The ARM target-specific code in elfload.c was incorrectly allowing the 64-bit ARM target to use most of the existing 32-bit definitions:
most noticably this meant that our HWCAP bits passed to the guest were wrong, and register handling when dumping core was totally broken. Fix this by properly separating the 64 and 32 bit code, since they have more differences than similarities.
--- linux-user/elfload.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 13 deletions(-)
linux-user/elfload.c +73 -13
@@ -267,17 +267,15 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en#ifdef TARGET_ARM +#ifndef TARGET_AARCH64 +/* 32 bit ARM definitions */ +#define ELF_START_MMAP 0x80000000#define elf_check_arch (x) ((x) == ELF_MACHINE)#define ELF_ARCH ELF_MACHINE - -#ifdef TARGET_AARCH64 -#define ELF_CLASS ELFCLASS64 -#else #define ELF_CLASS ELFCLASS32 -#endif static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop)
@@ -285,10 +283,6 @@ static inline void init_thread(struct target_pt_regs *regs,abi_long stack = infop->start_stack;memset (regs,0 ,sizeof (*regs)); -#ifdef TARGET_AARCH64 - regs->pc = infop->entry & ~0x3ULL ; - regs->sp = stack; -#else regs->ARM_cpsr =0x10 ;if (infop->entry &1 ) regs->ARM_cpsr |=CPSR_T ;
@@ -302,7 +296,6 @@ static inline void init_thread(struct target_pt_regs *regs,/* For uClinux PIC binaries. */ /* XXX: Linux does this only on ARM with no MMU (do we care ?) */ regs->ARM_r10 = infop->start_data; -#endif }#define ELF_NREG 18
@@ -360,7 +353,6 @@ enum ARM_HWCAP_ARM_EVTSTRM = 1 << 21, }; -#ifndef TARGET_AARCH64 /* The commpage only exists for 32 bit kernels */ #define TARGET_HAS_VALIDATE_GUEST_SPACE
@@ -422,7 +414,6 @@ static int validate_guest_space(unsigned long guest_base,return 1 ;/* All good */ } -#endif #define ELF_HWCAP get_elf_hwcap()
@@ -462,7 +453,76 @@ static uint32_t get_elf_hwcap(void)return hwcaps; } -#endif +#else +/* 64 bit ARM definitions */ +#define ELF_START_MMAP 0x80000000 + +#define elf_check_arch (x) ((x) == ELF_MACHINE) + +#define ELF_ARCH ELF_MACHINE +#define ELF_CLASS ELFCLASS64 +#define ELF_PLATFORM "aarch64" + +static inline void init_thread (struct target_pt_regs *regs, +struct image_info *infop) +{ +abi_long stack = infop->start_stack; +memset (regs,0 ,sizeof (*regs)); + + regs->pc = infop->entry & ~0x3ULL ; + regs->sp = stack; +} + +#define ELF_NREG 34 +typedef target_elf_greg_t target_elf_gregset_t [ELF_NREG ]; + +static void elf_core_copy_regs (target_elf_gregset_t *regs, +const CPUARMState *env) +{ +int i; + +for (i =0 ; i <32 ; i++) { + (*regs)[i] =tswapreg (env->xregs[i]); + } + (*regs)[32 ] =tswapreg (env->pc); + (*regs)[33 ] =tswapreg (pstate_read ((CPUARMState *)env)); +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +enum { +ARM_HWCAP_A64_FP =1 <<0 , +ARM_HWCAP_A64_ASIMD =1 <<1 , +ARM_HWCAP_A64_EVTSTRM =1 <<2 , +ARM_HWCAP_A64_AES =1 <<3 , +ARM_HWCAP_A64_PMULL =1 <<4 , +ARM_HWCAP_A64_SHA1 =1 <<5 , +ARM_HWCAP_A64_SHA2 =1 <<6 , +ARM_HWCAP_A64_CRC32 =1 <<7 , +}; + +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap (void ) +{ +ARMCPU *cpu =ARM_CPU (thread_cpu); +uint32_t hwcaps =0 ; + + hwcaps |=ARM_HWCAP_A64_FP ; + hwcaps |=ARM_HWCAP_A64_ASIMD ; + +/* probe for the extra features */ +#define GET_FEATURE (feat, hwcap) \ + do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) +GET_FEATURE (ARM_FEATURE_V8_AES ,ARM_HWCAP_A64_PMULL ); +#undef GET_FEATURE + +return hwcaps; +} + +#endif /* not TARGET_AARCH64 */ +#endif /* TARGET_ARM */ #ifdef TARGET_UNICORE32
Signature · 1 line
1.9.1
PATCH 26/108 arm: translate.c: Fix smlald Instruction
In reply to Michael RothFrom: Peter Crosthwaite <[email protected]>
The smlald (and probably smlsld) instruction was doing incorrect sign extensions of the operands amongst 64bit result calculation. The instruction psuedo-code is:
operand2 = if m_swap then ROR(R[m],16) else R[m]; product1 = SInt(R[n]<15:0>) * SInt(operand2<15:0>); product2 = SInt(R[n]<31:16>) * SInt(operand2<31:16>); result = product1 + product2 + SInt(R[dHi]:R[dLo]); R[dHi] = result<63:32>;
R[dLo] = result<31:0>;
The result calculation should be done in 64 bit arithmetic, and hence product1 and product2 should be sign extended to 64b before calculation.
The current implementation was adding product1 and product2 together then sign-extending the intermediate result leading to false negatives.
E.G. if product1 = product2 = 0x4000000, their sum = 0x80000000, which will be incorrectly interpreted as -ve on sign extension.
We fix by doing the 64b extensions on both product1 and product2 before any addition/subtraction happens.
We also fix where we were possibly incorrectly setting the Q saturation flag for SMLSLD, which the ARM ARM specifically says is not set.
Message-id: 2cddb6f5a15be4ab8d2160f3499d128ae93d304d.1397704570.git.peter.crosthwaite@xilinx.com
--- target-arm/translate.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
target-arm/translate.c +23 -11
@@ -8328,27 +8328,39 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s)if (insn & (1 <<5 ))gen_swap_half (tmp2);gen_smul_dual (tmp, tmp2); -if (insn & (1 <<6 )) { -/* This subtraction cannot overflow. */ -tcg_gen_sub_i32 (tmp, tmp, tmp2); - }else { -/* This addition cannot overflow 32 bits; -* however it may overflow considered as a signed -* operation, in which case we must set the Q flag. -*/ -gen_helper_add_setq (tmp, cpu_env, tmp, tmp2); - } -tcg_temp_free_i32 (tmp2);if (insn & (1 <<22 )) {/* smlald, smlsld */ +TCGv_i64 tmp64_2; + tmp64 =tcg_temp_new_i64 (); + tmp64_2 =tcg_temp_new_i64 ();tcg_gen_ext_i32_i64 (tmp64, tmp); +tcg_gen_ext_i32_i64 (tmp64_2, tmp2);tcg_temp_free_i32 (tmp); +tcg_temp_free_i32 (tmp2); +if (insn & (1 <<6 )) { +tcg_gen_sub_i64 (tmp64, tmp64, tmp64_2); + }else { +tcg_gen_add_i64 (tmp64, tmp64, tmp64_2); + } +tcg_temp_free_i64 (tmp64_2);gen_addq (s, tmp64, rd, rn);gen_storeq_reg (s, rd, rn, tmp64);tcg_temp_free_i64 (tmp64); }else {/* smuad, smusd, smlad, smlsd */ +if (insn & (1 <<6 )) { +/* This subtraction cannot overflow. */ +tcg_gen_sub_i32 (tmp, tmp, tmp2); + }else { +/* This addition cannot overflow 32 bits; +* however it may overflow considered as a +* signed operation, in which case we must set +* the Q flag. +*/ +gen_helper_add_setq (tmp, cpu_env, tmp, tmp2); + } +tcg_temp_free_i32 (tmp2);if (rd !=15 ) { tmp2 =load_reg (s, rd);
Signature · 1 line
1.9.1
PATCH 41/108 configure: remove bashism
In reply to Michael RothFrom: Michael Tokarev <[email protected]>
Commit e26110cfc67d48 added a check for shacmd to create a hash for modules. This check in configure is using bash construct &> to redirect both stdout and stderr, which does fun things on some shells. Get rid of it, use standard redirection instead.
--- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configure +1 -1
@@ -2624,7 +2624,7 @@ done if test "$modules" = yes; then shacmd_probe="sha1sum sha1 shasum" for c in $shacmd_probe; do - if which $c &>/dev/null; then + if which $c >/dev/null 2>&1; then shacmd="$c" break fi
Signature · 1 line
1.9.1
PATCH 43/108 pci-assign: limit # of msix vectors
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
KVM only supports MSIX table size up to 256 vectors, but some assigned devices support more vectors, at the moment attempts to assign them fail with EINVAL.
Tweak the MSIX capability exposed to guest to limit table size to a supported value.
--- hw/i386/kvm/pci-assign.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/i386/kvm/pci-assign.c +6 -6
@@ -1258,6 +1258,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)if (pos !=0 &&kvm_device_msix_supported (kvm_state)) {int bar_nr;uint32_t msix_table_entry; +uint16_t msix_max;if (!check_irqchip_in_kernel ()) {return -ENOTSUP ;
@@ -1269,9 +1270,10 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev) } pci_dev->msix_cap = pos; -pci_set_word (pci_dev->config + pos +PCI_MSIX_FLAGS , -pci_get_word (pci_dev->config + pos +PCI_MSIX_FLAGS ) & -PCI_MSIX_FLAGS_QSIZE ); + msix_max = (pci_get_word (pci_dev->config + pos +PCI_MSIX_FLAGS ) & +PCI_MSIX_FLAGS_QSIZE ) +1 ; + msix_max =MIN (msix_max,KVM_MAX_MSIX_PER_DEV ); +pci_set_word (pci_dev->config + pos +PCI_MSIX_FLAGS , msix_max -1 );/* Only enable and function mask bits are writable */ pci_set_word(pci_dev->wmask + pos + PCI_MSIX_FLAGS,
@@ -1281,9 +1283,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev) bar_nr = msix_table_entry &PCI_MSIX_FLAGS_BIRMASK ; msix_table_entry &= ~PCI_MSIX_FLAGS_BIRMASK ; dev->msix_table_addr = pci_region[bar_nr].base_addr + msix_table_entry; - dev->msix_max =pci_get_word (pci_dev->config + pos +PCI_MSIX_FLAGS ); - dev->msix_max &=PCI_MSIX_FLAGS_QSIZE ; - dev->msix_max +=1 ; + dev->msix_max = msix_max; }/* Minimal PM support, nothing writable, device appears to NAK changes */
Signature · 1 line
1.9.1
PATCH 42/108 Revert "qapi: Clean up superfluous null check in qapi_dealloc_type_str()"
In reply to Michael RothFrom: Peter Lieven <[email protected]>
This reverts commit 25a7017555f1b4aeb543b5d323ff4afb8f9c5437.
Turns out the argument *can* be null: QEMU now segfaults if it receives an invalid parameter via a qmp command instead of throwing an error.
For example:
{ "execute": "blockdev-add",
"arguments": { "options" : { "driver": "invalid-driver" } } }--- qapi/qapi-dealloc-visitor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
qapi/qapi-dealloc-visitor.c +3 -1
@@ -131,7 +131,9 @@ static void qapi_dealloc_end_list(Visitor *v, Error **errp)static void qapi_dealloc_type_str (Visitor *v,char **obj,const char *name,Error **errp) { -g_free (*obj); +if (obj) { +g_free (*obj); + } } static void qapi_dealloc_type_int(Visitor *v, int64_t *obj, const char *name,
Signature · 1 line
1.9.1
PATCH 45/108 qcow1: Make padding in the header explicit
In reply to Michael RothFrom: Kevin Wolf <[email protected]>
We were relying on all compilers inserting the same padding in the header struct that is used for the on-disk format. Let's not do that. Mark the struct as packed and insert an explicit padding field for compatibility.
--- block/qcow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/qcow.c +2 -1
@@ -48,9 +48,10 @@ typedef struct QCowHeader {uint64_t size;/* in bytes */ uint8_t cluster_bits;uint8_t l2_bits; +uint16_t padding;uint32_t crypt_method;uint64_t l1_table_offset; -} QCowHeader; +}QEMU_PACKED QCowHeader;#define L2_CACHE_SIZE 16
Signature · 1 line
1.9.1
PATCH 47/108 qcow1: Validate L2 table size (CVE-2014-0222)
In reply to Michael RothFrom: Kevin Wolf <[email protected]>
Too large L2 table sizes cause unbounded allocations. Images actually created by qemu-img only have 512 byte or 4k L2 tables.
To keep things consistent with cluster sizes, allow ranges between 512 bytes and 64k (in fact, down to 1 entry = 8 bytes is technically working, but L2 table sizes smaller than a cluster don't make a lot of sense).
This also means that the number of bytes on the virtual disk that are described by the same L2 table is limited to at most 8k * 64k or 2^29, preventively avoiding any integer overflows.
--- block/qcow.c | 8 ++++++++ tests/qemu-iotests/092 | 15 +++++++++++++++ tests/qemu-iotests/092.out | 11 +++++++++++ 3 files changed, 34 insertions(+)
block/qcow.c +8 -0
@@ -138,6 +138,14 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } +/* l2_bits specifies number of entries; storing a uint64_t in each entry, +* so bytes = num_entries << 3. */ +if (header.l2_bits <9 -3 || header.l2_bits >16 -3 ) { +error_setg (errp,"L2 table size must be between 512 and 64k" ); + ret = -EINVAL ; + goto fail; + } +if (header.crypt_method >QCOW_CRYPT_AES ) {error_setg (errp,"invalid encryption method in qcow header" ); ret = -EINVAL ;
tests/qemu-iotests/092 +15 -0
@@ -44,6 +44,7 @@ _supported_proto generic _supported_os Linux offset_cluster_bits=32 +offset_l2_bits=33 echo echo "== Invalid cluster size =="
@@ -57,6 +58,20 @@ poke_file "$TEST_IMG" "$offset_cluster_bits" "\x08" poke_file "$TEST_IMG" "$offset_cluster_bits" "\x11" { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +echo +echo "== Invalid L2 table size ==" +_make_test_img 64M +poke_file "$TEST_IMG" "$offset_l2_bits" "\xff" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +poke_file "$TEST_IMG" "$offset_l2_bits" "\x05" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +poke_file "$TEST_IMG" "$offset_l2_bits" "\x0e" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir + +# 1 << 0x1b = 2^31 / L2_CACHE_SIZE +poke_file "$TEST_IMG" "$offset_l2_bits" "\x1b" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/092.out +11 -0
@@ -10,4 +10,15 @@ qemu-io: can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and no file open, try 'help open' qemu-io: can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k no file open, try 'help open' + +== Invalid L2 table size == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +qemu-io: can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k +no file open, try 'help open' *** done
Signature · 1 line
1.9.1
PATCH 44/108 virtio: allow mapping up to max queue size
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
It's a loop from i < num_sg and the array is VIRTQUEUE_MAX_SIZE - so it's OK if the value read is VIRTQUEUE_MAX_SIZE.
Not a big problem in practice as people don't use
such big queues, but it's inelegant.
--- hw/virtio/virtio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio.c +1 -1
@@ -430,7 +430,7 @@ void virtqueue_map_sg(struct iovec *sg, hwaddr *addr,unsigned int i;hwaddr len; -if (num_sg >=VIRTQUEUE_MAX_SIZE ) { +if (num_sg >VIRTQUEUE_MAX_SIZE ) {error_report ("virtio: map attempt out of bounds: %zd > %d" , num_sg,VIRTQUEUE_MAX_SIZE );exit (1 );
Signature · 1 line
1.9.1
PATCH 46/108 qcow1: Check maximum cluster size
In reply to Michael RothFrom: Kevin Wolf <[email protected]>
Huge values for header.cluster_bits cause unbounded allocations (e.g. for s->cluster_cache) and crash qemu this way. Less huge values may survive those allocations, but can cause integer overflows later on.
The only cluster sizes that qemu can create are 4k (for standalone images) and 512 (for images with backing files), so we can limit it to 64k.
Conflicts:
tests/qemu-iotests/group
*removed context lines for tests not present in v2.0.0
--- block/qcow.c | 10 ++++++-- tests/qemu-iotests/092 | 63 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/092.out | 13 ++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100755 tests/qemu-iotests/092 create mode 100644 tests/qemu-iotests/092.out
block/qcow.c +8 -2
@@ -127,11 +127,17 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } -if (header.size <=1 || header.cluster_bits <9 ) { -error_setg (errp,"invalid value in qcow header" ); +if (header.size <=1 ) { +error_setg (errp,"Image size is too small (must be at least 2 bytes)" ); ret = -EINVAL ; goto fail; } +if (header.cluster_bits <9 || header.cluster_bits >16 ) { +error_setg (errp,"Cluster size must be between 512 and 64k" ); + ret = -EINVAL ; + goto fail; + } +if (header.crypt_method >QCOW_CRYPT_AES ) {error_setg (errp,"invalid encryption method in qcow header" ); ret = -EINVAL ;
tests/qemu-iotests/092 new file +63 -0
63 lines not on this page · raw message
tests/qemu-iotests/092.out new file +13 -0
@@ -0,0 +1,13 @@ +QA output created by 092 + +== Invalid cluster size == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +qemu-io: can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: Cluster size must be between 512 and 64k +no file open, try 'help open' +*** done
tests/qemu-iotests/group +1 -0
@@ -95,3 +95,4 @@ 086 rw auto quick 087 rw auto 088 rw auto +092 rw auto quick
Signature · 1 line
1.9.1
PATCH 49/108 qcow1: Stricter backing file length check
In reply to Michael RothFrom: Kevin Wolf <[email protected]>
Like qcow2 since commit 6d33e8e7, error out on invalid lengths instead of silently truncating them to 1023.
Also don't rely on bdrv_pread() catching integer overflows that make len negative, but use unsigned variables in the first place.
--- block/qcow.c | 7 +++++-- tests/qemu-iotests/092 | 11 +++++++++++ tests/qemu-iotests/092.out | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
block/qcow.c +5 -2
@@ -97,7 +97,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) {BDRVQcowState *s = bs->opaque; -int len, i, shift, ret; +unsigned int len, i, shift; +int ret;QCowHeader header; ret =bdrv_pread (bs->file,0 , &header,sizeof (header));
@@ -201,7 +202,9 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,if (header.backing_file_offset !=0 ) { len = header.backing_file_size;if (len >1023 ) { - len =1023 ; +error_setg (errp,"Backing file name too long" ); + ret = -EINVAL ; + goto fail; } ret =bdrv_pread (bs->file, header.backing_file_offset, bs->backing_file, len);
tests/qemu-iotests/092 +11 -0
@@ -43,6 +43,8 @@ _supported_fmt qcow _supported_proto generic _supported_os Linux +offset_backing_file_offset=8 +offset_backing_file_size=16 offset_size=24 offset_cluster_bits=32 offset_l2_bits=33
@@ -81,6 +83,15 @@ poke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\xee\xee\xee\xee\xee" poke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff" { $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +echo +echo "== Invalid backing file length ==" +_make_test_img 64M +poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\xff" +poke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +poke_file "$TEST_IMG" "$offset_backing_file_size" "\x7f\xff\xff\xff" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/092.out +7 -0
@@ -28,4 +28,11 @@ qemu-io: can't open device TEST_DIR/t.qcow: Image too large no file open, try 'help open' qemu-io: can't open device TEST_DIR/t.qcow: Image too large no file open, try 'help open' + +== Invalid backing file length == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +qemu-io: can't open device TEST_DIR/t.qcow: Backing file name too long +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: Backing file name too long +no file open, try 'help open' *** done
Signature · 1 line
1.9.1
PATCH 48/108 qcow1: Validate image size (CVE-2014-0223)
In reply to Michael RothFrom: Kevin Wolf <[email protected]>
A huge image size could cause s->l1_size to overflow. Make sure that images never require a L1 table larger than what fits in s->l1_size.
This cannot only cause unbounded allocations, but also the allocation of a too small L1 table, resulting in out-of-bounds array accesses (both reads and writes).
--- block/qcow.c | 16 ++++++++++++++-- tests/qemu-iotests/092 | 9 +++++++++ tests/qemu-iotests/092.out | 7 +++++++ 3 files changed, 30 insertions(+), 2 deletions(-)
block/qcow.c +14 -2
@@ -61,7 +61,7 @@ typedef struct BDRVQcowState {int cluster_sectors;int l2_bits;int l2_size; -int l1_size; +unsigned int l1_size;uint64_t cluster_offset_mask;uint64_t l1_table_offset;uint64_t *l1_table;
@@ -165,7 +165,19 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,/* read the level 1 table */ shift = s->cluster_bits + s->l2_bits; - s->l1_size = (header.size + (1LL << shift) -1 ) >> shift; +if (header.size >UINT64_MAX - (1LL << shift)) { +error_setg (errp,"Image too large" ); + ret = -EINVAL ; + goto fail; + }else { +uint64_t l1_size = (header.size + (1LL << shift) -1 ) >> shift; +if (l1_size >INT_MAX /sizeof (uint64_t )) { +error_setg (errp,"Image too large" ); + ret = -EINVAL ; + goto fail; + } + s->l1_size = l1_size; + } s->l1_table_offset = header.l1_table_offset; s->l1_table =g_malloc (s->l1_size *sizeof (uint64_t ));
tests/qemu-iotests/092 +9 -0
@@ -43,6 +43,7 @@ _supported_fmt qcow _supported_proto generic _supported_os Linux +offset_size=24 offset_cluster_bits=32 offset_l2_bits=33
@@ -72,6 +73,14 @@ poke_file "$TEST_IMG" "$offset_l2_bits" "\x0e" poke_file "$TEST_IMG" "$offset_l2_bits" "\x1b" { $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +echo +echo "== Invalid size ==" +_make_test_img 64M +poke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\xee\xee\xee\xee\xee" +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir +poke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff" +{ $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_testdir + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/092.out +7 -0
@@ -21,4 +21,11 @@ qemu-io: can't open device TEST_DIR/t.qcow: L2 table size must be between 512 an no file open, try 'help open' qemu-io: can't open device TEST_DIR/t.qcow: L2 table size must be between 512 and 64k no file open, try 'help open' + +== Invalid size == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +qemu-io: can't open device TEST_DIR/t.qcow: Image too large +no file open, try 'help open' +qemu-io: can't open device TEST_DIR/t.qcow: Image too large +no file open, try 'help open' *** done
Signature · 1 line
1.9.1
PATCH 52/108 cputlb: Fix regression with TCG interpreter (bug 1310324)
In reply to Michael RothFrom: Stefan Weil <[email protected]>
Commit 0f842f8a246f2b5b51a11c13f933bf7a90ae8e96 replaced GETPC_EXT() which was derived from GETPC() by GETRA_EXT() without fixing cputlb.c. A later patch replaced GETRA_EXT() by GETRA() in exec/softmmu_template.h which is included in cputlb.c.
The TCG interpreter failed because the values returned by GETRA() were no longer explicitly set to 0. The redefinition of GETRA() introduced here fixes this.
In addition, GETPC_ADJ which is also used in exec/softmmu_template.h is set to 0. Both changes reduce the compiled code size for cputlb.c by more than 100 bytes, so the normal TCG without interpreter also profits from the reduced code size and slightly faster code.
--- cputlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
cputlb.c +4 -2
@@ -331,8 +331,10 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) }#define MMUSUFFIX _cmmu -#undef GETPC -#define GETPC () ((uintptr_t)0) +#undef GETPC_ADJ +#define GETPC_ADJ 0 +#undef GETRA +#define GETRA () ((uintptr_t)0)#define SOFTMMU_CODE_ACCESS #define SHIFT 0
Signature · 1 line
1.9.1
PATCH 50/108 virtio-scsi: Plug memory leak on virtio_scsi_push_event() error path
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Spotted by Coverity.
--- hw/scsi/virtio-scsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +2 -1
@@ -498,7 +498,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, uint32_t event, uint32_t reason) {VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s); -VirtIOSCSIReq *req =virtio_scsi_pop_req (s, vs->event_vq); +VirtIOSCSIReq *req;VirtIOSCSIEvent *evt;VirtIODevice *vdev =VIRTIO_DEVICE (s);int in_size;
@@ -507,6 +507,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,return ; } + req =virtio_scsi_pop_req (s, vs->event_vq);if (!req) { s->events_dropped = true;return ;
Signature · 1 line
1.9.1
PATCH 51/108 target-xtensa: fix cross-page jumps/calls at the end of TB
In reply to Michael RothFrom: Max Filippov <[email protected]>
Use tb->pc instead of dc->pc to check for cross-page jumps. When TB translation stops at the page boundary dc->pc points to the next page allowing chaining to TBs in it, which is wrong.
--- target-xtensa/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target-xtensa/translate.c +2 -2
@@ -419,7 +419,7 @@ static void gen_jump(DisasContext *dc, TCGv dest)static void gen_jumpi (DisasContext *dc,uint32_t dest,int slot) {TCGv_i32 tmp =tcg_const_i32 (dest); -if (((dc->pc ^ dest) &TARGET_PAGE_MASK ) !=0 ) { +if (((dc->tb->pc ^ dest) &TARGET_PAGE_MASK ) !=0 ) { slot =-1 ; }gen_jump_slot (dc, tmp, slot);
@@ -447,7 +447,7 @@ static void gen_callw(DisasContext *dc, int callinc, TCGv_i32 dest)static void gen_callwi (DisasContext *dc,int callinc,uint32_t dest,int slot) {TCGv_i32 tmp =tcg_const_i32 (dest); -if (((dc->pc ^ dest) &TARGET_PAGE_MASK ) !=0 ) { +if (((dc->tb->pc ^ dest) &TARGET_PAGE_MASK ) !=0 ) { slot =-1 ; }gen_callw_slot (dc, callinc, tmp, slot);
Signature · 1 line
1.9.1
PATCH 53/108 input (curses): mask keycodes to remove modifier bits
In reply to Michael RothFrom: Andrew Oates <[email protected]>
Without the mask, control bits are passed on in the keycode, generating incorrect PS/2 sequences when SHIFT, ALT, etc are held down.
--- ui/curses.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ui/curses.c +2 -2
@@ -288,8 +288,8 @@ static void curses_refresh(DisplayChangeListener *dcl)qemu_input_event_send_key_number (NULL ,GREY |ALT_CODE , true); } -qemu_input_event_send_key_number (NULL , keycode, true); -qemu_input_event_send_key_number (NULL , keycode, false); +qemu_input_event_send_key_number (NULL , keycode &KEY_MASK , true); +qemu_input_event_send_key_number (NULL , keycode &KEY_MASK , false);if (keycode &ALTGR ) {qemu_input_event_send_key_number (NULL ,GREY |ALT_CODE , false);
Signature · 1 line
1.9.1
PATCH 54/108 qemu-img: Plug memory leak in convert command
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Introduced in commit 661a0f7. Spotted by Coverity.
--- qemu-img.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
@@ -1413,7 +1413,7 @@ static int img_convert(int argc, char **argv) ret =bdrv_parse_cache_flags (cache, &flags);if (ret <0 ) {error_report ("Invalid cache option: %s" , cache); -return -1 ; + goto out; } out_bs =bdrv_new_open (out_filename, out_fmt, flags, true, quiet);
Signature · 1 line
1.9.1
PATCH 55/108 block/sheepdog: Plug memory leak in sd_snapshot_create()
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Has always been leaky. Spotted by Coverity.
--- block/sheepdog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/sheepdog.c +2 -2
@@ -2149,6 +2149,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)strncpy (s->inode.tag, sn_info->name,sizeof (s->inode.tag));/* we don't need to update entire object */ datalen =SD_INODE_SIZE -sizeof (s->inode.data_vdi_id); + inode =g_malloc (datalen);/* refresh inode. */ fd =connect_to_sdog (s);
@@ -2171,8 +2172,6 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) goto cleanup; } - inode = (SheepdogInode *)g_malloc (datalen); - ret =read_object (fd, (char *)inode,vid_to_vdi_oid (new_vid), s->inode.nr_copies, datalen,0 , s->cache_flags);
@@ -2186,6 +2185,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) s->inode.name, s->inode.snap_id, s->inode.vdi_id); cleanup: +g_free (inode);closesocket (fd);return ret; }
Signature · 1 line
1.9.1
PATCH 56/108 block/vvfat: Plug memory leak in read_directory()
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Has always been leaky. Spotted by Coverity.
--- block/vvfat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/vvfat.c +3 -1
@@ -787,7 +787,9 @@ static int read_directory(BDRVVVFATState* s, int mapping_index) s->current_mapping->path=buffer; s->current_mapping->read_only = (st.st_mode & (S_IWUSR |S_IWGRP |S_IWOTH )) ==0 ; - } + }else { +g_free (buffer); + } }closedir (dir);
Signature · 1 line
1.9.1
PATCH 57/108 block/vvfat: Plug memory leak in check_directory_consistency()
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
On error path. Introduced in commit a046433a. Spotted by Coverity.
--- block/vvfat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/vvfat.c +1 -1
@@ -1866,7 +1866,7 @@ static int check_directory_consistency(BDRVVVFATState *s,if (s->used_clusters[cluster_num] &USED_ANY ) {fprintf (stderr,"cluster %d used more than once\n" , (int )cluster_num); -return 0 ; + goto fail; } s->used_clusters[cluster_num] =USED_DIRECTORY ;
Signature · 1 line
1.9.1
PATCH 58/108 block/qapi: Plug memory leak in dump_qobject() case QTYPE_QERROR
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Introduced in commit a8d8ecb. Spotted by Coverity.
--- block/qapi.c | 1 + 1 file changed, 1 insertion(+)
block/qapi.c +1 -0
@@ -474,6 +474,7 @@ static void dump_qobject(fprintf_function func_fprintf, void *f,case QTYPE_QERROR : {QString *value =qerror_human ((QError *)obj);func_fprintf (f,"%s" ,qstring_get_str (value)); +QDECREF (value);break ; }case QTYPE_NONE :
Signature · 1 line
1.9.1
PATCH 59/108 blockdev: Plug memory leak in drive_init()
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
bs_opts is leaked on all paths from its qdev_new() that don't got through blockdev_init(). Add the missing QDECREF(), and zap bs_opts after blockdev_init(), so the new QDECREF() does nothing when we go through blockdev_init().
Leak introduced in commit f298d07. Spotted by Coverity.
--- blockdev.c | 2 ++ 1 file changed, 2 insertions(+)
blockdev.c +2 -0
@@ -902,6 +902,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)/* Actual block device init: Functionality shared with blockdev-add */ dinfo =blockdev_init (filename, bs_opts, &local_err); + bs_opts =NULL ;if (dinfo ==NULL ) {if (local_err) {qerror_report_err (local_err);
@@ -939,6 +940,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) fail:qemu_opts_del (legacy_opts); +QDECREF (bs_opts);return dinfo; }
Signature · 1 line
1.9.1
PATCH 60/108 blockdev: Plug memory leak in blockdev_init()
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
blockdev_init() leaks bs_opts when qemu_opts_create() fails, i.e. when the ID is bad. Missed in commit ec9c10d.
--- blockdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
blockdev.c +3 -2
@@ -332,7 +332,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts, opts =qemu_opts_create (&qemu_common_drive_opts, id,1 , &error);if (error) {error_propagate (errp, error); -return NULL ; + goto err_no_opts; }qemu_opts_absorb_qdict (opts, bs_opts, &error);
@@ -527,8 +527,9 @@ err:QTAILQ_REMOVE (&drives, dinfo, next);g_free (dinfo); early_err: -QDECREF (bs_opts);qemu_opts_del (opts); +err_no_opts: +QDECREF (bs_opts);return NULL ; }
Signature · 1 line
1.9.1
PATCH 62/108 block: Plug memory leak on brv_open_image() error path
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Introduced in commit da557a. Spotted by Coverity.
--- block.c | 1 + 1 file changed, 1 insertion(+)
block.c +1 -0
@@ -1158,6 +1158,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char *filename, bdref_key); ret = -EINVAL ; } +QDECREF (image_options); goto done; }
Signature · 1 line
1.9.1
PATCH 63/108 qcow2: Plug memory leak on qcow2_invalidate_cache() error paths
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Introduced in commit 5a8a30d. Spotted by Coverity.
--- block/qcow2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/qcow2.c +1 -2
@@ -1306,6 +1306,7 @@ static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp) options =qdict_clone_shallow (bs->options); ret =qcow2_open (bs, options, flags, &local_err); +QDECREF (options);if (local_err) {error_setg (errp,"Could not reopen qcow2 layer: %s" ,error_get_pretty (local_err));
@@ -1316,8 +1317,6 @@ static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp)return ; } -QDECREF (options); -if (crypt_method) { s->crypt_method = crypt_method;memcpy (&s->aes_encrypt_key, &aes_encrypt_key,sizeof (aes_encrypt_key));
Signature · 1 line
1.9.1
PATCH 64/108 linux-user: Don't overrun guest buffer in sched_getaffinity
In reply to Michael RothFrom: Peter Maydell <[email protected]>
If the guest's "long" type is smaller than the host's, then our sched_getaffinity wrapper needs to round the buffer size up to a multiple of the host sizeof(long). This means that when we copy the data back from the host buffer to the guest's buffer there might be more than we can fit. Rather than overflowing the guest's buffer, handle this case by returning EINVAL or ignoring the unused extra space, as appropriate.
Note that only guests using the syscall interface directly might run into this bug -- the glibc wrappers around it will always use a buffer whose size is a multiple of 8 regardless of guest architecture.
--- linux-user/syscall.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
linux-user/syscall.c +16 -0
@@ -7499,6 +7499,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret =get_errno (sys_sched_getaffinity (arg1, mask_size, mask));if (!is_error (ret)) { +if (ret > arg2) { +/* More data returned than the caller's buffer will fit. +* This only happens if sizeof(abi_long) < sizeof(long) +* and the caller passed us a buffer holding an odd number +* of abi_longs. If the host kernel is actually using the +* extra 4 bytes then fail EINVAL; otherwise we can just +* ignore them and only copy the interesting part. +*/ +int numcpus =sysconf (_SC_NPROCESSORS_CONF); +if (numcpus > arg2 *8 ) { + ret = -TARGET_EINVAL ; +break ; + } + ret = arg2; + } +if (copy_to_user (arg3, mask, ret)) { goto efault; }
Signature · 1 line
1.9.1
PATCH 61/108 qemu-io: Plug memory leak in open command
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
Introduced in commit b543c5c. Spotted by Coverity.
--- qemu-io.c | 2 ++ 1 file changed, 2 insertions(+)
qemu-io.c +2 -0
@@ -54,6 +54,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)if (qemuio_bs) {fprintf (stderr,"file open already, try 'help close'\n" ); +QDECREF (opts);return 1 ; }
@@ -171,6 +172,7 @@ static int open_f(BlockDriverState *bs, int argc, char **argv) }else if (optind == argc) {return openfile (NULL , flags, growable, opts); }else { +QDECREF (opts);return qemuio_command_usage (&open_cmd); } }
Signature · 1 line
1.9.1
PATCH 65/108 tcg-i386: Fix win64 qemu store
In reply to Michael RothFrom: Richard Henderson <[email protected]>
The first non-register argument isn't placed at offset 0.
--- tcg/i386/tcg-target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tcg/i386/tcg-target.c +2 -1
@@ -1407,7 +1407,8 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) }else { retaddr =TCG_REG_RAX ;tcg_out_movi (s,TCG_TYPE_PTR , retaddr, (uintptr_t )l->raddr); -tcg_out_st (s,TCG_TYPE_PTR , retaddr,TCG_REG_ESP ,0 ); +tcg_out_st (s,TCG_TYPE_PTR , retaddr,TCG_REG_ESP , +TCG_TARGET_CALL_STACK_OFFSET ); } }
Signature · 1 line
1.9.1
PATCH 34/108 qdev: Fix crash by validating the object type
In reply to Michael RothFrom: Amos Kong <[email protected]>
QEMU crashed when I try to list device parameters and the driver name is actually an available bus name.
# qemu -device virtio-pci-bus,? # qemu -device virtio-bus,? # qemu -device virtio-serial-bus,? qdev-monitor.c:212:qdev_device_help: Object 0x7fd932f50620 is not an instance of type device Aborted (core dumped)
We can also reproduce this bug by adding device from monitor, so it's worth to fix the crash.
(qemu) device_add virtio-serial-bus qdev-monitor.c:491:qdev_device_add: Object 0x7f5e89530920 is not an instance of type device
Aborted (core dumped)
--- qdev-monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qdev-monitor.c +1 -1
@@ -206,7 +206,7 @@ int qdev_device_help(QemuOpts *opts) } } -if (!klass) { +if (!object_class_dynamic_cast (klass,TYPE_DEVICE )) {return 0 ; } do {
Signature · 1 line
1.9.1
PATCH 66/108 target-arm: Fix errors in writes to generic timer control registers
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The code for handling writes to the generic timer control registers had several bugs:
* ISTATUS (bit 2) is read-only but we forced it to zero on any write
* the check for "was IMASK (bit 1) toggled?" incorrectly used '&' where it should be '^'
* the handling of IMASK was inverted: we should set the IRQ if ISTATUS is set and IMASK is clear, not if both are set
The combination of these bugs meant that when running a Linux guest that uses the generic timers we would fairly quickly end up either forgetting that the timer output should be asserted, or failing to set the IRQ when the timer was unmasked. The result is that the guest never gets any more timer interrupts.
Message-id: [email protected]
--- target-arm/helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target-arm/helper.c +3 -3
@@ -963,16 +963,16 @@ static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,int timeridx = ri->crm &1 ;uint32_t oldval = env->cp15.c14_timer[timeridx].ctl; - env->cp15.c14_timer[timeridx].ctl = value &3 ; + env->cp15.c14_timer[timeridx].ctl =deposit64 (oldval,0 ,2 , value);if ((oldval ^ value) &1 ) {/* Enable toggled */ gt_recalc_timer (cpu, timeridx); - }else if ((oldval & value) &2 ) { + }else if ((oldval ^ value) &2 ) {/* IMASK toggled: don't need to recalculate, * just set the interrupt line based on ISTATUS */ qemu_set_irq (cpu->gt_timer_outputs[timeridx], - (oldval &4 ) && (value &2 )); + (oldval &4 ) && !(value &2 )); } }
Signature · 1 line
1.9.1
PATCH 67/108 s390x/css: handle emw correctly for tsch
In reply to Michael RothFrom: Cornelia Huck <[email protected]>
We should not try to store the emw portion of the irb if extended measurements are not applicable. In particular, we should not surprise the guest by storing a larger irb if it did not enable extended measurements.
--- hw/s390x/css.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
hw/s390x/css.c +20 -4
@@ -734,9 +734,11 @@ out:return ret; } -static void copy_irb_to_guest (IRB *dest,const IRB *src) +static void copy_irb_to_guest (IRB *dest,const IRB *src,PMCW *pmcw) {int i; +uint16_t stctl = src->scsw.ctrl &SCSW_CTRL_MASK_STCTL ; +uint16_t actl = src->scsw.ctrl &SCSW_CTRL_MASK_ACTL ;copy_scsw_to_guest (&dest->scsw, &src->scsw);
@@ -746,8 +748,22 @@ static void copy_irb_to_guest(IRB *dest, const IRB *src)for (i =0 ; i <ARRAY_SIZE (dest->ecw); i++) { dest->ecw[i] =cpu_to_be32 (src->ecw[i]); } -for (i =0 ; i <ARRAY_SIZE (dest->emw); i++) { - dest->emw[i] =cpu_to_be32 (src->emw[i]); +/* extended measurements enabled? */ +if ((src->scsw.flags &SCSW_FLAGS_MASK_ESWF ) || + !(pmcw->flags &PMCW_FLAGS_MASK_TF ) || + !(pmcw->chars &PMCW_CHARS_MASK_XMWME )) { +return ; + } +/* extended measurements pending? */ +if (!(stctl &SCSW_STCTL_STATUS_PEND )) { +return ; + } +if ((stctl &SCSW_STCTL_PRIMARY ) || + (stctl ==SCSW_STCTL_SECONDARY ) || + ((stctl &SCSW_STCTL_INTERMEDIATE ) && (actl &SCSW_ACTL_SUSP ))) { +for (i =0 ; i <ARRAY_SIZE (dest->emw); i++) { + dest->emw[i] =cpu_to_be32 (src->emw[i]); + } } }
@@ -793,7 +809,7 @@ int css_do_tsch(SubchDev *sch, IRB *target_irb) } }/* Store the irb to the guest. */ -copy_irb_to_guest (target_irb, &irb); +copy_irb_to_guest (target_irb, &irb, p);/* Clear conditions on subchannel, if applicable. */ if (stctl &SCSW_STCTL_STATUS_PEND ) {
Signature · 1 line
1.9.1
PATCH 68/108 aio: fix qemu_bh_schedule() bh->ctx race condition
In reply to Michael RothFrom: Stefan Hajnoczi <[email protected]>
qemu_bh_schedule() is supposed to be thread-safe at least the first time it is called. Unfortunately this is not quite true:
bh->scheduled = 1; aio_notify(bh->ctx);
Since another thread may run the BH callback once it has been scheduled, there is a race condition if the callback frees the BH before aio_notify(bh->ctx) has a chance to run.
--- async.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
async.c +10 -4
@@ -117,15 +117,21 @@ void qemu_bh_schedule_idle(QEMUBH *bh)void qemu_bh_schedule (QEMUBH *bh) { +AioContext *ctx; +if (bh->scheduled)return ; + ctx = bh->ctx; bh->idle =0 ; -/* Make sure that idle & any writes needed by the callback are done -* before the locations are read in the aio_bh_poll. +/* Make sure that: +* 1. idle & any writes needed by the callback are done before the +* locations are read in the aio_bh_poll. +* 2. ctx is loaded before scheduled is set and the callback has a chance +* to execute. */ -smp_wmb (); +smp_mb (); bh->scheduled =1 ; -aio_notify (bh->ctx); +aio_notify (ctx); }
Signature · 1 line
1.9.1
PATCH 70/108 migration: remove duplicate code
In reply to Michael RothFrom: ChenLiang <[email protected]>
version_id is checked twice in the ram_load.
--- arch_init.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 35 deletions(-)
arch_init.c +33 -35
@@ -997,7 +997,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) seq_iter++; -if (version_id <4 || version_id >4 ) { +if (version_id !=4 ) {return -EINVAL ; }
@@ -1008,44 +1008,42 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) addr &=TARGET_PAGE_MASK ;if (flags &RAM_SAVE_FLAG_MEM_SIZE ) { -if (version_id ==4 ) { -/* Synchronize RAM block list */ -char id[256 ]; -ram_addr_t length; -ram_addr_t total_ram_bytes = addr; - -while (total_ram_bytes) { -RAMBlock *block; -uint8_t len; - - len =qemu_get_byte (f); -qemu_get_buffer (f, (uint8_t *)id, len); - id[len] =0 ; - length =qemu_get_be64 (f); - - QTAILQ_FOREACH(block, &ram_list.blocks, next) { -if (!strncmp (id, block->idstr,sizeof (id))) { -if (block->length != length) { -fprintf (stderr, -"Length mismatch: %s: " RAM_ADDR_FMT -" in != " RAM_ADDR_FMT "\n" , id, length, - block->length); - ret = -EINVAL ; - goto done; - } -break ; +/* Synchronize RAM block list */ +char id[256 ]; +ram_addr_t length; +ram_addr_t total_ram_bytes = addr; + +while (total_ram_bytes) { +RAMBlock *block; +uint8_t len; + + len =qemu_get_byte (f); +qemu_get_buffer (f, (uint8_t *)id, len); + id[len] =0 ; + length =qemu_get_be64 (f); + + QTAILQ_FOREACH(block, &ram_list.blocks, next) { +if (!strncmp (id, block->idstr,sizeof (id))) { +if (block->length != length) { +fprintf (stderr, +"Length mismatch: %s: " RAM_ADDR_FMT +" in != " RAM_ADDR_FMT "\n" , id, length, + block->length); + ret = -EINVAL ; + goto done; } +break ; } + } -if (!block) { -fprintf (stderr,"Unknown ramblock \"%s\", cannot " -"accept migration\n" , id); - ret = -EINVAL ; - goto done; - } - - total_ram_bytes -= length; +if (!block) { +fprintf (stderr,"Unknown ramblock \"%s\", cannot " +"accept migration\n" , id); + ret = -EINVAL ; + goto done; } + + total_ram_bytes -= length; } }
Signature · 1 line
1.9.1
PATCH 69/108 qga: Fix handle fd leak in acquire_privilege()
In reply to Michael RothFrom: Gonglei <[email protected]>
token should be closed in all conditions.
So move CloseHandle(token) to "out" branch.
--- qga/commands-win32.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
qga/commands-win32.c +4 -2
@@ -31,7 +31,7 @@static void acquire_privilege (const char *name,Error **err) { -HANDLE token; +HANDLE token =NULL ;TOKEN_PRIVILEGES priv;Error *local_err =NULL ;
@@ -57,13 +57,15 @@ static void acquire_privilege(const char *name, Error **err) goto out; } -CloseHandle (token); }else {error_set (&local_err,QERR_QGA_COMMAND_FAILED ,"failed to open privilege token" ); } out: +if (token) { +CloseHandle (token); + }if (local_err) {error_propagate (err, local_err); }
Signature · 1 line
1.9.1
PATCH 71/108 arch_init: Be sure of only one exit entry with DPRINTF() for ram_load()
In reply to Michael RothFrom: Chen Gang <[email protected]>
When DPRINTF() has effect, the original author wants to print all ram_load() calling results. So need use 'goto' instead of 'return' within ram_load(), just like other areas have done.
--- arch_init.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch_init.c +8 -4
@@ -998,7 +998,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) seq_iter++;if (version_id !=4 ) { -return -EINVAL ; + ret = -EINVAL ; + goto done; } do {
@@ -1053,7 +1054,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -return -EINVAL ; + ret = -EINVAL ; + goto done; } ch =qemu_get_byte (f);
@@ -1063,14 +1065,16 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { -return -EINVAL ; + ret = -EINVAL ; + goto done; }qemu_get_buffer (f, host,TARGET_PAGE_SIZE ); }else if (flags &RAM_SAVE_FLAG_XBZRLE ) {void *host =host_from_stream_offset (f, addr, flags);if (!host) { -return -EINVAL ; + ret = -EINVAL ; + goto done; }if (load_xbzrle (f, addr, host) <0 ) {
Signature · 1 line
1.9.1
PATCH 72/108 migration: catch unknown flags in ram_load
In reply to Michael RothFrom: Peter Lieven <[email protected]>
if a saved vm has unknown flags in the memory data qemu currently simply ignores this flag and continues which yields in an unpredictable result.
This patch catches all unknown flags and aborts the loading of the vm. Additionally error reports are thrown if the migration aborts abnormally.
--- arch_init.c | 42 +++++++++++++++++++++++------------------- migration.c | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-)
arch_init.c +23 -19
@@ -992,17 +992,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) {ram_addr_t addr;int flags, ret =0 ; -int error;static uint64_t seq_iter; seq_iter++;if (version_id !=4 ) { ret = -EINVAL ; - goto done; } - do { +while (!ret) { addr =qemu_get_be64 (f); flags = addr & ~TARGET_PAGE_MASK ;
@@ -1031,7 +1029,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)" in != " RAM_ADDR_FMT "\n" , id, length, block->length); ret = -EINVAL ; - goto done; }break ; }
@@ -1041,21 +1038,22 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)fprintf (stderr,"Unknown ramblock \"%s\", cannot " "accept migration\n" , id); ret = -EINVAL ; - goto done; + } +if (ret) { +break ; } total_ram_bytes -= length; } - } - -if (flags &RAM_SAVE_FLAG_COMPRESS ) { + }else if (flags &RAM_SAVE_FLAG_COMPRESS ) {void *host;uint8_t ch; host =host_from_stream_offset (f, addr, flags);if (!host) { +error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); ret = -EINVAL ; - goto done; +break ; } ch =qemu_get_byte (f);
@@ -1065,33 +1063,39 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) host =host_from_stream_offset (f, addr, flags);if (!host) { +error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); ret = -EINVAL ; - goto done; +break ; }qemu_get_buffer (f, host,TARGET_PAGE_SIZE ); }else if (flags &RAM_SAVE_FLAG_XBZRLE ) {void *host =host_from_stream_offset (f, addr, flags);if (!host) { +error_report ("Illegal RAM offset " RAM_ADDR_FMT , addr); ret = -EINVAL ; - goto done; +break ; }if (load_xbzrle (f, addr, host) <0 ) { +error_report ("Failed to decompress XBZRLE page at " +RAM_ADDR_FMT , addr); ret = -EINVAL ; - goto done; +break ; } }else if (flags &RAM_SAVE_FLAG_HOOK ) {ram_control_load_hook (f, flags); + }else if (flags &RAM_SAVE_FLAG_EOS ) { +/* normal exit */ +break ; + }else { +error_report ("Unknown migration flags: %#x" , flags); + ret = -EINVAL ; +break ; } - error =qemu_file_get_error (f); -if (error) { - ret = error; - goto done; - } - }while (!(flags &RAM_SAVE_FLAG_EOS )); + ret =qemu_file_get_error (f); + } -done:DPRINTF ("Completed load of VM with exit code %d seq iteration " "%" PRIu64"\n" , ret, seq_iter);return ret;
migration.c +1 -1
@@ -98,7 +98,7 @@ static void process_incoming_migration_co(void *opaque)qemu_fclose (f);free_xbzrle_decoded_buf ();if (ret <0 ) { -fprintf (stderr,"load of migration failed\n" ); +error_report ("load of migration failed: %s" ,strerror (-ret));exit (EXIT_FAILURE ); }qemu_announce_self ();
Signature · 1 line
1.9.1
PATCH 73/108 rdma: bug fixes
In reply to Michael RothFrom: "Michael R. Hines" <[email protected]>
1. Fix small memory leak in parsing inet address from command line in data_init()
2. Fix ibv_post_send() return value check and pass error code back up correctly.
3. Fix rdma_destroy_qp() segfault after failure to connect to destination.
--- migration-rdma.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
migration-rdma.c +10 -10
@@ -1589,13 +1589,11 @@ static int qemu_rdma_post_send_control(RDMAContext *rdma, uint8_t *buf, } -if (ibv_post_send (rdma->qp, &send_wr, &bad_wr)) { -return -1 ; - } + ret =ibv_post_send (rdma->qp, &send_wr, &bad_wr); -if (ret <0 ) { +if (ret >0 ) {fprintf (stderr,"Failed to use post IB SEND for control!\n" ); -return ret; +return -ret; } ret =qemu_rdma_block_for_wrid (rdma,RDMA_WRID_SEND_CONTROL ,NULL );
@@ -2237,10 +2235,6 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) } } -if (rdma->qp) { -rdma_destroy_qp (rdma->cm_id); - rdma->qp =NULL ; - }if (rdma->cq) {ibv_destroy_cq (rdma->cq); rdma->cq =NULL ;
@@ -2258,6 +2252,10 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->listen_id =NULL ; }if (rdma->cm_id) { +if (rdma->qp) { +rdma_destroy_qp (rdma->cm_id); + rdma->qp =NULL ; + }rdma_destroy_id (rdma->cm_id); rdma->cm_id =NULL ; }
@@ -2512,8 +2510,10 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp) }else {ERROR (errp,"bad RDMA migration address '%s'" , host_port);g_free (rdma); -return NULL ; + rdma =NULL ; } + +qapi_free_InetSocketAddress (addr); }return rdma;
Signature · 1 line
1.9.1
PATCH 75/108 qdev: reorganize error reporting in bus_set_realized
In reply to Michael RothFrom: Paolo Bonzini <[email protected]>
No semantic change.
--- hw/core/qdev.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
hw/core/qdev.c +5 -13
@@ -520,27 +520,19 @@ static void bus_set_realized(Object *obj, bool value, Error **errp)if (value && !bus->realized) {if (bc->realize) { bc->realize (bus, &local_err); - -if (local_err !=NULL ) { - goto error; - } - } }else if (!value && bus->realized) {if (bc->unrealize) { bc->unrealize (bus, &local_err); - -if (local_err !=NULL ) { - goto error; - } } } - bus->realized = value; -return ; +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } -error: -error_propagate (errp, local_err); + bus->realized = value; } void qbus_create_inplace(void *bus, size_t size, const char *typename,
Signature · 1 line
1.9.1
PATCH 76/108 qdev: recursively unrealize devices when unrealizing bus
In reply to Michael RothFrom: Paolo Bonzini <[email protected]>
When the patch was posted that became 5c21ce7 (qdev: Realize buses on device realization, 2014-03-12), it included recursive realization and unrealization of devices when the bus's "realized" property was toggled.
However, due to the same old worries about recursive realization and prerequisites not being realized yet, those hunks were dropped when committing the patch. Unfortunately, this causes a use-after-free bug (easily reproduced by a PCI hot-unplug action).
Before the patch, device_unparent behaved as follows:
for each child bus
unparent bus ----------------------------.
| for each child device |
| unparent device ---------------. |
| | unrealize device | |
| | call dc->unparent | |
| '------------------------------- |
'----------------------------------------'unrealize device
After the patch, it behaves as follows instead:
unrealize device --------------------.
| for each child bus |
| unrealize bus (A) |
'------------------------------------'
for each child bus
unparent bus ----------------------.
| for each child device |
| unrealize device (B) |
| call dc->unparent |
'----------------------------------'At the step marked (B) the device might use data from the bus that is not available anymore due to step (A).
To fix this, we need to unrealize devices before step (A). To sidestep concerns about recursive realization, only do recursive unrealization and leave the "value && !bus->realized" case as it is.
The resulting flow is:
for each child bus
unrealize bus ---------------------.
| for each child device |
| unrealize device (B) |
| call bc->unrealize (A) |
'----------------------------------' unrealize device
for each child bus
unparent bus ----------------------.
| for each child device |
| unparent device |
'----------------------------------'
where everything is "powered down" before it is unassembled.
--- hw/core/qdev.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
hw/core/qdev.c +12 -1
@@ -515,14 +515,25 @@ static void bus_set_realized(Object *obj, bool value, Error **errp) {BusState *bus =BUS (obj);BusClass *bc =BUS_GET_CLASS (bus); +BusChild *kid;Error *local_err =NULL ;if (value && !bus->realized) {if (bc->realize) { bc->realize (bus, &local_err); } + +/* TODO: recursive realization */ }else if (!value && bus->realized) { -if (bc->unrealize) { + QTAILQ_FOREACH(kid, &bus->children, sibling) { +DeviceState *dev = kid->child; +object_property_set_bool (OBJECT (dev), false,"realized" , + &local_err); +if (local_err !=NULL ) { +break ; + } + } +if (bc->unrealize && local_err ==NULL ) { bc->unrealize (bus, &local_err); } }
Signature · 1 line
1.9.1
PATCH 78/108 vhost: fix resource leak in error handling
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
vhost_verify_ring_mappings leaks mappings on error. Fix this up.
--- hw/virtio/vhost.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
hw/virtio/vhost.c +6 -4
@@ -309,7 +309,9 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev, uint64_t size) {int i; -for (i =0 ; i < dev->nvqs; ++i) { +int r =0 ; + +for (i =0 ; !r && i < dev->nvqs; ++i) {struct vhost_virtqueue *vq = dev->vqs + i;hwaddr l;void *p;
@@ -321,15 +323,15 @@ static int vhost_verify_ring_mappings(struct vhost_dev *dev, p =cpu_physical_memory_map (vq->ring_phys, &l,1 );if (!p || l != vq->ring_size) {fprintf (stderr,"Unable to map ring buffer for ring %d\n" , i); -return -ENOMEM ; + r = -ENOMEM ; }if (p != vq->ring) {fprintf (stderr,"Ring buffer relocated for ring %d\n" , i); -return -EBUSY ; + r = -EBUSY ; }cpu_physical_memory_unmap (p, l,0 ,0 ); } -return 0 ; +return r; } static struct vhost_memory_region *vhost_dev_find_reg(struct vhost_dev *dev,
Signature · 1 line
1.9.1
PATCH 77/108 scsi-disk: fix bug in scsi_block_new_request() introduced by commit 137745c
In reply to Michael RothFrom: Ulrich Obergfell <[email protected]>
This patch fixes a bug in scsi_block_new_request() that was introduced by commit 137745c5c60f083ec982fe9e861e8c16ebca1ba8. If the host cache is used - i.e. if BDRV_O_NOCACHE is _not_ set - the 'break' statement needs to be executed to 'fall back' to SG_IO.
--- hw/scsi/scsi-disk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/scsi-disk.c +1 -1
@@ -2520,7 +2520,7 @@ static SCSIRequest *scsi_block_new_request(SCSIDevice *d, uint32_t tag,* ones (such as WRITE SAME or EXTENDED COPY, etc.). So, without * O_DIRECT everything must go through SG_IO. */ -if (bdrv_get_flags (s->qdev.conf.bs) &BDRV_O_NOCACHE ) { +if (!(bdrv_get_flags (s->qdev.conf.bs) &BDRV_O_NOCACHE )) {break ; }
Signature · 1 line
1.9.1
PATCH 79/108 virtio-scsi: define dummy handle_output for vhost-scsi vqs
In reply to Michael RothFrom: Ming Lei <[email protected]>
vhost userspace needn't to handle vq's notification from guest, so define dummy handle_output callback for all vqs of vhost-scsi.
In some corner cases(such as when handling vq's reset from VM), virtio-pci still trys to handle pending virtio-scsi events, then object check failure inside virtio_scsi_handle_event() for vhost-scsi can be triggered.
The issue can be reproduced by 'rmmod virtio-scsi', 'system sleep' or reboot inside VM.
--- hw/scsi/vhost-scsi.c | 8 +++++++- hw/scsi/virtio-scsi.c | 14 +++++++++----- include/hw/virtio/virtio-scsi.h | 7 ++++++- 3 files changed, 22 insertions(+), 7 deletions(-)
hw/scsi/vhost-scsi.c +7 -1
@@ -196,6 +196,10 @@ static void vhost_scsi_set_status(VirtIODevice *vdev, uint8_t val) } } +static void vhost_dummy_handle_output (VirtIODevice *vdev,VirtQueue *vq) +{ +} +static void vhost_scsi_realize (DeviceState *dev,Error **errp) {VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (dev);
@@ -217,7 +221,9 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) } } -virtio_scsi_common_realize (dev, &err); +virtio_scsi_common_realize (dev, &err, vhost_dummy_handle_output, + vhost_dummy_handle_output, + vhost_dummy_handle_output);if (err !=NULL ) {error_propagate (errp, err);return ;
hw/scsi/virtio-scsi.c +9 -5
@@ -605,7 +605,9 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = { .load_request = virtio_scsi_load_request, }; -void virtio_scsi_common_realize (DeviceState *dev,Error **errp) +void virtio_scsi_common_realize (DeviceState *dev,Error **errp, +HandleOutput ctrl,HandleOutput evt, +HandleOutput cmd) {VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIOSCSICommon *s =VIRTIO_SCSI_COMMON (dev);
@@ -619,12 +621,12 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp) s->cdb_size =VIRTIO_SCSI_CDB_SIZE ; s->ctrl_vq =virtio_add_queue (vdev,VIRTIO_SCSI_VQ_SIZE , - virtio_scsi_handle_ctrl); + ctrl); s->event_vq =virtio_add_queue (vdev,VIRTIO_SCSI_VQ_SIZE , - virtio_scsi_handle_event); + evt);for (i =0 ; i < s->conf.num_queues; i++) { s->cmd_vqs[i] =virtio_add_queue (vdev,VIRTIO_SCSI_VQ_SIZE , - virtio_scsi_handle_cmd); + cmd); } }
@@ -635,7 +637,9 @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)static int virtio_scsi_id;Error *err =NULL ; -virtio_scsi_common_realize (dev, &err); +virtio_scsi_common_realize (dev, &err, virtio_scsi_handle_ctrl, + virtio_scsi_handle_event, + virtio_scsi_handle_cmd);if (err !=NULL ) {error_propagate (errp, err);return ;
include/hw/virtio/virtio-scsi.h +6 -1
@@ -186,7 +186,12 @@ typedef struct {DEFINE_PROP_BIT ("param_change" , _state, _feature_field, \ VIRTIO_SCSI_F_CHANGE, true) -void virtio_scsi_common_realize (DeviceState *dev,Error **errp); +typedef void (*HandleOutput )(VirtIODevice *,VirtQueue *); + +void virtio_scsi_common_realize (DeviceState *dev,Error **errp, +HandleOutput ctrl,HandleOutput evt, +HandleOutput cmd); +void virtio_scsi_common_unrealize (DeviceState *dev,Error **errp);#endif /* _QEMU_VIRTIO_SCSI_H */
Signature · 1 line
1.9.1
PATCH 80/108 usb: Fix usb-bt-dongle initialization.
In reply to Michael RothFrom: Hani Benhabiles <[email protected]>
Due to an incomplete initialization, adding a usb-bt-dongle device through HMP or QMP will cause a segmentation fault.
--- hw/usb/dev-bluetooth.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
hw/usb/dev-bluetooth.c +16 -8
@@ -19,6 +19,7 @@*/ #include "qemu-common.h" +#include "qemu/error-report.h" #include "hw/usb.h" #include "hw/usb/desc.h" #include "sysemu/bt.h"
@@ -506,6 +507,14 @@ static int usb_bt_initfn(USBDevice *dev)usb_desc_create_serial (dev);usb_desc_init (dev); + s->dev.opaque = s; +if (!s->hci) { + s->hci =bt_new_hci (qemu_find_bt_vlan (0 )); + } + s->hci->opaque = s; + s->hci->evt_recv = usb_bt_out_hci_packet_event; + s->hci->acl_recv = usb_bt_out_hci_packet_acl; +usb_bt_handle_reset (&s->dev); s->intr =usb_ep_get (dev,USB_TOKEN_IN ,USB_EVT_EP );return 0 ;
@@ -516,6 +525,7 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)USBDevice *dev;struct USBBtState *s;HCIInfo *hci; +const char *name ="usb-bt-dongle" ;if (*cmdline) { hci =hci_init (cmdline);
@@ -525,19 +535,17 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)if (!hci)return NULL ; - dev =usb_create_simple (bus,"usb-bt-dongle" ); + dev =usb_create (bus, name);if (!dev) { +error_report ("Failed to create USB device '%s'" , name);return NULL ; } s = DO_UPCAST(struct USBBtState, dev, dev); - s->dev.opaque = s; - s->hci = hci; - s->hci->opaque = s; - s->hci->evt_recv = usb_bt_out_hci_packet_event; - s->hci->acl_recv = usb_bt_out_hci_packet_acl; - -usb_bt_handle_reset (&s->dev); +if (qdev_init (&dev->qdev) <0 ) { +error_report ("Failed to initialize USB device '%s'" , name); +return NULL ; + }return dev; }
Signature · 1 line
1.9.1
PATCH 83/108 coroutine-win32.c: Add noinline attribute to work around gcc bug
In reply to Michael RothFrom: Peter Maydell <[email protected]>
A gcc codegen bug in x86_64-w64-mingw32-gcc (GCC) 4.6.3 means that non-debug builds of QEMU for Windows tend to assert when using coroutines. Work around this by marking qemu_coroutine_switch as noinline.
If we allow gcc to inline qemu_coroutine_switch into coroutine_trampoline, then it hoists the code to get the address of the TLS variable "current" out of the while() loop. This is an invalid transformation because the SwitchToFiber() call may be called when running thread A but return in thread B, and so we might be in a different thread context each time round the loop. This can happen quite often. Typically. a coroutine is started when a VCPU thread does bdrv_aio_readv:
VCPU thread
main VCPU thread coroutine I/O coroutine
bdrv_aio_readv ----->
start I/O operation
thread_pool_submit_co
<------------ yields
back to emulation
Then I/O finishes and the thread-pool.c event notifier triggers in the I/O thread. event_notifier_ready calls thread_pool_co_cb, and the I/O coroutine now restarts *in another thread*:
iothread
main iothread coroutine I/O coroutine (formerly in VCPU thread)
event_notifier_ready
thread_pool_co_cb -----> current = I/O coroutine;
call AIO callback
But on Win32, because of the bug, the "current" being set here the current coroutine of the VCPU thread, not the iothread.
noinline is a good-enough workaround, and quite unlikely to break in the future.
(Thanks to Paolo Bonzini for assistance in diagnosing the problem and providing the detailed example/ascii art quoted above.)
Message-id: [email protected]
--- coroutine-win32.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
coroutine-win32.c +11 -2
@@ -36,8 +36,17 @@ typedef structstatic __threadCoroutineWin32 leader;static __threadCoroutine *current; -CoroutineAction qemu_coroutine_switch (Coroutine *from_,Coroutine *to_, -CoroutineAction action) +/* This function is marked noinline to prevent GCC from inlining it +* into coroutine_trampoline(). If we allow it to do that then it +* hoists the code to get the address of the TLS variable "current" +* out of the while() loop. This is an invalid transformation because +* the SwitchToFiber() call may be called when running thread A but +* return in thread B, and so we might be in a different thread +* context each time round the loop. +*/ +CoroutineAction __attribute__((noinline)) +qemu_coroutine_switch (Coroutine *from_,Coroutine *to_, +CoroutineAction action) {CoroutineWin32 *from =DO_UPCAST (CoroutineWin32, base, from_);CoroutineWin32 *to =DO_UPCAST (CoroutineWin32, base, to_);
Signature · 1 line
1.9.1
PATCH 82/108 q35: Use PC_Q35_COMPAT_1_4 on pc-q35-1.4 compat_props
In reply to Michael RothFrom: Eduardo Habkost <[email protected]>
pc-q35-1.4 was incorrectly using PC_COMPAT_1_4 instead of PC_Q35_COMPAT_1_4.
The only side-effect was that the hpet compat property (inherited from PC_Q35_COMPAT_1_7) was missing.
Without this patch, pc-q35-1.4 inicorrectly initializes hpet-intcap to 0xff0104 (behavior introduced in QEMU 2.0, by commit 7a10ef51c2397ac4323bc786af02c58b413b5cd2).
--- hw/i386/pc_q35.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/pc_q35.c +1 -1
@@ -351,7 +351,7 @@ static QEMUMachine pc_q35_machine_v1_4 = { .name = "pc-q35-1.4", .init = pc_q35_init_1_4, .compat_props = (GlobalProperty []) { -PC_COMPAT_1_4 , +PC_Q35_COMPAT_1_4 , {/* end of list */ } }, };
Signature · 1 line
1.9.1
PATCH 86/108 target-i386: Filter FEAT_7_0_EBX TCG features too
In reply to Michael RothFrom: Eduardo Habkost <[email protected]>
The TCG_7_0_EBX_FEATURES macro was defined but never used (it even had a typo that was never noticed). Make the existing TCG feature filtering code use it.
--- target-i386/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target-i386/cpu.c +2 -1
@@ -582,7 +582,7 @@ struct X86CPUDefinition {#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)#define TCG_SVM_FEATURES 0 -#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP \ +#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX)/* missing: CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
@@ -2598,6 +2598,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)if (!kvm_enabled ()) { env->features[FEAT_1_EDX ] &=TCG_FEATURES ; env->features[FEAT_1_ECX ] &=TCG_EXT_FEATURES ; + env->features[FEAT_7_0_EBX ] &=TCG_7_0_EBX_FEATURES ; env->features[FEAT_8000_0001_EDX ] &=TCG_EXT2_FEATURES ; env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ;
Signature · 1 line
1.9.1
PATCH 84/108 hw/xtensa/xtfpga: fix FLASH mapping to boot region for KC705
In reply to Michael RothFrom: Max Filippov <[email protected]>
On KC705 bootloader area is located at FLASH offset 0x06000000, not 0 as on older xtfpga boards.
--- hw/xtensa/xtensa_lx60.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
hw/xtensa/xtensa_lx60.c +5 -3
@@ -42,6 +42,7 @@typedef struct LxBoardDesc {hwaddr flash_base;size_t flash_size; +size_t flash_boot_base;size_t flash_sector_size;size_t sram_size; }LxBoardDesc ;
@@ -266,9 +267,9 @@ static void lx_init(const LxBoardDesc *board, QEMUMachineInitArgs *args)MemoryRegion *flash_io =g_malloc (sizeof (*flash_io));memory_region_init_alias (flash_io,NULL ,"lx60.flash" , - flash_mr,0 , - board->flash_size <0x02000000 ? - board->flash_size :0x02000000 ); + flash_mr, board->flash_boot_base, + board->flash_size - board->flash_boot_base <0x02000000 ? + board->flash_size - board->flash_boot_base :0x02000000 );memory_region_add_subregion (system_memory,0xfe000000 , flash_io); }
@@ -313,6 +314,7 @@ static void xtensa_kc705_init(QEMUMachineInitArgs *args)static const LxBoardDesc kc705_board = { .flash_base =0xf0000000 , .flash_size =0x08000000 , + .flash_boot_base =0x06000000 , .flash_sector_size =0x20000 , .sram_size =0x2000000 , };
Signature · 1 line
1.9.1
PATCH 85/108 target-i386: Make TCG feature filtering more readable
In reply to Michael RothFrom: Eduardo Habkost <[email protected]>
Instead of an #ifdef in the middle of the code, just set TCG_EXT2_FEATURES to a different value depending on TARGET_X86_64.
Conflicts:
target-i386/cpu.c
*removed dependency on 77549a78
--- target-i386/cpu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
target-i386/cpu.c +10 -6
@@ -566,9 +566,17 @@ struct X86CPUDefinition {CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_XSAVE, CPUID_EXT_OSXSAVE, CPUID_EXT_AVX, CPUID_EXT_F16C, CPUID_EXT_RDRAND */ + +#ifdef TARGET_X86_64 +#define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) +#else +#define TCG_EXT2_X86_64_FEATURES 0 +#endif +#define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \ CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \ - CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT) + CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | \ + TCG_EXT2_X86_64_FEATURES)/* missing: CPUID_EXT2_PDPE1GB */ #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
@@ -2590,11 +2598,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)if (!kvm_enabled ()) { env->features[FEAT_1_EDX ] &=TCG_FEATURES ; env->features[FEAT_1_ECX ] &=TCG_EXT_FEATURES ; - env->features[FEAT_8000_0001_EDX ] &= (TCG_EXT2_FEATURES -#ifdef TARGET_X86_64 - |CPUID_EXT2_SYSCALL |CPUID_EXT2_LM -#endif - ); + env->features[FEAT_8000_0001_EDX ] &=TCG_EXT2_FEATURES ; env->features[FEAT_8000_0001_ECX ] &=TCG_EXT3_FEATURES ; env->features[FEAT_SVM ] &=TCG_SVM_FEATURES ; }else {
Signature · 1 line
1.9.1
PATCH 88/108 virtio-serial: don't migrate the config space
In reply to Michael RothFrom: Alexander Graf <[email protected]>
The device configuration is set at realize time and never changes. It should not be migrated as it is done today. For the sake of compatibility, let's just skip them at load time.
[ added missing casts to uint16_t *,
added From, SoB and commit message,
Greg Kurz <[email protected]> ]
--- hw/char/virtio-serial-bus.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
hw/char/virtio-serial-bus.c +6 -10
@@ -670,6 +670,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)uint32_t max_nr_ports, nr_active_ports, ports_map;unsigned int i;int ret; +uint32_t tmp;if (version_id >3 ) {return -EINVAL ;
@@ -685,17 +686,12 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } -/* The config space */ -qemu_get_be16s (f, &s->config.cols); -qemu_get_be16s (f, &s->config.rows); - -qemu_get_be32s (f, &max_nr_ports); -tswap32s (&max_nr_ports); -if (max_nr_ports >tswap32 (s->config.max_nr_ports)) { -/* Source could have had more ports than us. Fail migration. */ -return -EINVAL ; - } +/* Unused */ +qemu_get_be16s (f, (uint16_t *) &tmp); +qemu_get_be16s (f, (uint16_t *) &tmp); +qemu_get_be32s (f, &tmp); + max_nr_ports =tswap32 (s->config.max_nr_ports);for (i =0 ; i < (max_nr_ports +31 ) /32 ; i++) {qemu_get_be32s (f, &ports_map);
Signature · 1 line
1.9.1
PATCH 87/108 virtio-net: byteswap virtio-net header
In reply to Michael RothFrom: Cédric Le Goater <[email protected]>
TCP connectivity fails when the guest has a different endianness. The packets are silently dropped on the host by the tap backend when they are read from user space because the endianness of the virtio-net header is in the wrong order. These lines may appear in the guest console:
[ 454.709327] skbuff: bad partial csum: csum=8704/4096 len=74 [ 455.702554] skbuff: bad partial csum: csum=8704/4096 len=74
The issue that got first spotted with a ppc64le PowerKVM guest, but it also exists for the less common case of a x86_64 guest run by a big-endian ppc64 TCG hypervisor.
[ Ported from PowerKVM,
Greg Kurz <[email protected]> ]
--- hw/net/virtio-net.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/net/virtio-net.c +17 -0
@@ -863,6 +863,14 @@ static int virtio_net_has_buffers(VirtIONetQueue *q, int bufsize)return 1 ; } +static void virtio_net_hdr_swap (struct virtio_net_hdr *hdr) +{ +tswap16s (&hdr->hdr_len); +tswap16s (&hdr->gso_size); +tswap16s (&hdr->csum_start); +tswap16s (&hdr->csum_offset); +} +/* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so * it never finds out that the packets don't have valid checksums. This * causes dhclient to get upset. Fedora's carried a patch for ages to
@@ -898,6 +906,7 @@ static void receive_header(VirtIONet *n, const struct iovec *iov, int iov_cnt,void *wbuf = (void *)buf;work_around_broken_dhclient (wbuf, wbuf + n->host_hdr_len, size - n->host_hdr_len); +virtio_net_hdr_swap (wbuf);iov_from_buf (iov, iov_cnt,0 , buf,sizeof (struct virtio_net_hdr )); }else { struct virtio_net_hdr hdr = {
@@ -1106,6 +1115,14 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)exit (1 ); } +if (n->has_vnet_hdr) { +if (out_sg[0 ].iov_len < n->guest_hdr_len) { +error_report ("virtio-net header incorrect" ); +exit (1 ); + } +virtio_net_hdr_swap ((void *) out_sg[0 ].iov_base); + } +/* * If host wants to see the guest header as is, we can * pass it on unchanged. Otherwise, copy just the parts
Signature · 1 line
1.9.1
PATCH 89/108 nbd: Don't export a block device with no medium.
In reply to Michael RothFrom: Hani Benhabiles <[email protected]>
The device is exported with erroneous values and can't be read.
Before the patch:
$ sudo nbd-client localhost -p 10809 /dev/nbd0 -name floppy0 Negotiation: ..size = 17592186044415MB bs=1024, sz=18446744073709547520 bytes
$ sudo mount /dev/nbd0 /mnt/tmp/ mount: block device /dev/nbd0 is write-protected, mounting read-only mount: /dev/nbd0: can't read superblock
After the patch:
(qemu) nbd_server_add ide0-hd0
(qemu) nbd_server_add floppy0
Device 'floppy0' has no medium
--- blockdev-nbd.c | 4 ++++ 1 file changed, 4 insertions(+)
blockdev-nbd.c +4 -0
@@ -91,6 +91,10 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,error_set (errp,QERR_DEVICE_NOT_FOUND , device);return ; } +if (!bdrv_is_inserted (bs)) { +error_set (errp,QERR_DEVICE_HAS_NO_MEDIUM , device); +return ; + }if (!has_writable) { writable = false;
Signature · 1 line
1.9.1
PATCH 74/108 hw: Consistently name Error ** objects errp, and not err
In reply to Michael RothFrom: Markus Armbruster <[email protected]>
--- hw/core/qdev.c | 20 ++++++++++---------- hw/intc/i8259.c | 4 ++-- hw/timer/i8254.c | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-)
hw/core/qdev.c +10 -10
@@ -174,14 +174,14 @@ int qdev_init(DeviceState *dev)return 0 ; } -static void device_realize (DeviceState *dev,Error **err) +static void device_realize (DeviceState *dev,Error **errp) {DeviceClass *dc =DEVICE_GET_CLASS (dev);if (dc->init) {int rc = dc->init (dev);if (rc <0 ) { -error_setg (err,"Device initialization failed." ); +error_setg (errp,"Device initialization failed." );return ; } }
@@ -504,14 +504,14 @@ static void bus_unparent(Object *obj) } } -static bool bus_get_realized (Object *obj,Error **err) +static bool bus_get_realized (Object *obj,Error **errp) {BusState *bus =BUS (obj);return bus->realized; } -static void bus_set_realized (Object *obj,bool value,Error **err) +static void bus_set_realized (Object *obj,bool value,Error **errp) {BusState *bus =BUS (obj);BusClass *bc =BUS_GET_CLASS (bus);
@@ -540,7 +540,7 @@ static void bus_set_realized(Object *obj, bool value, Error **err)return ; error: -error_propagate (err, local_err); +error_propagate (errp, local_err); } void qbus_create_inplace(void *bus, size_t size, const char *typename,
@@ -724,13 +724,13 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, } } -static bool device_get_realized (Object *obj,Error **err) +static bool device_get_realized (Object *obj,Error **errp) {DeviceState *dev =DEVICE (obj);return dev->realized; } -static void device_set_realized (Object *obj,bool value,Error **err) +static void device_set_realized (Object *obj,bool value,Error **errp) {DeviceState *dev =DEVICE (obj);DeviceClass *dc =DEVICE_GET_CLASS (dev);
@@ -738,7 +738,7 @@ static void device_set_realized(Object *obj, bool value, Error **err)Error *local_err =NULL ;if (dev->hotplugged && !dc->hotpluggable) { -error_set (err,QERR_DEVICE_NO_HOTPLUG ,object_get_typename (obj)); +error_set (errp,QERR_DEVICE_NO_HOTPLUG ,object_get_typename (obj));return ; }
@@ -797,14 +797,14 @@ static void device_set_realized(Object *obj, bool value, Error **err) }if (local_err !=NULL ) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return ; } dev->realized = value; } -static bool device_get_hotpluggable (Object *obj,Error **err) +static bool device_get_hotpluggable (Object *obj,Error **errp) {DeviceClass *dc =DEVICE_GET_CLASS (obj);DeviceState *dev =DEVICE (obj);
hw/intc/i8259.c +2 -2
@@ -412,7 +412,7 @@ static const MemoryRegionOps pic_elcr_ioport_ops = { }, }; -static void pic_realize (DeviceState *dev,Error **err) +static void pic_realize (DeviceState *dev,Error **errp) {PICCommonState *s =PIC_COMMON (dev);PICClass *pc =PIC_GET_CLASS (dev);
@@ -425,7 +425,7 @@ static void pic_realize(DeviceState *dev, Error **err)qdev_init_gpio_out (dev, s->int_out,ARRAY_SIZE (s->int_out));qdev_init_gpio_in (dev, pic_set_irq,8 ); - pc->parent_realize (dev, err); + pc->parent_realize (dev, errp); }void pic_info (Monitor *mon,const QDict *qdict)
hw/timer/i8254.c +2 -2
@@ -322,7 +322,7 @@ static void pit_post_load(PITCommonState *s) } } -static void pit_realizefn (DeviceState *dev,Error **err) +static void pit_realizefn (DeviceState *dev,Error **errp) {PITCommonState *pit =PIT_COMMON (dev);PITClass *pc =PIT_GET_CLASS (dev);
@@ -338,7 +338,7 @@ static void pit_realizefn(DeviceState *dev, Error **err)qdev_init_gpio_in (dev, pit_irq_control,1 ); - pc->parent_realize (dev, err); + pc->parent_realize (dev, errp); }static Property pit_properties[] = {
Signature · 1 line
1.9.1
PATCH 90/108 nbd: Don't validate from and len in NBD_CMD_DISC.
In reply to Michael RothFrom: Hani Benhabiles <[email protected]>
These values aren't used in this case.
Currently, the from field in the request sent by the nbd kernel module leading to a false error message when ending the connection with the client.
$ qemu-nbd some.img -v // After nbd-client -d /dev/nbd0 nbd.c:nbd_trip():L1031: From: 18446744073709551104, Len: 0, Size: 20971520, Offset: 0 nbd.c:nbd_trip():L1032: requested operation past EOF--bad client? nbd.c:nbd_receive_request():L638: read failed
--- nbd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
nbd.c +4 -3
@@ -1001,6 +1001,7 @@ static void nbd_trip(void *opaque)struct nbd_request request;struct nbd_reply reply;ssize_t ret; +uint32_t command;TRACE ("Reading request." );if (client->closing) {
@@ -1023,8 +1024,8 @@ static void nbd_trip(void *opaque) reply.error = -ret; goto error_reply; } - -if ((request.from + request.len) > exp->size) { + command = request.type &NBD_CMD_MASK_COMMAND ; +if (command !=NBD_CMD_DISC && (request.from + request.len) > exp->size) { LOG("From: %" PRIu64 ", Len: %u, Size: %" PRIu64 ", Offset: %" PRIu64 "\n", request.from, request.len,
@@ -1033,7 +1034,7 @@ static void nbd_trip(void *opaque) goto invalid_request; } -switch (request.type &NBD_CMD_MASK_COMMAND ) { +switch (command) {case NBD_CMD_READ :TRACE ("Request type is READ" );
Signature · 1 line
1.9.1
PATCH 94/108 pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout
In reply to Michael RothFrom: Don Slutz <[email protected]>
QEMU 2.0 changed memory layout for isapc and pc-0.10 to pc-0.13. This prevents migration from QEMU 1.7.0 for these machine types when -m 3.5G is specified.
Paolo Bonzini asked that:
smbios_legacy_mode = true;
has_reserved_memory = false;
option_rom_has_mr = true;
rom_file_has_mr = false;also be done.
Conflicts:
hw/i386/pc_piix.c
*removed dependency on c97294ec: smbios_legacy_mode always true pre-2.1.0 *removed dependency on de268e13: has_reserved_memory always false pre-2.1.0
--- hw/i386/pc_piix.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/i386/pc_piix.c +6 -0
@@ -346,6 +346,9 @@ static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args) has_pci_info = false; has_acpi_build = false; smbios_defaults = false; + gigabyte_align = false; + option_rom_has_mr = true; + rom_file_has_mr = false;x86_cpu_compat_disable_kvm_features (FEAT_KVM ,KVM_FEATURE_PV_EOI );enable_compat_apic_id_mode ();pc_init1 (args,1 ,0 );
@@ -356,6 +359,9 @@ static void pc_init_isa(QEMUMachineInitArgs *args) has_pci_info = false; has_acpi_build = false; smbios_defaults = false; + gigabyte_align = false; + option_rom_has_mr = true; + rom_file_has_mr = false;if (!args->cpu_model) { args->cpu_model ="486" ; }
Signature · 1 line
1.9.1
PATCH 91/108 nbd: Close socket on negotiation failure.
In reply to Michael RothFrom: Hani Benhabiles <[email protected]>
Otherwise, the nbd client may hang waiting for the server response.
--- blockdev-nbd.c | 4 ++-- qemu-nbd.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
blockdev-nbd.c +2 -2
@@ -27,8 +27,8 @@ static void nbd_accept(void *opaque)socklen_t addr_len =sizeof (addr);int fd =accept (server_fd, (struct sockaddr *)&addr, &addr_len); -if (fd >=0 ) { -nbd_client_new (NULL , fd, nbd_client_put); +if (fd >=0 && !nbd_client_new (NULL , fd, nbd_client_put)) { +close (fd); } }
qemu-nbd.c +3 -1
@@ -369,8 +369,10 @@ static void nbd_accept(void *opaque)return ; } -if (fd >=0 &&nbd_client_new (exp, fd, nbd_client_closed)) { +if (nbd_client_new (exp, fd, nbd_client_closed)) { nb_fds++; + }else { +close (fd); } }
Signature · 1 line
1.9.1
PATCH 95/108 sdhci: Fix misuse of qemu_free_irqs()
In reply to Michael RothFrom: Andreas Färber <[email protected]>
It does a g_free() on the pointer, so don't pass a local &foo reference.
--- hw/sd/sdhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/sd/sdhci.c +2 -2
@@ -1184,8 +1184,8 @@ static void sdhci_uninitfn(Object *obj)timer_free (s->insert_timer);timer_del (s->transfer_timer);timer_free (s->transfer_timer); -qemu_free_irqs (&s->eject_cb); -qemu_free_irqs (&s->ro_cb); +qemu_free_irq (s->eject_cb); +qemu_free_irq (s->ro_cb);if (s->fifo_buffer) {g_free (s->fifo_buffer);
Signature · 1 line
1.9.1
PATCH 92/108 nbd: Shutdown socket before closing.
In reply to Michael RothFrom: Hani Benhabiles <[email protected]>
This forces finishing data sending to client before closing the socket like in exports listing or replying with NBD_REP_ERR_UNSUP cases.
--- blockdev-nbd.c | 1 + qemu-nbd.c | 1 + 2 files changed, 2 insertions(+)
blockdev-nbd.c +1 -0
@@ -28,6 +28,7 @@ static void nbd_accept(void *opaque)int fd =accept (server_fd, (struct sockaddr *)&addr, &addr_len);if (fd >=0 && !nbd_client_new (NULL , fd, nbd_client_put)) { +shutdown (fd,2 );close (fd); } }
qemu-nbd.c +1 -0
@@ -372,6 +372,7 @@ static void nbd_accept(void *opaque)if (nbd_client_new (exp, fd, nbd_client_closed)) { nb_fds++; }else { +shutdown (fd,2 );close (fd); } }
Signature · 1 line
1.9.1
PATCH 96/108 hw: Fix qemu_allocate_irqs() leaks
In reply to Michael RothFrom: Andreas Färber <[email protected]>
Replace qemu_allocate_irqs(foo, bar, 1)[0]
with qemu_allocate_irq(foo, bar, 0).
This avoids leaking the dereferenced qemu_irq *.
[PC Changes:
* Applied change to instance in sh4/sh7750.c
]
--- hw/arm/omap1.c | 14 +++++++------- hw/arm/omap2.c | 2 +- hw/arm/pxa2xx.c | 4 ++-- hw/arm/spitz.c | 4 ++-- hw/arm/z2.c | 2 +- hw/core/irq.c | 4 ++-- hw/dma/omap_dma.c | 4 ++-- hw/ide/microdrive.c | 2 +- hw/misc/cbus.c | 6 +++--- hw/pcmcia/pxa2xx.c | 2 +- hw/sd/omap_mmc.c | 2 +- hw/sd/sdhci.c | 4 ++-- hw/sh4/sh7750.c | 3 +-- hw/timer/omap_gptimer.c | 4 ++-- 14 files changed, 28 insertions(+), 29 deletions(-)
hw/arm/omap1.c +7 -7
@@ -172,7 +172,7 @@ static void omap_timer_clk_update(void *opaque, int line, int on)static void omap_timer_clk_setup (struct omap_mpu_timer_s *timer) {omap_clk_adduser (timer->clk, -qemu_allocate_irqs (omap_timer_clk_update, timer,1 )[0 ]); +qemu_allocate_irq (omap_timer_clk_update, timer,0 )); timer->rate =omap_clk_getrate (timer->clk); }
@@ -2098,7 +2098,7 @@ static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory, "omap-mpuio", 0x800);memory_region_add_subregion (memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irqs (omap_mpuio_onoff, s,1 )[0 ]); +omap_clk_adduser (clk,qemu_allocate_irq (omap_mpuio_onoff, s,0 ));return s; }
@@ -2401,7 +2401,7 @@ static struct omap_pwl_s *omap_pwl_init(MemoryRegion *system_memory, "omap-pwl", 0x800);memory_region_add_subregion (system_memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irqs (omap_pwl_clk_update, s,1 )[0 ]); +omap_clk_adduser (clk,qemu_allocate_irq (omap_pwl_clk_update, s,0 ));return s; }
@@ -3485,8 +3485,8 @@ static void omap_mcbsp_i2s_start(void *opaque, int line, int level)void omap_mcbsp_i2s_attach (struct omap_mcbsp_s *s,I2SCodec *slave) { s->codec = slave; - slave->rx_swallow =qemu_allocate_irqs (omap_mcbsp_i2s_swallow, s,1 )[0 ]; - slave->tx_start =qemu_allocate_irqs (omap_mcbsp_i2s_start, s,1 )[0 ]; + slave->rx_swallow =qemu_allocate_irq (omap_mcbsp_i2s_swallow, s,0 ); + slave->tx_start =qemu_allocate_irq (omap_mcbsp_i2s_start, s,0 ); }/* LED Pulse Generators */
@@ -3634,7 +3634,7 @@ static struct omap_lpg_s *omap_lpg_init(MemoryRegion *system_memory,memory_region_init_io (&s->iomem,NULL , &omap_lpg_ops, s,"omap-lpg" ,0x800 );memory_region_add_subregion (system_memory, base, &s->iomem); -omap_clk_adduser (clk,qemu_allocate_irqs (omap_lpg_clk_update, s,1 )[0 ]); +omap_clk_adduser (clk,qemu_allocate_irq (omap_lpg_clk_update, s,0 ));return s; }
@@ -3848,7 +3848,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory, s->sdram_size = sdram_size; s->sram_size =OMAP15XX_SRAM_SIZE ; - s->wakeup =qemu_allocate_irqs (omap_mpu_wakeup, s,1 )[0 ]; + s->wakeup =qemu_allocate_irq (omap_mpu_wakeup, s,0 );/* Clocks */ omap_clk_init (s);
hw/arm/omap2.c +1 -1
@@ -2260,7 +2260,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem, s->sdram_size = sdram_size; s->sram_size =OMAP242X_SRAM_SIZE ; - s->wakeup =qemu_allocate_irqs (omap_mpu_wakeup, s,1 )[0 ]; + s->wakeup =qemu_allocate_irq (omap_mpu_wakeup, s,0 );/* Clocks */ omap_clk_init (s);
hw/arm/pxa2xx.c +2 -2
@@ -2059,7 +2059,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } - s->reset =qemu_allocate_irqs (pxa2xx_reset, s,1 )[0 ]; + s->reset =qemu_allocate_irq (pxa2xx_reset, s,0 );/* SDRAM & Internal Memory Storage */ memory_region_init_ram (&s->sdram,NULL ,"pxa270.sdram" , sdram_size);
@@ -2190,7 +2190,7 @@ PXA2xxState *pxa255_init(MemoryRegion *address_space, unsigned int sdram_size)fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } - s->reset =qemu_allocate_irqs (pxa2xx_reset, s,1 )[0 ]; + s->reset =qemu_allocate_irq (pxa2xx_reset, s,0 );/* SDRAM & Internal Memory Storage */ memory_region_init_ram (&s->sdram,NULL ,"pxa255.sdram" , sdram_size);
hw/arm/spitz.c +2 -2
@@ -744,7 +744,7 @@ static void spitz_i2c_setup(PXA2xxState *cpu)spitz_wm8750_addr (wm,0 ,0 );qdev_connect_gpio_out (cpu->gpio,SPITZ_GPIO_WM , -qemu_allocate_irqs (spitz_wm8750_addr, wm,1 )[0 ]); +qemu_allocate_irq (spitz_wm8750_addr, wm,0 ));/* .. and to the sound interface. */ cpu->i2s->opaque = wm; cpu->i2s->codec_out = wm8750_dac_dat;
@@ -850,7 +850,7 @@ static void spitz_gpio_setup(PXA2xxState *cpu, int slots)* wouldn't guarantee that a guest ever exits the loop. */ spitz_hsync =0 ; - lcd_hsync =qemu_allocate_irqs (spitz_lcd_hsync_handler, cpu,1 )[0 ]; + lcd_hsync =qemu_allocate_irq (spitz_lcd_hsync_handler, cpu,0 );pxa2xx_gpio_read_notifier (cpu->gpio, lcd_hsync);pxa2xx_lcd_vsync_notifier (cpu->lcd, lcd_hsync);
hw/arm/z2.c +1 -1
@@ -365,7 +365,7 @@ static void z2_init(QEMUMachineInitArgs *args)wm8750_data_req_set (wm, mpu->i2s->data_req, mpu->i2s);qdev_connect_gpio_out (mpu->gpio,Z2_GPIO_LCD_CS , -qemu_allocate_irqs (z2_lcd_cs, z2_lcd,1 )[0 ]); +qemu_allocate_irq (z2_lcd_cs, z2_lcd,0 )); z2_binfo.kernel_filename = kernel_filename; z2_binfo.kernel_cmdline = kernel_cmdline;
hw/core/irq.c +2 -2
@@ -102,7 +102,7 @@ qemu_irq qemu_irq_invert(qemu_irq irq) {/* The default state for IRQs is low, so raise the output now. */ qemu_irq_raise (irq); -return qemu_allocate_irqs (qemu_notirq, irq,1 )[0 ]; +return qemu_allocate_irq (qemu_notirq, irq,0 ); }static void qemu_splitirq (void *opaque,int line,int level)
@@ -117,7 +117,7 @@ qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2)qemu_irq *s =g_malloc0 (2 *sizeof (qemu_irq)); s[0 ] = irq1; s[1 ] = irq2; -return qemu_allocate_irqs (qemu_splitirq, s,1 )[0 ]; +return qemu_allocate_irq (qemu_splitirq, s,0 ); }static void proxy_irq_handler (void *opaque,int n,int level)
hw/dma/omap_dma.c +2 -2
@@ -1660,7 +1660,7 @@ struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs, }omap_dma_setcaps (s); -omap_clk_adduser (s->clk,qemu_allocate_irqs (omap_dma_clk_update, s,1 )[0 ]); +omap_clk_adduser (s->clk,qemu_allocate_irq (omap_dma_clk_update, s,0 ));omap_dma_reset (s->dma);omap_dma_clk_update (s,0 ,1 );
@@ -2082,7 +2082,7 @@ struct soc_dma_s *omap_dma4_init(hwaddr base, qemu_irq *irqs, s->intr_update = omap_dma_interrupts_4_update;omap_dma_setcaps (s); -omap_clk_adduser (s->clk,qemu_allocate_irqs (omap_dma_clk_update, s,1 )[0 ]); +omap_clk_adduser (s->clk,qemu_allocate_irq (omap_dma_clk_update, s,0 ));omap_dma_reset (s->dma);omap_dma_clk_update (s,0 , !!s->dma->freq);
hw/ide/microdrive.c +1 -1
@@ -594,7 +594,7 @@ static void microdrive_realize(DeviceState *dev, Error **errp) {MicroDriveState *md =MICRODRIVE (dev); -ide_init2 (&md->bus,qemu_allocate_irqs (md_set_irq, md,1 )[0 ]); +ide_init2 (&md->bus,qemu_allocate_irq (md_set_irq, md,0 )); }static void microdrive_init (Object *obj)
hw/misc/cbus.c +3 -3
@@ -135,9 +135,9 @@ CBus *cbus_init(qemu_irq dat)CBusPriv *s = (CBusPriv *)g_malloc0 (sizeof (*s)); s->dat_out = dat; - s->cbus.clk =qemu_allocate_irqs (cbus_clk, s,1 )[0 ]; - s->cbus.dat =qemu_allocate_irqs (cbus_dat, s,1 )[0 ]; - s->cbus.sel =qemu_allocate_irqs (cbus_sel, s,1 )[0 ]; + s->cbus.clk =qemu_allocate_irq (cbus_clk, s,0 ); + s->cbus.dat =qemu_allocate_irq (cbus_dat, s,0 ); + s->cbus.sel =qemu_allocate_irq (cbus_sel, s,0 ); s->sel =1 ; s->clk =0 ;
hw/pcmcia/pxa2xx.c +1 -1
@@ -195,7 +195,7 @@ static void pxa2xx_pcmcia_initfn(Object *obj)memory_region_add_subregion (&s->container_mem,0x0c000000 , &s->common_iomem); - s->slot.irq =qemu_allocate_irqs (pxa2xx_pcmcia_set_irq, s,1 )[0 ]; + s->slot.irq =qemu_allocate_irq (pxa2xx_pcmcia_set_irq, s,0 ); object_property_add_link(obj, "card", TYPE_PCMCIA_CARD, (Object **)&s->card,
hw/sd/omap_mmc.c +1 -1
@@ -625,7 +625,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,exit (1 ); } - s->cdet =qemu_allocate_irqs (omap_mmc_cover_cb, s,1 )[0 ]; + s->cdet =qemu_allocate_irq (omap_mmc_cover_cb, s,0 );sd_set_cb (s->card,NULL , s->cdet);return s;
hw/sd/sdhci.c +2 -2
@@ -1168,8 +1168,8 @@ static void sdhci_initfn(Object *obj)if (s->card ==NULL ) {exit (1 ); } - s->eject_cb =qemu_allocate_irqs (sdhci_insert_eject_cb, s,1 )[0 ]; - s->ro_cb =qemu_allocate_irqs (sdhci_card_readonly_cb, s,1 )[0 ]; + s->eject_cb =qemu_allocate_irq (sdhci_insert_eject_cb, s,0 ); + s->ro_cb =qemu_allocate_irq (sdhci_card_readonly_cb, s,0 );sd_set_cb (s->card, s->ro_cb, s->eject_cb); s->insert_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sdhci_raise_insertion_irq, s);
hw/sh4/sh7750.c +1 -2
@@ -838,6 +838,5 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)qemu_irq sh7750_irl (SH7750State *s) {sh_intc_toggle_source (sh_intc_source (&s->intc,IRL ),1 ,0 );/* enable */ -return qemu_allocate_irqs (sh_intc_set_irl,sh_intc_source (&s->intc,IRL ), -1 )[0 ]; +return qemu_allocate_irq (sh_intc_set_irl,sh_intc_source (&s->intc,IRL ),0 ); }
hw/timer/omap_gptimer.c +2 -2
@@ -227,7 +227,7 @@ static void omap_gp_timer_clk_update(void *opaque, int line, int on)static void omap_gp_timer_clk_setup (struct omap_gp_timer_s *timer) {omap_clk_adduser (timer->clk, -qemu_allocate_irqs (omap_gp_timer_clk_update, timer,1 )[0 ]); +qemu_allocate_irq (omap_gp_timer_clk_update, timer,0 )); timer->rate =omap_clk_getrate (timer->clk); }
@@ -476,7 +476,7 @@ struct omap_gp_timer_s *omap_gp_timer_init(struct omap_target_agent_s *ta, s->clk = fclk; s->timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , omap_gp_timer_tick, s); s->match =timer_new_ns (QEMU_CLOCK_VIRTUAL , omap_gp_timer_match, s); - s->in =qemu_allocate_irqs (omap_gp_timer_input, s,1 )[0 ]; + s->in =qemu_allocate_irq (omap_gp_timer_input, s,0 );omap_gp_timer_reset (s);omap_gp_timer_clk_setup (s);
Signature · 1 line
1.9.1
PATCH 93/108 SMBIOS: Rename symbols to better reflect future use
In reply to Michael RothFrom: "Gabriel L. Somlo" <[email protected]>
Rename the following symbols:
- smbios_set_type1_defaults() to the more general smbios_set_defaults();
- bool smbios_type1_defaults to the more general smbios_defaults;
- smbios_get_table() to smbios_get_table_legacy();
This patch contains no functional changes.
Conflicts:
hw/i386/pc_piix.c hw/i386/pc_q35.c
*removed dependency on 3458b2b0
--- hw/i386/pc.c | 2 +- hw/i386/pc_piix.c | 14 +++++++------- hw/i386/pc_q35.c | 10 +++++----- hw/i386/smbios.c | 18 ++++++++++++------ include/hw/i386/smbios.h | 6 +++--- 5 files changed, 28 insertions(+), 22 deletions(-)
hw/i386/pc.c +1 -1
@@ -655,7 +655,7 @@ static FWCfgState *bochs_bios_init(void) acpi_tables, acpi_tables_len);fw_cfg_add_i32 (fw_cfg,FW_CFG_IRQ0_OVERRIDE ,kvm_allows_irq0_override ()); - smbios_table =smbios_get_table (&smbios_len); + smbios_table =smbios_get_table_legacy (&smbios_len);if (smbios_table)fw_cfg_add_bytes (fw_cfg,FW_CFG_SMBIOS_ENTRIES , smbios_table, smbios_len);
hw/i386/pc_piix.c +7 -7
@@ -60,7 +60,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };static bool has_pci_info;static bool has_acpi_build = true; -static bool smbios_type1_defaults = true; +static bool smbios_defaults = true;/* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to * host addresses aligned at 1Gbyte boundaries. This way we can use 1GByte * pages in the host.
@@ -143,10 +143,10 @@ static void pc_init1(QEMUMachineInitArgs *args, guest_info->has_pci_info = has_pci_info; guest_info->isapc_ram_fw = !pci_enabled; -if (smbios_type1_defaults) { +if (smbios_defaults) {/* These values are guest ABI, do not change */ -smbios_set_type1_defaults ("QEMU" ,"Standard PC (i440FX + PIIX, 1996)" , - args->machine->name); +smbios_set_defaults ("QEMU" ,"Standard PC (i440FX + PIIX, 1996)" , + args->machine->name); }/* allocate ram and load rom/bios */
@@ -264,7 +264,7 @@ static void pc_init_pci(QEMUMachineInitArgs *args)static void pc_compat_1_7 (QEMUMachineInitArgs *args) { - smbios_type1_defaults = false; + smbios_defaults = false; gigabyte_align = false; option_rom_has_mr = true;x86_cpu_compat_disable_kvm_features (FEAT_1_ECX ,CPUID_EXT_X2APIC );
@@ -345,7 +345,7 @@ static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args) { has_pci_info = false; has_acpi_build = false; - smbios_type1_defaults = false; + smbios_defaults = false;x86_cpu_compat_disable_kvm_features (FEAT_KVM ,KVM_FEATURE_PV_EOI );enable_compat_apic_id_mode ();pc_init1 (args,1 ,0 );
@@ -355,7 +355,7 @@ static void pc_init_isa(QEMUMachineInitArgs *args) { has_pci_info = false; has_acpi_build = false; - smbios_type1_defaults = false; + smbios_defaults = false;if (!args->cpu_model) { args->cpu_model ="486" ; }
hw/i386/pc_q35.c +5 -5
@@ -50,7 +50,7 @@static bool has_pci_info;static bool has_acpi_build = true; -static bool smbios_type1_defaults = true; +static bool smbios_defaults = true;/* Make sure that guest addresses aligned at 1Gbyte boundaries get mapped to * host addresses aligned at 1Gbyte boundaries. This way we can use 1GByte * pages in the host.
@@ -130,10 +130,10 @@ static void pc_q35_init(QEMUMachineInitArgs *args) guest_info->isapc_ram_fw = false; guest_info->has_acpi_build = has_acpi_build; -if (smbios_type1_defaults) { +if (smbios_defaults) {/* These values are guest ABI, do not change */ -smbios_set_type1_defaults ("QEMU" ,"Standard PC (Q35 + ICH9, 2009)" , - args->machine->name); +smbios_set_defaults ("QEMU" ,"Standard PC (Q35 + ICH9, 2009)" , + args->machine->name); }/* allocate ram and load rom/bios */
@@ -242,7 +242,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)static void pc_compat_1_7 (QEMUMachineInitArgs *args) { - smbios_type1_defaults = false; + smbios_defaults = false; gigabyte_align = false; option_rom_has_mr = true;x86_cpu_compat_disable_kvm_features (FEAT_1_ECX ,CPUID_EXT_X2APIC );
hw/i386/smbios.c +12 -6
@@ -21,9 +21,8 @@#include "hw/i386/smbios.h" #include "hw/loader.h" -/* -* Structures shared with the BIOS -*/ + +/* legacy structures and constants for <= 2.0 machines */ struct smbios_header {uint16_t length;uint8_t type;
@@ -46,6 +45,9 @@ struct smbios_table {static uint8_t *smbios_entries;static size_t smbios_entries_len; +/* end: legacy structures & constants for <= 2.0 machines */ + +static int smbios_type4_count =0 ;static bool smbios_immutable;
@@ -187,6 +189,8 @@ static void smbios_check_collision(int type, int entry) } } + +/* legacy setup functions for <= 2.0 machines */ static void smbios_add_field (int type,int offset,const void *data,size_t len) {struct smbios_field *field;
@@ -256,8 +260,8 @@ static void smbios_build_type_1_fields(void) } } -void smbios_set_type1_defaults (const char *manufacturer, -const char *product,const char *version) +void smbios_set_defaults (const char *manufacturer,const char *product, +const char *version) {if (!type1.manufacturer) { type1.manufacturer = manufacturer;
@@ -270,7 +274,7 @@ void smbios_set_type1_defaults(const char *manufacturer, } } -uint8_t *smbios_get_table (size_t *length) +uint8_t *smbios_get_table_legacy (size_t *length) {if (!smbios_immutable) {smbios_build_type_0_fields ();
@@ -281,6 +285,8 @@ uint8_t *smbios_get_table(size_t *length) *length = smbios_entries_len;return smbios_entries; } +/* end: legacy setup functions for <= 2.0 machines */ +static void save_opt (const char **dest,QemuOpts *opts,const char *name) {
include/hw/i386/smbios.h +3 -3
@@ -16,9 +16,9 @@#include "qemu/option.h" void smbios_entry_add (QemuOpts *opts); -void smbios_set_type1_defaults (const char *manufacturer, -const char *product,const char *version); -uint8_t *smbios_get_table (size_t *length); +void smbios_set_defaults (const char *manufacturer,const char *product, +const char *version); +uint8_t *smbios_get_table_legacy (size_t *length);/* * SMBIOS spec defined tables
Signature · 1 line
1.9.1
PATCH 97/108 virtio: out-of-bounds buffer write on invalid state load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
CVE-2013-4151 QEMU 1.0 out-of-bounds buffer write in virtio_load@hw/virtio/virtio.c
So we have this code since way back when:
num = qemu_get_be32(f);
for (i = 0; i < num; i++) {
vdev->vq[i].vring.num = qemu_get_be32(f);array of vqs has size VIRTIO_PCI_QUEUE_MAX, so on invalid input this will write beyond end of buffer.
--- hw/virtio/virtio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +7 -1
@@ -897,7 +897,8 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)int virtio_load (VirtIODevice *vdev,QEMUFile *f) { -int num, i, ret; +int i, ret; +uint32_t num;uint32_t features;uint32_t supported_features;BusState *qbus =qdev_get_parent_bus (DEVICE (vdev));
@@ -928,6 +929,11 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) num =qemu_get_be32 (f); +if (num >VIRTIO_PCI_QUEUE_MAX ) { +error_report ("Invalid number of PCI queues: 0x%x" , num); +return -1 ; + } +for (i =0 ; i < num; i++) { vdev->vq[i].vring.num =qemu_get_be32 (f);if (k->has_variable_vring_alignment) {
Signature · 1 line
1.9.1
PATCH 81/108 KVM: Fix GSI number space limit
In reply to Michael RothFrom: Alexander Graf <[email protected]>
KVM tells us the number of GSIs it can handle inside the kernel. That value is basically KVM_MAX_IRQ_ROUTES. However when we try to set the GSI mapping table, it checks for
r = -EINVAL;
if (routing.nr >= KVM_MAX_IRQ_ROUTES)
goto out;erroring out even when we're only using all of the GSIs. To make sure we never hit that limit, let's reduce the number of GSIs we get from KVM by one.
--- kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kvm-all.c +1 -1
@@ -948,7 +948,7 @@ void kvm_init_irq_routing(KVMState *s) {int gsi_count, i; - gsi_count =kvm_check_extension (s,KVM_CAP_IRQ_ROUTING ); + gsi_count =kvm_check_extension (s,KVM_CAP_IRQ_ROUTING ) -1 ;if (gsi_count >0 ) {unsigned int gsi_bits, i;
Signature · 1 line
1.9.1
PATCH 98/108 virtio: validate config_len on load
In reply to Michael RothFrom: "Michael S. Tsirkin" <[email protected]>
Malformed input can have config_len in migration stream exceed the array size allocated on destination, the result will be heap overflow.
To fix, that config_len matches on both sides.
CVE-2014-0182
--
v2: use %ix and %zx to print config_len values
--- hw/virtio/virtio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +7 -1
@@ -898,6 +898,7 @@ int virtio_set_features(VirtIODevice *vdev, uint32_t val)int virtio_load (VirtIODevice *vdev,QEMUFile *f) {int i, ret; +int32_t config_len;uint32_t num;uint32_t features;uint32_t supported_features;
@@ -924,7 +925,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f) features, supported_features);return -1 ; } - vdev->config_len =qemu_get_be32 (f); + config_len =qemu_get_be32 (f); +if (config_len != vdev->config_len) { +error_report ("Unexpected config length 0x%x. Expected 0x%zx" , + config_len, vdev->config_len); +return -1 ; + }qemu_get_buffer (f, vdev->config, vdev->config_len); num =qemu_get_be32 (f);
Signature · 1 line
1.9.1
PATCH 101/108 mc146818rtc: register the clock reset notifier on the right clock
In reply to Michael RothFrom: Paolo Bonzini <[email protected]>
Commit 884f17c (aio / timers: Convert rtc_clock to be a QEMUClockType, 2013-08-21) erroneously changed an occurrence of rtc_clock to QEMU_CLOCK_REALTIME, which broke the RTC reset notifier in mc146818rtc. Fix this.
I redid the patch myself since the original reporter did not sign off on his.
--- hw/timer/mc146818rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/mc146818rtc.c +1 -1
@@ -852,7 +852,7 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)check_update_timer (s); s->clock_reset_notifier.notify = rtc_notify_clock_reset; -qemu_clock_register_reset_notifier (QEMU_CLOCK_REALTIME , +qemu_clock_register_reset_notifier (rtc_clock, &s->clock_reset_notifier); s->suspend_notifier.notify = rtc_notify_suspend;
Signature · 1 line
1.9.1
PATCH 102/108 disas/libvixl: prepend the include path of libvixl header files
In reply to Michael RothFrom: Stefano Stabellini <[email protected]>
Currently the Makefile of disas/libvixl appends -I$(SRC_PATH)/disas/libvixl to QEMU_CFLAGS. As a consequence C++ files that #include "utils.h", such as disas/libvixl/a64/instructions-a64.cc, are going to look for utils.h on all the other include paths first.
When building QEMU as part of the Xen make system, another unrelated utils.h file is going to be chosen for inclusion, causing a build failure:
In file included from disas/libvixl/a64/instructions-a64.cc:27:0:
/qemu/disas/libvixl/a64/instructions-a64.h:88:64: error:
'rawbits_to_float' was not declared in this scope
const float kFP32PositiveInfinity = rawbits_to_float(0x7f800000);
Fix the problem by prepending (rather than appending) the libvixl include path to QEMU_CFLAGS.
*added 2.0-specific fixup from Stefano in disas/Makefile.obj due to
lack of 849d8284
--- disas/Makefile.objs | 2 +- disas/libvixl/Makefile.objs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
disas/Makefile.objs +1 -1
@@ -4,7 +4,7 @@ common-obj-$(CONFIG_ARM_DIS) += arm.o common-obj-$(CONFIG_ARM_A64_DIS) += arm-a64.o common-obj-$(CONFIG_ARM_A64_DIS) += libvixl/ libvixldir = $(SRC_PATH)/disas/libvixl -$(obj)/arm-a64.o: QEMU_CFLAGS += -I$(libvixldir) +$(obj)/arm-a64.o: QEMU_CFLAGS := -I$(libvixldir) $(QEMU_CFLAGS) common-obj-$(CONFIG_CRIS_DIS) += cris.o common-obj-$(CONFIG_HPPA_DIS) += hppa.o common-obj-$(CONFIG_I386_DIS) += i386.o
disas/libvixl/Makefile.objs +1 -1
@@ -3,6 +3,6 @@ libvixl_OBJS = utils.o \ a64/decoder-a64.o \ a64/disasm-a64.o -$(addprefix $(obj)/,$(libvixl_OBJS)): QEMU_CFLAGS += -I$(SRC_PATH)/disas/libvixl +$(addprefix $(obj)/,$(libvixl_OBJS)): QEMU_CFLAGS := -I$(SRC_PATH)/disas/libvixl $(QEMU_CFLAGS) common-obj-$(CONFIG_ARM_A64_DIS) += $(libvixl_OBJS)
Signature · 1 line
1.9.1
PATCH 100/108 pci: assign devfn to pci_dev before calling pci_device_iommu_address_space()
In reply to Michael RothFrom: Le Tan <[email protected]>
In function do_pci_register_device() in file hw/pci/pci.c, move the assignment of pci_dev->devfn to the position before the call to pci_device_iommu_address_space(pci_dev) which will use the value of pci_dev->devfn.
pci: Introduce helper to retrieve a PCI device's DMA address space
--- hw/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
@@ -830,6 +830,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, } pci_dev->bus = bus; + pci_dev->devfn = devfn; dma_as =pci_device_iommu_address_space (pci_dev); memory_region_init_alias(&pci_dev->bus_master_enable_region,
@@ -839,7 +840,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region, name); - pci_dev->devfn = devfn;pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;pci_config_alloc (pci_dev);
Signature · 1 line
1.9.1
PATCH 103/108 s390x/kvm: synchronize guest floating point registers
In reply to Michael RothFrom: "Jason J. Herne" <[email protected]>
Add code to kvm_arch_get_registers and kvm_arch_put_registers to save/restore floating point registers. This missing sync was unnoticed until migration of userspace that uses fprs.
--- target-s390x/kvm.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
target-s390x/kvm.c +23 -0
@@ -164,6 +164,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)CPUS390XState *env = &cpu->env;struct kvm_sregs sregs;struct kvm_regs regs; +struct kvm_fpu fpu;int r;int i;
@@ -186,6 +187,17 @@ int kvm_arch_put_registers(CPUState *cs, int level) } } +/* Floating point */ +for (i =0 ; i <16 ; i++) { + fpu.fprs[i] = env->fregs[i].ll; + } + fpu.fpc = env->fpc; + + r =kvm_vcpu_ioctl (cs,KVM_SET_FPU , &fpu); +if (r <0 ) { +return r; + } +/* Do we need to save more than that? */ if (level ==KVM_PUT_RUNTIME_STATE ) {return 0 ;
@@ -251,6 +263,7 @@ int kvm_arch_get_registers(CPUState *cs)CPUS390XState *env = &cpu->env;struct kvm_sregs sregs;struct kvm_regs regs; +struct kvm_fpu fpu;int i, r;/* get the PSW */
@@ -291,6 +304,16 @@ int kvm_arch_get_registers(CPUState *cs) } } +/* Floating point */ + r =kvm_vcpu_ioctl (cs,KVM_GET_FPU , &fpu); +if (r <0 ) { +return r; + } +for (i =0 ; i <16 ; i++) { + env->fregs[i].ll = fpu.fprs[i]; + } + env->fpc = fpu.fpc; +/* The prefix */ if (cap_sync_regs && cs->kvm_run->kvm_valid_regs &KVM_SYNC_PREFIX ) { env->psa = cs->kvm_run->s.regs.prefix;
Signature · 1 line
1.9.1
PATCH 104/108 cadence_uart: check for serial backend before using it.
In reply to Michael RothFrom: KONRAD Frederic <[email protected]>
This checks that s->chr is not NULL before using it.
--- hw/char/cadence_uart.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
hw/char/cadence_uart.c +11 -4
@@ -175,8 +175,10 @@ static void uart_send_breaks(UartState *s) {int break_enabled =1 ; -qemu_chr_fe_ioctl (s->chr,CHR_IOCTL_SERIAL_SET_BREAK , - &break_enabled); +if (s->chr) { +qemu_chr_fe_ioctl (s->chr,CHR_IOCTL_SERIAL_SET_BREAK , + &break_enabled); + } }static void uart_parameters_setup (UartState *s)
@@ -227,7 +229,9 @@ static void uart_parameters_setup(UartState *s) packet_size += ssp.data_bits + ssp.stop_bits; s->char_tx_time = (get_ticks_per_sec () / ssp.speed) * packet_size; -qemu_chr_fe_ioctl (s->chr,CHR_IOCTL_SERIAL_SET_PARAMS , &ssp); +if (s->chr) { +qemu_chr_fe_ioctl (s->chr,CHR_IOCTL_SERIAL_SET_PARAMS , &ssp); + } }static int uart_can_receive (void *opaque)
@@ -295,6 +299,7 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond,/* instant drain the fifo when there's no back-end */ if (!s->chr) { s->tx_count =0 ; +return FALSE; }if (!s->tx_count) {
@@ -374,7 +379,9 @@ static void uart_read_rx_fifo(UartState *s, uint32_t *c) *c = s->rx_fifo[rx_rpos]; s->rx_count--; -qemu_chr_accept_input (s->chr); +if (s->chr) { +qemu_chr_accept_input (s->chr); + } }else { *c =0 ; }
Signature · 1 line
1.9.1
PATCH 105/108 kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL
In reply to Michael RothFrom: Chen Gang <[email protected]>
If kvm_arch_remove_sw_breakpoint() in CPU_FOREACH() always be fail, it will let 'cpu' NULL. And the next kvm_arch_remove_sw_breakpoint() in QTAILQ_FOREACH_SAFE() will get NULL parameter for 'cpu'.
And kvm_arch_remove_sw_breakpoint() can assumes 'cpu' must never be NULL, so need define additional temporary variable for 'cpu' to avoid the case.
--- kvm-all.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kvm-all.c +3 -2
@@ -2022,12 +2022,13 @@ void kvm_remove_all_breakpoints(CPUState *cpu) {struct kvm_sw_breakpoint *bp, *next;KVMState *s = cpu->kvm_state; +CPUState *tmpcpu; QTAILQ_FOREACH_SAFE(bp, &s->kvm_sw_breakpoints, entry, next) {if (kvm_arch_remove_sw_breakpoint (cpu, bp) !=0 ) {/* Try harder to find a CPU that currently sees the breakpoint. */ -CPU_FOREACH (cpu) { -if (kvm_arch_remove_sw_breakpoint (cpu, bp) ==0 ) { +CPU_FOREACH (tmpcpu) { +if (kvm_arch_remove_sw_breakpoint (tmpcpu, bp) ==0 ) {break ; } }
Signature · 1 line
1.9.1
PATCH 107/108 hw/misc/imx_ccm.c: Add missing VMState list terminator
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The VMStateDescription for the imx_ccm device was missing its
terminator. Found by static search of the codebase using
a regex based on one suggested by Ian Jackson:
pcregrep -rMi '(?s)VMStateField(?:(?!END_OF_LIST).)*?;' $(git grep -l 'VMStateField\[\]')
--- hw/misc/imx_ccm.c | 1 + 1 file changed, 1 insertion(+)
hw/misc/imx_ccm.c +1 -0
@@ -68,6 +68,7 @@ static const VMStateDescription vmstate_imx_ccm = { VMSTATE_UINT32(pmcr0, IMXCCMState), VMSTATE_UINT32(pmcr1, IMXCCMState), VMSTATE_UINT32(pll_refclk_freq, IMXCCMState), +VMSTATE_END_OF_LIST () }, .post_load = imx_ccm_post_load, };
Signature · 1 line
1.9.1
PATCH 108/108 hw/arm/boot: Set PC correctly when loading AArch64 ELF files
In reply to Michael RothFrom: Peter Maydell <[email protected]>
The code in do_cpu_reset() correctly handled AArch64 CPUs when running Linux kernels, but was missing code in the branch of the if() that deals with loading ELF files. Correctly jump to the ELF entry point on reset rather than leaving the reset PC at zero.
--- hw/arm/boot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/boot.c +6 -2
@@ -417,8 +417,12 @@ static void do_cpu_reset(void *opaque)if (info) {if (!info->is_linux) {/* Jump to the entry point. */ - env->regs[15 ] = info->entry &0xfffffffe ; - env->thumb = info->entry &1 ; +if (env->aarch64) { + env->pc = info->entry; + }else { + env->regs[15 ] = info->entry &0xfffffffe ; + env->thumb = info->entry &1 ; + } }else {if (CPU (cpu) == first_cpu) {if (env->aarch64) {
Signature · 1 line
1.9.1
PATCH 99/108 Allow mismatched virtio config-len
In reply to Michael RothFrom: "Dr. David Alan Gilbert" <[email protected]>
Commit 'virtio: validate config_len on load' restricted config_len loaded from the wire to match the config_len that the device had.
Unfortunately, there are cases where this isn't true, the one we found it on was the wce addition in virtio-blk.
Allow mismatched config-lengths:
*) If the version on the wire is shorter then fine
*) If the version on the wire is longer, load what we have space
for and skip the rest.
(This is [email protected]'s rework of what I originally posted)
--- hw/virtio/virtio.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
hw/virtio/virtio.c +11 -5
@@ -926,12 +926,18 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)return -1 ; } config_len =qemu_get_be32 (f); -if (config_len != vdev->config_len) { -error_report ("Unexpected config length 0x%x. Expected 0x%zx" , - config_len, vdev->config_len); -return -1 ; + +/* +* There are cases where the incoming config can be bigger or smaller +* than what we have; so load what we have space for, and skip +* any excess that's in the stream. +*/ +qemu_get_buffer (f, vdev->config,MIN (config_len, vdev->config_len)); + +while (config_len > vdev->config_len) { +qemu_get_byte (f); + config_len--; } -qemu_get_buffer (f, vdev->config, vdev->config_len); num =qemu_get_be32 (f);
Signature · 1 line
1.9.1
PATCH 106/108 vmstate_xhci_event: fix unterminated field list
In reply to Michael RothFrom: Laszlo Ersek <[email protected]>
"vmstate_xhci_event" was introduced in commit 37352df3 ("xhci: add live migration support"), and first released in v1.6.0. The field list in this VMSD is not terminated with the VMSTATE_END_OF_LIST() macro.
During normal use (ie. migration), the issue is practically invisible, because the "vmstate_xhci_event" object (with the unterminated field list) is only ever referenced -- via "vmstate_xhci_intr" -- if xhci_er_full() returns true, for the "ev_buffer" test. Since that field_exists() check (apparently) almost always returns false, we almost never traverse "vmstate_xhci_event" during migration, which hides the bug.
However, Amit's vmstate checker forces recursion into this VMSD as well, and the lack of VMSTATE_END_OF_LIST() breaks the field list terminator check (field->name != NULL) in dump_vmstate_vmsd(). The result is undefined behavior, which in my case translates to infinite recursion (because the loop happens to overflow into "vmstate_xhci_intr", which then links back to "vmstate_xhci_event").
Add the missing terminator.
--- hw/usb/hcd-xhci.c | 1 + 1 file changed, 1 insertion(+)
hw/usb/hcd-xhci.c +1 -0
@@ -3703,6 +3703,7 @@ static const VMStateDescription vmstate_xhci_event = {VMSTATE_UINT32 (flags, XHCIEvent),VMSTATE_UINT8 (slotid, XHCIEvent),VMSTATE_UINT8 (epid, XHCIEvent), + VMSTATE_END_OF_LIST() } };
Signature · 1 line
1.9.1
Quoted 4 lines · Michael Roth
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
Quoted 9 lines
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
http://wiki.qemu.org/Planning/2.0
Please respond here or CC [email protected] on any patches you think should be included in the release.
Libvirt could support active commit against qemu 2.0.1 if you backport these patches:
Jeff Cody
7676e2c597 block: make 'top' argument to block-commit optional
Fam Zheng
9e48b02540 mirror: Go through ready -> complete process for 0 len image
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoting Eric Blake (2014-08-06 16:49:50)
Quoted 15 lines · Michael Roth
Quoted 4 lines
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
Quoted 9 lines
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
http://wiki.qemu.org/Planning/2.0
Please respond here or CC [email protected] on any patches you think should be included in the release.
Quoted 8 lines
Libvirt could support active commit against qemu 2.0.1 if you backport these patches:
Jeff Cody
7676e2c597block: make 'top' argument to block-commit optionalFam Zheng
9e48b02540mirror: Go through ready -> complete process for 0 len image
Actually ended up needing the following with a few fix-ups:
7676e2c->98103fa block: make 'top' argument to block-commit optional 8b9a30c->e5f0eb0 qemu-iotests: Test BLOCK_JOB_READY event for 0Kb image active commit 9e48b02->43ac708 mirror: Go through ready -> complete process for 0 len image dc71ce4->8e09e20 blockjob: Add block_job_yield()
373df5b->520b341 mirror: Fix resource leak when bdrv_getlength fails
I've gone ahead and pushed them, but please test as we generally don't do features (even backward-compatible ones) for stable, and this wasn't as trivial as I was hoping.
Quoted 4 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 18 lines · Michael Roth
Quoted 9 lines
Libvirt could support active commit against qemu 2.0.1 if you backport these patches:
Jeff Cody
7676e2c597block: make 'top' argument to block-commit optionalFam Zheng
9e48b02540mirror: Go through ready -> complete process for 0 len imageActually ended up needing the following with a few fix-ups:
7676e2c->98103fa block: make 'top' argument to block-commit optional 8b9a30c->e5f0eb0 qemu-iotests: Test
BLOCK_JOB_READYevent for 0Kb image active commit 9e48b02->43ac708 mirror: Go through ready -> complete process for 0 len image dc71ce4->8e09e20 blockjob: Addblock_job_yield()
373df5b->520b341 mirror: Fix resource leak whenbdrv_getlengthfails
Quoted 3 lines
I've gone ahead and pushed them, but please test as we generally don't do features (even backward-compatible ones) for stable, and this wasn't as trivial as I was hoping.
Yes, I'll test and report back. However, I don't think this is a feature addition, so much as a bug fix for an existing feature (all the hard work for active commit was already in 2.0, all that was missing was a way for libvirt to introspect that it existed, and some corner case bugs with 0-length images).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoting Eric Blake (2014-08-07 10:50:41)
Quoted 19 lines · Michael Roth
Quoted 18 lines
Quoted 9 lines
Libvirt could support active commit against qemu 2.0.1 if you backport these patches:
Jeff Cody
7676e2c597block: make 'top' argument to block-commit optionalFam Zheng
9e48b02540mirror: Go through ready -> complete process for 0 len imageActually ended up needing the following with a few fix-ups:
7676e2c->98103fa block: make 'top' argument to block-commit optional 8b9a30c->e5f0eb0 qemu-iotests: Test
BLOCK_JOB_READYevent for 0Kb image active commit 9e48b02->43ac708 mirror: Go through ready -> complete process for 0 len image dc71ce4->8e09e20 blockjob: Addblock_job_yield()
373df5b->520b341 mirror: Fix resource leak whenbdrv_getlengthfails
Quoted 5 lines
Quoted 3 lines
I've gone ahead and pushed them, but please test as we generally don't do features (even backward-compatible ones) for stable, and this wasn't as trivial as I was hoping.
Yes, I'll test and report back. However, I don't think this is a
Thanks!
Quoted 5 lines
Yes, I'll test and report back. However, I don't think this is a feature addition, so much as a bug fix for an existing feature (all the hard work for active commit was already in 2.0, all that was missing was a way for libvirt to introspect that it existed, and some corner case bugs with 0-length images).
Well, I think it would be hard to draw the line if you start getting into things like new command-line options and such, but the distinction does seem reasonable in this case.
Quoted 4 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 10 lines · Michael Roth
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
Quoted 9 lines
Please respond here or CC [email protected] on any patches you think should be included in the release.
Due to delays, this is the final planned release for the 2.0.0 series. We will return to the standard 2-release cycle for 2.1 (one midway during 2.2 development cycle, one immediately following 2.2 release)
Testing/feedback is greatly appreciated.
I tried to compile on Fedora 20, but had to backport this to get it to work:
Luiz Capitulinoa49db98d fpu: softfloat: drop INLINE macro
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 8 lines · Eric Blake
Quoted 6 lines · Michael Roth
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
Quoted 7 lines
Quoted 2 lines
Testing/feedback is greatly appreciated.
I tried to compile on Fedora 20, but had to backport this to get it to work:
Luiz Capitulino
a49db98dfpu: softfloat: drop INLINE macro
Oops, spoke too soon. I hit another build failure - anyone recognize this, or which commit to backport?
make[1]: *** No rule to make target /home/eblake/qemu/hw/i386/ssdt-mem.dsl', needed by hw/i386/ssdt-mem.hex'. Stop.
make: *** [subdir-x86_64-softmmu] Error 2
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 6 lines · Eric Blake
Quoted 5 lines
I tried to compile on Fedora 20, but had to backport this to get it to work:
Luiz Capitulino
a49db98dfpu: softfloat: drop INLINE macro
Quoted 7 lines
Oops, spoke too soon. I hit another build failure - anyone recognize this, or which commit to backport?
make[1]: *** No rule to make target
/home/eblake/qemu/hw/i386/ssdt-mem.dsl', needed byhw/i386/ssdt-mem.hex'. Stop.
make: *** [subdir-x86_64-softmmu] Error 2
Turns out to be caused by leftovers, from trying an incremental build in the same tree where I had 2.1 object files. Maybe the makefiles can be improved to deal gracefully with this case, but as a clean build didn't suffer from the problem, it's not a showstopper.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 4 lines · Eric Blake
Turns out to be caused by leftovers, from trying an incremental build in the same tree where I had 2.1 object files. Maybe the makefiles can be improved to deal gracefully with this case, but as a clean build didn't suffer from the problem, it's not a showstopper.
That kind of 'deal with changes across time' robustness is difficult, I think. At any rate we don't deal with it at all well in many different aspects of our build system. We don't even guarantee that a make clean/distclean will fix things...
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 4 lines · Eric Blake
Turns out to be caused by leftovers, from trying an incremental build in the same tree where I had 2.1 object files. Maybe the makefiles can be improved to deal gracefully with this case, but as a clean build didn't suffer from the problem, it's not a showstopper.
That kind of 'deal with changes across time' robustness is difficult, I think. At any rate we don't deal with it at all well in many different aspects of our build system. We don't even guarantee that a make clean/distclean will fix things...
Yeah, I just have to get into a better habit of rebuilding the world when switching across drastically different branches (or maintaining parallel build trees, or ...). I'm not asking for an instant solution, because I know firsthand how hard it can be :)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 10 lines · Michael Roth
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
Quoted 8 lines
Please respond here or CC [email protected] on any patches you think should be included in the release.
Due to delays, this is the final planned release for the 2.0.0 series. We will return to the standard 2-release cycle for 2.1 (one midway during 2.2 development cycle, one immediately following 2.2 release)
Testing/feedback is greatly appreciated.
Another useful one to avoid a segfault during drive-mirror (possibly more related patches, as I know Kevin did several qiov cleanups, but at least this one was easy for me to hit in testing):
Kevin Wolf5a0f6fd5 mirror: Fix qiov size for short requests
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 19 lines · Eric Blake
Quoted 18 lines · Michael Roth
Quoted 9 lines
Libvirt could support active commit against qemu 2.0.1 if you backport these patches:
Jeff Cody
7676e2c597block: make 'top' argument to block-commit optionalFam Zheng
9e48b02540mirror: Go through ready -> complete process for 0 len imageActually ended up needing the following with a few fix-ups:
7676e2c->98103fa block: make 'top' argument to block-commit optional 8b9a30c->e5f0eb0 qemu-iotests: Test
BLOCK_JOB_READYevent for 0Kb image active commit 9e48b02->43ac708 mirror: Go through ready -> complete process for 0 len image dc71ce4->8e09e20 blockjob: Addblock_job_yield()
373df5b->520b341 mirror: Fix resource leak whenbdrv_getlengthfails
Quoted 5 lines
Quoted 3 lines
I've gone ahead and pushed them, but please test as we generally don't do features (even backward-compatible ones) for stable, and this wasn't as trivial as I was hoping.
Yes, I'll test and report back.
Testing complete - without the patches (commit e0efb023 on your branch), libvirt 1.2.7 failed to run an active commit, even though I could run one by hand via QMP; with the patches (commit 98103fa7 on your branch) libvirt detected active commit and managed it just fine. I've replied separately with a couple more patches (one that I needed for getting a build made for running my tests, another for a coredump in drive-mirror that I triggered while setting up my active commit tests).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoting Eric Blake (2014-08-07 16:23:14)
Quoted 18 lines · Michael Roth
Quoted 17 lines
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
http://wiki.qemu.org/Planning/2.0
Please respond here or CC [email protected] on any patches you think should be included in the release.
Due to delays, this is the final planned release for the 2.0.0 series. We will return to the standard 2-release cycle for 2.1 (one midway during 2.2 development cycle, one immediately following 2.2 release)
Quoted 8 lines
Quoted 1 line
Testing/feedback is greatly appreciated.
Another useful one to avoid a segfault during drive-mirror (possibly more related patches, as I know Kevin did several qiov cleanups, but at least this one was easy for me to hit in testing):
Kevin Wolf
5a0f6fd5mirror: Fix qiov size for short requests
Pushed now. Preceded it with:
d0d83e8 qemu-iotests: Test 0-length image for mirror
to bring 041 iotests closer in sync and add coverage for previous patches.
Quoted 4 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 18 lines · Eric Blake
Quoted 17 lines · Michael Roth
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
http://wiki.qemu.org/Planning/2.0
Please respond here or CC [email protected] on any patches you think should be included in the release.
Due to delays, this is the final planned release for the 2.0.0 series. We will return to the standard 2-release cycle for 2.1 (one midway during 2.2 development cycle, one immediately following 2.2 release)
Quoted 8 lines
Quoted 2 lines
Testing/feedback is greatly appreciated.
I tried to compile on Fedora 20, but had to backport this to get it to work:
Luiz Capitulino
a49db98dfpu: softfloat: drop INLINE macro
ping
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoting Eric Blake (2014-08-15 13:43:21)
Quoted 22 lines · Eric Blake
Quoted 21 lines · Michael Roth
Quoted 19 lines
Hi everyone,
The following new patches are queued for QEMU stable v2.0.1:
https://github.com/mdroth/qemu/commits/stable-2.0-staging
The release is planned for 2014-08-15:
http://wiki.qemu.org/Planning/2.0
Please respond here or CC [email protected] on any patches you think should be included in the release.
Due to delays, this is the final planned release for the 2.0.0 series. We will return to the standard 2-release cycle for 2.1 (one midway during 2.2 development cycle, one immediately following 2.2 release)
Testing/feedback is greatly appreciated.
Quoted 7 lines
Quoted 5 lines
I tried to compile on Fedora 20, but had to backport this to get it to work:
Luiz Capitulino
a49db98dfpu: softfloat: drop INLINE macroping
Hmm, unfortunately I didn't see this until after 2.0.1 was tagged/pushed. My understanding however was that the build issues you were seeing were the result of a dirty build directory. Can you confirm whether or not the build issue is present in v2.0.1 (now tagged in origin)? If a build fix is still required I can push a minor v2.0.2 update monday and skip v2.0.1 for the announcement/tarball.
Quoted 4 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 6 lines · Michael Roth
Quoted 6 lines
Quoted 5 lines
I tried to compile on Fedora 20, but had to backport this to get it to work:
Luiz Capitulino
a49db98dfpu: softfloat: drop INLINE macro
Quoted 8 lines
Quoted 1 line
ping
Hmm, unfortunately I didn't see this until after 2.0.1 was tagged/pushed. My understanding however was that the build issues you were seeing were the result of a dirty build directory. Can you confirm whether or not the build issue is present in v2.0.1 (now tagged in origin)? If a build fix is still required I can push a minor v2.0.2 update monday and skip v2.0.1 for the announcement/tarball.
Using Fedora 20, I did a fresh clone to v2.0.1, followed by:
./configure --enable-kvm --enable-system --disable-user \
--target-list=x86_64-softmmu --enable-debug
and make failed:
In file included from /usr/include/spice-server/spice.h:25:0,
from /home/eblake/qemu-tmp/include/ui/qemu-spice.h:25,
from qemu-char.c:84:/usr/include/spice-1/spice/macros.h:105:0: error: "INLINE" redefined [-Werror]
#define INLINE inline
^
Bummer. It's unrelated to a dirty build directory. I don't know how many others will be impacted, to know if it warrants an immediate 2.0.2 (if it's just me hitting it, I don't mind calling 2.0.1 good; and distro packagers can do the trivial backport that I did).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 8 lines · Eric Blake
In file included from
/usr/include/spice-server/spice.h:25:0,from /home/eblake/qemu-tmp/include/ui/qemu-spice.h:25, from qemu-char.c:84:
/usr/include/spice-1/spice/macros.h:105:0: error: "INLINE" redefined [-Werror]
#define INLINE inline
^
Quoted 4 lines
Bummer. It's unrelated to a dirty build directory. I don't know how many others will be impacted, to know if it warrants an immediate 2.0.2 (if it's just me hitting it, I don't mind calling 2.0.1 good; and distro packagers can do the trivial backport that I did).
It'll hit anybody with that buggy version of spice installed; I think that's just Fedora 20 currently. You probably want commit 37f6be977a as well as a49db98d1f.
-- PMM