1 /* SPDX-License-Identifier: MIT */ 2 /****************************************************************************** 3 * sysctl.h 4 * 5 * System management operations. For use by node control stack. 6 * 7 * Copyright (c) 2002-2006, K Fraser 8 */ 9 10 #ifndef __XEN_PUBLIC_SYSCTL_H__ 11 #define __XEN_PUBLIC_SYSCTL_H__ 12 13 #if !defined(__XEN__) && !defined(__XEN_TOOLS__) 14 #error "sysctl operations are intended for use by node control tools only" 15 #endif 16 17 #include "xen.h" 18 #include "domctl.h" 19 #include "physdev.h" 20 21 /* 22 * The interface version needs to be incremented by 1 in case the interface 23 * is modified in an incompatible way AND if the version hasn't been 24 * incremented in the current development cycle already. 25 * Pure additions (e.g. new sub-commands) or compatible interface changes 26 * (e.g. adding semantics to 0-checked input fields or data to zeroed output 27 * fields) don't require a change of the version. 28 * 29 * Last version bump: Xen 4.21 30 */ 31 #define XEN_SYSCTL_INTERFACE_VERSION 0x00000016 32 33 /* 34 * Read console content from Xen buffer ring. 35 */ 36 /* XEN_SYSCTL_readconsole */ 37 struct xen_sysctl_readconsole { 38 /* IN: Non-zero -> clear after reading. */ 39 uint8_t clear; 40 /* IN: Non-zero -> start index specified by @index field. */ 41 uint8_t incremental; 42 uint8_t pad0, pad1; 43 /* 44 * IN: Start index for consuming from ring buffer (if @incremental); 45 * OUT: End index after consuming from ring buffer. 46 */ 47 uint32_t index; 48 /* IN: Virtual address to write console data. */ 49 XEN_GUEST_HANDLE_64(char) buffer; 50 /* IN: Size of buffer; OUT: Bytes written to buffer. */ 51 uint32_t count; 52 }; 53 54 /* Get trace buffers machine base address */ 55 /* XEN_SYSCTL_tbuf_op */ 56 struct xen_sysctl_tbuf_op { 57 /* IN variables */ 58 #define XEN_SYSCTL_TBUFOP_get_info 0 59 #define XEN_SYSCTL_TBUFOP_set_cpu_mask 1 60 #define XEN_SYSCTL_TBUFOP_set_evt_mask 2 61 #define XEN_SYSCTL_TBUFOP_set_size 3 62 #define XEN_SYSCTL_TBUFOP_enable 4 63 #define XEN_SYSCTL_TBUFOP_disable 5 64 uint32_t cmd; 65 /* IN/OUT variables */ 66 struct xenctl_bitmap cpu_mask; 67 uint32_t evt_mask; 68 /* OUT variables */ 69 uint64_aligned_t buffer_mfn; 70 uint32_t size; /* Also an IN variable! */ 71 }; 72 73 /* 74 * Get physical information about the host machine 75 */ 76 /* XEN_SYSCTL_physinfo */ 77 /* The platform supports HVM guests. */ 78 #define _XEN_SYSCTL_PHYSCAP_hvm 0 79 #define XEN_SYSCTL_PHYSCAP_hvm (1u<<_XEN_SYSCTL_PHYSCAP_hvm) 80 /* The platform supports PV guests. */ 81 #define _XEN_SYSCTL_PHYSCAP_pv 1 82 #define XEN_SYSCTL_PHYSCAP_pv (1u<<_XEN_SYSCTL_PHYSCAP_pv) 83 /* The platform supports direct access to I/O devices with IOMMU. */ 84 #define _XEN_SYSCTL_PHYSCAP_directio 2 85 #define XEN_SYSCTL_PHYSCAP_directio (1u<<_XEN_SYSCTL_PHYSCAP_directio) 86 /* The platform supports Hardware Assisted Paging. */ 87 #define _XEN_SYSCTL_PHYSCAP_hap 3 88 #define XEN_SYSCTL_PHYSCAP_hap (1u<<_XEN_SYSCTL_PHYSCAP_hap) 89 /* The platform supports software paging. */ 90 #define _XEN_SYSCTL_PHYSCAP_shadow 4 91 #define XEN_SYSCTL_PHYSCAP_shadow (1u<<_XEN_SYSCTL_PHYSCAP_shadow) 92 /* The platform supports sharing of HAP page tables with the IOMMU. */ 93 #define _XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share 5 94 #define XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share \ 95 (1u << _XEN_SYSCTL_PHYSCAP_iommu_hap_pt_share) 96 #define XEN_SYSCTL_PHYSCAP_vmtrace (1u << 6) 97 /* The platform supports vPMU. */ 98 #define XEN_SYSCTL_PHYSCAP_vpmu (1u << 7) 99 100 /* Xen supports the Grant v1 and/or v2 ABIs. */ 101 #define XEN_SYSCTL_PHYSCAP_gnttab_v1 (1u << 8) 102 #define XEN_SYSCTL_PHYSCAP_gnttab_v2 (1u << 9) 103 104 /* Max XEN_SYSCTL_PHYSCAP_* constant. Used for ABI checking. */ 105 #define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_gnttab_v2 106 107 #if defined(__arm__) || defined(__aarch64__) 108 #define XEN_SYSCTL_PHYSCAP_ARM_SVE_MASK (0x1FU) 109 #endif 110 111 struct xen_sysctl_physinfo { 112 uint32_t threads_per_core; 113 uint32_t cores_per_socket; 114 uint32_t nr_cpus; /* # CPUs currently online */ 115 uint32_t max_cpu_id; /* Largest possible CPU ID on this host */ 116 uint32_t nr_nodes; /* # nodes currently online */ 117 uint32_t max_node_id; /* Largest possible node ID on this host */ 118 uint32_t cpu_khz; 119 uint32_t capabilities;/* XEN_SYSCTL_PHYSCAP_??? */ 120 uint32_t arch_capabilities;/* XEN_SYSCTL_PHYSCAP_{X86,ARM,...}_??? */ 121 uint32_t pad; 122 uint64_aligned_t total_pages; 123 uint64_aligned_t free_pages; 124 uint64_aligned_t scrub_pages; 125 uint64_aligned_t outstanding_pages; 126 uint64_aligned_t max_mfn; /* Largest possible MFN on this host */ 127 uint32_t hw_cap[8]; 128 }; 129 130 /* 131 * Get the ID of the current scheduler. 132 */ 133 /* XEN_SYSCTL_sched_id */ 134 struct xen_sysctl_sched_id { 135 /* OUT variable */ 136 uint32_t sched_id; 137 }; 138 139 /* Interface for controlling Xen software performance counters. */ 140 /* XEN_SYSCTL_perfc_op */ 141 /* Sub-operations: */ 142 #define XEN_SYSCTL_PERFCOP_reset 1 /* Reset all counters to zero. */ 143 #define XEN_SYSCTL_PERFCOP_query 2 /* Get perfctr information. */ 144 struct xen_sysctl_perfc_desc { 145 char name[80]; /* name of perf counter */ 146 uint32_t nr_vals; /* number of values for this counter */ 147 }; 148 typedef struct xen_sysctl_perfc_desc xen_sysctl_perfc_desc_t; 149 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_desc_t); 150 typedef uint32_t xen_sysctl_perfc_val_t; 151 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_val_t); 152 153 struct xen_sysctl_perfc_op { 154 /* IN variables. */ 155 uint32_t cmd; /* XEN_SYSCTL_PERFCOP_??? */ 156 /* OUT variables. */ 157 uint32_t nr_counters; /* number of counters description */ 158 uint32_t nr_vals; /* number of values */ 159 /* counter information (or NULL) */ 160 XEN_GUEST_HANDLE_64(xen_sysctl_perfc_desc_t) desc; 161 /* counter values (or NULL) */ 162 XEN_GUEST_HANDLE_64(xen_sysctl_perfc_val_t) val; 163 }; 164 165 /* XEN_SYSCTL_getdomaininfolist */ 166 struct xen_sysctl_getdomaininfolist { 167 /* IN variables. */ 168 domid_t first_domain; 169 uint32_t max_domains; 170 XEN_GUEST_HANDLE_64(xen_domctl_getdomaininfo_t) buffer; 171 /* OUT variables. */ 172 uint32_t num_domains; 173 }; 174 175 /* Inject debug keys into Xen. */ 176 /* XEN_SYSCTL_debug_keys */ 177 struct xen_sysctl_debug_keys { 178 /* IN variables. */ 179 XEN_GUEST_HANDLE_64(const_char) keys; 180 uint32_t nr_keys; 181 }; 182 183 /* Get physical CPU information. */ 184 /* XEN_SYSCTL_getcpuinfo */ 185 struct xen_sysctl_cpuinfo { 186 uint64_aligned_t idletime; 187 }; 188 typedef struct xen_sysctl_cpuinfo xen_sysctl_cpuinfo_t; 189 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpuinfo_t); 190 struct xen_sysctl_getcpuinfo { 191 /* IN variables. */ 192 uint32_t max_cpus; 193 XEN_GUEST_HANDLE_64(xen_sysctl_cpuinfo_t) info; 194 /* OUT variables. */ 195 uint32_t nr_cpus; 196 }; 197 198 /* XEN_SYSCTL_availheap */ 199 struct xen_sysctl_availheap { 200 /* IN variables. */ 201 uint32_t min_bitwidth; /* Smallest address width (zero if don't care). */ 202 uint32_t max_bitwidth; /* Largest address width (zero if don't care). */ 203 int32_t node; /* NUMA node of interest (-1 for all nodes). */ 204 /* OUT variables. */ 205 uint64_aligned_t avail_bytes;/* Bytes available in the specified region. */ 206 }; 207 208 /* XEN_SYSCTL_get_pmstat */ 209 struct pm_px_val { 210 uint64_aligned_t freq; /* Px core frequency */ 211 uint64_aligned_t residency; /* Px residency time */ 212 uint64_aligned_t count; /* Px transition count */ 213 }; 214 typedef struct pm_px_val pm_px_val_t; 215 DEFINE_XEN_GUEST_HANDLE(pm_px_val_t); 216 217 struct pm_px_stat { 218 /* 219 * IN: Number of elements in pt, number of rows/columns in trans_pt 220 * (PMSTAT_get_pxstat) 221 * OUT: total Px states (PMSTAT_get_max_px, PMSTAT_get_pxstat) 222 */ 223 uint8_t total; 224 uint8_t usable; /* OUT: usable Px states (PMSTAT_get_pxstat) */ 225 uint8_t last; /* OUT: last Px state (PMSTAT_get_pxstat) */ 226 uint8_t cur; /* OUT: current Px state (PMSTAT_get_pxstat) */ 227 /* 228 * OUT: Px transition table. This should have total * total elements. 229 * As it is a 2-D array, this will not be copied if input total is 230 * less than output total. (PMSTAT_get_pxstat) 231 */ 232 XEN_GUEST_HANDLE_64(uint64) trans_pt; 233 /* OUT: This should have total elements (PMSTAT_get_pxstat) */ 234 XEN_GUEST_HANDLE_64(pm_px_val_t) pt; 235 }; 236 237 struct pm_cx_stat { 238 /* 239 * IN: Number of elements in triggers, residencies (PMSTAT_get_cxstat) 240 * OUT: entry nr in triggers & residencies, including C0 241 * (PMSTAT_get_cxstat, PMSTAT_get_max_cx) 242 */ 243 uint32_t nr; 244 uint32_t last; /* OUT: last Cx state (PMSTAT_get_cxstat) */ 245 /* OUT: idle time from boot (PMSTAT_get_cxstat)*/ 246 uint64_aligned_t idle_time; 247 /* OUT: Cx trigger counts, nr elements (PMSTAT_get_cxstat) */ 248 XEN_GUEST_HANDLE_64(uint64) triggers; 249 /* OUT: Cx residencies, nr elements (PMSTAT_get_cxstat) */ 250 XEN_GUEST_HANDLE_64(uint64) residencies; 251 /* 252 * IN: entry nr in pc[] (PMSTAT_get_cxstat) 253 * OUT: Required size of pc[] for all known to Xen entries to be written 254 * (PMSTAT_get_cxstat) 255 */ 256 uint32_t nr_pc; 257 /* 258 * IN: entry nr in cc[] (PMSTAT_get_cxstat) 259 * OUT: Required size of cc[] for all known to Xen entries to be written 260 * (PMSTAT_get_cxstat) 261 */ 262 uint32_t nr_cc; 263 /* 264 * OUT: (PMSTAT_get_cxstat) 265 * These two arrays may (and generally will) have unused slots; slots not 266 * having a corresponding hardware register will not be written by the 267 * hypervisor. It is therefore up to the caller to put a suitable sentinel 268 * into all slots before invoking the function. 269 * Indexing is 1-biased (PC1/CC1 being at index 0). 270 */ 271 XEN_GUEST_HANDLE_64(uint64) pc; 272 XEN_GUEST_HANDLE_64(uint64) cc; 273 }; 274 275 struct xen_sysctl_get_pmstat { 276 #define PMSTAT_CATEGORY_MASK 0xf0 277 #define PMSTAT_PX 0x10 278 #define PMSTAT_CX 0x20 279 #define PMSTAT_get_max_px (PMSTAT_PX | 0x1) 280 #define PMSTAT_get_pxstat (PMSTAT_PX | 0x2) 281 #define PMSTAT_reset_pxstat (PMSTAT_PX | 0x3) 282 #define PMSTAT_get_max_cx (PMSTAT_CX | 0x1) 283 #define PMSTAT_get_cxstat (PMSTAT_CX | 0x2) 284 #define PMSTAT_reset_cxstat (PMSTAT_CX | 0x3) 285 uint32_t type; 286 uint32_t cpuid; 287 union { 288 struct pm_px_stat getpx; 289 struct pm_cx_stat getcx; 290 /* other struct for tx, etc */ 291 } u; 292 }; 293 294 /* XEN_SYSCTL_cpu_hotplug */ 295 struct xen_sysctl_cpu_hotplug { 296 /* IN variables */ 297 uint32_t cpu; /* Physical cpu. */ 298 299 /* Single CPU enable/disable. */ 300 #define XEN_SYSCTL_CPU_HOTPLUG_ONLINE 0 301 #define XEN_SYSCTL_CPU_HOTPLUG_OFFLINE 1 302 303 /* 304 * SMT enable/disable. 305 * 306 * These two ops loop over all present CPUs, and either online or offline 307 * every non-primary sibling thread (those with a thread id which is not 308 * 0). This behaviour is chosen to simplify the implementation. 309 * 310 * They are intended as a shorthand for identifying and feeding the cpu 311 * numbers individually to HOTPLUG_{ON,OFF}LINE. 312 * 313 * These are not expected to be used in conjunction with debugging options 314 * such as `maxcpus=` or when other manual configuration of offline cpus 315 * is in use. 316 */ 317 #define XEN_SYSCTL_CPU_HOTPLUG_SMT_ENABLE 2 318 #define XEN_SYSCTL_CPU_HOTPLUG_SMT_DISABLE 3 319 uint32_t op; /* hotplug opcode */ 320 }; 321 322 /* 323 * Get/set xen power management, include 324 * 1. cpufreq governors and related parameters 325 */ 326 /* XEN_SYSCTL_pm_op */ 327 struct xen_userspace { 328 uint32_t scaling_setspeed; 329 }; 330 331 struct xen_ondemand { 332 uint32_t sampling_rate_max; 333 uint32_t sampling_rate_min; 334 335 uint32_t sampling_rate; 336 uint32_t up_threshold; 337 }; 338 339 struct xen_cppc_para { 340 /* OUT */ 341 /* activity_window supported if set */ 342 #define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW (1 << 0) 343 uint32_t features; /* bit flags for features */ 344 /* 345 * See Intel SDM: HWP Performance Range and Dynamic Capabilities 346 * 347 * These four are 0-255 hardware-provided values. They're "continuous, 348 * abstract unit-less, performance" values. Smaller numbers are slower 349 * and larger ones are faster. 350 */ 351 uint32_t lowest; 352 uint32_t lowest_nonlinear; /* HWP: most_efficient */ 353 uint32_t nominal; /* HWP: guaranteed */ 354 uint32_t highest; 355 /* 356 * See Intel SDM: IA32_HWP_REQUEST MSR (Address: 774H Logical Processor 357 * Scope) 358 * 359 * These are all hints, and the processor may deviate outside of them. 360 * Values below are 0-255. 361 * 362 * minimum and maximum can be set to the above hardware values to constrain 363 * operation. The full range 0-255 is accepted and will be clipped by 364 * hardware. 365 */ 366 uint32_t minimum; 367 uint32_t maximum; 368 /* 369 * An explicit performance hint, disabling hardware selection. 370 * 0 lets the hardware decide. 371 */ 372 uint32_t desired; 373 /* 374 * Hint to hardware for energy/performance preference. 375 * 0: Performance 376 * 128: Balance (Default) 377 * 255: Powersaving 378 */ 379 uint32_t energy_perf; 380 /* 381 * Activity Window is a moving history window for the processor's operation 382 * calculations, controlling responsiveness. Measured in microseconds 383 * encoded as: 384 * 385 * bits 6:0 - 7bit mantissa 386 * bits 9:7 - 3bit base-10 exponent 387 * btis 15:10 - Unused - must be 0 388 */ 389 #define XEN_CPPC_ACT_WINDOW_MANTISSA_MASK 0x07f 390 #define XEN_CPPC_ACT_WINDOW_EXPONENT_MASK 0x380 391 uint32_t activity_window; 392 }; 393 394 /* 395 * Set CPPC values. 396 * 397 * Configure the parameters for CPPC. Set bits in set_params control which 398 * values are applied. If a bit is not set in set_params, the field must be 399 * zero. 400 * 401 * For HWP specifically, values must be limited to 0-255 or within 402 * XEN_SYSCTL_CPPC_ACT_WINDOW_MASK for activity window. Set bits outside the 403 * range will be returned as -EINVAL. 404 * 405 * Activity Window may not be supported by the hardware. In that case, the 406 * returned set_params will clear XEN_SYSCTL_CPPC_SET_ACT_WINDOW to indicate 407 * that it was not applied - though the rest of the values will be applied. 408 * 409 * There are a set of presets along with individual fields. Presets are 410 * applied first, and then individual fields. This allows customizing 411 * a preset without having to specify every value. 412 * 413 * The preset options values are as follows: 414 * 415 * preset | minimum | maxium | energy_perf 416 * ------------+---------+---------+---------------- 417 * powersave | lowest | lowest | powersave (255) 418 * ------------+---------+---------+---------------- 419 * balance | lowest | highest | balance (128) 420 * ------------+---------+---------+---------------- 421 * performance | highest | highest | performance (0) 422 * 423 * desired and activity_window are set to 0, hardware selected. 424 */ 425 struct xen_set_cppc_para { 426 #define XEN_SYSCTL_CPPC_SET_MINIMUM (1U << 0) 427 #define XEN_SYSCTL_CPPC_SET_MAXIMUM (1U << 1) 428 #define XEN_SYSCTL_CPPC_SET_DESIRED (1U << 2) 429 #define XEN_SYSCTL_CPPC_SET_ENERGY_PERF (1U << 3) 430 #define XEN_SYSCTL_CPPC_SET_ACT_WINDOW (1U << 4) 431 #define XEN_SYSCTL_CPPC_SET_PRESET_MASK 0xf0000000U 432 #define XEN_SYSCTL_CPPC_SET_PRESET_NONE 0x00000000U 433 #define XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND 0x10000000U 434 #define XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE 0x20000000U 435 #define XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE 0x30000000U 436 #define XEN_SYSCTL_CPPC_SET_PARAM_MASK \ 437 (XEN_SYSCTL_CPPC_SET_PRESET_MASK | \ 438 XEN_SYSCTL_CPPC_SET_MINIMUM | \ 439 XEN_SYSCTL_CPPC_SET_MAXIMUM | \ 440 XEN_SYSCTL_CPPC_SET_DESIRED | \ 441 XEN_SYSCTL_CPPC_SET_ENERGY_PERF | \ 442 XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) 443 /* IN/OUT */ 444 uint32_t set_params; /* bitflags for valid values */ 445 /* See comments in struct xen_cppc_para. */ 446 /* IN */ 447 uint32_t minimum; 448 uint32_t maximum; 449 uint32_t desired; 450 uint32_t energy_perf; 451 #define XEN_SYSCTL_CPPC_ACT_WINDOW_MASK (XEN_CPPC_ACT_WINDOW_MANTISSA_MASK | \ 452 XEN_CPPC_ACT_WINDOW_EXPONENT_MASK) 453 uint32_t activity_window; 454 }; 455 456 #define XEN_HWP_DRIVER_NAME "hwp" 457 458 /* 459 * cpufreq para name of this structure named 460 * same as sysfs file name of native linux 461 */ 462 #define CPUFREQ_NAME_LEN 16 463 struct xen_get_cpufreq_para { 464 /* IN/OUT variable */ 465 uint32_t cpu_num; 466 uint32_t freq_num; 467 uint32_t gov_num; 468 469 /* for all governors */ 470 /* OUT variable */ 471 XEN_GUEST_HANDLE_64(uint32) affected_cpus; 472 XEN_GUEST_HANDLE_64(uint32) scaling_available_frequencies; 473 XEN_GUEST_HANDLE_64(char) scaling_available_governors; 474 char scaling_driver[CPUFREQ_NAME_LEN]; 475 476 uint32_t cpuinfo_cur_freq; 477 uint32_t cpuinfo_max_freq; 478 uint32_t cpuinfo_min_freq; 479 union { 480 struct { 481 uint32_t scaling_cur_freq; 482 483 char scaling_governor[CPUFREQ_NAME_LEN]; 484 uint32_t scaling_max_freq; 485 uint32_t scaling_min_freq; 486 487 /* for specific governor */ 488 union { 489 struct xen_userspace userspace; 490 struct xen_ondemand ondemand; 491 } u; 492 } s; 493 struct xen_cppc_para cppc_para; 494 } u; 495 496 int32_t turbo_enabled; 497 }; 498 499 struct xen_set_cpufreq_gov { 500 char scaling_governor[CPUFREQ_NAME_LEN]; 501 }; 502 503 struct xen_set_cpufreq_para { 504 #define SCALING_MAX_FREQ 1 505 #define SCALING_MIN_FREQ 2 506 #define SCALING_SETSPEED 3 507 #define SAMPLING_RATE 4 508 #define UP_THRESHOLD 5 509 510 uint32_t ctrl_type; 511 uint32_t ctrl_value; 512 }; 513 514 struct xen_sysctl_pm_op { 515 #define PM_PARA_CATEGORY_MASK 0xf0 516 #define CPUFREQ_PARA 0x10 517 518 /* cpufreq command type */ 519 #define GET_CPUFREQ_PARA (CPUFREQ_PARA | 0x01) 520 #define SET_CPUFREQ_GOV (CPUFREQ_PARA | 0x02) 521 #define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03) 522 #define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04) 523 #define SET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x05) 524 525 /* set/reset scheduler power saving option */ 526 #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21 527 528 /* 529 * cpuidle max C-state and max C-sub-state access command: 530 * Set cpuid to 0 for max C-state. 531 * Set cpuid to 1 for max C-sub-state. 532 */ 533 #define XEN_SYSCTL_pm_op_get_max_cstate 0x22 534 #define XEN_SYSCTL_pm_op_set_max_cstate 0x23 535 536 /* set scheduler migration cost value */ 537 #define XEN_SYSCTL_pm_op_set_vcpu_migration_delay 0x24 538 #define XEN_SYSCTL_pm_op_get_vcpu_migration_delay 0x25 539 540 /* enable/disable turbo mode when in dbs governor */ 541 #define XEN_SYSCTL_pm_op_enable_turbo 0x26 542 #define XEN_SYSCTL_pm_op_disable_turbo 0x27 543 544 uint32_t cmd; 545 uint32_t cpuid; 546 union { 547 struct xen_get_cpufreq_para get_para; 548 struct xen_set_cpufreq_gov set_gov; 549 struct xen_set_cpufreq_para set_para; 550 struct xen_set_cppc_para set_cppc; 551 uint64_aligned_t get_avgfreq; 552 uint32_t set_sched_opt_smt; 553 #define XEN_SYSCTL_CX_UNLIMITED 0xffffffffU 554 uint32_t get_max_cstate; 555 uint32_t set_max_cstate; 556 } u; 557 }; 558 559 /* XEN_SYSCTL_page_offline_op */ 560 struct xen_sysctl_page_offline_op { 561 /* IN: range of page to be offlined */ 562 #define sysctl_page_offline 1 563 #define sysctl_page_online 2 564 #define sysctl_query_page_offline 3 565 uint32_t cmd; 566 uint32_t start; 567 uint32_t end; 568 /* OUT: result of page offline request */ 569 /* 570 * bit 0~15: result flags 571 * bit 16~31: owner 572 */ 573 XEN_GUEST_HANDLE(uint32) status; 574 }; 575 576 #define PG_OFFLINE_STATUS_MASK (0xFFUL) 577 578 /* The result is invalid, i.e. HV does not handle it */ 579 #define PG_OFFLINE_INVALID (0x1UL << 0) 580 581 #define PG_OFFLINE_OFFLINED (0x1UL << 1) 582 #define PG_OFFLINE_PENDING (0x1UL << 2) 583 #define PG_OFFLINE_FAILED (0x1UL << 3) 584 #define PG_OFFLINE_AGAIN (0x1UL << 4) 585 586 #define PG_ONLINE_FAILED PG_OFFLINE_FAILED 587 #define PG_ONLINE_ONLINED PG_OFFLINE_OFFLINED 588 589 #define PG_OFFLINE_STATUS_OFFLINED (0x1UL << 1) 590 #define PG_OFFLINE_STATUS_ONLINE (0x1UL << 2) 591 #define PG_OFFLINE_STATUS_OFFLINE_PENDING (0x1UL << 3) 592 #define PG_OFFLINE_STATUS_BROKEN (0x1UL << 4) 593 594 #define PG_OFFLINE_MISC_MASK (0xFFUL << 4) 595 596 /* valid when PG_OFFLINE_FAILED or PG_OFFLINE_PENDING */ 597 #define PG_OFFLINE_XENPAGE (0x1UL << 8) 598 #define PG_OFFLINE_DOM0PAGE (0x1UL << 9) 599 #define PG_OFFLINE_ANONYMOUS (0x1UL << 10) 600 #define PG_OFFLINE_NOT_CONV_RAM (0x1UL << 11) 601 #define PG_OFFLINE_OWNED (0x1UL << 12) 602 603 #define PG_OFFLINE_BROKEN (0x1UL << 13) 604 #define PG_ONLINE_BROKEN PG_OFFLINE_BROKEN 605 606 #define PG_OFFLINE_OWNER_SHIFT 16 607 608 /* XEN_SYSCTL_lockprof_op */ 609 /* Sub-operations: */ 610 #define XEN_SYSCTL_LOCKPROF_reset 1 /* Reset all profile data to zero. */ 611 #define XEN_SYSCTL_LOCKPROF_query 2 /* Get lock profile information. */ 612 /* Record-type: */ 613 #define LOCKPROF_TYPE_GLOBAL 0 /* global lock, idx meaningless */ 614 #define LOCKPROF_TYPE_PERDOM 1 /* per-domain lock, idx is domid */ 615 #define LOCKPROF_TYPE_N 2 /* number of types */ 616 struct xen_sysctl_lockprof_data { 617 char name[40]; /* lock name (may include up to 2 %d specifiers) */ 618 int32_t type; /* LOCKPROF_TYPE_??? */ 619 int32_t idx; /* index (e.g. domain id) */ 620 uint64_aligned_t lock_cnt; /* # of locking succeeded */ 621 uint64_aligned_t block_cnt; /* # of wait for lock */ 622 uint64_aligned_t lock_time; /* nsecs lock held */ 623 uint64_aligned_t block_time; /* nsecs waited for lock */ 624 }; 625 typedef struct xen_sysctl_lockprof_data xen_sysctl_lockprof_data_t; 626 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_lockprof_data_t); 627 struct xen_sysctl_lockprof_op { 628 /* IN variables. */ 629 uint32_t cmd; /* XEN_SYSCTL_LOCKPROF_??? */ 630 uint32_t max_elem; /* size of output buffer */ 631 /* OUT variables (query only). */ 632 uint32_t nr_elem; /* number of elements available */ 633 uint64_aligned_t time; /* nsecs of profile measurement */ 634 /* profile information (or NULL) */ 635 XEN_GUEST_HANDLE_64(xen_sysctl_lockprof_data_t) data; 636 }; 637 638 /* XEN_SYSCTL_cputopoinfo */ 639 #define XEN_INVALID_CORE_ID (~0U) 640 #define XEN_INVALID_SOCKET_ID (~0U) 641 #define XEN_INVALID_NODE_ID (~0U) 642 643 struct xen_sysctl_cputopo { 644 uint32_t core; 645 uint32_t socket; 646 uint32_t node; 647 }; 648 typedef struct xen_sysctl_cputopo xen_sysctl_cputopo_t; 649 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cputopo_t); 650 651 /* 652 * IN: 653 * - a NULL 'cputopo' handle is a request for maximun 'num_cpus'. 654 * - otherwise it's the number of entries in 'cputopo' 655 * 656 * OUT: 657 * - If 'num_cpus' is less than the number Xen wants to write but the handle 658 * handle is not a NULL one, partial data gets returned and 'num_cpus' gets 659 * updated to reflect the intended number. 660 * - Otherwise, 'num_cpus' shall indicate the number of entries written, which 661 * may be less than the input value. 662 */ 663 struct xen_sysctl_cputopoinfo { 664 uint32_t num_cpus; 665 XEN_GUEST_HANDLE_64(xen_sysctl_cputopo_t) cputopo; 666 }; 667 668 /* XEN_SYSCTL_numainfo */ 669 #define XEN_INVALID_MEM_SZ (~0U) 670 #define XEN_INVALID_NODE_DIST (~0U) 671 672 struct xen_sysctl_meminfo { 673 uint64_t memsize; 674 uint64_t memfree; 675 }; 676 typedef struct xen_sysctl_meminfo xen_sysctl_meminfo_t; 677 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_meminfo_t); 678 679 /* 680 * IN: 681 * - Both 'meminfo' and 'distance' handles being null is a request 682 * for maximum value of 'num_nodes'. 683 * - Otherwise it's the number of entries in 'meminfo' and square root 684 * of number of entries in 'distance' (when corresponding handle is 685 * non-null) 686 * 687 * OUT: 688 * - If 'num_nodes' is less than the number Xen wants to write but either 689 * handle is not a NULL one, partial data gets returned and 'num_nodes' 690 * gets updated to reflect the intended number. 691 * - Otherwise, 'num_nodes' shall indicate the number of entries written, which 692 * may be less than the input value. 693 */ 694 695 struct xen_sysctl_numainfo { 696 uint32_t num_nodes; 697 698 XEN_GUEST_HANDLE_64(xen_sysctl_meminfo_t) meminfo; 699 700 /* 701 * Distance between nodes 'i' and 'j' is stored in index 'i*N + j', 702 * where N is the number of nodes that will be returned in 'num_nodes' 703 * (i.e. not 'num_nodes' provided by the caller) 704 */ 705 XEN_GUEST_HANDLE_64(uint32) distance; 706 }; 707 708 /* XEN_SYSCTL_cpupool_op */ 709 #define XEN_SYSCTL_CPUPOOL_OP_CREATE 1 /* C */ 710 #define XEN_SYSCTL_CPUPOOL_OP_DESTROY 2 /* D */ 711 #define XEN_SYSCTL_CPUPOOL_OP_INFO 3 /* I */ 712 #define XEN_SYSCTL_CPUPOOL_OP_ADDCPU 4 /* A */ 713 #define XEN_SYSCTL_CPUPOOL_OP_RMCPU 5 /* R */ 714 #define XEN_SYSCTL_CPUPOOL_OP_MOVEDOMAIN 6 /* M */ 715 #define XEN_SYSCTL_CPUPOOL_OP_FREEINFO 7 /* F */ 716 #define XEN_SYSCTL_CPUPOOL_PAR_ANY 0xFFFFFFFFU 717 struct xen_sysctl_cpupool_op { 718 uint32_t op; /* IN */ 719 uint32_t cpupool_id; /* IN: CDIARM OUT: CI */ 720 uint32_t sched_id; /* IN: C OUT: I */ 721 uint32_t domid; /* IN: M */ 722 uint32_t cpu; /* IN: AR */ 723 uint32_t n_dom; /* OUT: I */ 724 struct xenctl_bitmap cpumap; /* OUT: IF */ 725 }; 726 727 /* 728 * Error return values of cpupool operations: 729 * 730 * -EADDRINUSE: 731 * XEN_SYSCTL_CPUPOOL_OP_RMCPU: A vcpu is temporarily pinned to the cpu 732 * which is to be removed from a cpupool. 733 * -EADDRNOTAVAIL: 734 * XEN_SYSCTL_CPUPOOL_OP_ADDCPU, XEN_SYSCTL_CPUPOOL_OP_RMCPU: A previous 735 * request to remove a cpu from a cpupool was terminated with -EAGAIN 736 * and has not been retried using the same parameters. 737 * -EAGAIN: 738 * XEN_SYSCTL_CPUPOOL_OP_RMCPU: The cpu can't be removed from the cpupool 739 * as it is active in the hypervisor. A retry will succeed soon. 740 * -EBUSY: 741 * XEN_SYSCTL_CPUPOOL_OP_DESTROY, XEN_SYSCTL_CPUPOOL_OP_RMCPU: A cpupool 742 * can't be destroyed or the last cpu can't be removed as there is still 743 * a running domain in that cpupool. 744 * -EEXIST: 745 * XEN_SYSCTL_CPUPOOL_OP_CREATE: A cpupool_id was specified and is already 746 * existing. 747 * -EINVAL: 748 * XEN_SYSCTL_CPUPOOL_OP_ADDCPU, XEN_SYSCTL_CPUPOOL_OP_RMCPU: An illegal 749 * cpu was specified (cpu does not exist). 750 * XEN_SYSCTL_CPUPOOL_OP_MOVEDOMAIN: An illegal domain was specified 751 * (domain id illegal or not suitable for operation). 752 * -ENODEV: 753 * XEN_SYSCTL_CPUPOOL_OP_ADDCPU, XEN_SYSCTL_CPUPOOL_OP_RMCPU: The specified 754 * cpu is either not free (add) or not member of the specified cpupool 755 * (remove). 756 * -ENOENT: 757 * all: The cpupool with the specified cpupool_id doesn't exist. 758 * 759 * Some common error return values like -ENOMEM and -EFAULT are possible for 760 * all the operations. 761 */ 762 763 #define ARINC653_MAX_DOMAINS_PER_SCHEDULE 64 764 /* 765 * This structure is used to pass a new ARINC653 schedule from a 766 * privileged domain (ie dom0) to Xen. 767 */ 768 struct xen_sysctl_arinc653_schedule { 769 /* major_frame holds the time for the new schedule's major frame 770 * in nanoseconds. */ 771 uint64_aligned_t major_frame; 772 /* num_sched_entries holds how many of the entries in the 773 * sched_entries[] array are valid. */ 774 uint8_t num_sched_entries; 775 /* The sched_entries array holds the actual schedule entries. */ 776 struct { 777 /* dom_handle must match a domain's UUID */ 778 xen_domain_handle_t dom_handle; 779 /* If a domain has multiple VCPUs, vcpu_id specifies which one 780 * this schedule entry applies to. It should be set to 0 if 781 * there is only one VCPU for the domain. */ 782 uint32_t vcpu_id; 783 /* runtime specifies the amount of time that should be allocated 784 * to this VCPU per major frame. It is specified in nanoseconds */ 785 uint64_aligned_t runtime; 786 } sched_entries[ARINC653_MAX_DOMAINS_PER_SCHEDULE]; 787 }; 788 typedef struct xen_sysctl_arinc653_schedule xen_sysctl_arinc653_schedule_t; 789 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_arinc653_schedule_t); 790 791 /* 792 * Valid range for context switch rate limit (in microseconds). 793 * Applicable to Credit and Credit2 schedulers. 794 */ 795 #define XEN_SYSCTL_SCHED_RATELIMIT_MAX 500000 796 #define XEN_SYSCTL_SCHED_RATELIMIT_MIN 100 797 798 struct xen_sysctl_credit_schedule { 799 /* Length of timeslice in milliseconds */ 800 #define XEN_SYSCTL_CSCHED_TSLICE_MAX 1000 801 #define XEN_SYSCTL_CSCHED_TSLICE_MIN 1 802 uint32_t tslice_ms; 803 uint32_t ratelimit_us; 804 /* 805 * How long we consider a vCPU to be cache-hot on the 806 * CPU where it has run (max 100ms, in microseconds) 807 */ 808 #define XEN_SYSCTL_CSCHED_MGR_DLY_MAX_US (100 * 1000) 809 uint32_t vcpu_migr_delay_us; 810 }; 811 812 struct xen_sysctl_credit2_schedule { 813 uint32_t ratelimit_us; 814 }; 815 816 /* XEN_SYSCTL_scheduler_op */ 817 /* Set or get info? */ 818 #define XEN_SYSCTL_SCHEDOP_putinfo 0 819 #define XEN_SYSCTL_SCHEDOP_getinfo 1 820 struct xen_sysctl_scheduler_op { 821 uint32_t cpupool_id; /* Cpupool whose scheduler is to be targetted. */ 822 uint32_t sched_id; /* XEN_SCHEDULER_* (domctl.h) */ 823 uint32_t cmd; /* XEN_SYSCTL_SCHEDOP_* */ 824 union { 825 struct xen_sysctl_sched_arinc653 { 826 XEN_GUEST_HANDLE_64(xen_sysctl_arinc653_schedule_t) schedule; 827 } sched_arinc653; 828 struct xen_sysctl_credit_schedule sched_credit; 829 struct xen_sysctl_credit2_schedule sched_credit2; 830 } u; 831 }; 832 833 /* 834 * Output format of gcov data: 835 * 836 * XEN_GCOV_FORMAT_MAGIC XEN_GCOV_RECORD ... XEN_GCOV_RECORD 837 * 838 * That is, one magic number followed by 0 or more record. 839 * 840 * The magic number is stored as an uint32_t field. 841 * 842 * The record is packed and variable in length. It has the form: 843 * 844 * filename: a NULL terminated path name extracted from gcov, used to 845 * create the name of gcda file. 846 * size: a uint32_t field indicating the size of the payload, the 847 * unit is byte. 848 * payload: the actual payload, length is `size' bytes. 849 * 850 * Userspace tool will split the record to different files. 851 */ 852 853 #define XEN_GCOV_FORMAT_MAGIC 0x58434f56 /* XCOV */ 854 855 /* 856 * Ouput format of LLVM coverage data is just a raw stream, as would be 857 * written by the compiler_rt run time library into a .profraw file. There 858 * are no special Xen tags or delimiters because none are needed. 859 */ 860 861 #define XEN_SYSCTL_COVERAGE_get_size 0 /* Get total size of output data */ 862 #define XEN_SYSCTL_COVERAGE_read 1 /* Read output data */ 863 #define XEN_SYSCTL_COVERAGE_reset 2 /* Reset all counters */ 864 865 struct xen_sysctl_coverage_op { 866 uint32_t cmd; 867 uint32_t size; /* IN/OUT: size of the buffer */ 868 XEN_GUEST_HANDLE_64(char) buffer; /* OUT */ 869 }; 870 871 #define XEN_SYSCTL_PSR_CMT_get_total_rmid 0 872 #define XEN_SYSCTL_PSR_CMT_get_l3_upscaling_factor 1 873 /* The L3 cache size is returned in KB unit */ 874 #define XEN_SYSCTL_PSR_CMT_get_l3_cache_size 2 875 #define XEN_SYSCTL_PSR_CMT_enabled 3 876 #define XEN_SYSCTL_PSR_CMT_get_l3_event_mask 4 877 struct xen_sysctl_psr_cmt_op { 878 uint32_t cmd; /* IN: XEN_SYSCTL_PSR_CMT_* */ 879 uint32_t flags; /* padding variable, may be extended for future use */ 880 union { 881 uint64_t data; /* OUT */ 882 struct { 883 uint32_t cpu; /* IN */ 884 uint32_t rsvd; 885 } l3_cache; 886 } u; 887 }; 888 889 /* XEN_SYSCTL_pcitopoinfo */ 890 #define XEN_INVALID_DEV (XEN_INVALID_NODE_ID - 1) 891 struct xen_sysctl_pcitopoinfo { 892 /* 893 * IN: Number of elements in 'devs' and 'nodes' arrays. 894 * OUT: Number of processed elements of those arrays. 895 */ 896 uint32_t num_devs; 897 898 /* IN: list of devices for which node IDs are requested. */ 899 XEN_GUEST_HANDLE_64(physdev_pci_device_t) devs; 900 901 /* 902 * OUT: node identifier for each device. 903 * If information for a particular device is not available then 904 * corresponding entry will be set to XEN_INVALID_NODE_ID. If 905 * device is not known to the hypervisor then XEN_INVALID_DEV 906 * will be provided. 907 */ 908 XEN_GUEST_HANDLE_64(uint32) nodes; 909 }; 910 911 #define XEN_SYSCTL_PSR_get_l3_info 0 912 #define XEN_SYSCTL_PSR_get_l2_info 1 913 #define XEN_SYSCTL_PSR_get_mba_info 2 914 struct xen_sysctl_psr_alloc { 915 uint32_t cmd; /* IN: XEN_SYSCTL_PSR_* */ 916 uint32_t target; /* IN */ 917 union { 918 struct { 919 uint32_t cbm_len; /* OUT: CBM length */ 920 uint32_t cos_max; /* OUT: Maximum COS */ 921 #define XEN_SYSCTL_PSR_CAT_L3_CDP (1u << 0) 922 uint32_t flags; /* OUT: CAT flags */ 923 } cat_info; 924 925 struct { 926 uint32_t thrtl_max; /* OUT: Maximum throttle */ 927 uint32_t cos_max; /* OUT: Maximum COS */ 928 #define XEN_SYSCTL_PSR_MBA_LINEAR (1u << 0) 929 uint32_t flags; /* OUT: MBA flags */ 930 } mba_info; 931 } u; 932 }; 933 934 /* 935 * XEN_SYSCTL_get_cpu_levelling_caps (x86 specific) 936 * 937 * Return hardware capabilities concerning masking or faulting of the cpuid 938 * instruction for PV guests. 939 */ 940 struct xen_sysctl_cpu_levelling_caps { 941 #define XEN_SYSCTL_CPU_LEVELCAP_faulting (1UL << 0) /* CPUID faulting */ 942 #define XEN_SYSCTL_CPU_LEVELCAP_ecx (1UL << 1) /* 0x00000001.ecx */ 943 #define XEN_SYSCTL_CPU_LEVELCAP_edx (1UL << 2) /* 0x00000001.edx */ 944 #define XEN_SYSCTL_CPU_LEVELCAP_extd_ecx (1UL << 3) /* 0x80000001.ecx */ 945 #define XEN_SYSCTL_CPU_LEVELCAP_extd_edx (1UL << 4) /* 0x80000001.edx */ 946 #define XEN_SYSCTL_CPU_LEVELCAP_xsave_eax (1UL << 5) /* 0x0000000D:1.eax */ 947 #define XEN_SYSCTL_CPU_LEVELCAP_thermal_ecx (1UL << 6) /* 0x00000006.ecx */ 948 #define XEN_SYSCTL_CPU_LEVELCAP_l7s0_eax (1UL << 7) /* 0x00000007:0.eax */ 949 #define XEN_SYSCTL_CPU_LEVELCAP_l7s0_ebx (1UL << 8) /* 0x00000007:0.ebx */ 950 uint32_t caps; 951 }; 952 953 /* 954 * XEN_SYSCTL_get_cpu_featureset (x86 specific) 955 * 956 * Return information about featuresets available on this host. 957 * - Raw: The real cpuid values. 958 * - Host: The values Xen is using, (after command line overrides, etc). 959 * - PV: Maximum set of features which can be given to a PV guest. 960 * - HVM: Maximum set of features which can be given to a HVM guest. 961 * May fail with -EOPNOTSUPP if querying for PV or HVM data when support is 962 * compiled out of Xen. 963 */ 964 struct xen_sysctl_cpu_featureset { 965 #define XEN_SYSCTL_cpu_featureset_raw 0 966 #define XEN_SYSCTL_cpu_featureset_host 1 967 #define XEN_SYSCTL_cpu_featureset_pv 2 968 #define XEN_SYSCTL_cpu_featureset_hvm 3 969 #define XEN_SYSCTL_cpu_featureset_pv_max 4 970 #define XEN_SYSCTL_cpu_featureset_hvm_max 5 971 uint32_t index; /* IN: Which featureset to query? */ 972 uint32_t nr_features; /* IN/OUT: Number of entries in/written to 973 * 'features', or the maximum number of features if 974 * the guest handle is NULL. NB. All featuresets 975 * come from the same numberspace, so have the same 976 * maximum length. */ 977 XEN_GUEST_HANDLE_64(uint32) features; /* OUT: */ 978 }; 979 980 /* 981 * XEN_SYSCTL_LIVEPATCH_op 982 * 983 * Refer to the docs/unstable/misc/livepatch.markdown 984 * for the design details of this hypercall. 985 * 986 * There are four sub-ops: 987 * XEN_SYSCTL_LIVEPATCH_UPLOAD (0) 988 * XEN_SYSCTL_LIVEPATCH_GET (1) 989 * XEN_SYSCTL_LIVEPATCH_LIST (2) 990 * XEN_SYSCTL_LIVEPATCH_ACTION (3) 991 * 992 * The normal sequence of sub-ops is to: 993 * 1) XEN_SYSCTL_LIVEPATCH_UPLOAD to upload the payload. If errors STOP. 994 * 2) XEN_SYSCTL_LIVEPATCH_GET to check the `->rc`. If -XEN_EAGAIN spin. 995 * If zero go to next step. 996 * 3) XEN_SYSCTL_LIVEPATCH_ACTION with LIVEPATCH_ACTION_APPLY to apply the patch. 997 * 4) XEN_SYSCTL_LIVEPATCH_GET to check the `->rc`. If in -XEN_EAGAIN spin. 998 * If zero exit with success. 999 */ 1000 1001 #define LIVEPATCH_PAYLOAD_VERSION 2 1002 /* 1003 * .livepatch.funcs structure layout defined in the `Payload format` 1004 * section in the Live Patch design document. 1005 * 1006 * We guard this with __XEN__ as toolstacks SHOULD not use it. 1007 */ 1008 #ifdef __XEN__ 1009 #define LIVEPATCH_OPAQUE_SIZE 31 1010 1011 struct livepatch_expectation { 1012 uint8_t enabled : 1; 1013 uint8_t len : 5; /* Length of data up to LIVEPATCH_OPAQUE_SIZE 1014 (5 bits is enough for now) */ 1015 uint8_t rsv : 2; /* Reserved. Zero value */ 1016 uint8_t data[LIVEPATCH_OPAQUE_SIZE]; /* Same size as opaque[] buffer of 1017 struct livepatch_func. This is the 1018 max number of bytes to be patched */ 1019 }; 1020 typedef struct livepatch_expectation livepatch_expectation_t; 1021 1022 typedef enum livepatch_func_state { 1023 LIVEPATCH_FUNC_NOT_APPLIED, 1024 LIVEPATCH_FUNC_APPLIED 1025 } livepatch_func_state_t; 1026 1027 struct livepatch_func { 1028 const char *name; /* Name of function to be patched. */ 1029 void *new_addr; 1030 void *old_addr; 1031 uint32_t new_size; 1032 uint32_t old_size; 1033 uint8_t version; /* MUST be LIVEPATCH_PAYLOAD_VERSION. */ 1034 uint8_t _pad[39]; 1035 livepatch_expectation_t expect; 1036 }; 1037 typedef struct livepatch_func livepatch_func_t; 1038 #endif 1039 1040 /* 1041 * Structure describing an ELF payload. Uniquely identifies the 1042 * payload. Should be human readable. 1043 * Recommended length is upto XEN_LIVEPATCH_NAME_SIZE. 1044 * Includes the NUL terminator. 1045 */ 1046 #define XEN_LIVEPATCH_NAME_SIZE 128 1047 struct xen_livepatch_name { 1048 XEN_GUEST_HANDLE_64(char) name; /* IN: pointer to name. */ 1049 uint16_t size; /* IN: size of name. May be upto 1050 XEN_LIVEPATCH_NAME_SIZE. */ 1051 uint16_t pad[3]; /* IN: MUST be zero. */ 1052 }; 1053 1054 /* 1055 * Upload a payload to the hypervisor. The payload is verified 1056 * against basic checks and if there are any issues the proper return code 1057 * will be returned. The payload is not applied at this time - that is 1058 * controlled by XEN_SYSCTL_LIVEPATCH_ACTION. 1059 * 1060 * The return value is zero if the payload was succesfully uploaded. 1061 * Otherwise an EXX return value is provided. Duplicate `name` are not 1062 * supported. 1063 * 1064 * The payload at this point is verified against basic checks. 1065 * 1066 * The `payload` is the ELF payload as mentioned in the `Payload format` 1067 * section in the Live Patch design document. 1068 */ 1069 #define XEN_SYSCTL_LIVEPATCH_UPLOAD 0 1070 struct xen_sysctl_livepatch_upload { 1071 struct xen_livepatch_name name; /* IN, name of the patch. */ 1072 uint64_t size; /* IN, size of the ELF file. */ 1073 XEN_GUEST_HANDLE_64(uint8) payload; /* IN, the ELF file. */ 1074 }; 1075 1076 /* 1077 * Retrieve an status of an specific payload. 1078 * 1079 * Upon completion the `struct xen_livepatch_status` is updated. 1080 * 1081 * The return value is zero on success and XEN_EXX on failure. This operation 1082 * is synchronous and does not require preemption. 1083 */ 1084 #define XEN_SYSCTL_LIVEPATCH_GET 1 1085 1086 struct xen_livepatch_status { 1087 #define LIVEPATCH_STATE_CHECKED 1 1088 #define LIVEPATCH_STATE_APPLIED 2 1089 uint32_t state; /* OUT: LIVEPATCH_STATE_*. */ 1090 int32_t rc; /* OUT: 0 if no error, otherwise -XEN_EXX. */ 1091 }; 1092 typedef struct xen_livepatch_status xen_livepatch_status_t; 1093 DEFINE_XEN_GUEST_HANDLE(xen_livepatch_status_t); 1094 1095 struct xen_sysctl_livepatch_get { 1096 struct xen_livepatch_name name; /* IN, name of the payload. */ 1097 struct xen_livepatch_status status; /* IN/OUT, state of it. */ 1098 }; 1099 1100 /* 1101 * Retrieve an array of abbreviated status, names and metadata of payloads that 1102 * are loaded in the hypervisor. 1103 * 1104 * If the hypercall returns an positive number, it is the number (up to `nr`) 1105 * of the payloads returned, along with `nr` updated with the number of remaining 1106 * payloads, `version` updated (it may be the same across hypercalls. If it varies 1107 * the data is stale and further calls could fail), `name_total_size` and 1108 * `metadata_total_size` containing total sizes of transferred data for both the 1109 * arrays. 1110 * The `status`, `name`, `len`, `metadata` and `metadata_len` are updated at their 1111 * designed index value (`idx`) with the returned value of data. 1112 * 1113 * If the hypercall returns E2BIG the `nr` is too big and should be 1114 * lowered. The upper limit of `nr` is left to the implemention. 1115 * 1116 * Note that due to the asynchronous nature of hypercalls the domain might have 1117 * added or removed the number of payloads making this information stale. It is 1118 * the responsibility of the toolstack to use the `version` field to check 1119 * between each invocation. if the version differs it should discard the stale 1120 * data and start from scratch. It is OK for the toolstack to use the new 1121 * `version` field. 1122 */ 1123 #define XEN_SYSCTL_LIVEPATCH_LIST 2 1124 struct xen_sysctl_livepatch_list { 1125 uint32_t version; /* OUT: Hypervisor stamps value. 1126 If varies between calls, we are 1127 * getting stale data. */ 1128 uint32_t idx; /* IN: Index into hypervisor list. */ 1129 uint32_t nr; /* IN: How many status, name, and len 1130 should fill out. Can be zero to get 1131 amount of payloads and version. 1132 OUT: How many payloads left. */ 1133 uint32_t pad; /* IN: Must be zero. */ 1134 uint32_t name_total_size; /* IN: Size of name buffer 1135 OUT: Total size of transferred 1136 names */ 1137 uint32_t metadata_total_size; /* IN: Size of metadata buffer 1138 OUT: Total size of transferred 1139 metadata */ 1140 XEN_GUEST_HANDLE_64(xen_livepatch_status_t) status; /* OUT. Must have enough 1141 space allocate for nr of them. */ 1142 XEN_GUEST_HANDLE_64(char) name; /* OUT: Array of names. Each member 1143 may have an arbitrary length up to 1144 XEN_LIVEPATCH_NAME_SIZE bytes. Must have 1145 nr of them. */ 1146 XEN_GUEST_HANDLE_64(uint32) len; /* OUT: Array of lengths of name's. 1147 Must have nr of them. */ 1148 XEN_GUEST_HANDLE_64(char) metadata; /* OUT: Array of metadata strings. Each 1149 member may have an arbitrary length. 1150 Must have nr of them. */ 1151 XEN_GUEST_HANDLE_64(uint32) metadata_len; /* OUT: Array of lengths of metadata's. 1152 Must have nr of them. */ 1153 }; 1154 1155 /* 1156 * Perform an operation on the payload structure referenced by the `name` field. 1157 * The operation request is asynchronous and the status should be retrieved 1158 * by using either XEN_SYSCTL_LIVEPATCH_GET or XEN_SYSCTL_LIVEPATCH_LIST hypercall. 1159 */ 1160 #define XEN_SYSCTL_LIVEPATCH_ACTION 3 1161 struct xen_sysctl_livepatch_action { 1162 struct xen_livepatch_name name; /* IN, name of the patch. */ 1163 #define LIVEPATCH_ACTION_UNLOAD 1 1164 #define LIVEPATCH_ACTION_REVERT 2 1165 #define LIVEPATCH_ACTION_APPLY 3 1166 #define LIVEPATCH_ACTION_REPLACE 4 1167 uint32_t cmd; /* IN: LIVEPATCH_ACTION_*. */ 1168 uint32_t timeout; /* IN: If zero then uses */ 1169 /* hypervisor default. */ 1170 /* Or upper bound of time (ns) */ 1171 /* for operation to take. */ 1172 1173 /* 1174 * Override default inter-module buildid dependency chain enforcement. 1175 * Check only if module is built for given hypervisor by comparing buildid. 1176 */ 1177 #define LIVEPATCH_ACTION_APPLY_NODEPS (1 << 0) 1178 uint32_t flags; /* IN: action flags. */ 1179 /* Provide additional parameters */ 1180 /* for an action. */ 1181 uint32_t pad; /* IN: Always zero. */ 1182 }; 1183 1184 struct xen_sysctl_livepatch_op { 1185 uint32_t cmd; /* IN: XEN_SYSCTL_LIVEPATCH_*. */ 1186 uint32_t flags; /* IN, flags. */ 1187 #define LIVEPATCH_FLAG_FORCE (1u << 0) /* Skip some checks. */ 1188 #define LIVEPATCH_FLAGS_MASK LIVEPATCH_FLAG_FORCE 1189 union { 1190 struct xen_sysctl_livepatch_upload upload; 1191 struct xen_sysctl_livepatch_list list; 1192 struct xen_sysctl_livepatch_get get; 1193 struct xen_sysctl_livepatch_action action; 1194 } u; 1195 }; 1196 1197 #if defined(__i386__) || defined(__x86_64__) 1198 /* 1199 * XEN_SYSCTL_get_cpu_policy (x86 specific) 1200 * 1201 * Return information about CPUID and MSR policies available on this host. 1202 * - Raw: The real H/W values. 1203 * - Host: The values Xen is using, (after command line overrides, etc). 1204 * - Max_*: Maximum set of features a PV or HVM guest can use. Includes 1205 * experimental features outside of security support. 1206 * - Default_*: Default set of features a PV or HVM guest can use. This is 1207 * the security supported set. 1208 * May fail with -EOPNOTSUPP if querying for PV or HVM data when support is 1209 * compiled out of Xen. 1210 */ 1211 struct xen_sysctl_cpu_policy { 1212 #define XEN_SYSCTL_cpu_policy_raw 0 1213 #define XEN_SYSCTL_cpu_policy_host 1 1214 #define XEN_SYSCTL_cpu_policy_pv_max 2 1215 #define XEN_SYSCTL_cpu_policy_hvm_max 3 1216 #define XEN_SYSCTL_cpu_policy_pv_default 4 1217 #define XEN_SYSCTL_cpu_policy_hvm_default 5 1218 uint32_t index; /* IN: Which policy to query? */ 1219 uint32_t nr_leaves; /* IN/OUT: Number of leaves in/written to 'leaves', 1220 * or the max number if 'leaves' is NULL. */ 1221 uint32_t nr_msrs; /* IN/OUT: Number of MSRs in/written to 'msrs', or 1222 * the max number of if 'msrs' is NULL. */ 1223 uint32_t _rsvd; /* Must be zero. */ 1224 XEN_GUEST_HANDLE_64(xen_cpuid_leaf_t) leaves; /* OUT */ 1225 XEN_GUEST_HANDLE_64(xen_msr_entry_t) msrs; /* OUT */ 1226 }; 1227 typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; 1228 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); 1229 #endif 1230 1231 #if defined(__arm__) || defined(__aarch64__) 1232 /* 1233 * XEN_SYSCTL_dt_overlay 1234 * Performs addition/removal of device tree nodes under parent node using dtbo 1235 * from dt_host. 1236 */ 1237 struct xen_sysctl_dt_overlay { 1238 XEN_GUEST_HANDLE_64(const_void) overlay_fdt; /* IN: overlay fdt. */ 1239 uint32_t overlay_fdt_size; /* IN: Overlay dtb size. */ 1240 #define XEN_SYSCTL_DT_OVERLAY_ADD 1 1241 #define XEN_SYSCTL_DT_OVERLAY_REMOVE 2 1242 uint8_t overlay_op; /* IN: Add or remove. */ 1243 uint8_t pad[3]; /* IN: Must be zero. */ 1244 }; 1245 #endif 1246 1247 struct xen_sysctl { 1248 uint32_t cmd; 1249 #define XEN_SYSCTL_readconsole 1 1250 #define XEN_SYSCTL_tbuf_op 2 1251 #define XEN_SYSCTL_physinfo 3 1252 #define XEN_SYSCTL_sched_id 4 1253 #define XEN_SYSCTL_perfc_op 5 1254 #define XEN_SYSCTL_getdomaininfolist 6 1255 #define XEN_SYSCTL_debug_keys 7 1256 #define XEN_SYSCTL_getcpuinfo 8 1257 #define XEN_SYSCTL_availheap 9 1258 #define XEN_SYSCTL_get_pmstat 10 1259 #define XEN_SYSCTL_cpu_hotplug 11 1260 #define XEN_SYSCTL_pm_op 12 1261 #define XEN_SYSCTL_page_offline_op 14 1262 #define XEN_SYSCTL_lockprof_op 15 1263 #define XEN_SYSCTL_cputopoinfo 16 1264 #define XEN_SYSCTL_numainfo 17 1265 #define XEN_SYSCTL_cpupool_op 18 1266 #define XEN_SYSCTL_scheduler_op 19 1267 #define XEN_SYSCTL_coverage_op 20 1268 #define XEN_SYSCTL_psr_cmt_op 21 1269 #define XEN_SYSCTL_pcitopoinfo 22 1270 #define XEN_SYSCTL_psr_alloc 23 1271 /* #define XEN_SYSCTL_tmem_op 24 */ 1272 #define XEN_SYSCTL_get_cpu_levelling_caps 25 1273 #define XEN_SYSCTL_get_cpu_featureset 26 1274 #define XEN_SYSCTL_livepatch_op 27 1275 /* #define XEN_SYSCTL_set_parameter 28 */ 1276 #define XEN_SYSCTL_get_cpu_policy 29 1277 #define XEN_SYSCTL_dt_overlay 30 1278 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ 1279 union { 1280 struct xen_sysctl_readconsole readconsole; 1281 struct xen_sysctl_tbuf_op tbuf_op; 1282 struct xen_sysctl_physinfo physinfo; 1283 struct xen_sysctl_cputopoinfo cputopoinfo; 1284 struct xen_sysctl_pcitopoinfo pcitopoinfo; 1285 struct xen_sysctl_numainfo numainfo; 1286 struct xen_sysctl_sched_id sched_id; 1287 struct xen_sysctl_perfc_op perfc_op; 1288 struct xen_sysctl_getdomaininfolist getdomaininfolist; 1289 struct xen_sysctl_debug_keys debug_keys; 1290 struct xen_sysctl_getcpuinfo getcpuinfo; 1291 struct xen_sysctl_availheap availheap; 1292 struct xen_sysctl_get_pmstat get_pmstat; 1293 struct xen_sysctl_cpu_hotplug cpu_hotplug; 1294 struct xen_sysctl_pm_op pm_op; 1295 struct xen_sysctl_page_offline_op page_offline; 1296 struct xen_sysctl_lockprof_op lockprof_op; 1297 struct xen_sysctl_cpupool_op cpupool_op; 1298 struct xen_sysctl_scheduler_op scheduler_op; 1299 struct xen_sysctl_coverage_op coverage_op; 1300 struct xen_sysctl_psr_cmt_op psr_cmt_op; 1301 struct xen_sysctl_psr_alloc psr_alloc; 1302 struct xen_sysctl_cpu_levelling_caps cpu_levelling_caps; 1303 struct xen_sysctl_cpu_featureset cpu_featureset; 1304 struct xen_sysctl_livepatch_op livepatch; 1305 #if defined(__i386__) || defined(__x86_64__) 1306 struct xen_sysctl_cpu_policy cpu_policy; 1307 #endif 1308 1309 #if defined(__arm__) || defined(__aarch64__) 1310 struct xen_sysctl_dt_overlay dt_overlay; 1311 #endif 1312 uint8_t pad[128]; 1313 } u; 1314 }; 1315 typedef struct xen_sysctl xen_sysctl_t; 1316 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_t); 1317 1318 #endif /* __XEN_PUBLIC_SYSCTL_H__ */ 1319 1320 /* 1321 * Local variables: 1322 * mode: C 1323 * c-file-style: "BSD" 1324 * c-basic-offset: 4 1325 * tab-width: 4 1326 * indent-tabs-mode: nil 1327 * End: 1328 */ 1329