[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 15/22] memory: add address_space_access_valid
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 15/22] memory: add address_space_access_valid |
Date: |
Fri, 24 May 2013 19:05:50 +0200 |
The old-style IOMMU lets you check whether an access is valid in a
given DMAContext. There is no equivalent for AddressSpace in the
memory API, but we can implement it easily.
Signed-off-by: Paolo Bonzini <address@hidden>
---
dma-helpers.c | 5 +++++
exec.c | 21 +++++++++++++++++++++
include/exec/memory.h | 15 +++++++++++++++
include/sysemu/dma.h | 3 ++-
4 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/dma-helpers.c b/dma-helpers.c
index 272632f..2e298b6 100644
--- a/dma-helpers.c
+++ b/dma-helpers.c
@@ -298,6 +298,11 @@ bool iommu_dma_memory_valid(DMAContext *dma, dma_addr_t
addr, dma_addr_t len,
plen = len;
}
+ if (!address_space_access_valid(dma->as, paddr, len,
+ dir == DMA_DIRECTION_FROM_DEVICE)) {
+ return false;
+ }
+
len -= plen;
addr += plen;
}
diff --git a/exec.c b/exec.c
index 8107530..17a3292 100644
--- a/exec.c
+++ b/exec.c
@@ -2064,6 +2064,27 @@ static void cpu_notify_map_clients(void)
}
}
+bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool
is_write)
+{
+ MemoryRegionSection *section;
+ hwaddr l, xlat;
+
+ while (len > 0) {
+ l = len;
+ section = address_space_translate(as, addr, &xlat, &l, is_write);
+ if (!memory_access_is_direct(section->mr, is_write)) {
+ l = memory_access_size(l, addr);
+ if (!memory_region_access_valid(section->mr, xlat, l, is_write)) {
+ return false;
+ }
+ }
+
+ len -= l;
+ addr += l;
+ }
+ return true;
+}
+
/* Map a physical memory region into a host virtual address.
* May map a subset of the requested range, given by and returned in *plen.
* May return NULL if resources needed to perform the mapping are exhausted.
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 688d3f0..81e0e41 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -866,6 +866,21 @@ MemoryRegionSection *address_space_translate(AddressSpace
*as, hwaddr addr,
hwaddr *xlat, hwaddr *len,
bool is_write);
+/* address_space_access_valid: check for validity of accessing an address
+ * space range
+ *
+ * Check whether memory is assigned to the given address space range.
+ *
+ * For now, addr and len should be aligned to a page size. This limitation
+ * will be lifted in the future.
+ *
+ * @as: #AddressSpace to be accessed
+ * @addr: address within that address space
+ * @len: length of the area to be checked
+ * @is_write: indicates the transfer direction
+ */
+bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool
is_write);
+
/* address_space_map: map a physical memory region into a host virtual address
*
* May map a subset of the requested range, given by and returned in @plen.
diff --git a/include/sysemu/dma.h b/include/sysemu/dma.h
index a52c93a..02e0dcd 100644
--- a/include/sysemu/dma.h
+++ b/include/sysemu/dma.h
@@ -113,7 +113,8 @@ static inline bool dma_memory_valid(DMAContext *dma,
DMADirection dir)
{
if (!dma_has_iommu(dma)) {
- return true;
+ return address_space_access_valid(dma->as, addr, len,
+ dir == DMA_DIRECTION_FROM_DEVICE);
} else {
return iommu_dma_memory_valid(dma, addr, len, dir);
}
--
1.8.1.4
- [Qemu-devel] [PATCH 11/22] exec: introduce memory_access_is_direct, (continued)
- [Qemu-devel] [PATCH 11/22] exec: introduce memory_access_is_direct, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 12/22] exec: introduce memory_access_size, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 10/22] exec: expect mr->ops to be initialized for ROM, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 13/22] memory: export memory_region_access_valid to exec.c, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 14/22] exec: implement .valid.accepts for subpages, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 20/22] exec: just use io_mem_read/io_mem_write for 8-byte I/O accesses, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 21/22] memory: propagate errors on I/O dispatch, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 22/22] memory: add return value to address_space_rw/read/write, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 18/22] memory: split accesses even when the old MMIO callbacks are used, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 19/22] memory: correctly handle endian-swapped 64-bit accesses, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 15/22] memory: add address_space_access_valid,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 17/22] memory: add big endian support to access_with_adjusted_size, Paolo Bonzini, 2013/05/24
- [Qemu-devel] [PATCH 16/22] memory: accept mismatching sizes in memory_region_access_valid, Paolo Bonzini, 2013/05/24
- Re: [Qemu-devel] [PATCH 00/22] Memory/IOMMU patches, part 2: unassigned access detection, Richard Henderson, 2013/05/24