From patchwork Thu Apr 10 12:26:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 879753 Delivered-To: patch@linaro.org Received: by 2002:a5d:4882:0:b0:38f:210b:807b with SMTP id g2csp217395wrq; Thu, 10 Apr 2025 05:27:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXARY0FytaRd+CrsYm5LK6jQyDCGK67YCpF+nJHPYxyewJRPGY2EMxf8NLrX3r/TXjKx//wjA==@linaro.org X-Google-Smtp-Source: AGHT+IHlFDjvRoy8B5d8Dh+uDNMer9gbRnJ1Bakfk7/IiJ4Oafl1FTQx0N5a2dXcxjAJVKMaGvis X-Received: by 2002:ac8:5996:0:b0:476:9e28:ce49 with SMTP id d75a77b69052e-4796cd49568mr37252581cf.43.1744288051308; Thu, 10 Apr 2025 05:27:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744288051; cv=none; d=google.com; s=arc-20240605; b=KlFsCuSkJ3p8E3eaW65Uh4h+5fxFiSvXsFK6YiM/8YZ7aluXRkqN5FitMqdKRfbZ76 mi2CvEzdQTcZdaet/RG6Z1+4Oc6sOI9pzNyQv8WUwXlLMic7aHrbLIWJYdhmeTtMtxZz PQnYyu3b5DBLHLFaRgpSogsFmadtbW9gGfXKd/ADjyGZx8Z+6fygipq5626iwDVN4HTS 09mYkL+yfC09++wzaIzvpJ8E5rwQLNcb1TZX3hhqpX5F0pe5lXOpIm5SjZvg5oAyUhYQ AWZS4SNvHJGUIkepS2pKS9NWrehtfbQp6aOmWVWopAxO5cnwmcOhBWRvtZ7igMTkShqW lOcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UU0LoY4xVh4T7ejP0yIlqdytiVhNHfWI17GoV5hTncM=; fh=737+bNslWfbb2sVyD32kEy1zggF5qB7uyD1+44/EeVs=; b=ScmUfeLvxHyH2L6tXdb+PQ13XhiBzwU9ANx1iLxPqubRZpLCPXiDetYoY721+AQYn0 PiA53gO5W7sUaWnKSz5dXMkU1xJ8KsM4TenvE8TiWNnshHep5nP0Rf1MB+ty/vu4UY57 Hh/1w1RnQsvm/2mFP4/Q5tZ72YYct8TDkPS7kzqyplcA5iOdeBTuvFxEti+j/oY6vtok 1O/ytKbzSqM/QOONXU8qOBzz3g1Ai2k6BIbtPBkdVGQYtFr7l+wLg+j+SWnt9kYzkDUP YW10F+k+7OQqOH1FolQOJLoKp4v0H5KEpHcjdq2OYCYYuXdUqvQPQ803H5WO2atXq/Lq 6lxw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=STbQzh1F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4796edd60dfsi9175761cf.381.2025.04.10.05.27.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Apr 2025 05:27:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=STbQzh1F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u2qzg-0008NB-Bf; Thu, 10 Apr 2025 08:26:56 -0400 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 1u2qzc-0008HB-O1 for qemu-devel@nongnu.org; Thu, 10 Apr 2025 08:26:52 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u2qzZ-0000bs-H9 for qemu-devel@nongnu.org; Thu, 10 Apr 2025 08:26:52 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5e5e8274a74so1179873a12.1 for ; Thu, 10 Apr 2025 05:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744288007; x=1744892807; 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=UU0LoY4xVh4T7ejP0yIlqdytiVhNHfWI17GoV5hTncM=; b=STbQzh1Ft/ebX04UNM1hZRxV6bVX1JWtk8+dFpV6bsNhU+OvlvPFxsH6ZvPJBA0+NU Ta4OZhmbAbn5LfuBm8PXL+VLH3qmyDSQnTGLfWr34Iq+lvrupBOZcQgxunPuM9xAxFhB 6kamiiG1YK/BwFV9KqoTWqgF71IwIfdmc+O1sPTC5ROqXJKqDjFTVM8caOgsapKaMGpy mSULDP4hC0YfBrOriVyOUbXYag4d4y1jp6z869CRTbnMnQwo2s1+DMWinwvfcrq6ORfB FTt/rUDtrS2Smyc+2CXJOUjlx8iS1Eo8GiYp7ebgFykHfNXJY+OGTFTTfEN47wTD1ni6 ztpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744288007; x=1744892807; 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=UU0LoY4xVh4T7ejP0yIlqdytiVhNHfWI17GoV5hTncM=; b=MXSEtWrW2lvDy4wLNqe45Vg3JEPegR82tRpSNcISOwZhaTBjvyvVgGhmsg450ijwj/ QtVK8yloqCZqeTo9lDdp993/pMFRa7U2DXNiHU8gcTPeKMVopo+jzv1oF4ocQ4ujpm0H 87hq8Lr1b4Gpi7LbAhgMSPs64Y60AQFZQiiETudCsG3wGW/aPlElODpyw7ByQkg2l33s NL3HKJAAHdURC7Stodujdlg09QNppLcAt/oaoSqeKBhpHZyiUs8xOuOAEHZkfhKWJxBD 1wOePl9bpd5t2dyEdyHkUXl6dGN+9TlGLTguLQBAvz591t/0+JirJaWQeoNP1qu0WPj6 ay9Q== X-Gm-Message-State: AOJu0Yw8BIckbX326KCZo4q4ord497U26FxHwDRz7LB95DTrY/t4/0Im +XplidEIb6ydIlf/bHp4VC42F7M34o6pfBu4iBVemJ1ZYLvhtm6KMta4bVplLBBu0pnZsnkef8l 7Zpc= X-Gm-Gg: ASbGnctF27/UeRRq1hr5t1oQST+0gm4phToubMDkmV+lq7hb7iw56a5rCNpDbrS5Uuu uucBj37tqARX117jh6+HnPwh834ST8mL/xoNszHrXlXvt3wBuGYoycbfj56rcHCZ0vM+oIrZz3V gp4RIwXC+jyST6YMzvxeXFcnqM3p4KViIkTy6oSSRysplNCiEtmH+wBoy4LgM7JQCtgjVGLIYo4 SCBAD4oHS0LItb3k0Kc0jIIhtj91nZkDRctGcozBPpgbIPpg13Rlkb17hEH9f3zcMyxR+j2WpXH StQNgZluorthyB9yfM7mwoZj8ClkALRE3PkRerSaMv4ETyWaH7hq49gR5302HMgeGrLKVFgunM3 mdrhS1sgmMkRi/MEGaOb7J/M= X-Received: by 2002:a17:907:3d4b:b0:ac7:cc25:9637 with SMTP id a640c23a62f3a-acabcb3ac4bmr294485066b.0.1744288007368; Thu, 10 Apr 2025 05:26:47 -0700 (PDT) Received: from localhost.localdomain (adsl-194.109.242.94.tellas.gr. [109.242.94.194]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-acaa1be98c9sm271794866b.65.2025.04.10.05.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 05:26:47 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Richard Henderson , "Michael S. Tsirkin" , Paolo Bonzini , Peter Xu , David Hildenbrand Subject: [PATCH v2 1/3] hw/display: re-arrange memory region tracking Date: Thu, 10 Apr 2025 15:26:36 +0300 Message-ID: <20250410122643.1747913-2-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250410122643.1747913-1-manos.pitsidianakis@linaro.org> References: <20250410122643.1747913-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-ed1-x532.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Alex Bennée QOM objects can be embedded in other QOM objects and managed as part of their lifetime but this isn't the case for virtio_gpu_virgl_hostmem_region. However before we can split it out we need some other way of associating the wider data structure with the memory region. Fortunately MemoryRegion has an opaque pointer. This is passed down to MemoryRegionOps for device type regions but is unused in the memory_region_init_ram_ptr() case. Use the opaque to carry the reference and allow the final MemoryRegion object to be reaped when its reference count is cleared. Signed-off-by: Alex Bennée Signed-off-by: Manos Pitsidianakis --- include/exec/memory.h | 1 + hw/display/virtio-gpu-virgl.c | 23 ++++++++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index d09af58c97..bb735a3c7e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -784,6 +784,7 @@ struct MemoryRegion { DeviceState *dev; const MemoryRegionOps *ops; + /* opaque data, used by backends like @ops */ void *opaque; MemoryRegion *container; int mapped_via_alias; /* Mapped via an alias, container might be NULL */ diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 145a0b3879..71a7500de9 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -52,17 +52,11 @@ virgl_get_egl_display(G_GNUC_UNUSED void *cookie) #if VIRGL_VERSION_MAJOR >= 1 struct virtio_gpu_virgl_hostmem_region { - MemoryRegion mr; + MemoryRegion *mr; struct VirtIOGPU *g; bool finish_unmapping; }; -static struct virtio_gpu_virgl_hostmem_region * -to_hostmem_region(MemoryRegion *mr) -{ - return container_of(mr, struct virtio_gpu_virgl_hostmem_region, mr); -} - static void virtio_gpu_virgl_resume_cmdq_bh(void *opaque) { VirtIOGPU *g = opaque; @@ -73,14 +67,12 @@ static void virtio_gpu_virgl_resume_cmdq_bh(void *opaque) static void virtio_gpu_virgl_hostmem_region_free(void *obj) { MemoryRegion *mr = MEMORY_REGION(obj); - struct virtio_gpu_virgl_hostmem_region *vmr; + struct virtio_gpu_virgl_hostmem_region *vmr = mr->opaque; VirtIOGPUBase *b; VirtIOGPUGL *gl; - vmr = to_hostmem_region(mr); - vmr->finish_unmapping = true; - b = VIRTIO_GPU_BASE(vmr->g); + vmr->finish_unmapping = true; b->renderer_blocked--; /* @@ -118,8 +110,8 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g, vmr = g_new0(struct virtio_gpu_virgl_hostmem_region, 1); vmr->g = g; + mr = g_new0(MemoryRegion, 1); - mr = &vmr->mr; memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data); memory_region_add_subregion(&b->hostmem, offset, mr); memory_region_set_enabled(mr, true); @@ -131,7 +123,9 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g, * command processing until MR is fully unreferenced and freed. */ OBJECT(mr)->free = virtio_gpu_virgl_hostmem_region_free; + mr->opaque = vmr; + vmr->mr = mr; res->mr = mr; return 0; @@ -142,16 +136,15 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g, struct virtio_gpu_virgl_resource *res, bool *cmd_suspended) { - struct virtio_gpu_virgl_hostmem_region *vmr; VirtIOGPUBase *b = VIRTIO_GPU_BASE(g); MemoryRegion *mr = res->mr; + struct virtio_gpu_virgl_hostmem_region *vmr; int ret; if (!mr) { return 0; } - - vmr = to_hostmem_region(res->mr); + vmr = mr->opaque; /* * Perform async unmapping in 3 steps: