Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

s390.c 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /*
  2. * s390-specific syscalls decoders.
  3. *
  4. * Copyright (c) 2018 The strace developers.
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. #if defined S390 || defined S390X
  11. # include <sys/user.h>
  12. # include "print_fields.h"
  13. # include "xlat/s390_guarded_storage_commands.h"
  14. # include "xlat/s390_runtime_instr_commands.h"
  15. # include "xlat/s390_sthyi_function_codes.h"
  16. /*
  17. * Since, for some reason, kernel doesn't expose all these nice constants and
  18. * structures in UAPI, we have to re-declare them ourselves.
  19. */
  20. /**
  21. * "The header section is placed at the beginning of the response buffer and
  22. * identifies the location and length of all other sections. Valid sections have
  23. * nonzero offset values in the header. Each section provides information about
  24. * validity of fields within that section."
  25. */
  26. struct sthyi_hdr {
  27. /**
  28. * Header Flag Byte 1 - These flag settings indicate the environment
  29. * that the instruction was executed in and may influence the value of
  30. * the validity bits. The validity bits, and not these flags, should be
  31. * used to determine if a field is valid.
  32. * - 0x80 - Global Performance Data unavailable
  33. * - 0x40 - One or more hypervisor levels below this level does not
  34. * support the STHYI instruction. When this flag is set the
  35. * value of INFGPDU is not meaningful because the state of the
  36. * Global Performance Data setting cannot be determined.
  37. * - 0x20 - Virtualization stack is incomplete. This bit indicates one
  38. * of two cases:
  39. * - One or more hypervisor levels does not support the STHYI
  40. * instruction. For this case, INFSTHYI will also be set.
  41. * - There were more than three levels of guest/hypervisor information
  42. * to report.
  43. * - 0x10 - Execution environment is not within a logical partition.
  44. */
  45. uint8_t infhflg1;
  46. uint8_t infhflg2; /**< Header Flag Byte 2 reserved for IBM(R) use */
  47. uint8_t infhval1; /**< Header Validity Byte 1 reserved for IBM use */
  48. uint8_t infhval2; /**< Header Validity Byte 2 reserved for IBM use */
  49. char reserved_1__[3]; /**< Reserved for future IBM use */
  50. uint8_t infhygct; /**< Count of Hypervisor and Guest Sections */
  51. uint16_t infhtotl; /**< Total length of response buffer */
  52. uint16_t infhdln; /**< Length of Header Section mapped by INF0HDR */
  53. uint16_t infmoff; /**< Offset to Machine Section mapped by INF0MAC */
  54. uint16_t infmlen; /**< Length of Machine Section */
  55. uint16_t infpoff; /**< Offset to Partition Section mapped by INF0PAR */
  56. uint16_t infplen; /**< Length of Partition Section */
  57. uint16_t infhoff1; /**< Offset to Hypervisor Section1 mapped by INF0HYP */
  58. uint16_t infhlen1; /**< Length of Hypervisor Section1 */
  59. uint16_t infgoff1; /**< Offset to Guest Section1 mapped by INF0GST */
  60. uint16_t infglen1; /**< Length of Guest Section1 */
  61. uint16_t infhoff2; /**< Offset to Hypervisor Section2 mapped by INF0HYP */
  62. uint16_t infhlen2; /**< Length of Hypervisor Section2 */
  63. uint16_t infgoff2; /**< Offset to Guest Section2 mapped by INF0GST */
  64. uint16_t infglen2; /**< Length of Guest Section2 */
  65. uint16_t infhoff3; /**< Offset to Hypervisor Section3 mapped by INF0HYP */
  66. uint16_t infhlen3; /**< Length of Hypervisor Section3 */
  67. uint16_t infgoff3; /**< Offset to Guest Section3 mapped by INF0GST */
  68. uint16_t infglen3; /**< Length of Guest Section3 */
  69. /* 44 bytes in total */
  70. } ATTRIBUTE_PACKED;
  71. struct sthyi_machine {
  72. uint8_t infmflg1; /**< Machine Flag Byte 1 reserved for IBM use */
  73. uint8_t infmflg2; /**< Machine Flag Byte 2 reserved for IBM use */
  74. /**
  75. * Machine Validity Byte 1
  76. * - 0x80 - Processor Count Validity. When this bit is on, it indicates
  77. * that INFMSCPS, INFMDCPS, INFMSIFL, and INFMDIFL contain
  78. * valid counts. The validity bit may be off when:
  79. * - STHYI support is not available on a lower level hypervisor, or
  80. * - Global Performance Data is not enabled.
  81. * - 0x40 - Machine ID Validity. This bit being on indicates that a
  82. * SYSIB 1.1.1 was obtained from STSI and information reported
  83. * in the following fields is valid: INFMTYPE, INFMMANU,
  84. * INFMSEQ, and INFMPMAN.
  85. * - 0x20 - Machine Name Validity. This bit being on indicates that the
  86. * INFMNAME field is valid.
  87. */
  88. uint8_t infmval1;
  89. uint8_t infmval2; /**< Machine Validity Byte 2 reserved for IBM use */
  90. /**
  91. * Number of shared CPs configured in the machine or in the physical
  92. * partition if the system is physically partitioned.
  93. */
  94. uint16_t infmscps;
  95. /**
  96. * Number of dedicated CPs configured in this machine or in the physical
  97. * partition if the system is physically partitioned.
  98. */
  99. uint16_t infmdcps;
  100. /**
  101. * Number of shared IFLs configured in this machine or in the physical
  102. * partition if the system is physically partitioned.
  103. */
  104. uint16_t infmsifl;
  105. /**
  106. * Number of dedicated IFLs configured in this machine or in the
  107. * physical partition if the system is physically partitioned.
  108. */
  109. uint16_t infmdifl;
  110. char infmname[8]; /**< EBCDIC Machine Name */
  111. char infmtype[4]; /**< EBCDIC Type */
  112. char infmmanu[16]; /**< EBCDIC Manufacturer */
  113. char infmseq[16]; /**< EBCDIC Sequence Code */
  114. char infmpman[4]; /**< EBCDIC Plant of Manufacture */
  115. /* 60 bytes in total*/
  116. } ATTRIBUTE_PACKED;
  117. struct sthyi_partition {
  118. /**
  119. * Partition Flag Byte 1
  120. * - 0x80 - Multithreading (MT) is enabled.
  121. */
  122. uint8_t infpflg1;
  123. /** Partition Flag Byte 2 reserved for IBM use */
  124. uint8_t infpflg2;
  125. /**
  126. * Partition Validity Byte 1
  127. * - 0x80 - Processor count validity. This bit being on indicates that
  128. * INFPSCPS, INFPDCPS, INFPSIFL, and INFPDIFL contain valid
  129. * counts.
  130. * - 0x40 - Partition weight-based capped capacity validity. This bit
  131. * being on indicates that INFPWBCP and INFPWBIF are valid
  132. * - 0x20 - Partition absolute capped capacity validity. This bit being
  133. * on indicates that INFPABCP and INFPABIF are valid.
  134. * - 0x10 - Partition ID validity. This bit being on indicates that a
  135. * SYSIB 2.2.2 was obtained from STSI and information reported
  136. * in the following fields is valid: INFPPNUM and INFPPNAM.
  137. * - 0x08 - LPAR group absolute capacity capping information validity.
  138. * This bit being on indicates that INFPLGNM, INFPLGCP, and
  139. * INFPLGIF are valid.
  140. */
  141. uint8_t infpval1;
  142. /** Partition Validity Byte 2 reserved for IBM use */
  143. uint8_t infpval2;
  144. /** Logical partition number */
  145. uint16_t infppnum;
  146. /**
  147. * Number of shared logical CPs configured for this partition. Count
  148. * of cores when MT is enabled.
  149. */
  150. uint16_t infpscps;
  151. /**
  152. * Number of dedicated logical CPs configured for this partition. Count
  153. * of cores when MT is enabled.
  154. */
  155. uint16_t infpdcps;
  156. /**
  157. * Number of shared logical IFLs configured for this partition. Count
  158. * of cores when MT is enabled.
  159. */
  160. uint16_t infpsifl;
  161. /**
  162. * Number of dedicated logical IFLs configured for this partition.
  163. * Count of cores when MT is enabled.
  164. */
  165. uint16_t infpdifl;
  166. /** Reserved for future IBM use */
  167. char reserved_1__[2];
  168. /** EBCIDIC Logical partition name */
  169. char infppnam[8];
  170. /**
  171. * Partition weight-based capped capacity for CPs, a scaled number where
  172. * 0x00010000 represents one core. Zero if not capped.
  173. */
  174. uint32_t infpwbcp;
  175. /**
  176. * Partition absolute capped capacity for CPs, a scaled number where
  177. * 0x00010000 represents one core. Zero if not capped.
  178. */
  179. uint32_t infpabcp;
  180. /**
  181. * Partition weight-based capped capacity for IFLs, a scaled number
  182. * where 0x00010000 represents one core. Zero if not capped.
  183. */
  184. uint32_t infpwbif;
  185. /**
  186. * Partition absolute capped capacity for IFLs, a scaled number where
  187. * 0x00010000 represents one core. Zero if not capped.
  188. */
  189. uint32_t infpabif;
  190. /**
  191. * EBCIDIC LPAR group name. Binary zeros when the partition is not in
  192. * an LPAR group. EBCDIC and padded with blanks on the right when in a
  193. * group. The group name is reported only when there is a group cap on
  194. * CP or IFL CPU types and the partition has the capped CPU type.
  195. */
  196. char infplgnm[8];
  197. /**
  198. * LPAR group absolute capacity value for CP CPU type when nonzero. This
  199. * field will be nonzero only when INFPLGNM is nonzero and a cap is
  200. * defined for the LPAR group for the CP CPU type. When nonzero,
  201. * contains a scaled number where 0x00010000 represents one core.
  202. */
  203. uint32_t infplgcp;
  204. /**
  205. * LPAR group absolute capacity value for IFL CPU type when nonzero.
  206. * This field will be nonzero only when INFPLGNM is nonzero and a cap
  207. * is defined for the LPAR group for the IFL CPU type. When nonzero,
  208. * contains a scaled number where 0x00010000 represents one core.
  209. */
  210. uint32_t infplgif;
  211. /* 56 bytes */
  212. } ATTRIBUTE_PACKED;
  213. struct sthyi_hypervisor {
  214. /**
  215. * Hypervisor Flag Byte 1
  216. * - 0x80 - Guest CPU usage hard limiting is using the consumption
  217. * method.
  218. * - 0x40 - If on, LIMITHARD caps use prorated core time for capping.
  219. * If off, raw CPU time is used.
  220. */
  221. uint8_t infyflg1;
  222. uint8_t infyflg2; /**< Hypervisor Flag Byte 2 reserved for IBM use */
  223. uint8_t infyval1; /**< Hypervisor Validity Byte 1 reserved for IBM use */
  224. uint8_t infyval2; /**< Hypervisor Validity Byte 2 reserved for IBM use */
  225. /**
  226. * Hypervisor Type
  227. * - 1 - z/VM is the hypervisor.
  228. */
  229. uint8_t infytype;
  230. char reserved_1__[1]; /**< Reserved for future IBM use */
  231. /**
  232. * Threads in use per CP core. Only valid when MT enabled
  233. * (INFPFLG1 0x80 is ON).
  234. */
  235. uint8_t infycpt;
  236. /**
  237. * Threads in use per IFL core. Only valid when MT enabled
  238. * (INFPFLG1 0x80 is ON).
  239. */
  240. uint8_t infyiflt;
  241. /**
  242. * EBCID System Identifier. Left justified and padded with blanks.
  243. * This field will be blanks if non-existent.
  244. */
  245. char infysyid[8];
  246. /**
  247. * EBCID Cluster Name. Left justified and padded with blanks. This is
  248. * the name on the SSI statement in the system configuration file. This
  249. * field will be blanks if nonexistent.
  250. */
  251. char infyclnm[8];
  252. /**
  253. * Total number of CPs shared among guests of this hypervisor.
  254. * Number of cores when MT enabled.
  255. */
  256. uint16_t infyscps;
  257. /**
  258. * Total number of CPs dedicated to guests of this hypervisor.
  259. * Number of cores when MT enabled.
  260. */
  261. uint16_t infydcps;
  262. /**
  263. * Total number of IFLs shared among guests of this hypervisor.
  264. * Number of cores when MT enabled.
  265. */
  266. uint16_t infysifl;
  267. /**
  268. * Total number of IFLs dedicated to guests of this hypervisor.
  269. * Number of cores when MT enabled.
  270. */
  271. uint16_t infydifl;
  272. /* 32 bytes */
  273. } ATTRIBUTE_PACKED;
  274. struct sthyi_guest {
  275. /**
  276. * Guest Flag Byte 1
  277. * - 0x80 - Guest is mobility enabled
  278. * - 0x40 - Guest has multiple virtual CPU types
  279. * - 0x20 - Guest CP dispatch type has LIMITHARD cap
  280. * - 0x10 - Guest IFL dispatch type has LIMITHARD cap
  281. * - 0x08 - Virtual CPs are thread dispatched
  282. * - 0x04 - Virtual IFLs are thread dispatched
  283. */
  284. uint8_t infgflg1;
  285. uint8_t infgflg2; /**< Guest Flag Byte 2 reserved for IBM use */
  286. uint8_t infgval1; /**< Guest Validity Byte 1 reserved for IBM use */
  287. uint8_t infgval2; /**< Guest Validity Byte 2 reserved for IBM use */
  288. char infgusid[8]; /**< EBCDIC Userid */
  289. uint16_t infgscps; /**< Number of guest shared CPs */
  290. uint16_t infgdcps; /**< Number of guest dedicated CPs */
  291. /**
  292. * Dispatch type for guest CPs. This field is valid if INFGSCPS or
  293. * INFGDCPS is greater than zero.
  294. * - 0 - General Purpose (CP)
  295. */
  296. uint8_t infgcpdt;
  297. char reserved_1__[3]; /**< Reserved for future IBM use */
  298. /**
  299. * Guest current capped capacity for shared virtual CPs, a scaled number
  300. * where 0x00010000 represents one core. This field is zero to
  301. * indicate not capped when:
  302. * - There is no CP individual limit (that is, the "Guest CP dispatch
  303. * type has LIMITHARD cap" bit in field INFGFLG1 is OFF).
  304. * - There are no shared CPs on the system (that is, INFYSCPS = 0).
  305. * If there is a CP limit but there are no shared CPs or virtual CPs,
  306. * the limit is meaningless and does not apply to anything.
  307. */
  308. uint32_t infgcpcc;
  309. uint16_t infgsifl; /**< Number of guest shared IFLs */
  310. uint16_t infgdifl; /**< Number of guest dedicated IFLs */
  311. /**
  312. * Dispatch type for guest IFLs. This field is valid if INFGSIFL or
  313. * INFGDIFL is greater than zero.
  314. * - 0 - General Purpose (CP)
  315. * - 3 - Integrated Facility for Linux (IFL)
  316. */
  317. uint8_t infgifdt;
  318. char reserved_2__[3]; /**< Reserved for future IBM use */
  319. /**
  320. * Guest current capped capacity for shared virtual IFLs, a scaled
  321. * number where 0x00010000 represents one core. This field is zero
  322. * to indicate not capped with an IFL limit when:
  323. * - There is no IFL individual limit (that is, the "Guest IFL dispatch
  324. * type has LIMITHARD cap" bit in field INFGFLG1 is OFF).
  325. * - The guest's IFLs are dispatched on CPs (that is, INFGIFDT = 00).
  326. * When the guest's IFLs are dispatched on CPs, the CP individual
  327. * limit (in INFGCPCC) is applied to the guest's virtual IFLs and
  328. * virtual CPs.
  329. */
  330. uint32_t infgifcc;
  331. /**
  332. * CPU Pool Capping Flags
  333. * - 0x80 - CPU Pool's CP virtual type has LIMITHARD cap
  334. * - 0x40 - CPU Pool's CP virtual type has CAPACITY cap
  335. * - 0x20 - CPU Pool's IFL virtual type has LIMITHARD cap
  336. * - 0x10 - CPU Pool's IFL virtual type has CAPACITY cap
  337. * - 0x08 - CPU Pool uses prorated core time.
  338. */
  339. uint8_t infgpflg;
  340. char reserved_3__[3]; /**< Reserved for future IBM use */
  341. /**
  342. * EBCDIC CPU Pool Name. This field will be blanks if the guest is not
  343. * in a CPU Pool.
  344. */
  345. char infgpnam[8];
  346. /**
  347. * CPU Pool capped capacity for shared virtual CPs, a scaled number
  348. * where 0x00010000 represents one core. This field will be zero if
  349. * not capped.
  350. */
  351. uint32_t infgpccc;
  352. /**
  353. * CPU Pool capped capacity for shared virtual IFLs, a scaled number
  354. * where 0x00010000 represents one core. This field will be zero if
  355. * not capped.
  356. */
  357. uint32_t infgpicc;
  358. /* 56 bytes */
  359. } ATTRIBUTE_PACKED;
  360. static void
  361. decode_ebcdic(const char *ebcdic, char *ascii, size_t size)
  362. {
  363. /*
  364. * This is mostly Linux's EBCDIC-ASCII conversion table, except for
  365. * various non-representable characters that are converted to spaces for
  366. * readability purposes, as it is intended to be a hint for the string
  367. * contents and not precise conversion.
  368. */
  369. static char conv_table[] =
  370. "\0\1\2\3 \11 \177 \13\14\15\16\17"
  371. "\20\21\22\23 \n\10 \30\31 \34\35\36\37"
  372. " \34 \n\27\33 \5\6\7"
  373. " \26 \4 \24\25 \32"
  374. " " " .<(+|"
  375. "& " "!$*);~"
  376. "-/ " "|,%_>?"
  377. " `" ":#@'=\""
  378. " abcdefghi" " "
  379. " jklmnopqr" " "
  380. " ~stuvwxyz" " "
  381. "^ " "[] "
  382. "{ABCDEFGHI" " "
  383. "}JKLMNOPQR" " "
  384. "\\ STUVWXYZ" " "
  385. "0123456789" " ";
  386. while (size--)
  387. *ascii++ = conv_table[(unsigned char) *ebcdic++];
  388. }
  389. # define DECODE_EBCDIC(ebcdic_, ascii_) \
  390. decode_ebcdic((ebcdic_), (ascii_), \
  391. sizeof(ebcdic_) + MUST_BE_ARRAY(ebcdic_))
  392. # define PRINT_EBCDIC(ebcdic_) \
  393. do { \
  394. char ascii_str[sizeof(ebcdic_) + MUST_BE_ARRAY(ebcdic_)]; \
  395. \
  396. DECODE_EBCDIC(ebcdic_, ascii_str); \
  397. print_quoted_string(ascii_str, sizeof(ascii_str), \
  398. QUOTE_EMIT_COMMENT); \
  399. } while (0)
  400. # define PRINT_FIELD_EBCDIC(prefix_, where_, field_) \
  401. do { \
  402. PRINT_FIELD_HEX_ARRAY(prefix_, where_, field_); \
  403. PRINT_EBCDIC((where_).field_); \
  404. } while (0)
  405. # define PRINT_FIELD_WEIGHT(prefix_, where_, field_) \
  406. do { \
  407. PRINT_FIELD_X(prefix_, where_, field_); \
  408. if ((where_).field_) \
  409. tprintf_comment("%u %u/65536 cores", \
  410. (where_).field_ >> 16, \
  411. (where_).field_ & 0xFFFF); \
  412. else \
  413. tprints_comment("unlimited"); \
  414. } while (0)
  415. # define IS_BLANK(arr_) /* 0x40 is space in EBCDIC */ \
  416. is_filled(arr_, '\x40', sizeof(arr_) + MUST_BE_ARRAY(arr_))
  417. # define CHECK_SIZE(hdr_, size_, name_, ...) \
  418. do { \
  419. if ((size_) < sizeof(*(hdr_))) { \
  420. tprintf_comment("Invalid " name_ " with size " \
  421. "%hu < %zu expected", \
  422. ##__VA_ARGS__, \
  423. (size_), sizeof(*(hdr_))); \
  424. print_quoted_string((char *) (hdr_), (size_), \
  425. QUOTE_FORCE_HEX); \
  426. \
  427. return; \
  428. } \
  429. } while (0)
  430. # define PRINT_UNKNOWN_TAIL(hdr_, size_) \
  431. do { \
  432. if ((size_) > sizeof(*(hdr_)) && \
  433. !is_filled((char *) ((hdr_) + 1), '\0', \
  434. (size_) - sizeof(*(hdr_)))) { \
  435. tprints(", "); \
  436. print_quoted_string((char *) ((hdr_) + 1), \
  437. (size_) - sizeof(*(hdr_)), \
  438. QUOTE_FORCE_HEX); \
  439. } \
  440. } while (0)
  441. static void
  442. print_sthyi_machine(struct tcb *tcp, struct sthyi_machine *hdr, uint16_t size,
  443. bool *dummy)
  444. {
  445. int cnt_val, name_val, id_val;
  446. CHECK_SIZE(hdr, size, "machine structure");
  447. tprints("/* machine */ {");
  448. if (!abbrev(tcp)) {
  449. if (hdr->infmflg1) { /* Reserved */
  450. PRINT_FIELD_0X("", *hdr, infmflg1);
  451. tprints(", ");
  452. }
  453. if (hdr->infmflg2) { /* Reserved */
  454. PRINT_FIELD_0X(", ", *hdr, infmflg2);
  455. tprints(", ");
  456. }
  457. }
  458. PRINT_FIELD_0X("", *hdr, infmval1);
  459. cnt_val = !!(hdr->infmval1 & 0x80);
  460. id_val = !!(hdr->infmval1 & 0x40);
  461. name_val = !!(hdr->infmval1 & 0x20);
  462. if (!abbrev(tcp)) {
  463. if (hdr->infmval1)
  464. tprintf_comment("processor count validity: %d, "
  465. "machine ID validity: %d, "
  466. "machine name validity: %d%s%#.0x%s",
  467. cnt_val, id_val, name_val,
  468. hdr->infmval1 & 0x1F ? ", " : "",
  469. hdr->infmval1 & 0x1F,
  470. hdr->infmval1 & 0x1F ? " - ???" : "");
  471. if (hdr->infmval2)
  472. PRINT_FIELD_0X(", ", *hdr, infmval2);
  473. }
  474. if (cnt_val || hdr->infmscps)
  475. PRINT_FIELD_U(", ", *hdr, infmscps);
  476. if (cnt_val || hdr->infmdcps)
  477. PRINT_FIELD_U(", ", *hdr, infmdcps);
  478. if (cnt_val || hdr->infmsifl)
  479. PRINT_FIELD_U(", ", *hdr, infmsifl);
  480. if (cnt_val || hdr->infmdifl)
  481. PRINT_FIELD_U(", ", *hdr, infmdifl);
  482. if (!abbrev(tcp)) {
  483. if (name_val || hdr->infmname)
  484. PRINT_FIELD_EBCDIC(", ", *hdr, infmname);
  485. if (id_val || !IS_ARRAY_ZERO(hdr->infmtype))
  486. PRINT_FIELD_EBCDIC(", ", *hdr, infmtype);
  487. if (id_val || !IS_ARRAY_ZERO(hdr->infmmanu))
  488. PRINT_FIELD_EBCDIC(", ", *hdr, infmmanu);
  489. if (id_val || !IS_ARRAY_ZERO(hdr->infmseq))
  490. PRINT_FIELD_EBCDIC(", ", *hdr, infmseq);
  491. if (id_val || !IS_ARRAY_ZERO(hdr->infmpman))
  492. PRINT_FIELD_EBCDIC(", ", *hdr, infmpman);
  493. PRINT_UNKNOWN_TAIL(hdr, size);
  494. } else {
  495. tprints(", ...");
  496. }
  497. tprints("}");
  498. }
  499. static void
  500. print_sthyi_partition(struct tcb *tcp, struct sthyi_partition *hdr,
  501. uint16_t size, bool *mt)
  502. {
  503. int cnt_val, wcap_val, acap_val, id_val, lpar_val;
  504. *mt = false;
  505. CHECK_SIZE(hdr, size, "partition structure");
  506. *mt = !!(hdr->infpflg1 & 0x80);
  507. PRINT_FIELD_0X("/* partition */ {", *hdr, infpflg1);
  508. if (!abbrev(tcp) && hdr->infpflg1)
  509. tprintf_comment("%s%s%#.0x%s",
  510. hdr->infpflg1 & 0x80 ?
  511. "0x80 - multithreading is enabled" : "",
  512. (hdr->infpflg1 & 0x80) && (hdr->infpflg1 & 0x7F) ?
  513. ", " : "",
  514. hdr->infpflg1 & 0x7F,
  515. hdr->infpflg1 & 0x7F ? " - ???" : "");
  516. if (!abbrev(tcp) && hdr->infpflg2) /* Reserved */
  517. PRINT_FIELD_0X(", ", *hdr, infpflg2);
  518. PRINT_FIELD_0X(", ", *hdr, infpval1);
  519. cnt_val = !!(hdr->infpval1 & 0x80);
  520. wcap_val = !!(hdr->infpval1 & 0x40);
  521. acap_val = !!(hdr->infpval1 & 0x20);
  522. id_val = !!(hdr->infpval1 & 0x10);
  523. lpar_val = !!(hdr->infpval1 & 0x08);
  524. if (!abbrev(tcp) && hdr->infpval1)
  525. tprintf_comment("processor count validity: %d, "
  526. "partition weight-based capacity validity: %d, "
  527. "partition absolute capacity validity: %d, "
  528. "partition ID validity: %d, "
  529. "LPAR group absolute capacity capping "
  530. "information validity: %d%s%#.0x%s",
  531. cnt_val, wcap_val, acap_val, id_val, lpar_val,
  532. hdr->infpval1 & 0x07 ? ", " : "",
  533. hdr->infpval1 & 0x07,
  534. hdr->infpval1 & 0x07 ? " - ???" : "");
  535. if (!abbrev(tcp) && hdr->infpval2) /* Reserved */
  536. PRINT_FIELD_0X(", ", *hdr, infpval2);
  537. if (id_val || hdr->infppnum)
  538. PRINT_FIELD_U(", ", *hdr, infppnum);
  539. if (cnt_val || hdr->infpscps)
  540. PRINT_FIELD_U(", ", *hdr, infpscps);
  541. if (cnt_val || hdr->infpdcps)
  542. PRINT_FIELD_U(", ", *hdr, infpdcps);
  543. if (cnt_val || hdr->infpsifl)
  544. PRINT_FIELD_U(", ", *hdr, infpsifl);
  545. if (cnt_val || hdr->infpdifl)
  546. PRINT_FIELD_U(", ", *hdr, infpdifl);
  547. if (!abbrev(tcp) && !IS_ARRAY_ZERO(hdr->reserved_1__))
  548. PRINT_FIELD_HEX_ARRAY(", ", *hdr, reserved_1__);
  549. if (id_val || !IS_ARRAY_ZERO(hdr->infppnam))
  550. PRINT_FIELD_EBCDIC(", ", *hdr, infppnam);
  551. if (!abbrev(tcp)) {
  552. if (wcap_val || hdr->infpwbcp)
  553. PRINT_FIELD_WEIGHT(", ", *hdr, infpwbcp);
  554. if (acap_val || hdr->infpabcp)
  555. PRINT_FIELD_WEIGHT(", ", *hdr, infpabcp);
  556. if (wcap_val || hdr->infpwbif)
  557. PRINT_FIELD_WEIGHT(", ", *hdr, infpwbif);
  558. if (acap_val || hdr->infpabif)
  559. PRINT_FIELD_WEIGHT(", ", *hdr, infpabif);
  560. if (!IS_ARRAY_ZERO(hdr->infplgnm)) {
  561. PRINT_FIELD_EBCDIC(", ", *hdr, infplgnm);
  562. PRINT_FIELD_WEIGHT(", ", *hdr, infplgcp);
  563. PRINT_FIELD_WEIGHT(", ", *hdr, infplgif);
  564. } else {
  565. if (lpar_val)
  566. PRINT_FIELD_HEX_ARRAY(", ", *hdr, infplgnm);
  567. if (hdr->infplgcp)
  568. PRINT_FIELD_X(", ", *hdr, infplgcp);
  569. if (hdr->infplgif)
  570. PRINT_FIELD_X(", ", *hdr, infplgif);
  571. }
  572. PRINT_UNKNOWN_TAIL(hdr, size);
  573. } else {
  574. tprints(", ...");
  575. }
  576. tprints("}");
  577. }
  578. static void
  579. print_sthyi_hypervisor(struct tcb *tcp, struct sthyi_hypervisor *hdr,
  580. uint16_t size, int num, bool mt)
  581. {
  582. CHECK_SIZE(hdr, size, "hypervisor %d structure", num);
  583. tprintf("/* hypervisor %d */ ", num);
  584. PRINT_FIELD_0X("{", *hdr, infyflg1);
  585. if (!abbrev(tcp) && hdr->infyflg1)
  586. tprintf_comment("%s%s%s%s%#.0x%s",
  587. hdr->infyflg1 & 0x80 ?
  588. "0x80 - guest CPU usage had limiting is using "
  589. "the consumption method" : "",
  590. (hdr->infyflg1 & 0x80) && (hdr->infyflg1 & 0x40) ?
  591. ", " : "",
  592. hdr->infyflg1 & 0x40 ?
  593. "0x40 - LIMITHARD caps use prorated core time "
  594. "for capping" : "",
  595. (hdr->infyflg1 & 0xC0) && (hdr->infyflg1 & 0x3F) ?
  596. ", " : "",
  597. hdr->infyflg1 & 0x3F,
  598. hdr->infyflg1 & 0x3F ? " - ???" : "");
  599. if (!abbrev(tcp)) {
  600. if (hdr->infyflg2) /* Reserved */
  601. PRINT_FIELD_0X(", ", *hdr, infyflg2);
  602. if (hdr->infyval1) /* Reserved */
  603. PRINT_FIELD_0X(", ", *hdr, infyval1);
  604. if (hdr->infyval2) /* Reserved */
  605. PRINT_FIELD_0X(", ", *hdr, infyval2);
  606. PRINT_FIELD_U(", ", *hdr, infytype);
  607. switch (hdr->infytype) {
  608. case 1:
  609. tprints_comment("z/VM is the hypervisor");
  610. break;
  611. default:
  612. tprints_comment("unknown hypervisor type");
  613. }
  614. if (!IS_ARRAY_ZERO(hdr->reserved_1__))
  615. PRINT_FIELD_HEX_ARRAY(", ", *hdr, reserved_1__);
  616. if (mt || hdr->infycpt)
  617. PRINT_FIELD_U(", ", *hdr, infycpt);
  618. if (mt || hdr->infyiflt)
  619. PRINT_FIELD_U(", ", *hdr, infyiflt);
  620. }
  621. if (!abbrev(tcp) || !IS_BLANK(hdr->infysyid))
  622. PRINT_FIELD_EBCDIC(", ", *hdr, infysyid);
  623. if (!abbrev(tcp) || !IS_BLANK(hdr->infyclnm))
  624. PRINT_FIELD_EBCDIC(", ", *hdr, infyclnm);
  625. if (!abbrev(tcp) || hdr->infyscps)
  626. PRINT_FIELD_U(", ", *hdr, infyscps);
  627. if (!abbrev(tcp) || hdr->infydcps)
  628. PRINT_FIELD_U(", ", *hdr, infydcps);
  629. if (!abbrev(tcp) || hdr->infysifl)
  630. PRINT_FIELD_U(", ", *hdr, infysifl);
  631. if (!abbrev(tcp) || hdr->infydifl)
  632. PRINT_FIELD_U(", ", *hdr, infydifl);
  633. if (!abbrev(tcp)) {
  634. PRINT_UNKNOWN_TAIL(hdr, size);
  635. } else {
  636. tprints(", ...");
  637. }
  638. tprints("}");
  639. }
  640. static void
  641. print_sthyi_guest(struct tcb *tcp, struct sthyi_guest *hdr, uint16_t size,
  642. int num, bool mt)
  643. {
  644. CHECK_SIZE(hdr, size, "guest %d structure", num);
  645. tprintf("/* guest %d */ ", num);
  646. PRINT_FIELD_0X("{", *hdr, infgflg1);
  647. if (!abbrev(tcp) && hdr->infgflg1)
  648. tprintf_comment("%s%s%s%s%s%s%s%s%s%s%s%s%#.0x%s",
  649. hdr->infgflg1 & 0x80 ?
  650. "0x80 - guest is mobility enabled" : "",
  651. (hdr->infgflg1 & 0x80) && (hdr->infgflg1 & 0x40) ?
  652. ", " : "",
  653. hdr->infgflg1 & 0x40 ?
  654. "0x40 - guest has multiple virtual CPU types" :
  655. "",
  656. (hdr->infgflg1 & 0xC0) && (hdr->infgflg1 & 0x20) ?
  657. ", " : "",
  658. hdr->infgflg1 & 0x20 ?
  659. "0x20 - guest CP dispatch type has LIMITHARD "
  660. "cap" : "",
  661. (hdr->infgflg1 & 0xE0) && (hdr->infgflg1 & 0x10) ?
  662. ", " : "",
  663. hdr->infgflg1 & 0x10 ?
  664. "0x10 - guest IFL dispatch type has LIMITHARD "
  665. "cap" : "",
  666. (hdr->infgflg1 & 0xF0) && (hdr->infgflg1 & 0x08) ?
  667. ", " : "",
  668. hdr->infgflg1 & 0x08 ?
  669. "0x08 - virtual CPs are thread dispatched" :
  670. "",
  671. (hdr->infgflg1 & 0xF8) && (hdr->infgflg1 & 0x04) ?
  672. ", " : "",
  673. hdr->infgflg1 & 0x04 ?
  674. "0x04 - virtual IFLs are thread dispatched" :
  675. "",
  676. (hdr->infgflg1 & 0xFC) && (hdr->infgflg1 & 0x03) ?
  677. ", " : "",
  678. hdr->infgflg1 & 0x03,
  679. hdr->infgflg1 & 0x03 ? " - ???" : "");
  680. if (!abbrev(tcp)) {
  681. if (hdr->infgflg2) /* Reserved */
  682. PRINT_FIELD_0X(", ", *hdr, infgflg2);
  683. if (hdr->infgval1) /* Reserved */
  684. PRINT_FIELD_0X(", ", *hdr, infgval1);
  685. if (hdr->infgval2) /* Reserved */
  686. PRINT_FIELD_0X(", ", *hdr, infgval2);
  687. }
  688. PRINT_FIELD_EBCDIC(", ", *hdr, infgusid);
  689. if (!abbrev(tcp) || hdr->infgscps)
  690. PRINT_FIELD_U(", ", *hdr, infgscps);
  691. if (!abbrev(tcp) || hdr->infgdcps)
  692. PRINT_FIELD_U(", ", *hdr, infgdcps);
  693. if (!abbrev(tcp)) {
  694. PRINT_FIELD_U(", ", *hdr, infgcpdt);
  695. switch (hdr->infgcpdt) {
  696. case 0:
  697. tprints_comment("General Purpose (CP)");
  698. break;
  699. default:
  700. tprints_comment("unknown");
  701. }
  702. if (!IS_ARRAY_ZERO(hdr->reserved_1__))
  703. PRINT_FIELD_HEX_ARRAY(", ", *hdr, reserved_1__);
  704. }
  705. if (!abbrev(tcp) || hdr->infgcpcc)
  706. PRINT_FIELD_WEIGHT(", ", *hdr, infgcpcc);
  707. if (!abbrev(tcp) || hdr->infgsifl)
  708. PRINT_FIELD_U(", ", *hdr, infgsifl);
  709. if (!abbrev(tcp) || hdr->infgdifl)
  710. PRINT_FIELD_U(", ", *hdr, infgdifl);
  711. if (!abbrev(tcp)) {
  712. PRINT_FIELD_U(", ", *hdr, infgifdt);
  713. switch (hdr->infgifdt) {
  714. case 0:
  715. tprints_comment("General Purpose (CP)");
  716. break;
  717. case 3:
  718. tprints_comment("Integrated Facility for Linux (IFL)");
  719. break;
  720. default:
  721. tprints_comment("unknown");
  722. }
  723. if (!IS_ARRAY_ZERO(hdr->reserved_2__))
  724. PRINT_FIELD_HEX_ARRAY(", ", *hdr, reserved_2__);
  725. }
  726. if (!abbrev(tcp) || hdr->infgifcc)
  727. PRINT_FIELD_WEIGHT(", ", *hdr, infgifcc);
  728. PRINT_FIELD_0X(", ", *hdr, infgpflg);
  729. if (!abbrev(tcp) && hdr->infgpflg)
  730. tprintf_comment("%s%s%s%s%s%s%s%s%s%s%#.0x%s",
  731. hdr->infgpflg & 0x80 ?
  732. "0x80 - CPU pool's CP virtual type has "
  733. "LIMITHARD cap" : "",
  734. (hdr->infgpflg & 0x80) && (hdr->infgpflg & 0x40) ?
  735. ", " : "",
  736. hdr->infgpflg & 0x40 ?
  737. "0x40 - CPU pool's CP virtual type has "
  738. "CAPACITY cap" : "",
  739. (hdr->infgpflg & 0xC0) && (hdr->infgpflg & 0x20) ?
  740. ", " : "",
  741. hdr->infgpflg & 0x20 ?
  742. "0x20 - CPU pool's IFL virtual type has "
  743. "LIMITHARD cap" : "",
  744. (hdr->infgpflg & 0xE0) && (hdr->infgpflg & 0x10) ?
  745. ", " : "",
  746. hdr->infgpflg & 0x10 ?
  747. "0x10 - CPU pool's IFL virtual type has "
  748. "CAPACITY cap" : "",
  749. (hdr->infgpflg & 0xF0) && (hdr->infgpflg & 0x08) ?
  750. ", " : "",
  751. hdr->infgpflg & 0x08 ?
  752. "0x08 - CPU pool uses prorated core time" : "",
  753. (hdr->infgpflg & 0xF8) && (hdr->infgpflg & 0x07) ?
  754. ", " : "",
  755. hdr->infgpflg & 0x07,
  756. hdr->infgpflg & 0x07 ? " - ???" : "");
  757. if (!abbrev(tcp)) {
  758. if (!IS_ARRAY_ZERO(hdr->reserved_3__))
  759. PRINT_FIELD_HEX_ARRAY(", ", *hdr, reserved_3__);
  760. if (!IS_BLANK(hdr->infgpnam))
  761. PRINT_FIELD_EBCDIC(", ", *hdr, infgpnam);
  762. PRINT_FIELD_WEIGHT(", ", *hdr, infgpccc);
  763. PRINT_FIELD_WEIGHT(", ", *hdr, infgpicc);
  764. PRINT_UNKNOWN_TAIL(hdr, size);
  765. } else {
  766. tprints(", ...");
  767. }
  768. tprints("}");
  769. }
  770. # define STHYI_PRINT_STRUCT(l_, name_) \
  771. do { \
  772. if (hdr->inf ##l_## off && hdr->inf ##l_## off + \
  773. hdr->inf ##l_## len <= sizeof(data)) { \
  774. tprints(", "); \
  775. print_sthyi_ ##name_(tcp, (struct sthyi_ ##name_ *) \
  776. (data + hdr->inf ##l_## off), \
  777. hdr->inf ##l_## len, &mt); \
  778. } \
  779. } while (0)
  780. # define STHYI_PRINT_HV_STRUCT(l_, n_, name_) \
  781. do { \
  782. if (hdr->inf ##l_## off ##n_ && hdr->inf ##l_## off ##n_ + \
  783. hdr->inf ##l_## len ##n_ <= sizeof(data)) { \
  784. tprints(", "); \
  785. print_sthyi_ ##name_(tcp, (struct sthyi_ ##name_ *) \
  786. (data + hdr->inf ##l_## off ##n_), \
  787. hdr->inf ##l_## len ##n_, n_, mt); \
  788. } \
  789. } while (0)
  790. static void
  791. print_sthyi_buf(struct tcb *tcp, kernel_ulong_t ptr)
  792. {
  793. char data[PAGE_SIZE];
  794. struct sthyi_hdr *hdr = (struct sthyi_hdr *) data;
  795. bool mt = false;
  796. if (umove_or_printaddr(tcp, ptr, &data))
  797. return;
  798. tprints("{");
  799. /* Header */
  800. PRINT_FIELD_0X("/* header */ {", *hdr, infhflg1);
  801. if (abbrev(tcp)) {
  802. tprints(", ...");
  803. goto sthyi_sections;
  804. }
  805. if (hdr->infhflg1)
  806. tprintf_comment("%s%s%s%s%s%s%s%s%#.0x%s",
  807. hdr->infhflg1 & 0x80 ?
  808. "0x80 - Global Performance Data unavailable" :
  809. "",
  810. (hdr->infhflg1 & 0x80) && (hdr->infhflg1 & 0x40) ?
  811. ", " : "",
  812. hdr->infhflg1 & 0x40 ?
  813. "0x40 - One or more hypervisor levels below "
  814. "this level does not support the STHYI "
  815. "instruction" : "",
  816. (hdr->infhflg1 & 0xC0) && (hdr->infhflg1 & 0x20) ?
  817. ", " : "",
  818. hdr->infhflg1 & 0x20 ?
  819. "0x20 - Virtualization stack is incomplete" :
  820. "",
  821. (hdr->infhflg1 & 0xE0) && (hdr->infhflg1 & 0x10) ?
  822. ", " : "",
  823. hdr->infhflg1 & 0x10 ?
  824. "0x10 - Execution environment is not within "
  825. "a logical partition" : "",
  826. (hdr->infhflg1 & 0xF0) && (hdr->infhflg1 & 0x0F) ?
  827. ", " : "",
  828. hdr->infhflg1 & 0x0F,
  829. hdr->infhflg1 & 0x0F ? " - ???" : "");
  830. if (hdr->infhflg2) /* Reserved */
  831. PRINT_FIELD_0X(", ", *hdr, infhflg2);
  832. if (hdr->infhval1) /* Reserved */
  833. PRINT_FIELD_0X(", ", *hdr, infhval1);
  834. if (hdr->infhval2) /* Reserved */
  835. PRINT_FIELD_0X(", ", *hdr, infhval2);
  836. if (!IS_ARRAY_ZERO(hdr->reserved_1__))
  837. PRINT_FIELD_HEX_ARRAY(", ", *hdr, reserved_1__);
  838. PRINT_FIELD_U(", ", *hdr, infhygct);
  839. PRINT_FIELD_U(", ", *hdr, infhtotl);
  840. PRINT_FIELD_U(", ", *hdr, infhdln);
  841. PRINT_FIELD_U(", ", *hdr, infmoff);
  842. PRINT_FIELD_U(", ", *hdr, infmlen);
  843. PRINT_FIELD_U(", ", *hdr, infpoff);
  844. PRINT_FIELD_U(", ", *hdr, infplen);
  845. PRINT_FIELD_U(", ", *hdr, infhoff1);
  846. PRINT_FIELD_U(", ", *hdr, infhlen1);
  847. PRINT_FIELD_U(", ", *hdr, infgoff1);
  848. PRINT_FIELD_U(", ", *hdr, infglen1);
  849. PRINT_FIELD_U(", ", *hdr, infhoff2);
  850. PRINT_FIELD_U(", ", *hdr, infhlen2);
  851. PRINT_FIELD_U(", ", *hdr, infgoff2);
  852. PRINT_FIELD_U(", ", *hdr, infglen2);
  853. PRINT_FIELD_U(", ", *hdr, infhoff3);
  854. PRINT_FIELD_U(", ", *hdr, infhlen3);
  855. PRINT_FIELD_U(", ", *hdr, infgoff3);
  856. PRINT_FIELD_U(", ", *hdr, infglen3);
  857. PRINT_UNKNOWN_TAIL(hdr, hdr->infhdln);
  858. sthyi_sections:
  859. tprints("}");
  860. STHYI_PRINT_STRUCT(m, machine);
  861. STHYI_PRINT_STRUCT(p, partition);
  862. STHYI_PRINT_HV_STRUCT(h, 1, hypervisor);
  863. STHYI_PRINT_HV_STRUCT(g, 1, guest);
  864. STHYI_PRINT_HV_STRUCT(h, 2, hypervisor);
  865. STHYI_PRINT_HV_STRUCT(g, 2, guest);
  866. STHYI_PRINT_HV_STRUCT(h, 3, hypervisor);
  867. STHYI_PRINT_HV_STRUCT(g, 3, guest);
  868. tprints("}");
  869. }
  870. /**
  871. * Wrapper for the s390 STHYI instruction that provides hypervisor information.
  872. *
  873. * See https://www.ibm.com/support/knowledgecenter/SSB27U_6.3.0/com.ibm.zvm.v630.hcpb4/hcpb4sth.htm
  874. * for the instruction documentation.
  875. *
  876. * The difference in the kernel wrapper is that it doesn't require the 4K
  877. * alignment for the resp_buffer page (as it just copies from the internal
  878. * cache).
  879. */
  880. SYS_FUNC(s390_sthyi)
  881. {
  882. /* in, function ID from s390_sthyi_function_codes */
  883. kernel_ulong_t function_code = tcp->u_arg[0];
  884. /* out, pointer to page-sized buffer */
  885. kernel_ulong_t resp_buffer_ptr = tcp->u_arg[1];
  886. /* out, pointer to u64 containing function result */
  887. kernel_ulong_t return_code_ptr = tcp->u_arg[2];
  888. /* in, should be 0, at the moment */
  889. kernel_ulong_t flags = tcp->u_arg[3];
  890. if (entering(tcp)) {
  891. printxval64(s390_sthyi_function_codes, function_code,
  892. "STHYI_FC_???");
  893. tprints(", ");
  894. } else {
  895. switch (function_code) {
  896. case STHYI_FC_CP_IFL_CAP:
  897. print_sthyi_buf(tcp, resp_buffer_ptr);
  898. break;
  899. default:
  900. printaddr(resp_buffer_ptr);
  901. }
  902. tprints(", ");
  903. printnum_int64(tcp, return_code_ptr, "%" PRIu64);
  904. tprintf(", %#" PRI_klx, flags);
  905. }
  906. return 0;
  907. }
  908. /*
  909. * Structures are written based on
  910. * https://www-304.ibm.com/support/docview.wss?uid=isg29c69415c1e82603c852576700058075a&aid=1#page=85
  911. */
  912. struct guard_storage_control_block {
  913. uint64_t reserved;
  914. /**
  915. * Guard Storage Designation
  916. * - Bits 0..J, J == 64-GSC - Guard Storage Origin (GSO)
  917. * - Bits 53..55 - Guard Load Shift (GLS)
  918. * - Bits 58..63 - Guard Storage Characteristic (GSC), this is J from
  919. * the first item, valud values are 25..56.
  920. */
  921. uint64_t gsd;
  922. uint64_t gssm; /**< Guard Storage Section Mask */
  923. uint64_t gs_epl_a; /**< Guard Storage Event Parameter List Address */
  924. };
  925. struct guard_storage_event_parameter_list {
  926. uint8_t pad1;
  927. /**
  928. * Guard Storage Event Addressing Mode
  929. * - 0x40 - Extended addressing mode (E)
  930. * - 0x80 - Basic addressing mode (B)
  931. */
  932. uint8_t gs_eam;
  933. /**
  934. * Guard Storage Event Cause indication
  935. * - 0x01 - CPU was in transaction execution mode (TX)
  936. * - 0x02 - CPU was in constrained transaction execution mode (CX)
  937. * - 0x80 - Instruction causing the event: 0 - LGG, 1 - LLGFGS
  938. */
  939. uint8_t gs_eci;
  940. /**
  941. * Guard Storage Event Access Information
  942. * - 0x01 - DAT mode
  943. * - Bits 1..2 - Address space indication
  944. * - Bits 4..7 - AR number
  945. */
  946. uint8_t gs_eai;
  947. uint32_t pad2;
  948. uint64_t gs_eha; /**< Guard Storage Event Handler Address */
  949. uint64_t gs_eia; /**< Guard Storage Event Instruction Address */
  950. uint64_t gs_eoa; /**< Guard Storage Event Operation Address */
  951. uint64_t gs_eir; /**< Guard Storage Event Intermediate Result */
  952. uint64_t gs_era; /**< Guard Storage Event Return Address */
  953. };
  954. static void
  955. guard_storage_print_gsepl(struct tcb *tcp, uint64_t addr)
  956. {
  957. struct guard_storage_event_parameter_list gsepl;
  958. /* Since it is 64-bit even on 31-bit s390... */
  959. if (sizeof(addr) > current_klongsize &&
  960. addr >= (1ULL << (current_klongsize * 8))) {
  961. tprintf("%#" PRIx64, addr);
  962. return;
  963. }
  964. if (umove_or_printaddr(tcp, addr, &gsepl))
  965. return;
  966. tprints("[{");
  967. if (!abbrev(tcp)) {
  968. if (gsepl.pad1) {
  969. PRINT_FIELD_0X("", gsepl, pad1);
  970. tprints(", ");
  971. }
  972. PRINT_FIELD_0X("", gsepl, gs_eam);
  973. tprintf_comment("extended addressing mode: %u, "
  974. "basic addressing mode: %u",
  975. !!(gsepl.gs_eam & 0x2), !!(gsepl.gs_eam & 0x1));
  976. PRINT_FIELD_0X(", ", gsepl, gs_eci);
  977. tprintf_comment("CPU in TX: %u, CPU in CX: %u, instruction: %s",
  978. !!(gsepl.gs_eci & 0x80),
  979. !!(gsepl.gs_eci & 0x40),
  980. gsepl.gs_eci & 0x01 ? "LLGFGS" : "LGG");
  981. PRINT_FIELD_0X(", ", gsepl, gs_eai);
  982. tprintf_comment("DAT: %u, address space indication: %u, "
  983. "AR number: %u",
  984. !!(gsepl.gs_eai & 0x40),
  985. (gsepl.gs_eai >> 4) & 0x3,
  986. gsepl.gs_eai & 0xF);
  987. if (gsepl.pad2)
  988. PRINT_FIELD_0X(", ", gsepl, pad2);
  989. tprints(", ");
  990. }
  991. PRINT_FIELD_X("", gsepl, gs_eha);
  992. if (!abbrev(tcp)) {
  993. PRINT_FIELD_X(", ", gsepl, gs_eia);
  994. PRINT_FIELD_X(", ", gsepl, gs_eoa);
  995. PRINT_FIELD_X(", ", gsepl, gs_eir);
  996. PRINT_FIELD_X(", ", gsepl, gs_era);
  997. } else {
  998. tprints(", ...");
  999. }
  1000. tprints("}]");
  1001. }
  1002. # define DIV_ROUND_UP(x,y) (((x) + ((y) - 1)) / (y))
  1003. static void
  1004. guard_storage_print_gscb(struct tcb *tcp, kernel_ulong_t addr)
  1005. {
  1006. struct guard_storage_control_block gscb;
  1007. if (umove_or_printaddr(tcp, addr, &gscb))
  1008. return;
  1009. tprints("{");
  1010. if (gscb.reserved) {
  1011. PRINT_FIELD_0X("", gscb, reserved);
  1012. tprints(", ");
  1013. }
  1014. PRINT_FIELD_0X("", gscb, gsd);
  1015. if (!abbrev(tcp)) {
  1016. unsigned int gsc = gscb.gsd & 0x3F;
  1017. bool gsc_valid = gsc >= 25 && gsc <= 56;
  1018. tprintf_comment("GS origin: %#*.*" PRIx64 "%s, "
  1019. "guard load shift: %" PRIu64 ", "
  1020. "GS characteristic: %u",
  1021. gsc_valid ? 2 + DIV_ROUND_UP(64 - gsc, 4) : 0,
  1022. gsc_valid ? DIV_ROUND_UP(64 - gsc, 4) : 0,
  1023. gsc_valid ? gscb.gsd >> gsc : 0,
  1024. gsc_valid ? "" : "[invalid]",
  1025. (gscb.gsd >> 8) & 0x7, gsc);
  1026. }
  1027. PRINT_FIELD_0X(", ", gscb, gssm);
  1028. tprints(", gs_epl_a=");
  1029. guard_storage_print_gsepl(tcp, gscb.gs_epl_a);
  1030. tprints("}");
  1031. }
  1032. SYS_FUNC(s390_guarded_storage)
  1033. {
  1034. int command = (int) tcp->u_arg[0];
  1035. kernel_ulong_t gs_cb = tcp->u_arg[1];
  1036. printxval(s390_guarded_storage_commands, command, "GS_???");
  1037. switch (command) {
  1038. case GS_ENABLE:
  1039. case GS_DISABLE:
  1040. case GS_CLEAR_BC_CB:
  1041. case GS_BROADCAST:
  1042. break;
  1043. case GS_SET_BC_CB:
  1044. tprints(", ");
  1045. guard_storage_print_gscb(tcp, gs_cb);
  1046. break;
  1047. default:
  1048. tprints(", ");
  1049. printaddr(gs_cb);
  1050. }
  1051. return RVAL_DECODED;
  1052. }
  1053. SYS_FUNC(s390_runtime_instr)
  1054. {
  1055. int command = (int) tcp->u_arg[0];
  1056. int signum = (int) tcp->u_arg[1];
  1057. printxval_d(s390_runtime_instr_commands, command,
  1058. "S390_RUNTIME_INSTR_???");
  1059. /*
  1060. * signum is ignored since Linux 4.4, but let's print it for start
  1061. * command anyway.
  1062. */
  1063. switch (command) {
  1064. case S390_RUNTIME_INSTR_START:
  1065. tprints(", ");
  1066. printsignal(signum);
  1067. break;
  1068. case S390_RUNTIME_INSTR_STOP:
  1069. default:
  1070. break;
  1071. }
  1072. return RVAL_DECODED;
  1073. }
  1074. SYS_FUNC(s390_pci_mmio_write)
  1075. {
  1076. kernel_ulong_t mmio_addr = tcp->u_arg[0];
  1077. kernel_ulong_t user_buf = tcp->u_arg[1];
  1078. kernel_ulong_t length = tcp->u_arg[2];
  1079. tprintf("%#" PRI_klx ", ", mmio_addr);
  1080. printstr_ex(tcp, user_buf, length, QUOTE_FORCE_HEX);
  1081. tprintf(", %" PRI_klu, length);
  1082. return RVAL_DECODED;
  1083. }
  1084. SYS_FUNC(s390_pci_mmio_read)
  1085. {
  1086. kernel_ulong_t mmio_addr = tcp->u_arg[0];
  1087. kernel_ulong_t user_buf = tcp->u_arg[1];
  1088. kernel_ulong_t length = tcp->u_arg[2];
  1089. if (entering(tcp)) {
  1090. tprintf("%#" PRI_klx ", ", mmio_addr);
  1091. } else {
  1092. if (!syserror(tcp))
  1093. printstr_ex(tcp, user_buf, length, QUOTE_FORCE_HEX);
  1094. else
  1095. printaddr(user_buf);
  1096. tprintf(", %" PRI_klu, length);
  1097. }
  1098. return 0;
  1099. }
  1100. #endif /* defined S390 || defined S390X */