1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2022 Google LLC 4 * Author: Keir Fraser <keirf@google.com> 5 */ 6 7 #ifndef _LINUX_VIRTIO_BALLOON_H 8 #define _LINUX_VIRTIO_BALLOON_H 9 10 #include <uapi/linux/virtio_balloon.h> 11 12 struct page; 13 14 #ifdef CONFIG_VIRTIO_BALLOON_HYP_OPS 15 16 struct virtio_balloon_hyp_ops { 17 bool (*page_relinquish_disallowed)(void); 18 void (*page_relinquish)(struct page *page, unsigned int nr); 19 void (*post_page_relinquish_tlb_inv)(void); 20 }; 21 22 extern struct virtio_balloon_hyp_ops *virtio_balloon_hyp_ops; 23 page_relinquish_disallowed(void)24static inline bool page_relinquish_disallowed(void) 25 { 26 if (virtio_balloon_hyp_ops && 27 virtio_balloon_hyp_ops->page_relinquish_disallowed) 28 return virtio_balloon_hyp_ops->page_relinquish_disallowed(); 29 return false; 30 } 31 page_relinquish(struct page * page,unsigned int nr)32static inline void page_relinquish(struct page *page, unsigned int nr) 33 { 34 if (virtio_balloon_hyp_ops && 35 virtio_balloon_hyp_ops->page_relinquish_disallowed) 36 return virtio_balloon_hyp_ops->page_relinquish(page, nr); 37 } 38 post_page_relinquish_tlb_inv(void)39static inline void post_page_relinquish_tlb_inv(void) 40 { 41 if (virtio_balloon_hyp_ops && 42 virtio_balloon_hyp_ops->post_page_relinquish_tlb_inv) 43 return virtio_balloon_hyp_ops->post_page_relinquish_tlb_inv(); 44 } 45 #else /* !CONFIG_VIRTIO_BALLOON_HYP_OPS */ 46 page_relinquish_disallowed(void)47static inline bool page_relinquish_disallowed(void) { return false; } page_relinquish(struct page * page,unsigned int nr)48static inline void page_relinquish(struct page *page, unsigned int nr) { } post_page_relinquish_tlb_inv(void)49static inline void post_page_relinquish_tlb_inv(void) { } 50 51 #endif /* CONFIG_VIRTIO_BALLOON_HYP_OPS */ 52 53 #endif /* _LINUX_VIRTIO_BALLOON_H */ 54