From nobody Mon May 5 19:03:18 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=1603366417; cv=none; d=zohomail.com; s=zohoarc; b=bmF66pi9M9OQk7CLVnjNj/d9nw6qFX9u1ff2SnOl0aQGc6O4LNVrBw24s/Vlg9V9cbbvt63Zs7CCHxqy6lNtCIp/Eh/mPiG93wwr8/M69ULlNXE4owIPyQWRG1XrbHpEAvVOdtVa0pPH3A9VsQg8rC1IUbrfU0p3FQVgUXjHikU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366417; 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=pDPK/gDxvSqd+AKC4ACRi9LgzC2OcfLuz1FIto+Zozc=; b=AMi5h4aNI8DsCJv4WV1YHAgu9ksaC05ihCIkFhn4f4sE4/rVTVv+OBDiRb1GV/pKniffnDPqzFrVBSf5rApR5KaPBqP8MwAv6t7P45KzQIPfqvJdljNrXNNaJpY7NSmj92SBA0yubf7oCKEFXbJ4a5S4plJjv259GnajwRd46m8= 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=<stefanha@redhat.com> (p=none dis=none) header.from=<stefanha@redhat.com> Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16033664171601005.0419677812997; Thu, 22 Oct 2020 04:33:37 -0700 (PDT) Received: from localhost ([::1]:36814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>) id 1kVYqd-0002GW-Us for importer@patchew.org; Thu, 22 Oct 2020 07:33:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <stefanha@redhat.com>) id 1kVYly-00059Y-P8 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46141) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from <stefanha@redhat.com>) id 1kVYlx-00055V-1D for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:46 -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-475-TXtnzSfIMNul0suezRU_iw-1; Thu, 22 Oct 2020 07:28:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7F2E835B76; Thu, 22 Oct 2020 11:28:38 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88A6C19C78; Thu, 22 Oct 2020 11:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366124; 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=pDPK/gDxvSqd+AKC4ACRi9LgzC2OcfLuz1FIto+Zozc=; b=HBJuS+/yTFELrIETBgvJuvOHKER7usZfj3q4O85Qk+7sX8pErsvzlsD+AB7BvdzHZV9OnC wEQj3ZxrPtBH/siGaC2y4rQBcl0PPlKyG0xtU1h2o9u8v0DbgYxTXpbyHApQaLU16ostm3 tvC1IZ8g0e6yfxqIHpjDO9P3ph/+T4w= X-MC-Unique: TXtnzSfIMNul0suezRU_iw-1 From: Stefan Hajnoczi <stefanha@redhat.com> To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org> Subject: [PULL v2 11/28] block/export: consolidate request structs into VuBlockReq Date: Thu, 22 Oct 2020 12:27:09 +0100 Message-Id: <20201022112726.736757-12-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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/22 00:54:46 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: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, qemu-block@nongnu.org, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Coiby Xu <Coiby.Xu@gmail.com>, Markus Armbruster <armbru@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Max Reitz <mreitz@redhat.com> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org> 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 <stefanha@redhat.com> Message-id: 20200924151549.913737-6-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> --- 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 2ba1613cc9..d227b468d8 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