Skip to content

Commit

Permalink
Kernel/VirtIO: Determine names without PCI access in IRQ context
Browse files Browse the repository at this point in the history
This is a fix so the VirtIO code doesn't lead to assertion because we
try to determine the name based on the PCI values of the VirtIO device,
because trying to read from the PCI configuration space requires to
acquire a Mutex, which fails in an IRQ context.

To ensure we never encounter a situation when we call a pure virtual
function in an IRQ context, let's make class_name() method to be a
non-pure virtual function, so it can be still called at anytime.
  • Loading branch information
supercomputer7 authored and awesomekling committed Sep 8, 2021
1 parent ac798da commit 666c0c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Kernel/Bus/VirtIO/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,25 +396,25 @@ bool Device::handle_irq(const RegisterState&)
{
u8 isr_type = isr_status();
if ((isr_type & (QUEUE_INTERRUPT | DEVICE_CONFIG_INTERRUPT)) == 0) {
dbgln_if(VIRTIO_DEBUG, "{}: Handling interrupt with unknown type: {}", VirtIO::determine_device_class(pci_address()), isr_type);
dbgln_if(VIRTIO_DEBUG, "{}: Handling interrupt with unknown type: {}", class_name(), isr_type);
return false;
}
if (isr_type & DEVICE_CONFIG_INTERRUPT) {
dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Device config interrupt!", VirtIO::determine_device_class(pci_address()));
dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Device config interrupt!", class_name());
if (!handle_device_config_change()) {
set_status_bit(DEVICE_STATUS_FAILED);
dbgln("{}: Failed to handle device config change!", VirtIO::determine_device_class(pci_address()));
dbgln("{}: Failed to handle device config change!", class_name());
}
}
if (isr_type & QUEUE_INTERRUPT) {
dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Queue interrupt!", VirtIO::determine_device_class(pci_address()));
dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Queue interrupt!", class_name());
for (size_t i = 0; i < m_queues.size(); i++) {
if (get_queue(i).new_data_available()) {
handle_queue_update(i);
return true;
}
}
dbgln_if(VIRTIO_DEBUG, "{}: Got queue interrupt but all queues are up to date!", VirtIO::determine_device_class(pci_address()));
dbgln_if(VIRTIO_DEBUG, "{}: Got queue interrupt but all queues are up to date!", class_name());
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Bus/VirtIO/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Device
virtual void initialize();

protected:
virtual StringView class_name() const = 0;
virtual StringView class_name() const { return "VirtIO::Device"; }
explicit Device(PCI::Address);
struct MappedMMIO {
OwnPtr<Memory::Region> base;
Expand Down

0 comments on commit 666c0c5

Please sign in to comment.