From nobody Wed Dec 17 21:51:29 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602273330; cv=none; d=zohomail.com; s=zohoarc; b=dle5+bvu30OeSfAkX/higy7v/ufark5uA3RnkUd4oJCS/Plg2E4X3KRPGx9Axw1uxGCYYsak0YfBbyKhHYio4RMGIilzpX+jm1bPhgcxJVxp8TGsStRzIeLMWG9EQkRpyb2qeOzNKw1muF8Nazgdjed+mmdiOJt4xlRbubFVihg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602273330; h=Content-Type: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=X+QE+ha5fJzUlptXByqU2+dcTMFzxzMcUxOdUKkjuO4=; b=LNGI5E2J7hZ/ERh9C3M0Vqha42YCET7JmQHjJQcvSgdOEWQ4iau4UdFl2kFPZwk6wi2hya3tvP2Dt+RSXBZ9FxkmoQdmdBKzq0vgvoxpRF7vypp1vBnZourKEQ27bbgW+dZvraoxv2UCoQXwIJYrBNF2oQVn/tnnUKAAyIeDIdg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602273330087970.2005327920734; Fri, 9 Oct 2020 12:55:30 -0700 (PDT) Received: from localhost ([::1]:36970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQyUC-0005Ra-OG for importer@patchew.org; Fri, 09 Oct 2020 15:55:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQyCB-0001YG-0D for qemu-devel@nongnu.org; Fri, 09 Oct 2020 15:36:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQyC9-0002z7-7r for qemu-devel@nongnu.org; Fri, 09 Oct 2020 15:36:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-593-4pdCEfqqP0265IzBZLtS-g-1; Fri, 09 Oct 2020 15:36:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 455021DDE3; Fri, 9 Oct 2020 19:36:43 +0000 (UTC) Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 168135C1D7; Fri, 9 Oct 2020 19:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602272208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X+QE+ha5fJzUlptXByqU2+dcTMFzxzMcUxOdUKkjuO4=; b=PYe/cHA8AIOLs7nQ60MHkCtYDpX6l4SZLEx3e5y4Ndes2Uy8tBDOKDYkSgFiClbjYsrgRK v520Zr4U2JHYCZm660/vlIv7nqMZZ9tsfgsTOLZDO3GaLQQb7ZxGZNu5w8i4wbpSjmAj/L l4fkDT5HOttH2npqtG8uUjVgvea2Jls= X-MC-Unique: 4pdCEfqqP0265IzBZLtS-g-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 12/30] block/export: consolidate request structs into VuBlockReq Date: Fri, 9 Oct 2020 20:35:11 +0100 Message-Id: <20201009193529.322822-13-stefanha@redhat.com> In-Reply-To: <20201009193529.322822-1-stefanha@redhat.com> References: <20201009193529.322822-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Kevin Wolf , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Coiby Xu , Max Reitz , Stefan Hajnoczi , Cleber Rosa , Paolo Bonzini , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Only one struct is needed per request. Drop req_data and the separate VuBlockReq instance. Instead let vu_queue_pop() allocate everything at once. This fixes the req_data memory leak in vu_block_virtio_process_req(). Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-6-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 68 +++++++++------------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index fb7764a730..ef07a87eb1 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -25,7 +25,7 @@ struct virtio_blk_inhdr { }; =20 typedef struct VuBlockReq { - VuVirtqElement *elem; + VuVirtqElement elem; int64_t sector_num; size_t size; struct virtio_blk_inhdr *in; @@ -39,14 +39,10 @@ static void vu_block_req_complete(VuBlockReq *req) VuDev *vu_dev =3D &req->server->vu_dev; =20 /* IO size with 1 extra status byte */ - vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); + vu_queue_push(vu_dev, req->vq, &req->elem, req->size + 1); vu_queue_notify(vu_dev, req->vq); =20 - if (req->elem) { - free(req->elem); - } - - g_free(req); + free(req); } =20 static VuBlockDev *get_vu_block_device_by_server(VuServer *server) @@ -89,20 +85,12 @@ static void coroutine_fn vu_block_flush(VuBlockReq *req) blk_co_flush(backend); } =20 -struct req_data { - VuServer *server; - VuVirtq *vq; - VuVirtqElement *elem; -}; - static void coroutine_fn vu_block_virtio_process_req(void *opaque) { - struct req_data *data =3D opaque; - VuServer *server =3D data->server; - VuVirtq *vq =3D data->vq; - VuVirtqElement *elem =3D data->elem; + VuBlockReq *req =3D opaque; + VuServer *server =3D req->server; + VuVirtqElement *elem =3D &req->elem; uint32_t type; - VuBlockReq *req; =20 VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); BlockBackend *backend =3D vdev_blk->backend; @@ -111,18 +99,13 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) struct iovec *out_iov =3D elem->out_sg; unsigned in_num =3D elem->in_num; unsigned out_num =3D elem->out_num; + /* refer to hw/block/virtio_blk.c */ if (elem->out_num < 1 || elem->in_num < 1) { error_report("virtio-blk request missing headers"); - free(elem); - return; + goto err; } =20 - req =3D g_new0(VuBlockReq, 1); - req->server =3D server; - req->vq =3D vq; - req->elem =3D elem; - if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, sizeof(req->out)) !=3D sizeof(req->out))) { error_report("virtio-blk request outhdr too short"); @@ -202,36 +185,27 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) =20 err: free(elem); - g_free(req); - return; } =20 static void vu_block_process_vq(VuDev *vu_dev, int idx) { - VuServer *server; - VuVirtq *vq; - struct req_data *req_data; + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + VuVirtq *vq =3D vu_get_queue(vu_dev, idx); =20 - server =3D container_of(vu_dev, VuServer, vu_dev); - assert(server); - - vq =3D vu_get_queue(vu_dev, idx); - assert(vq); - VuVirtqElement *elem; while (1) { - elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + - sizeof(VuBlockReq)); - if (elem) { - req_data =3D g_new0(struct req_data, 1); - req_data->server =3D server; - req_data->vq =3D vq; - req_data->elem =3D elem; - Coroutine *co =3D qemu_coroutine_create(vu_block_virtio_proces= s_req, - req_data); - aio_co_enter(server->ioc->ctx, co); - } else { + VuBlockReq *req; + + req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); + if (!req) { break; } + + req->server =3D server; + req->vq =3D vq; + + Coroutine *co =3D + qemu_coroutine_create(vu_block_virtio_process_req, req); + qemu_coroutine_enter(co); } } =20 --=20 2.26.2