From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
qemu-devel@nongnu.org, pbonzini@redhat.com
Cc: peterx@redhat.com
Subject: [Qemu-devel] [PATCH] exec: Fix MAP_RAM for cached access
Date: Tue, 12 Jun 2018 21:05:25 +0200 [thread overview]
Message-ID: <1528830325-5501-1-git-send-email-eric.auger@redhat.com> (raw)
When an IOMMUMemoryRegion is in front of a virtio device,
address_space_cache_init does not set cache->ptr as the memory
region is not RAM. However when the device performs an access,
we end up in glue() which performs the translation and then uses
MAP_RAM. This latter uses the unset ptr and returns a wrong value
which leads to a SIGSEV in address_space_lduw_internal_cached_slow,
for instance. Let's test whether the cache->ptr is set, and in
the negative use the old macro definition. This fixes the
use cases featuring vIOMMU (Intel and ARM SMMU) which lead to
a SIGSEV.
Fixes: 48564041a73a (exec: reintroduce MemoryRegion caching)
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
I am not sure whether it doesn't break any targeted optimization
but at least it removes the SIGSEV.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
exec.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/exec.c b/exec.c
index f6645ed..46fbd25 100644
--- a/exec.c
+++ b/exec.c
@@ -3800,7 +3800,9 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,
#define SUFFIX _cached_slow
#define TRANSLATE(...) address_space_translate_cached(cache, __VA_ARGS__)
#define IS_DIRECT(mr, is_write) memory_access_is_direct(mr, is_write)
-#define MAP_RAM(mr, ofs) (cache->ptr + (ofs - cache->xlat))
+#define MAP_RAM(mr, ofs) (cache->ptr ? \
+ (cache->ptr + (ofs - cache->xlat)) : \
+ qemu_map_ram_ptr((mr)->ram_block, ofs))
#define INVALIDATE(mr, ofs, len) invalidate_and_set_dirty(mr, ofs, len)
#define RCU_READ_LOCK() ((void)0)
#define RCU_READ_UNLOCK() ((void)0)
--
2.5.5
next reply other threads:[~2018-06-12 19:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-12 19:05 Eric Auger [this message]
2018-06-13 3:15 ` [Qemu-devel] [PATCH] exec: Fix MAP_RAM for cached access Peter Xu
2018-06-13 6:31 ` Auger Eric
2018-06-13 6:53 ` Peter Xu
2018-06-13 9:56 ` Paolo Bonzini
2018-06-13 13:20 ` Auger Eric
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1528830325-5501-1-git-send-email-eric.auger@redhat.com \
--to=eric.auger@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).