From nobody Wed Apr 16 15:07: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=1603467615; cv=none; d=zohomail.com; s=zohoarc; b=El1I5pB4u+KeGmcHoysu3T4Ajb+O38V7g6lET5ARMk8sigkYj7i5K0MW8kh5ucygLV1NE/372I5oT5s1/5Lky9EY+8rlIrvvMWl0nXGk/UnoEEX088ZVG2Ik2WL17o8oSHQnXacc/9J2BMb2ovFZIRAaofqhDCMCLKOctXPtES8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603467615; 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=kSXikipCerV45qVf7y16tpcnVnZygr22HGQsRzYtgrQmGdU8VPH2NIYrunV5OLmiUK+ZHKoLEAJQDR939xU22GGJaAKufRw+fHw/P65DNUCbUT4YR3acMpiud4BzAmQbhDjWLGnRPjLPyzWf+4lVcmau3MGA307uq8anHt/koOo= 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 1603467615863963.3715921085845; Fri, 23 Oct 2020 08:40:15 -0700 (PDT) Received: from localhost ([::1]:50566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVzAs-0003Zt-N0 for importer@patchew.org; Fri, 23 Oct 2020 11:40:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVyuE-0005dJ-24 for qemu-devel@nongnu.org; Fri, 23 Oct 2020 11:23:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVyuA-0000iF-77 for qemu-devel@nongnu.org; Fri, 23 Oct 2020 11:23:01 -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-289-hJcku50NNx2H_0rWjYxABA-1; Fri, 23 Oct 2020 11:22:54 -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 57AE11006CAF; Fri, 23 Oct 2020 15:22:52 +0000 (UTC) Received: from localhost (ovpn-114-178.ams2.redhat.com [10.36.114.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id A743E5C1CF; Fri, 23 Oct 2020 15:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603466576; 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=ZayOn/kJ8KVJKl0ALMeiSlUN2Fb1j8FcHudK9srqgj1Nkq6OI3I7QoWPFg1IsK/3SpSIjB MANRM4oyy1uXzLjRz6+dtVtQkReGDBwcaLnhw6zI6ZUxoE9iVLy2OGz///pfY+sCWgXc4i mF8iA0YnzzEmAArQWvTRUl51n4USOfw= X-MC-Unique: hJcku50NNx2H_0rWjYxABA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v3 11/28] block/export: consolidate request structs into VuBlockReq Date: Fri, 23 Oct 2020 16:21:30 +0100 Message-Id: <20201023152147.1016281-12-stefanha@redhat.com> In-Reply-To: <20201023152147.1016281-1-stefanha@redhat.com> References: <20201023152147.1016281-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/23 01:44:00 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=ham 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: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz 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 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