From nobody Tue Feb 10 05:44:58 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=163.com ARC-Seal: i=1; a=rsa-sha256; t=1621134476; cv=none; d=zohomail.com; s=zohoarc; b=KltauA3popm/FSu98NTm6DnM6JMXcTrwp/ekHc19nS6nDqFMI0J7MJjkibZn2gvK7C4PWRxUHgPFWNtwfRES5dxvBK/GVkkA71dWyEj7q5HxgHy4hBVs7Xh97faabm+hdQCKTq6ZDf7BFmOPSd7DHGLxpfRMPXumZJ00zqwrw34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621134476; 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=DcDXRblPPvnfD/xYLg4aHe8aReG2NSYKLxSU3hh7qxU=; b=NA0aIWg6EdFbhRhLf6cvohwHG+8qoKu5R+mpyp08GFkgNvbScuwhsE/HUOZgXruedR9fvUum0Ev3StC72Fcx6Q1J+Hfsgy9JHhkBCv/bg+IGqR/F7acgG/ryneSMA3OSO+1wtzbTYf0B9bDqjoLjWrBpuOojE0kHuHsvHX7hq+s= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621134476860883.4416829670722; Sat, 15 May 2021 20:07:56 -0700 (PDT) Received: from localhost ([::1]:35550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li78F-0000VW-Sl for importer@patchew.org; Sat, 15 May 2021 23:07:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74p-0000pR-Th for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 Received: from m12-13.163.com ([220.181.12.13]:52352) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74n-0002gO-Bn for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S12; Sun, 16 May 2021 11:04:16 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=DcDXR blPPvnfD/xYLg4aHe8aReG2NSYKLxSU3hh7qxU=; b=Y5Bgc8mH5zeTUX/Vx9YDV AZMXoLjBFtsWlEDlLjx1Yf9bIu2EURiBVX0qWqd/Ny41gBy0Wmnv4uhlfC/oOzUI h3bECCSy4qIaAtrkXdu6GvDcsZjEAuHmtEfWQEvrbgC5+2OB4ymabr3gYZYkIB4m /ZtfIek8cumCquCKAveJ5g= From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 8/8] vhost-user-gpu: abstract vg_cleanup_mapping_iov Date: Sat, 15 May 2021 20:04:03 -0700 Message-Id: <20210516030403.107723-9-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S12 X-Coremail-Antispam: 1Uf129KBjvJXoWxWrW7Gr4DJr47XFWUGw4UJwb_yoWrJFyUpF yxW3W2kF48Zr4fKa97Aw1UZFnav3WrZFWYkr1akan8ursIg3yqq3Z8u3Z8Kr15JFyktF47 tFn8Gw18GrWUAFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UD5rcUUUUU= X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiKRCUbVXl0i9ZPQAAsp 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=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, 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: Li Qiang , liq3ea@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @163.com) Content-Type: text/plain; charset="utf-8" Currently in vhost-user-gpu, we free resource directly in the cleanup case of resource. If we change the cleanup logic we need to change several places, also abstruct a 'vg_create_mapping_iov' can be symmetry with the 'vg_create_mapping_iov'. This is like what virtio-gpu does, no function changed. Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/vhost-user-gpu.c | 24 ++++++++++++++++++++---- contrib/vhost-user-gpu/virgl.c | 9 +++++---- contrib/vhost-user-gpu/vugpu.h | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index 770dfad529..6dc6a44f4e 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -49,6 +49,8 @@ static char *opt_render_node; static gboolean opt_virgl; =20 static void vg_handle_ctrl(VuDev *dev, int qidx); +static void vg_cleanup_mapping(VuGpu *g, + struct virtio_gpu_simple_resource *res); =20 static const char * vg_cmd_to_string(int cmd) @@ -400,7 +402,7 @@ vg_resource_destroy(VuGpu *g, } =20 vugbm_buffer_destroy(&res->buffer); - g_free(res->iov); + vg_cleanup_mapping(g, res); pixman_image_unref(res->image); QTAILQ_REMOVE(&g->reslist, res, next); g_free(res); @@ -504,6 +506,22 @@ vg_resource_attach_backing(VuGpu *g, res->iov_cnt =3D ab.nr_entries; } =20 +/* Though currently only free iov, maybe later will do more work. */ +void vg_cleanup_mapping_iov(VuGpu *g, + struct iovec *iov, uint32_t count) +{ + g_free(iov); +} + +static void +vg_cleanup_mapping(VuGpu *g, + struct virtio_gpu_simple_resource *res) +{ + vg_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + res->iov =3D NULL; + res->iov_cnt =3D 0; +} + static void vg_resource_detach_backing(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) @@ -522,9 +540,7 @@ vg_resource_detach_backing(VuGpu *g, return; } =20 - g_free(res->iov); - res->iov =3D NULL; - res->iov_cnt =3D 0; + vg_cleanup_mapping(g, res); } =20 static void diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 7172104b19..3e45e1bd33 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -116,8 +116,9 @@ virgl_cmd_resource_unref(VuGpu *g, virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); - g_free(res_iovs); - + if (res_iovs !=3D NULL && num_iovs !=3D 0) { + vg_cleanup_mapping_iov(g, res_iovs, num_iovs); + } virgl_renderer_resource_unref(unref.resource_id); } =20 @@ -294,7 +295,7 @@ virgl_resource_attach_backing(VuGpu *g, ret =3D virgl_renderer_resource_attach_iov(att_rb.resource_id, res_iovs, att_rb.nr_entries); if (ret !=3D 0) { - g_free(res_iovs); + vg_cleanup_mapping_iov(g, res_iovs, att_rb.nr_entries); } } =20 @@ -314,7 +315,7 @@ virgl_resource_detach_backing(VuGpu *g, if (res_iovs =3D=3D NULL || num_iovs =3D=3D 0) { return; } - g_free(res_iovs); + vg_cleanup_mapping_iov(g, res_iovs, num_iovs); } =20 static void diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h index 04d5615812..e2864bba68 100644 --- a/contrib/vhost-user-gpu/vugpu.h +++ b/contrib/vhost-user-gpu/vugpu.h @@ -169,7 +169,7 @@ int vg_create_mapping_iov(VuGpu *g, struct virtio_gpu_resource_attach_backing *a= b, struct virtio_gpu_ctrl_command *cmd, struct iovec **iov); - +void vg_cleanup_mapping_iov(VuGpu *g, struct iovec *iov, uint32_t count= ); void vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd= ); =20 void vg_wait_ok(VuGpu *g); --=20 2.25.1