Add dirty-tracking infrastructure for non-page-backed address spaces
Subsystems (2)
cover Add dirty-tracking infrastructure for non-page-backed address spaces
Hi!
Before going any further with this I'd like to check whether this is an acceptable way to go.
Background:
GPU buffer objects in general and vmware svga GPU buffers in particular are mapped by user-space using MIXEDMAP or PFNMAP. Sometimes the address space is backed by a set of pages, sometimes it's backed by PCI memory. In the latter case in particular, there is no way to track dirty regions using page_mkwrite() and page_mkclean(), other than allocating a bounce buffer and perform dirty tracking on it, and then copy data to the real GPU buffer. This comes with a big memory- and performance overhead.
So I'd like to add the following infrastructure with a callback pfn_mkwrite() and a function mkclean_mapping_range(). Typically we will be cleaning a range of ptes rather than random ptes in a vma.
This comes with the extra benefit of being usable when the backing memory of the GPU buffer is not coherent with the GPU itself, and where we either need to flush caches or move data to synchronize.
So this is a RFC for
1) The API. Is it acceptable? Any other suggestions if not?
2) Modifying apply_to_page_range(). Better to make a standalone non-populating version?
3) tlb- mmu- and cache-flushing calls. I've looked at unmap_mapping_range() and page_mkclean_one() to try to get it right, but still unsure.
Thanks,
Thomas Hellström
RFC PATCH 1/3 mm: Add pfn_mkwrite()
A callback similar to page_mkwrite except it will be called before making ptes that don't point to normal pages writable.
--- include/linux/mm.h | 9 +++++++++ mm/memory.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-)
include/linux/mm.h +9 -0
@@ -212,6 +212,15 @@ struct vm_operations_struct {* writable, if an error is returned it will cause a SIGBUS */ int (*page_mkwrite)(struct vm_area_struct *vma,struct vm_fault *vmf); +/* +* Notification that a previously read-only pfn map is about to become +* writable, Returning VM_FAULT_NOPAGE will cause the fault to be +* retried, +* Returning a VM_FAULT_SIGBUS or VM_FAULT_OOM will propagate the +* error. Returning 0 will make the pfn map writable. +*/ +int (*pfn_mkwrite)(struct vm_area_struct *vma,struct vm_fault *vmf); +/* called by access_process_vm when get_user_pages() fails, typically * for use by special VMAs that can switch between memory and hardware */
mm/memory.c +49 -3
67 lines not on this page · raw message
Signature · 7 lines
1.7.10.4 -- 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>
RFC PATCH 2/3 mm: Add a non-populating version of apply_to_page_range()
In reply to Thomas HellstromFor some tasks, like cleaning ptes it's desirable to operate on only populated ptes. This avoids the overhead of page table memory allocation and also avoids memory allocation errors.
Adds apply_to_pt_range() which, in addition to apply_to_page_range(), optionally skips the populating step. Share code with apply_to_page_range().
--- mm/memory.c | 73 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 25 deletions(-)
mm/memory.c +48 -25
@@ -2433,19 +2433,22 @@ int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned longEXPORT_SYMBOL (vm_iomap_memory);static int apply_to_pte_range (struct mm_struct *mm,pmd_t *pmd, -unsigned long addr,unsigned long end, -pte_fn_t fn,void *data) +unsigned long addr,unsigned long end, +pte_fn_t fn,void *data,bool fill) {pte_t *pte;int err;pgtable_t token;spinlock_t *uninitialized_var (ptl ); - pte = (mm == &init_mm) ? -pte_alloc_kernel (pmd, addr) : -pte_alloc_map_lock (mm, pmd, addr, &ptl); -if (!pte) -return -ENOMEM ; +if (fill) { + pte = (mm == &init_mm) ? +pte_alloc_kernel (pmd, addr) : +pte_alloc_map_lock (mm, pmd, addr, &ptl); +if (!pte) +return -ENOMEM ; + }else + pte =pte_offset_map_lock (mm, pmd, addr, &ptl);BUG_ON (pmd_huge (*pmd));
@@ -2461,27 +2464,32 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,arch_leave_lazy_mmu_mode (); -if (mm != &init_mm) +if (!fill || mm != &init_mm)pte_unmap_unlock (pte-1 , ptl);return err; }static int apply_to_pmd_range (struct mm_struct *mm,pud_t *pud, -unsigned long addr,unsigned long end, -pte_fn_t fn,void *data) +unsigned long addr,unsigned long end, +pte_fn_t fn,void *data,bool fill) {pmd_t *pmd;unsigned long next; -int err; +int err =0 ;BUG_ON (pud_huge (*pud)); - pmd =pmd_alloc (mm, pud, addr); -if (!pmd) -return -ENOMEM ; +if (fill) { + pmd =pmd_alloc (mm, pud, addr); +if (!pmd) +return -ENOMEM ; + }else + pmd =pmd_offset (pud, addr);do { next =pmd_addr_end (addr, end); - err =apply_to_pte_range (mm, pmd, addr, next, fn, data); +if (!fill &&pmd_none_or_clear_bad (pmd)) +continue ; + err =apply_to_pte_range (mm, pmd, addr, next, fn, data, fill);if (err)break ; }while (pmd++, addr = next, addr != end);
@@ -2489,19 +2497,24 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, }static int apply_to_pud_range (struct mm_struct *mm,pgd_t *pgd, -unsigned long addr,unsigned long end, -pte_fn_t fn,void *data) +unsigned long addr,unsigned long end, +pte_fn_t fn,void *data,bool fill) {pud_t *pud;unsigned long next; -int err; +int err =0 ; - pud =pud_alloc (mm, pgd, addr); -if (!pud) -return -ENOMEM ; +if (fill) { + pud =pud_alloc (mm, pgd, addr); +if (!pud) +return -ENOMEM ; + }else + pud =pud_offset (pgd, addr);do { next =pud_addr_end (addr, end); - err =apply_to_pmd_range (mm, pud, addr, next, fn, data); +if (!fill &&pud_none_or_clear_bad (pud)) +continue ; + err =apply_to_pmd_range (mm, pud, addr, next, fn, data, fill);if (err)break ; }while (pud++, addr = next, addr != end);
@@ -2512,25 +2525,35 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,* Scan a region of virtual memory, filling in page tables as necessary * and calling a provided function on each leaf page table. */ -int apply_to_page_range (struct mm_struct *mm,unsigned long addr, -unsigned long size,pte_fn_t fn,void *data) +static int apply_to_pt_range (struct mm_struct *mm,unsigned long addr, +unsigned long size,pte_fn_t fn,void *data, +bool fill) {pgd_t *pgd;unsigned long next;unsigned long end = addr + size;int err; +BUG_ON (!fill && mm == &init_mm);BUG_ON (addr >= end); + pgd =pgd_offset (mm, addr);do { next =pgd_addr_end (addr, end); - err =apply_to_pud_range (mm, pgd, addr, next, fn, data); + err =apply_to_pud_range (mm, pgd, addr, next, fn, data, + fill);if (err)break ; }while (pgd++, addr = next, addr != end);return err; } + +int apply_to_page_range (struct mm_struct *mm,unsigned long addr, +unsigned long size,pte_fn_t fn,void *data) +{ +return apply_to_pt_range (mm, addr, size, fn, data, true); +}EXPORT_SYMBOL_GPL (apply_to_page_range);/*
Signature · 7 lines
1.7.10.4 -- 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>
RFC PATCH 3/3 mm: Add mkclean_mapping_range()
In reply to Thomas HellstromA general function to clean (Mark non-writeable and non-dirty) all ptes pointing to a certain range in an address space.
Although it is primarily intended for PFNMAP and MIXEDMAP vmas, AFAICT it should work on address spaces backed by normal pages as well. It will not clean COW'd pages and it will not work with nonlinear VMAs.
--- include/linux/mm.h | 3 ++ mm/memory.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
include/linux/mm.h +3 -0
@@ -982,6 +982,9 @@ int copy_page_range(struct mm_struct *dst, struct mm_struct *src, struct vm_area_struct *vma);void unmap_mapping_range (struct address_space *mapping,loff_t const holebegin,loff_t const holelen,int even_cows); +void mkclean_mapping_range (struct address_space *mapping, +pgoff_t pg_clean_begin, +pgoff_t pg_len);int follow_pfn (struct vm_area_struct *vma,unsigned long address,unsigned long *pfn); int follow_phys(struct vm_area_struct *vma, unsigned long address,
mm/memory.c +108 -0
111 lines not on this page · raw message
Signature · 7 lines
1.7.10.4 -- 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 20 lines · Thomas Hellstrom
Hi!
Before going any further with this I'd like to check whether this is an acceptable way to go.
Background:
GPU buffer objects in general and vmware svga GPU buffers in particular are mapped by user-space using MIXEDMAP or PFNMAP. Sometimes the address space is backed by a set of pages, sometimes it's backed by PCI memory. In the latter case in particular, there is no way to track dirty regions usingpage_mkwrite()andpage_mkclean(), other than allocating a bounce buffer and perform dirty tracking on it, and then copy data to the real GPU buffer. This comes with a big memory- and performance overhead.So I'd like to add the following infrastructure with a callback
pfn_mkwrite()and a functionmkclean_mapping_range(). Typically we will be cleaning a range of ptes rather than random ptes in a vma.
This comes with the extra benefit of being usable when the backing memory of the GPU buffer is not coherent with the GPU itself, and where we either need to flush caches or move data to synchronize.
Quoted 6 lines
So this is a RFC for
1) The API. Is it acceptable? Any other suggestions if not?
2) Modifyingapply_to_page_range(). Better to make a standalone non-populating version?
3) tlb- mmu- and cache-flushing calls. I've looked atunmap_mapping_range()andpage_mkclean_one()to try to get it right, but still unsure.
Most (all?) architectures have real dirty tracking -- you can mark a pte as "clean" and the hardware (or arch code) will mark it dirty when written, *without* a page fault.
I'm not convinced that it works completely correctly right now (I suspect that there are some TLB flushing issues on the dirty->clean transition), and it's likely prone to bit-rot, since the page cache doesn't rely on it.
That being said, using hardware dirty tracking should be *much* faster and less latency-inducing than doing it in software like this. It may be worth trying to get HW dirty tracking working before adding more page fault-based tracking.
(I think there's also some oddity on S/390. I don't know what that oddity is or whether you should care.)
--Andy
--
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 41 lines · Andy Lutomirski
Quoted 20 lines · Thomas Hellstrom
Hi!
Before going any further with this I'd like to check whether this is an acceptable way to go.
Background:
GPU buffer objects in general and vmware svga GPU buffers in particular are mapped by user-space using MIXEDMAP or PFNMAP. Sometimes the address space is backed by a set of pages, sometimes it's backed by PCI memory. In the latter case in particular, there is no way to track dirty regions usingpage_mkwrite()andpage_mkclean(), other than allocating a bounce buffer and perform dirty tracking on it, and then copy data to the real GPU buffer. This comes with a big memory- and performance overhead.So I'd like to add the following infrastructure with a callback
pfn_mkwrite()and a functionmkclean_mapping_range(). Typically we will be cleaning a range of ptes rather than random ptes in a vma.
This comes with the extra benefit of being usable when the backing memory of the GPU buffer is not coherent with the GPU itself, and where we either need to flush caches or move data to synchronize.Quoted 6 lines
So this is a RFC for
1) The API. Is it acceptable? Any other suggestions if not?
2) Modifyingapply_to_page_range(). Better to make a standalone non-populating version?
3) tlb- mmu- and cache-flushing calls. I've looked atunmap_mapping_range()andpage_mkclean_one()to try to get it right, but still unsure.Most (all?) architectures have real dirty tracking -- you can mark a pte as "clean" and the hardware (or arch code) will mark it dirty when written, *without* a page fault.
I'm not convinced that it works completely correctly right now (I suspect that there are some TLB flushing issues on the
dirty->cleantransition), and it's likely prone to bit-rot, since the page cache doesn't rely on it.That being said, using hardware dirty tracking should be *much* faster and less latency-inducing than doing it in software like this. It may be worth trying to get HW dirty tracking working before adding more page fault-based tracking.
Quoted 4 lines
(I think there's also some oddity on S/390. I don't know what that oddity is or whether you should care.)
--Andy
Andy,
Thanks for the tip. It indeed sounds interesting, however there are a couple of culprits:
1) As you say, it sounds like there might be TLB flushing issues. Let's say the TLB detects a write and raises an IRQ for the arch code to set the PTE dirty bit, and before servicing that interrupt, we clear the PTE and flush that TLB. What will happen? And if the TLB hardware would write directly to the in-memory PTE I guess we'd have the same synchronization issues. I guess we'd then need an atomic read-modify-write against the TLB hardware?
2) Even if most hardware is capable of this stuff, I'm not sure what would happen in a virtual machine. Need to check.
3) For dirty contents that need to appear on a screen within a short interval, we need the write notification anyway, to start a delayed task that will gather the dirty data and flush it to the screen...
Thanks,
/Thomas
Quoted 61 lines · Thomas Hellstrom
Quoted 52 lines · Andy Lutomirski
Quoted 28 lines · Thomas Hellstrom
Hi!
Before going any further with this I'd like to check whether this is an acceptable way to go.
Background:
GPU buffer objects in general and vmware svga GPU buffers in particular are mapped by user-space using MIXEDMAP or PFNMAP. Sometimes the
address space is backed by a set of pages, sometimes it's backed by PCI memory.
In the latter case in particular, there is no way to track dirty regions usingpage_mkwrite()andpage_mkclean(), other than allocating a bounce buffer and perform dirty tracking on it, and then copy data to the real GPU
buffer. This comes with a big memory- and performance overhead.So I'd like to add the following infrastructure with a callback
pfn_mkwrite()
and a functionmkclean_mapping_range(). Typically we will be cleaning a range
of ptes rather than random ptes in a vma.
This comes with the extra benefit of being usable when the backing memory of
the GPU buffer is not coherent with the GPU itself, and where we either need
to flush caches or move data to synchronize.Quoted 7 lines
So this is a RFC for
1) The API. Is it acceptable? Any other suggestions if not?
2) Modifyingapply_to_page_range(). Better to make a standalone non-populating version?
3) tlb- mmu- and cache-flushing calls. I've looked atunmap_mapping_range()
andpage_mkclean_one()to try to get it right, but still unsure.Most (all?) architectures have real dirty tracking -- you can mark a pte as "clean" and the hardware (or arch code) will mark it dirty when written, *without* a page fault.
I'm not convinced that it works completely correctly right now (I suspect that there are some TLB flushing issues on the
dirty->cleantransition), and it's likely prone to bit-rot, since the page cache doesn't rely on it.That being said, using hardware dirty tracking should be *much* faster and less latency-inducing than doing it in software like this. It may be worth trying to get HW dirty tracking working before adding more page fault-based tracking.
Quoted 4 lines
(I think there's also some oddity on S/390. I don't know what that oddity is or whether you should care.)
--Andy
Andy,
Quoted 7 lines
Thanks for the tip. It indeed sounds interesting, however there are a couple of culprits:
1) As you say, it sounds like there might be TLB flushing issues. Let's say the TLB detects a write and raises an IRQ for the arch code to set the PTE dirty bit, and before servicing that interrupt, we clear the PTE and flush that TLB. What will happen?
This should be fine. I assume that all architectures that do this kind of software dirty tracking will make the write block until the fault is handled, so the write won't have happened when you clear the PTE. After the TLB flush, the PTE will become dirty again and then the page will be written.
Quoted 3 lines
And if the TLB hardware would write directly to
the in-memory PTE I guess we'd have the same synchronization issues. I guess we'd then need an atomic read-modify-write against the TLB hardware?
IIRC the part that looked fishy to me was the combination of hw dirty tracking and write protecting the page. If you see that the pte is clean and want to write protect it, you probably need to set the write protect bit (atomically so you don't lose a dirty bit), flush the TLB, and then check the dirty bit again.
Quoted 2 lines
2) Even if most hardware is capable of this stuff, I'm not sure what would happen in a virtual machine. Need to check.
This should be fine. Any VM monitor that fails to implement dirty tracking is probably terminally broken.
Quoted 4 lines
3) For dirty contents that need to appear on a screen within a short interval, we need the write notification anyway, to start a delayed task that will gather the dirty data and flush it to the screen...
So that's what you want to do :)
I bet that the best approach is some kind of hybrid. If, on the first page fault per frame, you un-write-protected the entire buffer and then, near the end of the frame, check all the hw dirty bits and re-write-protect the entire buffer, you get the benefit detecting which pages were written, but you only take one write fault per frame instead of one write fault per page.
(I imagine that there are video apps out that there that would slow down measurably if they started taking one write fault per page per frame.)
--Andy
Quoted 81 lines · Andy Lutomirski
Quoted 57 lines · Thomas Hellstrom
Quoted 49 lines · Andy Lutomirski
Quoted 27 lines · Thomas Hellstrom
Hi!
Before going any further with this I'd like to check whether this is an acceptable way to go.
Background:
GPU buffer objects in general and vmware svga GPU buffers in particular are mapped by user-space using MIXEDMAP or PFNMAP. Sometimes the
address space is backed by a set of pages, sometimes it's backed by PCI memory.
In the latter case in particular, there is no way to track dirty regions usingpage_mkwrite()andpage_mkclean(), other than allocating a bounce buffer and perform dirty tracking on it, and then copy data to the real GPU
buffer. This comes with a big memory- and performance overhead.So I'd like to add the following infrastructure with a callback
pfn_mkwrite()
and a functionmkclean_mapping_range(). Typically we will be cleaning a range
of ptes rather than random ptes in a vma.
This comes with the extra benefit of being usable when the backing memory of
the GPU buffer is not coherent with the GPU itself, and where we either need
to flush caches or move data to synchronize.Quoted 7 lines
So this is a RFC for
1) The API. Is it acceptable? Any other suggestions if not?
2) Modifyingapply_to_page_range(). Better to make a standalone non-populating version?
3) tlb- mmu- and cache-flushing calls. I've looked atunmap_mapping_range()
andpage_mkclean_one()to try to get it right, but still unsure.Most (all?) architectures have real dirty tracking -- you can mark a pte as "clean" and the hardware (or arch code) will mark it dirty when written, *without* a page fault.
I'm not convinced that it works completely correctly right now (I suspect that there are some TLB flushing issues on the
dirty->cleantransition), and it's likely prone to bit-rot, since the page cache doesn't rely on it.That being said, using hardware dirty tracking should be *much* faster and less latency-inducing than doing it in software like this. It may be worth trying to get HW dirty tracking working before adding more page fault-based tracking.
Quoted 4 lines
(I think there's also some oddity on S/390. I don't know what that oddity is or whether you should care.)
--Andy
Andy,
Quoted 7 lines
Thanks for the tip. It indeed sounds interesting, however there are a couple of culprits:
1) As you say, it sounds like there might be TLB flushing issues. Let's say the TLB detects a write and raises an IRQ for the arch code to set the PTE dirty bit, and before servicing that interrupt, we clear the PTE and flush that TLB. What will happen?
This should be fine. I assume that all architectures that do this kind of software dirty tracking will make the write block until the fault is handled, so the write won't have happened when you clear the PTE. After the TLB flush, the PTE will become dirty again and then the page will be written.
Quoted 3 lines
And if the TLB hardware would write directly to
the in-memory PTE I guess we'd have the same synchronization issues. I guess we'd then need an atomic read-modify-write against the TLB hardware?IIRC the part that looked fishy to me was the combination of hw dirty tracking and write protecting the page. If you see that the pte is clean and want to write protect it, you probably need to set the write protect bit (atomically so you don't lose a dirty bit), flush the TLB, and then check the dirty bit again.
Quoted 4 lines
Quoted 2 lines
2) Even if most hardware is capable of this stuff, I'm not sure what would happen in a virtual machine. Need to check.
This should be fine. Any VM monitor that fails to implement dirty tracking is probably terminally broken.
OK. I'll give it a try. If I understand this correctly, even if I set up a shared RW mapping, the PTEs should magically be marked dirty if written to, and everything works as it should?
Quoted 6 lines
Quoted 5 lines
3) For dirty contents that need to appear on a screen within a short interval, we need the write notification anyway, to start a delayed task that will gather the dirty data and flush it to the screen...
So that's what you want to do :)
Well this is mostly a benefit, actually. We already do this using fb_defio, but without this new interface we need a bounce-buffer covering the whole screen. Luckily this isn't a common use-case.
Typically (if we use this) we'd gather dirty data when the buffer is referenced in a GPU command stream.
Quoted 7 lines
I bet that the best approach is some kind of hybrid. If, on the first page fault per frame, you un-write-protected the entire buffer and then, near the end of the frame, check all the hw dirty bits and re-write-protect the entire buffer, you get the benefit detecting which pages were written, but you only take one write fault per frame instead of one write fault per page.
Yes, that sounds sane, particularly as un-write-protecting shouldn't need any additional tlb flushing, AFAICT.
Quoted 4 lines
(I imagine that there are video apps out that there that would slow down measurably if they started taking one write fault per page per frame.)
I actually hope to be able to avoid this stuff completely, but I need a backup plan, so that's why I threw out this RFC.
Quoted 2 lines
--Andy
Thanks,
Thomas
Quoted 101 lines · Thomas Hellstrom
Quoted 100 lines · Andy Lutomirski
Quoted 68 lines · Thomas Hellstrom
Quoted 54 lines · Andy Lutomirski
Quoted 30 lines · Thomas Hellstrom
Hi!
Before going any further with this I'd like to check whether this is an acceptable way to go.
Background:
GPU buffer objects in general and vmware svga GPU buffers in particular are mapped by user-space using MIXEDMAP or PFNMAP. Sometimes the
address space is backed by a set of pages, sometimes it's backed by PCI memory.
In the latter case in particular, there is no way to track dirty regions
usingpage_mkwrite()andpage_mkclean(), other than allocating a bounce buffer and perform dirty tracking on it, and then copy data to the real GPU
buffer. This comes with a big memory- and performance overhead.So I'd like to add the following infrastructure with a callback
pfn_mkwrite()
and a functionmkclean_mapping_range(). Typically we will be cleaning a range
of ptes rather than random ptes in a vma.
This comes with the extra benefit of being usable when the backing memory
of
the GPU buffer is not coherent with the GPU itself, and where we either need
to flush caches or move data to synchronize.Quoted 7 lines
So this is a RFC for
1) The API. Is it acceptable? Any other suggestions if not?
2) Modifyingapply_to_page_range(). Better to make a standalone non-populating version?
3) tlb- mmu- and cache-flushing calls. I've looked atunmap_mapping_range()
andpage_mkclean_one()to try to get it right, but still unsure.Most (all?) architectures have real dirty tracking -- you can mark a pte as "clean" and the hardware (or arch code) will mark it dirty when written, *without* a page fault.
I'm not convinced that it works completely correctly right now (I suspect that there are some TLB flushing issues on the
dirty->cleantransition), and it's likely prone to bit-rot, since the page cache doesn't rely on it.That being said, using hardware dirty tracking should be *much* faster and less latency-inducing than doing it in software like this. It may be worth trying to get HW dirty tracking working before adding more page fault-based tracking.
Quoted 4 lines
(I think there's also some oddity on S/390. I don't know what that oddity is or whether you should care.)
--Andy
Andy,
Thanks for the tip. It indeed sounds interesting, however there are a couple
of culprits:Quoted 7 lines
1) As you say, it sounds like there might be TLB flushing issues. Let's say
the TLB detects a write and raises an IRQ for the arch code to set the PTE
dirty bit, and before servicing that interrupt, we clear the PTE and flush
that TLB. What will happen?This should be fine. I assume that all architectures that do this kind of software dirty tracking will make the write block until the fault is handled, so the write won't have happened when you clear the PTE. After the TLB flush, the PTE will become dirty again and then the page will be written.
Quoted 4 lines
And if the TLB hardware would write directly to
the in-memory PTE I guess we'd have the same synchronization issues. I guess
we'd then need an atomic read-modify-write against the TLB hardware?IIRC the part that looked fishy to me was the combination of hw dirty tracking and write protecting the page. If you see that the pte is clean and want to write protect it, you probably need to set the write protect bit (atomically so you don't lose a dirty bit), flush the TLB, and then check the dirty bit again.
Quoted 3 lines
2) Even if most hardware is capable of this stuff, I'm not sure what would
happen in a virtual machine. Need to check.
Quoted 9 lines
Quoted 2 lines
This should be fine. Any VM monitor that fails to implement dirty tracking is probably terminally broken.
OK. I'll give it a try. If I understand this correctly, even if I set up a shared RW mapping, the
PTEs should magically be marked dirty if written to, and everything works as it should?
I *think* so. (It's certainly worth doing a quick-and-dirty test to make sure I'm not completely nuts before you invest too much time here -- I've read the code, and I've looked at the Intel specs, but I've never actually verified that pte_dirty and pte_mkclean to what I think they do.)
(If you ever intend to run on S/390, you should ask someone who understands what's going on. I, personally, have no clue, other than having seen references to something weird happening.)
--Andy
--
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>