linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] mm/hmm: fault non-owner device private entries
@ 2022-07-27  0:08 Ralph Campbell
  2022-07-27  0:08 ` [PATCH v3 1/2] " Ralph Campbell
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ralph Campbell @ 2022-07-27  0:08 UTC (permalink / raw)
  To: linux-mm
  Cc: Felix Kuehling, Philip Yang, Alistair Popple, John Hubbard,
	Jason Gunthorpe, Andrew Morton, Ralph Campbell

Changes from v1 to v2:
Made code style changes suggested by Alistair Popple
Added a self test to hmm-tests.c (Jason Gunthorpe)

Changes from v2 to v3:
Updated the change description for patch 1 to include an example user
visible effect of the change.
Updated the change description for patch 2 to mention the deleted code.
Added reviewed-by tags and updated the fixes reference.

Andrew's mm tree already has everything except the updated description
for patch 2.

Ralph Campbell (2):
  mm/hmm: fault non-owner device private entries
  mm/hmm: add a test for cross device private faults

 mm/hmm.c                               | 19 ++++++++-----------
 tools/testing/selftests/vm/hmm-tests.c | 14 ++++++++++++--
 2 files changed, 20 insertions(+), 13 deletions(-)

-- 
2.35.3



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

* [PATCH v3 1/2] mm/hmm: fault non-owner device private entries
  2022-07-27  0:08 [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Ralph Campbell
@ 2022-07-27  0:08 ` Ralph Campbell
  2022-07-27  0:08 ` [PATCH v3 2/2] mm/hmm: add a test for cross device private faults Ralph Campbell
  2022-07-28 23:17 ` [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Andrew Morton
  2 siblings, 0 replies; 4+ messages in thread
From: Ralph Campbell @ 2022-07-27  0:08 UTC (permalink / raw)
  To: linux-mm
  Cc: Felix Kuehling, Philip Yang, Alistair Popple, John Hubbard,
	Jason Gunthorpe, Andrew Morton, Ralph Campbell, stable

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.

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.

Cc: stable@vger.kernel.org
Fixes: 08ddddda667b ("mm/hmm: check the device private page owner in hmm_range_fault()")
Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
Reported-by: Felix Kuehling <felix.kuehling@amd.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
 mm/hmm.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/mm/hmm.c b/mm/hmm.c
index 3fd3242c5e50..f2aa63b94d9b 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -212,14 +212,6 @@ int hmm_vma_handle_pmd(struct mm_walk *walk, unsigned long addr,
 		unsigned long end, unsigned long hmm_pfns[], pmd_t pmd);
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
-static inline bool hmm_is_device_private_entry(struct hmm_range *range,
-		swp_entry_t entry)
-{
-	return is_device_private_entry(entry) &&
-		pfn_swap_entry_to_page(entry)->pgmap->owner ==
-		range->dev_private_owner;
-}
-
 static inline unsigned long pte_to_hmm_pfn_flags(struct hmm_range *range,
 						 pte_t pte)
 {
@@ -252,10 +244,12 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr,
 		swp_entry_t entry = pte_to_swp_entry(pte);
 
 		/*
-		 * Never fault in device private pages, but just report
-		 * the PFN even if not present.
+		 * Don't fault in device private pages owned by the caller,
+		 * just report the PFN.
 		 */
-		if (hmm_is_device_private_entry(range, entry)) {
+		if (is_device_private_entry(entry) &&
+		    pfn_swap_entry_to_page(entry)->pgmap->owner ==
+		    range->dev_private_owner) {
 			cpu_flags = HMM_PFN_VALID;
 			if (is_writable_device_private_entry(entry))
 				cpu_flags |= HMM_PFN_WRITE;
@@ -273,6 +267,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.35.3



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

* [PATCH v3 2/2] mm/hmm: add a test for cross device private faults
  2022-07-27  0:08 [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Ralph Campbell
  2022-07-27  0:08 ` [PATCH v3 1/2] " Ralph Campbell
@ 2022-07-27  0:08 ` Ralph Campbell
  2022-07-28 23:17 ` [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Andrew Morton
  2 siblings, 0 replies; 4+ messages in thread
From: Ralph Campbell @ 2022-07-27  0:08 UTC (permalink / raw)
  To: linux-mm
  Cc: Felix Kuehling, Philip Yang, Alistair Popple, John Hubbard,
	Jason Gunthorpe, Andrew Morton, Ralph Campbell

Add a simple test case for when hmm_range_fault() is called with the
HMM_PFN_REQ_FAULT flag and a device private PTE is found for a device
other than the hmm_range::dev_private_owner. This should cause the
page to be faulted back to system memory from the other device and the
PFN returned in the output array.
Also, remove a piece of code that unnecessarily unmaps part of the
buffer.

Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Cc: Felix Kuehling <felix.kuehling@amd.com>
Cc: Philip Yang <Philip.Yang@amd.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
 tools/testing/selftests/vm/hmm-tests.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c
index 203323967b50..a5ce7cc2e7aa 100644
--- a/tools/testing/selftests/vm/hmm-tests.c
+++ b/tools/testing/selftests/vm/hmm-tests.c
@@ -1520,9 +1520,19 @@ TEST_F(hmm2, double_map)
 	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
 		ASSERT_EQ(ptr[i], i);
 
-	/* Punch a hole after the first page address. */
-	ret = munmap(buffer->ptr + self->page_size, self->page_size);
+	/* Migrate pages to device 1 and try to read from device 0. */
+	ret = hmm_dmirror_cmd(self->fd1, HMM_DMIRROR_MIGRATE, buffer, npages);
+	ASSERT_EQ(ret, 0);
+	ASSERT_EQ(buffer->cpages, npages);
+
+	ret = hmm_dmirror_cmd(self->fd0, HMM_DMIRROR_READ, buffer, npages);
 	ASSERT_EQ(ret, 0);
+	ASSERT_EQ(buffer->cpages, npages);
+	ASSERT_EQ(buffer->faults, 1);
+
+	/* Check what device 0 read. */
+	for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i)
+		ASSERT_EQ(ptr[i], i);
 
 	hmm_buffer_free(buffer);
 }
-- 
2.35.3



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

* Re: [PATCH v3 0/2] mm/hmm: fault non-owner device private entries
  2022-07-27  0:08 [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Ralph Campbell
  2022-07-27  0:08 ` [PATCH v3 1/2] " Ralph Campbell
  2022-07-27  0:08 ` [PATCH v3 2/2] mm/hmm: add a test for cross device private faults Ralph Campbell
@ 2022-07-28 23:17 ` Andrew Morton
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2022-07-28 23:17 UTC (permalink / raw)
  To: Ralph Campbell
  Cc: linux-mm, Felix Kuehling, Philip Yang, Alistair Popple,
	John Hubbard, Jason Gunthorpe

On Tue, 26 Jul 2022 17:08:35 -0700 Ralph Campbell <rcampbell@nvidia.com> wrote:

> Andrew's mm tree already has everything except the updated description
> for patch 2.

Thanks, I updated the changelog and the Link: tags in place.


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

end of thread, other threads:[~2022-07-28 23:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27  0:08 [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Ralph Campbell
2022-07-27  0:08 ` [PATCH v3 1/2] " Ralph Campbell
2022-07-27  0:08 ` [PATCH v3 2/2] mm/hmm: add a test for cross device private faults Ralph Campbell
2022-07-28 23:17 ` [PATCH v3 0/2] mm/hmm: fault non-owner device private entries Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox