1*1a992bbaSAndre Przywara #ifndef _LINUX_VIRTIO_BALLOON_H 2*1a992bbaSAndre Przywara #define _LINUX_VIRTIO_BALLOON_H 3*1a992bbaSAndre Przywara /* This header is BSD licensed so anyone can use the definitions to implement 4*1a992bbaSAndre Przywara * compatible drivers/servers. 5*1a992bbaSAndre Przywara * 6*1a992bbaSAndre Przywara * Redistribution and use in source and binary forms, with or without 7*1a992bbaSAndre Przywara * modification, are permitted provided that the following conditions 8*1a992bbaSAndre Przywara * are met: 9*1a992bbaSAndre Przywara * 1. Redistributions of source code must retain the above copyright 10*1a992bbaSAndre Przywara * notice, this list of conditions and the following disclaimer. 11*1a992bbaSAndre Przywara * 2. Redistributions in binary form must reproduce the above copyright 12*1a992bbaSAndre Przywara * notice, this list of conditions and the following disclaimer in the 13*1a992bbaSAndre Przywara * documentation and/or other materials provided with the distribution. 14*1a992bbaSAndre Przywara * 3. Neither the name of IBM nor the names of its contributors 15*1a992bbaSAndre Przywara * may be used to endorse or promote products derived from this software 16*1a992bbaSAndre Przywara * without specific prior written permission. 17*1a992bbaSAndre Przywara * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18*1a992bbaSAndre Przywara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*1a992bbaSAndre Przywara * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*1a992bbaSAndre Przywara * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21*1a992bbaSAndre Przywara * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*1a992bbaSAndre Przywara * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*1a992bbaSAndre Przywara * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*1a992bbaSAndre Przywara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*1a992bbaSAndre Przywara * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*1a992bbaSAndre Przywara * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*1a992bbaSAndre Przywara * SUCH DAMAGE. */ 28*1a992bbaSAndre Przywara #include <linux/types.h> 29*1a992bbaSAndre Przywara #include <linux/virtio_types.h> 30*1a992bbaSAndre Przywara #include <linux/virtio_ids.h> 31*1a992bbaSAndre Przywara #include <linux/virtio_config.h> 32*1a992bbaSAndre Przywara 33*1a992bbaSAndre Przywara /* The feature bitmap for virtio balloon */ 34*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_F_MUST_TELL_HOST 0 /* Tell before reclaiming pages */ 35*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_F_STATS_VQ 1 /* Memory Stats virtqueue */ 36*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_F_DEFLATE_ON_OOM 2 /* Deflate balloon on OOM */ 37*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_F_FREE_PAGE_HINT 3 /* VQ to report free pages */ 38*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_F_PAGE_POISON 4 /* Guest is using page poisoning */ 39*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_F_REPORTING 5 /* Page reporting virtqueue */ 40*1a992bbaSAndre Przywara 41*1a992bbaSAndre Przywara /* Size of a PFN in the balloon interface. */ 42*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_PFN_SHIFT 12 43*1a992bbaSAndre Przywara 44*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_CMD_ID_STOP 0 45*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_CMD_ID_DONE 1 46*1a992bbaSAndre Przywara struct virtio_balloon_config { 47*1a992bbaSAndre Przywara /* Number of pages host wants Guest to give up. */ 48*1a992bbaSAndre Przywara __le32 num_pages; 49*1a992bbaSAndre Przywara /* Number of pages we've actually got in balloon. */ 50*1a992bbaSAndre Przywara __le32 actual; 51*1a992bbaSAndre Przywara /* 52*1a992bbaSAndre Przywara * Free page hint command id, readonly by guest. 53*1a992bbaSAndre Przywara * Was previously named free_page_report_cmd_id so we 54*1a992bbaSAndre Przywara * need to carry that name for legacy support. 55*1a992bbaSAndre Przywara */ 56*1a992bbaSAndre Przywara union { 57*1a992bbaSAndre Przywara __le32 free_page_hint_cmd_id; 58*1a992bbaSAndre Przywara __le32 free_page_report_cmd_id; /* deprecated */ 59*1a992bbaSAndre Przywara }; 60*1a992bbaSAndre Przywara /* Stores PAGE_POISON if page poisoning is in use */ 61*1a992bbaSAndre Przywara __le32 poison_val; 62*1a992bbaSAndre Przywara }; 63*1a992bbaSAndre Przywara 64*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_SWAP_IN 0 /* Amount of memory swapped in */ 65*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_SWAP_OUT 1 /* Amount of memory swapped out */ 66*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_MAJFLT 2 /* Number of major faults */ 67*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */ 68*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ 69*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ 70*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_AVAIL 6 /* Available memory as in /proc */ 71*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_CACHES 7 /* Disk caches */ 72*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_HTLB_PGALLOC 8 /* Hugetlb page allocations */ 73*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_HTLB_PGFAIL 9 /* Hugetlb page allocation failures */ 74*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_NR 10 75*1a992bbaSAndre Przywara 76*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_NAMES_WITH_PREFIX(VIRTIO_BALLOON_S_NAMES_prefix) { \ 77*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "swap-in", \ 78*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "swap-out", \ 79*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "major-faults", \ 80*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "minor-faults", \ 81*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "free-memory", \ 82*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "total-memory", \ 83*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "available-memory", \ 84*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "disk-caches", \ 85*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-allocations", \ 86*1a992bbaSAndre Przywara VIRTIO_BALLOON_S_NAMES_prefix "hugetlb-failures" \ 87*1a992bbaSAndre Przywara } 88*1a992bbaSAndre Przywara 89*1a992bbaSAndre Przywara #define VIRTIO_BALLOON_S_NAMES VIRTIO_BALLOON_S_NAMES_WITH_PREFIX("") 90*1a992bbaSAndre Przywara 91*1a992bbaSAndre Przywara /* 92*1a992bbaSAndre Przywara * Memory statistics structure. 93*1a992bbaSAndre Przywara * Driver fills an array of these structures and passes to device. 94*1a992bbaSAndre Przywara * 95*1a992bbaSAndre Przywara * NOTE: fields are laid out in a way that would make compiler add padding 96*1a992bbaSAndre Przywara * between and after fields, so we have to use compiler-specific attributes to 97*1a992bbaSAndre Przywara * pack it, to disable this padding. This also often causes compiler to 98*1a992bbaSAndre Przywara * generate suboptimal code. 99*1a992bbaSAndre Przywara * 100*1a992bbaSAndre Przywara * We maintain this statistics structure format for backwards compatibility, 101*1a992bbaSAndre Przywara * but don't follow this example. 102*1a992bbaSAndre Przywara * 103*1a992bbaSAndre Przywara * If implementing a similar structure, do something like the below instead: 104*1a992bbaSAndre Przywara * struct virtio_balloon_stat { 105*1a992bbaSAndre Przywara * __virtio16 tag; 106*1a992bbaSAndre Przywara * __u8 reserved[6]; 107*1a992bbaSAndre Przywara * __virtio64 val; 108*1a992bbaSAndre Przywara * }; 109*1a992bbaSAndre Przywara * 110*1a992bbaSAndre Przywara * In other words, add explicit reserved fields to align field and 111*1a992bbaSAndre Przywara * structure boundaries at field size, avoiding compiler padding 112*1a992bbaSAndre Przywara * without the packed attribute. 113*1a992bbaSAndre Przywara */ 114*1a992bbaSAndre Przywara struct virtio_balloon_stat { 115*1a992bbaSAndre Przywara __virtio16 tag; 116*1a992bbaSAndre Przywara __virtio64 val; 117*1a992bbaSAndre Przywara } __attribute__((packed)); 118*1a992bbaSAndre Przywara 119*1a992bbaSAndre Przywara #endif /* _LINUX_VIRTIO_BALLOON_H */ 120