Skip to content
Snippets Groups Projects
Commit 08e21679 authored by Florent Gluck's avatar Florent Gluck
Browse files

Small change to clarify how to inject values into the guest

parent 36861eae
No related branches found
No related tags found
No related merge requests found
......@@ -737,8 +737,8 @@ How does VMM retrieve an hypercall's parameters?
## KVM_EXIT_IO: retrieving data written by the guest
\footnotesize
- Guest wrote a value (8, 16, or 32 bits) to a PMIO address (I/O port)
- VMM retrieves: value, address, size written (8, 16, 32 bits)
- Guest wrote a value (8, 16, 32, 64 bits) to a PMIO address (I/O port)
- VMM retrieves: value, address, size written (8, 16, 32, 64 bits)
```{.c .tiny}
if (run->io.direction == KVM_EXIT_IO_OUT) { // See struct kvm_run in "(6) Create a vCPU"
......@@ -766,8 +766,8 @@ if (run->io.direction == KVM_EXIT_IO_OUT) { // See struct kvm_run in "(6) Creat
## KVM_EXIT_MMIO: retrieving data written by the guest
\footnotesize
- Guest wrote a value (8, 16, or 32 bits) to a MMIO address
- VMM retrieves: value, address, size written (8, 16, 32 bits)
- Guest wrote a value (8, 16, 32, 64 bits) to a MMIO address
- VMM retrieves: value, address, size written (8, 16, 32, 64 bits)
```{.c .tiny}
if (run->mmio.is_write) { // See struct kvm_run in "(6) Create a vCPU"
......@@ -798,8 +798,8 @@ if (run->mmio.is_write) { // See struct kvm_run in "(6) Create a vCPU"
## KVM_EXIT_IO: injecting data into the guest
\footnotesize
- Guest read a value (8, 16, or 32 bits) from a PMIO address (I/O port)
- VMM retrieves: address, size read (8, 16, 32 bits)
- Guest read a value (8, 16, 32, 64 bits) from a PMIO address (I/O port)
- VMM retrieves: address, size read (8, 16, 32, 64 bits)
- VMM injects a specific value (the one read by the guest)
```{.c .tiny}
......@@ -807,18 +807,18 @@ if (run->io.direction == KVM_EXIT_IO_IN) { // See struct kvm_run
uint8_t *addr = (uint8_t *)run + run->io.data_offset;
switch (run->io.size) {
case 1: { // Guest is reading 8 bits from the port
*addr = 0x12; // 8-bit example value injected into the guest
*addr = 42; // 8-bit example value injected into the guest
} break;
case 2: { // Guest is reading 16 bits from the port
*((uint16_t *)addr) = 0x1234; // 16-bit example value injected into the guest
*((uint16_t *)addr) = 42; // 16-bit example value injected into the guest
} break;
case 4: { // Guest is reading 32 bits from the port
*((uint32_t *)addr) = 0x12345678; // 32-bit example value injected into the guest
*((uint32_t *)addr) = 42; // 32-bit example value injected into the guest
} break;
default:
fprintf(stderr, "Unsupported size in KVM_EXIT_IO\n");
}
printf("PMIO guest read: size=%d port=0x%x [value injected by VMM=0x%x]\n", run->io.size, run->io.port, injected_val);
printf("PMIO guest read: port=0x%x size=%d [value injected by VMM=%d]\n", run->io.port, run->io.size, 42);
}
```
......@@ -826,8 +826,8 @@ if (run->io.direction == KVM_EXIT_IO_IN) { // See struct kvm_run
## KVM_EXIT_MMIO: injecting data into the guest
\footnotesize
- Guest read a value (8, 16, or 32 bits) from a MMIO address
- VMM retrieves: address, size read (8, 16, 32 bits)
- Guest read a value (8, 16, 32, 64 bits) from a MMIO address
- VMM retrieves: address, size read (8, 16, 32, 64 bits)
- VMM injects a specific value (the one read by the guest)
```{.c .tiny}
......@@ -836,20 +836,20 @@ if (!run->mmio.is_write) { // See struct kvm_run
switch (bytes_read) {
case 1: { // Guest is reading 8 bits
uint8_t *addr = (uint8_t *)run->mmio.data;
*addr = 0x12; // 8-bit example value injected into the guest
*addr = 42; // 8-bit example value injected into the guest
} break;
case 2: { // Guest is reading 16 bits
uint16_t *addr = (uint16_t *)run->mmio.data;
*addr = 0x1234; // 16-bit example value injected into the guest
*addr = 42; // 16-bit example value injected into the guest
} break;
case 4: { // Guest is reading 32 bits
uint32_t *addr = (uint32_t *)run->mmio.data;
*addr = 0x12345678; // 32-bit example value injected into the guest
*addr = 42; // 32-bit example value injected into the guest
} break;
default:
fprintf(stderr, "Unsupported size in KVM_EXIT_MMIO\n");
}
fprintf(stderr, "MMIO guest read: addr=0x%llx injected=0x%x len=%d\n", run->mmio.phys_addr, injected_val, bytes_read);
printf("MMIO guest read: addr=0x%x size=%d [value injected by VMM=%d]\n", run->mmio.phys_addr, bytes_read, 42);
}
```
......@@ -942,7 +942,7 @@ outb(0x3C5, 0x0F);
- the operation to perform
- the address written to/read from
- the expected written value or value to inject
- the size of the operation (8, 16, or 32 bits)
- the size of the operation (8, 16, 32, 64 bits)
- possibly a custom user function that would be executed at the beginning or end of the state
[//]: # ----------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment