linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Small HMM fixes
@ 2018-03-26 21:30 jglisse
  2018-03-26 21:30 ` [PATCH 1/2] mm/hmm: do not ignore specific pte fault flag in hmm_vma_fault() jglisse
  2018-03-26 21:30 ` [PATCH 2/2] mm/hmm: clarify fault logic for device private memory jglisse
  0 siblings, 2 replies; 3+ messages in thread
From: jglisse @ 2018-03-26 21:30 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, linux-kernel, Jérôme Glisse,
	Ralph Campbell, Evgeny Baskakov, Mark Hairgrove, John Hubbard

From: Jérôme Glisse <jglisse@redhat.com>

Two small fixes on top of what i already sent. First one fix a real
dumb mistake (i did). Second one fix fault logic to be consistant in
respect to all combinations.

No cc-ing stable for lack of current upstream user.

Kudos to Ralph for catching those.

Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Evgeny Baskakov <ebaskakov@nvidia.com>
Cc: Mark Hairgrove <mhairgrove@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>

Ralph Campbell (2):
  mm/hmm: do not ignore specific pte fault flag in hmm_vma_fault()
  mm/hmm: clarify fault logic for device private memory

 mm/hmm.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

-- 
2.14.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] mm/hmm: do not ignore specific pte fault flag in hmm_vma_fault()
  2018-03-26 21:30 [PATCH 0/2] Small HMM fixes jglisse
@ 2018-03-26 21:30 ` jglisse
  2018-03-26 21:30 ` [PATCH 2/2] mm/hmm: clarify fault logic for device private memory jglisse
  1 sibling, 0 replies; 3+ messages in thread
From: jglisse @ 2018-03-26 21:30 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, linux-kernel, Ralph Campbell,
	Jérôme Glisse, Evgeny Baskakov, Mark Hairgrove,
	John Hubbard

From: Ralph Campbell <rcampbell@nvidia.com>

Save requested fault flags from caller supplied pfns array before
overwriting it with the special none value. Without this we would
not fault on all cases requested by caller, leading to caller calling
us in a loop unless something else did change the CPU page table.

Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Cc: Evgeny Baskakov <ebaskakov@nvidia.com>
Cc: Mark Hairgrove <mhairgrove@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
---
 mm/hmm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/hmm.c b/mm/hmm.c
index e4742f6f1e05..ba912da1c1a1 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -498,10 +498,11 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
 	bool fault, write_fault;
 	uint64_t cpu_flags;
 	pte_t pte = *ptep;
+	uint64_t orig_pfn = *pfn;
 
 	*pfn = range->values[HMM_PFN_NONE];
 	cpu_flags = pte_to_hmm_pfn_flags(range, pte);
-	hmm_pte_need_fault(hmm_vma_walk, *pfn, cpu_flags,
+	hmm_pte_need_fault(hmm_vma_walk, orig_pfn, cpu_flags,
 			   &fault, &write_fault);
 
 	if (pte_none(pte)) {
@@ -528,7 +529,7 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
 				range->flags[HMM_PFN_DEVICE_PRIVATE];
 			cpu_flags |= is_write_device_private_entry(entry) ?
 				range->flags[HMM_PFN_WRITE] : 0;
-			hmm_pte_need_fault(hmm_vma_walk, *pfn, cpu_flags,
+			hmm_pte_need_fault(hmm_vma_walk, orig_pfn, cpu_flags,
 					   &fault, &write_fault);
 			if (fault || write_fault)
 				goto fault;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mm/hmm: clarify fault logic for device private memory
  2018-03-26 21:30 [PATCH 0/2] Small HMM fixes jglisse
  2018-03-26 21:30 ` [PATCH 1/2] mm/hmm: do not ignore specific pte fault flag in hmm_vma_fault() jglisse
@ 2018-03-26 21:30 ` jglisse
  1 sibling, 0 replies; 3+ messages in thread
From: jglisse @ 2018-03-26 21:30 UTC (permalink / raw)
  To: linux-mm
  Cc: Andrew Morton, linux-kernel, Ralph Campbell,
	Jérôme Glisse, Evgeny Baskakov, Mark Hairgrove,
	John Hubbard

From: Ralph Campbell <rcampbell@nvidia.com>

For device private memory caller of hmm_vma_fault() want to be able to
carefully control fault behavior. Update logic to only fault on device
private entry if explicitly requested.

Before this patch a read only device private CPU page table entry would
fault if caller requested write permission without the device private
flag set (in caller's flag fault request). After this patch it will only
fault if the device private flag is also set.

Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Cc: Evgeny Baskakov <ebaskakov@nvidia.com>
Cc: Mark Hairgrove <mhairgrove@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
---
 mm/hmm.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/mm/hmm.c b/mm/hmm.c
index ba912da1c1a1..398d0214be66 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -390,18 +390,22 @@ static inline void hmm_pte_need_fault(const struct hmm_vma_walk *hmm_vma_walk,
 	/* We aren't ask to do anything ... */
 	if (!(pfns & range->flags[HMM_PFN_VALID]))
 		return;
+	/* If this is device memory than only fault if explicitly requested */
+	if ((cpu_flags & range->flags[HMM_PFN_DEVICE_PRIVATE])) {
+		/* Do we fault on device memory ? */
+		if (pfns & range->flags[HMM_PFN_DEVICE_PRIVATE]) {
+			*write_fault = pfns & range->flags[HMM_PFN_WRITE];
+			*fault = true;
+		}
+		return;
+	}
+
 	/* If CPU page table is not valid then we need to fault */
-	*fault = cpu_flags & range->flags[HMM_PFN_VALID];
+	*fault = !(cpu_flags & range->flags[HMM_PFN_VALID]);
 	/* Need to write fault ? */
 	if ((pfns & range->flags[HMM_PFN_WRITE]) &&
 	    !(cpu_flags & range->flags[HMM_PFN_WRITE])) {
-		*fault = *write_fault = false;
-		return;
-	}
-	/* Do we fault on device memory ? */
-	if ((pfns & range->flags[HMM_PFN_DEVICE_PRIVATE]) &&
-	    (cpu_flags & range->flags[HMM_PFN_DEVICE_PRIVATE])) {
-		*write_fault = pfns & range->flags[HMM_PFN_WRITE];
+		*write_fault = true;
 		*fault = true;
 	}
 }
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-26 21:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-26 21:30 [PATCH 0/2] Small HMM fixes jglisse
2018-03-26 21:30 ` [PATCH 1/2] mm/hmm: do not ignore specific pte fault flag in hmm_vma_fault() jglisse
2018-03-26 21:30 ` [PATCH 2/2] mm/hmm: clarify fault logic for device private memory jglisse

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).