Skip to content

Commit cbd6302

Browse files
crab2313andreeaflorescu
authored andcommitted
vcpu: expose type and flags on KVM_EXIT_SYSTEM_EVENT
Signed-off-by: Qiu Wenbo <[email protected]>
1 parent b968736 commit cbd6302

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

coverage_config_aarch64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 76.5,
2+
"coverage_score": 77.2,
33
"exclude_path": "",
44
"crate_features": ""
55
}

coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 92.0,
2+
"coverage_score": 91.3,
33
"exclude_path": "",
44
"crate_features": ""
55
}

src/ioctls/vcpu.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub enum VcpuExit<'a> {
8585
/// Corresponds to KVM_EXIT_EPR.
8686
Epr,
8787
/// Corresponds to KVM_EXIT_SYSTEM_EVENT.
88-
SystemEvent,
88+
SystemEvent(u32 /* type */, u64 /* flags */),
8989
/// Corresponds to KVM_EXIT_S390_STSI.
9090
S390Stsi,
9191
/// Corresponds to KVM_EXIT_IOAPIC_EOI.
@@ -1150,7 +1150,15 @@ impl VcpuFd {
11501150
KVM_EXIT_WATCHDOG => Ok(VcpuExit::Watchdog),
11511151
KVM_EXIT_S390_TSCH => Ok(VcpuExit::S390Tsch),
11521152
KVM_EXIT_EPR => Ok(VcpuExit::Epr),
1153-
KVM_EXIT_SYSTEM_EVENT => Ok(VcpuExit::SystemEvent),
1153+
KVM_EXIT_SYSTEM_EVENT => {
1154+
// Safe because the exit_reason (which comes from the kernel) told us which
1155+
// union field to use.
1156+
let system_event = unsafe { &mut run.__bindgen_anon_1.system_event };
1157+
Ok(VcpuExit::SystemEvent(
1158+
system_event.type_,
1159+
system_event.flags,
1160+
))
1161+
}
11541162
KVM_EXIT_S390_STSI => Ok(VcpuExit::S390Stsi),
11551163
KVM_EXIT_IOAPIC_EOI => {
11561164
// Safe because the exit_reason (which comes from the kernel) told us which
@@ -1445,6 +1453,9 @@ mod tests {
14451453
0x1f, 0x18, 0x14, 0x71, /* cmp w0, #0x506 */
14461454
0x20, 0x00, 0x82, 0x1a, /* csel w0, w1, w2, eq */
14471455
0x20, 0x01, 0x00, 0xb9, /* str w0, [x9]; test MMIO write */
1456+
0x00, 0x80, 0xb0, 0x52, /* mov w0, #0x84000000 */
1457+
0x00, 0x00, 0x1d, 0x32, /* orr w0, w0, #0x08 */
1458+
0x02, 0x00, 0x00, 0xd4, /* hvc #0x0 */
14481459
0x00, 0x00, 0x00, 0x14, /* b <this address>; shouldn't get here, but if so loop forever */
14491460
];
14501461

@@ -1473,6 +1484,7 @@ mod tests {
14731484
let vcpu_fd = vm.create_vcpu(0).unwrap();
14741485
let mut kvi = kvm_bindings::kvm_vcpu_init::default();
14751486
vm.get_preferred_target(&mut kvi).unwrap();
1487+
kvi.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
14761488
vcpu_fd.vcpu_init(&kvi).unwrap();
14771489

14781490
let core_reg_base: u64 = 0x6030_0000_0010_0000;
@@ -1516,6 +1528,10 @@ mod tests {
15161528
.map(|page| page.count_ones())
15171529
.fold(0, |dirty_page_count, i| dirty_page_count + i);
15181530
assert_eq!(dirty_pages, 1);
1531+
}
1532+
VcpuExit::SystemEvent(type_, flags) => {
1533+
assert_eq!(type_, KVM_SYSTEM_EVENT_SHUTDOWN);
1534+
assert_eq!(flags, 0);
15191535
break;
15201536
}
15211537
r => panic!("unexpected exit reason: {:?}", r),

0 commit comments

Comments
 (0)