diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-11-20 18:08:27 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-11-21 12:09:25 +0000 |
commit | 27266271977c5a30f2f7d493e042be1897827bdd (patch) | |
tree | 868a090274abc1c4419b8f6fba94f46d84920b58 /include | |
parent | a61d343986c13d9ea607f42e5dadea3261c14ba5 (diff) |
exec.c: Factor out before/after actions for notdirty memory writes
The function notdirty_mem_write() has a sequence of actions
it has to do before and after the actual business of writing
data to host RAM to ensure that dirty flags are correctly
updated and we flush any TCG translations for the region.
We need to do this also in other places that write directly
to host RAM, most notably the TCG atomic helper functions.
Pull out the before and after pieces into their own functions.
We use an API where the prepare function stashes the various
bits of information about the write into a struct for the
complete function to use, because in the calls for the atomic
helpers the place where the complete function will be called
doesn't have the information to hand.
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1511201308-23580-2-git-send-email-peter.maydell@linaro.org
Diffstat (limited to 'include')
-rw-r--r-- | include/exec/memory-internal.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 647e9bd5c4..98d82964cc 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -39,5 +39,67 @@ void mtree_print_dispatch(fprintf_function mon, void *f, struct AddressSpaceDispatch *d, MemoryRegion *root); +/* Opaque struct for passing info from memory_notdirty_write_prepare() + * to memory_notdirty_write_complete(). Callers should treat all fields + * as private, with the exception of @active. + * + * @active is a field which is not touched by either the prepare or + * complete functions, but which the caller can use if it wishes to + * track whether it has called prepare for this struct and so needs + * to later call the complete function. + */ +typedef struct { + CPUState *cpu; + ram_addr_t ram_addr; + vaddr mem_vaddr; + unsigned size; + bool locked; + bool active; +} NotDirtyInfo; + +/** + * memory_notdirty_write_prepare: call before writing to non-dirty memory + * @ndi: pointer to opaque NotDirtyInfo struct + * @cpu: CPU doing the write + * @mem_vaddr: virtual address of write + * @ram_addr: the ram address of the write + * @size: size of write in bytes + * + * Any code which writes to the host memory corresponding to + * guest RAM which has been marked as NOTDIRTY must wrap those + * writes in calls to memory_notdirty_write_prepare() and + * memory_notdirty_write_complete(): + * + * NotDirtyInfo ndi; + * memory_notdirty_write_prepare(&ndi, ....); + * ... perform write here ... + * memory_notdirty_write_complete(&ndi); + * + * These calls will ensure that we flush any TCG translated code for + * the memory being written, update the dirty bits and (if possible) + * remove the slowpath callback for writing to the memory. + * + * This must only be called if we are using TCG; it will assert otherwise. + * + * We may take a lock in the prepare call, so callers must ensure that + * they don't exit (via longjump or otherwise) without calling complete. + * + * This call must only be made inside an RCU critical section. + * (Note that while we're executing a TCG TB we're always in an + * RCU critical section, which is likely to be the case for callers + * of these functions.) + */ +void memory_notdirty_write_prepare(NotDirtyInfo *ndi, + CPUState *cpu, + vaddr mem_vaddr, + ram_addr_t ram_addr, + unsigned size); +/** + * memory_notdirty_write_complete: finish write to non-dirty memory + * @ndi: pointer to the opaque NotDirtyInfo struct which was initialized + * by memory_not_dirty_write_prepare(). + */ +void memory_notdirty_write_complete(NotDirtyInfo *ndi); + #endif #endif |