Skip to content

Conversation

@kwrx
Copy link
Owner

@kwrx kwrx commented Jan 15, 2026

This pull request introduces several improvements and fixes across the drivers and build system, with a particular focus on the virtio GPU driver, PCI MSI-X handling, and debugging support. The most notable changes include a significant refactor of the virtio GPU framebuffer initialization and update logic, improvements to the PCI MSI-X interrupt handling, and the addition of more granular debug logging for PTY and other subsystems.

Virtio GPU driver improvements

  • Refactored the framebuffer initialization in virtio-gpu/main.c to use a dynamic resource ID (virtgpu_fb_resid) and removed hardcoded macros and unused code, improving resource management and readability. The framebuffer is now created, attached, and set as the scanout in a more robust sequence, with error handling for display enablement and command failures. ([[1]](https://github.com/kwrx/aplus/pull/32/files#diff-ea594d89bf0752573aa484e356e537c8f0c900f6957d07f27bad22c974c5e594L56-L57), [[2]](https://github.com/kwrx/aplus/pull/32/files#diff-ea594d89bf0752573aa484e356e537c8f0c900f6957d07f27bad22c974c5e594R89-L105), [[3]](https://github.com/kwrx/aplus/pull/32/files#diff-ea594d89bf0752573aa484e356e537c8f0c900f6957d07f27bad22c974c5e594L115-L160), [[4]](https://github.com/kwrx/aplus/pull/32/files#diff-ea594d89bf0752573aa484e356e537c8f0c900f6957d07f27bad22c974c5e594L198-R180))
  • Updated the vsync and framebuffer flush logic to use the new dynamic resource ID, ensuring correct synchronization and display updates. ([drivers/virtio/virtio-gpu/main.cL246-R231](https://github.com/kwrx/aplus/pull/32/files#diff-ea594d89bf0752573aa484e356e537c8f0c900f6957d07f27bad22c974c5e594L246-R231))
  • Cleaned up verbose debug output and assertions in interrupt and PCI device discovery handlers for the GPU driver. ([drivers/virtio/virtio-gpu/main.cL296-L320](https://github.com/kwrx/aplus/pull/32/files#diff-ea594d89bf0752573aa484e356e537c8f0c900f6957d07f27bad22c974c5e594L296-L320))
  • Removed unnecessary debug prints and blank lines in virtgpu_cmd.c, streamlining resource management commands and improving maintainability. ([[1]](https://github.com/kwrx/aplus/pull/32/files#diff-4fd1958662a1c8900ddb55ee008bf7b2fdc0bd6be1f19faa45ac783b84908a96L48-L59), [[2]](https://github.com/kwrx/aplus/pull/32/files#diff-4fd1958662a1c8900ddb55ee008bf7b2fdc0bd6be1f19faa45ac783b84908a96L68-L79), [[3]](https://github.com/kwrx/aplus/pull/32/files#diff-4fd1958662a1c8900ddb55ee008bf7b2fdc0bd6be1f19faa45ac783b84908a96L88-L96), [[4]](https://github.com/kwrx/aplus/pull/32/files#diff-4fd1958662a1c8900ddb55ee008bf7b2fdc0bd6be1f19faa45ac783b84908a96L105-L128), [[5]](https://github.com/kwrx/aplus/pull/32/files#diff-4fd1958662a1c8900ddb55ee008bf7b2fdc0bd6be1f19faa45ac783b84908a96L138-L158))

PCI MSI-X interrupt handling

  • Added memory zeroing for MSI-X tables and PBA in pci_msix.c to ensure a clean state before masking interrupts, improving reliability. ([drivers/dev/pci/pci_msix.cR116-R118](https://github.com/kwrx/aplus/pull/32/files#diff-f93480b8db103254db27bd9cb9be59fc00eac5e87f8c7c48e3092678717dde4cR116-R118))
  • Fixed the interrupt mapping and unmapping logic by adding missing break statements, preventing unnecessary iterations and possible bugs. ([[1]](https://github.com/kwrx/aplus/pull/32/files#diff-f93480b8db103254db27bd9cb9be59fc00eac5e87f8c7c48e3092678717dde4cR203), [[2]](https://github.com/kwrx/aplus/pull/32/files#diff-f93480b8db103254db27bd9cb9be59fc00eac5e87f8c7c48e3092678717dde4cR244))

Debug logging enhancements

  • Added conditional debug logging to PTY input processing, including discard, signal sending, canonical mode handling, and character processing, gated by DEBUG_LEVEL_TRACE for easier troubleshooting. ([[1]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dL67-R69), [[2]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR192-R194), [[3]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR239-R241), [[4]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR255-R258), [[5]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR267-R276), [[6]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR293-R295), [[7]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR309-R311), [[8]](https://github.com/kwrx/aplus/pull/32/files#diff-819e605dd2015540a65582a6f1cdbe9f74f164edf009a8c8b632bc4c11c8329dR320-R348))
  • Fixed a preprocessor condition for VGA debug tracing to use #if instead of #ifdef, ensuring correct compilation. ([drivers/platform/pc/video/bochs-vga/main.cL269-R269](https://github.com/kwrx/aplus/pull/32/files#diff-0d242fb45fe0c16791acda4d0a7fcd7553e6ff5580dac62be83969a2f6dd1a89L269-R269))

Input and console driver fixes

  • Improved PS/2 mouse packet handling by resetting the cycle counter on invalid packet start, preventing input errors. ([[1]](https://github.com/kwrx/aplus/pull/32/files#diff-c1e61c0fa5b74c1b69b71bae9933ba1f87832f05208503381618b65f46411b3fL271-R274), [[2]](https://github.com/kwrx/aplus/pull/32/files#diff-c1e61c0fa5b74c1b69b71bae9933ba1f87832f05208503381618b65f46411b3fL382))
  • Updated the virtio console write logic to respect the driver's send window size, sending data in appropriately sized chunks and improving reliability for large writes. ([drivers/virtio/virtio-console/main.cR152-R169](https://github.com/kwrx/aplus/pull/32/files#diff-bf73670fc756b476b8c6b0195b42973c48cbd2bfffd708f08139789063dd83d9R152-R169))

Build system updates

  • Added necessary include paths and compiler flags to the Makefile for the kilo app, ensuring proper compilation in cross-build environments. ([apps/extra/kilo/MakefileR1-R5](https://github.com/kwrx/aplus/pull/32/files#diff-0130715cda0bcbb04c66dda8ef166a8c7fbf9db8720d7d9dbec6337133e4b628R1-R5))

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances the procfs filesystem implementation with new service files (version, filesystems), adds proper error handling for virtio MSI-X vector mapping, updates spinlock memory order semantics for correctness, and fixes several bugs in procfs directory operations.

Changes:

  • Added error handling for MSI-X vector mapping failures in virtio-pci initialization
  • Implemented new procfs service files (/proc/version, /proc/filesystems) with proper filesystem table exposure
  • Updated atomic memory ordering in spinlock operations from deprecated memory_order_consume to memory_order_acquire and added release semantics
  • Fixed multiple bugs in procfs readdir implementation (wrong task/offset usage) and converted cache spinlock to recursive mode

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
drivers/virtio/virtio-pci/main.c Added error handling for MSI-X vector mapping with proper status reporting
kernel/ipc/spinlock.c Updated memory order semantics for atomic operations (acquire/release)
kernel/syscalls/257_openat.c Added 'syscall:' prefix to debug output for consistency
libk/utils/cache.c Changed to recursive spinlock and removed unnecessary key assertions
kernel/fs/vfs.c Refactored filesystem table from static array to exposed global structure
kernel/fs/fstable.c.in Added nodev attribute to filesystem entries
include/aplus/vfs.h Added fstable_t type definition and VFS_MAX_FILESYSTEMS constant
kernel/fs/procfs/procfs_service_version.c New file implementing /proc/version service
kernel/fs/procfs/procfs_service_filesystems.c New file implementing /proc/filesystems service
kernel/fs/procfs/procfs_root_getattr.c New file implementing getattr for procfs root
kernel/fs/procfs/procfs_service_pid.c Fixed finddir to check inode->name instead of unused name parameter
kernel/fs/procfs/procfs_root_readdir.c Fixed task variable usage and d_off field to use index instead of pos
kernel/fs/procfs/procfs_root_finddir.c Uncommented version and filesystems service lookups
kernel/fs/procfs/procfs_mount.c Enabled getattr operation for procfs root
kernel/fs/procfs/procfs.h Added function declarations for new service files
kernel/fs/procfs/procfs_service_{uptime,meminfo,cmdline}.c Removed overly restrictive inode->sb->root assertions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +53 to +67
if (isdigit(inode->name[0])) {

long pid = atol(inode->name);

if (pid > 0) {
return procfs_service_pid_inode(inode, pid);
} else {
return errno = ENOENT, NULL;
}

} else if(strcmp(inode->name, "self") == 0) {
return procfs_service_pid_inode(inode, current_task->tid);
} else {
return errno = ENOENT, NULL;
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function procfs_service_pid_finddir receives a parameter 'name' but checks 'inode->name' instead. This appears to be incorrect - the function should be checking the 'name' parameter to determine which child entry to find within the current inode directory, not the inode's own name. This logic should match the pattern in procfs_root_finddir which correctly uses the 'name' parameter.

Copilot uses AI. Check for mistakes.
return errno = ENOENT, NULL;
}

} else if(strcmp(inode->name, "self") == 0) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be 'if (' instead of 'if(' to match the coding style used throughout the rest of the codebase.

Suggested change
} else if(strcmp(inode->name, "self") == 0) {
} else if (strcmp(inode->name, "self") == 0) {

Copilot uses AI. Check for mistakes.

// if(strcmp(name, "version") == 0)
// return procfs_version_inode();
if(strcmp(name, "version") == 0)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be 'if (' instead of 'if(' to match the coding style used in surrounding code (see lines 61, 67, 70, 79).

Copilot uses AI. Check for mistakes.

// if(strcmp(name, "filesystems") == 0)
// return procfs_filesystems_inode();
if(strcmp(name, "filesystems") == 0)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be 'if (' instead of 'if(' to match the coding style used in surrounding code.

Copilot uses AI. Check for mistakes.

static char buffer[BUFSIZ] = {0};

for(size_t i = 0; i < VFS_MAX_FILESYSTEMS; i++) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'for' keyword. Should be 'for (' instead of 'for(' to maintain consistent coding style.

Suggested change
for(size_t i = 0; i < VFS_MAX_FILESYSTEMS; i++) {
for (size_t i = 0; i < VFS_MAX_FILESYSTEMS; i++) {

Copilot uses AI. Check for mistakes.
uint16_t i = k % (vector_limit - 1);

pci_msix_map_irq(driver->device, &msix, (pci_irq_handler_t)virtio_pci_interrupt, (pci_irq_data_t)driver, i);
if(pci_msix_map_irq(driver->device, &msix, (pci_irq_handler_t)virtio_pci_interrupt, (pci_irq_data_t)driver, i) < 0) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be 'if (' instead of 'if(' to maintain consistent coding style.

Suggested change
if(pci_msix_map_irq(driver->device, &msix, (pci_irq_handler_t)virtio_pci_interrupt, (pci_irq_data_t)driver, i) < 0) {
if (pci_msix_map_irq(driver->device, &msix, (pci_irq_handler_t)virtio_pci_interrupt, (pci_irq_data_t)driver, i) < 0) {

Copilot uses AI. Check for mistakes.
}

pci_msix_map_irq(driver->device, &msix, (pci_irq_handler_t)virtio_pci_interrupt, (pci_irq_data_t)driver, vector_limit - 1);
if(pci_msix_map_irq(driver->device, &msix, (pci_irq_handler_t)virtio_pci_interrupt, (pci_irq_data_t)driver, vector_limit - 1) < 0) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after 'if' keyword. Should be 'if (' instead of 'if(' to maintain consistent coding style.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants