mmu_notifier semantic update
Subsystems (6)
cover mmu_notifier semantic update
So we do not want to allow sleep during call to mmu_notifier_invalidate_page() but some code do not have surrounding mmu_notifier_invalidate_range_start()/ mmu_notifier_invalidate_range_end() or mmu_notifier_invalidate_range()
This patch serie just make sure that there is at least a call (outside spinlock section) to mmu_notifier_invalidate_range() after mmu_notifier_invalidate_page()
This fix issue with AMD IOMMU v2 while avoiding to introduce issue for others user of the mmu_notifier API. For releavent threads see:
https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]
https://marc.info/?l=kvm&m=150327081325160&w=2
JA(C)rA'me Glisse (4):
mm/mmu_notifier: document new behavior for
mmu_notifier_invalidate_page()
dax/mmu_notifier: update to new mmu_notifier semantic mm/rmap: update to new mmu_notifier_invalidate_page() semantic iommu/amd: update to new mmu_notifier_invalidate_page() semantic
drivers/iommu/amd_iommu_v2.c | 8 -------- fs/dax.c | 8 ++++++-- include/linux/mmu_notifier.h | 6 ++++++ mm/rmap.c | 18 +++++++++++++++++- 4 files changed, 29 insertions(+), 11 deletions(-)
Signature · 7 lines
2.13.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/4 mm/mmu_notifier: document new behavior for mmu_notifier_invalidate_page()
The invalidate page callback use to happen outside the page table spinlock and thus callback use to be allow to sleep. This is no longer the case. However now all call to mmu_notifier_invalidate_page() are bracketed by call to mmu_notifier_invalidate_range_start/mmu_notifier_invalidate_range_end
--- include/linux/mmu_notifier.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/mmu_notifier.h +6 -0
@@ -100,6 +100,12 @@ struct mmu_notifier_ops {* pte because the page hasn't been freed yet and it won't be * freed until this returns. If required set_page_dirty has to * be called internally to this method. +* +* Note that previously this callback wasn't call from under +* a spinlock and thus you were able to sleep inside it. This +* is no longer the case. However now all call to this callback +* is either bracketed by call to range_start()/range_end() or +* follow by a call to invalidate_range(). */ void (*invalidate_page)(struct mmu_notifier *mn, struct mm_struct *mm,
Signature · 7 lines
2.13.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/4 dax/mmu_notifier: update to new mmu_notifier semantic
In reply to Jérôme Glissemmu_notifier_invalidate_page() can now be call from under the spinlock. Move it approprietly and add a call to mmu_notifier_invalidate_range() for user that need to be able to sleep.
--- fs/dax.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/dax.c +8 -2
@@ -650,7 +650,7 @@ static void dax_mapping_entry_mkclean(struct address_space *mapping,i_mmap_lock_read (mapping); vma_interval_tree_foreach(vma, &mapping->i_mmap, index, index) { -unsigned long address; +unsigned long start, address, end;cond_resched ();
@@ -676,6 +676,9 @@ static void dax_mapping_entry_mkclean(struct address_space *mapping, pmd =pmd_wrprotect (pmd); pmd =pmd_mkclean (pmd);set_pmd_at (vma->vm_mm, address, pmdp, pmd); + start = address &PMD_MASK ; + end = start +PMD_SIZE ; +mmu_notifier_invalidate_page (vma->vm_mm, address); changed = true; unlock_pmd:spin_unlock (ptl);
@@ -691,13 +694,16 @@ static void dax_mapping_entry_mkclean(struct address_space *mapping, pte =pte_wrprotect (pte); pte =pte_mkclean (pte);set_pte_at (vma->vm_mm, address, ptep, pte); +mmu_notifier_invalidate_page (vma->vm_mm, address); changed = true; + start = address; + end = start +PAGE_SIZE ; unlock_pte:pte_unmap_unlock (ptep, ptl); }if (changed) -mmu_notifier_invalidate_page (vma->vm_mm, address); +mmu_notifier_invalidate_range (vma->vm_mm, start, end); }i_mmap_unlock_read (mapping); }
Signature · 7 lines
2.13.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/4 mm/rmap: update to new mmu_notifier_invalidate_page() semantic
In reply to Jérôme Glissemmu_notifier_invalidate_page() is now be call from under the spinlock. Add a call to mmu_notifier_invalidate_range() for user that need to be able to sleep.
Relevent threads:
https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]
https://marc.info/?l=kvm&m=150327081325160&w=2
--- mm/rmap.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
mm/rmap.c +17 -1
@@ -887,6 +887,8 @@ static bool page_mkclean_one(struct page *page, struct vm_area_struct *vma, .address = address, .flags = PVMW_SYNC, }; +unsigned long start = address, end = address; +bool invalidate = false;int *cleaned = arg;while (page_vma_mapped_walk (&pvmw)) {
@@ -927,10 +929,16 @@ static bool page_mkclean_one(struct page *page, struct vm_area_struct *vma,if (ret) {mmu_notifier_invalidate_page (vma->vm_mm, address); +/* range is exclusive */ + end = address +PAGE_SIZE ; + invalidate = true; (*cleaned)++; } } +if (invalidate) +mmu_notifier_invalidate_range (vma->vm_mm, start, end); +return true; }
@@ -1323,8 +1331,9 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, };pte_t pteval;struct page *subpage; -bool ret = true; +bool ret = true, invalidate = false;enum ttu_flags flags = (enum ttu_flags )arg; +unsigned long start = address, end = address;/* munlock has nothing to gain from examining un-locked vmas */ if ((flags &TTU_MUNLOCK ) && !(vma->vm_flags &VM_LOCKED ))
@@ -1491,7 +1500,14 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,page_remove_rmap (subpage,PageHuge (page));put_page (page);mmu_notifier_invalidate_page (mm, address); +/* range is exclusive */ + end = address +PAGE_SIZE ; + invalidate = true; } + +if (invalidate) +mmu_notifier_invalidate_range (vma->vm_mm, start, end); +return ret; }
Signature · 7 lines
2.13.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/4 iommu/amd: update to new mmu_notifier_invalidate_page() semantic
In reply to Jérôme Glissemmu_notifier_invalidate_page() is now be call from under the spinlock. But we can now rely on invalidate_range() being call afterward.
--- drivers/iommu/amd_iommu_v2.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/iommu/amd_iommu_v2.c +0 -8
@@ -391,13 +391,6 @@ static int mn_clear_flush_young(struct mmu_notifier *mn,return 0 ; } -static void mn_invalidate_page (struct mmu_notifier *mn, -struct mm_struct *mm, -unsigned long address) -{ -__mn_flush_page (mn, address); -} -static void mn_invalidate_range (struct mmu_notifier *mn,struct mm_struct *mm,unsigned long start,unsigned long end)
@@ -436,7 +429,6 @@ static void mn_release(struct mmu_notifier *mn, struct mm_struct *mm)static const struct mmu_notifier_ops iommu_mn = { .release = mn_release, .clear_flush_young = mn_clear_flush_young, - .invalidate_page = mn_invalidate_page, .invalidate_range = mn_invalidate_range, };
Signature · 7 lines
2.13.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Jerome Glisse
So we do not want to allow sleep during call to
mmu_notifier_invalidate_page()but some code do not have surrounding mmu_notifier_invalidate_range_start()/mmu_notifier_invalidate_range_end()ormmu_notifier_invalidate_range()This patch serie just make sure that there is at least a call (outside spinlock section) to
mmu_notifier_invalidate_range()aftermmu_notifier_invalidate_page()
Quoted 6 lines
This fix issue with AMD IOMMU v2 while avoiding to introduce issue for others user of the
mmu_notifierAPI. For releavent threads see:https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]
https://marc.info/?l=kvm&m=150327081325160&w=2
Please ignore this. Instead plan is to kill invalidate_page() switch it to invalidate_range() and make sure there is always range_start/ range_end happening around.
Jerome
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>