copypage.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Based on arch/arm/mm/copypage.c
  4. *
  5. * Copyright (C) 2002 Deep Blue Solutions Ltd, All Rights Reserved.
  6. * Copyright (C) 2012 ARM Ltd.
  7. */
  8. #include <linux/bitops.h>
  9. #include <linux/mm.h>
  10. #include <asm/page.h>
  11. #include <asm/cacheflush.h>
  12. #include <asm/cpufeature.h>
  13. #include <asm/mte.h>
  14. void copy_highpage(struct page *to, struct page *from)
  15. {
  16. struct page *kto = page_address(to);
  17. struct page *kfrom = page_address(from);
  18. copy_page(kto, kfrom);
  19. if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) {
  20. set_bit(PG_mte_tagged, &to->flags);
  21. page_kasan_tag_reset(to);
  22. /*
  23. * We need smp_wmb() in between setting the flags and clearing the
  24. * tags because if another thread reads page->flags and builds a
  25. * tagged address out of it, there is an actual dependency to the
  26. * memory access, but on the current thread we do not guarantee that
  27. * the new page->flags are visible before the tags were updated.
  28. */
  29. smp_wmb();
  30. mte_copy_page_tags(kto, kfrom);
  31. }
  32. }
  33. EXPORT_SYMBOL(copy_highpage);
  34. void copy_user_highpage(struct page *to, struct page *from,
  35. unsigned long vaddr, struct vm_area_struct *vma)
  36. {
  37. copy_highpage(to, from);
  38. flush_dcache_page(to);
  39. }
  40. EXPORT_SYMBOL_GPL(copy_user_highpage);