jump_label.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. unsigned long *target;
  19. struct insn *insn;
  20. ssize_t size;
  21. };
  22. static int __arch_jump_label_transform(void *data)
  23. {
  24. struct insn_args *args = data;
  25. int rc;
  26. rc = probe_kernel_write(args->target, args->insn, args->size);
  27. WARN_ON_ONCE(rc < 0);
  28. return 0;
  29. }
  30. void arch_jump_label_transform(struct jump_entry *entry,
  31. enum jump_label_type type)
  32. {
  33. struct insn_args args;
  34. struct insn insn;
  35. if (type == JUMP_LABEL_ENABLE) {
  36. /* brcl 15,offset */
  37. insn.opcode = 0xc0f4;
  38. insn.offset = (entry->target - entry->code) >> 1;
  39. } else {
  40. /* brcl 0,0 */
  41. insn.opcode = 0xc004;
  42. insn.offset = 0;
  43. }
  44. args.target = (void *) entry->code;
  45. args.insn = &insn;
  46. args.size = JUMP_LABEL_NOP_SIZE;
  47. stop_machine(__arch_jump_label_transform, &args, NULL);
  48. }
  49. #endif