xref: /qemu/include/system/ramblock.h (revision 548a01650c9be153b352406cd4afb86cb350788e)
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 
26 struct RAMBlock {
27     struct rcu_head rcu;
28     struct MemoryRegion *mr;
29     uint8_t *host;
30     uint8_t *colo_cache; /* For colo, VM's ram cache */
31     ram_addr_t offset;
32     ram_addr_t used_length;
33     ram_addr_t max_length;
34     void (*resized)(const char*, uint64_t length, void *host);
35     uint32_t flags;
36     /* Protected by the BQL.  */
37     char idstr[256];
38     /* RCU-enabled, writes protected by the ramlist lock */
39     QLIST_ENTRY(RAMBlock) next;
40     QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers;
41     Error *cpr_blocker;
42     int fd;
43     uint64_t fd_offset;
44     int guest_memfd;
45     size_t page_size;
46     /* dirty bitmap used during migration */
47     unsigned long *bmap;
48 
49     /*
50      * Below fields are only used by mapped-ram migration
51      */
52     /* bitmap of pages present in the migration file */
53     unsigned long *file_bmap;
54     /*
55      * offset in the file pages belonging to this ramblock are saved,
56      * used only during migration to a file.
57      */
58     off_t bitmap_offset;
59     uint64_t pages_offset;
60 
61     /* Bitmap of already received pages.  Only used on destination side. */
62     unsigned long *receivedmap;
63 
64     /*
65      * bitmap to track already cleared dirty bitmap.  When the bit is
66      * set, it means the corresponding memory chunk needs a log-clear.
67      * Set this up to non-NULL to enable the capability to postpone
68      * and split clearing of dirty bitmap on the remote node (e.g.,
69      * KVM).  The bitmap will be set only when doing global sync.
70      *
71      * It is only used during src side of ram migration, and it is
72      * protected by the global ram_state.bitmap_mutex.
73      *
74      * NOTE: this bitmap is different comparing to the other bitmaps
75      * in that one bit can represent multiple guest pages (which is
76      * decided by the `clear_bmap_shift' variable below).  On
77      * destination side, this should always be NULL, and the variable
78      * `clear_bmap_shift' is meaningless.
79      */
80     unsigned long *clear_bmap;
81     uint8_t clear_bmap_shift;
82 
83     /*
84      * RAM block length that corresponds to the used_length on the migration
85      * source (after RAM block sizes were synchronized). Especially, after
86      * starting to run the guest, used_length and postcopy_length can differ.
87      * Used to register/unregister uffd handlers and as the size of the received
88      * bitmap. Receiving any page beyond this length will bail out, as it
89      * could not have been valid on the source.
90      */
91     ram_addr_t postcopy_length;
92 };
93 
94 #endif
95