19fbe302bSMichael S. Tsirkin #ifndef _LINUX_VIRTIO_BALLOON_H 29fbe302bSMichael S. Tsirkin #define _LINUX_VIRTIO_BALLOON_H 39fbe302bSMichael S. Tsirkin /* This header is BSD licensed so anyone can use the definitions to implement 49fbe302bSMichael S. Tsirkin * compatible drivers/servers. 59fbe302bSMichael S. Tsirkin * 69fbe302bSMichael S. Tsirkin * Redistribution and use in source and binary forms, with or without 79fbe302bSMichael S. Tsirkin * modification, are permitted provided that the following conditions 89fbe302bSMichael S. Tsirkin * are met: 99fbe302bSMichael S. Tsirkin * 1. Redistributions of source code must retain the above copyright 109fbe302bSMichael S. Tsirkin * notice, this list of conditions and the following disclaimer. 119fbe302bSMichael S. Tsirkin * 2. Redistributions in binary form must reproduce the above copyright 129fbe302bSMichael S. Tsirkin * notice, this list of conditions and the following disclaimer in the 139fbe302bSMichael S. Tsirkin * documentation and/or other materials provided with the distribution. 149fbe302bSMichael S. Tsirkin * 3. Neither the name of IBM nor the names of its contributors 159fbe302bSMichael S. Tsirkin * may be used to endorse or promote products derived from this software 169fbe302bSMichael S. Tsirkin * without specific prior written permission. 179fbe302bSMichael S. Tsirkin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 189fbe302bSMichael S. Tsirkin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 199fbe302bSMichael S. Tsirkin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 209fbe302bSMichael S. Tsirkin * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 219fbe302bSMichael S. Tsirkin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 229fbe302bSMichael S. Tsirkin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 239fbe302bSMichael S. Tsirkin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 249fbe302bSMichael S. Tsirkin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 259fbe302bSMichael S. Tsirkin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 269fbe302bSMichael S. Tsirkin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 279fbe302bSMichael S. Tsirkin * SUCH DAMAGE. */ 287a52ce8aSCornelia Huck #include "standard-headers/linux/types.h" 2925b8b39bSAlexey Kardashevskiy #include "standard-headers/linux/virtio_types.h" 309fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_ids.h" 319fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_config.h" 329fbe302bSMichael S. Tsirkin 339fbe302bSMichael S. Tsirkin /* The feature bitmap for virtio balloon */ 349fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */ 359fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory Stats virtqueue */ 369fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */ 37da054c64SPaolo Bonzini #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */ 38da054c64SPaolo Bonzini #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ 39dc6f8d45SCornelia Huck #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ 409fbe302bSMichael S. Tsirkin 419fbe302bSMichael S. Tsirkin /* Size of a PFN in the balloon interface. */ 429fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_PFN_SHIFT 12 439fbe302bSMichael S. Tsirkin 44da054c64SPaolo Bonzini #define VIRTIO_BALLOON_CMD_ID_STOP 0 45da054c64SPaolo Bonzini #define VIRTIO_BALLOON_CMD_ID_DONE 1 469fbe302bSMichael S. Tsirkin struct virtio_balloon_config { 479fbe302bSMichael S. Tsirkin /* Number of pages host wants Guest to give up. */ 489fbe302bSMichael S. Tsirkin uint32_t num_pages; 499fbe302bSMichael S. Tsirkin /* Number of pages we've actually got in balloon. */ 509fbe302bSMichael S. Tsirkin uint32_t actual; 51dc6f8d45SCornelia Huck /* 52dc6f8d45SCornelia Huck * Free page hint command id, readonly by guest. 53dc6f8d45SCornelia Huck * Was previously named free_page_report_cmd_id so we 54dc6f8d45SCornelia Huck * need to carry that name for legacy support. 55dc6f8d45SCornelia Huck */ 56dc6f8d45SCornelia Huck union { 57dc6f8d45SCornelia Huck uint32_t free_page_hint_cmd_id; 58dc6f8d45SCornelia Huck uint32_t free_page_report_cmd_id; /* deprecated */ 59dc6f8d45SCornelia Huck }; 60da054c64SPaolo Bonzini /* Stores PAGE_POISON if page poisoning is in use */ 61da054c64SPaolo Bonzini uint32_t poison_val; 629fbe302bSMichael S. Tsirkin }; 639fbe302bSMichael S. Tsirkin 649fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */ 659fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */ 669fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */ 679fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */ 689fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ 699fbe302bSMichael S. Tsirkin #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ 70b89485a5SPaolo Bonzini #define VIRTIO_BALLOON_S_AVAIL 6 /* Available memory as in /proc */ 71bf1e7140STomáš Golembiovský #define VIRTIO_BALLOON_S_CACHES 7 /* Disk caches */ 72b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGALLOC 8 /* Hugetlb page allocations */ 73b7b12644SJonathan Helman #define VIRTIO_BALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */ 74*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_OOM_KILL 10 /* OOM killer invocations */ 75*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_ALLOC_STALL 11 /* Stall count of memory allocatoin */ 76*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_ASYNC_SCAN 12 /* Amount of memory scanned asynchronously */ 77*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_DIRECT_SCAN 13 /* Amount of memory scanned directly */ 78*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_ASYNC_RECLAIM 14 /* Amount of memory reclaimed asynchronously */ 79*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_DIRECT_RECLAIM 15 /* Amount of memory reclaimed directly */ 80*0d2eeef7SBibo Mao #define VIRTIO_BALLOON_S_NR 16 819fbe302bSMichael S. Tsirkin 8265a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \ 8365a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \ 8465a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \ 8565a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \ 8665a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \ 8765a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \ 8865a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \ 8965a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \ 9065a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \ 9165a6d8ddSPeter Maydell VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \ 92*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures", \ 93*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "oom-kills", \ 94*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "alloc-stalls", \ 95*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "async-scans", \ 96*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "direct-scans", \ 97*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "async-reclaims", \ 98*0d2eeef7SBibo Mao VIRTIO_BALLOON_S_NAMES_prefix "direct-reclaims" \ 9965a6d8ddSPeter Maydell } 10065a6d8ddSPeter Maydell 10165a6d8ddSPeter Maydell #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("") 10265a6d8ddSPeter Maydell 1037a52ce8aSCornelia Huck /* 1047a52ce8aSCornelia Huck * Memory statistics structure. 1057a52ce8aSCornelia Huck * Driver fills an array of these structures and passes to device. 1067a52ce8aSCornelia Huck * 1077a52ce8aSCornelia Huck * NOTE: fields are laid out in a way that would make compiler add padding 1087a52ce8aSCornelia Huck * between and after fields, so we have to use compiler-specific attributes to 1097a52ce8aSCornelia Huck * pack it, to disable this padding. This also often causes compiler to 1107a52ce8aSCornelia Huck * generate suboptimal code. 1117a52ce8aSCornelia Huck * 1127a52ce8aSCornelia Huck * We maintain this statistics structure format for backwards compatibility, 1137a52ce8aSCornelia Huck * but don't follow this example. 1147a52ce8aSCornelia Huck * 1157a52ce8aSCornelia Huck * If implementing a similar structure, do something like the below instead: 1167a52ce8aSCornelia Huck * struct virtio_balloon_stat { 1177a52ce8aSCornelia Huck * __virtio16 tag; 1187a52ce8aSCornelia Huck * uint8_t reserved[6]; 1197a52ce8aSCornelia Huck * __virtio64 val; 1207a52ce8aSCornelia Huck * }; 1217a52ce8aSCornelia Huck * 1227a52ce8aSCornelia Huck * In other words, add explicit reserved fields to align field and 1237a52ce8aSCornelia Huck * structure boundaries at field size, avoiding compiler padding 1247a52ce8aSCornelia Huck * without the packed attribute. 1257a52ce8aSCornelia Huck */ 1269fbe302bSMichael S. Tsirkin struct virtio_balloon_stat { 1277a52ce8aSCornelia Huck __virtio16 tag; 1287a52ce8aSCornelia Huck __virtio64 val; 1299fbe302bSMichael S. Tsirkin } QEMU_PACKED; 1309fbe302bSMichael S. Tsirkin 1319fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_BALLOON_H */ 132