Skip to contentSkip to conversation

mm/hmm: fault non-owner device private entries

PATCH Superseded Ralph Campbell 5 participants 9 messages Jul 22, 2022 – Jul 25, 2022

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hmm: fault non-owner device private entries

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

Fixes 76612d6ce4cc ("mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte()")
---
 mm/hmm.c | 3 +++
 1 file changed, 3 insertions(+)
mm/hmm.c +3 -0
index 3fd3242c5e50..7db2b29bdc85 100644
@@ -273,6 +273,9 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
 		if (!non_swap_entry(entry))
 			goto fault;
 
+		if (is_device_private_entry(entry))
+			goto fault;
+
 		if (is_device_exclusive_entry(entry))
 			goto fault;
 
Signature · 1 line
2.35.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ralph Campbell

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

Quoted 7 lines
Fixes 76612d6ce4cc ("mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte()")
---
 mm/hmm.c | 3 +++
 1 file changed, 3 insertions(+)

Should we have a test for this ?

Jason

#3 lore raw
In reply to Ralph Campbell
Quoted 6 lines · Ralph Campbell

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

		/*
		 * Never fault in device private pages, but just report
		 * the PFN even if not present.
		 */

This comment needs updating because it will be possible to fault in device private pages now.

It also looks a bit strange to be checking for device private entries twice - I think it would be clearer if hmm_is_device_private_entry() is removed and the ownership check done directly in hmm_vma_handle_pte().

- Alistair

Quoted 21 lines
Fixes 76612d6ce4cc ("mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte()")
---
 mm/hmm.c | 3 +++
 1 file changed, 3 insertions(+)
mm/hmm.c +3 -0
index 3fd3242c5e50..7db2b29bdc85 100644
@@ -273,6 +273,9 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
 		if (!non_swap_entry(entry))
 			goto fault;
 
+		if (is_device_private_entry(entry))
+			goto fault;
+
 		if (is_device_exclusive_entry(entry))
 			goto fault;
Acked-by on v1 1/1
#5 lore raw
In reply to Ralph Campbell

Am 2022-07-22 um 18:56 schrieb Ralph Campbell:

Quoted 11 lines

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

Fixes 76612d6ce4cc ("mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte()")

Thank you!

Quoted 18 lines
---
  mm/hmm.c | 3 +++
  1 file changed, 3 insertions(+)
mm/hmm.c +3 -0
index 3fd3242c5e50..7db2b29bdc85 100644
@@ -273,6 +273,9 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
  		if (!non_swap_entry(entry))
  			goto fault;
 
+		if (is_device_private_entry(entry))
+			goto fault;
+
  		if (is_device_exclusive_entry(entry))
  			goto fault;
 
#2 lore raw
In reply to Jason Gunthorpe
Quoted 15 lines · Jason Gunthorpe
Quoted 7 lines · Ralph Campbell

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

Quoted 7 lines
Fixes 76612d6ce4cc ("mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte()")
---
  mm/hmm.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 5 lines

Should we have a test for this ?

Jason

Sure, I'll add something to tools/testing/selftests/vm/hmm-tests.c

#4 lore raw
In reply to Alistair Popple
Quoted 13 lines · Alistair Popple
Quoted 6 lines · Ralph Campbell

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

		/*
		 * Never fault in device private pages, but just report
		 * the PFN even if not present.
		 */
Quoted 8 lines

This comment needs updating because it will be possible to fault in device private pages now.

It also looks a bit strange to be checking for device private entries twice - I think it would be clearer if hmm_is_device_private_entry() is removed and the ownership check done directly in hmm_vma_handle_pte().

- Alistair

I'll fix this in v2. Thanks for the review.

maintainer
#6 lore raw
In reply to Ralph Campbell
Quoted 6 lines · On Fri, 22 Jul 2022 15:56:32 -0700 Ralph Campbell <[email protected]> wrote:

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

Could we please include here a description of the end-user visible effects of the bug?

Quoted 1 line

Especially when proposing a -stable backport.

#7 lore raw
Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Fri, 22 Jul 2022 15:56:32 -0700 Ralph Campbell <[email protected]> wrote:

If hmm_range_fault() is called with the HMM_PFN_REQ_FAULT flag and a device private PTE is found, the hmm_range::dev_private_owner page is used to determine if the device private page should not be faulted in. However, if the device private page is not owned by the caller, hmm_range_fault() returns an error instead of calling migrate_to_ram() to fault in the page.

Quoted 5 lines

Could we please include here a description of the end-user visible effects of the bug?

Quoted 1 line

Especially when proposing a -stable backport.

If I add the following, would that be sufficient?
Should I post a v3?

For example, if a page is migrated to GPU private
memory and a RDMA fault capable NIC tries to read the migrated page, without this patch it will get an error. With this patch, the page will be migrated back to system memory and the NIC will be able to read the data.

maintainer
#8 lore raw
Quoted 7 lines · On Mon, 25 Jul 2022 12:07:27 -0700 Ralph Campbell <[email protected]> wrote:
Quoted 6 lines
Quoted 1 line

to fault in the page.

Could we please include here a description of the end-user visible effects of the bug?

Quoted 1 line

Especially when proposing a -stable backport.

Quoted 8 lines

If I add the following, would that be sufficient?
Should I post a v3?

For example, if a page is migrated to GPU private
memory and a RDMA fault capable NIC tries to read the migrated page, without this patch it will get an error. With this patch, the page will be migrated back to system memory and the NIC will be able to read the data.

I added it, thanks.