Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
advanced_virtualization_pub_soir_fall24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_courses
advanced_virtualization
advanced_virtualization_pub_soir_fall24
Commits
08e21679
Commit
08e21679
authored
5 months ago
by
Florent Gluck
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
course/02-KVM.md
+17
-17
17 additions, 17 deletions
course/02-KVM.md
with
17 additions
and
17 deletions
course/02-KVM.md
+
17
−
17
View file @
08e21679
...
...
@@ -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 =
0x1
2; // 8-bit example value injected into the guest
*
addr =
4
2; // 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 =
0x1
2; // 8-bit example value injected into the guest
*
addr =
4
2; // 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
");
}
f
printf(
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
[//]: # ----------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment