6868#include <linux/completion.h>
6969#include <linux/mmu_notifier.h>
7070
71-
72- /*
73- * struct hmm - HMM per mm struct
74- *
75- * @mm: mm struct this HMM struct is bound to
76- * @lock: lock protecting ranges list
77- * @ranges: list of range being snapshotted
78- * @mirrors: list of mirrors for this mm
79- * @mmu_notifier: mmu notifier to track updates to CPU page table
80- * @mirrors_sem: read/write semaphore protecting the mirrors list
81- * @wq: wait queue for user waiting on a range invalidation
82- * @notifiers: count of active mmu notifiers
83- */
84- struct hmm {
85- struct mmu_notifier mmu_notifier ;
86- spinlock_t ranges_lock ;
87- struct list_head ranges ;
88- struct list_head mirrors ;
89- struct rw_semaphore mirrors_sem ;
90- wait_queue_head_t wq ;
91- long notifiers ;
92- };
93-
9471/*
9572 * hmm_pfn_flag_e - HMM flag enums
9673 *
@@ -143,9 +120,8 @@ enum hmm_pfn_value_e {
143120/*
144121 * struct hmm_range - track invalidation lock on virtual address range
145122 *
146- * @notifier: an optional mmu_interval_notifier
147- * @notifier_seq: when notifier is used this is the result of
148- * mmu_interval_read_begin()
123+ * @notifier: a mmu_interval_notifier that includes the start/end
124+ * @notifier_seq: result of mmu_interval_read_begin()
149125 * @hmm: the core HMM structure this range is active against
150126 * @vma: the vm area struct for the range
151127 * @list: all range lock are on a list
@@ -162,8 +138,6 @@ enum hmm_pfn_value_e {
162138struct hmm_range {
163139 struct mmu_interval_notifier * notifier ;
164140 unsigned long notifier_seq ;
165- struct hmm * hmm ;
166- struct list_head list ;
167141 unsigned long start ;
168142 unsigned long end ;
169143 uint64_t * pfns ;
@@ -172,32 +146,8 @@ struct hmm_range {
172146 uint64_t default_flags ;
173147 uint64_t pfn_flags_mask ;
174148 uint8_t pfn_shift ;
175- bool valid ;
176149};
177150
178- /*
179- * hmm_range_wait_until_valid() - wait for range to be valid
180- * @range: range affected by invalidation to wait on
181- * @timeout: time out for wait in ms (ie abort wait after that period of time)
182- * Return: true if the range is valid, false otherwise.
183- */
184- static inline bool hmm_range_wait_until_valid (struct hmm_range * range ,
185- unsigned long timeout )
186- {
187- return wait_event_timeout (range -> hmm -> wq , range -> valid ,
188- msecs_to_jiffies (timeout )) != 0 ;
189- }
190-
191- /*
192- * hmm_range_valid() - test if a range is valid or not
193- * @range: range
194- * Return: true if the range is valid, false otherwise.
195- */
196- static inline bool hmm_range_valid (struct hmm_range * range )
197- {
198- return range -> valid ;
199- }
200-
201151/*
202152 * hmm_device_entry_to_page() - return struct page pointed to by a device entry
203153 * @range: range use to decode device entry value
@@ -267,111 +217,6 @@ static inline uint64_t hmm_device_entry_from_pfn(const struct hmm_range *range,
267217 range -> flags [HMM_PFN_VALID ];
268218}
269219
270- /*
271- * Mirroring: how to synchronize device page table with CPU page table.
272- *
273- * A device driver that is participating in HMM mirroring must always
274- * synchronize with CPU page table updates. For this, device drivers can either
275- * directly use mmu_notifier APIs or they can use the hmm_mirror API. Device
276- * drivers can decide to register one mirror per device per process, or just
277- * one mirror per process for a group of devices. The pattern is:
278- *
279- * int device_bind_address_space(..., struct mm_struct *mm, ...)
280- * {
281- * struct device_address_space *das;
282- *
283- * // Device driver specific initialization, and allocation of das
284- * // which contains an hmm_mirror struct as one of its fields.
285- * ...
286- *
287- * ret = hmm_mirror_register(&das->mirror, mm, &device_mirror_ops);
288- * if (ret) {
289- * // Cleanup on error
290- * return ret;
291- * }
292- *
293- * // Other device driver specific initialization
294- * ...
295- * }
296- *
297- * Once an hmm_mirror is registered for an address space, the device driver
298- * will get callbacks through sync_cpu_device_pagetables() operation (see
299- * hmm_mirror_ops struct).
300- *
301- * Device driver must not free the struct containing the hmm_mirror struct
302- * before calling hmm_mirror_unregister(). The expected usage is to do that when
303- * the device driver is unbinding from an address space.
304- *
305- *
306- * void device_unbind_address_space(struct device_address_space *das)
307- * {
308- * // Device driver specific cleanup
309- * ...
310- *
311- * hmm_mirror_unregister(&das->mirror);
312- *
313- * // Other device driver specific cleanup, and now das can be freed
314- * ...
315- * }
316- */
317-
318- struct hmm_mirror ;
319-
320- /*
321- * struct hmm_mirror_ops - HMM mirror device operations callback
322- *
323- * @update: callback to update range on a device
324- */
325- struct hmm_mirror_ops {
326- /* release() - release hmm_mirror
327- *
328- * @mirror: pointer to struct hmm_mirror
329- *
330- * This is called when the mm_struct is being released. The callback
331- * must ensure that all access to any pages obtained from this mirror
332- * is halted before the callback returns. All future access should
333- * fault.
334- */
335- void (* release )(struct hmm_mirror * mirror );
336-
337- /* sync_cpu_device_pagetables() - synchronize page tables
338- *
339- * @mirror: pointer to struct hmm_mirror
340- * @update: update information (see struct mmu_notifier_range)
341- * Return: -EAGAIN if mmu_notifier_range_blockable(update) is false
342- * and callback needs to block, 0 otherwise.
343- *
344- * This callback ultimately originates from mmu_notifiers when the CPU
345- * page table is updated. The device driver must update its page table
346- * in response to this callback. The update argument tells what action
347- * to perform.
348- *
349- * The device driver must not return from this callback until the device
350- * page tables are completely updated (TLBs flushed, etc); this is a
351- * synchronous call.
352- */
353- int (* sync_cpu_device_pagetables )(
354- struct hmm_mirror * mirror ,
355- const struct mmu_notifier_range * update );
356- };
357-
358- /*
359- * struct hmm_mirror - mirror struct for a device driver
360- *
361- * @hmm: pointer to struct hmm (which is unique per mm_struct)
362- * @ops: device driver callback for HMM mirror operations
363- * @list: for list of mirrors of a given mm
364- *
365- * Each address space (mm_struct) being mirrored by a device must register one
366- * instance of an hmm_mirror struct with HMM. HMM will track the list of all
367- * mirrors for each mm_struct.
368- */
369- struct hmm_mirror {
370- struct hmm * hmm ;
371- const struct hmm_mirror_ops * ops ;
372- struct list_head list ;
373- };
374-
375220/*
376221 * Retry fault if non-blocking, drop mmap_sem and return -EAGAIN in that case.
377222 */
@@ -381,15 +226,9 @@ struct hmm_mirror {
381226#define HMM_FAULT_SNAPSHOT (1 << 1)
382227
383228#ifdef CONFIG_HMM_MIRROR
384- int hmm_mirror_register (struct hmm_mirror * mirror , struct mm_struct * mm );
385- void hmm_mirror_unregister (struct hmm_mirror * mirror );
386-
387229/*
388230 * Please see Documentation/vm/hmm.rst for how to use the range API.
389231 */
390- int hmm_range_register (struct hmm_range * range , struct hmm_mirror * mirror );
391- void hmm_range_unregister (struct hmm_range * range );
392-
393232long hmm_range_fault (struct hmm_range * range , unsigned int flags );
394233
395234long hmm_range_dma_map (struct hmm_range * range ,
@@ -401,24 +240,6 @@ long hmm_range_dma_unmap(struct hmm_range *range,
401240 dma_addr_t * daddrs ,
402241 bool dirty );
403242#else
404- int hmm_mirror_register (struct hmm_mirror * mirror , struct mm_struct * mm )
405- {
406- return - EOPNOTSUPP ;
407- }
408-
409- void hmm_mirror_unregister (struct hmm_mirror * mirror )
410- {
411- }
412-
413- int hmm_range_register (struct hmm_range * range , struct hmm_mirror * mirror )
414- {
415- return - EOPNOTSUPP ;
416- }
417-
418- void hmm_range_unregister (struct hmm_range * range )
419- {
420- }
421-
422243static inline long hmm_range_fault (struct hmm_range * range , unsigned int flags )
423244{
424245 return - EOPNOTSUPP ;
0 commit comments