/* * Transitional page tables for kexec and hibernate * * This file derived from: arch/arm64/kernel/hibernate.c * * Copyright (c) 2021, Microsoft Corporation. * Pasha Tatashin <pasha.tatashin@soleen.com> *
*/
/* * Transitional tables are used during system transferring from one world to * another: such as during hibernate restore, and kexec reboots. During these * phases one cannot rely on page table not being overwritten. This is because * hibernate and kexec can overwrite the current page tables during transition.
*/
if (pte_valid(pte)) { /* * Resume will overwrite areas that may be marked * read only (code, rodata). Clear the RDONLY bit from * the temporary mappings we use during restore.
*/
__set_pte(dst_ptep, pte_mkwrite_novma(pte));
} elseif (!pte_none(pte)) { /* * debug_pagealloc will removed the PTE_VALID bit if * the page isn't in use by the resume kernel. It may have * been in use by the original kernel, in which case we need * to put it back in our copy to do the restore. * * Other cases include kfence / vmalloc / memfd_secret which * may call `set_direct_map_invalid_noflush()`. * * Before marking this entry valid, check the pfn should * be mapped.
*/
BUG_ON(!pfn_valid(pte_pfn(pte)));
dst_pgdp = pgd_offset_pgd(dst_pgdp, start); do {
next = pgd_addr_end(addr, end); if (pgd_none(READ_ONCE(*src_pgdp))) continue; if (copy_p4d(info, dst_pgdp, src_pgdp, addr, next)) return -ENOMEM;
} while (dst_pgdp++, src_pgdp++, addr = next, addr != end);
return 0;
}
/* * Create trans_pgd and copy linear map. * info: contains allocator and its argument * dst_pgdp: new page table that is created, and to which map is copied. * start: Start of the interval (inclusive). * end: End of the interval (exclusive). * * Returns 0 on success, and -ENOMEM on failure.
*/ int trans_pgd_create_copy(struct trans_pgd_info *info, pgd_t **dst_pgdp, unsignedlong start, unsignedlong end)
{ int rc;
pgd_t *trans_pgd = trans_alloc(info);
if (!trans_pgd) {
pr_err("Failed to allocate memory for temporary page tables.\n"); return -ENOMEM;
}
/* * The page we want to idmap may be outside the range covered by VA_BITS that * can be built using the kernel's p?d_populate() helpers. As a one off, for a * single page, we build these page tables bottom up and just assume that will * need the maximum T0SZ. * * Returns 0 on success, and -ENOMEM on failure. * On success trans_ttbr0 contains page table with idmapped page, t0sz is set to * maximum T0SZ for this page.
*/ int trans_pgd_idmap_page(struct trans_pgd_info *info, phys_addr_t *trans_ttbr0, unsignedlong *t0sz, void *page)
{
phys_addr_t dst_addr = virt_to_phys(page); unsignedlong pfn = __phys_to_pfn(dst_addr); int max_msb = (dst_addr & GENMASK(52, 48)) ? 51 : 47; int bits_mapped = PAGE_SHIFT - 4; unsignedlong level_mask, prev_level_entry, *levels[4]; int this_level, index, level_lsb, level_msb;
/* * Create a copy of the vector table so we can call HVC_SET_VECTORS or * HVC_SOFT_RESTART from contexts where the table may be overwritten.
*/ int trans_pgd_copy_el2_vectors(struct trans_pgd_info *info,
phys_addr_t *el2_vectors)
{ void *hyp_stub = trans_alloc(info);
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.