1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright 2013 Red Hat Inc.
7 * See Documentation/vm/hmm.rst for reasons and overview of what HMM is.
12 #include <linux/kconfig.h>
13 #include <linux/pgtable.h>
15 #include <linux/device.h>
16 #include <linux/migrate.h>
17 #include <linux/memremap.h>
18 #include <linux/completion.h>
19 #include <linux/mmu_notifier.h>
23 * 0 - The page is faultable and a future call with
24 * HMM_PFN_REQ_FAULT could succeed.
25 * HMM_PFN_VALID - the pfn field points to a valid PFN. This PFN is at
26 * least readable. If dev_private_owner is !NULL then this could
27 * point at a DEVICE_PRIVATE page.
28 * HMM_PFN_WRITE - if the page memory can be written to (requires HMM_PFN_VALID)
29 * HMM_PFN_ERROR - accessing the pfn is impossible and the device should
30 * fail. ie poisoned memory, special pages, no vma, etc
33 * 0 - Return the current state of the page, do not fault it.
34 * HMM_PFN_REQ_FAULT - The output must have HMM_PFN_VALID or hmm_range_fault()
36 * HMM_PFN_REQ_WRITE - The output must have HMM_PFN_WRITE or hmm_range_fault()
37 * will fail. Must be combined with HMM_PFN_REQ_FAULT.
41 HMM_PFN_VALID = 1UL << (BITS_PER_LONG - 1),
42 HMM_PFN_WRITE = 1UL << (BITS_PER_LONG - 2),
43 HMM_PFN_ERROR = 1UL << (BITS_PER_LONG - 3),
46 HMM_PFN_REQ_FAULT = HMM_PFN_VALID,
47 HMM_PFN_REQ_WRITE = HMM_PFN_WRITE,
49 HMM_PFN_FLAGS = HMM_PFN_VALID | HMM_PFN_WRITE | HMM_PFN_ERROR,
53 * hmm_pfn_to_page() - return struct page pointed to by a device entry
55 * This must be called under the caller 'user_lock' after a successful
56 * mmu_interval_read_begin(). The caller must have tested for HMM_PFN_VALID
59 static inline struct page *hmm_pfn_to_page(unsigned long hmm_pfn)
61 return pfn_to_page(hmm_pfn & ~HMM_PFN_FLAGS);
65 * struct hmm_range - track invalidation lock on virtual address range
67 * @notifier: a mmu_interval_notifier that includes the start/end
68 * @notifier_seq: result of mmu_interval_read_begin()
69 * @start: range virtual start address (inclusive)
70 * @end: range virtual end address (exclusive)
71 * @hmm_pfns: array of pfns (big enough for the range)
72 * @default_flags: default flags for the range (write, read, ... see hmm doc)
73 * @pfn_flags_mask: allows to mask pfn flags so that only default_flags matter
74 * @dev_private_owner: owner of device private pages
77 struct mmu_interval_notifier *notifier;
78 unsigned long notifier_seq;
81 unsigned long *hmm_pfns;
82 unsigned long default_flags;
83 unsigned long pfn_flags_mask;
84 void *dev_private_owner;
88 * Please see Documentation/vm/hmm.rst for how to use the range API.
90 int hmm_range_fault(struct hmm_range *range);
93 * HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range
95 * When waiting for mmu notifiers we need some kind of time out otherwise we
96 * could potentialy wait for ever, 1000ms ie 1s sounds like a long time to
99 #define HMM_RANGE_DEFAULT_TIMEOUT 1000
101 #endif /* LINUX_HMM_H */