Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1353336
| Path | csiph.com!aioe.org!gothmog.csi.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Jérôme Glisse <jglisse@redhat.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH v12 27/29] HMM: fork copy migrated memory into system memory for child process. |
| Date | Tue, 08 Mar 2016 20:50:02 +0100 |
| Message-ID | <ravNM-5ru-7@gated-at.bofh.it> (permalink) |
| References | <ravNL-5ru-3@gated-at.bofh.it> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Scanned-By | MIMEDefang 2.68 on 10.5.11.24 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 68 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Linus Torvalds <torvalds@linux-foundation.org>, <joro@8bytes.org>, Mel Gorman <mgorman@suse.de>, "H. Peter Anvin" <hpa@zytor.com>, Peter Zijlstra <peterz@infradead.org>, Andrea Arcangeli <aarcange@redhat.com>, Johannes Weiner <jweiner@redhat.com>, Larry Woodman <lwoodman@redhat.com>, Rik van Riel <riel@redhat.com>, Dave Airlie <airlied@redhat.com>, Brendan Conoboy <blc@redhat.com>, Joe Donohue <jdonohue@redhat.com>, Christophe Harle <charle@nvidia.com>, Duncan Poole <dpoole@nvidia.com>, Sherry Cheung <SCheung@nvidia.com>, Subhash Gutti <sgutti@nvidia.com>, John Hubbard <jhubbard@nvidia.com>, Mark Hairgrove <mhairgrove@nvidia.com>, Lucien Dunning <ldunning@nvidia.com>, Cameron Buschardt <cabuschardt@nvidia.com>, Arvind Gopalakrishnan <arvindg@nvidia.com>, Haggai Eran <haggaie@mellanox.com>, Shachar Raindel <raindel@mellanox.com>, Liran Liss <liranl@mellanox.com>, Roland Dreier <roland@purestorage.com>, Ben Sander <ben.sander@amd.com>, Greg Stoner <Greg.Stoner@amd.com>, John Bridgman <John.Bridgman@amd.com>, Michael Mantor <Michael.Mantor@amd.com>, Paul Blinzer <Paul.Blinzer@amd.com>, Leonid Shamis <Leonid.Shamis@amd.com>, Laurent Morichetti <Laurent.Morichetti@amd.com>, Alexander Deucher <Alexander.Deucher@amd.com>, Jérôme Glisse <jglisse@redhat.com> |
| X-Original-Date | Tue, 8 Mar 2016 15:43:20 -0500 |
| X-Original-Message-ID | <1457469802-11850-28-git-send-email-jglisse@redhat.com> |
| X-Original-References | <1457469802-11850-1-git-send-email-jglisse@redhat.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1353336 |
Show key headers only | View raw
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@redhat.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
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH v12 27/29] HMM: fork copy migrated memory into system memory for child process. Jérôme Glisse <jglisse@redhat.com> - 2016-03-08 20:50 +0100
csiph-web