Commit | Line | Data |
---|---|---|
c942fddf | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
133ff0ea JG |
2 | /* |
3 | * Copyright 2013 Red Hat Inc. | |
4 | * | |
f813f219 | 5 | * Authors: Jérôme Glisse <jglisse@redhat.com> |
133ff0ea | 6 | * |
f970b977 | 7 | * See Documentation/vm/hmm.rst for reasons and overview of what HMM is. |
133ff0ea JG |
8 | */ |
9 | #ifndef LINUX_HMM_H | |
10 | #define LINUX_HMM_H | |
11 | ||
12 | #include <linux/kconfig.h> | |
ca5999fd | 13 | #include <linux/pgtable.h> |
133ff0ea | 14 | |
858b54da | 15 | #include <linux/device.h> |
4ef589dc JG |
16 | #include <linux/migrate.h> |
17 | #include <linux/memremap.h> | |
18 | #include <linux/completion.h> | |
a3e0d41c | 19 | #include <linux/mmu_notifier.h> |
4ef589dc | 20 | |
133ff0ea | 21 | /* |
2733ea14 JG |
22 | * On output: |
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 | |
f88a1e90 | 31 | * |
2733ea14 JG |
32 | * On input: |
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() | |
35 | * will fail | |
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. | |
f88a1e90 | 38 | */ |
2733ea14 JG |
39 | enum hmm_pfn_flags { |
40 | /* Output flags */ | |
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), | |
44 | ||
45 | /* Input flags */ | |
46 | HMM_PFN_REQ_FAULT = HMM_PFN_VALID, | |
47 | HMM_PFN_REQ_WRITE = HMM_PFN_WRITE, | |
48 | ||
49 | HMM_PFN_FLAGS = HMM_PFN_VALID | HMM_PFN_WRITE | HMM_PFN_ERROR, | |
f88a1e90 JG |
50 | }; |
51 | ||
52 | /* | |
2733ea14 | 53 | * hmm_pfn_to_page() - return struct page pointed to by a device entry |
f88a1e90 | 54 | * |
2733ea14 JG |
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 | |
57 | * already. | |
133ff0ea | 58 | */ |
2733ea14 JG |
59 | static inline struct page *hmm_pfn_to_page(unsigned long hmm_pfn) |
60 | { | |
61 | return pfn_to_page(hmm_pfn & ~HMM_PFN_FLAGS); | |
62 | } | |
f88a1e90 JG |
63 | |
64 | /* | |
65 | * struct hmm_range - track invalidation lock on virtual address range | |
66 | * | |
a22dd506 JG |
67 | * @notifier: a mmu_interval_notifier that includes the start/end |
68 | * @notifier_seq: result of mmu_interval_read_begin() | |
f88a1e90 JG |
69 | * @start: range virtual start address (inclusive) |
70 | * @end: range virtual end address (exclusive) | |
2733ea14 | 71 | * @hmm_pfns: array of pfns (big enough for the range) |
023a019a JG |
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 | |
08ddddda | 74 | * @dev_private_owner: owner of device private pages |
f88a1e90 JG |
75 | */ |
76 | struct hmm_range { | |
04ec32fb JG |
77 | struct mmu_interval_notifier *notifier; |
78 | unsigned long notifier_seq; | |
f88a1e90 JG |
79 | unsigned long start; |
80 | unsigned long end; | |
2733ea14 JG |
81 | unsigned long *hmm_pfns; |
82 | unsigned long default_flags; | |
83 | unsigned long pfn_flags_mask; | |
08ddddda | 84 | void *dev_private_owner; |
f88a1e90 | 85 | }; |
133ff0ea | 86 | |
da4c3c73 | 87 | /* |
a3e0d41c | 88 | * Please see Documentation/vm/hmm.rst for how to use the range API. |
da4c3c73 | 89 | */ |
be957c88 | 90 | int hmm_range_fault(struct hmm_range *range); |
74eee180 JG |
91 | |
92 | /* | |
a3e0d41c | 93 | * HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range |
74eee180 | 94 | * |
a3e0d41c JG |
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 | |
97 | * wait already. | |
74eee180 | 98 | */ |
a3e0d41c JG |
99 | #define HMM_RANGE_DEFAULT_TIMEOUT 1000 |
100 | ||
133ff0ea | 101 | #endif /* LINUX_HMM_H */ |