From patchwork Tue Oct 30 11:47:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 195466 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 71F752C00BA for ; Tue, 30 Oct 2012 22:53:59 +1100 (EST) Received: from localhost ([::1]:33695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTAJb-0001zB-Cv for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 07:49:03 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTAIr-0008Dl-Hf for qemu-devel@nongnu.org; Tue, 30 Oct 2012 07:48:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTAIl-0003wG-Cs for qemu-devel@nongnu.org; Tue, 30 Oct 2012 07:48:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTAIl-0003wC-5P for qemu-devel@nongnu.org; Tue, 30 Oct 2012 07:48:11 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9UBm8bc003551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 30 Oct 2012 07:48:08 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9UBlrJI028808; Tue, 30 Oct 2012 07:48:05 -0400 From: Avi Kivity To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2012 13:47:47 +0200 Message-Id: <1351597670-23031-5-git-send-email-avi@redhat.com> In-Reply-To: <1351597670-23031-1-git-send-email-avi@redhat.com> References: <1351597670-23031-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: "Michael S. Tsirkin" , Alexander Graf , Blue Swirl , Alex Williamson , Anthony Liguori Subject: [Qemu-devel] [PATCH v2 4/7] memory: provide a MemoryRegion for IOMMUs to log faults 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 Accesses which do not translate will hit the fault region, which can then log the access. Signed-off-by: Avi Kivity --- memory.c | 9 ++++++--- memory.h | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/memory.c b/memory.c index ba2d4a0..d6b46fd 100644 --- a/memory.c +++ b/memory.c @@ -778,7 +778,9 @@ static void memory_region_destructor_rom_device(MemoryRegion *mr) static void memory_region_destructor_iommu(MemoryRegion *mr) { address_space_destroy(mr->iommu_target_as); + address_space_destroy(mr->iommu_fault_as); g_free(mr->iommu_target_as); + g_free(mr->iommu_fault_as); } static bool memory_region_wrong_endianness(MemoryRegion *mr) @@ -1001,9 +1003,7 @@ static void memory_region_iommu_rw(MemoryRegion *iommu, hwaddr addr, xlat = (tlb.translated_addr & ~tlb.addr_mask) | (addr & tlb.addr_mask); address_space_rw(iommu->iommu_target_as, xlat, buf, clen, is_write); } else { - if (!is_write) { - memset(buf, 0xff, clen); - } + address_space_rw(iommu->iommu_fault_as, addr, buf, clen, is_write); } buf += clen; addr += clen; @@ -1068,6 +1068,7 @@ static void memory_region_iommu_write(void *opaque, hwaddr addr, void memory_region_init_iommu(MemoryRegion *mr, MemoryRegionIOMMUOps *ops, MemoryRegion *target, + MemoryRegion *fault, const char *name, uint64_t size) { @@ -1079,6 +1080,8 @@ void memory_region_init_iommu(MemoryRegion *mr, mr->destructor = memory_region_destructor_iommu; mr->iommu_target_as = g_new(AddressSpace, 1); address_space_init(mr->iommu_target_as, target); + mr->iommu_fault_as = g_new(AddressSpace, 1); + address_space_init(mr->iommu_fault_as, fault); } static uint64_t invalid_read(void *opaque, hwaddr addr, diff --git a/memory.h b/memory.h index 47362c9..6312197 100644 --- a/memory.h +++ b/memory.h @@ -162,6 +162,7 @@ struct MemoryRegion { unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; struct AddressSpace *iommu_target_as; + struct AddressSpace *iommu_fault_as; }; struct MemoryRegionPortio { @@ -361,12 +362,15 @@ void memory_region_init_reservation(MemoryRegion *mr, * @ops: a function that translates addresses into the @target region * @target: a #MemoryRegion that will be used to satisfy accesses to translated * addresses + * @fault: a #MemoryRegion for servicing failed translations; accessed with + * untranslated addresses * @name: used for debugging; not visible to the user or ABI * @size: size of the region. */ void memory_region_init_iommu(MemoryRegion *mr, MemoryRegionIOMMUOps *ops, MemoryRegion *target, + MemoryRegion *fault, const char *name, uint64_t size);