From nobody Sun May 19 00:42:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150108809922597.55336979578112; Wed, 26 Jul 2017 09:54:59 -0700 (PDT) Received: from localhost ([::1]:39228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daPaL-0002lw-Kh for importer@patchew.org; Wed, 26 Jul 2017 12:54:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daPZE-00021U-P9 for qemu-devel@nongnu.org; Wed, 26 Jul 2017 12:53:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1daPZ9-0003sR-SV for qemu-devel@nongnu.org; Wed, 26 Jul 2017 12:53:48 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:15902) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1daPZ9-0003rR-Ld for qemu-devel@nongnu.org; Wed, 26 Jul 2017 12:53:43 -0400 X-IronPort-AV: E=Sophos;i="5.40,416,1496102400"; d="scan'208";a="441440400" From: Anthony PERARD To: Date: Wed, 26 Jul 2017 17:53:26 +0100 Message-ID: <20170726165326.10327-1-anthony.perard@citrix.com> X-Mailer: git-send-email 2.13.3 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Subject: [Qemu-devel] [PATCH for-2.10] exec: Add lock parameter to qemu_ram_ptr_length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Paolo Bonzini , Richard Henderson , Stefano Stabellini , Peter Crosthwaite Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 04bf2526ce87f21b32c9acba1c5518708c243ad0 (exec: use qemu_ram_ptr_length to access guest ram) start using qemu_ram_ptr_length instead of qemu_map_ram_ptr, but when used with Xen, the behavior of both function is different. They both call xen_map_cache, but one with "lock", meaning the mapping of guest memory is never released implicitly, and the second one without, which means, mapping can be release later, when needed. In the context of address_space_{read,write}_continue, the ptr to those mapping should not be locked because it is used immediatly and never used again. The lock parameter make it explicit in which context qemu_ram_ptr_length is called. Signed-off-by: Anthony PERARD Reviewed-by: Stefano Stabellini --- exec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exec.c b/exec.c index 01ac21e3cd..63508cd35e 100644 --- a/exec.c +++ b/exec.c @@ -2203,7 +2203,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_= t addr) * Called within RCU critical section. */ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, - hwaddr *size) + hwaddr *size, bool lock) { RAMBlock *block =3D ram_block; if (*size =3D=3D 0) { @@ -2222,10 +2222,10 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_bloc= k, ram_addr_t addr, * In that case just map the requested area. */ if (block->offset =3D=3D 0) { - return xen_map_cache(addr, *size, 1, true); + return xen_map_cache(addr, *size, lock ? 1 : 0, lock); } =20 - block->host =3D xen_map_cache(block->offset, block->max_length, 1,= true); + block->host =3D xen_map_cache(block->offset, block->max_length, 1,= lock); } =20 return ramblock_ptr(block, addr); @@ -2947,7 +2947,7 @@ static MemTxResult address_space_write_continue(Addre= ssSpace *as, hwaddr addr, } } else { /* RAM case */ - ptr =3D qemu_ram_ptr_length(mr->ram_block, addr1, &l); + ptr =3D qemu_ram_ptr_length(mr->ram_block, addr1, &l, false); memcpy(ptr, buf, l); invalidate_and_set_dirty(mr, addr1, l); } @@ -3038,7 +3038,7 @@ MemTxResult address_space_read_continue(AddressSpace = *as, hwaddr addr, } } else { /* RAM case */ - ptr =3D qemu_ram_ptr_length(mr->ram_block, addr1, &l); + ptr =3D qemu_ram_ptr_length(mr->ram_block, addr1, &l, false); memcpy(buf, ptr, l); } =20 @@ -3349,7 +3349,7 @@ void *address_space_map(AddressSpace *as, =20 memory_region_ref(mr); *plen =3D address_space_extend_translation(as, addr, len, mr, xlat, l,= is_write); - ptr =3D qemu_ram_ptr_length(mr->ram_block, xlat, plen); + ptr =3D qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); rcu_read_unlock(); =20 return ptr; --=20 Anthony PERARD