1 /* 2 * Copyright 2017 The Chromium OS Authors. All rights reserved. 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 fd for the gpu server. 179 */ 180 int crosvm_get_render_server_fd(void); 181 182 /* 183 * Gets the network configuration. 184 */ 185 int crosvm_net_get_config(struct crosvm*, struct crosvm_net_config*); 186 187 /* 188 * Registers a range in the given address space that, when accessed, will block 189 * and wait for a crosvm_vcpu_resume call. 190 * 191 * To unreserve a range previously reserved by this function, pass the |__space| 192 * and |__start| of the old reservation with a 0 |__length|. 193 */ 194 int crosvm_reserve_range(struct crosvm*, uint32_t __space, uint64_t __start, 195 uint64_t __length); 196 197 /* 198 * Registers a range in the given address space that, when accessed via write, 199 * will cause a notification in crosvm_vcpu_wait() but the VM will continue 200 * running. 201 * For this type of notification (where |no_resume| is set) the next call 202 * should be crosvm_vcpu_wait() (without an inbetween call to 203 * crosvm_vcpu_resume() ). 204 * 205 * The requested range must not overlap any prior (and currently active) 206 * reservation to crosvm_reserve_range() or crosvm_reserve_async_write_range(). 207 * 208 * To unreserve a range previously reserved by this function, pass the |__space| 209 * and |__start| of the old reservation with a 0 |__length|. 210 */ 211 int crosvm_reserve_async_write_range(struct crosvm*, uint32_t __space, 212 uint64_t __start, uint64_t __length); 213 214 /* 215 * Sets the state of the given irq pin. 216 */ 217 int crosvm_set_irq(struct crosvm*, uint32_t __irq_id, bool __active); 218 219 enum crosvm_irq_route_kind { 220 /* IRQ pin to GSI route */ 221 CROSVM_IRQ_ROUTE_IRQCHIP = 0, 222 /* MSI address and data to GSI route */ 223 CROSVM_IRQ_ROUTE_MSI, 224 }; 225 226 /* One entry in the array of irq routing table */ 227 struct crosvm_irq_route { 228 /* The IRQ number to trigger. */ 229 uint32_t irq_id; 230 /* A `crosvm_irq_route_kind` indicating which union member to use */ 231 uint32_t kind; 232 union { 233 struct { 234 /* 235 * One of KVM_IRQCHIP_PIC_MASTER, KVM_IRQCHIP_PIC_SLAVE, or 236 * KVM_IRQCHIP_IOAPIC indicating which irqchip the indicated pin is on. 237 */ 238 uint32_t irqchip; 239 /* The pin on the irqchip used to trigger the IRQ. */ 240 uint32_t pin; 241 } irqchip; 242 243 struct { 244 /* Address that triggers the irq. */ 245 uint64_t address; 246 /* Data written to `address` that triggers the irq */ 247 uint32_t data; 248 249 uint8_t _reserved[4]; 250 } msi; 251 252 uint8_t _reserved[16]; 253 }; 254 }; 255 256 #ifdef static_assert 257 static_assert(sizeof(struct crosvm_irq_route) == 24, 258 "extra padding in struct crosvm_irq_route"); 259 #endif 260 261 /* 262 * Sets all the gsi routing entries to those indicated by `routes`. 263 * 264 * To remove all routing entries, pass NULL for `routes` and 0 to route_count. 265 */ 266 int crosvm_set_irq_routing(struct crosvm*, uint32_t __route_count, 267 const struct crosvm_irq_route* __routes); 268 269 /* Hint on what information is queried for a particular hypercall. */ 270 struct crosvm_hint_detail { 271 bool match_rax; 272 bool match_rbx; 273 bool match_rcx; 274 bool match_rdx; 275 uint8_t _reserved[4]; 276 uint64_t rax; 277 uint64_t rbx; 278 uint64_t rcx; 279 uint64_t rdx; 280 bool send_sregs; 281 bool send_debugregs; 282 uint8_t _reserved2[6]; 283 }; 284 285 #ifdef static_assert 286 static_assert(sizeof(struct crosvm_hint_detail) == 48, 287 "extra padding in struct crosvm_hint_detail"); 288 #endif 289 290 /* Maximum # of hints that can be passed to crosvm_set_hypercall_hint(). */ 291 #define CROSVM_MAX_HINT_COUNT 1 292 293 /* Maximum # of hint details that can be provided for a hint. */ 294 #define CROSVM_MAX_HINT_DETAIL_COUNT 32 295 296 #define CROSVM_HINT_ON_WRITE 0x1 297 298 /* Hint on what information is queried for a particular hypercall. */ 299 struct crosvm_hint { 300 uint32_t hint_version; /* For now only 0 is defined. */ 301 uint32_t _reserved; /* Must be zero. */ 302 uint32_t address_space; /* Value from crosvm_address_space. */ 303 uint16_t address_flags; /* 0: read/in; CROSVM_HINT_ON_WRITE: write/out. */ 304 uint16_t details_count; /* # of elements in |details|. */ 305 uint64_t address; 306 union { 307 struct crosvm_hint_detail *details; 308 uint64_t _reserved2; /* forcing pointer length to 64-bit */ 309 }; 310 }; 311 312 #ifdef static_assert 313 static_assert(sizeof(struct crosvm_hint) == 32, 314 "extra padding in struct crosvm_hint"); 315 #endif 316 317 /* 318 * Sets performance hint(s) for a hypercall port. 319 * 320 * If a VM does an io access the specified |address_space|, |address| 321 * (|address| must be non-zero), and direction (|address_flags|), then 322 * crosvm will assume the plugin is likely to call crosvm_vcpu_get_regs() 323 * (and thus utilize a cache to improve performance). 324 * 325 * Additional hints can be provided via |details| (the element length of 326 * |details| is limited to CROSVM_MAX_HINT_DETAIL_COUNT) on when to also cache 327 * information for crosvm_vcpu_get_sregs() and crosvm_vcpu_get_debugregs() 328 * based on values in the vcpu registers. |match_XXX| indicates which of 329 * 1 or more of |XXX| needs to be equal to the vcpu registers to be a match. 330 * On a match |send_sregs| and |send_debugregs| are used to determine what 331 * data to proactively cache for the plugin's use. Once a match is found 332 * the remaining hints are not consulted. 333 * 334 * To remove all hints, pass 0 for |__hint_count|. The value of 335 * |__hint_count| can be at most CROSVM_MAX_HINT_COUNT. Currently the API 336 * is limited to 1 hint (i.e., |__hint_count| must be 0 or 1). Each call 337 * to this API will replace the values specified by any prior call to this API. 338 */ 339 int crosvm_set_hypercall_hint(struct crosvm *, uint32_t __hints_count, 340 const struct crosvm_hint* __hints); 341 342 /* Gets the state of interrupt controller in a VM. */ 343 int crosvm_get_pic_state(struct crosvm *, bool __primary, 344 struct kvm_pic_state *__pic_state); 345 346 /* Sets the state of interrupt controller in a VM. */ 347 int crosvm_set_pic_state(struct crosvm *, bool __primary, 348 const struct kvm_pic_state *__pic_state); 349 350 /* Gets the state of IOAPIC in a VM. */ 351 int crosvm_get_ioapic_state(struct crosvm *, 352 struct kvm_ioapic_state *__ioapic_state); 353 354 /* Sets the state of IOAPIC in a VM. */ 355 int crosvm_set_ioapic_state(struct crosvm *, 356 const struct kvm_ioapic_state *__ioapic_state); 357 358 /* Gets the state of interrupt controller in a VM. */ 359 int crosvm_get_pit_state(struct crosvm *, struct kvm_pit_state2 *__pit_state); 360 361 /* Sets the state of interrupt controller in a VM. */ 362 int crosvm_set_pit_state(struct crosvm *, 363 const struct kvm_pit_state2 *__pit_state); 364 365 /* Gets the current timestamp of kvmclock as seen by the VM. */ 366 int crosvm_get_clock(struct crosvm *, struct kvm_clock_data *__clock_data); 367 368 /* Sets the current timestamp of kvmclock for the VM. */ 369 int crosvm_set_clock(struct crosvm *, 370 const struct kvm_clock_data *__clock_data); 371 372 /* Sets the identity map address as in the KVM_SET_IDENTITY_MAP_ADDR ioctl. */ 373 int crosvm_set_identity_map_addr(struct crosvm*, uint32_t __addr); 374 375 /* 376 * Triggers a CROSVM_VCPU_EVENT_KIND_PAUSED event on each vcpu identified 377 * |__cpu_mask|. 378 * 379 * The `user` pointer will be given as the `user` pointer in the `struct 380 * crosvm_vcpu_event` returned by crosvm_vcpu_wait. 381 */ 382 int crosvm_pause_vcpus(struct crosvm*, uint64_t __cpu_mask, void* __user); 383 384 /* 385 * Call once initialization is done. This indicates that crosvm should proceed 386 * with running the VM. 387 * 388 * After this call, this function is no longer valid to call. 389 */ 390 int crosvm_start(struct crosvm*); 391 392 /* 393 * Allocates an eventfd that is triggered asynchronously on write in |__space| 394 * at the given |__addr|. 395 * 396 * If |__datamatch| is non-NULL, it must be contain |__length| bytes that will 397 * be compared to the bytes being written by the vcpu which will only trigger 398 * the eventfd if equal. If datamatch is NULL all writes to the address will 399 * trigger the eventfd. 400 * 401 * On successful allocation, returns a crosvm_io. Obtain the actual fd 402 * by passing this result to crosvm_io_event_fd(). 403 */ 404 int crosvm_create_io_event(struct crosvm*, uint32_t __space, uint64_t __addr, 405 uint32_t __len, const uint8_t* __datamatch, 406 struct crosvm_io**); 407 408 /* 409 * Destroys the given io event and unregisters it from the VM. 410 */ 411 int crosvm_destroy_io_event(struct crosvm*, struct crosvm_io**); 412 413 /* 414 * Gets the eventfd triggered by the given io event. 415 * 416 * The returned fd is owned by the given `struct crosvm_io` and has a lifetime 417 * equal to that handle. 418 */ 419 int crosvm_io_event_fd(struct crosvm_io*); 420 421 /* 422 * Creates a shared memory segment backed by a memfd. 423 * 424 * Inserts non-overlapping memory pages in the guest physical address range 425 * specified by |__start| address and |__length| bytes. The memory pages are 426 * backed by the memfd |__fd| and are taken starting at |__offset| bytes from 427 * the beginning of the memfd. 428 * 429 * The `memfd_create` syscall |__fd| must be used to create |__fd| and a shrink 430 * seal must have been added to |__fd|. The memfd must be at least 431 * `__length+__offset` bytes long. 432 * 433 * If |read_only| is true, attempts by the guest to write to this memory region 434 * will trigger an IO access exit. 435 * 436 * To use the `crosvm_memory_get_dirty_log` method with the returned object, 437 * |__dirty_log| must be true. 438 */ 439 int crosvm_create_memory(struct crosvm*, int __fd, uint64_t __offset, 440 uint64_t __length, uint64_t __start, 441 bool __read_only, bool __dirty_log, 442 struct crosvm_memory**); 443 444 /* 445 * Destroys the given shared memory and unregisters it from guest physical 446 * address space. 447 */ 448 int crosvm_destroy_memory(struct crosvm*, struct crosvm_memory**); 449 450 /* 451 * For a given memory region returns a bitmap containing any pages 452 * dirtied since the last call to this function. 453 * 454 * The `log` array must have as many bits as the memory segment has pages. 455 */ 456 int crosvm_memory_get_dirty_log(struct crosvm*, struct crosvm_memory*, 457 uint8_t* __log); 458 459 /* 460 * Creates an irq eventfd that can be used to trigger an irq asynchronously. 461 * 462 * The irq that will be triggered is identified as pin |__irq_id|. 463 */ 464 int crosvm_create_irq_event(struct crosvm*, uint32_t __irq_id, 465 struct crosvm_irq**); 466 467 /* 468 * Unregisters and destroys an irq eventfd. 469 */ 470 int crosvm_destroy_irq_event(struct crosvm*, struct crosvm_irq**); 471 472 /* 473 * Gets the eventfd used to trigger the irq 474 * 475 * The returned fd is owned by the given `struct crosvm_irq` and has a lifetime 476 * equal to that handle. 477 */ 478 int crosvm_irq_event_get_fd(const struct crosvm_irq*); 479 480 /* 481 * Gets the resample eventfd associated with the crosvm_irq object. 482 */ 483 int crosvm_irq_event_get_resample_fd(const struct crosvm_irq*); 484 485 enum crosvm_vcpu_event_kind { 486 /* 487 * The first event returned by crosvm_vcpu_wait, indicating the VCPU has been 488 * created but not yet started for the first time. 489 */ 490 CROSVM_VCPU_EVENT_KIND_INIT = 0, 491 492 /* 493 * Access to an address in a space previously reserved by 494 * crosvm_reserve_range. 495 */ 496 CROSVM_VCPU_EVENT_KIND_IO_ACCESS, 497 498 /* 499 * A pause on this vcpu (and possibly others) was requested by this plugin in 500 * a `crosvm_pause_vcpus` call. 501 */ 502 CROSVM_VCPU_EVENT_KIND_PAUSED, 503 504 /* 505 * Hyper-V hypercall. 506 */ 507 CROSVM_VCPU_EVENT_KIND_HYPERV_HCALL, 508 509 /* 510 * Hyper-V synic change. 511 */ 512 CROSVM_VCPU_EVENT_KIND_HYPERV_SYNIC, 513 }; 514 515 struct crosvm_vcpu_event { 516 /* Indicates the kind of event and which union member is valid. */ 517 uint32_t kind; 518 519 uint8_t _padding[4]; 520 521 union { 522 /* CROSVM_VCPU_EVENT_KIND_IO_ACCESS */ 523 struct { 524 /* 525 * One of `enum crosvm_address_space` indicating which address space the 526 * access occurred in. 527 */ 528 uint32_t address_space; 529 530 uint8_t _padding[4]; 531 532 /* The address that the access occurred at. */ 533 uint64_t address; 534 535 /* 536 * In the case that `is_write` is true, the first `length` bytes are the 537 * data being written by the vcpu. 538 */ 539 uint8_t *data; 540 541 /* 542 * Number of bytes in the access. In the case that the access is larger 543 * than 8 bytes, such as by AVX-512 instructions, multiple vcpu access 544 * events are generated serially to cover each 8 byte fragment of the 545 * access. 546 * 547 * Larger I/O accesses are possible. "rep in" can generate I/Os larger 548 * than 8 bytes, though such accesses can also be split into multiple 549 * events. Currently kvm doesn't seem to batch "rep out" I/Os. 550 */ 551 uint32_t length; 552 553 /* 554 * True if the vcpu was attempting to write, false in case of an attempt 555 * to read. 556 */ 557 uint8_t is_write; 558 559 /* 560 * Valid when |is_write| is true -- indicates that VM has continued 561 * to run. The only next valid call for the vcpu is crosvm_vcpu_wait(). 562 */ 563 uint8_t no_resume; 564 565 uint8_t _reserved[2]; 566 } io_access; 567 568 /* CROSVM_VCPU_EVENT_KIND_PAUSED */ 569 void *user; 570 571 /* CROSVM_VCPU_EVENT_KIND_HYPERV_HCALL */ 572 struct { 573 /* 574 * The |input| and |params| members are populated for the plugin to use. 575 * The |result| member is populated by the API to point to a uint64_t 576 * that the plugin should update before resuming. 577 */ 578 uint64_t input; 579 uint64_t *result; 580 uint64_t params[2]; 581 } hyperv_call; 582 583 /* CROSVM_VCPU_EVENT_KIND_HYPERV_SYNIC */ 584 struct { 585 /* 586 * The |msr|, |control|, |evt_page|, and |msg_page| fields are populated 587 * for the plugin to use. 588 */ 589 uint32_t msr; 590 uint32_t _reserved; 591 uint64_t control; 592 uint64_t evt_page; 593 uint64_t msg_page; 594 } hyperv_synic; 595 596 uint8_t _reserved[64]; 597 }; 598 }; 599 600 #ifdef static_assert 601 static_assert(sizeof(struct crosvm_vcpu_event) == 72, 602 "extra padding in struct crosvm_vcpu_event"); 603 #endif 604 605 /* 606 * Gets the vcpu object for the given |__cpu_id|. 607 * 608 * 609 * The `struct crosvm_vcpu` is owned by `struct crosvm`. Each call with the same 610 * `crosvm` and |__cpu_id| will yield the same pointer. The `crosvm_vcpu` does 611 * not need to be destroyed or created explicitly. 612 * 613 * The range of valid |__cpu_id|s is 0 to the number of vcpus - 1. To get every 614 * `crosvm_vcpu`, simply call this function iteratively with increasing 615 * |__cpu_id| until `-ENOENT` is returned. 616 * 617 */ 618 int crosvm_get_vcpu(struct crosvm*, uint32_t __cpu_id, struct crosvm_vcpu**); 619 620 /* 621 * Blocks until a vcpu event happens that requires a response. 622 * 623 * When crosvm_vcpu_wait returns successfully, the event structure is filled 624 * with the description of the event that occurred. The vcpu will suspend 625 * execution until a matching call to `crosvm_vcpu_resume` is made. Until such a 626 * call is made, the vcpu's run structure can be read and written using any 627 * `crosvm_vcpu_get` or `crosvm_vcpu_set` function. 628 */ 629 int crosvm_vcpu_wait(struct crosvm_vcpu*, struct crosvm_vcpu_event*); 630 631 /* 632 * Resumes execution of a vcpu after a call to `crosvm_vcpu_wait` returns. 633 * 634 * In the case that the event was a read operation, `data` indicates what the 635 * result of that read operation should be. If the read operation was larger 636 * than 8 bytes, such as by AVX-512 instructions, this will not actually resume 637 * the vcpu, but instead generate another vcpu access event of the next fragment 638 * of the read, which can be handled by the next `crosvm_vcpu_wait` call. 639 * 640 * Once the vcpu event has been responded to sufficiently enough to resume 641 * execution, `crosvm_vcpu_resume` should be called. After `crosvm_vcpu_resume` 642 * is called, none of the vcpu state operations are valid until the next time 643 * `crosvm_vcpu_wait` returns. 644 */ 645 int crosvm_vcpu_resume(struct crosvm_vcpu*); 646 647 /* Gets the state of the vcpu's registers. */ 648 int crosvm_vcpu_get_regs(struct crosvm_vcpu*, struct kvm_regs*); 649 /* Sets the state of the vcpu's registers. */ 650 int crosvm_vcpu_set_regs(struct crosvm_vcpu*, const struct kvm_regs*); 651 652 /* Gets the state of the vcpu's special registers. */ 653 int crosvm_vcpu_get_sregs(struct crosvm_vcpu*, struct kvm_sregs*); 654 /* Sets the state of the vcpu's special registers. */ 655 int crosvm_vcpu_set_sregs(struct crosvm_vcpu*, const struct kvm_sregs*); 656 657 /* Gets the state of the vcpu's floating point unint. */ 658 int crosvm_vcpu_get_fpu(struct crosvm_vcpu*, struct kvm_fpu*); 659 /* Sets the state of the vcpu's floating point unint. */ 660 int crosvm_vcpu_set_fpu(struct crosvm_vcpu*, const struct kvm_fpu*); 661 662 /* Gets the state of the vcpu's debug registers. */ 663 int crosvm_vcpu_get_debugregs(struct crosvm_vcpu*, struct kvm_debugregs*); 664 /* Sets the state of the vcpu's debug registers */ 665 int crosvm_vcpu_set_debugregs(struct crosvm_vcpu*, const struct kvm_debugregs*); 666 667 /* Gets the state of the vcpu's xcr registers. */ 668 int crosvm_vcpu_get_xcrs(struct crosvm_vcpu*, struct kvm_xcrs*); 669 /* Sets the state of the vcpu's xcr registers. */ 670 int crosvm_vcpu_set_xcrs(struct crosvm_vcpu*, const struct kvm_xcrs*); 671 672 /* Gets the MSRs of the vcpu indicated by the index field of each entry. */ 673 int crosvm_vcpu_get_msrs(struct crosvm_vcpu*, uint32_t __msr_count, 674 struct kvm_msr_entry *__msr_entries, 675 uint32_t *__out_count); 676 /* Sets the MSRs of the vcpu indicated by the index field of each entry. */ 677 int crosvm_vcpu_set_msrs(struct crosvm_vcpu*, uint32_t __msr_count, 678 const struct kvm_msr_entry *__msr_entries); 679 680 /* Sets the responses to the cpuid instructions executed on this vcpu, */ 681 int crosvm_vcpu_set_cpuid(struct crosvm_vcpu*, uint32_t __cpuid_count, 682 const struct kvm_cpuid_entry2 *__cpuid_entries); 683 684 /* 685 * Enable an extended capability for a vcpu. Currently |__flags| and 686 * |__args| must be zero. The only permitted values for |__capability| 687 * are KVM_CAP_HYPERV_SYNIC or KVM_CAP_HYPERV_SYNIC2, though the latter 688 * also depends on kernel support. 689 */ 690 int crosvm_vcpu_enable_capability(struct crosvm_vcpu*, uint32_t __capability, 691 uint32_t __flags, uint64_t __args[4]); 692 693 /* Gets state of LAPIC of the VCPU. */ 694 int crosvm_vcpu_get_lapic_state(struct crosvm_vcpu *, 695 struct kvm_lapic_state *__lapic_state); 696 /* Sets state of LAPIC of the VCPU. */ 697 int crosvm_vcpu_set_lapic_state(struct crosvm_vcpu *, 698 const struct kvm_lapic_state *__lapic_state); 699 700 /* Gets the "multiprocessor state" of given VCPU. */ 701 int crosvm_vcpu_get_mp_state(struct crosvm_vcpu *, 702 struct kvm_mp_state *__mp_state); 703 /* Sets the "multiprocessor state" of given VCPU. */ 704 int crosvm_vcpu_set_mp_state(struct crosvm_vcpu *, 705 const struct kvm_mp_state *__mp_state); 706 707 /* Gets currently pending exceptions, interrupts, NMIs, etc for VCPU. */ 708 int crosvm_vcpu_get_vcpu_events(struct crosvm_vcpu *, 709 struct kvm_vcpu_events *); 710 711 /* Sets currently pending exceptions, interrupts, NMIs, etc for VCPU. */ 712 int crosvm_vcpu_set_vcpu_events(struct crosvm_vcpu *, 713 const struct kvm_vcpu_events *); 714 715 #ifdef __cplusplus 716 } 717 #endif 718 719 #endif 720