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