Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: trans_pgd: make trans_pgd_map_page generic

kexec is going to use a different allocator, so make
trans_pgd_map_page to accept allocator as an argument, and also
kexec is going to use a different map protection, so also pass
it via argument.

Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Matthias Brugger <mbrugger@suse.com>
Link: https://lore.kernel.org/r/20210125191923.1060122-5-pasha.tatashin@soleen.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Pavel Tatashin and committed by
Will Deacon
50f53fb7 072e3d96

+50 -11
+17 -2
arch/arm64/include/asm/trans_pgd.h
··· 12 12 #include <linux/types.h> 13 13 #include <asm/pgtable-types.h> 14 14 15 + /* 16 + * trans_alloc_page 17 + * - Allocator that should return exactly one zeroed page, if this 18 + * allocator fails, trans_pgd_create_copy() and trans_pgd_map_page() 19 + * return -ENOMEM error. 20 + * 21 + * trans_alloc_arg 22 + * - Passed to trans_alloc_page as an argument 23 + */ 24 + 25 + struct trans_pgd_info { 26 + void * (*trans_alloc_page)(void *arg); 27 + void *trans_alloc_arg; 28 + }; 29 + 15 30 int trans_pgd_create_copy(pgd_t **dst_pgdp, unsigned long start, 16 31 unsigned long end); 17 32 18 - int trans_pgd_map_page(pgd_t *trans_pgd, void *page, unsigned long dst_addr, 19 - pgprot_t pgprot); 33 + int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, 34 + void *page, unsigned long dst_addr, pgprot_t pgprot); 20 35 21 36 #endif /* _ASM_TRANS_TABLE_H */
+11 -1
arch/arm64/kernel/hibernate.c
··· 176 176 } 177 177 EXPORT_SYMBOL(arch_hibernation_header_restore); 178 178 179 + static void *hibernate_page_alloc(void *arg) 180 + { 181 + return (void *)get_safe_page((gfp_t)(unsigned long)arg); 182 + } 183 + 179 184 /* 180 185 * Copies length bytes, starting at src_start into an new page, 181 186 * perform cache maintenance, then maps it at the specified address low ··· 197 192 unsigned long dst_addr, 198 193 phys_addr_t *phys_dst_addr) 199 194 { 195 + struct trans_pgd_info trans_info = { 196 + .trans_alloc_page = hibernate_page_alloc, 197 + .trans_alloc_arg = (void *)GFP_ATOMIC, 198 + }; 199 + 200 200 void *page = (void *)get_safe_page(GFP_ATOMIC); 201 201 pgd_t *trans_pgd; 202 202 int rc; ··· 216 206 if (!trans_pgd) 217 207 return -ENOMEM; 218 208 219 - rc = trans_pgd_map_page(trans_pgd, page, dst_addr, 209 + rc = trans_pgd_map_page(&trans_info, trans_pgd, page, dst_addr, 220 210 PAGE_KERNEL_EXEC); 221 211 if (rc) 222 212 return rc;
+22 -8
arch/arm64/mm/trans_pgd.c
··· 25 25 #include <linux/mm.h> 26 26 #include <linux/mmzone.h> 27 27 28 + static void *trans_alloc(struct trans_pgd_info *info) 29 + { 30 + return info->trans_alloc_page(info->trans_alloc_arg); 31 + } 32 + 28 33 static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep, unsigned long addr) 29 34 { 30 35 pte_t pte = READ_ONCE(*src_ptep); ··· 206 201 return rc; 207 202 } 208 203 209 - int trans_pgd_map_page(pgd_t *trans_pgd, void *page, 210 - unsigned long dst_addr, 211 - pgprot_t pgprot) 204 + /* 205 + * Add map entry to trans_pgd for a base-size page at PTE level. 206 + * info: contains allocator and its argument 207 + * trans_pgd: page table in which new map is added. 208 + * page: page to be mapped. 209 + * dst_addr: new VA address for the page 210 + * pgprot: protection for the page. 211 + * 212 + * Returns 0 on success, and -ENOMEM on failure. 213 + */ 214 + int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, 215 + void *page, unsigned long dst_addr, pgprot_t pgprot) 212 216 { 213 217 pgd_t *pgdp; 214 218 p4d_t *p4dp; ··· 227 213 228 214 pgdp = pgd_offset_pgd(trans_pgd, dst_addr); 229 215 if (pgd_none(READ_ONCE(*pgdp))) { 230 - p4dp = (void *)get_safe_page(GFP_ATOMIC); 216 + p4dp = trans_alloc(info); 231 217 if (!pgdp) 232 218 return -ENOMEM; 233 219 pgd_populate(&init_mm, pgdp, p4dp); ··· 235 221 236 222 p4dp = p4d_offset(pgdp, dst_addr); 237 223 if (p4d_none(READ_ONCE(*p4dp))) { 238 - pudp = (void *)get_safe_page(GFP_ATOMIC); 224 + pudp = trans_alloc(info); 239 225 if (!pudp) 240 226 return -ENOMEM; 241 227 p4d_populate(&init_mm, p4dp, pudp); ··· 243 229 244 230 pudp = pud_offset(p4dp, dst_addr); 245 231 if (pud_none(READ_ONCE(*pudp))) { 246 - pmdp = (void *)get_safe_page(GFP_ATOMIC); 232 + pmdp = trans_alloc(info); 247 233 if (!pmdp) 248 234 return -ENOMEM; 249 235 pud_populate(&init_mm, pudp, pmdp); ··· 251 237 252 238 pmdp = pmd_offset(pudp, dst_addr); 253 239 if (pmd_none(READ_ONCE(*pmdp))) { 254 - ptep = (void *)get_safe_page(GFP_ATOMIC); 240 + ptep = trans_alloc(info); 255 241 if (!ptep) 256 242 return -ENOMEM; 257 243 pmd_populate_kernel(&init_mm, pmdp, ptep); 258 244 } 259 245 260 246 ptep = pte_offset_kernel(pmdp, dst_addr); 261 - set_pte(ptep, pfn_pte(virt_to_pfn(page), PAGE_KERNEL_EXEC)); 247 + set_pte(ptep, pfn_pte(virt_to_pfn(page), pgprot)); 262 248 263 249 return 0; 264 250 }