s390-dasd-ipl.rst 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. Booting from real channel-attached devices on s390x
  2. ===================================================
  3. s390 hardware IPL
  4. -----------------
  5. The s390 hardware IPL process consists of the following steps.
  6. 1. A READ IPL ccw is constructed in memory location ``0x0``.
  7. This ccw, by definition, reads the IPL1 record which is located on the disk
  8. at cylinder 0 track 0 record 1. Note that the chain flag is on in this ccw
  9. so when it is complete another ccw will be fetched and executed from memory
  10. location ``0x08``.
  11. 2. Execute the Read IPL ccw at ``0x00``, thereby reading IPL1 data into ``0x00``.
  12. IPL1 data is 24 bytes in length and consists of the following pieces of
  13. information: ``[psw][read ccw][tic ccw]``. When the machine executes the Read
  14. IPL ccw it read the 24-bytes of IPL1 to be read into memory starting at
  15. location ``0x0``. Then the ccw program at ``0x08`` which consists of a read
  16. ccw and a tic ccw is automatically executed because of the chain flag from
  17. the original READ IPL ccw. The read ccw will read the IPL2 data into memory
  18. and the TIC (Transfer In Channel) will transfer control to the channel
  19. program contained in the IPL2 data. The TIC channel command is the
  20. equivalent of a branch/jump/goto instruction for channel programs.
  21. NOTE: The ccws in IPL1 are defined by the architecture to be format 0.
  22. 3. Execute IPL2.
  23. The TIC ccw instruction at the end of the IPL1 channel program will begin
  24. the execution of the IPL2 channel program. IPL2 is stage-2 of the boot
  25. process and will contain a larger channel program than IPL1. The point of
  26. IPL2 is to find and load either the operating system or a small program that
  27. loads the operating system from disk. At the end of this step all or some of
  28. the real operating system is loaded into memory and we are ready to hand
  29. control over to the guest operating system. At this point the guest
  30. operating system is entirely responsible for loading any more data it might
  31. need to function.
  32. NOTE: The IPL2 channel program might read data into memory
  33. location ``0x0`` thereby overwriting the IPL1 psw and channel program. This is ok
  34. as long as the data placed in location ``0x0`` contains a psw whose instruction
  35. address points to the guest operating system code to execute at the end of
  36. the IPL/boot process.
  37. NOTE: The ccws in IPL2 are defined by the architecture to be format 0.
  38. 4. Start executing the guest operating system.
  39. The psw that was loaded into memory location ``0x0`` as part of the ipl process
  40. should contain the needed flags for the operating system we have loaded. The
  41. psw's instruction address will point to the location in memory where we want
  42. to start executing the operating system. This psw is loaded (via LPSW
  43. instruction) causing control to be passed to the operating system code.
  44. In a non-virtualized environment this process, handled entirely by the hardware,
  45. is kicked off by the user initiating a "Load" procedure from the hardware
  46. management console. This "Load" procedure crafts a special "Read IPL" ccw in
  47. memory location 0x0 that reads IPL1. It then executes this ccw thereby kicking
  48. off the reading of IPL1 data. Since the channel program from IPL1 will be
  49. written immediately after the special "Read IPL" ccw, the IPL1 channel program
  50. will be executed immediately (the special read ccw has the chaining bit turned
  51. on). The TIC at the end of the IPL1 channel program will cause the IPL2 channel
  52. program to be executed automatically. After this sequence completes the "Load"
  53. procedure then loads the psw from ``0x0``.
  54. How this all pertains to QEMU (and the kernel)
  55. ----------------------------------------------
  56. In theory we should merely have to do the following to IPL/boot a guest
  57. operating system from a DASD device:
  58. 1. Place a "Read IPL" ccw into memory location ``0x0`` with chaining bit on.
  59. 2. Execute channel program at ``0x0``.
  60. 3. LPSW ``0x0``.
  61. However, our emulation of the machine's channel program logic within the kernel
  62. is missing one key feature that is required for this process to work:
  63. non-prefetch of ccw data.
  64. When we start a channel program we pass the channel subsystem parameters via an
  65. ORB (Operation Request Block). One of those parameters is a prefetch bit. If the
  66. bit is on then the vfio-ccw kernel driver is allowed to read the entire channel
  67. program from guest memory before it starts executing it. This means that any
  68. channel commands that read additional channel commands will not work as expected
  69. because the newly read commands will only exist in guest memory and NOT within
  70. the kernel's channel subsystem memory. The kernel vfio-ccw driver currently
  71. requires this bit to be on for all channel programs. This is a problem because
  72. the IPL process consists of transferring control from the "Read IPL" ccw
  73. immediately to the IPL1 channel program that was read by "Read IPL".
  74. Not being able to turn off prefetch will also prevent the TIC at the end of the
  75. IPL1 channel program from transferring control to the IPL2 channel program.
  76. Lastly, in some cases (the zipl bootloader for example) the IPL2 program also
  77. transfers control to another channel program segment immediately after reading
  78. it from the disk. So we need to be able to handle this case.
  79. What QEMU does
  80. --------------
  81. Since we are forced to live with prefetch we cannot use the very simple IPL
  82. procedure we defined in the preceding section. So we compensate by doing the
  83. following.
  84. 1. Place "Read IPL" ccw into memory location ``0x0``, but turn off chaining bit.
  85. 2. Execute "Read IPL" at ``0x0``.
  86. So now IPL1's psw is at ``0x0`` and IPL1's channel program is at ``0x08``.
  87. 3. Write a custom channel program that will seek to the IPL2 record and then
  88. execute the READ and TIC ccws from IPL1. Normally the seek is not required
  89. because after reading the IPL1 record the disk is automatically positioned
  90. to read the very next record which will be IPL2. But since we are not reading
  91. both IPL1 and IPL2 as part of the same channel program we must manually set
  92. the position.
  93. 4. Grab the target address of the TIC instruction from the IPL1 channel program.
  94. This address is where the IPL2 channel program starts.
  95. Now IPL2 is loaded into memory somewhere, and we know the address.
  96. 5. Execute the IPL2 channel program at the address obtained in step #4.
  97. Because this channel program can be dynamic, we must use a special algorithm
  98. that detects a READ immediately followed by a TIC and breaks the ccw chain
  99. by turning off the chain bit in the READ ccw. When control is returned from
  100. the kernel/hardware to the QEMU bios code we immediately issue another start
  101. subchannel to execute the remaining TIC instruction. This causes the entire
  102. channel program (starting from the TIC) and all needed data to be refetched
  103. thereby stepping around the limitation that would otherwise prevent this
  104. channel program from executing properly.
  105. Now the operating system code is loaded somewhere in guest memory and the psw
  106. in memory location ``0x0`` will point to entry code for the guest operating
  107. system.
  108. 6. LPSW ``0x0``
  109. LPSW transfers control to the guest operating system and we're done.