From nobody Tue Nov 26 18:34:58 2024 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1706543255; cv=none; d=zohomail.com; s=zohoarc; b=nV++zdKCdP8AbCkXyxcOUFzwVZcRTUSJW3sRyJSKGG1LfOZck/yR5C93SisZg9md/840OZX9eEvhNshv4MHZ9GPP2iEVj0LHLt5kWFDhL1gzVpoLpmcPsfPwqsZTuNpMCgP7JQuZsiQqYbPBJ02Bcd3OwmvJC3jVeX9+9tAFO9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706543255; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iNVaeUpKkteNL3rGYKpxiJd02hUkBiHBGooaL89rDcI=; b=m79NK+nzOD1VGcgb50l5kf8akiF/Qgo3ASCK7cdH2mq6FxCOUhbu5TDNwgSAigAZ1RoDVRMQsMfVjIAjcdHl3ZqHCmkx1KU13QbK50ZBpwczIcwYKrASDLao6ecJDX//AJ30qUu1SxOKZSBasTtuw8Jh/aBzN1dB5BdskRJXOOQ= 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 1706543255466227.35511774708095; Mon, 29 Jan 2024 07:47:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUTqI-0000P5-Tj; Mon, 29 Jan 2024 10:46:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rUTqH-0000Oe-6l for qemu-devel@nongnu.org; Mon, 29 Jan 2024 10:46:37 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rUTqF-0005Fj-Ge for qemu-devel@nongnu.org; Mon, 29 Jan 2024 10:46:36 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40ef3f351d2so7373495e9.1 for ; Mon, 29 Jan 2024 07:46:35 -0800 (PST) Received: from localhost.localdomain (adsl-101.109.242.224.tellas.gr. [109.242.224.101]) by smtp.gmail.com with ESMTPSA id h15-20020a05600016cf00b0033aedfc5581sm2852608wrf.32.2024.01.29.07.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 07:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706543193; x=1707147993; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iNVaeUpKkteNL3rGYKpxiJd02hUkBiHBGooaL89rDcI=; b=VVsUlifc3DhYZQj0u5zKX9hikD3kMVA82DdELQYVZtmIRMMC3+vcUuVnipxZ7B+G5n 8xSTivNF4HEn242Egy+AzO65d/fry1xj0bdKYaNRvckOxBM/Tdpk11smlYh76JUNRjvD OsRk4hg8ARzkK/t4BDGMaGQeavXqd7v6W2GL7TWWczuEdLL+4vOJjHPVIq1P1wXdk8F0 yFcuSoAN6Q/qPlTl+Q+sOg07zZbwx97/3rAbMT2zTB+u+sLG5WN+KuoOmu1OCZULgCbW Ovqo6oNUjEfC0YeHRs2xlt+BSQNYRrWd9n1DdUrdPHCxZvHZ+g6mHK8j77rdqxgcLKOn fx3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706543193; x=1707147993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iNVaeUpKkteNL3rGYKpxiJd02hUkBiHBGooaL89rDcI=; b=u1rNUVeZPTw09cOcPx5IbT8hxKQyqfW62D+RVF8ZcRSBMXSxBwHENtsWOXU/F16Wo8 TlmhA4qcyQrtRlBXIFvvuonLAndyX/XXsTryIYS9f5ZUxxV6SHK5RZlzjdgO+IsubEz0 FCzjxhAT4a99pSTOKZ4vN1hKObvDvuaGn4LF9K18zIeaJgYy2n2/xJydqP/UYs5XlKSj StChxh/RxR/TIcAk1xhKzdp+Q301BhW+h6AOIdmcClusz96XUg5RraxKQk+Yesl6aefq WfJe/0+7fnRavX+v1whqM+Jk0UwLY2cAi+iCpt3XiE+x8nl3BKBK4XcreOK7OpMNBppL Y74w== X-Gm-Message-State: AOJu0YzXOc5y4I6WMdY9J1YhTNpR6kCEQKlwyzXFbpjluFheXWn8FlyL YV2PUjslbg4939bPSkRguKGugQvTSFFuSwD/cfoqXF2TSsdCzxY4VhxsDCk/6NUxKHlwAvQWywX 4W9Y= X-Google-Smtp-Source: AGHT+IFA3b71JMcdaOcgc9COsG1PPXZGyeRNYW91RHTbUBk9D10soDBAbTCirplbbzwQF5SeTo/LKg== X-Received: by 2002:adf:fc84:0:b0:337:d84c:1d6 with SMTP id g4-20020adffc84000000b00337d84c01d6mr5262303wrr.18.1706543193612; Mon, 29 Jan 2024 07:46:33 -0800 (PST) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , "Michael S. Tsirkin" , Gurchetan Singh , Alyssa Ross Subject: [PATCH v2 3/3] virtio-gpu-rutabaga.c: override resource_destroy method Date: Mon, 29 Jan 2024 17:45:25 +0200 Message-Id: <926db899bebc1f9ca575bfd29d140f7658050a82.1706542958.git.manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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=2a00:1450:4864:20::332; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm1-x332.google.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, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1706543256753100002 Content-Type: text/plain; charset="utf-8" When the Rutabaga GPU device frees resources, it calls rutabaga_resource_unref for that resource_id. However, when the generic VirtIOGPU functions destroys resources, it only removes the virtio_gpu_simple_resource from the device's VirtIOGPU->reslist list. The rutabaga resource associated with that resource_id is then leaked. This commit overrides the resource_destroy class method introduced in the previous commit to fix this. Signed-off-by: Manos Pitsidianakis --- hw/display/virtio-gpu-rutabaga.c | 51 ++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 9e67f9bd51..6ac0776005 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -148,14 +148,42 @@ rutabaga_cmd_create_resource_3d(VirtIOGPU *g, } =20 static void +virtio_gpu_rutabaga_resource_unref(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res, + Error **errp) +{ + int32_t result; + const char *strerror =3D NULL; + VirtIOGPURutabaga *vr =3D VIRTIO_GPU_RUTABAGA(g); + + result =3D rutabaga_resource_unref(vr->rutabaga, res->resource_id); + if (result) { + error_setg(errp, "%s: rutabaga_resource_unref returned %"PRIi32 + " for resource_id =3D %"PRIu32, __func__, result, + res->resource_id); + strerror =3D strerrorname_np((int)result); + if (strerror !=3D NULL) { + error_append_hint(errp, "%s: %s\n", + strerror, strerrordesc_np((int)result) ? : "= "); + } + } + + if (res->image) { + pixman_image_unref(res->image); + } + + QTAILQ_REMOVE(&g->reslist, res, next); + g_free(res); +} + +static void rutabaga_cmd_resource_unref(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { - int32_t result; + int32_t result =3D 0; struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_unref unref; - - VirtIOGPURutabaga *vr =3D VIRTIO_GPU_RUTABAGA(g); + Error *local_err =3D NULL; =20 VIRTIO_GPU_FILL_CMD(unref); =20 @@ -164,15 +192,14 @@ rutabaga_cmd_resource_unref(VirtIOGPU *g, res =3D virtio_gpu_find_resource(g, unref.resource_id); CHECK(res, cmd); =20 - result =3D rutabaga_resource_unref(vr->rutabaga, unref.resource_id); - CHECK(!result, cmd); - - if (res->image) { - pixman_image_unref(res->image); + virtio_gpu_rutabaga_resource_unref(g, res, &local_err); + if (local_err) { + error_report_err(local_err); + /* local_err was freed, do not reuse it. */ + local_err =3D NULL; + result =3D 1; } - - QTAILQ_REMOVE(&g->reslist, res, next); - g_free(res); + CHECK(!result, cmd); } =20 static void @@ -1099,7 +1126,7 @@ static void virtio_gpu_rutabaga_class_init(ObjectClas= s *klass, void *data) vgc->handle_ctrl =3D virtio_gpu_rutabaga_handle_ctrl; vgc->process_cmd =3D virtio_gpu_rutabaga_process_cmd; vgc->update_cursor_data =3D virtio_gpu_rutabaga_update_cursor; - + vgc->resource_destroy =3D virtio_gpu_rutabaga_resource_unref; vdc->realize =3D virtio_gpu_rutabaga_realize; device_class_set_props(dc, virtio_gpu_rutabaga_properties); } --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89