address_space_read: address_space_to_flatview needs RCU lock
address_space_read is calling address_space_to_flatview but it can be called outside the RCU lock. To fix it, push the rcu_read_lock/unlock pair up from flatview_read_full to address_space_read's constant size fast path and address_space_read_full. Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
4c6ebbb364
commit
b2a44fcad7
38
exec.c
38
exec.c
|
@ -2616,6 +2616,8 @@ static const MemoryRegionOps watch_mem_ops = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static MemTxResult flatview_read(FlatView *fv, hwaddr addr,
|
||||||
|
MemTxAttrs attrs, uint8_t *buf, int len);
|
||||||
static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs,
|
static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs,
|
||||||
const uint8_t *buf, int len);
|
const uint8_t *buf, int len);
|
||||||
static bool flatview_access_valid(FlatView *fv, hwaddr addr, int len,
|
static bool flatview_access_valid(FlatView *fv, hwaddr addr, int len,
|
||||||
|
@ -3165,24 +3167,18 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemTxResult flatview_read_full(FlatView *fv, hwaddr addr,
|
/* Called from RCU critical section. */
|
||||||
MemTxAttrs attrs, uint8_t *buf, int len)
|
static MemTxResult flatview_read(FlatView *fv, hwaddr addr,
|
||||||
|
MemTxAttrs attrs, uint8_t *buf, int len)
|
||||||
{
|
{
|
||||||
hwaddr l;
|
hwaddr l;
|
||||||
hwaddr addr1;
|
hwaddr addr1;
|
||||||
MemoryRegion *mr;
|
MemoryRegion *mr;
|
||||||
MemTxResult result = MEMTX_OK;
|
|
||||||
|
|
||||||
if (len > 0) {
|
l = len;
|
||||||
rcu_read_lock();
|
mr = flatview_translate(fv, addr, &addr1, &l, false);
|
||||||
l = len;
|
return flatview_read_continue(fv, addr, attrs, buf, len,
|
||||||
mr = flatview_translate(fv, addr, &addr1, &l, false);
|
addr1, l, mr);
|
||||||
result = flatview_read_continue(fv, addr, attrs, buf, len,
|
|
||||||
addr1, l, mr);
|
|
||||||
rcu_read_unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static MemTxResult flatview_rw(FlatView *fv, hwaddr addr, MemTxAttrs attrs,
|
static MemTxResult flatview_rw(FlatView *fv, hwaddr addr, MemTxAttrs attrs,
|
||||||
|
@ -3203,6 +3199,22 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr addr,
|
||||||
addr, attrs, buf, len, is_write);
|
addr, attrs, buf, len, is_write);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,
|
||||||
|
MemTxAttrs attrs, uint8_t *buf, int len)
|
||||||
|
{
|
||||||
|
MemTxResult result = MEMTX_OK;
|
||||||
|
FlatView *fv;
|
||||||
|
|
||||||
|
if (len > 0) {
|
||||||
|
rcu_read_lock();
|
||||||
|
fv = address_space_to_flatview(as);
|
||||||
|
result = flatview_read(fv, addr, attrs, buf, len);
|
||||||
|
rcu_read_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
|
MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
|
||||||
MemTxAttrs attrs,
|
MemTxAttrs attrs,
|
||||||
const uint8_t *buf, int len)
|
const uint8_t *buf, int len)
|
||||||
|
|
|
@ -1917,13 +1917,12 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
|
||||||
|
|
||||||
|
|
||||||
/* Internal functions, part of the implementation of address_space_read. */
|
/* Internal functions, part of the implementation of address_space_read. */
|
||||||
|
MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr,
|
||||||
|
MemTxAttrs attrs, uint8_t *buf, int len);
|
||||||
MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
|
MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
|
||||||
MemTxAttrs attrs, uint8_t *buf,
|
MemTxAttrs attrs, uint8_t *buf,
|
||||||
int len, hwaddr addr1, hwaddr l,
|
int len, hwaddr addr1, hwaddr l,
|
||||||
MemoryRegion *mr);
|
MemoryRegion *mr);
|
||||||
|
|
||||||
MemTxResult flatview_read_full(FlatView *fv, hwaddr addr,
|
|
||||||
MemTxAttrs attrs, uint8_t *buf, int len);
|
|
||||||
void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
|
void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
|
||||||
|
|
||||||
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
|
static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
|
||||||
|
@ -1942,25 +1941,28 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write)
|
||||||
*
|
*
|
||||||
* Return a MemTxResult indicating whether the operation succeeded
|
* Return a MemTxResult indicating whether the operation succeeded
|
||||||
* or failed (eg unassigned memory, device rejected the transaction,
|
* or failed (eg unassigned memory, device rejected the transaction,
|
||||||
* IOMMU fault).
|
* IOMMU fault). Called within RCU critical section.
|
||||||
*
|
*
|
||||||
* @fv: #FlatView to be accessed
|
* @as: #AddressSpace to be accessed
|
||||||
* @addr: address within that address space
|
* @addr: address within that address space
|
||||||
* @attrs: memory transaction attributes
|
* @attrs: memory transaction attributes
|
||||||
* @buf: buffer with the data transferred
|
* @buf: buffer with the data transferred
|
||||||
*/
|
*/
|
||||||
static inline __attribute__((__always_inline__))
|
static inline __attribute__((__always_inline__))
|
||||||
MemTxResult flatview_read(FlatView *fv, hwaddr addr, MemTxAttrs attrs,
|
MemTxResult address_space_read(AddressSpace *as, hwaddr addr,
|
||||||
uint8_t *buf, int len)
|
MemTxAttrs attrs, uint8_t *buf,
|
||||||
|
int len)
|
||||||
{
|
{
|
||||||
MemTxResult result = MEMTX_OK;
|
MemTxResult result = MEMTX_OK;
|
||||||
hwaddr l, addr1;
|
hwaddr l, addr1;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
MemoryRegion *mr;
|
MemoryRegion *mr;
|
||||||
|
FlatView *fv;
|
||||||
|
|
||||||
if (__builtin_constant_p(len)) {
|
if (__builtin_constant_p(len)) {
|
||||||
if (len) {
|
if (len) {
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
fv = address_space_to_flatview(as);
|
||||||
l = len;
|
l = len;
|
||||||
mr = flatview_translate(fv, addr, &addr1, &l, false);
|
mr = flatview_translate(fv, addr, &addr1, &l, false);
|
||||||
if (len == l && memory_access_is_direct(mr, false)) {
|
if (len == l && memory_access_is_direct(mr, false)) {
|
||||||
|
@ -1973,18 +1975,11 @@ MemTxResult flatview_read(FlatView *fv, hwaddr addr, MemTxAttrs attrs,
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = flatview_read_full(fv, addr, attrs, buf, len);
|
result = address_space_read_full(as, addr, attrs, buf, len);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline MemTxResult address_space_read(AddressSpace *as, hwaddr addr,
|
|
||||||
MemTxAttrs attrs, uint8_t *buf,
|
|
||||||
int len)
|
|
||||||
{
|
|
||||||
return flatview_read(address_space_to_flatview(as), addr, attrs, buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* address_space_read_cached: read from a cached RAM region
|
* address_space_read_cached: read from a cached RAM region
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue