kvm: Fix dirty tracking with large kernel page size
PATCH RESEND 1/1 kvm: Fix dirty tracking with large kernel page size
From: Ben Herrenschmidt <[email protected]>
If the kernel page size is larger than TARGET_PAGE_SIZE, which happens for example on ppc64 with kernels compiled for 64K pages, the dirty tracking doesn't work.
--- kvm-all.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
I've sent this a number of times now, the last couple without comment. It fixes a real bug, please apply.
kvm-all.c +4 -2
@@ -354,6 +354,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,unsigned long page_number, c;target_phys_addr_t addr, addr1;unsigned int len = ((section->size /TARGET_PAGE_SIZE ) +HOST_LONG_BITS -1 ) /HOST_LONG_BITS ; +unsigned long hpratio =getpagesize () /TARGET_PAGE_SIZE ;/* * bitmap-traveling is faster than memory-traveling (for addr...)
@@ -365,10 +366,11 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,do { j =ffsl (c) -1 ; c &= ~(1ul << j); - page_number = i *HOST_LONG_BITS + j; + page_number = (i *HOST_LONG_BITS + j) * hpratio; addr1 = page_number *TARGET_PAGE_SIZE ; addr = section->offset_within_region + addr1; -memory_region_set_dirty (section->mr, addr,TARGET_PAGE_SIZE ); +memory_region_set_dirty (section->mr, addr, +TARGET_PAGE_SIZE * hpratio); }while (c !=0 ); } }
Signature · 1 line
1.7.9.1
Quoted 5 lines · David Gibson
From: Ben Herrenschmidt <[email protected]>
If the kernel page size is larger than
TARGET_PAGE_SIZE, which happens for example on ppc64 with kernels compiled for 64K pages, the dirty tracking doesn't work.
BTW. That was discussed ages back on the list and we basically agreed it was the right fix for now, but for some reason the patch then went into a black hole :-)
Cheers,
Ben.
Quoted 38 lines
Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by David Gibson <[email protected]>--- kvm-all.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)I've sent this a number of times now, the last couple without comment. It fixes a real bug, please apply.
kvm-all.c +4
-2@@ -354,6 +354,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,unsigned long page_number, c;target_phys_addr_t addr, addr1;unsigned int len = ((section->size /TARGET_PAGE_SIZE ) +HOST_LONG_BITS -1 ) /HOST_LONG_BITS ; +unsigned long hpratio =getpagesize () /TARGET_PAGE_SIZE ;/* * bitmap-traveling is faster than memory-traveling (for addr...) @@ -365,10 +366,11 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,do { j =ffsl (c) -1 ; c &= ~(1ul << j); - page_number = i *HOST_LONG_BITS + j; + page_number = (i *HOST_LONG_BITS + j) * hpratio; addr1 = page_number *TARGET_PAGE_SIZE ; addr = section->offset_within_region + addr1; -memory_region_set_dirty (section->mr, addr,TARGET_PAGE_SIZE ); +memory_region_set_dirty (section->mr, addr, +TARGET_PAGE_SIZE * hpratio); }while (c !=0 ); } }
Quoted 34 lines · David Gibson
From: Ben Herrenschmidt <[email protected]>
If the kernel page size is larger than
TARGET_PAGE_SIZE, which happens for example on ppc64 with kernels compiled for 64K pages, the dirty tracking doesn't work.Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by David Gibson <[email protected]>--- kvm-all.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)I've sent this a number of times now, the last couple without comment. It fixes a real bug, please apply.
kvm-all.c +1
-0@@ -354,6 +354,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,unsigned long page_number, c;target_phys_addr_t addr, addr1;unsigned int len = ((section->size /TARGET_PAGE_SIZE ) +HOST_LONG_BITS -1 ) /HOST_LONG_BITS ; +unsigned long hpratio =getpagesize () /TARGET_PAGE_SIZE ;/* * bitmap-traveling is faster than memory-traveling (for addr...) @@ -365,10 +366,11 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, do { j = ffsl(c) - 1; c &= ~(1ul << j);
kvm-all.c static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, · line 376
Quoted 10 lines
kvm-all.c +3
-2- page_number = i *HOST_LONG_BITS + j; + page_number = (i *HOST_LONG_BITS + j) * hpratio; addr1 = page_number *TARGET_PAGE_SIZE ; addr = section->offset_within_region + addr1; -memory_region_set_dirty (section->mr, addr,TARGET_PAGE_SIZE ); +memory_region_set_dirty (section->mr, addr, +TARGET_PAGE_SIZE * hpratio); }while (c !=0 ); } }
Ack for this, but - as proposed earlier - please add an assert(TARGET_PAGE_SIZE <= getpagesize()) + comment to kvm_init().
Also, what's about coalesced MMIO? I see that the ring definition depends on [TARGET_]PAGE_SIZE. What page size does the power kernel use for it, and does it make a relevant difference for space?
Jan
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · David Gibson
From: Ben Herrenschmidt <[email protected]>
If the kernel page size is larger than
TARGET_PAGE_SIZE, which happens for example on ppc64 with kernels compiled for 64K pages, the dirty tracking doesn't work.Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by David Gibson <[email protected]>--- kvm-all.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)I've sent this a number of times now, the last couple without comment. It fixes a real bug, please apply.
kvm-all.c +2
-2@@ -354,6 +354,7 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,unsigned long page_number, c;target_phys_addr_t addr, addr1;unsigned int len = ((section->size /TARGET_PAGE_SIZE ) +HOST_LONG_BITS -1 ) /HOST_LONG_BITS ; +unsigned long hpratio =getpagesize () /TARGET_PAGE_SIZE ;/* * bitmap-traveling is faster than memory-traveling (for addr...) @@ -365,10 +366,11 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, do { j = ffsl(c) - 1; c &= ~(1ul << j); - page_number = i * HOST_LONG_BITS + j; + page_number = (i * HOST_LONG_BITS + j) * hpratio; addr1 = page_number * TARGET_PAGE_SIZE; addr = section->offset_within_region + addr1; - memory_region_set_dirty(section->mr, addr, TARGET_PAGE_SIZE);
Quoted 8 lines
kvm-all.c static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, · line 376
Quoted 5 lines
kvm-all.c +2
-0+memory_region_set_dirty (section->mr, addr, +TARGET_PAGE_SIZE * hpratio); }while (c !=0 ); } }Ack for this, but - as proposed earlier - please add an
assert(TARGET_PAGE_SIZE <= getpagesize())+ comment tokvm_init().
Ok.
Quoted 3 lines
Also, what's about coalesced MMIO? I see that the ring definition depends on [TARGET_]PAGE_SIZE. What page size does the power kernel use for it, and does it make a relevant difference for space?
Hr, so the HV variant of Power KVM doesn't do coalesced mmio. The PR variant does, but I don't know enough about it to easily answer that. If there's a bug there, it hasn't bitten yet, so how about we fix that another day.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 8 lines · David Gibson
Quoted 3 lines
Also, what's about coalesced MMIO? I see that the ring definition depends on [TARGET_]PAGE_SIZE. What page size does the power kernel use for it, and does it make a relevant difference for space?
Hr, so the HV variant of Power KVM doesn't do coalesced mmio. The PR variant does, but I don't know enough about it to easily answer that. If there's a bug there, it hasn't bitten yet, so how about we fix that another day.
Not really a smart approach, specifically now that we are aware of a potential problem here.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 5 lines · Jan Kiszka
Quoted 4 lines · David Gibson
Quoted 3 lines
Also, what's about coalesced MMIO? I see that the ring definition depends on [TARGET_]PAGE_SIZE. What page size does the power kernel use for it, and does it make a relevant difference for space?
Quoted 7 lines
Quoted 4 lines
Hr, so the HV variant of Power KVM doesn't do coalesced mmio. The PR variant does, but I don't know enough about it to easily answer that. If there's a bug there, it hasn't bitten yet, so how about we fix that another day.
Not really a smart approach, specifically now that we are aware of a potential problem here.
My point is that the fact that there may be another bug out there should sure as hell not hold up putting this bug fix in. The bugs may have similar causes and solutions, but they're entirely different code paths and the other fix will in no way replace or subsume this one.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 11 lines · David Gibson
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · David Gibson
Quoted 3 lines
Also, what's about coalesced MMIO? I see that the ring definition depends on [TARGET_]PAGE_SIZE. What page size does the power kernel use for it, and does it make a relevant difference for space?
Hr, so the HV variant of Power KVM doesn't do coalesced mmio. The PR variant does, but I don't know enough about it to easily answer that. If there's a bug there, it hasn't bitten yet, so how about we fix that another day.
Quoted 7 lines
Quoted 2 lines
Not really a smart approach, specifically now that we are aware of a potential problem here.
My point is that the fact that there may be another bug out there should sure as hell not hold up putting this bug fix in. The bugs may have similar causes and solutions, but they're entirely different code paths and the other fix will in no way replace or subsume this one.
I don't disagree. Maybe I over-interpreted your reply as "let's wait if this actually bites us".
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux