From patchwork Tue May 7 14:17:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 242371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC3702C016C for ; Wed, 8 May 2013 01:38:49 +1000 (EST) Received: from localhost ([::1]:49691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiqv-0000Ee-6X for incoming@patchwork.ozlabs.org; Tue, 07 May 2013 10:26:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZio0-0005qF-Uw for qemu-devel@nongnu.org; Tue, 07 May 2013 10:23:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZinx-0007oG-Nd for qemu-devel@nongnu.org; Tue, 07 May 2013 10:23:48 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:36658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiiv-000609-Ct for qemu-devel@nongnu.org; Tue, 07 May 2013 10:18:33 -0400 Received: by mail-wi0-f175.google.com with SMTP id h11so3817045wiv.8 for ; Tue, 07 May 2013 07:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=vDOdecww21kkRPBZkXkXei5Yz0cK+co8Bs4fQ7mG7f8=; b=ILNYfNLrKZmFJfGEjZxaLcwDtlxkYNxLjE5npcpxxZ0aPkRtXQiJI5Q1Q4qx6jyTex b2hkRMP5liZBrBlM5Wcc4G2DKH6XQw4Igeme49pjT7rJdoYIFqWyXrxMTeWf1yz1Nh+m 5x3UWUpfPd2vDb9wNxsnQ6GCuVFzN9F996qaYNKZJjVwgaXO8CKaS7UQaMEaAfvyVtac qAl4zFeNl8I9klpFnXwF4Ry8eKK6uTC+WLTqLFFbg6MI4QnlIxfHiniW2QptqxRCKIjl IxkJ/KiMKqbSGEg6m0N6SqYLh3Idx2gtmxRU2ngV9QJaQX97QCwzaUp8jXbF6DN/HjJ+ CseA== X-Received: by 10.180.14.5 with SMTP id l5mr15127090wic.32.1367936312496; Tue, 07 May 2013 07:18:32 -0700 (PDT) Received: from localhost.localdomain (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPSA id ge7sm3335978wib.6.2013.05.07.07.18.30 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 May 2013 07:18:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 7 May 2013 16:17:03 +0200 Message-Id: <1367936238-12196-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1367936238-12196-1-git-send-email-pbonzini@redhat.com> References: <1367936238-12196-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22f Cc: aik@ozlabs.ru, jan.kiszka@siemens.com, qemulist@gmail.com, stefanha@redhat.com, david@gibson.dropbear.id.au Subject: [Qemu-devel] [PATCH 25/40] memory: add ref/unref X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 34 ++++++++++++++++++++++++++++++++++ memory.c | 14 ++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5c20bac..ebac085 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -253,6 +253,40 @@ struct MemoryListener { void memory_region_init(MemoryRegion *mr, const char *name, uint64_t size); + +/** + * memory_region_ref: Add 1 to a memory region's reference count + * + * Whenever memory regions are accessed outside the BQL, they need to be + * preserved against hot-unplug. MemoryRegions actually do not have their + * own reference count; they piggyback on a QOM object, their "owner". + * This function adds a reference to the owner. + * + * All MemoryRegions must have an owner if they can disappear, even if the + * device they belong to operates exclusively under the BQL. This is because + * the region could be returned at any time by memory_region_find, and this + * is usually under guest control. + * + * @mr: the #MemoryRegion to be initialized + * @name: used for debugging; not visible to the user or ABI + * @size: size of the region; any subregions beyond this size will be clipped + */ +void memory_region_ref(MemoryRegion *mr); + +/** + * memory_region_ref: Remove 1 to a memory region's reference count + * + * Whenever memory regions are accessed outside the BQL, they need to be + * preserved against hot-unplug. MemoryRegions actually do not have their + * own reference count; they piggyback on a QOM object, their "owner". + * This function removes a reference to the owner and possibly destroys it. + * + * @mr: the #MemoryRegion to be initialized + * @name: used for debugging; not visible to the user or ABI + * @size: size of the region; any subregions beyond this size will be clipped + */ +void memory_region_unref(MemoryRegion *mr); + /** * memory_region_init_io: Initialize an I/O memory region. * diff --git a/memory.c b/memory.c index f7fddb1..c7ab19c 100644 --- a/memory.c +++ b/memory.c @@ -1061,6 +1061,20 @@ void memory_region_set_owner(MemoryRegion *mr, } } +void memory_region_ref(MemoryRegion *mr) +{ + if (mr && mr->owner) { + object_ref(mr->owner); + } +} + +void memory_region_unref(MemoryRegion *mr) +{ + if (mr && mr->owner) { + object_unref(mr->owner); + } +} + uint64_t memory_region_size(MemoryRegion *mr) { if (int128_eq(mr->size, int128_2_64())) {