| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Based on arch/arm/mm/copypage.c |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2002 Deep Blue Solutions Ltd, All Rights Reserved. |
|---|
| 5 | 6 | * Copyright (C) 2012 ARM Ltd. |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | 7 | */ |
|---|
| 19 | 8 | |
|---|
| 9 | +#include <linux/bitops.h> |
|---|
| 20 | 10 | #include <linux/mm.h> |
|---|
| 21 | 11 | |
|---|
| 22 | 12 | #include <asm/page.h> |
|---|
| 23 | 13 | #include <asm/cacheflush.h> |
|---|
| 14 | +#include <asm/cpufeature.h> |
|---|
| 15 | +#include <asm/mte.h> |
|---|
| 24 | 16 | |
|---|
| 25 | | -void __cpu_copy_user_page(void *kto, const void *kfrom, unsigned long vaddr) |
|---|
| 17 | +void copy_highpage(struct page *to, struct page *from) |
|---|
| 26 | 18 | { |
|---|
| 27 | | - struct page *page = virt_to_page(kto); |
|---|
| 19 | + void *kto = page_address(to); |
|---|
| 20 | + void *kfrom = page_address(from); |
|---|
| 21 | + |
|---|
| 28 | 22 | copy_page(kto, kfrom); |
|---|
| 29 | | - flush_dcache_page(page); |
|---|
| 30 | | -} |
|---|
| 31 | | -EXPORT_SYMBOL_GPL(__cpu_copy_user_page); |
|---|
| 32 | 23 | |
|---|
| 33 | | -void __cpu_clear_user_page(void *kaddr, unsigned long vaddr) |
|---|
| 34 | | -{ |
|---|
| 35 | | - clear_page(kaddr); |
|---|
| 24 | + if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) { |
|---|
| 25 | + set_bit(PG_mte_tagged, &to->flags); |
|---|
| 26 | + page_kasan_tag_reset(to); |
|---|
| 27 | + /* |
|---|
| 28 | + * We need smp_wmb() in between setting the flags and clearing the |
|---|
| 29 | + * tags because if another thread reads page->flags and builds a |
|---|
| 30 | + * tagged address out of it, there is an actual dependency to the |
|---|
| 31 | + * memory access, but on the current thread we do not guarantee that |
|---|
| 32 | + * the new page->flags are visible before the tags were updated. |
|---|
| 33 | + */ |
|---|
| 34 | + smp_wmb(); |
|---|
| 35 | + mte_copy_page_tags(kto, kfrom); |
|---|
| 36 | + } |
|---|
| 36 | 37 | } |
|---|
| 37 | | -EXPORT_SYMBOL_GPL(__cpu_clear_user_page); |
|---|
| 38 | +EXPORT_SYMBOL(copy_highpage); |
|---|
| 39 | + |
|---|
| 40 | +void copy_user_highpage(struct page *to, struct page *from, |
|---|
| 41 | + unsigned long vaddr, struct vm_area_struct *vma) |
|---|
| 42 | +{ |
|---|
| 43 | + copy_highpage(to, from); |
|---|
| 44 | + flush_dcache_page(to); |
|---|
| 45 | +} |
|---|
| 46 | +EXPORT_SYMBOL_GPL(copy_user_highpage); |
|---|