jump_label.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Jump label s390 support
  3. *
  4. * Copyright IBM Corp. 2011
  5. * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/stop_machine.h>
  10. #include <linux/jump_label.h>
  11. #include <asm/ipl.h>
  12. #ifdef HAVE_JUMP_LABEL
  13. struct insn {
  14. u16 opcode;
  15. s32 offset;
  16. } __packed;
  17. struct insn_args {
  18. struct jump_entry *entry;
  19. enum jump_label_type type;
  20. };
  21. static void __jump_label_transform(struct jump_entry *entry,
  22. enum jump_label_type type)
  23. {
  24. struct insn insn;
  25. int rc;
  26. if (type == JUMP_LABEL_ENABLE) {
  27. /* brcl 15,offset */
  28. insn.opcode = 0xc0f4;
  29. insn.offset = (entry->target - entry->code) >> 1;
  30. } else {
  31. /* brcl 0,0 */
  32. insn.opcode = 0xc004;
  33. insn.offset = 0;
  34. }
  35. rc = probe_kernel_write((void *)entry->code, &insn, JUMP_LABEL_NOP_SIZE);
  36. WARN_ON_ONCE(rc < 0);
  37. }
  38. static int __sm_arch_jump_label_transform(void *data)
  39. {
  40. struct insn_args *args = data;
  41. __jump_label_transform(args->entry, args->type);
  42. return 0;
  43. }
  44. void arch_jump_label_transform(struct jump_entry *entry,
  45. enum jump_label_type type)
  46. {
  47. struct insn_args args;
  48. args.entry = entry;
  49. args.type = type;
  50. stop_machine(__sm_arch_jump_label_transform, &args, NULL);
  51. }
  52. void arch_jump_label_transform_static(struct jump_entry *entry,
  53. enum jump_label_type type)
  54. {
  55. __jump_label_transform(entry, type);
  56. }
  57. #endif