From 2f770192125f5692ad1151512e0a6b748089386c Mon Sep 17 00:00:00 2001 From: Guanghui Zhou Date: Mon, 11 Nov 2019 11:51:07 +0800 Subject: [PATCH] mm: insert hugepage pte by pa scend inclusion category: feature bugzilla: NA CVE: NA ------------------- The cross OS sdma copy needs to map the OS's physical address to the tx-atu of the remote device through PCIE. However, the sdma copy only receives the virtual address, thus a page table is necessary to provide mapping between tx-atu and the virtual address. Signed-off-by: Guanghui Zhou Signed-off-by: LI Heng Signed-off-by: Lijun Fang Reviewed-by: Kefeng Wang Signed-off-by: Yang Yingliang --- mm/hugetlb.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5163775eaa81..833ab71427a0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5196,4 +5196,28 @@ int hugetlb_insert_hugepage_pte(struct mm_struct *mm, unsigned long addr, } EXPORT_SYMBOL_GPL(hugetlb_insert_hugepage_pte); +int hugetlb_insert_hugepage_pte_by_pa(struct mm_struct *mm, + unsigned long vir_addr, + pgprot_t prot, unsigned long phy_addr) +{ + pte_t *ptep, entry; + struct hstate *h = &default_hstate; + + ptep = hugetlb_huge_pte_alloc(mm, vir_addr, huge_page_size(h)); + if (!ptep) + return -ENXIO; + + WARN_ON(ptep && !pte_none(*ptep) && !pte_huge(*ptep)); + + entry = pfn_pte(phy_addr >> PAGE_SHIFT, prot); + entry = huge_pte_mkdirty(entry); + entry = huge_pte_mkwrite(entry); + entry = pte_mkyoung(entry); + entry = pte_mkhuge(entry); + entry = pte_mkspecial(entry); + set_huge_pte_at(mm, vir_addr, ptep, entry); + return 0; +} +EXPORT_SYMBOL_GPL(hugetlb_insert_hugepage_pte_by_pa); + #endif -- GitLab