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 size_t page_size; 50 /* dirty bitmap used during migration */ 51 unsigned long *bmap; 52 53 /* 54 * Below fields are only used by mapped-ram migration 55 */ 56 /* bitmap of pages present in the migration file */ 57 unsigned long *file_bmap; 58 /* 59 * offset in the file pages belonging to this ramblock are saved, 60 * used only during migration to a file. 61 */ 62 off_t bitmap_offset; 63 uint64_t pages_offset; 64 65 /* Bitmap of already received pages. Only used on destination side. */ 66 unsigned long *receivedmap; 67 68 /* 69 * bitmap to track already cleared dirty bitmap. When the bit is 70 * set, it means the corresponding memory chunk needs a log-clear. 71 * Set this up to non-NULL to enable the capability to postpone 72 * and split clearing of dirty bitmap on the remote node (e.g., 73 * KVM). The bitmap will be set only when doing global sync. 74 * 75 * It is only used during src side of ram migration, and it is 76 * protected by the global ram_state.bitmap_mutex. 77 * 78 * NOTE: this bitmap is different comparing to the other bitmaps 79 * in that one bit can represent multiple guest pages (which is 80 * decided by the `clear_bmap_shift' variable below). On 81 * destination side, this should always be NULL, and the variable 82 * `clear_bmap_shift' is meaningless. 83 */ 84 unsigned long *clear_bmap; 85 uint8_t clear_bmap_shift; 86 87 /* 88 * RAM block length that corresponds to the used_length on the migration 89 * source (after RAM block sizes were synchronized). Especially, after 90 * starting to run the guest, used_length and postcopy_length can differ. 91 * Used to register/unregister uffd handlers and as the size of the received 92 * bitmap. Receiving any page beyond this length will bail out, as it 93 * could not have been valid on the source. 94 */ 95 ram_addr_t postcopy_length; 96 }; 97 98 struct RamBlockAttributes { 99 Object parent; 100 101 RAMBlock *ram_block; 102 103 /* 1-setting of the bitmap represents ram is populated (shared) */ 104 unsigned bitmap_size; 105 unsigned long *bitmap; 106 107 QLIST_HEAD(, RamDiscardListener) rdl_list; 108 }; 109 110 RamBlockAttributes *ram_block_attributes_create(RAMBlock *ram_block); 111 void ram_block_attributes_destroy(RamBlockAttributes *attr); 112 int ram_block_attributes_state_change(RamBlockAttributes *attr, uint64_t offset, 113 uint64_t size, bool to_discard); 114 115 #endif 116