From nobody Mon Feb 9 11:32:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654790247; cv=none; d=zohomail.com; s=zohoarc; b=jGXvHPmnkR429tvS8j2HwhNHocYI8LpzPWkeEAKW0u1h8+uXF4AkAzqYGLGoV20DE+WLAFZfu4PJ2pbSn06G1Fkk1fjFVPf019BxLXI07c5LDY9zFj1hMw+EHpsSIhvHctat/bWCiVBewIhU94ckeoIQ7j2X2Us64PcCUMdDJEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654790247; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gBYz+24fQRhzaFS9ZOhkXmN+1cmAhTazfgjITWX5BNA=; b=WmQmqzzJ4yG44I6rPf6eznPWaOCq36TgtThe31iPg/GTw14pQTUoXrVmHdDgVJ8Y3+Kui8GsFvuPh01tA1qmNbp20aSoFaCBFFDX3ZuAREipwvSSS/duGFgfGCyxyeYAP9H52nLVoIntlvg4zQsNPEn4uyRf5/xcJ21up8q79ZQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1654790247957734.2269825894904; Thu, 9 Jun 2022 08:57:27 -0700 (PDT) Received: from localhost ([::1]:37552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzKXE-0007ym-OH for importer@patchew.org; Thu, 09 Jun 2022 11:57:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzJI2-0002Jn-H6 for qemu-devel@nongnu.org; Thu, 09 Jun 2022 10:37:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42276) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzJHz-00070h-LY for qemu-devel@nongnu.org; Thu, 09 Jun 2022 10:37:37 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649-9s_JSOATPAq7rQddTttQ1w-1; Thu, 09 Jun 2022 10:37:34 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A65D238005C9; Thu, 9 Jun 2022 14:37:33 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66A3D492C3B; Thu, 9 Jun 2022 14:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654785455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gBYz+24fQRhzaFS9ZOhkXmN+1cmAhTazfgjITWX5BNA=; b=evryU3WKPTTvtV7seF6fvjScEbiWwRSa9boqjQm/a7eLY/c/DW3jZu6Hs/V2nXvRSnRrra fDEknw8wFYeSKSlZEgsz+pFZeFgDGRKWhQyocLn/aGyRKbFXOABnt7wfKUtpnqa2VKEjVU oJGFOsZ+nv1Ky5aBCVmod/lkOHiMrB4= X-MC-Unique: 9s_JSOATPAq7rQddTttQ1w-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , "Michael S. Tsirkin" , Paolo Bonzini , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH 5/8] virtio-blk: mark GLOBAL_STATE_CODE functions Date: Thu, 9 Jun 2022 10:37:24 -0400 Message-Id: <20220609143727.1151816-6-eesposit@redhat.com> In-Reply-To: <20220609143727.1151816-1-eesposit@redhat.com> References: <20220609143727.1151816-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654790249043100001 Content-Type: text/plain; charset="utf-8" Just as done in the block API, mark functions in virtio-blk that are always called in the main loop with BQL held. We know such functions are GS because they all are callbacks from virtio.c API that has already classified them as GS. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- hw/block/dataplane/virtio-blk.c | 4 ++++ hw/block/virtio-blk.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 03e10a36a4..bda6b3e8de 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -89,6 +89,8 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, Vir= tIOBlkConf *conf, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); =20 + GLOBAL_STATE_CODE(); + *dataplane =3D NULL; =20 if (conf->iothread) { @@ -140,6 +142,8 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane= *s) { VirtIOBlock *vblk; =20 + GLOBAL_STATE_CODE(); + if (!s) { return; } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 4e6421c35e..2eb0408f92 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -51,6 +51,8 @@ static const VirtIOFeature feature_sizes[] =3D { =20 static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_featu= res) { + GLOBAL_STATE_CODE(); + s->config_size =3D MAX(VIRTIO_BLK_CFG_SIZE, virtio_feature_get_config_size(feature_sizes, host_features)); =20 @@ -865,6 +867,10 @@ void virtio_blk_restart_bh(void *opaque) virtio_blk_process_queued_requests(s, true); } =20 +/* + * Only called when VM is started or stopped in cpus.c. + * No iothread runs in parallel + */ static void virtio_blk_dma_restart_cb(void *opaque, bool running, RunState state) { @@ -872,6 +878,8 @@ static void virtio_blk_dma_restart_cb(void *opaque, boo= l running, BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(s))); VirtioBusState *bus =3D VIRTIO_BUS(qbus); =20 + GLOBAL_STATE_CODE(); + if (!running) { return; } @@ -894,8 +902,14 @@ static void virtio_blk_reset(VirtIODevice *vdev) AioContext *ctx; VirtIOBlockReq *req; =20 + GLOBAL_STATE_CODE(); + ctx =3D blk_get_aio_context(s->blk); aio_context_acquire(ctx); + /* + * This drain together with ->stop_ioeventfd() in virtio_pci_reset() + * stops all Iothreads. + */ blk_drain(s->blk); =20 /* We drop queued requests after blk_drain() because blk_drain() itsel= f can @@ -1064,11 +1078,17 @@ static void virtio_blk_set_status(VirtIODevice *vde= v, uint8_t status) } } =20 +/* + * VM is stopped while doing migration, so iothread has + * no requests to process. + */ static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f) { VirtIOBlock *s =3D VIRTIO_BLK(vdev); VirtIOBlockReq *req =3D s->rq; =20 + GLOBAL_STATE_CODE(); + while (req) { qemu_put_sbyte(f, 1); =20 @@ -1082,11 +1102,17 @@ static void virtio_blk_save_device(VirtIODevice *vd= ev, QEMUFile *f) qemu_put_sbyte(f, 0); } =20 +/* + * VM is stopped while doing migration, so iothread has + * no requests to process. + */ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f, int version_id) { VirtIOBlock *s =3D VIRTIO_BLK(vdev); =20 + GLOBAL_STATE_CODE(); + while (qemu_get_sbyte(f)) { unsigned nvqs =3D s->conf.num_queues; unsigned vq_idx =3D 0; @@ -1135,6 +1161,7 @@ static const BlockDevOps virtio_block_ops =3D { .resize_cb =3D virtio_blk_resize, }; =20 +/* Iothread is not yet created */ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -1143,6 +1170,8 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) Error *err =3D NULL; unsigned i; =20 + GLOBAL_STATE_CODE(); + if (!conf->conf.blk) { error_setg(errp, "drive property not set"); return; --=20 2.31.1