From nobody Fri Mar 29 14:59:35 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528830408513381.6136775431339; Tue, 12 Jun 2018 12:06:48 -0700 (PDT) Received: from localhost ([::1]:58029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSocs-0006xO-Cg for importer@patchew.org; Tue, 12 Jun 2018 15:06:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSobq-0006YH-E8 for qemu-devel@nongnu.org; Tue, 12 Jun 2018 15:05:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSobn-0001KH-3t for qemu-devel@nongnu.org; Tue, 12 Jun 2018 15:05:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45892 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSobn-0001Jf-0F for qemu-devel@nongnu.org; Tue, 12 Jun 2018 15:05:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93A064023337; Tue, 12 Jun 2018 19:05:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-69.ams2.redhat.com [10.36.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 599D62026DEF; Tue, 12 Jun 2018 19:05:33 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, pbonzini@redhat.com Date: Tue, 12 Jun 2018 21:05:25 +0200 Message-Id: <1528830325-5501-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 12 Jun 2018 19:05:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 12 Jun 2018 19:05:34 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] exec: Fix MAP_RAM for cached access 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: peterx@redhat.com 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 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- I am not sure whether it doesn't break any targeted optimization but at least it removes the SIGSEV. Signed-off-by: Eric Auger --- 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 *ca= che, hwaddr addr, #define SUFFIX _cached_slow #define TRANSLATE(...) address_space_translate_cached(cache, __V= A_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) --=20 2.5.5