2020-02-07 20:34:33 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
|
|
|
|
/*
|
|
|
|
* Copyright 2020-2021 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KFD_MIGRATE_H_
|
|
|
|
#define KFD_MIGRATE_H_
|
|
|
|
|
2021-03-29 22:49:12 +00:00
|
|
|
#if IS_ENABLED(CONFIG_HSA_AMD_SVM)
|
|
|
|
|
2020-02-07 20:34:33 +00:00
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/sched/mm.h>
|
|
|
|
#include <linux/hmm.h>
|
|
|
|
#include "kfd_priv.h"
|
|
|
|
#include "kfd_svm.h"
|
|
|
|
|
2020-02-07 22:08:04 +00:00
|
|
|
enum MIGRATION_COPY_DIR {
|
|
|
|
FROM_RAM_TO_VRAM = 0,
|
|
|
|
FROM_VRAM_TO_RAM
|
|
|
|
};
|
|
|
|
|
2021-02-25 04:57:33 +00:00
|
|
|
int svm_migrate_to_vram(struct svm_range *prange, uint32_t best_loc,
|
|
|
|
struct mm_struct *mm);
|
2021-03-17 04:24:12 +00:00
|
|
|
int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm);
|
|
|
|
unsigned long
|
|
|
|
svm_migrate_addr_to_pfn(struct amdgpu_device *adev, unsigned long addr);
|
drm/amdkfd: HMM migrate ram to vram
Register svm range with same address and size but perferred_location
is changed from CPU to GPU or from GPU to CPU, trigger migration the svm
range from ram to vram or from vram to ram.
If svm range prefetch location is GPU with flags
KFD_IOCTL_SVM_FLAG_HOST_ACCESS, validate the svm range on ram first,
then migrate it from ram to vram.
After migrating to vram is done, CPU access will have cpu page fault,
page fault handler migrate it back to ram and resume cpu access.
Migration steps:
1. migrate_vma_pages get svm range ram pages, notify the
interval is invalidated and unmap from CPU page table, HMM interval
notifier callback evict process queues
2. Allocate new pages in vram using TTM
3. Use svm copy memory to sdma copy data from ram to vram
4. migrate_vma_pages copy ram pages structure to vram pages structure
5. migrate_vma_finalize put ram pages to free ram pages and memory
6. Restore work wait for migration is finished, then update GPUs page
table mapping to new vram pages, resume process queues
If migrate_vma_setup failed to collect all ram pages of range, retry 3
times until success to start migration.
Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2021-02-25 01:40:20 +00:00
|
|
|
|
2020-02-07 20:34:33 +00:00
|
|
|
int svm_migrate_init(struct amdgpu_device *adev);
|
|
|
|
void svm_migrate_fini(struct amdgpu_device *adev);
|
|
|
|
|
|
|
|
#else
|
2021-03-29 22:49:12 +00:00
|
|
|
|
2020-02-07 20:34:33 +00:00
|
|
|
static inline int svm_migrate_init(struct amdgpu_device *adev)
|
|
|
|
{
|
2021-03-29 22:49:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void svm_migrate_fini(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
/* empty */
|
2020-02-07 20:34:33 +00:00
|
|
|
}
|
2021-03-29 22:49:12 +00:00
|
|
|
|
|
|
|
#endif /* IS_ENABLED(CONFIG_HSA_AMD_SVM) */
|
|
|
|
|
2020-02-07 20:34:33 +00:00
|
|
|
#endif /* KFD_MIGRATE_H_ */
|