Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Experimenting with MDEV-Based Virtualization for PCI Serial Port Devices

Tech 1

This practice is based on the following Linux kernel documentation: Documentation/driver-api/vfio-mediated-device.rst Documentation/driver-api/vfio.rst

Compiling and Loading the MTTY Kernel Module

This step establishes a dummy device at /sys/devices/virtual/mtty/mtty/. Enable the CONFIG_SAMPLE_VFIO_MDEV_MTTY kernel configuration option. Recompile the kernel to generate the mtty.ko module.

make CONFIG_VFIO_MDEV=m -C /lib/modules/$(uname -r)/build M=/path/to/linux/source/drivers/vfio/mdev/ modules
make CONFIG_SAMPLE_VFIO_MDEV_MTTY=m -C /lib/modules/$(uname -r)/build M=/path/to/linux/source/samples/vfio-mdev/ modules

After rebooting the system, proceed to load the modules:

sudo insmod /path/to/mdev.ko
sudo insmod /path/to/vfio_mdev.ko
sudo insmod /path/to/mtty.ko

Understanding MDEV Groups: When mutliple types of MDEV devices are supported, separate subdirectories are created under the device's sysfs directory for managing each distinct type. Upon successful installation, the difference between device types can be observed in /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-#NUM/name. One type represents a single-port TTY, while the other corresponds to a dual-port TTY.

Creating a Mediated Device Instance

Use the dummy device created earlier to instantiate a mediated device. Any valid UUID is acceptable; it is common to generate one using a uuid utility.

echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001" > /sys/devices/virtual/mtty/mtty/mdev_supported_types/mtty-2/create

This sysfs write operation triggers the following kernel call stack, which handles the device creation. The new device is implemented as a PCI device, requiring the configuration of its PCI configuration space. A dedicated IOMMU group is established for the device, and the MDEV intsance is associated with it. The vendor and product IDs in the configuration space (e.g., 0x32534348) correspond to a device such as a CH352 16550 PCI UART serial driver, thereby linking the PCI abstraction to the MTTY MDEV device.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.