From nobody Mon Feb 9 00:06:16 2026 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.zoho.com; dkim=fail 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 149124903631577.71952915984355; Mon, 3 Apr 2017 12:50:36 -0700 (PDT) Received: from localhost ([::1]:60937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv7zm-0001o2-PU for importer@patchew.org; Mon, 03 Apr 2017 15:50:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv7tl-0005Is-IY for qemu-devel@nongnu.org; Mon, 03 Apr 2017 15:44:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv7tk-0003CP-Fo for qemu-devel@nongnu.org; Mon, 03 Apr 2017 15:44:21 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:32829) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv7tk-0003Bl-6H for qemu-devel@nongnu.org; Mon, 03 Apr 2017 15:44:20 -0400 Received: by mail-wr0-x243.google.com with SMTP id u18so36375016wrc.0 for ; Mon, 03 Apr 2017 12:44:20 -0700 (PDT) Received: from donizetti.lan (94-39-184-28.adsl-ull.clienti.tiscali.it. [94.39.184.28]) by smtp.gmail.com with ESMTPSA id 18sm19436935wrt.52.2017.04.03.12.44.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 12:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=NJ/NyLn71vhzB6KOOrmaYscNoOa2gVD40aq72JYipBI=; b=nSqQC8tq/bjmrByuOSW3qvBJuKquA475RplLSJ5psXzJPG4CM59Ul4WrAksX5NCrbm t0Bfk817Xo18hYC5YretdLjlK3XzMZ14loBzK3OMdXtZgIyE4Fu4WHkDMrKl3eXYHHld jqcI0aOuXXCzYc9t5RZIi3jBLMuqtAtRgtYMej0zAp1u4P6yUHS3iLAJVstkGvk+NkNv 1W4Bi5CYez/IBvHBNkLBSWHOzMXZATKChWGezk/1vKuyBhR/bieSs5eA5b7xyjaglygC o5Eg4AdmcHtUO5gvMYsVG25nGJF3ZJlmXdvhX01zGt64qFxi+QxdmT3ig63rfdz0RkMx bP/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=NJ/NyLn71vhzB6KOOrmaYscNoOa2gVD40aq72JYipBI=; b=ftq+h8xakPJn5/RWDyNLS6O8SjbQL52WTawngXKXWnXce1mQYV4HeVfx4vzOaIOdM9 CbkPA1pL/+KumaQzrU3v+JMBHL2EPRgnuZVBlLnpklqX2PZMYLd2vsl32Bn9wLEtIruS TomZ1xIB3XUCpgGusqidNPdzcKcCG91vfnrKThi6X857eozczZr6bGivvk75DS8Smhc3 EPmpmy2S92ZUwB2RTGJOrIlxcDYzZJmvwZzbp5sTImfLJrxY+Vn3emmWNy2AYrptT92z PNbq82hCwT/qRurwWZSmI2iof8dEyXN5V3euaqQ80I2QXGn+eHuZzDQH0yEE3UP8xkiA +yIg== X-Gm-Message-State: AFeK/H2EwUq49ZK1IXZQ+obh25LVYwHDCnAdLoBelZuZlDch7wlMF/jKRjhH/vUIfSPp8w== X-Received: by 10.223.177.219 with SMTP id r27mr18332136wra.194.1491248658914; Mon, 03 Apr 2017 12:44:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 3 Apr 2017 21:44:08 +0200 Message-Id: <20170403194409.21276-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170403194409.21276-1-pbonzini@redhat.com> References: <20170403194409.21276-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PULL 5/6] exec: revert MemoryRegionCache 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" MemoryRegionCache did not know about virtio support for IOMMUs (because the two features were developed at the same time). Revert MemoryRegionCache to "normal" address_space_* operations for 2.9, as it is simpler than undoing the virtio patches. Signed-off-by: Paolo Bonzini --- exec.c | 64 +++++++++--------------------------------------= ---- include/exec/memory.h | 10 ++++---- 2 files changed, 15 insertions(+), 59 deletions(-) diff --git a/exec.c b/exec.c index e57a8a2..c97ef4a 100644 --- a/exec.c +++ b/exec.c @@ -3236,75 +3236,33 @@ int64_t address_space_cache_init(MemoryRegionCache = *cache, hwaddr len, bool is_write) { - hwaddr l, xlat; - MemoryRegion *mr; - void *ptr; - - assert(len > 0); - - l =3D len; - mr =3D address_space_translate(as, addr, &xlat, &l, is_write); - if (!memory_access_is_direct(mr, is_write)) { - return -EINVAL; - } - - l =3D address_space_extend_translation(as, addr, len, mr, xlat, l, is_= write); - ptr =3D qemu_ram_ptr_length(mr->ram_block, xlat, &l); - - cache->xlat =3D xlat; - cache->is_write =3D is_write; - cache->mr =3D mr; - cache->ptr =3D ptr; - cache->len =3D l; - memory_region_ref(cache->mr); - - return l; + cache->len =3D len; + cache->as =3D as; + cache->xlat =3D addr; + return len; } =20 void address_space_cache_invalidate(MemoryRegionCache *cache, hwaddr addr, hwaddr access_len) { - assert(cache->is_write); - invalidate_and_set_dirty(cache->mr, addr + cache->xlat, access_len); } =20 void address_space_cache_destroy(MemoryRegionCache *cache) { - if (!cache->mr) { - return; - } - - if (xen_enabled()) { - xen_invalidate_map_cache_entry(cache->ptr); - } - memory_region_unref(cache->mr); - cache->mr =3D NULL; -} - -/* Called from RCU critical section. This function has the same - * semantics as address_space_translate, but it only works on a - * predefined range of a MemoryRegion that was mapped with - * address_space_cache_init. - */ -static inline MemoryRegion *address_space_translate_cached( - MemoryRegionCache *cache, hwaddr addr, hwaddr *xlat, - hwaddr *plen, bool is_write) -{ - assert(addr < cache->len && *plen <=3D cache->len - addr); - *xlat =3D addr + cache->xlat; - return cache->mr; + cache->as =3D NULL; } =20 #define ARG1_DECL MemoryRegionCache *cache #define ARG1 cache #define SUFFIX _cached -#define TRANSLATE(...) address_space_translate_cached(cache, __V= A_ARGS__) +#define TRANSLATE(addr, ...) \ + address_space_translate(cache->as, cache->xlat + (addr), __VA_ARGS__) #define IS_DIRECT(mr, is_write) true -#define MAP_RAM(mr, ofs) (cache->ptr + (ofs - cache->xlat)) -#define INVALIDATE(mr, ofs, len) ((void)0) -#define RCU_READ_LOCK() ((void)0) -#define RCU_READ_UNLOCK() ((void)0) +#define MAP_RAM(mr, ofs) qemu_map_ram_ptr((mr)->ram_block, ofs) +#define INVALIDATE(mr, ofs, len) invalidate_and_set_dirty(mr, ofs, len) +#define RCU_READ_LOCK() rcu_read_lock() +#define RCU_READ_UNLOCK() rcu_read_unlock() #include "memory_ldst.inc.c" =20 /* virtual memory access for debug (includes writing to ROM) */ diff --git a/include/exec/memory.h b/include/exec/memory.h index e39256a..f20b191 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1426,13 +1426,11 @@ void stq_be_phys(AddressSpace *as, hwaddr addr, uin= t64_t val); =20 struct MemoryRegionCache { hwaddr xlat; - void *ptr; hwaddr len; - MemoryRegion *mr; - bool is_write; + AddressSpace *as; }; =20 -#define MEMORY_REGION_CACHE_INVALID ((MemoryRegionCache) { .mr =3D NULL }) +#define MEMORY_REGION_CACHE_INVALID ((MemoryRegionCache) { .as =3D NULL }) =20 /* address_space_cache_init: prepare for repeated access to a physical * memory region @@ -1688,7 +1686,7 @@ address_space_read_cached(MemoryRegionCache *cache, h= waddr addr, void *buf, int len) { assert(addr < cache->len && len <=3D cache->len - addr); - memcpy(buf, cache->ptr + addr, len); + address_space_read(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIFI= ED, buf, len); } =20 /** @@ -1704,7 +1702,7 @@ address_space_write_cached(MemoryRegionCache *cache, = hwaddr addr, void *buf, int len) { assert(addr < cache->len && len <=3D cache->len - addr); - memcpy(cache->ptr + addr, buf, len); + address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIF= IED, buf, len); } =20 #endif --=20 1.8.3.1