mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-23 16:31:16 +00:00
fuzz: block: Rely on custom EpollHelper::run and VirtioCommon:reset
This commit also extends the copyright header. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
a9924df2b8
commit
6cb214f15c
@ -1,6 +1,10 @@
|
|||||||
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
//
|
||||||
|
// Copyright © 2022 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
@ -16,7 +20,6 @@ use std::sync::Arc;
|
|||||||
use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
|
use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
|
||||||
use virtio_queue::{Queue, QueueT};
|
use virtio_queue::{Queue, QueueT};
|
||||||
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
|
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
|
||||||
use vmm::{EpollContext, EpollDispatch};
|
|
||||||
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
|
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
|
||||||
|
|
||||||
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
|
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
|
||||||
@ -61,6 +64,9 @@ fuzz_target!(|bytes| {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Kick the 'queue' event before activate the block device
|
||||||
|
queue_evt.write(1).unwrap();
|
||||||
|
|
||||||
block
|
block
|
||||||
.activate(
|
.activate(
|
||||||
guest_memory,
|
guest_memory,
|
||||||
@ -69,11 +75,8 @@ fuzz_target!(|bytes| {
|
|||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
queue_evt.write(77).unwrap(); // Rings the doorbell, any byte will do.
|
// Wait for the events to finish and block device worker thread to return
|
||||||
|
block.reset();
|
||||||
wait_queue_event_processed(queue_evt);
|
|
||||||
|
|
||||||
block.reset(); // Ensure the virtio-block device thread is killed and joined
|
|
||||||
});
|
});
|
||||||
|
|
||||||
fn memfd_create(name: &ffi::CStr, flags: u32) -> Result<RawFd, io::Error> {
|
fn memfd_create(name: &ffi::CStr, flags: u32) -> Result<RawFd, io::Error> {
|
||||||
@ -93,29 +96,3 @@ impl VirtioInterrupt for NoopVirtioInterrupt {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_queue_event_processed(queue_evt: EventFd) {
|
|
||||||
let mut epoll = EpollContext::new().unwrap();
|
|
||||||
epoll.add_event(&queue_evt, EpollDispatch::Api).unwrap();
|
|
||||||
|
|
||||||
let epoll_fd = epoll.as_raw_fd();
|
|
||||||
let mut events = vec![epoll::Event::new(epoll::Events::empty(), 0); 1];
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let num_events = match epoll::wait(epoll_fd, 0, &mut events[..]) {
|
|
||||||
Ok(res) => res,
|
|
||||||
Err(e) => {
|
|
||||||
if e.kind() == io::ErrorKind::Interrupted {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Warning: Unexpected epoll::wait() error!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if num_events == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user