mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
2733ea144d
Presumably the intent here was that hmm_range_fault() could put the data into some HW specific format and thus avoid some work. However, nothing actually does that, and it isn't clear how anything actually could do that as hmm_range_fault() provides CPU addresses which must be DMA mapped. Perhaps there is some special HW that does not need DMA mapping, but we don't have any examples of this, and the theoretical performance win of avoiding an extra scan over the pfns array doesn't seem worth the complexity. Plus pfns needs to be scanned anyhow to sort out any DEVICE_PRIVATE pages. This version replaces the uint64_t with an usigned long containing a pfn and fixed flags. On input flags is filled with the HMM_PFN_REQ_* values, on successful output it is filled with HMM_PFN_* values, describing the state of the pages. amdgpu is simple to convert, it doesn't use snapshot and doesn't use per-page flags. nouveau uses only 16 hmm_pte entries at most (ie fits in a few cache lines), and it sweeps over its pfns array a couple of times anyhow. It also has a nasty call chain before it reaches the dma map and hardware suggesting performance isn't important: nouveau_svm_fault(): args.i.m.method = NVIF_VMM_V0_PFNMAP nouveau_range_fault() nvif_object_ioctl() client->driver->ioctl() struct nvif_driver nvif_driver_nvkm: .ioctl = nvkm_client_ioctl nvkm_ioctl() nvkm_ioctl_path() nvkm_ioctl_v0[type].func(..) nvkm_ioctl_mthd() nvkm_object_mthd() struct nvkm_object_func nvkm_uvmm: .mthd = nvkm_uvmm_mthd nvkm_uvmm_mthd() nvkm_uvmm_mthd_pfnmap() nvkm_vmm_pfn_map() nvkm_vmm_ptes_get_map() func == gp100_vmm_pgt_pfn struct nvkm_vmm_desc_func gp100_vmm_desc_spt: .pfn = gp100_vmm_pgt_pfn nvkm_vmm_iter() REF_PTES == func == gp100_vmm_pgt_pfn() dma_map_page() Link: https://lore.kernel.org/r/5-v2-b4e84f444c7d+24f57-hmm_no_flags_jgg@mellanox.com Acked-by: Felix Kuehling <Felix.Kuehling@amd.com> Tested-by: Ralph Campbell <rcampbell@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
102 lines
3.3 KiB
C
102 lines
3.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright 2013 Red Hat Inc.
|
|
*
|
|
* Authors: Jérôme Glisse <jglisse@redhat.com>
|
|
*
|
|
* See Documentation/vm/hmm.rst for reasons and overview of what HMM is.
|
|
*/
|
|
#ifndef LINUX_HMM_H
|
|
#define LINUX_HMM_H
|
|
|
|
#include <linux/kconfig.h>
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/migrate.h>
|
|
#include <linux/memremap.h>
|
|
#include <linux/completion.h>
|
|
#include <linux/mmu_notifier.h>
|
|
|
|
/*
|
|
* 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
|
|
*
|
|
* 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.
|
|
*/
|
|
enum hmm_pfn_flags {
|
|
/* Output flags */
|
|
HMM_PFN_VALID = 1UL << (BITS_PER_LONG - 1),
|
|
HMM_PFN_WRITE = 1UL << (BITS_PER_LONG - 2),
|
|
HMM_PFN_ERROR = 1UL << (BITS_PER_LONG - 3),
|
|
|
|
/* Input flags */
|
|
HMM_PFN_REQ_FAULT = HMM_PFN_VALID,
|
|
HMM_PFN_REQ_WRITE = HMM_PFN_WRITE,
|
|
|
|
HMM_PFN_FLAGS = HMM_PFN_VALID | HMM_PFN_WRITE | HMM_PFN_ERROR,
|
|
};
|
|
|
|
/*
|
|
* hmm_pfn_to_page() - return struct page pointed to by a device entry
|
|
*
|
|
* 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 struct page *hmm_pfn_to_page(unsigned long hmm_pfn)
|
|
{
|
|
return pfn_to_page(hmm_pfn & ~HMM_PFN_FLAGS);
|
|
}
|
|
|
|
/*
|
|
* struct hmm_range - track invalidation lock on virtual address range
|
|
*
|
|
* @notifier: a mmu_interval_notifier that includes the start/end
|
|
* @notifier_seq: result of mmu_interval_read_begin()
|
|
* @start: range virtual start address (inclusive)
|
|
* @end: range virtual end address (exclusive)
|
|
* @hmm_pfns: array of pfns (big enough for the range)
|
|
* @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
|
|
* @dev_private_owner: owner of device private pages
|
|
*/
|
|
struct hmm_range {
|
|
struct mmu_interval_notifier *notifier;
|
|
unsigned long notifier_seq;
|
|
unsigned long start;
|
|
unsigned long end;
|
|
unsigned long *hmm_pfns;
|
|
unsigned long default_flags;
|
|
unsigned long pfn_flags_mask;
|
|
void *dev_private_owner;
|
|
};
|
|
|
|
/*
|
|
* Please see Documentation/vm/hmm.rst for how to use the range API.
|
|
*/
|
|
int hmm_range_fault(struct hmm_range *range);
|
|
|
|
/*
|
|
* HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range
|
|
*
|
|
* 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.
|
|
*/
|
|
#define HMM_RANGE_DEFAULT_TIMEOUT 1000
|
|
|
|
#endif /* LINUX_HMM_H */
|