* [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated
@ 2014-07-10 21:53 Oded Gabbay
2014-07-10 22:15 ` Andrew Morton
2014-07-10 22:22 ` Joerg Roedel
0 siblings, 2 replies; 4+ messages in thread
From: Oded Gabbay @ 2014-07-10 21:53 UTC (permalink / raw)
To: Andrew Morton
Cc: David Airlie, Alex Deucher, Jerome Glisse, linux-kernel,
dri-devel, John Bridgman, Andrew Lewycky, Joerg Roedel, linux-mm,
Oded Gabbay, Naoya Horiguchi, Joonsoo Kim, Kirill A. Shutemov,
Hugh Dickins, Cyrill Gorcunov, Jérôme Glisse,
Jianyu Zhan
From: Andrew Lewycky <Andrew.Lewycky@amd.com>
This patch changes the location of the mmu_notifier_invalidate_page function
call inside try_to_unmap_one. The mmu_notifier_invalidate_page function
call tells the IOMMU that a pgae should be invalidated.
The location is changed from after releasing the physical page to
before releasing the physical page.
This change should prevent the bug that would occur in the
(rare) case where the GPU attempts to access a page while the CPU
attempts to swap out that page (or discard it if it is not dirty).
Signed-off-by: Andrew Lewycky <Andrew.Lewycky@amd.com>
Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
---
mm/rmap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/rmap.c b/mm/rmap.c
index 196cd0c..73d4c3d 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1231,13 +1231,17 @@ static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
} else
dec_mm_counter(mm, MM_FILEPAGES);
+ pte_unmap_unlock(pte, ptl);
+
+ mmu_notifier_invalidate_page(vma, address, event);
+
page_remove_rmap(page);
page_cache_release(page);
+ return ret;
+
out_unmap:
pte_unmap_unlock(pte, ptl);
- if (ret != SWAP_FAIL && !(flags & TTU_MUNLOCK))
- mmu_notifier_invalidate_page(vma, address, event);
out:
return ret;
--
1.9.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated
2014-07-10 21:53 [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated Oded Gabbay
@ 2014-07-10 22:15 ` Andrew Morton
2014-07-10 22:22 ` Joerg Roedel
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2014-07-10 22:15 UTC (permalink / raw)
To: Oded Gabbay
Cc: David Airlie, Alex Deucher, Jerome Glisse, linux-kernel,
dri-devel, John Bridgman, Andrew Lewycky, Joerg Roedel, linux-mm,
Oded Gabbay, Naoya Horiguchi, Joonsoo Kim, Kirill A. Shutemov,
Hugh Dickins, Cyrill Gorcunov, Jérôme Glisse,
Jianyu Zhan
On Fri, 11 Jul 2014 00:53:26 +0300 Oded Gabbay <oded.gabbay@gmail.com> wrote:
> From: Andrew Lewycky <Andrew.Lewycky@amd.com>
>
> This patch changes the location of the mmu_notifier_invalidate_page function
> call inside try_to_unmap_one. The mmu_notifier_invalidate_page function
> call tells the IOMMU that a pgae should be invalidated.
>
> The location is changed from after releasing the physical page to
> before releasing the physical page.
>
> This change should prevent the bug that would occur in the
> (rare) case where the GPU attempts to access a page while the CPU
> attempts to swap out that page (or discard it if it is not dirty).
um OK, but what is the effect on all the other
mmu_notifier_ops.invalidate_page() implementations?
Please spell this out in full detail within the changelog and be sure
to cc the affected maintainers.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated
2014-07-10 21:53 [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated Oded Gabbay
2014-07-10 22:15 ` Andrew Morton
@ 2014-07-10 22:22 ` Joerg Roedel
2014-07-10 22:34 ` Hugh Dickins
1 sibling, 1 reply; 4+ messages in thread
From: Joerg Roedel @ 2014-07-10 22:22 UTC (permalink / raw)
To: Oded Gabbay
Cc: Andrew Morton, David Airlie, Alex Deucher, Jerome Glisse,
linux-kernel, dri-devel, John Bridgman, Andrew Lewycky, linux-mm,
Oded Gabbay, Naoya Horiguchi, Joonsoo Kim, Kirill A. Shutemov,
Hugh Dickins, Cyrill Gorcunov, Jérôme Glisse,
Jianyu Zhan
On Fri, Jul 11, 2014 at 12:53:26AM +0300, Oded Gabbay wrote:
> mm/rmap.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 196cd0c..73d4c3d 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1231,13 +1231,17 @@ static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
> } else
> dec_mm_counter(mm, MM_FILEPAGES);
>
> + pte_unmap_unlock(pte, ptl);
> +
> + mmu_notifier_invalidate_page(vma, address, event);
> +
> page_remove_rmap(page);
> page_cache_release(page);
>
> + return ret;
> +
> out_unmap:
> pte_unmap_unlock(pte, ptl);
> - if (ret != SWAP_FAIL && !(flags & TTU_MUNLOCK))
> - mmu_notifier_invalidate_page(vma, address, event);
> out:
> return ret;
I think there is no bug. In that function the page is just unmapped,
removed from the rmap (page_remove_rmap), and the LRU list
(page_cache_release). The page itself is not released in this function,
so the call mmu_notifier_invalidate_page() at the end is fine.
Joerg
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated
2014-07-10 22:22 ` Joerg Roedel
@ 2014-07-10 22:34 ` Hugh Dickins
0 siblings, 0 replies; 4+ messages in thread
From: Hugh Dickins @ 2014-07-10 22:34 UTC (permalink / raw)
To: Joerg Roedel
Cc: Oded Gabbay, Andrew Morton, David Airlie, Alex Deucher,
Jerome Glisse, linux-kernel, dri-devel, John Bridgman,
Andrew Lewycky, linux-mm, Oded Gabbay, Naoya Horiguchi,
Joonsoo Kim, Kirill A. Shutemov, Hugh Dickins, Cyrill Gorcunov,
Jerome Glisse, Jianyu Zhan
On Fri, 11 Jul 2014, Joerg Roedel wrote:
> On Fri, Jul 11, 2014 at 12:53:26AM +0300, Oded Gabbay wrote:
> > mm/rmap.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/rmap.c b/mm/rmap.c
> > index 196cd0c..73d4c3d 100644
> > --- a/mm/rmap.c
> > +++ b/mm/rmap.c
> > @@ -1231,13 +1231,17 @@ static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
> > } else
> > dec_mm_counter(mm, MM_FILEPAGES);
> >
> > + pte_unmap_unlock(pte, ptl);
> > +
> > + mmu_notifier_invalidate_page(vma, address, event);
> > +
> > page_remove_rmap(page);
> > page_cache_release(page);
> >
> > + return ret;
> > +
> > out_unmap:
> > pte_unmap_unlock(pte, ptl);
> > - if (ret != SWAP_FAIL && !(flags & TTU_MUNLOCK))
> > - mmu_notifier_invalidate_page(vma, address, event);
> > out:
> > return ret;
>
> I think there is no bug. In that function the page is just unmapped,
> removed from the rmap (page_remove_rmap), and the LRU list
> (page_cache_release). The page itself is not released in this function,
> so the call mmu_notifier_invalidate_page() at the end is fine.
Agreed, nothing to fix here: the try_to_unmap() callers must hold
their own reference to the page. If they did not, how could they
be sure that this is a page which is appropriate to unmap?
(Nit: we don't actually take a separate reference for the LRU list:
the page_cache_release above corresponds to the reference in the
pte which has just been removed.)
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-10 22:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-10 21:53 [PATCH 28/83] mm: Change timing of notification to IOMMUs about a page to be invalidated Oded Gabbay
2014-07-10 22:15 ` Andrew Morton
2014-07-10 22:22 ` Joerg Roedel
2014-07-10 22:34 ` Hugh Dickins
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox