1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:37:35 +00:00

Kernel/VirtIO: Defer initialization of device out of the constructor

This ensures we safely handle interrupts (which can call virtual
functions), so they don't happen in the constructor - this pattern can
lead to a crash, if we are still in the constructor context because
not all methods are available for usage (some are pure virtual,
so it's possible to call __cxa_pure_virtual).

Also, under some conditions like adding a PCI device via PCI-passthrough
mechanism in QEMU, it became exposed to the eye that the code asserts on
RNG::handle_device_config_change(). That device has no configuration but
if the hypervisor still misbehaves and tries to configure it, we should
simply return false to indicate nothing happened.
This commit is contained in:
Liav A 2021-09-04 08:42:31 +03:00 committed by Andreas Kling
parent e490c17bde
commit ed6c1f53af
9 changed files with 47 additions and 17 deletions

View file

@ -15,10 +15,9 @@
namespace Kernel::Graphics::VirtIOGPU {
GPU::GPU(PCI::Address address)
: VirtIO::Device(address)
, m_scratch_space(MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Memory::Region::Access::ReadWrite))
void GPU::initialize()
{
Device::initialize();
VERIFY(!!m_scratch_space);
if (auto cfg = get_config(VirtIO::ConfigurationType::Device)) {
m_device_configuration = cfg;
@ -47,6 +46,12 @@ GPU::GPU(PCI::Address address)
}
}
GPU::GPU(PCI::Address address)
: VirtIO::Device(address)
, m_scratch_space(MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Memory::Region::Access::ReadWrite))
{
}
GPU::~GPU()
{
}

View file

@ -57,6 +57,8 @@ public:
return IterationDecision::Continue;
}
virtual void initialize() override;
RefPtr<Console> default_console()
{
if (m_default_scanout.has_value())

View file

@ -22,6 +22,7 @@ GraphicsAdapter::GraphicsAdapter(PCI::Address base_address)
: PCI::Device(base_address)
{
m_gpu_device = adopt_ref(*new GPU(base_address)).leak_ref();
m_gpu_device->initialize();
}
void GraphicsAdapter::initialize_framebuffer_devices()