Reading Notes on "CPU Introduction for Programmers"

This was an excellent book with key points organized in a very clear way. I was especially pleased that it included experimental sample code written in assembly 1. Even if you know concepts theoretically, running them gives you a deeper understanding. Here I’ll leave some miscellaneous notes for myself. Assembly Notation Intel syntax is easier to understand than AT&T syntax. I feel the same way. In Intel syntax, the destination comes on the left side....

May 18, 2023

Building a Virtual Environment on Intel NUC 12 Pro

I bought an Intel NUC 12 Pro 1 as a development machine and installed Proxmox VE 2. Until now, I was using an old Thinkpad as a development machine, so I think it’s become more comfortable. The specs are like this. I wanted to prioritize memory and disk, so I went with more. On the other hand, I didn’t care much about core count, so I chose the i3 model. I considered a vPro-equipped model, but I passed on it because of limited availability and the assumption that virtualization would reduce the frequency of remote management operations....

May 1, 2023

Installing LUA4-U3-AGTE-NBK Driver

It seems I broke something under /lib/modules while playing with a privileged container. I’m not sure why, but when going out from this machine to the outside, it sometimes connects and sometimes doesn’t. I’m using a BUFFALO LUA4-U3-AGTE-NBK 1 adapter that receives Ethernet as USB Type-A, and the driver for it seems suspicious. The log looks like this. ubuntu2004thinkpad:~$ dmesg IPv6: ADDRCONF(NETDEV_CHANGE): enx9096f349a025: link becomes ready usb 3-1: USB disconnect, device number 45 ax88179_178a 3-1:1....

March 31, 2023

vhost-user Negotiation

Introduction When adapting gokvm to vhost-user, I investigated the initialization part, so I’m leaving it as a memo. The QEMU documentation Vhost-user Protocol 1 summarizes it in detail, but there are parts that can’t be understood without actually running it (exception handling, request order, log output, etc.), so I tried it. After various trial and error, I was able to test it easily with just QEMU and DPDK. Here, I ran QEMU in server mode and DPDK in client mode....

March 8, 2023

Self-made VMM: u-root-based initrd

Introduction Continuation of gokvm development 1 2 3 4 5 6. As introduced up to last time, by supporting virtio-blk and virtio-net, the virtual machine can now communicate with the outside through IO. This time, I changed the initrd from busybox-based to u-root-based, so I’ll talk about that. 0d89a47f Introduction of u-root-based initrd I received a Pull Request suggesting that a VMM written in Go language should have an initrd also written in Go....

June 13, 2022

virtio-blk Support for Custom VMM

Introduction Continuing gokvm development 1 2 3 4 5. Following the previous virtio-net support, I added support for virtio-blk. The data structure and behavior of virt queue can be reused as is. I’m impressed that Virtio is well designed in this regard. 7389ff59 Adjust Guest Kernel Compile Options To achieve block IO through the filesystem from the guest kernel, I enabled the following options: CONFIG_VIRTIO_BLK=y CONFIG_XFS_FS=y CONFIG_EXT3_FS=y CONFIG_EXT4_FS=y 4f4bbb78 virtio-blk Implementation Now, let’s move on to the main topic of virtio-blk implementation....

April 12, 2022

virtio-net Support for Custom VMM

Introduction Continuing gokvm development 1 2 3 4. Through recent development, I was able to provide a virtual NIC to VMs on gokvm via virtio-net. Networking support was one of the initial goals, so I feel a sense of accomplishment. With this support, VMs on gokvm can now communicate with the host (or the outside via a software switch). It broadens what you can do, such as providing a web server or logging in via SSH, which I think is a major change....

March 18, 2022

PCI Device Support for Custom VMM

Introduction Continuing gokvm development 1 2 3. I’ve been developing to enable VMs on gokvm to handle PCI devices. The road will be long, but ultimately I want to establish IP connectivity between the VM and the outside via virtio-net. At the moment, I was able to get the guest kernel to recognize the virtio-net device as a network interface, so I’ll leave a log up to that point for now....

January 24, 2022

SMP Support for Custom VMM with KVM

Introduction A progress report on gokvm development 1 2. Until now, I only supported a single virtual CPU. I wanted to support SMP (Symmetric Multiprocessing) for multi-CPU, and after about 2-3 weeks of trial and error, I was able to implement it successfully. As far as I know, while searching for efforts to create a VMM with KVM, I couldn’t find many resources that explain what SMP support specifically looks like in implementation....

November 25, 2021

Building a Busybox-based Minimal Linux Environment and Booting with QEMU

As many people have already undertaken similar efforts and compiled them nicely into blog posts 1 2 3, I think being able to quickly create such an environment at hand is very meaningful. Here I’ll record the rough mechanism. I’ve compiled the results into scripts and uploaded them to Github. Features Supports building kernels for major distributions like CentOS6, CentOS7, Ubuntu20.04, enabling practical applications Uses Busybox to deploy userland in memory, creating a pure and minimal environment on each boot SSH login and external network connectivity are possible, making it easy to verify operations involving integration with other systems Can reference internal kernel data through debugging with GDB Currently only supports x86/64 Building the Kernel Building the kernel basically corresponds to writing the build configuration in a ....

July 7, 2021

Building a VMM with KVM to Boot Linux - Development Log 2

2021/2/24 WSL2 Support 4f6b785 When running gokvm on Ubuntu 20.04 on WSL2 (Windows Subsystem for Linux 2), output to IO port 0x64 was repeated infinitely and didn’t reach the Init process startup. It seems the behavior around the PS/2 keyboard was the cause. In kvmtool, it returns 0x20 for in (0x61) 1, so I followed that approach. IO port 0x61 appears to be used as NMI (Non-Maskable Interrupt) status and control register 2....

March 3, 2021

Building a VMM with KVM to Boot Linux - Development Log

Introduction I created a naive and experimental VMM using KVM. It creates virtual machines by calling /dev/kvm through ioctl, and can boot the Linux Kernel and user processes on them. I also implemented a very simple serial console emulation that can be recognized by the kernel’s device driver, allowing operation from the login shell. On the other hand, networking and disks are not yet supported at this time. Recently, KVM has been used not only as a traditional virtual machine, but also to strengthen isolation levels in multi-tenant cloud environments, such as Google gVisor 1, Kata Containers 2, and Amazon Firecracker 3, for use in containers and micro VMs....

February 18, 2021

x86 Emulator Development Log (5)

Happy New Year. I have been continuing the development of the x86 emulator, but as six months have passed and the development pace has slowed down, I have decided to make the code public at this point. It is available at https://github.com/bobuhiro11/tiny_x86_emu, so please take a look if you are interested.

January 4, 2019

x86 Emulator Development Log (4)

Last month, Go 1.11 was released and WebAssembly was experimentally supported. Since the emulator I’m developing is also written in Go, I took this opportunity to port it to WebAssembly. Simply compiling Go to WebAssembly uses the browser console as standard output, but I wanted to output to a div tag, so I manipulated the DOM using the syscall/js package. No other changes were necessary. It’s published at https://bobuhiro11.net/tiny_x86_emu/. It’s still a work in progress, and development on user process execution has been stalled, so I should start working on that soon....

September 19, 2018

x86 Emulator Development Log (3)

The emulator development has progressed to the point where process switching is possible through mpmain(), scheduler(), and swtch(). The xv6 code at line 334 of proc.c keeps issuing the sti instruction, and it seems to have entered a loop, so I’d like to summarize scheduling and context switching here. The process being switched to performs I/O immediately after being switched in the forkret() and iinit() functions. Here, it enters a sleep state and appears to be waiting for an interrupt....

August 19, 2018

Reading Notes on "First Time Reading the 486"

I read “First Time Reading the 486,” so I’ll note down what caught my attention. It’s helpful since I’m making an emulator. Throughout the book, the diagrams are very clear, so just looking at them is educational. Segments When reading instructions from EIP, the segment pointed to by the CS register is used, and when accessing memory during instruction execution, the segment pointed to by the DS register is used. Also, for stack-related operations like PUSH, POP, CALL, RET, the segment pointed to by the SS register is used....

August 4, 2018

x86 Emulator Development Log (2)

I want to summarize xv6’s paging. In the kernel main function, the page table and page directory initialization is performed twice. The first initialization of the paging mechanism maps the lower 4MB of virtual addresses 0x0 ~ 0x400000 directly to physical addresses 0x0 ~ 0x400000. Also, virtual addresses 0x80000000 ~ 0x80400000 with 0x80000000 as an offset are also mapped to the same physical addresses 0x0 ~ 0x400000. This paging is only used during kernel initialization....

July 21, 2018

x86 Emulator Development Log (1)

I read a book titled “Learning x86 Architecture by Creating Your Own Emulator.” As a continuation, with the goal of fully running xv6, an x86 OS mainly used for educational purposes, I plan to extend the self-made emulator. Since I’ll be developing over a relatively long period, I want to summarize the current situation. Currently, the bootloader has deployed the kernel body into memory, and I can start execution from the kernel’s main function....

July 1, 2018