From patchwork Thu Oct 21 17:36:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 68762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 35787B6EFF for ; Fri, 22 Oct 2010 05:45:27 +1100 (EST) Received: from localhost ([127.0.0.1]:40775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8zIL-0005yv-FV for incoming@patchwork.ozlabs.org; Thu, 21 Oct 2010 13:51:17 -0400 Received: from [140.186.70.92] (port=42936 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8z5P-0000lU-B2 for qemu-devel@nongnu.org; Thu, 21 Oct 2010 13:37:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8z5K-0005oI-Ob for qemu-devel@nongnu.org; Thu, 21 Oct 2010 13:37:53 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:52050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8z5K-0005jY-Gt for qemu-devel@nongnu.org; Thu, 21 Oct 2010 13:37:50 -0400 X-IronPort-AV: E=Sophos;i="4.58,218,1286164800"; d="scan'208";a="119106435" Received: from ftlpexchmx02.citrite.net ([10.9.154.127]) by FTLPIPO02.CITRIX.COM with ESMTP; 21 Oct 2010 13:37:50 -0400 Received: from smtp01.ad.xensource.com ([10.219.128.104]) by FTLPEXCHMX02.citrite.net with Microsoft SMTPSVC(6.0.3790.4675); Thu, 21 Oct 2010 13:37:48 -0400 Received: from perard.cam.xci-test.com (perard.cam.xci-test.com [10.80.248.106]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id o9LHb2ir009642; Thu, 21 Oct 2010 10:37:48 -0700 From: anthony.perard@citrix.com To: QEMU-devel Date: Thu, 21 Oct 2010 18:36:23 +0100 Message-Id: <1287682587-18642-12-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1287682587-18642-1-git-send-email-anthony.perard@citrix.com> References: <1287682587-18642-1-git-send-email-anthony.perard@citrix.com> X-OriginalArrivalTime: 21 Oct 2010 17:37:48.0854 (UTC) FILETIME=[ADD94D60:01CB7146] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Anthony PERARD , Xen Devel , Stefano Stabellini Subject: [Qemu-devel] [PATCH V6 11/15] Introduce qemu_ram_ptr_unlock. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Anthony PERARD This function allows to unlock a ram_ptr give by qemu_get_ram_ptr. After a call to qemu_ram_ptr_unlock, the pointer may be unmap from QEMU when used with Xen. Signed-off-by: Anthony PERARD --- cpu-common.h | 1 + exec.c | 10 ++++++++++ xen-mapcache.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index a543b5d..8ec01f4 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -46,6 +46,7 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size); void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr(ram_addr_t addr); +void qemu_ram_ptr_unlock(void *addr); /* This should not be used by devices. */ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr); diff --git a/exec.c b/exec.c index d2cded6..e188859 100644 --- a/exec.c +++ b/exec.c @@ -2957,6 +2957,13 @@ void *qemu_get_ram_ptr(ram_addr_t addr) return NULL; } +void qemu_ram_ptr_unlock(void *addr) +{ + if (xen_mapcache_enabled()) { + qemu_map_cache_unlock(addr); + } +} + int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) { RAMBlock *block; @@ -3546,6 +3553,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, cpu_physical_memory_set_dirty_flags( addr1, (0xff & ~CODE_DIRTY_FLAG)); } + qemu_ram_ptr_unlock(ptr); } } else { if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && @@ -3576,6 +3584,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, ptr = qemu_get_ram_ptr(pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK); memcpy(buf, ptr, l); + qemu_ram_ptr_unlock(ptr); } } len -= l; @@ -3616,6 +3625,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, /* ROM/RAM case */ ptr = qemu_get_ram_ptr(addr1); memcpy(ptr, buf, l); + qemu_ram_ptr_unlock(ptr); } len -= l; buf += l; diff --git a/xen-mapcache.c b/xen-mapcache.c index 3e1cca9..23a23f9 100644 --- a/xen-mapcache.c +++ b/xen-mapcache.c @@ -187,6 +187,40 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size, u return mapcache->last_address_vaddr + address_offset; } +void qemu_map_cache_unlock(void *buffer) +{ + MapCacheEntry *entry = NULL, *pentry = NULL; + MapCacheRev *reventry; + target_phys_addr_t paddr_index; + int found = 0; + + QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { + if (reventry->vaddr_req == buffer) { + paddr_index = reventry->paddr_index; + found = 1; + break; + } + } + if (!found) { + return; + } + QTAILQ_REMOVE(&mapcache->locked_entries, reventry, next); + qemu_free(reventry); + + entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; + while (entry && entry->paddr_index != paddr_index) { + pentry = entry; + entry = entry->next; + } + if (!entry) { + return; + } + entry->lock--; + if (entry->lock > 0) { + entry->lock--; + } +} + ram_addr_t qemu_ram_addr_from_mapcache(void *ptr) { MapCacheRev *reventry;