Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1253179

[PATCH v11 14/15] HMM: Add support for hugetlb.

From Jérôme Glisse <jglisse@redhat.com>
Newsgroups linux.kernel
Subject [PATCH v11 14/15] HMM: Add support for hugetlb.
Date 2015-10-21 22:10 +0200
Message-ID <qm7RV-54Y-47@gated-at.bofh.it> (permalink)
References <qm7RT-54Y-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Support hugetlb vma allmost like other vma. Exception being that we
will not support migration of hugetlb memory.

Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
---
 mm/hmm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/mm/hmm.c b/mm/hmm.c
index 6ed1081..9e5017a 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -809,6 +809,65 @@ static int hmm_mirror_fault_pmd(pmd_t *pmdp,
 	return ret;
 }
 
+static int hmm_mirror_fault_hugetlb_entry(pte_t *ptep,
+					  unsigned long hmask,
+					  unsigned long addr,
+					  unsigned long end,
+					  struct mm_walk *walk)
+{
+#ifdef CONFIG_HUGETLB_PAGE
+	struct hmm_mirror_fault *mirror_fault = walk->private;
+	struct hmm_event *event = mirror_fault->event;
+	struct hmm_pt_iter *iter = mirror_fault->iter;
+	bool write = (event->etype == HMM_DEVICE_WFAULT);
+	unsigned long pfn, next;
+	dma_addr_t *hmm_pte;
+	pte_t pte;
+
+	/*
+	 * Hugepages under user process are always in RAM and never
+	 * swapped out, but theoretically it needs to be checked.
+	 */
+	if (!ptep)
+		return -ENOENT;
+
+	pte = huge_ptep_get(ptep);
+	pfn = pte_pfn(pte);
+	if (!huge_pte_none(pte) || (write && !huge_pte_write(pte)))
+		return -ENOENT;
+
+	hmm_pte = hmm_pt_iter_populate(iter, addr, &next);
+	if (!hmm_pte)
+		return -ENOMEM;
+	hmm_pt_iter_directory_lock(iter);
+	for (; addr != end; addr += PAGE_SIZE, ++pfn, ++hmm_pte) {
+		/* Switch to another HMM page table directory ? */
+		if (addr == next) {
+			hmm_pt_iter_directory_unlock(iter);
+			hmm_pte = hmm_pt_iter_populate(iter, addr, &next);
+			if (!hmm_pte)
+				return -ENOMEM;
+			hmm_pt_iter_directory_lock(iter);
+		}
+
+		if (hmm_pte_test_valid_dma(hmm_pte))
+			continue;
+
+		if (!hmm_pte_test_valid_pfn(hmm_pte)) {
+			*hmm_pte = hmm_pte_from_pfn(pfn);
+			hmm_pt_iter_directory_ref(iter);
+		}
+		BUG_ON(hmm_pte_pfn(*hmm_pte) != pfn);
+		if (write)
+			hmm_pte_set_write(hmm_pte);
+	}
+	hmm_pt_iter_directory_unlock(iter);
+#else
+	BUG();
+#endif
+	return 0;
+}
+
 static int hmm_mirror_dma_map(struct hmm_mirror *mirror,
 			      struct hmm_pt_iter *iter,
 			      unsigned long start,
@@ -916,6 +975,7 @@ static int hmm_mirror_handle_fault(struct hmm_mirror *mirror,
 		walk.mm = mirror->hmm->mm;
 		walk.private = &mirror_fault;
 		walk.pmd_entry = hmm_mirror_fault_pmd;
+		walk.hugetlb_entry = hmm_mirror_fault_hugetlb_entry;
 		walk.pte_hole = hmm_pte_hole;
 		ret = walk_page_range(addr, event->end, &walk);
 		if (ret)
@@ -1002,7 +1062,7 @@ retry:
 		goto out;
 	}
 	event->end = min(event->end, vma->vm_end) & PAGE_MASK;
-	if ((vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP | VM_HUGETLB))) {
+	if ((vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP))) {
 		ret = -EFAULT;
 		goto out;
 	}
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v11 00/15] HMM (Heterogeneous Memory Management) Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 03/15] mmu_notifier: pass page pointer to mmu_notifier_invalidate_page() v2 Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 06/15] HMM: add HMM page table v4. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 07/15] HMM: add per mirror page table v4. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 15/15] HMM: add documentation explaining HMM internals and how to use it. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
    Re: [PATCH v11 15/15] HMM: add documentation explaining HMM internals  and how to use it. Randy Dunlap <rdunlap@infradead.org> - 2015-10-22 05:30 +0200
      Re: [PATCH v11 15/15] HMM: add documentation explaining HMM  internals and how to use it. Jerome Glisse <jglisse@redhat.com> - 2015-10-22 16:20 +0200
      Re: [PATCH v11 15/15] HMM: add documentation explaining HMM  internals and how to use it. David Woodhouse <dwmw2@infradead.org> - 2015-10-28 02:20 +0100
        Re: [PATCH v11 15/15] HMM: add documentation explaining HMM internals  and how to use it. Randy Dunlap <rdunlap@infradead.org> - 2015-10-28 18:20 +0100
  [PATCH v11 04/15] mmu_notifier: allow range invalidation to exclude a specific mmu_notifier Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 05/15] HMM: introduce heterogeneous memory management v5. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
    Re: [PATCH v11 05/15] HMM: introduce heterogeneous memory management  v5. Randy Dunlap <rdunlap@infradead.org> - 2015-10-21 22:20 +0200
  [PATCH v11 11/15] HMM: add discard range helper (to clear and free resources for a range). Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 14/15] HMM: Add support for hugetlb. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 13/15] HMM: DMA map memory on behalf of device driver v2. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 09/15] HMM: add mm page table iterator helpers. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200
  [PATCH v11 08/15] HMM: add device page fault support v6. Jérôme Glisse <jglisse@redhat.com> - 2015-10-21 22:10 +0200

csiph-web