#if __LINUX_ARM_ARCH__ < 6 /* * We take the easy way out of this problem - we make the * PTE uncacheable. However, we leave the write buffer on. * * Note that the pte lock held when calling update_mmu_cache must also * guard the pte (somewhere else in the same mm) that we modify here. * Therefore those configurations which might call adjust_pte (those * without CONFIG_CPU_CACHE_VIPT) cannot support split page_table_lock.
*/ staticint do_adjust_pte(struct vm_area_struct *vma, unsignedlong address, unsignedlong pfn, pte_t *ptep)
{
pte_t entry = *ptep; int ret;
/* * If this page is present, it's actually being shared.
*/
ret = pte_present(entry);
/* * If this page isn't present, or is already setup to * fault (ie, is old), we can safely ignore any issues.
*/ if (ret && (pte_val(entry) & L_PTE_MT_MASK) != shared_pte_mask) {
flush_cache_page(vma, address, pfn);
outer_flush_range((pfn << PAGE_SHIFT),
(pfn << PAGE_SHIFT) + PAGE_SIZE);
pte_val(entry) &= ~L_PTE_MT_MASK;
pte_val(entry) |= shared_pte_mask;
set_pte_at(vma->vm_mm, address, ptep, entry);
flush_tlb_page(vma, address);
}
pgd = pgd_offset(vma->vm_mm, address); if (pgd_none_or_clear_bad(pgd)) return 0;
p4d = p4d_offset(pgd, address); if (p4d_none_or_clear_bad(p4d)) return 0;
pud = pud_offset(p4d, address); if (pud_none_or_clear_bad(pud)) return 0;
pmd = pmd_offset(pud, address); if (pmd_none_or_clear_bad(pmd)) return 0;
again: /* * This is called while another page table is mapped, so we * must use the nested version. This also means we need to * open-code the spin-locking.
*/
pte = pte_offset_map_rw_nolock(vma->vm_mm, pmd, address, &pmdval, &ptl); if (!pte) return 0;
if (need_lock) { /* * Use nested version here to indicate that we are already * holding one similar spinlock.
*/
spin_lock_nested(ptl, SINGLE_DEPTH_NESTING); if (unlikely(!pmd_same(pmdval, pmdp_get_lockless(pmd)))) {
pte_unmap_unlock(pte, ptl); goto again;
}
}
/* * If we have any shared mappings that are in the same mm * space, then we need to handle them specially to maintain * cache coherency.
*/
flush_dcache_mmap_lock(mapping);
vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) { /* * If we are using split PTE locks, then we need to take the pte * lock. Otherwise we are using shared mm->page_table_lock which * is already locked, thus cannot take it.
*/ bool need_lock = IS_ENABLED(CONFIG_SPLIT_PTE_PTLOCKS); unsignedlong mpnt_addr;
/* * If this VMA is not in our MM, we can ignore it. * Note that we intentionally mask out the VMA * that we are fixing up.
*/ if (mpnt->vm_mm != mm || mpnt == vma) continue; if (!(mpnt->vm_flags & VM_MAYSHARE)) continue;
offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
mpnt_addr = mpnt->vm_start + offset;
/* Avoid deadlocks by not grabbing the same PTE lock again. */ if (mpnt_addr >= pmd_start_addr && mpnt_addr < pmd_end_addr)
need_lock = false;
aliases += adjust_pte(mpnt, mpnt_addr, pfn, need_lock);
}
flush_dcache_mmap_unlock(mapping); if (aliases)
do_adjust_pte(vma, addr, pfn, ptep);
}
/* * Take care of architecture specific things when placing a new PTE into * a page table, or changing an existing PTE. Basically, there are two * things that we need to take care of: * * 1. If PG_dcache_clean is not set for the page, we need to ensure * that any cache entries for the kernels virtual memory * range are written back to the page. * 2. If we have multiple shared mappings of the same space in * an object, we need to deal with the cache aliasing issues. * * Note that the pte lock will be held.
*/ void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, unsignedlong addr, pte_t *ptep, unsignedint nr)
{ unsignedlong pfn = pte_pfn(*ptep); struct address_space *mapping; struct folio *folio;
if (!pfn_valid(pfn)) return;
/* * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed.
*/ if (is_zero_pfn(pfn)) return;
/* * Check whether the write buffer has physical address aliasing * issues. If it has, we need to avoid them for the case where * we have several shared mappings of the same object in user * space.
*/ staticint __init check_writebuffer(unsignedlong *p1, unsignedlong *p2)
{ registerunsignedlong zero = 0, one = 1, val;
local_irq_disable();
mb();
*p1 = one;
mb();
*p2 = zero;
mb();
val = *p1;
mb();
local_irq_enable(); return val != zero;
}
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 und die Messung sind noch experimentell.