alternative.c 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/uaccess.h>
  3. #include <asm/nospec-branch.h>
  4. #include <asm/abs_lowcore.h>
  5. #include <asm/alternative.h>
  6. #include <asm/facility.h>
  7. void __apply_alternatives(struct alt_instr *start, struct alt_instr *end, unsigned int ctx)
  8. {
  9. u8 *instr, *replacement;
  10. struct alt_instr *a;
  11. bool replace;
  12. /*
  13. * The scan order should be from start to end. A later scanned
  14. * alternative code can overwrite previously scanned alternative code.
  15. */
  16. for (a = start; a < end; a++) {
  17. if (!(a->ctx & ctx))
  18. continue;
  19. switch (a->type) {
  20. case ALT_TYPE_FACILITY:
  21. replace = test_facility(a->data);
  22. break;
  23. case ALT_TYPE_SPEC:
  24. replace = nobp_enabled();
  25. break;
  26. case ALT_TYPE_LOWCORE:
  27. replace = have_relocated_lowcore();
  28. break;
  29. default:
  30. replace = false;
  31. }
  32. if (!replace)
  33. continue;
  34. instr = (u8 *)&a->instr_offset + a->instr_offset;
  35. replacement = (u8 *)&a->repl_offset + a->repl_offset;
  36. s390_kernel_write(instr, replacement, a->instrlen);
  37. }
  38. }