@@ -1149,6 +1149,20 @@ static void kvm_unpoison_all(void *param)
}
}
+bool kvm_hwpoisoned_page(RAMBlock *block, void *offset)
+{
+ HWPoisonPage *pg;
+ ram_addr_t ram_addr = (ram_addr_t) offset;
+
+ QLIST_FOREACH(pg, &hwpoison_page_list, list) {
+ if ((ram_addr >= pg->ram_addr) &&
+ (ram_addr - pg->ram_addr < block->page_size)) {
+ return true;
+ }
+ }
+ return false;
+}
+
void kvm_hwpoison_page_add(ram_addr_t ram_addr)
{
HWPoisonPage *page;
@@ -124,3 +124,8 @@ uint32_t kvm_dirty_ring_size(void)
{
return 0;
}
+
+bool kvm_hwpoisoned_page(RAMBlock *block, void *ram_addr)
+{
+ return false;
+}
@@ -539,4 +539,14 @@ bool kvm_arch_cpu_check_are_resettable(void);
bool kvm_dirty_ring_enabled(void);
uint32_t kvm_dirty_ring_size(void);
+
+/**
+ * kvm_hwpoisoned_page - indicate if the given page is poisoned
+ * @block: memory block of the given page
+ * @ram_addr: offset of the page
+ *
+ * Returns: true: page is poisoned
+ * false: page not yet poisoned
+ */
+bool kvm_hwpoisoned_page(RAMBlock *block, void *ram_addr);
#endif
@@ -35,6 +35,7 @@
#include "qemu/stats64.h"
#include "migration.h"
#include "options.h"
+#include "ram.h"
#include "io/channel-null.h"
#include "exec/target_page.h"
#include "exec/ramblock.h"
@@ -214,7 +215,7 @@ static CompressResult do_compress_ram_page(QEMUFile *f, z_stream *stream,
assert(qemu_file_buffer_empty(f));
- if (buffer_is_zero(p, page_size)) {
+ if (migration_buffer_is_zero(block, offset, page_size)) {
return RES_ZEROPAGE;
}
@@ -1107,6 +1107,26 @@ void ram_release_page(const char *rbname, uint64_t offset)
ram_discard_range(rbname, offset, TARGET_PAGE_SIZE);
}
+/**
+ * migration_buffer_is_zero: indicate if the page at the given
+ * location is entirely filled with zero, or is a poisoned page.
+ *
+ * @block: block that contains the page
+ * @offset: offset inside the block for the page
+ * @len: size to consider
+ */
+bool migration_buffer_is_zero(RAMBlock *block, ram_addr_t offset,
+ size_t len)
+{
+ uint8_t *p = block->host + offset;
+
+ if (kvm_enabled() && kvm_hwpoisoned_page(block, (void *)offset)) {
+ return true;
+ }
+
+ return buffer_is_zero(p, len);
+}
+
/**
* save_zero_page: send the zero page to the stream
*
@@ -1119,11 +1139,10 @@ void ram_release_page(const char *rbname, uint64_t offset)
static int save_zero_page(RAMState *rs, PageSearchStatus *pss,
ram_addr_t offset)
{
- uint8_t *p = pss->block->host + offset;
QEMUFile *file = pss->pss_channel;
int len = 0;
- if (!buffer_is_zero(p, TARGET_PAGE_SIZE)) {
+ if (!migration_buffer_is_zero(pss->block, offset, TARGET_PAGE_SIZE)) {
return 0;
}
@@ -1154,6 +1173,7 @@ static int save_zero_page(RAMState *rs, PageSearchStatus *pss,
* > 0 - number of pages written
*
* Return true if the pages has been saved, otherwise false is returned.
+ * TODO: hwpoison pages fail RDMA migration, should be handled.
*/
static bool control_save_page(PageSearchStatus *pss,
ram_addr_t offset, int *pages)
@@ -65,6 +65,8 @@ void ram_handle_zero(void *host, uint64_t size);
void ram_transferred_add(uint64_t bytes);
void ram_release_page(const char *rbname, uint64_t offset);
+bool migration_buffer_is_zero(RAMBlock *block, ram_addr_t offset, size_t len);
+
int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr);
bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_offset);
void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr);