From patchwork Mon Jan 29 15:45:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 13535907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C7F0C47DDB for ; Mon, 29 Jan 2024 15:47:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUTq5-0000Kq-J4; Mon, 29 Jan 2024 10:46:25 -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 1rUTq2-0000JM-UN for qemu-devel@nongnu.org; Mon, 29 Jan 2024 10:46:23 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rUTq1-0005D2-96 for qemu-devel@nongnu.org; Mon, 29 Jan 2024 10:46:22 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e80046246so15775795e9.1 for ; Mon, 29 Jan 2024 07:46:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706543179; x=1707147979; 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=3zRxwzBg1JPAeksvDXKolStU0KP7INqkx8/kV22Vx3g=; b=OhOcobVvRsl/loBwTy6LuldPMX0Pp/3xDtYXMQTBKUF81/uSkocsdj208daJzRSP+/ noXAxMThzN1EvlGALsOngUJ3U6BgtcsbIc34zyMhomQXdbERouf+wB+RAqf7xyyJnkSk pM3m+tufJC8PsBXUzl/uukkFphu+g480y0O3+kQcDWjwRrHCchUwbszeWyo/pUH5QVHv 92vWl9qpRalhU6Sk4kYQc32Zp+mAuhWbZgieDVwvtJykVAJU/PFpVJLd5W0fECvw+Fou tXcryPkT8ff8ahF1hnPe8jPkP2IFvxAxhVBa7nzy4jxS2c9CEctEM7VkcfNC7LE72kZa 4KfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706543179; x=1707147979; 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=3zRxwzBg1JPAeksvDXKolStU0KP7INqkx8/kV22Vx3g=; b=Km7cuKyi56ZXRq1C6pcVx5qKiax9Q0KNl0nG8GsNSDEjrzNGwGGmJvV9A0LS5TTdsB zltiKC46YFDKb9eef0M8HRWFnCCsZxGx1neQVL19p28ssdjq39PrdPmfCrv+fCsOqc9c V1MZsti5g/GLwcwzDHXiI7SGL5xS/QvFZo+v5VSddNRZnucouO7dvNoGPtCXbGYC7Cbi Ldh2gaKtJsUL5g/twOl0jWfHjGbXGlAbJy0kcYesyKKAaG7KMHqS21rF0fyRzk05LypL Y9N25jRqbEKes4nzugDGogVhspGgBTDw0J2Mue1BATPa5Tk5MpBkfWkOtwYvdSd012q3 JxZA== X-Gm-Message-State: AOJu0Yxbspq8NHt73XnEJu+gm+gvwDfQp5ztC18848gEnQzGlw/x3MoW gAaRCayb4RFt7j2YYufJ6N3N+UXm7h6wOxvBk+s8sxz3C5qfoPnKazWCN83mNx0Eni3uD8Z6/kJ JWsM= X-Google-Smtp-Source: AGHT+IHOS9K957M7773lIW9B1ZTmACZrKo0G+OXpIoINScUUN0p/8FQhRyYy+EcpKvKnicFl+KJ9NQ== X-Received: by 2002:a05:600c:4e92:b0:40e:b27c:9cc3 with SMTP id f18-20020a05600c4e9200b0040eb27c9cc3mr5783457wmq.0.1706543178978; Mon, 29 Jan 2024 07:46:18 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 07:46:18 -0800 (PST) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , "Michael S. Tsirkin" , Gurchetan Singh , Alyssa Ross , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v2 1/3] hw/display/virtio-gpu.c: use reset_bh class method Date: Mon, 29 Jan 2024 17:45:23 +0200 Message-Id: <5893fb45d1a3f770fbb5dcea0c541eb92e386c4a.1706542958.git.manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm1-x334.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org While the VirtioGPU type has a reset_bh field to specify a reset callback, it's never used. virtio_gpu_reset() calls the general virtio_gpu_reset_bh() function for all devices that inherit from VirtioGPU. While no devices override reset_bh at the moment, a device reset might require special logic for implementations in the future. Reviewed-by: Marc-André Lureau Signed-off-by: Manos Pitsidianakis --- hw/display/virtio-gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f8a675eb30..2b73ae585b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1515,7 +1515,7 @@ void virtio_gpu_reset(VirtIODevice *vdev) qemu_cond_wait_bql(&g->reset_cond); } } else { - virtio_gpu_reset_bh(g); + aio_bh_call(g->reset_bh); } while (!QTAILQ_EMPTY(&g->cmdq)) { From patchwork Mon Jan 29 15:45:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 13535906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6269C47DDB for ; Mon, 29 Jan 2024 15:46:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUTqF-0000Np-3q; Mon, 29 Jan 2024 10:46:35 -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 1rUTqD-0000N5-7x for qemu-devel@nongnu.org; Mon, 29 Jan 2024 10:46:33 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rUTqB-0005Eh-4q for qemu-devel@nongnu.org; Mon, 29 Jan 2024 10:46:32 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40e80046246so15777095e9.1 for ; Mon, 29 Jan 2024 07:46:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706543189; x=1707147989; 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=OO1Xd496GZU9VnfGz8L9/dfv4mIbaz4PPUfJmAWvi4E=; b=XCNw98moHjT8fWX3O1Olh0L3dWS/IRlLm//uLtt37asDAOFKd7eNSm3cB1DJUT3wnH smZI/d6y76HErxFm5OfvylwjaguEkZVXpXuTVNHHueWBbNmdtTfmUVSWtgU/zOlK0NOL CaXHRc05QRMpmwh6NxxPeM1v15gs2GE324toeo0hnNjm2foZT+hGC016MqdMNi+lA+CE kIsolTi1IN0WJybt11VlGw5ndW4bd6kNzfxzSRdh5XBXhx42mlWkVZsxXN23e44OizEU R3uiI8zTN1wtD1EMm6INDmYx6xievFVHyItnoZSK1JnY9LO8bqh5LS0xfpzNHyc05U5R KlNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706543189; x=1707147989; 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=OO1Xd496GZU9VnfGz8L9/dfv4mIbaz4PPUfJmAWvi4E=; b=CNuxS1RjcEizLPxrMQ8MPFVCFf9nFC6SQsse3jEvT+e8w68zdRn9yEfBFRh/HP4oUp zXjlVZUG4TZydR22GWbZmdZYY5/a6DCkeIJdkvXL0aaSeqFEHWKuxgn+dH+9kIc/QipP uOcIOGn4HiReRPIQ7ENiBCak48XCSUkct9NkPDsSzLnGt3E1LKU1+GaeKIJ/kOT5jjja sVp5xHV6WH03e3wYEHhzvjabXNDM7nEMKB8I5Tc0kxpp7646AZp68TtQcjh480ETYitf i//6b2vmbIC7jK65KmTu5A7MbhVbDz5wvaR7yuLaMjUiDIr0Yr9BaspkWuK8LBr/cna5 ntwQ== X-Gm-Message-State: AOJu0YyA7teKgKaU914lNf81y73pi01v2I3XyCJM0uyuxU6PyHP8tfbP qGAIQZbkyiVzcsNKkvUBPXEdCgFtBKz2QvQRv7M10J2L4YNPhcXeWvBI2q1p1lUV+yu7chAAyal N6uM= X-Google-Smtp-Source: AGHT+IEbhvq46WfB26KVKDoPqwu7uC6IFLXmRvAJVSOMGlQWMYSorr/E+rcAzgUP67285OgCXI9Iaw== X-Received: by 2002:a05:600c:5108:b0:40e:f14c:e1a6 with SMTP id o8-20020a05600c510800b0040ef14ce1a6mr3889537wms.6.1706543189201; Mon, 29 Jan 2024 07:46:29 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 07:46:28 -0800 (PST) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gerd Hoffmann , "Michael S. Tsirkin" , Gurchetan Singh , Alyssa Ross Subject: [PATCH v2 2/3] virtio-gpu.c: add resource_destroy class method Date: Mon, 29 Jan 2024 17:45:24 +0200 Message-Id: <78b15e8f7e2af529aeaed2e6ef37efa508cf405f.1706542958.git.manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm1-x32a.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When destroying/unrefing resources, devices such as virtio-gpu-rutabaga need to do their own bookkeeping (free rutabaga resources that are associated with the virtio_gpu_simple_resource). This commit adds a class method so that virtio-gpu-rutabaga can override it in the next commit. Signed-off-by: Manos Pitsidianakis Reviewed-by: Marc-André Lureau --- include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu.c | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 584ba2ed73..b28e7ef0d2 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -219,6 +219,9 @@ struct VirtIOGPUClass { void (*update_cursor_data)(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id); + void (*resource_destroy)(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res, + Error **errp); }; struct VirtIOGPUGL { diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 2b73ae585b..1c1ee230b3 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -402,7 +402,8 @@ static void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id) } static void virtio_gpu_resource_destroy(VirtIOGPU *g, - struct virtio_gpu_simple_resource *res) + struct virtio_gpu_simple_resource *res, + Error **errp) { int i; @@ -438,7 +439,11 @@ static void virtio_gpu_resource_unref(VirtIOGPU *g, cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; return; } - virtio_gpu_resource_destroy(g, res); + /* + * virtio_gpu_resource_destroy does not set any errors, so pass a NULL errp + * to ignore them. + */ + virtio_gpu_resource_destroy(g, res, NULL); } static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g, @@ -1488,11 +1493,24 @@ static void virtio_gpu_device_unrealize(DeviceState *qdev) static void virtio_gpu_reset_bh(void *opaque) { VirtIOGPU *g = VIRTIO_GPU(opaque); + VirtIOGPUClass *vgc = VIRTIO_GPU_GET_CLASS(g); struct virtio_gpu_simple_resource *res, *tmp; + uint32_t resource_id; + Error *local_err = NULL; int i = 0; QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) { - virtio_gpu_resource_destroy(g, res); + resource_id = res->resource_id; + vgc->resource_destroy(g, res, &local_err); + if (local_err) { + error_append_hint(&local_err, "%s: %s resource_destroy" + "for resource_id = %"PRIu32" failed.\n", + __func__, object_get_typename(OBJECT(g)), + resource_id); + /* error_report_err frees the error object for us */ + error_report_err(local_err); + local_err = NULL; + } } for (i = 0; i < g->parent_obj.conf.max_outputs; i++) { @@ -1632,6 +1650,7 @@ static void virtio_gpu_class_init(ObjectClass *klass, void *data) vgc->handle_ctrl = virtio_gpu_handle_ctrl; vgc->process_cmd = virtio_gpu_simple_process_cmd; vgc->update_cursor_data = virtio_gpu_update_cursor_data; + vgc->resource_destroy = virtio_gpu_resource_destroy; vgbc->gl_flushed = virtio_gpu_handle_gl_flushed; vdc->realize = virtio_gpu_device_realize; From patchwork Mon Jan 29 15:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 13535908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F913C48285 for ; Mon, 29 Jan 2024 15:47:35 +0000 (UTC) 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) 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) 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) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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-rutabaga.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, } static void +virtio_gpu_rutabaga_resource_unref(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res, + Error **errp) +{ + int32_t result; + const char *strerror = NULL; + VirtIOGPURutabaga *vr = VIRTIO_GPU_RUTABAGA(g); + + result = rutabaga_resource_unref(vr->rutabaga, res->resource_id); + if (result) { + error_setg(errp, "%s: rutabaga_resource_unref returned %"PRIi32 + " for resource_id = %"PRIu32, __func__, result, + res->resource_id); + strerror = strerrorname_np((int)result); + if (strerror != 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 = 0; struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_unref unref; - - VirtIOGPURutabaga *vr = VIRTIO_GPU_RUTABAGA(g); + Error *local_err = NULL; VIRTIO_GPU_FILL_CMD(unref); @@ -164,15 +192,14 @@ rutabaga_cmd_resource_unref(VirtIOGPU *g, res = virtio_gpu_find_resource(g, unref.resource_id); CHECK(res, cmd); - result = 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 = NULL; + result = 1; } - - QTAILQ_REMOVE(&g->reslist, res, next); - g_free(res); + CHECK(!result, cmd); } static void @@ -1099,7 +1126,7 @@ static void virtio_gpu_rutabaga_class_init(ObjectClass *klass, void *data) vgc->handle_ctrl = virtio_gpu_rutabaga_handle_ctrl; vgc->process_cmd = virtio_gpu_rutabaga_process_cmd; vgc->update_cursor_data = virtio_gpu_rutabaga_update_cursor; - + vgc->resource_destroy = virtio_gpu_rutabaga_resource_unref; vdc->realize = virtio_gpu_rutabaga_realize; device_class_set_props(dc, virtio_gpu_rutabaga_properties); }