[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1457469802-11850-28-git-send-email-jglisse@redhat.com>
Date: Tue, 8 Mar 2016 15:43:20 -0500
From: Jérôme Glisse <jglisse@...hat.com>
To: akpm@...ux-foundation.org, <linux-kernel@...r.kernel.org>,
linux-mm@...ck.org
Cc: Linus Torvalds <torvalds@...ux-foundation.org>, <joro@...tes.org>,
Mel Gorman <mgorman@...e.de>, "H. Peter Anvin" <hpa@...or.com>,
Peter Zijlstra <peterz@...radead.org>,
Andrea Arcangeli <aarcange@...hat.com>,
Johannes Weiner <jweiner@...hat.com>,
Larry Woodman <lwoodman@...hat.com>,
Rik van Riel <riel@...hat.com>,
Dave Airlie <airlied@...hat.com>,
Brendan Conoboy <blc@...hat.com>,
Joe Donohue <jdonohue@...hat.com>,
Christophe Harle <charle@...dia.com>,
Duncan Poole <dpoole@...dia.com>,
Sherry Cheung <SCheung@...dia.com>,
Subhash Gutti <sgutti@...dia.com>,
John Hubbard <jhubbard@...dia.com>,
Mark Hairgrove <mhairgrove@...dia.com>,
Lucien Dunning <ldunning@...dia.com>,
Cameron Buschardt <cabuschardt@...dia.com>,
Arvind Gopalakrishnan <arvindg@...dia.com>,
Haggai Eran <haggaie@...lanox.com>,
Shachar Raindel <raindel@...lanox.com>,
Liran Liss <liranl@...lanox.com>,
Roland Dreier <roland@...estorage.com>,
Ben Sander <ben.sander@....com>,
Greg Stoner <Greg.Stoner@....com>,
John Bridgman <John.Bridgman@....com>,
Michael Mantor <Michael.Mantor@....com>,
Paul Blinzer <Paul.Blinzer@....com>,
Leonid Shamis <Leonid.Shamis@....com>,
Laurent Morichetti <Laurent.Morichetti@....com>,
Alexander Deucher <Alexander.Deucher@....com>,
Jérôme Glisse <jglisse@...hat.com>
Subject: [PATCH v12 27/29] HMM: fork copy migrated memory into system memory for child process.
When forking if process being fork had any memory migrated to some
device memory, we need to make a system copy for the child process.
Latter patches can revisit this and use the same COW semantic for
device memory.
Signed-off-by: Jérôme Glisse <jglisse@...hat.com>
---
mm/hmm.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/mm/hmm.c b/mm/hmm.c
index 435e376..4dcd98f 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -483,7 +483,37 @@ int hmm_mm_fork(struct mm_struct *src_mm,
unsigned long start,
unsigned long end)
{
- return -ENOMEM;
+ unsigned long npages = (end - start) >> PAGE_SHIFT;
+ struct hmm_event event;
+ dma_addr_t *dst;
+ struct hmm *hmm;
+ pte_t *new_pte;
+ int ret;
+
+ hmm = hmm_ref(src_mm->hmm);
+ if (!hmm)
+ return -EINVAL;
+
+
+ dst = kcalloc(npages, sizeof(*dst), GFP_KERNEL);
+ if (!dst) {
+ hmm_unref(hmm);
+ return -ENOMEM;
+ }
+ new_pte = kcalloc(npages, sizeof(*new_pte), GFP_KERNEL);
+ if (!new_pte) {
+ kfree(dst);
+ hmm_unref(hmm);
+ return -ENOMEM;
+ }
+
+ hmm_event_init(&event, hmm, start, end, HMM_FORK);
+ ret = hmm_migrate_back(hmm, &event, dst_mm, dst_vma, new_pte,
+ dst, start, end);
+ hmm_unref(hmm);
+ kfree(new_pte);
+ kfree(dst);
+ return ret;
}
EXPORT_SYMBOL(hmm_mm_fork);
@@ -665,6 +695,12 @@ static void hmm_mirror_update_pte(struct hmm_mirror *mirror,
}
if (hmm_pte_test_valid_dev(hmm_pte)) {
+ /*
+ * On fork device memory is duplicated so no need to write
+ * protect it.
+ */
+ if (event->etype == HMM_FORK)
+ return;
*hmm_pte &= event->pte_mask;
if (!hmm_pte_test_valid_dev(hmm_pte))
hmm_pt_iter_directory_unref(iter);
--
2.4.3
Powered by blists - more mailing lists