From: jglisse@redhat.com
To: linux-mm@kvack.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
"Jérôme Glisse" <jglisse@redhat.com>,
"Ralph Campbell" <rcampbell@nvidia.com>,
"John Hubbard" <jhubbard@nvidia.com>
Subject: [PATCH 6/7] mm/hmm: invalidate device page table at start of invalidation
Date: Fri, 24 Aug 2018 15:25:48 -0400 [thread overview]
Message-ID: <20180824192549.30844-7-jglisse@redhat.com> (raw)
In-Reply-To: <20180824192549.30844-1-jglisse@redhat.com>
From: JA(C)rA'me Glisse <jglisse@redhat.com>
Invalidate device page table at start of invalidation and invalidate
in progress CPU page table snapshooting at both start and end of any
invalidation.
This is helpful when device need to dirty page because the device page
table report the page as dirty. Dirtying page must happen in the start
mmu notifier callback and not in the end one.
Signed-off-by: JA(C)rA'me Glisse <jglisse@redhat.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/hmm.h | 2 +-
mm/hmm.c | 21 ++++++++++++++-------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/include/linux/hmm.h b/include/linux/hmm.h
index a7f7600b6bb0..064924bce75c 100644
--- a/include/linux/hmm.h
+++ b/include/linux/hmm.h
@@ -325,7 +325,7 @@ struct hmm_mirror_ops {
* synchronous call.
*/
void (*sync_cpu_device_pagetables)(struct hmm_mirror *mirror,
- const struct hmm_update *update);
+ const struct hmm_update *update);
};
/*
diff --git a/mm/hmm.c b/mm/hmm.c
index debd2f734ab5..6fe31e2bfa1e 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -43,7 +43,6 @@ static const struct mmu_notifier_ops hmm_mmu_notifier_ops;
*
* @mm: mm struct this HMM struct is bound to
* @lock: lock protecting ranges list
- * @sequence: we track updates to the CPU page table with a sequence number
* @ranges: list of range being snapshotted
* @mirrors: list of mirrors for this mm
* @mmu_notifier: mmu notifier to track updates to CPU page table
@@ -52,7 +51,6 @@ static const struct mmu_notifier_ops hmm_mmu_notifier_ops;
struct hmm {
struct mm_struct *mm;
spinlock_t lock;
- atomic_t sequence;
struct list_head ranges;
struct list_head mirrors;
struct mmu_notifier mmu_notifier;
@@ -85,7 +83,6 @@ static struct hmm *hmm_register(struct mm_struct *mm)
return NULL;
INIT_LIST_HEAD(&hmm->mirrors);
init_rwsem(&hmm->mirrors_sem);
- atomic_set(&hmm->sequence, 0);
hmm->mmu_notifier.ops = NULL;
INIT_LIST_HEAD(&hmm->ranges);
spin_lock_init(&hmm->lock);
@@ -126,8 +123,8 @@ void hmm_mm_destroy(struct mm_struct *mm)
kfree(mm->hmm);
}
-static void hmm_invalidate_range(struct hmm *hmm,
- const struct hmm_update *update)
+static void hmm_invalidate_range(struct hmm *hmm, bool device,
+ const struct hmm_update *update)
{
struct hmm_mirror *mirror;
struct hmm_range *range;
@@ -147,6 +144,9 @@ static void hmm_invalidate_range(struct hmm *hmm,
}
spin_unlock(&hmm->lock);
+ if (!device)
+ return;
+
down_read(&hmm->mirrors_sem);
list_for_each_entry(mirror, &hmm->mirrors, list)
mirror->ops->sync_cpu_device_pagetables(mirror, update);
@@ -185,11 +185,18 @@ static int hmm_invalidate_range_start(struct mmu_notifier *mn,
unsigned long end,
bool blockable)
{
+ struct hmm_update update;
struct hmm *hmm = mm->hmm;
+ if (!blockable)
+ return -EAGAIN;
+
VM_BUG_ON(!hmm);
- atomic_inc(&hmm->sequence);
+ update.start = start;
+ update.end = end;
+ update.event = HMM_UPDATE_INVALIDATE;
+ hmm_invalidate_range(hmm, true, &update);
return 0;
}
@@ -207,7 +214,7 @@ static void hmm_invalidate_range_end(struct mmu_notifier *mn,
update.start = start;
update.end = end;
update.event = HMM_UPDATE_INVALIDATE;
- hmm_invalidate_range(hmm, &update);
+ hmm_invalidate_range(hmm, false, &update);
}
static const struct mmu_notifier_ops hmm_mmu_notifier_ops = {
--
2.17.1
next prev parent reply other threads:[~2018-08-24 19:25 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-24 19:25 [PATCH 0/7] HMM updates, improvements and fixes jglisse
2018-08-24 19:25 ` [PATCH 1/7] mm/hmm: fix utf8 jglisse
2018-08-24 19:25 ` [PATCH 2/7] mm/rmap: map_pte() was not handling private ZONE_DEVICE page properly jglisse
2018-08-30 14:05 ` Balbir Singh
2018-08-30 14:34 ` Jerome Glisse
2018-08-30 14:41 ` [PATCH 3/7] mm/rmap: map_pte() was not handling private ZONE_DEVICE page properly v2 jglisse
2018-08-31 9:27 ` Balbir Singh
2018-08-31 16:19 ` Jerome Glisse
2018-09-02 6:58 ` Balbir Singh
2018-08-24 19:25 ` [PATCH 3/7] mm/hmm: fix race between hmm_mirror_unregister() and mmu_notifier callback jglisse
2018-08-30 14:14 ` Balbir Singh
2018-08-24 19:25 ` [PATCH 4/7] mm/hmm: properly handle migration pmd jglisse
2018-08-25 0:05 ` Zi Yan
2018-08-28 0:35 ` Jerome Glisse
2018-08-28 15:24 ` Michal Hocko
2018-08-28 15:36 ` Jerome Glisse
2018-08-28 15:42 ` Michal Hocko
2018-08-28 15:45 ` Michal Hocko
2018-08-28 15:54 ` Zi Yan
2018-08-28 16:06 ` Jerome Glisse
2018-08-28 16:10 ` Michal Hocko
2018-08-29 17:17 ` [PATCH 4/7] mm/hmm: properly handle migration pmd v2 jglisse
2018-08-24 19:25 ` [PATCH 5/7] mm/hmm: use a structure for update callback parameters jglisse
2018-08-30 23:11 ` Balbir Singh
2018-08-31 16:12 ` Jerome Glisse
2018-08-24 19:25 ` jglisse [this message]
2018-08-24 19:25 ` [PATCH 7/7] mm/hmm: proper support for blockable mmu_notifier jglisse
2018-10-12 18:15 ` [PATCH 0/7] HMM updates, improvements and fixes Jerome Glisse
2018-10-12 21:12 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180824192549.30844-7-jglisse@redhat.com \
--to=jglisse@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rcampbell@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).