2019-05-27 13:55:06 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2017-09-09 06:11:23 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Red Hat Inc.
|
|
|
|
*
|
2018-10-31 05:04:06 +07:00
|
|
|
* Authors: Jérôme Glisse <jglisse@redhat.com>
|
2017-09-09 06:11:23 +07:00
|
|
|
*
|
2020-03-28 03:00:15 +07:00
|
|
|
* See Documentation/vm/hmm.rst for reasons and overview of what HMM is.
|
2017-09-09 06:11:23 +07:00
|
|
|
*/
|
|
|
|
#ifndef LINUX_HMM_H
|
|
|
|
#define LINUX_HMM_H
|
|
|
|
|
|
|
|
#include <linux/kconfig.h>
|
2018-12-28 15:39:46 +07:00
|
|
|
#include <asm/pgtable.h>
|
2017-09-09 06:11:23 +07:00
|
|
|
|
2017-09-09 06:12:02 +07:00
|
|
|
#include <linux/device.h>
|
2017-09-09 06:11:58 +07:00
|
|
|
#include <linux/migrate.h>
|
|
|
|
#include <linux/memremap.h>
|
|
|
|
#include <linux/completion.h>
|
2019-05-14 07:20:01 +07:00
|
|
|
#include <linux/mmu_notifier.h>
|
2017-09-09 06:11:58 +07:00
|
|
|
|
2017-09-09 06:11:23 +07:00
|
|
|
/*
|
2018-04-11 06:29:06 +07:00
|
|
|
* hmm_pfn_flag_e - HMM flag enums
|
|
|
|
*
|
2017-09-09 06:11:23 +07:00
|
|
|
* Flags:
|
2018-04-11 06:28:34 +07:00
|
|
|
* HMM_PFN_VALID: pfn is valid. It has, at least, read permission.
|
2017-09-09 06:11:23 +07:00
|
|
|
* HMM_PFN_WRITE: CPU page table has write permission set
|
2018-04-11 06:29:06 +07:00
|
|
|
*
|
2019-05-07 06:29:39 +07:00
|
|
|
* The driver provides a flags array for mapping page protections to device
|
|
|
|
* PTE bits. If the driver valid bit for an entry is bit 3,
|
|
|
|
* i.e., (entry & (1 << 3)), then the driver must provide
|
2018-04-11 06:29:06 +07:00
|
|
|
* an array in hmm_range.flags with hmm_range.flags[HMM_PFN_VALID] == 1 << 3.
|
2019-05-07 06:29:39 +07:00
|
|
|
* Same logic apply to all flags. This is the same idea as vm_page_prot in vma
|
2018-04-11 06:29:06 +07:00
|
|
|
* except that this is per device driver rather than per architecture.
|
|
|
|
*/
|
|
|
|
enum hmm_pfn_flag_e {
|
|
|
|
HMM_PFN_VALID = 0,
|
|
|
|
HMM_PFN_WRITE,
|
|
|
|
HMM_PFN_FLAG_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hmm_pfn_value_e - HMM pfn special value
|
|
|
|
*
|
|
|
|
* Flags:
|
2017-09-09 06:11:31 +07:00
|
|
|
* HMM_PFN_ERROR: corresponding CPU page table entry points to poisoned memory
|
2018-04-11 06:29:06 +07:00
|
|
|
* HMM_PFN_NONE: corresponding CPU page table entry is pte_none()
|
2017-09-09 06:11:31 +07:00
|
|
|
* HMM_PFN_SPECIAL: corresponding CPU page table entry is special; i.e., the
|
2018-10-27 05:04:26 +07:00
|
|
|
* result of vmf_insert_pfn() or vm_insert_page(). Therefore, it should not
|
2017-09-09 06:11:31 +07:00
|
|
|
* be mirrored by a device, because the entry will never have HMM_PFN_VALID
|
|
|
|
* set and the pfn value is undefined.
|
2018-04-11 06:29:06 +07:00
|
|
|
*
|
2019-05-07 06:29:39 +07:00
|
|
|
* Driver provides values for none entry, error entry, and special entry.
|
|
|
|
* Driver can alias (i.e., use same value) error and special, but
|
|
|
|
* it should not alias none with error or special.
|
2018-04-11 06:29:06 +07:00
|
|
|
*
|
|
|
|
* HMM pfn value returned by hmm_vma_get_pfns() or hmm_vma_fault() will be:
|
|
|
|
* hmm_range.values[HMM_PFN_ERROR] if CPU page table entry is poisonous,
|
2019-05-07 06:29:39 +07:00
|
|
|
* hmm_range.values[HMM_PFN_NONE] if there is no CPU page table entry,
|
2018-04-11 06:29:06 +07:00
|
|
|
* hmm_range.values[HMM_PFN_SPECIAL] if CPU page table entry is a special one
|
2017-09-09 06:11:23 +07:00
|
|
|
*/
|
2018-04-11 06:29:06 +07:00
|
|
|
enum hmm_pfn_value_e {
|
|
|
|
HMM_PFN_ERROR,
|
|
|
|
HMM_PFN_NONE,
|
|
|
|
HMM_PFN_SPECIAL,
|
|
|
|
HMM_PFN_VALUE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct hmm_range - track invalidation lock on virtual address range
|
|
|
|
*
|
2019-11-13 03:22:30 +07:00
|
|
|
* @notifier: a mmu_interval_notifier that includes the start/end
|
|
|
|
* @notifier_seq: result of mmu_interval_read_begin()
|
2018-04-11 06:29:06 +07:00
|
|
|
* @start: range virtual start address (inclusive)
|
|
|
|
* @end: range virtual end address (exclusive)
|
|
|
|
* @pfns: array of pfns (big enough for the range)
|
|
|
|
* @flags: pfn flags to match device driver page table
|
|
|
|
* @values: pfn value for some special case (none, special, error, ...)
|
2019-05-14 07:20:05 +07: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-28 03:00:15 +07:00
|
|
|
* @pfn_shift: pfn shift value (should be <= PAGE_SHIFT)
|
2020-03-17 02:32:16 +07:00
|
|
|
* @dev_private_owner: owner of device private pages
|
2018-04-11 06:29:06 +07:00
|
|
|
*/
|
|
|
|
struct hmm_range {
|
2019-11-13 03:22:20 +07:00
|
|
|
struct mmu_interval_notifier *notifier;
|
|
|
|
unsigned long notifier_seq;
|
2018-04-11 06:29:06 +07:00
|
|
|
unsigned long start;
|
|
|
|
unsigned long end;
|
|
|
|
uint64_t *pfns;
|
|
|
|
const uint64_t *flags;
|
|
|
|
const uint64_t *values;
|
2019-05-14 07:20:05 +07:00
|
|
|
uint64_t default_flags;
|
|
|
|
uint64_t pfn_flags_mask;
|
2018-04-11 06:29:06 +07:00
|
|
|
uint8_t pfn_shift;
|
2020-03-17 02:32:16 +07:00
|
|
|
void *dev_private_owner;
|
2018-04-11 06:29:06 +07:00
|
|
|
};
|
2017-09-09 06:11:23 +07:00
|
|
|
|
|
|
|
/*
|
2019-05-14 07:20:31 +07:00
|
|
|
* hmm_device_entry_to_page() - return struct page pointed to by a device entry
|
|
|
|
* @range: range use to decode device entry value
|
|
|
|
* @entry: device entry value to get corresponding struct page from
|
2019-05-07 06:29:39 +07:00
|
|
|
* Return: struct page pointer if entry is a valid, NULL otherwise
|
2017-09-09 06:11:23 +07:00
|
|
|
*
|
2019-05-14 07:20:31 +07:00
|
|
|
* If the device entry is valid (ie valid flag set) then return the struct page
|
|
|
|
* matching the entry value. Otherwise return NULL.
|
2017-09-09 06:11:23 +07:00
|
|
|
*/
|
2019-05-14 07:20:31 +07:00
|
|
|
static inline struct page *hmm_device_entry_to_page(const struct hmm_range *range,
|
|
|
|
uint64_t entry)
|
2017-09-09 06:11:23 +07:00
|
|
|
{
|
2019-05-14 07:20:31 +07:00
|
|
|
if (entry == range->values[HMM_PFN_NONE])
|
2018-04-11 06:29:06 +07:00
|
|
|
return NULL;
|
2019-05-14 07:20:31 +07:00
|
|
|
if (entry == range->values[HMM_PFN_ERROR])
|
2018-04-11 06:29:06 +07:00
|
|
|
return NULL;
|
2019-05-14 07:20:31 +07:00
|
|
|
if (entry == range->values[HMM_PFN_SPECIAL])
|
2017-09-09 06:11:23 +07:00
|
|
|
return NULL;
|
2019-05-14 07:20:31 +07:00
|
|
|
if (!(entry & range->flags[HMM_PFN_VALID]))
|
2018-04-11 06:29:06 +07:00
|
|
|
return NULL;
|
2019-05-14 07:20:31 +07:00
|
|
|
return pfn_to_page(entry >> range->pfn_shift);
|
2017-09-09 06:11:23 +07:00
|
|
|
}
|
|
|
|
|
2017-09-09 06:11:31 +07:00
|
|
|
/*
|
2019-05-14 07:20:01 +07:00
|
|
|
* Please see Documentation/vm/hmm.rst for how to use the range API.
|
2017-09-09 06:11:31 +07:00
|
|
|
*/
|
2020-03-28 03:00:16 +07:00
|
|
|
long hmm_range_fault(struct hmm_range *range);
|
2017-09-09 06:11:35 +07:00
|
|
|
|
|
|
|
/*
|
2019-05-14 07:20:01 +07:00
|
|
|
* HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range
|
2017-09-09 06:11:35 +07:00
|
|
|
*
|
2019-05-14 07:20:01 +07:00
|
|
|
* When waiting for mmu notifiers we need some kind of time out otherwise we
|
|
|
|
* could potentialy wait for ever, 1000ms ie 1s sounds like a long time to
|
|
|
|
* wait already.
|
2017-09-09 06:11:35 +07:00
|
|
|
*/
|
2019-05-14 07:20:01 +07:00
|
|
|
#define HMM_RANGE_DEFAULT_TIMEOUT 1000
|
|
|
|
|
2017-09-09 06:11:23 +07:00
|
|
|
#endif /* LINUX_HMM_H */
|