jump_label.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2013 Huawei Ltd.
  4. * Author: Jiang Liu <liuj97@gmail.com>
  5. *
  6. * Based on arch/arm/kernel/jump_label.c
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/jump_label.h>
  10. #include <asm/insn.h>
  11. void arch_jump_label_transform(struct jump_entry *entry,
  12. enum jump_label_type type)
  13. {
  14. void *addr = (void *)jump_entry_code(entry);
  15. u32 insn;
  16. if (type == JUMP_LABEL_JMP) {
  17. insn = aarch64_insn_gen_branch_imm(jump_entry_code(entry),
  18. jump_entry_target(entry),
  19. AARCH64_INSN_BRANCH_NOLINK);
  20. } else {
  21. insn = aarch64_insn_gen_nop();
  22. }
  23. aarch64_insn_patch_text_nosync(addr, insn);
  24. }
  25. void arch_jump_label_transform_static(struct jump_entry *entry,
  26. enum jump_label_type type)
  27. {
  28. /*
  29. * We use the architected A64 NOP in arch_static_branch, so there's no
  30. * need to patch an identical A64 NOP over the top of it here. The core
  31. * will call arch_jump_label_transform from a module notifier if the
  32. * NOP needs to be replaced by a branch.
  33. */
  34. }