Misc patches for 2017-05-19
The following changes since commit 56821559f0ba682fe6b367815572e6f974d329ab:
Merge remote-tracking branch 'dgilbert/tags/pull-hmp-20170517' into staging (2017-05-18 13:36:15 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 7860f87b6523324bd35ee5e25f698bf0d779e767:
sockets: improve error reporting if UNIX socket path is too long (2017-05-26 13:22:52 +0200)
----------------------------------------------------------------
* virtio-scsi use-after-free fix (Fam)
* vhost-user-scsi support (Felipe)
* SMM fixes and improvements for TCG (myself, Mihail)
* irqchip and AddressSpaceDispatch cleanups and fixes (Peter)
* Coverity fix (Stefano)
* NBD cleanups (Vladimir)
* RTC accuracy improvements and code cleanups (Guangrong+Yunfang)
* socket error reporting improvement (Daniel)
----------------------------------------------------------------
v2->v3: replaced one NBD patch, added the last two
Daniel P. Berrange (1):
sockets: improve error reporting if UNIX socket path is too long
Fam Zheng (1):
virtio-scsi: Unset hotplug handler when unrealize
Felipe Franciosi (2):
vhost-user-scsi: Introduce vhost-user-scsi host device
vhost-user-scsi: Introduce a vhost-user-scsi sample application
Mihail Abakumov (1):
i386: fix read/write cr with icount option
Paolo Bonzini (2):
target/i386: enable A20 automatically in system management mode target/i386: use multiple CPU AddressSpaces
Peter Xu (4):
kvm: irqchip: trace changes on msi add/remove
msix: trace control bit write op
kvm: irqchip: skip update msi when disabled
exec: simplify phys_page_find() params
Stefano Stabellini (1):
Check the return value of fcntl in qemu_set_cloexec
Tai Yunfang (1):
mc146818rtc: precisely count the clock for periodic timer
Vladimir Sementsov-Ogievskiy (5):
nbd: strict nbd_wr_syncv
nbd: read_sync and friends: return 0 on success
nbd: add errp parameter to nbd_wr_syncv()
nbd: add errp to read_sync, write_sync and drop_sync nbd/client.c: use errp instead of LOG
Xiao Guangrong (4):
mc146818rtc: update periodic timer only if it is needed
mc146818rtc: ensure LOST_TICK_POLICY_SLEW is only enabled on TARGET_I386
mc146818rtc: drop unnecessary '#ifdef TARGET_I386'
mc146818rtc: embrace all x86 specific code
.gitignore | 1 + Makefile | 3 + Makefile.objs | 4 + block/nbd-client.c | 11 +- contrib/libvhost-user/libvhost-user.h | 11 +- contrib/vhost-user-scsi/Makefile.objs | 1 + contrib/vhost-user-scsi/vhost-user-scsi.c | 886 ++++++++++++++++++++++++++++++ default-configs/pci.mak | 1 + default-configs/s390x-softmmu.mak | 1 + exec.c | 13 +- hw/pci/msix.c | 11 +- hw/pci/trace-events | 3 + hw/scsi/Makefile.objs | 1 + hw/scsi/vhost-user-scsi.c | 211 +++++++ hw/scsi/virtio-scsi.c | 3 + hw/timer/mc146818rtc.c | 206 ++++--- hw/virtio/virtio-pci.c | 54 ++ hw/virtio/virtio-pci.h | 11 + include/block/nbd.h | 8 +- include/hw/virtio/vhost-user-scsi.h | 35 ++ include/hw/virtio/virtio-scsi.h | 2 + kvm-all.c | 4 +- nbd/client.c | 125 ++--- nbd/common.c | 23 +- nbd/nbd-internal.h | 40 +- nbd/server.c | 92 ++-- qemu-nbd.c | 3 +- target/i386/arch_memory_mapping.c | 18 +- target/i386/cpu.c | 15 +- target/i386/cpu.h | 20 +- target/i386/helper.c | 96 ++-- target/i386/kvm.c | 12 +- target/i386/machine.c | 4 - target/i386/smm_helper.c | 18 - target/i386/translate.c | 12 + tests/qemu-iotests/083.out | 2 + trace-events | 3 +- util/oslib-posix.c | 4 +- util/qemu-sockets.c | 68 ++- 39 files changed, 1703 insertions(+), 333 deletions(-) create mode 100644 contrib/vhost-user-scsi/Makefile.objs create mode 100644 contrib/vhost-user-scsi/vhost-user-scsi.c create mode 100644 hw/scsi/vhost-user-scsi.c create mode 100644 include/hw/virtio/vhost-user-scsi.h
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 14/22] nbd/client.c: use errp instead of LOG
From: Vladimir Sementsov-Ogievskiy <[email protected]>
Move to modern errp scheme from just LOGging errors.
Message-Id: <[email protected]>
--- block/nbd-client.c | 7 ++++++- include/block/nbd.h | 5 +++-- nbd/client.c | 30 +++++++++++++++++------------- qemu-nbd.c | 3 ++- tests/qemu-iotests/083.out | 2 ++ 5 files changed, 30 insertions(+), 17 deletions(-)
block/nbd-client.c +6 -1
@@ -28,6 +28,7 @@*/ #include "qemu/osdep.h" +#include "qapi/error.h" #include "nbd-client.h" #define HANDLE_TO_INDEX (bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs))
@@ -70,10 +71,14 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)NBDClientSession *s = opaque;uint64_t i;int ret; +Error *local_err =NULL ;for (;;) {assert (s->reply.handle ==0 ); - ret =nbd_receive_reply (s->ioc, &s->reply); + ret =nbd_receive_reply (s->ioc, &s->reply, &local_err); +if (ret <0 ) { +error_report_err (local_err); + }if (ret <=0 ) {break ; }
include/block/nbd.h +3 -2
@@ -133,9 +133,10 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *flags, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, off_t *size, Error **errp); -int nbd_init (int fd,QIOChannelSocket *sioc,uint16_t flags,off_t size); +int nbd_init (int fd,QIOChannelSocket *sioc,uint16_t flags,off_t size, +Error **errp);ssize_t nbd_send_request (QIOChannel *ioc,NBDRequest *request); -ssize_t nbd_receive_reply (QIOChannel *ioc,NBDReply *reply); +ssize_t nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp);int nbd_client (int fd);int nbd_disconnect (int fd);
nbd/client.c +17 -13
@@ -627,11 +627,13 @@ fail: }#ifdef __linux__ -int nbd_init (int fd,QIOChannelSocket *sioc,uint16_t flags,off_t size) +int nbd_init (int fd,QIOChannelSocket *sioc,uint16_t flags,off_t size, +Error **errp) {unsigned long sectors = size /BDRV_SECTOR_SIZE ;if (size /BDRV_SECTOR_SIZE != sectors) { -LOG ("Export size %lld too large for 32-bit kernel" , (long long ) size); +error_setg (errp,"Export size %lld too large for 32-bit kernel" , + (long long ) size);return -E2BIG ; }
@@ -639,7 +641,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)if (ioctl (fd,NBD_SET_SOCK , (unsigned long ) sioc->fd) <0 ) {int serrno = errno; -LOG ("Failed to set NBD socket" ); +error_setg (errp,"Failed to set NBD socket" );return -serrno; }
@@ -647,7 +649,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)if (ioctl (fd,NBD_SET_BLKSIZE , (unsigned long )BDRV_SECTOR_SIZE ) <0 ) {int serrno = errno; -LOG ("Failed setting NBD block size" ); +error_setg (errp,"Failed setting NBD block size" );return -serrno; }
@@ -659,7 +661,7 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)if (ioctl (fd,NBD_SET_SIZE_BLOCKS , sectors) <0 ) {int serrno = errno; -LOG ("Failed setting size (in blocks)" ); +error_setg (errp,"Failed setting size (in blocks)" );return -serrno; }
@@ -670,12 +672,12 @@ int nbd_init(int fd, QIOChannelSocket *sioc, uint16_t flags, off_t size)if (ioctl (fd,BLKROSET , (unsigned long ) &read_only) <0 ) {int serrno = errno; -LOG ("Failed setting read-only attribute" ); +error_setg (errp,"Failed setting read-only attribute" );return -serrno; } }else {int serrno = errno; -LOG ("Failed setting flags" ); +error_setg (errp,"Failed setting flags" );return -serrno; } }
@@ -723,8 +725,10 @@ int nbd_disconnect(int fd) }#else -int nbd_init (int fd,QIOChannelSocket *ioc,uint16_t flags,off_t size) +int nbd_init (int fd,QIOChannelSocket *ioc,uint16_t flags,off_t size, +Error **errp) { +error_setg (errp,"nbd_init is only supported on Linux" );return -ENOTSUP ; }
@@ -758,19 +762,19 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request)return write_sync (ioc, buf,sizeof (buf),NULL ); } -ssize_t nbd_receive_reply (QIOChannel *ioc,NBDReply *reply) +ssize_t nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp) {uint8_t buf[NBD_REPLY_SIZE ];uint32_t magic;ssize_t ret; - ret =read_sync_eof (ioc, buf,sizeof (buf),NULL ); + ret =read_sync_eof (ioc, buf,sizeof (buf), errp);if (ret <=0 ) {return ret; }if (ret !=sizeof (buf)) { -LOG ("read failed" ); +error_setg (errp,"read failed" );return -EINVAL ; }
@@ -788,7 +792,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply)if (reply->error ==ESHUTDOWN ) {/* This works even on mingw which lacks a native ESHUTDOWN */ -LOG ("server shutting down" ); +error_setg (errp,"server shutting down" );return -EINVAL ; } TRACE("Got reply: { magic = 0x%" PRIx32 ", .error = % " PRId32
@@ -796,7 +800,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply) magic, reply->error, reply->handle);if (magic !=NBD_REPLY_MAGIC ) { -LOG ("invalid magic (got 0x%" PRIx32")" , magic); +error_setg (errp,"invalid magic (got 0x%" PRIx32")" , magic);return -EINVAL ; }return sizeof (buf);
qemu-nbd.c +2 -1
@@ -288,8 +288,9 @@ static void *nbd_client_thread(void *arg) goto out_socket; } - ret =nbd_init (fd, sioc, nbdflags, size); + ret =nbd_init (fd, sioc, nbdflags, size, &local_error);if (ret <0 ) { +error_report_err (local_error); goto out_fd; }
tests/qemu-iotests/083.out +2 -0
@@ -69,10 +69,12 @@ read failed: Input/output error === Check disconnect 4 reply === +read failed read failed: Input/output error === Check disconnect 8 reply === +read failed read failed: Input/output error === Check disconnect before data ===
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 21/22] i386: fix read/write cr with icount option
In reply to Paolo BonziniFrom: Mihail Abakumov <[email protected]>
Running Windows with icount causes a crash in instruction of write cr. This patch fixes it.
Reading and writing cr cause an icount read because there are called cpu_get_apic_tpr and cpu_set_apic_tpr functions. So, there is need gen_io_start()/gen_io_end() calls.
Message-Id: <[email protected]>
--- target/i386/translate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target/i386/translate.c +12 -0
@@ -7914,14 +7914,26 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,gen_update_cc_op (s);gen_jmp_im (pc_start - s->cs_base);if (b &2 ) { +if (s->tb->cflags &CF_USE_ICOUNT ) { +gen_io_start (); + }gen_op_mov_v_reg (ot, cpu_T0, rm);gen_helper_write_crN (cpu_env,tcg_const_i32 (reg), cpu_T0); +if (s->tb->cflags &CF_USE_ICOUNT ) { +gen_io_end (); + }gen_jmp_im (s->pc - s->cs_base);gen_eob (s); }else { +if (s->tb->cflags &CF_USE_ICOUNT ) { +gen_io_start (); + }gen_helper_read_crN (cpu_T0, cpu_env,tcg_const_i32 (reg));gen_op_mov_reg_v (ot, rm, cpu_T0); +if (s->tb->cflags &CF_USE_ICOUNT ) { +gen_io_end (); + } }break ;default :
Signature · 1 line
2.13.0
[Qemu-devel] [PULL 22/22] sockets: improve error reporting if UNIX socket path is too long
In reply to Paolo BonziniFrom: "Daniel P. Berrange" <[email protected]>
The 'struct sockaddr_un' only allows 108 bytes for the socket path.
If the user supplies a path, QEMU uses snprintf() to silently truncate it when too long. This is undesirable because the user will then be unable to connect to the path they asked for.
If the user doesn't supply a path, QEMU builds one based on TMPDIR, but if that leads to an overlong path, it mistakenly uses error_setg_errno() with a stale errno value, because snprintf() does not set errno on truncation.
In solving this the code needed some refactoring to ensure we don't pass 'un.sun_path' directly to any APIs which expect NUL-terminated strings, because the path is not required to be terminated.
Message-Id: <[email protected]>
--- util/qemu-sockets.c | 68 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 22 deletions(-)
util/qemu-sockets.c +46 -22
@@ -845,6 +845,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, {struct sockaddr_un un;int sock, fd; +char *pathbuf =NULL ; +const char *path; sock =qemu_socket (PF_UNIX ,SOCK_STREAM ,0 );if (sock <0 ) {
@@ -852,20 +854,22 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,return -1 ; } -memset (&un,0 ,sizeof (un)); - un.sun_family =AF_UNIX ; -if (saddr->path &&strlen (saddr->path)) { -snprintf (un.sun_path,sizeof (un.sun_path),"%s" , saddr->path); +if (saddr->path && saddr->path[0 ]) { + path = saddr->path; }else {const char *tmpdir =getenv ("TMPDIR" ); tmpdir = tmpdir ? tmpdir :"/tmp" ; -if (snprintf (un.sun_path,sizeof (un.sun_path),"%s/qemu-socket-XXXXXX" , - tmpdir) >=sizeof (un.sun_path)) { -error_setg_errno (errp, errno, -"TMPDIR environment variable (%s) too large" , tmpdir); - goto err; - } + path = pathbuf =g_strdup_printf ("%s/qemu-socket-XXXXXX" , tmpdir); + } +if (strlen (path) >sizeof (un.sun_path)) { +error_setg (errp,"UNIX socket path '%s' is too long" , path); +error_append_hint (errp,"Path must be less than %zu bytes\n" , +sizeof (un.sun_path)); + goto err; + } + +if (pathbuf !=NULL ) {/* * This dummy fd usage silences the mktemp() unsecure warning. * Using mkstemp() doesn't make things more secure here
@@ -873,24 +877,25 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,* to unlink first and thus re-open the race window. The * worst case possible is bind() failing, i.e. a DoS attack. */ - fd =mkstemp (un.sun_path); + fd =mkstemp (pathbuf);if (fd <0 ) {error_setg_errno (errp, errno, -"Failed to make a temporary socket name in %s" , tmpdir); +"Failed to make a temporary socket %s" , pathbuf); goto err; }close (fd); -if (update_addr) { -g_free (saddr->path); - saddr->path =g_strdup (un.sun_path); - } } -if (unlink (un.sun_path) <0 && errno !=ENOENT ) { +if (unlink (path) <0 && errno !=ENOENT ) {error_setg_errno (errp, errno, -"Failed to unlink socket %s" , un.sun_path); +"Failed to unlink socket %s" , path); goto err; } + +memset (&un,0 ,sizeof (un)); + un.sun_family =AF_UNIX ; +strncpy (un.sun_path, path,sizeof (un.sun_path)); +if (bind (sock, (struct sockaddr *) &un,sizeof (un)) <0 ) {error_setg_errno (errp, errno,"Failed to bind socket to %s" , un.sun_path); goto err;
@@ -900,9 +905,16 @@ static int unix_listen_saddr(UnixSocketAddress *saddr, goto err; } +if (update_addr && pathbuf) { +g_free (saddr->path); + saddr->path = pathbuf; + }else { +g_free (pathbuf); + }return sock; err: +g_free (pathbuf);closesocket (sock);return -1 ; }
@@ -932,9 +944,16 @@ static int unix_connect_saddr(UnixSocketAddress *saddr,qemu_set_nonblock (sock); } +if (strlen (saddr->path) >sizeof (un.sun_path)) { +error_setg (errp,"UNIX socket path '%s' is too long" , saddr->path); +error_append_hint (errp,"Path must be less than %zu bytes\n" , +sizeof (un.sun_path)); + goto err; + } +memset (&un,0 ,sizeof (un)); un.sun_family =AF_UNIX ; -snprintf (un.sun_path,sizeof (un.sun_path),"%s" , saddr->path); +strncpy (un.sun_path, saddr->path,sizeof (un.sun_path));/* connect to peer */ do {
@@ -956,13 +975,18 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, }if (rc <0 ) { -error_setg_errno (errp, -rc,"Failed to connect socket" ); -close (sock); - sock =-1 ; +error_setg_errno (errp, -rc,"Failed to connect socket %s" , + saddr->path); + goto err; }g_free (connect_state);return sock; + + err: +close (sock); +g_free (connect_state); +return -1 ; }#else
Signature · 1 line
2.13.0
Stefan Hajnoczi
AppliedQuoted 104 lines · Paolo Bonzini
The following changes since commit
56821559f0ba682fe6b367815572e6f974d329ab:Merge remote-tracking branch 'dgilbert/tags/pull-hmp-20170517' into staging (2017-05-18 13:36:15 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.gittags/for-upstreamfor you to fetch changes up to
7860f87b6523324bd35ee5e25f698bf0d779e767:sockets: improve error reporting if UNIX socket path is too long (2017-05-26 13:22:52 +0200)
----------------------------------------------------------------
* virtio-scsi use-after-free fix (Fam)
* vhost-user-scsi support (Felipe)
* SMM fixes and improvements for TCG (myself, Mihail)
* irqchip and AddressSpaceDispatch cleanups and fixes (Peter)
* Coverity fix (Stefano)
* NBD cleanups (Vladimir)
* RTC accuracy improvements and code cleanups (Guangrong+Yunfang)
* socket error reporting improvement (Daniel)----------------------------------------------------------------
v2->v3: replaced one NBD patch, added the last twoDaniel P. Berrange (1):
sockets: improve error reporting if UNIX socket path is too longFam Zheng (1):
virtio-scsi: Unset hotplug handler when unrealizeFelipe Franciosi (2):
vhost-user-scsi: Introduce vhost-user-scsi host device
vhost-user-scsi: Introduce a vhost-user-scsi sample applicationMihail Abakumov (1):
i386: fix read/write cr with icount optionPaolo Bonzini (2):
target/i386: enable A20 automatically in system management mode target/i386: use multiple CPU AddressSpacesPeter Xu (4):
kvm: irqchip: trace changes on msi add/remove
msix: trace control bit write op
kvm: irqchip: skip update msi when disabled
exec: simplifyphys_page_find()paramsStefano Stabellini (1):
Check the return value of fcntl inqemu_set_cloexecTai Yunfang (1):
mc146818rtc: precisely count the clock for periodic timerVladimir Sementsov-Ogievskiy (5):
nbd: strictnbd_wr_syncv
nbd:read_syncand friends: return 0 on success
nbd: add errp parameter tonbd_wr_syncv()
nbd: add errp toread_sync,write_syncanddrop_syncnbd/client.c: use errp instead of LOGXiao Guangrong (4):
mc146818rtc: update periodic timer only if it is needed
mc146818rtc: ensureLOST_TICK_POLICY_SLEWis only enabled onTARGET_I386
mc146818rtc: drop unnecessary '#ifdefTARGET_I386'
mc146818rtc: embrace all x86 specific code.gitignore | 1 + Makefile | 3 + Makefile.objs | 4 + block/nbd-client.c | 11 +- contrib/libvhost-user/libvhost-user.h | 11 +- contrib/vhost-user-scsi/Makefile.objs | 1 + contrib/vhost-user-scsi/vhost-user-scsi.c | 886 ++++++++++++++++++++++++++++++ default-configs/pci.mak | 1 + default-configs/s390x-softmmu.mak | 1 + exec.c | 13 +- hw/pci/msix.c | 11 +- hw/pci/trace-events | 3 + hw/scsi/Makefile.objs | 1 + hw/scsi/vhost-user-scsi.c | 211 +++++++ hw/scsi/virtio-scsi.c | 3 + hw/timer/mc146818rtc.c | 206 ++++--- hw/virtio/virtio-pci.c | 54 ++ hw/virtio/virtio-pci.h | 11 + include/block/nbd.h | 8 +- include/hw/virtio/vhost-user-scsi.h | 35 ++ include/hw/virtio/virtio-scsi.h | 2 + kvm-all.c | 4 +- nbd/client.c | 125 ++--- nbd/common.c | 23 +- nbd/nbd-internal.h | 40 +- nbd/server.c | 92 ++-- qemu-nbd.c | 3 +- target/i386/arch_memory_mapping.c | 18 +- target/i386/cpu.c | 15 +- target/i386/cpu.h | 20 +- target/i386/helper.c | 96 ++-- target/i386/kvm.c | 12 +- target/i386/machine.c | 4 - target/i386/smm_helper.c | 18 - target/i386/translate.c | 12 + tests/qemu-iotests/083.out | 2 +
Quoted 12 lines
trace-events | 3 +- util/oslib-posix.c | 4 +- util/qemu-sockets.c | 68 ++- 39 files changed, 1703 insertions(+), 333 deletions(-) create mode 100644 contrib/vhost-user-scsi/Makefile.objs create mode 100644 contrib/vhost-user-scsi/vhost-user-scsi.c create mode 100644 hw/scsi/vhost-user-scsi.c create mode 100644 include/hw/virtio/vhost-user-scsi.hSignature · 1 line
2.13.0
Thanks, applied to my staging tree:
https://github.com/stefanha/qemu/commits/staging
Stefan