/** * struct wp_walk - Private struct for pagetable walk callbacks * @range: Range for mmu notifiers * @tlbflush_start: Address of first modified pte * @tlbflush_end: Address of last modified pte + 1 * @total: Total number of modified ptes
*/ struct wp_walk { struct mmu_notifier_range range; unsignedlong tlbflush_start; unsignedlong tlbflush_end; unsignedlong total;
};
/** * wp_pte - Write-protect a pte * @pte: Pointer to the pte * @addr: The start of protecting virtual address * @end: The end of protecting virtual address * @walk: pagetable walk callback argument * * The function write-protects a pte and records the range in * virtual address space of touched ptes for efficient range TLB flushes.
*/ staticint wp_pte(pte_t *pte, unsignedlong addr, unsignedlong end, struct mm_walk *walk)
{ struct wp_walk *wpwalk = walk->private;
pte_t ptent = ptep_get(pte);
if (pte_write(ptent)) {
pte_t old_pte = ptep_modify_prot_start(walk->vma, addr, pte);
/** * struct clean_walk - Private struct for the clean_record_pte function. * @base: struct wp_walk we derive from * @bitmap_pgoff: Address_space Page offset of the first bit in @bitmap * @bitmap: Bitmap with one bit for each page offset in the address_space range * covered. * @start: Address_space page offset of first modified pte relative * to @bitmap_pgoff * @end: Address_space page offset of last modified pte relative * to @bitmap_pgoff
*/ struct clean_walk { struct wp_walk base;
pgoff_t bitmap_pgoff; unsignedlong *bitmap;
pgoff_t start;
pgoff_t end;
};
/** * clean_record_pte - Clean a pte and record its address space offset in a * bitmap * @pte: Pointer to the pte * @addr: The start of virtual address to be clean * @end: The end of virtual address to be clean * @walk: pagetable walk callback argument * * The function cleans a pte and records the range in * virtual address space of touched ptes for efficient TLB flushes. * It also records dirty ptes in a bitmap representing page offsets * in the address_space, as well as the first and last of the bits * touched.
*/ staticint clean_record_pte(pte_t *pte, unsignedlong addr, unsignedlong end, struct mm_walk *walk)
{ struct wp_walk *wpwalk = walk->private; struct clean_walk *cwalk = to_clean_walk(wpwalk);
pte_t ptent = ptep_get(pte);
/* * wp_clean_pmd_entry - The pagewalk pmd callback. * * Dirty-tracking should take place on the PTE level, so * WARN() if encountering a dirty huge pmd. * Furthermore, never split huge pmds, since that currently * causes dirty info loss. The pagefault handler should do * that if needed.
*/ staticint wp_clean_pmd_entry(pmd_t *pmd, unsignedlong addr, unsignedlong end, struct mm_walk *walk)
{
pmd_t pmdval = pmdp_get_lockless(pmd);
/* Do not split a huge pmd, present or migrated */ if (pmd_trans_huge(pmdval)) {
WARN_ON(pmd_write(pmdval) || pmd_dirty(pmdval));
walk->action = ACTION_CONTINUE;
} return 0;
}
/* * wp_clean_pud_entry - The pagewalk pud callback. * * Dirty-tracking should take place on the PTE level, so * WARN() if encountering a dirty huge puds. * Furthermore, never split huge puds, since that currently * causes dirty info loss. The pagefault handler should do * that if needed.
*/ staticint wp_clean_pud_entry(pud_t *pud, unsignedlong addr, unsignedlong end, struct mm_walk *walk)
{ #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
pud_t pudval = READ_ONCE(*pud);
/* Do not split a huge pud */ if (pud_trans_huge(pudval)) {
WARN_ON(pud_write(pudval) || pud_dirty(pudval));
walk->action = ACTION_CONTINUE;
} #endif return 0;
}
/* * wp_clean_pre_vma - The pagewalk pre_vma callback. * * The pre_vma callback performs the cache flush, stages the tlb flush * and calls the necessary mmu notifiers.
*/ staticint wp_clean_pre_vma(unsignedlong start, unsignedlong end, struct mm_walk *walk)
{ struct wp_walk *wpwalk = walk->private;
/* * We're not using tlb_gather_mmu() since typically * only a small subrange of PTEs are affected, whereas * tlb_gather_mmu() records the full range.
*/
inc_tlb_flush_pending(walk->mm);
return 0;
}
/* * wp_clean_post_vma - The pagewalk post_vma callback. * * The post_vma callback performs the tlb flush and calls necessary mmu * notifiers.
*/ staticvoid wp_clean_post_vma(struct mm_walk *walk)
{ struct wp_walk *wpwalk = walk->private;
/** * wp_shared_mapping_range - Write-protect all ptes in an address space range * @mapping: The address_space we want to write protect * @first_index: The first page offset in the range * @nr: Number of incremental page offsets to cover * * Note: This function currently skips transhuge page-table entries, since * it's intended for dirty-tracking on the PTE level. It will warn on * encountering transhuge write-enabled entries, though, and can easily be * extended to handle them as well. * * Return: The number of ptes actually write-protected. Note that * already write-protected ptes are not counted.
*/ unsignedlong wp_shared_mapping_range(struct address_space *mapping,
pgoff_t first_index, pgoff_t nr)
{ struct wp_walk wpwalk = { .total = 0 };
/** * clean_record_shared_mapping_range - Clean and record all ptes in an * address space range * @mapping: The address_space we want to clean * @first_index: The first page offset in the range * @nr: Number of incremental page offsets to cover * @bitmap_pgoff: The page offset of the first bit in @bitmap * @bitmap: Pointer to a bitmap of at least @nr bits. The bitmap needs to * cover the whole range @first_index..@first_index + @nr. * @start: Pointer to number of the first set bit in @bitmap. * is modified as new bits are set by the function. * @end: Pointer to the number of the last set bit in @bitmap. * none set. The value is modified as new bits are set by the function. * * When this function returns there is no guarantee that a CPU has * not already dirtied new ptes. However it will not clean any ptes not * reported in the bitmap. The guarantees are as follows: * * * All ptes dirty when the function starts executing will end up recorded * in the bitmap. * * All ptes dirtied after that will either remain dirty, be recorded in the * bitmap or both. * * If a caller needs to make sure all dirty ptes are picked up and none * additional are added, it first needs to write-protect the address-space * range and make sure new writers are blocked in page_mkwrite() or * pfn_mkwrite(). And then after a TLB flush following the write-protection * pick up all dirty bits. * * This function currently skips transhuge page-table entries, since * it's intended for dirty-tracking on the PTE level. It will warn on * encountering transhuge dirty entries, though, and can easily be extended * to handle them as well. * * Return: The number of dirty ptes actually cleaned.
*/ unsignedlong clean_record_shared_mapping_range(struct address_space *mapping,
pgoff_t first_index, pgoff_t nr,
pgoff_t bitmap_pgoff, unsignedlong *bitmap,
pgoff_t *start,
pgoff_t *end)
{ bool none_set = (*start >= *end); struct clean_walk cwalk = {
.base = { .total = 0 },
.bitmap_pgoff = bitmap_pgoff,
.bitmap = bitmap,
.start = none_set ? nr : *start,
.end = none_set ? 0 : *end,
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.