1 /* 2 * Declarations for cpu physical memory functions 3 * 4 * Copyright 2011 Red Hat, Inc. and/or its affiliates 5 * 6 * Authors: 7 * Avi Kivity <avi@redhat.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or 10 * later. See the COPYING file in the top-level directory. 11 * 12 */ 13 14 /* 15 * This header is for use by exec.c and memory.c ONLY. Do not include it. 16 * The functions declared here will be removed soon. 17 */ 18 19 #ifndef SYSTEM_RAMBLOCK_H 20 #define SYSTEM_RAMBLOCK_H 21 22 #include "exec/cpu-common.h" 23 #include "qemu/rcu.h" 24 #include "exec/ramlist.h" 25 #include "system/hostmem.h" 26 27 #define TYPE_RAM_BLOCK_ATTRIBUTES "ram-block-attributes" 28 OBJECT_DECLARE_SIMPLE_TYPE(RamBlockAttributes, RAM_BLOCK_ATTRIBUTES) 29 30 struct RAMBlock { 31 struct rcu_head rcu; 32 struct MemoryRegion *mr; 33 uint8_t *host; 34 uint8_t *colo_cache; /* For colo, VM's ram cache */ 35 ram_addr_t offset; 36 ram_addr_t used_length; 37 ram_addr_t max_length; 38 void (*resized)(const char*, uint64_t length, void *host); 39 uint32_t flags; 40 /* Protected by the BQL. */ 41 char idstr[256]; 42 /* RCU-enabled, writes protected by the ramlist lock */ 43 QLIST_ENTRY(RAMBlock) next; 44 QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers; 45 Error *cpr_blocker; 46 int fd; 47 uint64_t fd_offset; 48 int guest_memfd; 49 RamBlockAttributes *attributes; 50 size_t page_size; 51 /* dirty bitmap used during migration */ 52 unsigned long *bmap; 53 54 /* 55 * Below fields are only used by mapped-ram migration 56 */ 57 /* bitmap of pages present in the migration file */ 58 unsigned long *file_bmap; 59 /* 60 * offset in the file pages belonging to this ramblock are saved, 61 * used only during migration to a file. 62 */ 63 off_t bitmap_offset; 64 uint64_t pages_offset; 65 66 /* Bitmap of already received pages. Only used on destination side. */ 67 unsigned long *receivedmap; 68 69 /* 70 * bitmap to track already cleared dirty bitmap. When the bit is 71 * set, it means the corresponding memory chunk needs a log-clear. 72 * Set this up to non-NULL to enable the capability to postpone 73 * and split clearing of dirty bitmap on the remote node (e.g., 74 * KVM). The bitmap will be set only when doing global sync. 75 * 76 * It is only used during src side of ram migration, and it is 77 * protected by the global ram_state.bitmap_mutex. 78 * 79 * NOTE: this bitmap is different comparing to the other bitmaps 80 * in that one bit can represent multiple guest pages (which is 81 * decided by the `clear_bmap_shift' variable below). On 82 * destination side, this should always be NULL, and the variable 83 * `clear_bmap_shift' is meaningless. 84 */ 85 unsigned long *clear_bmap; 86 uint8_t clear_bmap_shift; 87 88 /* 89 * RAM block length that corresponds to the used_length on the migration 90 * source (after RAM block sizes were synchronized). Especially, after 91 * starting to run the guest, used_length and postcopy_length can differ. 92 * Used to register/unregister uffd handlers and as the size of the received 93 * bitmap. Receiving any page beyond this length will bail out, as it 94 * could not have been valid on the source. 95 */ 96 ram_addr_t postcopy_length; 97 }; 98 99 struct RamBlockAttributes { 100 Object parent; 101 102 RAMBlock *ram_block; 103 104 /* 1-setting of the bitmap represents ram is populated (shared) */ 105 unsigned bitmap_size; 106 unsigned long *bitmap; 107 108 QLIST_HEAD(, RamDiscardListener) rdl_list; 109 }; 110 111 RamBlockAttributes *ram_block_attributes_create(RAMBlock *ram_block); 112 void ram_block_attributes_destroy(RamBlockAttributes *attr); 113 int ram_block_attributes_state_change(RamBlockAttributes *attr, uint64_t offset, 114 uint64_t size, bool to_discard); 115 116 #endif 117