From nobody Mon Nov 25 01:38:48 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 ARC-Seal: i=1; a=rsa-sha256; t=1719400142; cv=none; d=zohomail.com; s=zohoarc; b=R+Fsovy9N+mIanwWRA3OKT5WsSO0hV4+H070HkqYZ4ry0D7OP0pSfXjDCnXcPuEuEYagW3gLu9yYNOPvhMkQ+nCzurjCPYRDkbISF7QEl1CtY3WxA9+QBOnsij1KMWLQyaNVxNA9UU9XpqRLekS8FAaXypfuLzNAQt5Bew592xE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719400142; 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=iVExPEERs03d8J7JOBkBCKVU3MF1YFO5OIPVbHq+rGo=; b=nhKA4fLsf4E6ZQd6IPqS/nNDrZnws2uFuf3ef0HITRAz+6ZsIxEFPqCu9R0GH/1WZeWpYgXzlWZibuPSTkGCh6F2W05ebeBvxbs2v74IIDAGpm3Owy9AHBq/7vesI6eLUMO/6AhxfgIlpHw4mxuzl9tRcKGTdksWDn/8Z2etCs8= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1719400142974830.9704118067588; Wed, 26 Jun 2024 04:09:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMQV4-00069G-CM; Wed, 26 Jun 2024 07:07:42 -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 1sMQUw-0005x4-VJ for qemu-devel@nongnu.org; Wed, 26 Jun 2024 07:07:35 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMQUq-0004om-BQ for qemu-devel@nongnu.org; Wed, 26 Jun 2024 07:07:33 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1f47f07acd3so53930905ad.0 for ; Wed, 26 Jun 2024 04:07:27 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2c8e3d5c212sm658497a91.39.2024.06.26.04.07.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jun 2024 04:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1719400047; x=1720004847; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=iVExPEERs03d8J7JOBkBCKVU3MF1YFO5OIPVbHq+rGo=; b=PJKT2esgUPOSw4PI1EviJa7jzgkEzKz8wr71MnZDp2IK/jlrk+dCS3nlm0ms4jHOvp qzYXEEUc/MZ24ig7zqKsLZJVV30vCxYafjzoGSuq2+a4Tec4G4ex8Y+Z8azB7MCfXh8a 92ws+Sy1yHDe/bRz3IqbfEw06HO3nO0AsUrsbFIBr9ho2nQmfZ3Rd22oICkkUCD2luW8 dhHBOzk2whFQcRUJC7nkbTQzPB7J0iQrvoq3tF4d2n8RHO3HMI7RKEBDwwChLpBG4uxy +Z/i0nJ3TlyXNRyD/5+B4efdhXeoW4iHTC4pjsG7rg9OF7PP+LSRcjZlVxw+AmXmhedH kZ4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719400047; x=1720004847; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iVExPEERs03d8J7JOBkBCKVU3MF1YFO5OIPVbHq+rGo=; b=OuApOCNywMR+5ddyTi8KKA6t7yvN3WgIbLM5msSVa/LcSh5TgbjqoAKpYSnY9TMeWw 7/eUXdAYnzgf3r9xlpSMB97ONacC3TIWWGeRBHuZaS2hME4KltxtkBMebyt9oIhP4LSl SYMdUwbRHCPLaEI9/FK/VBFVNDUQINYScz0NVovaeEXA3J60yI+XeTXq7DBT+GPpDwX0 cuzo0wTpeXV6lRkTVSB0JZBTMxGJSCr6T2NSBzaeJEUmAV2wJEgOR2+TvH3RwhRpezpP fBcIVhFGcSxwu9d9gExGx2KV2kY4yLEB6DpTHX2pGbnCCCE6FLiSrlWEN240oubV3Q/F Hclw== X-Gm-Message-State: AOJu0Yz4cGKmBSVKLFSlJ68/vAaAMu+PqQh/uUkUZmqKLLuKVkphU/qJ nvgDW46CuHuyRMbKBu1iT6YuXVaqyu2E95uFXi9fdQZz1RUe5T1bZ9/YqDGhcm0= X-Google-Smtp-Source: AGHT+IFHZSiES9BZEEPk+NXe29hftgQvC9L7D5dfAK7MIvE4y2e9kzrX+7AOJKzd50WKmiX8oIWT7Q== X-Received: by 2002:a17:90b:1d89:b0:2c7:9b9a:7619 with SMTP id 98e67ed59e1d1-2c858275bd3mr9505817a91.32.1719400046756; Wed, 26 Jun 2024 04:07:26 -0700 (PDT) From: Akihiko Odaki Date: Wed, 26 Jun 2024 20:06:31 +0900 Subject: [PATCH 08/14] memory: Do not create circular reference with subregion MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240626-san-v1-8-f3cc42302189@daynix.com> References: <20240626-san-v1-0-f3cc42302189@daynix.com> In-Reply-To: <20240626-san-v1-0-f3cc42302189@daynix.com> To: Eduardo Habkost , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Yanan Wang , John Snow , BALATON Zoltan , Jiaxun Yang , Nicholas Piggin , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , Alexey Kardashevskiy , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Xu , Fabiano Rosas , Paolo Bonzini , David Hildenbrand , Thomas Huth , Laurent Vivier Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, qemu-ppc@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: none client-ip=2607:f8b0:4864:20::636; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1719400143967100001 A memory region does not use their own reference counters, but instead piggybacks on another QOM object, "owner" (unless the owner is not the memory region itself). When creating a subregion, a new reference to the owner of the container must be created. However, if the subregion is owned by the same QOM object, this result in a self-reference, and make the owner immortal. Avoid such a self-reference. Signed-off-by: Akihiko Odaki --- system/memory.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/system/memory.c b/system/memory.c index 9540caa8a1f4..6645da02c658 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2638,7 +2638,10 @@ static void memory_region_update_container_subregion= s(MemoryRegion *subregion) =20 memory_region_transaction_begin(); =20 - memory_region_ref(subregion); + if (mr->owner !=3D subregion->owner) { + memory_region_ref(subregion); + } + QTAILQ_FOREACH(other, &mr->subregions, subregions_link) { if (subregion->priority >=3D other->priority) { QTAILQ_INSERT_BEFORE(other, subregion, subregions_link); @@ -2696,7 +2699,11 @@ void memory_region_del_subregion(MemoryRegion *mr, assert(alias->mapped_via_alias >=3D 0); } QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link); - memory_region_unref(subregion); + + if (mr->owner !=3D subregion->owner) { + memory_region_unref(subregion); + } + memory_region_update_pending |=3D mr->enabled && subregion->enabled; memory_region_transaction_commit(); } --=20 2.45.2