File: userfaultfd_util.h

package info (click to toggle)
linux 6.17.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,734,900 kB
  • sloc: ansic: 26,684,436; asm: 271,195; sh: 147,406; python: 75,980; makefile: 57,306; perl: 36,943; xml: 19,562; cpp: 5,899; yacc: 4,909; lex: 2,943; awk: 1,556; sed: 29; ruby: 25
file content (52 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * KVM userfaultfd util
 *
 * Copyright (C) 2018, Red Hat, Inc.
 * Copyright (C) 2019-2022 Google LLC
 */
#include <inttypes.h>
#include <time.h>
#include <pthread.h>
#include <linux/userfaultfd.h>

#include "test_util.h"

typedef int (*uffd_handler_t)(int uffd_mode, int uffd, struct uffd_msg *msg);

struct uffd_reader_args {
	int uffd_mode;
	int uffd;
	useconds_t delay;
	uffd_handler_t handler;
	/* Holds the read end of the pipe for killing the reader. */
	int pipe;
};

struct uffd_desc {
	int uffd;
	uint64_t num_readers;
	/* Holds the write ends of the pipes for killing the readers. */
	int *pipefds;
	pthread_t *readers;
	struct uffd_reader_args *reader_args;
};

struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay,
					   void *hva, uint64_t len,
					   uint64_t num_readers,
					   uffd_handler_t handler);

void uffd_stop_demand_paging(struct uffd_desc *uffd);

#ifdef PRINT_PER_PAGE_UPDATES
#define PER_PAGE_DEBUG(...) printf(__VA_ARGS__)
#else
#define PER_PAGE_DEBUG(...) _no_printf(__VA_ARGS__)
#endif

#ifdef PRINT_PER_VCPU_UPDATES
#define PER_VCPU_DEBUG(...) printf(__VA_ARGS__)
#else
#define PER_VCPU_DEBUG(...) _no_printf(__VA_ARGS__)
#endif