* [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory
@ 2014-07-22 10:51 Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 1/2] exec: fix migration with devices that use address_space_rw Paolo Bonzini
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-07-22 10:51 UTC (permalink / raw)
To: qemu-devel
The following changes since commit fa666c10f2f3e15685ff88abd3bc433ddce012d6:
Revert "kvmclock: Ensure time in migration never goes backward" (2014-07-18 15:28:03 +0200)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to dc54e2525389e903cee2b847cf761b5d857f75cb:
kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL (2014-07-22 12:38:17 +0200)
----------------------------------------------------------------
One of the two pending migration fix, and a small KVM patch.
----------------------------------------------------------------
Chen Gang (1):
kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL
Paolo Bonzini (1):
exec: fix migration with devices that use address_space_rw
exec.c | 20 ++++----------------
include/exec/ram_addr.h | 11 +++++++++++
kvm-all.c | 5 +++--
3 files changed, 18 insertions(+), 18 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PULL 1/2] exec: fix migration with devices that use address_space_rw
2014-07-22 10:51 [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Paolo Bonzini
@ 2014-07-22 10:51 ` Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 2/2] kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL Paolo Bonzini
2014-07-22 12:14 ` [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Peter Maydell
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-07-22 10:51 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann, Dave Gilbert, Michael S. Tsirkin
Devices that use address_space_rw to write large areas to memory
(as opposed to address_space_map/unmap) were broken with respect
to migration since fe680d0 (exec: Limit translation limiting in
address_space_translate to xen, 2014-05-07). Such devices include
IDE CD-ROMs.
The reason is that invalidate_and_set_dirty (called by address_space_rw
but not address_space_map/unmap) was only setting the dirty bit for
the first page in the translation.
To fix this, introduce cpu_physical_memory_set_dirty_range_nocode that
is the same as cpu_physical_memory_set_dirty_range except it does not
muck with the DIRTY_MEMORY_CODE bitmap. This function can be used if
the caller invalidates translations with tb_invalidate_phys_page_range.
There is another difference between cpu_physical_memory_set_dirty_range
and cpu_physical_memory_set_dirty_flag; the former includes a call
to xen_modified_memory. This is handled separately in
invalidate_and_set_dirty, and is not needed in other callers of
cpu_physical_memory_set_dirty_range_nocode, so leave it alone.
Just one nit: now that invalidate_and_set_dirty takes care of handling
multiple pages, there is no need for address_space_unmap to wrap it
in a loop. In fact that loop would now be O(n^2).
Reported-by: Dave Gilbert <dgilbert@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
exec.c | 20 ++++----------------
include/exec/ram_addr.h | 11 +++++++++++
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/exec.c b/exec.c
index 5a2a25e..765bd94 100644
--- a/exec.c
+++ b/exec.c
@@ -1568,8 +1568,7 @@ static void notdirty_mem_write(void *opaque, hwaddr ram_addr,
default:
abort();
}
- cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_MIGRATION);
- cpu_physical_memory_set_dirty_flag(ram_addr, DIRTY_MEMORY_VGA);
+ cpu_physical_memory_set_dirty_range_nocode(ram_addr, size);
/* we remove the notdirty callback only if the code has been
flushed */
if (!cpu_physical_memory_is_clean(ram_addr)) {
@@ -1978,8 +1977,7 @@ static void invalidate_and_set_dirty(hwaddr addr,
/* invalidate code */
tb_invalidate_phys_page_range(addr, addr + length, 0);
/* set dirty bit */
- cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_VGA);
- cpu_physical_memory_set_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
+ cpu_physical_memory_set_dirty_range_nocode(addr, length);
}
xen_modified_memory(addr, length);
}
@@ -2335,15 +2333,7 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
mr = qemu_ram_addr_from_host(buffer, &addr1);
assert(mr != NULL);
if (is_write) {
- while (access_len) {
- unsigned l;
- l = TARGET_PAGE_SIZE;
- if (l > access_len)
- l = access_len;
- invalidate_and_set_dirty(addr1, l);
- addr1 += l;
- access_len -= l;
- }
+ invalidate_and_set_dirty(addr1, access_len);
}
if (xen_enabled()) {
xen_invalidate_map_cache_entry(buffer);
@@ -2581,9 +2571,7 @@ void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
/* invalidate code */
tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
/* set dirty bit */
- cpu_physical_memory_set_dirty_flag(addr1,
- DIRTY_MEMORY_MIGRATION);
- cpu_physical_memory_set_dirty_flag(addr1, DIRTY_MEMORY_VGA);
+ cpu_physical_memory_set_dirty_range_nocode(addr1, 4);
}
}
}
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index e9eb831..6593be1 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -71,6 +71,17 @@ static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
}
+static inline void cpu_physical_memory_set_dirty_range_nocode(ram_addr_t start,
+ ram_addr_t length)
+{
+ unsigned long end, page;
+
+ end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
+ page = start >> TARGET_PAGE_BITS;
+ bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION], page, end - page);
+ bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_VGA], page, end - page);
+}
+
static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
ram_addr_t length)
{
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PULL 2/2] kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL
2014-07-22 10:51 [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 1/2] exec: fix migration with devices that use address_space_rw Paolo Bonzini
@ 2014-07-22 10:51 ` Paolo Bonzini
2014-07-22 12:14 ` [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Peter Maydell
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-07-22 10:51 UTC (permalink / raw)
To: qemu-devel; +Cc: Chen Gang, qemu-stable
From: Chen Gang <gang.chen.5i5j@gmail.com>
If kvm_arch_remove_sw_breakpoint() in CPU_FOREACH() always be fail, it
will let 'cpu' NULL. And the next kvm_arch_remove_sw_breakpoint() in
QTAILQ_FOREACH_SAFE() will get NULL parameter for 'cpu'.
And kvm_arch_remove_sw_breakpoint() can assumes 'cpu' must never be NULL,
so need define additional temporary variable for 'cpu' to avoid the case.
Cc: qemu-stable@nongnu.org
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
kvm-all.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index 3ae30ee..1402f4f 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2077,12 +2077,13 @@ void kvm_remove_all_breakpoints(CPUState *cpu)
{
struct kvm_sw_breakpoint *bp, *next;
KVMState *s = cpu->kvm_state;
+ CPUState *tmpcpu;
QTAILQ_FOREACH_SAFE(bp, &s->kvm_sw_breakpoints, entry, next) {
if (kvm_arch_remove_sw_breakpoint(cpu, bp) != 0) {
/* Try harder to find a CPU that currently sees the breakpoint. */
- CPU_FOREACH(cpu) {
- if (kvm_arch_remove_sw_breakpoint(cpu, bp) == 0) {
+ CPU_FOREACH(tmpcpu) {
+ if (kvm_arch_remove_sw_breakpoint(tmpcpu, bp) == 0) {
break;
}
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory
2014-07-22 10:51 [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 1/2] exec: fix migration with devices that use address_space_rw Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 2/2] kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL Paolo Bonzini
@ 2014-07-22 12:14 ` Peter Maydell
2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2014-07-22 12:14 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: QEMU Developers
On 22 July 2014 11:51, Paolo Bonzini <pbonzini@redhat.com> wrote:
> The following changes since commit fa666c10f2f3e15685ff88abd3bc433ddce012d6:
>
> Revert "kvmclock: Ensure time in migration never goes backward" (2014-07-18 15:28:03 +0200)
>
> are available in the git repository at:
>
> git://github.com/bonzini/qemu.git tags/for-upstream
>
> for you to fetch changes up to dc54e2525389e903cee2b847cf761b5d857f75cb:
>
> kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL (2014-07-22 12:38:17 +0200)
>
> ----------------------------------------------------------------
> One of the two pending migration fix, and a small KVM patch.
>
> ----------------------------------------------------------------
> Chen Gang (1):
> kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL
>
> Paolo Bonzini (1):
> exec: fix migration with devices that use address_space_rw
Applied, thanks.
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-22 12:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 10:51 [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 1/2] exec: fix migration with devices that use address_space_rw Paolo Bonzini
2014-07-22 10:51 ` [Qemu-devel] [PULL 2/2] kvm-all: Use 'tmpcpu' instead of 'cpu' in sub-looping to avoid 'cpu' be NULL Paolo Bonzini
2014-07-22 12:14 ` [Qemu-devel] [PULL for-2.1 0/2] Two fixes for KVM and memory Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).