Revision 51644ab7

b/dma-helpers.c
298 298
            plen = len;
299 299
        }
300 300

  
301
        if (!address_space_access_valid(dma->as, paddr, len,
302
                                        dir == DMA_DIRECTION_FROM_DEVICE)) {
303
            return false;
304
        }
305

  
301 306
        len -= plen;
302 307
        addr += plen;
303 308
    }
b/exec.c
2067 2067
    }
2068 2068
}
2069 2069

  
2070
bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write)
2071
{
2072
    MemoryRegionSection *section;
2073
    hwaddr l, xlat;
2074

  
2075
    while (len > 0) {
2076
        l = len;
2077
        section = address_space_translate(as, addr, &xlat, &l, is_write);
2078
        if (!memory_access_is_direct(section->mr, is_write)) {
2079
            l = memory_access_size(l, addr);
2080
            if (!memory_region_access_valid(section->mr, xlat, l, is_write)) {
2081
                return false;
2082
            }
2083
        }
2084

  
2085
        len -= l;
2086
        addr += l;
2087
    }
2088
    return true;
2089
}
2090

  
2070 2091
/* Map a physical memory region into a host virtual address.
2071 2092
 * May map a subset of the requested range, given by and returned in *plen.
2072 2093
 * May return NULL if resources needed to perform the mapping are exhausted.
b/include/exec/memory.h
866 866
                                             hwaddr *xlat, hwaddr *len,
867 867
                                             bool is_write);
868 868

  
869
/* address_space_access_valid: check for validity of accessing an address
870
 * space range
871
 *
872
 * Check whether memory is assigned to the given address space range.
873
 *
874
 * For now, addr and len should be aligned to a page size.  This limitation
875
 * will be lifted in the future.
876
 *
877
 * @as: #AddressSpace to be accessed
878
 * @addr: address within that address space
879
 * @len: length of the area to be checked
880
 * @is_write: indicates the transfer direction
881
 */
882
bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
883

  
869 884
/* address_space_map: map a physical memory region into a host virtual address
870 885
 *
871 886
 * May map a subset of the requested range, given by and returned in @plen.
b/include/sysemu/dma.h
113 113
                                    DMADirection dir)
114 114
{
115 115
    if (!dma_has_iommu(dma)) {
116
        return true;
116
        return address_space_access_valid(dma->as, addr, len,
117
                                          dir == DMA_DIRECTION_FROM_DEVICE);
117 118
    } else {
118 119
        return iommu_dma_memory_valid(dma, addr, len, dir);
119 120
    }

Also available in: Unified diff