1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * KVM userfaultfd util 4 * 5 * Copyright (C) 2018, Red Hat, Inc. 6 * Copyright (C) 2019-2022 Google LLC 7 */ 8 9 #define _GNU_SOURCE /* for pipe2 */ 10 11 #include <inttypes.h> 12 #include <time.h> 13 #include <pthread.h> 14 #include <linux/userfaultfd.h> 15 16 #include "test_util.h" 17 18 typedef int (*uffd_handler_t)(int uffd_mode, int uffd, struct uffd_msg *msg); 19 20 struct uffd_desc { 21 int uffd_mode; 22 int uffd; 23 int pipefds[2]; 24 useconds_t delay; 25 uffd_handler_t handler; 26 pthread_t thread; 27 }; 28 29 struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay, 30 void *hva, uint64_t len, 31 uffd_handler_t handler); 32 33 void uffd_stop_demand_paging(struct uffd_desc *uffd); 34 35 #ifdef PRINT_PER_PAGE_UPDATES 36 #define PER_PAGE_DEBUG(...) printf(__VA_ARGS__) 37 #else 38 #define PER_PAGE_DEBUG(...) _no_printf(__VA_ARGS__) 39 #endif 40 41 #ifdef PRINT_PER_VCPU_UPDATES 42 #define PER_VCPU_DEBUG(...) printf(__VA_ARGS__) 43 #else 44 #define PER_VCPU_DEBUG(...) _no_printf(__VA_ARGS__) 45 #endif 46