From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stxk1-0006U0-Ak for qemu-devel@nongnu.org; Wed, 25 Jul 2012 05:18:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Stxjz-0006yp-9f for qemu-devel@nongnu.org; Wed, 25 Jul 2012 05:18:49 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:49419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stxjz-0006yi-5T for qemu-devel@nongnu.org; Wed, 25 Jul 2012 05:18:47 -0400 Received: by ghrr14 with SMTP id r14so473447ghr.4 for ; Wed, 25 Jul 2012 02:18:46 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <500FB9EB.5010306@redhat.com> Date: Wed, 25 Jul 2012 11:18:35 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1343187070-27371-1-git-send-email-qemulist@gmail.com> <1343187070-27371-3-git-send-email-qemulist@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/5] exec.c: use refcnt to protect device during dispatching List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liu ping fan Cc: kvm@vger.kernel.org, Stefan Hajnoczi , Marcelo Tosatti , qemu-devel@nongnu.org, Avi Kivity , Anthony Liguori , Jan Kiszka Il 25/07/2012 10:12, liu ping fan ha scritto: >>> >> + qemu_rwlock_rdlock_devtree(); >>> >> section = phys_page_find(page >> TARGET_PAGE_BITS); >>> >> + if (!(memory_region_is_ram(section->mr) || >>> >> + memory_region_is_romd(section->mr)) && !is_write) { >>> >> + bk = get_backend(section->mr, addr); >>> >> + object_ref(bk); >>> >> + } else if (!memory_region_is_ram(section->mr) && is_write) { >>> >> + bk = get_backend(section->mr, addr); >>> >> + object_ref(bk); >>> >> + } >>> >> + qemu_rwlock_unlock_devtree(); >>> >> >>> >> if (is_write) { >>> >> if (!memory_region_is_ram(section->mr)) { >>> >> @@ -3426,6 +3462,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, >>> >> io_mem_write(section->mr, addr1, val, 1); >>> >> l = 1; >>> >> } >>> >> + object_unref(bk); >> > >> > Currently object_ref()/object_unref() are not atomic. Will you send > We obey the rule: > rdlock->search->ref_get, > wrlock->remove ->ref_put > So can it causes problem if object_ref()/object_unref() are not atomic? Yes, two CPUs can perform object_ref at the same time. You can find a header file for atomic operations here: https://github.com/bonzini/qemu/commit/atomics.patch Paolo