From patchwork Fri Jun 19 07:45:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 486604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 15293140295 for ; Fri, 19 Jun 2015 17:50:19 +1000 (AEST) Received: from localhost ([::1]:56700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5r45-0005yY-AW for incoming@patchwork.ozlabs.org; Fri, 19 Jun 2015 03:50:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5r02-00066o-KC for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:46:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5r00-0002Rk-Pz for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:46:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5r00-0002R9-Gx for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:46:04 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 23BDFC6A06 for ; Fri, 19 Jun 2015 07:46:04 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5J7jbhQ019014 for ; Fri, 19 Jun 2015 03:46:03 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 19 Jun 2015 09:45:35 +0200 Message-Id: <1434699936-4433-15-git-send-email-pbonzini@redhat.com> In-Reply-To: <1434699936-4433-1-git-send-email-pbonzini@redhat.com> References: <1434699936-4433-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/15] exec: do not clamp accesses to MMIO regions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is common for MMIO registers to overlap, for example a 4 byte register at 0xcf8 (totally random choice... :)) and a 1 byte register at 0xcf9. If these registers are implemented via separate MemoryRegions, it is wrong to clamp the accesses as the value written would be truncated. Hence for these regions the effects of commit 23820db (exec: Respect as_translate_internal length clamp, 2015-03-16, previously applied as commit c3c1bb99) must be skipped. Tested-by: Hervé Poussineau Tested-by: Mark Cave-Ayland Signed-off-by: Paolo Bonzini --- exec.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 76bfc4a..d00e017 100644 --- a/exec.c +++ b/exec.c @@ -341,6 +341,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x hwaddr *plen, bool resolve_subpage) { MemoryRegionSection *section; + MemoryRegion *mr; Int128 diff; section = address_space_lookup_region(d, addr, resolve_subpage); @@ -350,8 +351,11 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x /* Compute offset within MemoryRegion */ *xlat = addr + section->offset_within_region; - diff = int128_sub(section->mr->size, int128_make64(addr)); - *plen = int128_get64(int128_min(diff, int128_make64(*plen))); + mr = section->mr; + if (memory_region_is_ram(mr)) { + diff = int128_sub(mr->size, int128_make64(addr)); + *plen = int128_get64(int128_min(diff, int128_make64(*plen))); + } return section; }