2019-05-27 14:55:06 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2017-09-09 07:11:23 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Red Hat Inc.
|
|
|
|
*
|
2018-10-31 06:04:06 +08:00
|
|
|
* Authors: Jérôme Glisse <jglisse@redhat.com>
|
2017-09-09 07:11:23 +08:00
|
|
|
*
|
2022-06-27 14:00:26 +08:00
|
|
|
* See Documentation/mm/hmm.rst for reasons and overview of what HMM is.
|
2017-09-09 07:11:23 +08:00
|
|
|
*/
|
|
|
|
#ifndef LINUX_HMM_H
|
|
|
|
#define LINUX_HMM_H
|
|
|
|
|
2022-02-16 12:31:35 +08:00
|
|
|
#include <linux/mm.h>
|
2017-09-09 07:11:23 +08:00
|
|
|
|
2022-02-16 12:31:35 +08:00
|
|
|
struct mmu_interval_notifier;
|
2017-09-09 07:11:58 +08:00
|
|
|
|
2017-09-09 07:11:23 +08:00
|
|
|
/*
|
2020-05-02 02:20:48 +08:00
|
|
|
* On output:
|
|
|
|
* 0 - The page is faultable and a future call with
|
|
|
|
* HMM_PFN_REQ_FAULT could succeed.
|
|
|
|
* HMM_PFN_VALID - the pfn field points to a valid PFN. This PFN is at
|
|
|
|
* least readable. If dev_private_owner is !NULL then this could
|
|
|
|
* point at a DEVICE_PRIVATE page.
|
|
|
|
* HMM_PFN_WRITE - if the page memory can be written to (requires HMM_PFN_VALID)
|
|
|
|
* HMM_PFN_ERROR - accessing the pfn is impossible and the device should
|
|
|
|
* fail. ie poisoned memory, special pages, no vma, etc
|
2018-04-11 07:29:06 +08:00
|
|
|
*
|
2020-05-02 02:20:48 +08:00
|
|
|
* On input:
|
|
|
|
* 0 - Return the current state of the page, do not fault it.
|
|
|
|
* HMM_PFN_REQ_FAULT - The output must have HMM_PFN_VALID or hmm_range_fault()
|
|
|
|
* will fail
|
|
|
|
* HMM_PFN_REQ_WRITE - The output must have HMM_PFN_WRITE or hmm_range_fault()
|
|
|
|
* will fail. Must be combined with HMM_PFN_REQ_FAULT.
|
2018-04-11 07:29:06 +08:00
|
|
|
*/
|
2020-05-02 02:20:48 +08:00
|
|
|
enum hmm_pfn_flags {
|
2020-07-02 06:53:49 +08:00
|
|
|
/* Output fields and flags */
|
2020-05-02 02:20:48 +08:00
|
|
|
HMM_PFN_VALID = 1UL << (BITS_PER_LONG - 1),
|
|
|
|
HMM_PFN_WRITE = 1UL << (BITS_PER_LONG - 2),
|
|
|
|
HMM_PFN_ERROR = 1UL << (BITS_PER_LONG - 3),
|
2020-07-02 06:53:49 +08:00
|
|
|
HMM_PFN_ORDER_SHIFT = (BITS_PER_LONG - 8),
|
2020-05-02 02:20:48 +08:00
|
|
|
|
|
|
|
/* Input flags */
|
|
|
|
HMM_PFN_REQ_FAULT = HMM_PFN_VALID,
|
|
|
|
HMM_PFN_REQ_WRITE = HMM_PFN_WRITE,
|
|
|
|
|
2020-07-02 06:53:49 +08:00
|
|
|
HMM_PFN_FLAGS = 0xFFUL << HMM_PFN_ORDER_SHIFT,
|
2018-04-11 07:29:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2020-05-02 02:20:48 +08:00
|
|
|
* hmm_pfn_to_page() - return struct page pointed to by a device entry
|
2018-04-11 07:29:06 +08:00
|
|
|
*
|
2020-05-02 02:20:48 +08:00
|
|
|
* This must be called under the caller 'user_lock' after a successful
|
|
|
|
* mmu_interval_read_begin(). The caller must have tested for HMM_PFN_VALID
|
|
|
|
* already.
|
2017-09-09 07:11:23 +08:00
|
|
|
*/
|
2020-05-02 02:20:48 +08:00
|
|
|
static inline struct page *hmm_pfn_to_page(unsigned long hmm_pfn)
|
|
|
|
{
|
|
|
|
return pfn_to_page(hmm_pfn & ~HMM_PFN_FLAGS);
|
|
|
|
}
|
2018-04-11 07:29:06 +08:00
|
|
|
|
2020-07-02 06:53:49 +08:00
|
|
|
/*
|
|
|
|
* hmm_pfn_to_map_order() - return the CPU mapping size order
|
|
|
|
*
|
|
|
|
* This is optionally useful to optimize processing of the pfn result
|
|
|
|
* array. It indicates that the page starts at the order aligned VA and is
|
|
|
|
* 1<<order bytes long. Every pfn within an high order page will have the
|
|
|
|
* same pfn flags, both access protections and the map_order. The caller must
|
|
|
|
* be careful with edge cases as the start and end VA of the given page may
|
|
|
|
* extend past the range used with hmm_range_fault().
|
|
|
|
*
|
|
|
|
* This must be called under the caller 'user_lock' after a successful
|
|
|
|
* mmu_interval_read_begin(). The caller must have tested for HMM_PFN_VALID
|
|
|
|
* already.
|
|
|
|
*/
|
|
|
|
static inline unsigned int hmm_pfn_to_map_order(unsigned long hmm_pfn)
|
|
|
|
{
|
|
|
|
return (hmm_pfn >> HMM_PFN_ORDER_SHIFT) & 0x1F;
|
|
|
|
}
|
|
|
|
|
2018-04-11 07:29:06 +08:00
|
|
|
/*
|
|
|
|
* struct hmm_range - track invalidation lock on virtual address range
|
|
|
|
*
|
2019-11-13 04:22:30 +08:00
|
|
|
* @notifier: a mmu_interval_notifier that includes the start/end
|
|
|
|
* @notifier_seq: result of mmu_interval_read_begin()
|
2018-04-11 07:29:06 +08:00
|
|
|
* @start: range virtual start address (inclusive)
|
|
|
|
* @end: range virtual end address (exclusive)
|
2020-05-02 02:20:48 +08:00
|
|
|
* @hmm_pfns: array of pfns (big enough for the range)
|
2019-05-14 08:20:05 +08:00
|
|
|
* @default_flags: default flags for the range (write, read, ... see hmm doc)
|
|
|
|
* @pfn_flags_mask: allows to mask pfn flags so that only default_flags matter
|
2020-03-17 03:32:16 +08:00
|
|
|
* @dev_private_owner: owner of device private pages
|
2018-04-11 07:29:06 +08:00
|
|
|
*/
|
|
|
|
struct hmm_range {
|
2019-11-13 04:22:20 +08:00
|
|
|
struct mmu_interval_notifier *notifier;
|
|
|
|
unsigned long notifier_seq;
|
2018-04-11 07:29:06 +08:00
|
|
|
unsigned long start;
|
|
|
|
unsigned long end;
|
2020-05-02 02:20:48 +08:00
|
|
|
unsigned long *hmm_pfns;
|
|
|
|
unsigned long default_flags;
|
|
|
|
unsigned long pfn_flags_mask;
|
2020-03-17 03:32:16 +08:00
|
|
|
void *dev_private_owner;
|
2018-04-11 07:29:06 +08:00
|
|
|
};
|
2017-09-09 07:11:23 +08:00
|
|
|
|
2017-09-09 07:11:31 +08:00
|
|
|
/*
|
2022-06-27 14:00:26 +08:00
|
|
|
* Please see Documentation/mm/hmm.rst for how to use the range API.
|
2017-09-09 07:11:31 +08:00
|
|
|
*/
|
2020-05-02 02:20:45 +08:00
|
|
|
int hmm_range_fault(struct hmm_range *range);
|
2017-09-09 07:11:35 +08:00
|
|
|
|
|
|
|
/*
|
2019-05-14 08:20:01 +08:00
|
|
|
* HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range
|
2017-09-09 07:11:35 +08:00
|
|
|
*
|
2019-05-14 08:20:01 +08:00
|
|
|
* When waiting for mmu notifiers we need some kind of time out otherwise we
|
2021-07-08 09:08:19 +08:00
|
|
|
* could potentially wait for ever, 1000ms ie 1s sounds like a long time to
|
2019-05-14 08:20:01 +08:00
|
|
|
* wait already.
|
2017-09-09 07:11:35 +08:00
|
|
|
*/
|
2019-05-14 08:20:01 +08:00
|
|
|
#define HMM_RANGE_DEFAULT_TIMEOUT 1000
|
|
|
|
|
2017-09-09 07:11:23 +08:00
|
|
|
#endif /* LINUX_HMM_H */
|