shadow.c (b073d7f8aee4ebf05d10e3380df377b73120cf16) shadow.c (3c206509826094e85ead0b056f484db96829248d)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * KMSAN shadow implementation.
4 *
5 * Copyright (C) 2017-2022 Google LLC
6 * Author: Alexander Potapenko <glider@google.com>
7 *
8 */

--- 244 unchanged lines hidden (view full) ---

253 flush_tlb_kernel_range(origin_start, origin_end);
254 flush_cache_vmap(shadow_start, shadow_end);
255 flush_cache_vmap(origin_start, origin_end);
256
257ret:
258 kfree(s_pages);
259 kfree(o_pages);
260}
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * KMSAN shadow implementation.
4 *
5 * Copyright (C) 2017-2022 Google LLC
6 * Author: Alexander Potapenko <glider@google.com>
7 *
8 */

--- 244 unchanged lines hidden (view full) ---

253 flush_tlb_kernel_range(origin_start, origin_end);
254 flush_cache_vmap(shadow_start, shadow_end);
255 flush_cache_vmap(origin_start, origin_end);
256
257ret:
258 kfree(s_pages);
259 kfree(o_pages);
260}
261
262/* Allocate metadata for pages allocated at boot time. */
263void __init kmsan_init_alloc_meta_for_range(void *start, void *end)
264{
265 struct page *shadow_p, *origin_p;
266 void *shadow, *origin;
267 struct page *page;
268 u64 size;
269
270 start = (void *)ALIGN_DOWN((u64)start, PAGE_SIZE);
271 size = ALIGN((u64)end - (u64)start, PAGE_SIZE);
272 shadow = memblock_alloc(size, PAGE_SIZE);
273 origin = memblock_alloc(size, PAGE_SIZE);
274 for (u64 addr = 0; addr < size; addr += PAGE_SIZE) {
275 page = virt_to_page_or_null((char *)start + addr);
276 shadow_p = virt_to_page_or_null((char *)shadow + addr);
277 set_no_shadow_origin_page(shadow_p);
278 shadow_page_for(page) = shadow_p;
279 origin_p = virt_to_page_or_null((char *)origin + addr);
280 set_no_shadow_origin_page(origin_p);
281 origin_page_for(page) = origin_p;
282 }
283}
284
285void kmsan_setup_meta(struct page *page, struct page *shadow,
286 struct page *origin, int order)
287{
288 for (int i = 0; i < (1 << order); i++) {
289 set_no_shadow_origin_page(&shadow[i]);
290 set_no_shadow_origin_page(&origin[i]);
291 shadow_page_for(&page[i]) = &shadow[i];
292 origin_page_for(&page[i]) = &origin[i];
293 }
294}