From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631617688107.20521283657433; Mon, 27 Mar 2017 09:20:17 -0700 (PDT) Received: from localhost ([::1]:47950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXNQ-0001Bp-2r for importer@patchew.org; Mon, 27 Mar 2017 12:20:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJf-0006jS-9O for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJb-0000kW-Bg for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15889) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJb-0000jG-5G for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:19 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A2AE88E60; Mon, 27 Mar 2017 16:16:18 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8q009176; Mon, 27 Mar 2017 12:16:17 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3A2AE88E60 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3A2AE88E60 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:07 +0200 Message-Id: <20170327161615.19637-2-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Mar 2017 16:16:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/9] clear pending status before calling memory commit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Xu, Anthony" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Xu, Anthony" clear pending status before calling memory commit. Otherwise when memory_region_finalize is called, memory_region_transaction_depth is 0 and memory_region_update_pending is true. That's wrong. Signed-off -by: Anthony Xu Message-Id: <4712D8F4B26E034E80552F30A67BE0B1A2E3D5@ORSMSX112.amr.corp.inte= l.com> Signed-off-by: Paolo Bonzini --- memory.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/memory.c b/memory.c index 64b0a60..4c95aaf 100644 --- a/memory.c +++ b/memory.c @@ -906,12 +906,6 @@ void memory_region_transaction_begin(void) ++memory_region_transaction_depth; } =20 -static void memory_region_clear_pending(void) -{ - memory_region_update_pending =3D false; - ioeventfd_update_pending =3D false; -} - void memory_region_transaction_commit(void) { AddressSpace *as; @@ -927,14 +921,14 @@ void memory_region_transaction_commit(void) QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { address_space_update_topology(as); } - + memory_region_update_pending =3D false; MEMORY_LISTENER_CALL_GLOBAL(commit, Forward); } else if (ioeventfd_update_pending) { QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { address_space_update_ioeventfds(as); } + ioeventfd_update_pending =3D false; } - memory_region_clear_pending(); } } =20 --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149063148852660.165298072164774; Mon, 27 Mar 2017 09:18:08 -0700 (PDT) Received: from localhost ([::1]:47943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXLK-0007sT-Kv for importer@patchew.org; Mon, 27 Mar 2017 12:18:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJf-0006jT-9i for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJc-0000mH-HD for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJc-0000l4-Bj for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CB998123D for ; Mon, 27 Mar 2017 16:16:19 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8r009176; Mon, 27 Mar 2017 12:16:18 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6CB998123D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6CB998123D From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:08 +0200 Message-Id: <20170327161615.19637-3-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Mar 2017 16:16:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/9] virtio-scsi: Make virtio_scsi_acquire/release public X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng They will be used in virtio-scsi-dataplane.c as well, so move them to header. Signed-off-by: Fam Zheng Message-Id: <20170317061447.16243-2-famz@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/virtio-scsi.c | 14 -------------- include/hw/virtio/virtio-scsi.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 1dbc4bc..e7466d3 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -422,20 +422,6 @@ static void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s,= VirtIOSCSIReq *req) } } =20 -static inline void virtio_scsi_acquire(VirtIOSCSI *s) -{ - if (s->ctx) { - aio_context_acquire(s->ctx); - } -} - -static inline void virtio_scsi_release(VirtIOSCSI *s) -{ - if (s->ctx) { - aio_context_release(s->ctx); - } -} - bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq) { VirtIOSCSIReq *req; diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index f536f77..8ae0aca 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -121,6 +121,20 @@ typedef struct VirtIOSCSIReq { } req; } VirtIOSCSIReq; =20 +static inline void virtio_scsi_acquire(VirtIOSCSI *s) +{ + if (s->ctx) { + aio_context_acquire(s->ctx); + } +} + +static inline void virtio_scsi_release(VirtIOSCSI *s) +{ + if (s->ctx) { + aio_context_release(s->ctx); + } +} + void virtio_scsi_common_realize(DeviceState *dev, Error **errp, VirtIOHandleOutput ctrl, VirtIOHandleOutpu= t evt, VirtIOHandleOutput cmd); --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631488552362.86634495948203; Mon, 27 Mar 2017 09:18:08 -0700 (PDT) Received: from localhost ([::1]:47942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXLL-0007s3-34 for importer@patchew.org; Mon, 27 Mar 2017 12:18:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJf-0006jU-Dc for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJd-0000oO-Rl for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJd-0000mv-IS for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:21 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CC8D804F4 for ; Mon, 27 Mar 2017 16:16:20 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8s009176; Mon, 27 Mar 2017 12:16:19 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9CC8D804F4 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9CC8D804F4 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:09 +0200 Message-Id: <20170327161615.19637-4-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Mar 2017 16:16:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/9] virtio-scsi: Fix acquire/release in dataplane handlers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng After the AioContext lock push down, there is a race between virtio_scsi_dataplane_start and those "assert(s->ctx && s->dataplane_started)", because the latter doesn't isn't wrapped in aio_context_acquire. Reproducer is simply booting a Fedora guest with an empty virtio-scsi-dataplane controller: qemu-system-x86_64 \ -drive if=3Dnone,id=3Droot,format=3Draw,file=3DFedora-Cloud-Base-25-1= .3.x86_64.raw \ -device virtio-scsi \ -device scsi-disk,drive=3Droot,bootindex=3D1 \ -object iothread,id=3Dio \ -device virtio-scsi-pci,iothread=3Dio \ -net user,hostfwd=3Dtcp::10022-:22 -net nic,model=3Dvirtio -m 2048 \ --enable-kvm Fix this by moving acquire/release pairs from virtio_scsi_handle_*_vq to their callers - and wrap the broken assertions in. Signed-off-by: Fam Zheng Message-Id: <20170317061447.16243-3-famz@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/virtio-scsi-dataplane.c | 20 ++++++++++++++++---- hw/scsi/virtio-scsi.c | 27 ++++++++++++++------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 74c95e0..944ea4e 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -52,28 +52,40 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error *= *errp) static bool virtio_scsi_data_plane_handle_cmd(VirtIODevice *vdev, VirtQueue *vq) { - VirtIOSCSI *s =3D (VirtIOSCSI *)vdev; + bool progress; + VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 + virtio_scsi_acquire(s); assert(s->ctx && s->dataplane_started); - return virtio_scsi_handle_cmd_vq(s, vq); + progress =3D virtio_scsi_handle_cmd_vq(s, vq); + virtio_scsi_release(s); + return progress; } =20 static bool virtio_scsi_data_plane_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { + bool progress; VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 + virtio_scsi_acquire(s); assert(s->ctx && s->dataplane_started); - return virtio_scsi_handle_ctrl_vq(s, vq); + progress =3D virtio_scsi_handle_ctrl_vq(s, vq); + virtio_scsi_release(s); + return progress; } =20 static bool virtio_scsi_data_plane_handle_event(VirtIODevice *vdev, VirtQueue *vq) { + bool progress; VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); =20 + virtio_scsi_acquire(s); assert(s->ctx && s->dataplane_started); - return virtio_scsi_handle_event_vq(s, vq); + progress =3D virtio_scsi_handle_event_vq(s, vq); + virtio_scsi_release(s); + return progress; } =20 static int virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, int n, diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index e7466d3..bd62d08 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -427,12 +427,10 @@ bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQu= eue *vq) VirtIOSCSIReq *req; bool progress =3D false; =20 - virtio_scsi_acquire(s); while ((req =3D virtio_scsi_pop_req(s, vq))) { progress =3D true; virtio_scsi_handle_ctrl_req(s, req); } - virtio_scsi_release(s); return progress; } =20 @@ -446,7 +444,9 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev,= VirtQueue *vq) return; } } + virtio_scsi_acquire(s); virtio_scsi_handle_ctrl_vq(s, vq); + virtio_scsi_release(s); } =20 static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req) @@ -590,7 +590,6 @@ bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue= *vq) =20 QTAILQ_HEAD(, VirtIOSCSIReq) reqs =3D QTAILQ_HEAD_INITIALIZER(reqs); =20 - virtio_scsi_acquire(s); do { virtio_queue_set_notification(vq, 0); =20 @@ -618,7 +617,6 @@ bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue= *vq) QTAILQ_FOREACH_SAFE(req, &reqs, next, next) { virtio_scsi_handle_cmd_req_submit(s, req); } - virtio_scsi_release(s); return progress; } =20 @@ -633,7 +631,9 @@ static void virtio_scsi_handle_cmd(VirtIODevice *vdev, = VirtQueue *vq) return; } } + virtio_scsi_acquire(s); virtio_scsi_handle_cmd_vq(s, vq); + virtio_scsi_release(s); } =20 static void virtio_scsi_get_config(VirtIODevice *vdev, @@ -709,12 +709,10 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice= *dev, return; } =20 - virtio_scsi_acquire(s); - req =3D virtio_scsi_pop_req(s, vs->event_vq); if (!req) { s->events_dropped =3D true; - goto out; + return; } =20 if (s->events_dropped) { @@ -724,7 +722,7 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *= dev, =20 if (virtio_scsi_parse_req(req, 0, sizeof(VirtIOSCSIEvent))) { virtio_scsi_bad_req(req); - goto out; + return; } =20 evt =3D &req->resp.event; @@ -744,19 +742,14 @@ void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice= *dev, evt->lun[3] =3D dev->lun & 0xFF; } virtio_scsi_complete_req(req); -out: - virtio_scsi_release(s); } =20 bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq) { - virtio_scsi_acquire(s); if (s->events_dropped) { virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); - virtio_scsi_release(s); return true; } - virtio_scsi_release(s); return false; } =20 @@ -770,7 +763,9 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev= , VirtQueue *vq) return; } } + virtio_scsi_acquire(s); virtio_scsi_handle_event_vq(s, vq); + virtio_scsi_release(s); } =20 static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense se= nse) @@ -780,8 +775,10 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevic= e *dev, SCSISense sense) =20 if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_CHANGE) && dev->type !=3D TYPE_ROM) { + virtio_scsi_acquire(s); virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE, sense.asc | (sense.ascq << 8)); + virtio_scsi_release(s); } } =20 @@ -803,9 +800,11 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplu= g_dev, DeviceState *dev, } =20 if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { + virtio_scsi_acquire(s); virtio_scsi_push_event(s, sd, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_RESCAN); + virtio_scsi_release(s); } } =20 @@ -817,9 +816,11 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotp= lug_dev, DeviceState *dev, SCSIDevice *sd =3D SCSI_DEVICE(dev); =20 if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { + virtio_scsi_acquire(s); virtio_scsi_push_event(s, sd, VIRTIO_SCSI_T_TRANSPORT_RESET, VIRTIO_SCSI_EVT_RESET_REMOVED); + virtio_scsi_release(s); } =20 qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631618880106.40490610098402; Mon, 27 Mar 2017 09:20:18 -0700 (PDT) Received: from localhost ([::1]:47951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXNR-0001Co-Lx for importer@patchew.org; Mon, 27 Mar 2017 12:20:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJg-0006jV-7u for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJf-0000qA-1Q for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJe-0000os-Rn for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:22 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5DC480F98; Mon, 27 Mar 2017 16:16:21 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8t009176; Mon, 27 Mar 2017 12:16:20 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E5DC480F98 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E5DC480F98 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:10 +0200 Message-Id: <20170327161615.19637-5-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Mar 2017 16:16:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/9] tcg/i386: Check the size of instruction being translated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Pranith Kumar Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pranith Kumar This fixes the bug: 'user-to-root privesc inside VM via bad translation caching' reported by Jann Horn here: https://bugs.chromium.org/p/project-zero/issues/detail?id=3D1122 Reviewed-by: Richard Henderson CC: Peter Maydell CC: Paolo Bonzini Reported-by: Jann Horn Signed-off-by: Pranith Kumar Message-Id: <20170323175851.14342-1-bobby.prani@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/translate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/translate.c b/target/i386/translate.c index 72c1b03..1d1372f 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -4418,6 +4418,13 @@ static target_ulong disas_insn(CPUX86State *env, Dis= asContext *s, s->vex_l =3D 0; s->vex_v =3D 0; next_byte: + /* x86 has an upper limit of 15 bytes for an instruction. Since we + * do not want to decode and generate IR for an illegal + * instruction, the following check limits the instruction size to + * 25 bytes: 14 prefix + 1 opc + 6 (modrm+sib+ofs) + 4 imm */ + if (s->pc - pc_start > 14) { + goto illegal_op; + } b =3D cpu_ldub_code(env, s->pc); s->pc++; /* Collect prefixes. */ --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631494890271.0009404038735; Mon, 27 Mar 2017 09:18:14 -0700 (PDT) Received: from localhost ([::1]:47944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXLR-0007yA-Lh for importer@patchew.org; Mon, 27 Mar 2017 12:18:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJh-0006jt-Jr for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJg-0000sL-6Y for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49598) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJf-0000qw-WE for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:24 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 239A0C60ED; Mon, 27 Mar 2017 16:16:23 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8u009176; Mon, 27 Mar 2017 12:16:22 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 239A0C60ED Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 239A0C60ED From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:11 +0200 Message-Id: <20170327161615.19637-6-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 27 Mar 2017 16:16:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/9] mem-prealloc: fix sysconf(_SC_NPROCESSORS_ONLN) failure case. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jitendra Kolhe Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jitendra Kolhe This was spotted by Coverity, in case where sysconf(_SC_NPROCESSORS_ONLN) fails and returns -1. This results in memset_num_threads getting set to -1. Which we then pass to g_new0(). The patch replaces MAX_MEM_PREALLOC_THREAD_COUNT macro with a function call get_memset_num_threads() to handle sysconf() failure gracefully. In case sysconf() fails, we fall back to single threaded. (Spotted by Coverity, CID 1372465.) Signed-off-by: Jitendra Kolhe Message-Id: <1490079006-32495-1-git-send-email-jitendra.kolhe@hpe.com> Signed-off-by: Paolo Bonzini --- util/oslib-posix.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 3fe6089..4d9189e 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -55,7 +55,7 @@ #include "qemu/error-report.h" #endif =20 -#define MAX_MEM_PREALLOC_THREAD_COUNT (MIN(sysconf(_SC_NPROCESSORS_ONLN), = 16)) +#define MAX_MEM_PREALLOC_THREAD_COUNT 16 =20 struct MemsetThread { char *addr; @@ -381,6 +381,18 @@ static void *do_touch_pages(void *arg) return NULL; } =20 +static inline int get_memset_num_threads(int smp_cpus) +{ + long host_procs =3D sysconf(_SC_NPROCESSORS_ONLN); + int ret =3D 1; + + if (host_procs > 0) { + ret =3D MIN(MIN(host_procs, MAX_MEM_PREALLOC_THREAD_COUNT), smp_cp= us); + } + /* In case sysconf() fails, we fall back to single threaded */ + return ret; +} + static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages, int smp_cpus) { @@ -389,7 +401,7 @@ static bool touch_all_pages(char *area, size_t hpagesiz= e, size_t numpages, int i =3D 0; =20 memset_thread_failed =3D false; - memset_num_threads =3D MIN(smp_cpus, MAX_MEM_PREALLOC_THREAD_COUNT); + memset_num_threads =3D get_memset_num_threads(smp_cpus); memset_thread =3D g_new0(MemsetThread, memset_num_threads); numpages_per_thread =3D (numpages / memset_num_threads); size_per_thread =3D (hpagesize * numpages_per_thread); --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631868807150.78132230542406; Mon, 27 Mar 2017 09:24:28 -0700 (PDT) Received: from localhost ([::1]:47971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXR8-0004Mw-Aa for importer@patchew.org; Mon, 27 Mar 2017 12:24:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJj-0006lU-3V for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJh-0000uj-LT for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4311) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJh-0000tO-CC for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:25 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F98280511; Mon, 27 Mar 2017 16:16:24 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8v009176; Mon, 27 Mar 2017 12:16:23 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6F98280511 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6F98280511 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:12 +0200 Message-Id: <20170327161615.19637-7-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 27 Mar 2017 16:16:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/9] win32: replace custom mutex and condition variable with native primitives X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrey Shedel , Andrew Baumann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Andrey Shedel The multithreaded TCG implementation exposed deadlocks in the win32 condition variables: as implemented, qemu_cond_broadcast waited on receivers, whereas the pthreads API it was intended to emulate does not. This was causing a deadlock because broadcast was called while holding the IO lock, as well as all possible waiters blocked on the same lock. This patch replaces all the custom synchronisation code for mutexes and condition variables with native Windows primitives (SRWlocks and condition variables) with the same semantics as their POSIX equivalents. To enable that, it requires a Windows Vista or newer host OS. Signed-off-by: Andrey Shedel [AB: edited commit message] Signed-off-by: Andrew Baumann Message-Id: <20170324220141.10104-1-Andrew.Baumann@microsoft.com> Signed-off-by: Paolo Bonzini --- include/qemu/thread-win32.h | 7 +-- util/qemu-thread-win32.c | 136 +++++-----------------------------------= ---- 2 files changed, 17 insertions(+), 126 deletions(-) diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h index 5fb6541..4c4a261 100644 --- a/include/qemu/thread-win32.h +++ b/include/qemu/thread-win32.h @@ -4,8 +4,7 @@ #include =20 struct QemuMutex { - CRITICAL_SECTION lock; - LONG owner; + SRWLOCK lock; }; =20 typedef struct QemuRecMutex QemuRecMutex; @@ -19,9 +18,7 @@ int qemu_rec_mutex_trylock(QemuRecMutex *mutex); void qemu_rec_mutex_unlock(QemuRecMutex *mutex); =20 struct QemuCond { - LONG waiters, target; - HANDLE sema; - HANDLE continue_event; + CONDITION_VARIABLE var; }; =20 struct QemuSemaphore { diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 29c3e4d..59befd5 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -10,6 +10,11 @@ * See the COPYING file in the top-level directory. * */ + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#endif + #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/thread.h" @@ -39,44 +44,30 @@ static void error_exit(int err, const char *msg) =20 void qemu_mutex_init(QemuMutex *mutex) { - mutex->owner =3D 0; - InitializeCriticalSection(&mutex->lock); + InitializeSRWLock(&mutex->lock); } =20 void qemu_mutex_destroy(QemuMutex *mutex) { - assert(mutex->owner =3D=3D 0); - DeleteCriticalSection(&mutex->lock); + InitializeSRWLock(&mutex->lock); } =20 void qemu_mutex_lock(QemuMutex *mutex) { - EnterCriticalSection(&mutex->lock); - - /* Win32 CRITICAL_SECTIONs are recursive. Assert that we're not - * using them as such. - */ - assert(mutex->owner =3D=3D 0); - mutex->owner =3D GetCurrentThreadId(); + AcquireSRWLockExclusive(&mutex->lock); } =20 int qemu_mutex_trylock(QemuMutex *mutex) { int owned; =20 - owned =3D TryEnterCriticalSection(&mutex->lock); - if (owned) { - assert(mutex->owner =3D=3D 0); - mutex->owner =3D GetCurrentThreadId(); - } + owned =3D TryAcquireSRWLockExclusive(&mutex->lock); return !owned; } =20 void qemu_mutex_unlock(QemuMutex *mutex) { - assert(mutex->owner =3D=3D GetCurrentThreadId()); - mutex->owner =3D 0; - LeaveCriticalSection(&mutex->lock); + ReleaseSRWLockExclusive(&mutex->lock); } =20 void qemu_rec_mutex_init(QemuRecMutex *mutex) @@ -107,124 +98,27 @@ void qemu_rec_mutex_unlock(QemuRecMutex *mutex) void qemu_cond_init(QemuCond *cond) { memset(cond, 0, sizeof(*cond)); - - cond->sema =3D CreateSemaphore(NULL, 0, LONG_MAX, NULL); - if (!cond->sema) { - error_exit(GetLastError(), __func__); - } - cond->continue_event =3D CreateEvent(NULL, /* security */ - FALSE, /* auto-reset */ - FALSE, /* not signaled */ - NULL); /* name */ - if (!cond->continue_event) { - error_exit(GetLastError(), __func__); - } + InitializeConditionVariable(&cond->var); } =20 void qemu_cond_destroy(QemuCond *cond) { - BOOL result; - result =3D CloseHandle(cond->continue_event); - if (!result) { - error_exit(GetLastError(), __func__); - } - cond->continue_event =3D 0; - result =3D CloseHandle(cond->sema); - if (!result) { - error_exit(GetLastError(), __func__); - } - cond->sema =3D 0; + InitializeConditionVariable(&cond->var); } =20 void qemu_cond_signal(QemuCond *cond) { - DWORD result; - - /* - * Signal only when there are waiters. cond->waiters is - * incremented by pthread_cond_wait under the external lock, - * so we are safe about that. - */ - if (cond->waiters =3D=3D 0) { - return; - } - - /* - * Waiting threads decrement it outside the external lock, but - * only if another thread is executing pthread_cond_broadcast and - * has the mutex. So, it also cannot be decremented concurrently - * with this particular access. - */ - cond->target =3D cond->waiters - 1; - result =3D SignalObjectAndWait(cond->sema, cond->continue_event, - INFINITE, FALSE); - if (result =3D=3D WAIT_ABANDONED || result =3D=3D WAIT_FAILED) { - error_exit(GetLastError(), __func__); - } + WakeConditionVariable(&cond->var); } =20 void qemu_cond_broadcast(QemuCond *cond) { - BOOLEAN result; - /* - * As in pthread_cond_signal, access to cond->waiters and - * cond->target is locked via the external mutex. - */ - if (cond->waiters =3D=3D 0) { - return; - } - - cond->target =3D 0; - result =3D ReleaseSemaphore(cond->sema, cond->waiters, NULL); - if (!result) { - error_exit(GetLastError(), __func__); - } - - /* - * At this point all waiters continue. Each one takes its - * slice of the semaphore. Now it's our turn to wait: Since - * the external mutex is held, no thread can leave cond_wait, - * yet. For this reason, we can be sure that no thread gets - * a chance to eat *more* than one slice. OTOH, it means - * that the last waiter must send us a wake-up. - */ - WaitForSingleObject(cond->continue_event, INFINITE); + WakeAllConditionVariable(&cond->var); } =20 void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) { - /* - * This access is protected under the mutex. - */ - cond->waiters++; - - /* - * Unlock external mutex and wait for signal. - * NOTE: we've held mutex locked long enough to increment - * waiters count above, so there's no problem with - * leaving mutex unlocked before we wait on semaphore. - */ - qemu_mutex_unlock(mutex); - WaitForSingleObject(cond->sema, INFINITE); - - /* Now waiters must rendez-vous with the signaling thread and - * let it continue. For cond_broadcast this has heavy contention - * and triggers thundering herd. So goes life. - * - * Decrease waiters count. The mutex is not taken, so we have - * to do this atomically. - * - * All waiters contend for the mutex at the end of this function - * until the signaling thread relinquishes it. To ensure - * each waiter consumes exactly one slice of the semaphore, - * the signaling thread stops until it is told by the last - * waiter that it can go on. - */ - if (InterlockedDecrement(&cond->waiters) =3D=3D cond->target) { - SetEvent(cond->continue_event); - } - - qemu_mutex_lock(mutex); + SleepConditionVariableSRW(&cond->var, &mutex->lock, INFINITE, 0); } =20 void qemu_sem_init(QemuSemaphore *sem, int init) --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631499625415.190582389224; Mon, 27 Mar 2017 09:18:19 -0700 (PDT) Received: from localhost ([::1]:47945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXLW-00083V-Ce for importer@patchew.org; Mon, 27 Mar 2017 12:18:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJj-0006lv-M4 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJi-0000we-NI for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35868) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJi-0000vI-Hs for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:26 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4F3461B8F for ; Mon, 27 Mar 2017 16:16:25 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8w009176; Mon, 27 Mar 2017 12:16:24 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A4F3461B8F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A4F3461B8F From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:13 +0200 Message-Id: <20170327161615.19637-8-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 27 Mar 2017 16:16:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 7/9] nbd: drop unused NBDClientSession.is_unix field X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-Id: <20170327123223.1199-1-stefanha@redhat.com> Signed-off-by: Paolo Bonzini --- block/nbd-client.h | 2 -- block/nbd.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index 8cdfc92..891ba44 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -30,8 +30,6 @@ typedef struct NBDClientSession { =20 Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; NBDReply reply; - - bool is_unix; } NBDClientSession; =20 NBDClientSession *nbd_get_client_session(BlockDriverState *bs); diff --git a/block/nbd.c b/block/nbd.c index f478f80..1b832c2 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -285,8 +285,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict= *options, Error **errp) goto done; } =20 - s->client.is_unix =3D saddr->type =3D=3D SOCKET_ADDRESS_KIND_UNIX; - done: QDECREF(addr); qobject_decref(crumpled_addr); --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490631733678553.1367961821228; Mon, 27 Mar 2017 09:22:13 -0700 (PDT) Received: from localhost ([::1]:47962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXPI-0002mN-HR for importer@patchew.org; Mon, 27 Mar 2017 12:22:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJl-0006nW-Di for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJk-0000yr-43 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35918) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJj-0000xY-RY for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:28 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF1C0636FE; Mon, 27 Mar 2017 16:16:26 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF8x009176; Mon, 27 Mar 2017 12:16:25 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DF1C0636FE Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DF1C0636FE From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:14 +0200 Message-Id: <20170327161615.19637-9-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 27 Mar 2017 16:16:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 8/9] Revert "apic: save apic_delivered flag" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pavel Dovgalyuk Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This reverts commit 07bfa354772f2de67008dc66c201b627acff0106. The global variable is only read as part of a apic_reset_irq_delivered(); qemu_irq_raise(s->irq); if (!apic_get_irq_delivered()) { sequence, so the value never matters at migration time. Reported-by: Dr. David Alan Gilbert Cc: Pavel Dovgalyuk Signed-off-by: Paolo Bonzini --- hw/intc/apic_common.c | 33 --------------------------------- include/hw/i386/apic_internal.h | 2 -- 2 files changed, 35 deletions(-) diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 7a6e771..c3829e3 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -387,25 +387,6 @@ static bool apic_common_sipi_needed(void *opaque) return s->wait_for_sipi !=3D 0; } =20 -static bool apic_irq_delivered_needed(void *opaque) -{ - APICCommonState *s =3D APIC_COMMON(opaque); - return s->cpu =3D=3D X86_CPU(first_cpu) && apic_irq_delivered !=3D 0; -} - -static void apic_irq_delivered_pre_save(void *opaque) -{ - APICCommonState *s =3D APIC_COMMON(opaque); - s->apic_irq_delivered =3D apic_irq_delivered; -} - -static int apic_irq_delivered_post_load(void *opaque, int version_id) -{ - APICCommonState *s =3D APIC_COMMON(opaque); - apic_irq_delivered =3D s->apic_irq_delivered; - return 0; -} - static const VMStateDescription vmstate_apic_common_sipi =3D { .name =3D "apic_sipi", .version_id =3D 1, @@ -418,19 +399,6 @@ static const VMStateDescription vmstate_apic_common_si= pi =3D { } }; =20 -static const VMStateDescription vmstate_apic_irq_delivered =3D { - .name =3D "apic_irq_delivered", - .version_id =3D 1, - .minimum_version_id =3D 1, - .needed =3D apic_irq_delivered_needed, - .pre_save =3D apic_irq_delivered_pre_save, - .post_load =3D apic_irq_delivered_post_load, - .fields =3D (VMStateField[]) { - VMSTATE_INT32(apic_irq_delivered, APICCommonState), - VMSTATE_END_OF_LIST() - } -}; - static const VMStateDescription vmstate_apic_common =3D { .name =3D "apic", .version_id =3D 3, @@ -465,7 +433,6 @@ static const VMStateDescription vmstate_apic_common =3D= { }, .subsections =3D (const VMStateDescription*[]) { &vmstate_apic_common_sipi, - &vmstate_apic_irq_delivered, NULL } }; diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_interna= l.h index 20ad28c..1209eb4 100644 --- a/include/hw/i386/apic_internal.h +++ b/include/hw/i386/apic_internal.h @@ -189,8 +189,6 @@ struct APICCommonState { DeviceState *vapic; hwaddr vapic_paddr; /* note: persistence via kvmvapic */ bool legacy_instance_id; - - int apic_irq_delivered; /* for saving static variable */ }; =20 typedef struct VAPICState { --=20 2.9.3 From nobody Thu May 2 22:27:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149063162302141.98203482296958; Mon, 27 Mar 2017 09:20:23 -0700 (PDT) Received: from localhost ([::1]:47956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXNV-0001HO-Tc for importer@patchew.org; Mon, 27 Mar 2017 12:20:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csXJq-0006sG-2W for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csXJl-00010i-5w for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1csXJl-0000zW-0C for qemu-devel@nongnu.org; Mon, 27 Mar 2017 12:16:29 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F526C054C58 for ; Mon, 27 Mar 2017 16:16:28 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-208.ams2.redhat.com [10.36.117.208]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2RGGF90009176; Mon, 27 Mar 2017 12:16:27 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1F526C054C58 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1F526C054C58 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:16:15 +0200 Message-Id: <20170327161615.19637-10-pbonzini@redhat.com> In-Reply-To: <20170327161615.19637-1-pbonzini@redhat.com> References: <20170327161615.19637-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 27 Mar 2017 16:16:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 9/9] scsi-generic: Fill in opt_xfer_len in INQUIRY reply if it is zero X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng When opt_xfer_len is zero, Linux ignores max_xfer_len erroneously. While that obviously should be fixed, we do older guests a favor to always filling in a value. Signed-off-by: Fam Zheng Message-Id: <20170327142625.1249-1-famz@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-generic.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 2933119..a55ff87 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -237,9 +237,8 @@ static void scsi_read_complete(void * opaque, int ret) assert(max_transfer); stl_be_p(&r->buf[8], max_transfer); /* Also take care of the opt xfer len. */ - if (ldl_be_p(&r->buf[12]) > max_transfer) { - stl_be_p(&r->buf[12], max_transfer); - } + stl_be_p(&r->buf[12], + MIN_NON_ZERO(max_transfer, ldl_be_p(&r->buf[12]))); } scsi_req_data(&r->req, len); scsi_req_unref(&r->req); --=20 2.9.3