| 416 | } |
| 417 | |
| 418 | int |
| 419 | vmcb_getdesc(void *arg, int vcpu, int reg, struct seg_desc *desc) |
| 420 | { |
| 421 | struct vmcb *vmcb; |
| 422 | struct svm_softc *sc; |
| 423 | struct vmcb_segment *seg; |
| 424 | |
| 425 | sc = arg; |
| 426 | vmcb = svm_get_vmcb(sc, vcpu); |
| 427 | seg = vmcb_segptr(vmcb, reg); |
| 428 | KASSERT(seg != NULL, ("%s: invalid segment descriptor %d", |
| 429 | __func__, reg)); |
| 430 | |
| 431 | desc->base = seg->base; |
| 432 | desc->limit = seg->limit; |
| 433 | desc->access = 0; |
| 434 | |
| 435 | if (reg != VM_REG_GUEST_GDTR && reg != VM_REG_GUEST_IDTR) { |
| 436 | /* Map seg_desc access to VMCB attribute format */ |
| 437 | desc->access = ((seg->attrib & 0xF00) << 4) | |
| 438 | (seg->attrib & 0xFF); |
| 439 | |
| 440 | /* |
| 441 | * VT-x uses bit 16 to indicate a segment that has been loaded |
| 442 | * with a NULL selector (aka unusable). The 'desc->access' |
| 443 | * field is interpreted in the VT-x format by the |
| 444 | * processor-independent code. |
| 445 | * |
| 446 | * SVM uses the 'P' bit to convey the same information so |
| 447 | * convert it into the VT-x format. For more details refer to |
| 448 | * section "Segment State in the VMCB" in APMv2. |
| 449 | */ |
| 450 | if (reg != VM_REG_GUEST_CS && reg != VM_REG_GUEST_TR) { |
| 451 | if ((desc->access & 0x80) == 0) |
| 452 | desc->access |= 0x10000; /* Unusable segment */ |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | return (0); |
| 457 | } |
| 458 | |
| 459 | #ifdef BHYVE_SNAPSHOT |
| 460 | int |
no test coverage detected