1 /* 2 * Copyright 2017 The ChromiumOS Authors 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7 #ifndef __CROSVM_H__ 8 #define __CROSVM_H__ 9 10 #include <assert.h> 11 #include <stdint.h> 12 #include <stdbool.h> 13 14 #include <linux/kvm.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /* 21 * This module is used to implement a plugin for crosvm. 22 * 23 * A plugin for crosvm interfaces with the virtual machine using the `struct 24 * crosvm` object and its child objects. A typical plugin is expected to call 25 * `crosvm_connect`, perform some amount of setup with the functions defined 26 * here, get a handle to every vcpu using `struct crosvm_vcpu` and then call 27 * `crosvm_start`. Each vcpu will then be waited on with `crosvm_vcpu_wait`, 28 * each event will be responded to by the plugin, and then the vcpu is resumed 29 * with `crosvm_vcpu_resume`. The vcpu state can only be examined and modified 30 * between the `crosvm_vcpu_wait` and `crosvm_vcpu_resume` calls. The crosvm 31 * connection can be used to modify global virtual machine state at any time, 32 * with some structural restrictions after `crosvm_start` is called. 33 * 34 * In general, functions that return an `int` return 0 on success or a non- 35 * negative file descriptor if one is expected. A negative return value is an 36 * errno and indicates error. Functions that take a pointer-to-pointer to an 37 * opaque structure either return a structure or delete and nullify that 38 * structure pointer. 39 */ 40 41 /* 42 * We use Semantic Versioning (http://semver.org/) here, which means that as 43 * long as MAJOR is 0, breaking changes can occur, but once MAJOR is non-zero, a 44 * breaking change requires a MAJOR version bump. The MINOR number increases as 45 * backward compatible functionality is added. The PATCH number increases bug 46 * fixes are done. The version numbers indicate here are for the plugin API and 47 * do not indicate anything about what version of crosvm is running. 48 */ 49 #define CROSVM_API_MAJOR 0 50 #define CROSVM_API_MINOR 22 51 #define CROSVM_API_PATCH 0 52 53 enum crosvm_address_space { 54 /* I/O port */ 55 CROSVM_ADDRESS_SPACE_IOPORT = 0, 56 /* physical memory space */ 57 CROSVM_ADDRESS_SPACE_MMIO, 58 }; 59 60 /* Handle to the parent crosvm process. */ 61 struct crosvm; 62 63 /* Handle to a register ioeventfd. */ 64 struct crosvm_io; 65 66 /* Handle to a registered range of shared memory. */ 67 struct crosvm_memory; 68 69 /* Handle to a registered irqfd. */ 70 struct crosvm_irq; 71 72 /* Handle to one of the VM's VCPUs. */ 73 struct crosvm_vcpu; 74 75 /* 76 * Connects to the parent crosvm process and returns a new `struct crosvm` 77 * interface object. 78 * 79 * This is the entry point for interfacing with crosvm as a plugin. This should 80 * be called before any other function. The returned object is not-thread safe. 81 */ 82 int crosvm_connect(struct crosvm**); 83 84 /* 85 * Creates another connection for interfacing with crosvm concurrently. 86 * 87 * The new connection behaves exactly like the original `struct crosvm` but can 88 * be used concurrently on a different thread than the original. Actual 89 * execution order of the requests to crosvm is unspecified but every request is 90 * completed when the `crosvm_*` call returns. 91 * 92 * It is invalid to call this after `crosvm_start` is called on any `struct 93 * crosvm`. 94 */ 95 int crosvm_new_connection(struct crosvm*, struct crosvm**); 96 97 /* 98 * Destroys this connection and tells the parent crosvm process to stop 99 * listening for messages from it. 100 */ 101 int crosvm_destroy_connection(struct crosvm**); 102 103 /* 104 * Gets an eventfd that is triggered when this plugin should exit. 105 * 106 * The returned eventfd is owned by the caller but the underlying event is 107 * shared and will therefore only trigger once. 108 */ 109 int crosvm_get_shutdown_eventfd(struct crosvm*); 110 111 /* 112 * Gets a bool indicating if a KVM_CAP_* enum is supported on this VM 113 */ 114 int crosvm_check_extension(struct crosvm*, uint32_t __extension, 115 bool *has_extension); 116 117 /* 118 * Enable an extended capability for the VM. Currently |__flags| and 119 * |__args| must be zero. No values for |__capability| are supported, 120 * so all calls will fail. 121 */ 122 int crosvm_enable_capability(struct crosvm*, uint32_t __capability, 123 uint32_t __flags, uint64_t __args[4]); 124 125 /* 126 * Queries x86 cpuid features which are supported by the hardware and 127 * kvm. 128 */ 129 int crosvm_get_supported_cpuid(struct crosvm*, uint32_t __entry_count, 130 struct kvm_cpuid_entry2 *__cpuid_entries, 131 uint32_t *__out_count); 132 133 /* 134 * Queries x86 cpuid features which are emulated by kvm. 135 */ 136 int crosvm_get_emulated_cpuid(struct crosvm*, uint32_t __entry_count, 137 struct kvm_cpuid_entry2 *__cpuid_entries, 138 uint32_t *__out_count); 139 140 /* 141 * Queries x86 hyper-v cpuid features which are emulated by kvm. 142 */ 143 int crosvm_get_hyperv_cpuid(struct crosvm_vcpu*, uint32_t __entry_count, 144 struct kvm_cpuid_entry2 *__cpuid_entries, 145 uint32_t *__out_count); 146 147 /* 148 * Queries kvm for list of supported MSRs. 149 */ 150 int crosvm_get_msr_index_list(struct crosvm*, uint32_t __entry_count, 151 uint32_t *__msr_indices, 152 uint32_t *__out_count); 153 154 /* 155 * The network configuration for a crosvm instance. 156 */ 157 struct crosvm_net_config { 158 /* 159 * The tap device fd. This fd is owned by the caller, and should be closed 160 * by the caller when it is no longer in use. 161 */ 162 int tap_fd; 163 /* The IPv4 address of the tap interface, in network (big-endian) format. */ 164 uint32_t host_ip; 165 /* The netmask of the tap interface subnet, in network (big-endian) format. */ 166 uint32_t netmask; 167 /* The mac address of the host side of the tap interface. */ 168 uint8_t host_mac_address[6]; 169 uint8_t _padding[2]; 170 }; 171 172 #ifdef static_assert 173 static_assert(sizeof(struct crosvm_net_config) == 20, 174 "extra padding in struct crosvm_net_config"); 175 #endif 176 177 /* 178 * Gets the network configuration. 179 */ 180 int crosvm_net_get_config(struct crosvm*, struct crosvm_net_config*); 181 182 /* 183 * Registers a range in the given address space that, when accessed, will block 184 * and wait for a crosvm_vcpu_resume call. 185 * 186 * To unreserve a range previously reserved by this function, pass the |__space| 187 * and |__start| of the old reservation with a 0 |__length|. 188 */ 189 int crosvm_reserve_range(struct crosvm*, uint32_t __space, uint64_t __start, 190 uint64_t __length); 191 192 /* 193 * Registers a range in the given address space that, when accessed via write, 194 * will cause a notification in crosvm_vcpu_wait() but the VM will continue 195 * running. 196 * For this type of notification (where |no_resume| is set) the next call 197 * should be crosvm_vcpu_wait() (without an inbetween call to 198 * crosvm_vcpu_resume() ). 199 * 200 * The requested range must not overlap any prior (and currently active) 201 * reservation to crosvm_reserve_range() or crosvm_reserve_async_write_range(). 202 * 203 * To unreserve a range previously reserved by this function, pass the |__space| 204 * and |__start| of the old reservation with a 0 |__length|. 205 */ 206 int crosvm_reserve_async_write_range(struct crosvm*, uint32_t __space, 207 uint64_t __start, uint64_t __length); 208 209 /* 210 * Sets the state of the given irq pin. 211 */ 212 int crosvm_set_irq(struct crosvm*, uint32_t __irq_id, bool __active); 213 214 enum crosvm_irq_route_kind { 215 /* IRQ pin to GSI route */ 216 CROSVM_IRQ_ROUTE_IRQCHIP = 0, 217 /* MSI address and data to GSI route */ 218 CROSVM_IRQ_ROUTE_MSI, 219 }; 220 221 /* One entry in the array of irq routing table */ 222 struct crosvm_irq_route { 223 /* The IRQ number to trigger. */ 224 uint32_t irq_id; 225 /* A `crosvm_irq_route_kind` indicating which union member to use */ 226 uint32_t kind; 227 union { 228 struct { 229 /* 230 * One of KVM_IRQCHIP_PIC_MASTER, KVM_IRQCHIP_PIC_SLAVE, or 231 * KVM_IRQCHIP_IOAPIC indicating which irqchip the indicated pin is on. 232 */ 233 uint32_t irqchip; 234 /* The pin on the irqchip used to trigger the IRQ. */ 235 uint32_t pin; 236 } irqchip; 237 238 struct { 239 /* Address that triggers the irq. */ 240 uint64_t address; 241 /* Data written to `address` that triggers the irq */ 242 uint32_t data; 243 244 uint8_t _reserved[4]; 245 } msi; 246 247 uint8_t _reserved[16]; 248 }; 249 }; 250 251 #ifdef static_assert 252 static_assert(sizeof(struct crosvm_irq_route) == 24, 253 "extra padding in struct crosvm_irq_route"); 254 #endif 255 256 /* 257 * Sets all the gsi routing entries to those indicated by `routes`. 258 * 259 * To remove all routing entries, pass NULL for `routes` and 0 to route_count. 260 */ 261 int crosvm_set_irq_routing(struct crosvm*, uint32_t __route_count, 262 const struct crosvm_irq_route* __routes); 263 264 /* Hint on what information is queried for a particular hypercall. */ 265 struct crosvm_hint_detail { 266 bool match_rax; 267 bool match_rbx; 268 bool match_rcx; 269 bool match_rdx; 270 uint8_t _reserved[4]; 271 uint64_t rax; 272 uint64_t rbx; 273 uint64_t rcx; 274 uint64_t rdx; 275 bool send_sregs; 276 bool send_debugregs; 277 uint8_t _reserved2[6]; 278 }; 279 280 #ifdef static_assert 281 static_assert(sizeof(struct crosvm_hint_detail) == 48, 282 "extra padding in struct crosvm_hint_detail"); 283 #endif 284 285 /* Maximum # of hints that can be passed to crosvm_set_hypercall_hint(). */ 286 #define CROSVM_MAX_HINT_COUNT 1 287 288 /* Maximum # of hint details that can be provided for a hint. */ 289 #define CROSVM_MAX_HINT_DETAIL_COUNT 32 290 291 #define CROSVM_HINT_ON_WRITE 0x1 292 293 /* Hint on what information is queried for a particular hypercall. */ 294 struct crosvm_hint { 295 uint32_t hint_version; /* For now only 0 is defined. */ 296 uint32_t _reserved; /* Must be zero. */ 297 uint32_t address_space; /* Value from crosvm_address_space. */ 298 uint16_t address_flags; /* 0: read/in; CROSVM_HINT_ON_WRITE: write/out. */ 299 uint16_t details_count; /* # of elements in |details|. */ 300 uint64_t address; 301 union { 302 struct crosvm_hint_detail *details; 303 uint64_t _reserved2; /* forcing pointer length to 64-bit */ 304 }; 305 }; 306 307 #ifdef static_assert 308 static_assert(sizeof(struct crosvm_hint) == 32, 309 "extra padding in struct crosvm_hint"); 310 #endif 311 312 /* 313 * Sets performance hint(s) for a hypercall port. 314 * 315 * If a VM does an io access the specified |address_space|, |address| 316 * (|address| must be non-zero), and direction (|address_flags|), then 317 * crosvm will assume the plugin is likely to call crosvm_vcpu_get_regs() 318 * (and thus utilize a cache to improve performance). 319 * 320 * Additional hints can be provided via |details| (the element length of 321 * |details| is limited to CROSVM_MAX_HINT_DETAIL_COUNT) on when to also cache 322 * information for crosvm_vcpu_get_sregs() and crosvm_vcpu_get_debugregs() 323 * based on values in the vcpu registers. |match_XXX| indicates which of 324 * 1 or more of |XXX| needs to be equal to the vcpu registers to be a match. 325 * On a match |send_sregs| and |send_debugregs| are used to determine what 326 * data to proactively cache for the plugin's use. Once a match is found 327 * the remaining hints are not consulted. 328 * 329 * To remove all hints, pass 0 for |__hint_count|. The value of 330 * |__hint_count| can be at most CROSVM_MAX_HINT_COUNT. Currently the API 331 * is limited to 1 hint (i.e., |__hint_count| must be 0 or 1). Each call 332 * to this API will replace the values specified by any prior call to this API. 333 */ 334 int crosvm_set_hypercall_hint(struct crosvm *, uint32_t __hints_count, 335 const struct crosvm_hint* __hints); 336 337 /* Gets the state of interrupt controller in a VM. */ 338 int crosvm_get_pic_state(struct crosvm *, bool __primary, 339 struct kvm_pic_state *__pic_state); 340 341 /* Sets the state of interrupt controller in a VM. */ 342 int crosvm_set_pic_state(struct crosvm *, bool __primary, 343 const struct kvm_pic_state *__pic_state); 344 345 /* Gets the state of IOAPIC in a VM. */ 346 int crosvm_get_ioapic_state(struct crosvm *, 347 struct kvm_ioapic_state *__ioapic_state); 348 349 /* Sets the state of IOAPIC in a VM. */ 350 int crosvm_set_ioapic_state(struct crosvm *, 351 const struct kvm_ioapic_state *__ioapic_state); 352 353 /* Gets the state of interrupt controller in a VM. */ 354 int crosvm_get_pit_state(struct crosvm *, struct kvm_pit_state2 *__pit_state); 355 356 /* Sets the state of interrupt controller in a VM. */ 357 int crosvm_set_pit_state(struct crosvm *, 358 const struct kvm_pit_state2 *__pit_state); 359 360 /* Gets the current timestamp of kvmclock as seen by the VM. */ 361 int crosvm_get_clock(struct crosvm *, struct kvm_clock_data *__clock_data); 362 363 /* Sets the current timestamp of kvmclock for the VM. */ 364 int crosvm_set_clock(struct crosvm *, 365 const struct kvm_clock_data *__clock_data); 366 367 /* Sets the identity map address as in the KVM_SET_IDENTITY_MAP_ADDR ioctl. */ 368 int crosvm_set_identity_map_addr(struct crosvm*, uint32_t __addr); 369 370 /* 371 * Triggers a CROSVM_VCPU_EVENT_KIND_PAUSED event on each vcpu identified 372 * |__cpu_mask|. 373 * 374 * The `user` pointer will be given as the `user` pointer in the `struct 375 * crosvm_vcpu_event` returned by crosvm_vcpu_wait. 376 */ 377 int crosvm_pause_vcpus(struct crosvm*, uint64_t __cpu_mask, void* __user); 378 379 /* 380 * Call once initialization is done. This indicates that crosvm should proceed 381 * with running the VM. 382 * 383 * After this call, this function is no longer valid to call. 384 */ 385 int crosvm_start(struct crosvm*); 386 387 /* 388 * Allocates an eventfd that is triggered asynchronously on write in |__space| 389 * at the given |__addr|. 390 * 391 * If |__datamatch| is non-NULL, it must be contain |__length| bytes that will 392 * be compared to the bytes being written by the vcpu which will only trigger 393 * the eventfd if equal. If datamatch is NULL all writes to the address will 394 * trigger the eventfd. 395 * 396 * On successful allocation, returns a crosvm_io. Obtain the actual fd 397 * by passing this result to crosvm_io_event_fd(). 398 */ 399 int crosvm_create_io_event(struct crosvm*, uint32_t __space, uint64_t __addr, 400 uint32_t __len, const uint8_t* __datamatch, 401 struct crosvm_io**); 402 403 /* 404 * Destroys the given io event and unregisters it from the VM. 405 */ 406 int crosvm_destroy_io_event(struct crosvm*, struct crosvm_io**); 407 408 /* 409 * Gets the eventfd triggered by the given io event. 410 * 411 * The returned fd is owned by the given `struct crosvm_io` and has a lifetime 412 * equal to that handle. 413 */ 414 int crosvm_io_event_fd(struct crosvm_io*); 415 416 /* 417 * Creates a shared memory segment backed by a memfd. 418 * 419 * Inserts non-overlapping memory pages in the guest physical address range 420 * specified by |__start| address and |__length| bytes. The memory pages are 421 * backed by the memfd |__fd| and are taken starting at |__offset| bytes from 422 * the beginning of the memfd. 423 * 424 * The `memfd_create` syscall |__fd| must be used to create |__fd| and a shrink 425 * seal must have been added to |__fd|. The memfd must be at least 426 * `__length+__offset` bytes long. 427 * 428 * If |read_only| is true, attempts by the guest to write to this memory region 429 * will trigger an IO access exit. 430 * 431 * To use the `crosvm_memory_get_dirty_log` method with the returned object, 432 * |__dirty_log| must be true. 433 */ 434 int crosvm_create_memory(struct crosvm*, int __fd, uint64_t __offset, 435 uint64_t __length, uint64_t __start, 436 bool __read_only, bool __dirty_log, 437 struct crosvm_memory**); 438 439 /* 440 * Destroys the given shared memory and unregisters it from guest physical 441 * address space. 442 */ 443 int crosvm_destroy_memory(struct crosvm*, struct crosvm_memory**); 444 445 /* 446 * For a given memory region returns a bitmap containing any pages 447 * dirtied since the last call to this function. 448 * 449 * The `log` array must have as many bits as the memory segment has pages. 450 */ 451 int crosvm_memory_get_dirty_log(struct crosvm*, struct crosvm_memory*, 452 uint8_t* __log); 453 454 /* 455 * Creates an irq eventfd that can be used to trigger an irq asynchronously. 456 * 457 * The irq that will be triggered is identified as pin |__irq_id|. 458 */ 459 int crosvm_create_irq_event(struct crosvm*, uint32_t __irq_id, 460 struct crosvm_irq**); 461 462 /* 463 * Unregisters and destroys an irq eventfd. 464 */ 465 int crosvm_destroy_irq_event(struct crosvm*, struct crosvm_irq**); 466 467 /* 468 * Gets the eventfd used to trigger the irq 469 * 470 * The returned fd is owned by the given `struct crosvm_irq` and has a lifetime 471 * equal to that handle. 472 */ 473 int crosvm_irq_event_get_fd(const struct crosvm_irq*); 474 475 /* 476 * Gets the resample eventfd associated with the crosvm_irq object. 477 */ 478 int crosvm_irq_event_get_resample_fd(const struct crosvm_irq*); 479 480 enum crosvm_vcpu_event_kind { 481 /* 482 * The first event returned by crosvm_vcpu_wait, indicating the VCPU has been 483 * created but not yet started for the first time. 484 */ 485 CROSVM_VCPU_EVENT_KIND_INIT = 0, 486 487 /* 488 * Access to an address in a space previously reserved by 489 * crosvm_reserve_range. 490 */ 491 CROSVM_VCPU_EVENT_KIND_IO_ACCESS, 492 493 /* 494 * A pause on this vcpu (and possibly others) was requested by this plugin in 495 * a `crosvm_pause_vcpus` call. 496 */ 497 CROSVM_VCPU_EVENT_KIND_PAUSED, 498 499 /* 500 * Hyper-V hypercall. 501 */ 502 CROSVM_VCPU_EVENT_KIND_HYPERV_HCALL, 503 504 /* 505 * Hyper-V synic change. 506 */ 507 CROSVM_VCPU_EVENT_KIND_HYPERV_SYNIC, 508 }; 509 510 struct crosvm_vcpu_event { 511 /* Indicates the kind of event and which union member is valid. */ 512 uint32_t kind; 513 514 uint8_t _padding[4]; 515 516 union { 517 /* CROSVM_VCPU_EVENT_KIND_IO_ACCESS */ 518 struct { 519 /* 520 * One of `enum crosvm_address_space` indicating which address space the 521 * access occurred in. 522 */ 523 uint32_t address_space; 524 525 uint8_t _padding[4]; 526 527 /* The address that the access occurred at. */ 528 uint64_t address; 529 530 /* 531 * In the case that `is_write` is true, the first `length` bytes are the 532 * data being written by the vcpu. 533 */ 534 uint8_t *data; 535 536 /* 537 * Number of bytes in the access. In the case that the access is larger 538 * than 8 bytes, such as by AVX-512 instructions, multiple vcpu access 539 * events are generated serially to cover each 8 byte fragment of the 540 * access. 541 * 542 * Larger I/O accesses are possible. "rep in" can generate I/Os larger 543 * than 8 bytes, though such accesses can also be split into multiple 544 * events. Currently kvm doesn't seem to batch "rep out" I/Os. 545 */ 546 uint32_t length; 547 548 /* 549 * True if the vcpu was attempting to write, false in case of an attempt 550 * to read. 551 */ 552 uint8_t is_write; 553 554 /* 555 * Valid when |is_write| is true -- indicates that VM has continued 556 * to run. The only next valid call for the vcpu is crosvm_vcpu_wait(). 557 */ 558 uint8_t no_resume; 559 560 uint8_t _reserved[2]; 561 } io_access; 562 563 /* CROSVM_VCPU_EVENT_KIND_PAUSED */ 564 void *user; 565 566 /* CROSVM_VCPU_EVENT_KIND_HYPERV_HCALL */ 567 struct { 568 /* 569 * The |input| and |params| members are populated for the plugin to use. 570 * The |result| member is populated by the API to point to a uint64_t 571 * that the plugin should update before resuming. 572 */ 573 uint64_t input; 574 uint64_t *result; 575 uint64_t params[2]; 576 } hyperv_call; 577 578 /* CROSVM_VCPU_EVENT_KIND_HYPERV_SYNIC */ 579 struct { 580 /* 581 * The |msr|, |control|, |evt_page|, and |msg_page| fields are populated 582 * for the plugin to use. 583 */ 584 uint32_t msr; 585 uint32_t _reserved; 586 uint64_t control; 587 uint64_t evt_page; 588 uint64_t msg_page; 589 } hyperv_synic; 590 591 uint8_t _reserved[64]; 592 }; 593 }; 594 595 #ifdef static_assert 596 static_assert(sizeof(struct crosvm_vcpu_event) == 72, 597 "extra padding in struct crosvm_vcpu_event"); 598 #endif 599 600 /* 601 * Gets the vcpu object for the given |__cpu_id|. 602 * 603 * 604 * The `struct crosvm_vcpu` is owned by `struct crosvm`. Each call with the same 605 * `crosvm` and |__cpu_id| will yield the same pointer. The `crosvm_vcpu` does 606 * not need to be destroyed or created explicitly. 607 * 608 * The range of valid |__cpu_id|s is 0 to the number of vcpus - 1. To get every 609 * `crosvm_vcpu`, simply call this function iteratively with increasing 610 * |__cpu_id| until `-ENOENT` is returned. 611 * 612 */ 613 int crosvm_get_vcpu(struct crosvm*, uint32_t __cpu_id, struct crosvm_vcpu**); 614 615 /* 616 * Blocks until a vcpu event happens that requires a response. 617 * 618 * When crosvm_vcpu_wait returns successfully, the event structure is filled 619 * with the description of the event that occurred. The vcpu will suspend 620 * execution until a matching call to `crosvm_vcpu_resume` is made. Until such a 621 * call is made, the vcpu's run structure can be read and written using any 622 * `crosvm_vcpu_get` or `crosvm_vcpu_set` function. 623 */ 624 int crosvm_vcpu_wait(struct crosvm_vcpu*, struct crosvm_vcpu_event*); 625 626 /* 627 * Resumes execution of a vcpu after a call to `crosvm_vcpu_wait` returns. 628 * 629 * In the case that the event was a read operation, `data` indicates what the 630 * result of that read operation should be. If the read operation was larger 631 * than 8 bytes, such as by AVX-512 instructions, this will not actually resume 632 * the vcpu, but instead generate another vcpu access event of the next fragment 633 * of the read, which can be handled by the next `crosvm_vcpu_wait` call. 634 * 635 * Once the vcpu event has been responded to sufficiently enough to resume 636 * execution, `crosvm_vcpu_resume` should be called. After `crosvm_vcpu_resume` 637 * is called, none of the vcpu state operations are valid until the next time 638 * `crosvm_vcpu_wait` returns. 639 */ 640 int crosvm_vcpu_resume(struct crosvm_vcpu*); 641 642 /* Gets the state of the vcpu's registers. */ 643 int crosvm_vcpu_get_regs(struct crosvm_vcpu*, struct kvm_regs*); 644 /* Sets the state of the vcpu's registers. */ 645 int crosvm_vcpu_set_regs(struct crosvm_vcpu*, const struct kvm_regs*); 646 647 /* Gets the state of the vcpu's special registers. */ 648 int crosvm_vcpu_get_sregs(struct crosvm_vcpu*, struct kvm_sregs*); 649 /* Sets the state of the vcpu's special registers. */ 650 int crosvm_vcpu_set_sregs(struct crosvm_vcpu*, const struct kvm_sregs*); 651 652 /* Gets the state of the vcpu's floating point unint. */ 653 int crosvm_vcpu_get_fpu(struct crosvm_vcpu*, struct kvm_fpu*); 654 /* Sets the state of the vcpu's floating point unint. */ 655 int crosvm_vcpu_set_fpu(struct crosvm_vcpu*, const struct kvm_fpu*); 656 657 /* Gets the state of the vcpu's debug registers. */ 658 int crosvm_vcpu_get_debugregs(struct crosvm_vcpu*, struct kvm_debugregs*); 659 /* Sets the state of the vcpu's debug registers */ 660 int crosvm_vcpu_set_debugregs(struct crosvm_vcpu*, const struct kvm_debugregs*); 661 662 /* Gets the state of the vcpu's xcr registers. */ 663 int crosvm_vcpu_get_xcrs(struct crosvm_vcpu*, struct kvm_xcrs*); 664 /* Sets the state of the vcpu's xcr registers. */ 665 int crosvm_vcpu_set_xcrs(struct crosvm_vcpu*, const struct kvm_xcrs*); 666 667 /* Gets the MSRs of the vcpu indicated by the index field of each entry. */ 668 int crosvm_vcpu_get_msrs(struct crosvm_vcpu*, uint32_t __msr_count, 669 struct kvm_msr_entry *__msr_entries, 670 uint32_t *__out_count); 671 /* Sets the MSRs of the vcpu indicated by the index field of each entry. */ 672 int crosvm_vcpu_set_msrs(struct crosvm_vcpu*, uint32_t __msr_count, 673 const struct kvm_msr_entry *__msr_entries); 674 675 /* Sets the responses to the cpuid instructions executed on this vcpu, */ 676 int crosvm_vcpu_set_cpuid(struct crosvm_vcpu*, uint32_t __cpuid_count, 677 const struct kvm_cpuid_entry2 *__cpuid_entries); 678 679 /* 680 * Enable an extended capability for a vcpu. Currently |__flags| and 681 * |__args| must be zero. The only permitted values for |__capability| 682 * are KVM_CAP_HYPERV_SYNIC or KVM_CAP_HYPERV_SYNIC2, though the latter 683 * also depends on kernel support. 684 */ 685 int crosvm_vcpu_enable_capability(struct crosvm_vcpu*, uint32_t __capability, 686 uint32_t __flags, uint64_t __args[4]); 687 688 /* Gets state of LAPIC of the VCPU. */ 689 int crosvm_vcpu_get_lapic_state(struct crosvm_vcpu *, 690 struct kvm_lapic_state *__lapic_state); 691 /* Sets state of LAPIC of the VCPU. */ 692 int crosvm_vcpu_set_lapic_state(struct crosvm_vcpu *, 693 const struct kvm_lapic_state *__lapic_state); 694 695 /* Gets the "multiprocessor state" of given VCPU. */ 696 int crosvm_vcpu_get_mp_state(struct crosvm_vcpu *, 697 struct kvm_mp_state *__mp_state); 698 /* Sets the "multiprocessor state" of given VCPU. */ 699 int crosvm_vcpu_set_mp_state(struct crosvm_vcpu *, 700 const struct kvm_mp_state *__mp_state); 701 702 /* Gets currently pending exceptions, interrupts, NMIs, etc for VCPU. */ 703 int crosvm_vcpu_get_vcpu_events(struct crosvm_vcpu *, 704 struct kvm_vcpu_events *); 705 706 /* Sets currently pending exceptions, interrupts, NMIs, etc for VCPU. */ 707 int crosvm_vcpu_set_vcpu_events(struct crosvm_vcpu *, 708 const struct kvm_vcpu_events *); 709 710 #ifdef __cplusplus 711 } 712 #endif 713 714 #endif 715