kexec_image.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Image loader for kexec_file_load system call.
  4. *
  5. * Copyright IBM Corp. 2018
  6. *
  7. * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com>
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/kernel.h>
  11. #include <linux/kexec.h>
  12. #include <asm/setup.h>
  13. static int kexec_file_add_image_kernel(struct kimage *image,
  14. struct s390_load_data *data,
  15. char *kernel, unsigned long kernel_len)
  16. {
  17. struct kexec_buf buf;
  18. int ret;
  19. buf.image = image;
  20. buf.buffer = kernel + STARTUP_NORMAL_OFFSET;
  21. buf.bufsz = kernel_len - STARTUP_NORMAL_OFFSET;
  22. buf.mem = STARTUP_NORMAL_OFFSET;
  23. if (image->type == KEXEC_TYPE_CRASH)
  24. buf.mem += crashk_res.start;
  25. buf.memsz = buf.bufsz;
  26. ret = kexec_add_buffer(&buf);
  27. data->kernel_buf = kernel;
  28. data->memsz += buf.memsz + STARTUP_NORMAL_OFFSET;
  29. return ret;
  30. }
  31. static void *s390_image_load(struct kimage *image,
  32. char *kernel, unsigned long kernel_len,
  33. char *initrd, unsigned long initrd_len,
  34. char *cmdline, unsigned long cmdline_len)
  35. {
  36. struct s390_load_data data = {0};
  37. int ret;
  38. ret = kexec_file_add_image_kernel(image, &data, kernel, kernel_len);
  39. if (ret)
  40. return ERR_PTR(ret);
  41. if (initrd) {
  42. ret = kexec_file_add_initrd(image, &data, initrd, initrd_len);
  43. if (ret)
  44. return ERR_PTR(ret);
  45. }
  46. ret = kexec_file_add_purgatory(image, &data);
  47. if (ret)
  48. return ERR_PTR(ret);
  49. return kexec_file_update_kernel(image, &data);
  50. }
  51. static int s390_image_probe(const char *buf, unsigned long len)
  52. {
  53. /* Can't reliably tell if an image is valid. Therefore give the
  54. * user whatever he wants.
  55. */
  56. return 0;
  57. }
  58. const struct kexec_file_ops s390_kexec_image_ops = {
  59. .probe = s390_image_probe,
  60. .load = s390_image_load,
  61. };