userfaultfd_util.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <inttypes.h>
  9. #include <time.h>
  10. #include <pthread.h>
  11. #include <linux/userfaultfd.h>
  12. #include "test_util.h"
  13. typedef int (*uffd_handler_t)(int uffd_mode, int uffd, struct uffd_msg *msg);
  14. struct uffd_reader_args {
  15. int uffd_mode;
  16. int uffd;
  17. useconds_t delay;
  18. uffd_handler_t handler;
  19. /* Holds the read end of the pipe for killing the reader. */
  20. int pipe;
  21. };
  22. struct uffd_desc {
  23. int uffd;
  24. uint64_t num_readers;
  25. /* Holds the write ends of the pipes for killing the readers. */
  26. int *pipefds;
  27. pthread_t *readers;
  28. struct uffd_reader_args *reader_args;
  29. };
  30. struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay,
  31. void *hva, uint64_t len,
  32. uint64_t num_readers,
  33. uffd_handler_t handler);
  34. void uffd_stop_demand_paging(struct uffd_desc *uffd);
  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. #ifdef PRINT_PER_VCPU_UPDATES
  41. #define PER_VCPU_DEBUG(...) printf(__VA_ARGS__)
  42. #else
  43. #define PER_VCPU_DEBUG(...) _no_printf(__VA_ARGS__)
  44. #endif