Skip to contentSkip to conversation

Small HMM fixes

PATCH New [email protected] 1 participant 3 messages Mar 26, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Small HMM fixes

From: JA(C)rA'me Glisse <[email protected]>

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 <[email protected]>
Cc Evgeny Baskakov <[email protected]>
Cc Mark Hairgrove <[email protected]>
Cc John Hubbard <[email protected]>

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(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/2 mm/hmm: do not ignore specific pte fault flag in hmm_vma_fault()

From: Ralph Campbell <[email protected]>

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.

Cc Evgeny Baskakov <[email protected]>
Cc Mark Hairgrove <[email protected]>
Cc John Hubbard <[email protected]>
---
 mm/hmm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/hmm.c +3 -2
index e4742f6f1e05..ba912da1c1a1 100644
@@ -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;
Signature · 1 line
2.14.3
#2 lore raw

PATCH 2/2 mm/hmm: clarify fault logic for device private memory

In reply to [email protected]

From: Ralph Campbell <[email protected]>

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.

Cc Evgeny Baskakov <[email protected]>
Cc Mark Hairgrove <[email protected]>
Cc John Hubbard <[email protected]>
---
 mm/hmm.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
mm/hmm.c +12 -8
index ba912da1c1a1..398d0214be66 100644
@@ -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;
 	}
 }
Signature · 1 line
2.14.3