MASTER THESIS Guest OS Backward Compatibility for the Freebsd
Total Page:16
File Type:pdf, Size:1020Kb
University “Politehnica” of Bucharest Automatic Control and Computers Faculty, Computer Science and Engineering Department MASTER THESIS Guest OS Backward Compatibility for the FreeBSD Hypervisor Scientific Adviser: Author: As.dr.ing. Mihai Carabas Ionut - Alexandru Teaca Bucharest, 2017 Contents 1 Introduction 1 1.1 Motivation.......................................1 1.2 Objectives........................................2 1.3 Outline.........................................2 2 Background 4 2.1 Virtualization......................................4 2.2 Hardware devices....................................5 2.3 Overview of the bhyve hypervisor...........................6 3 Related Work9 4 The ATA/ATAPI Emulation 11 4.1 Overview........................................ 11 4.2 Hardware Resources.................................. 12 4.2.1 I/O ports description............................. 12 4.2.2 Interrupts.................................... 13 4.3 Data Transfer Protocols................................ 14 4.3.1 PIO command protocol............................ 14 4.3.2 DMA command protocol........................... 15 4.4 Command descriptions................................. 16 4.4.1 ATA commands................................ 17 4.4.2 ATA-ATAPI commands............................ 18 4.4.3 ATAPI commands............................... 18 4.5 Implementation Details................................ 19 4.5.1 Initialization.................................. 19 4.5.2 Software reset protocol............................. 20 4.5.3 Device addressing considerations....................... 20 4.5.4 Block device emulation............................ 21 5 The NE2000 Emulation 22 5.1 Overview........................................ 22 5.2 Hardware Resources.................................. 23 5.2.1 I/O ports description............................. 23 5.2.2 Interrupts.................................... 24 5.3 Packet Transfer Protocols............................... 24 5.3.1 Packet Ring Buffers.............................. 25 5.3.2 Packet Transfer Emulation.......................... 26 5.4 Implementation Details................................ 27 5.4.1 Initialization.................................. 27 5.4.2 Software Reset command........................... 28 5.4.3 Multithreading environment.......................... 29 i CONTENTS ii 6 Device Emulation Evaluation 30 6.1 ATA/ATAPI...................................... 30 6.1.1 Configuration.................................. 30 6.1.2 Results of ATA/ATAPI emulation...................... 32 6.1.3 Validation and Performance.......................... 34 6.2 NE2000......................................... 35 6.2.1 Configuration.................................. 35 6.2.2 Results of NE2000 emulation......................... 36 6.2.3 Validation and Performance.......................... 37 7 Conclusion and Further Work 40 List of Figures 2.1 Virtual Machine Monitor...............................5 2.2 Hosted Virtualization.................................6 2.3 bhyve structure.....................................7 2.4 VM state machine...................................7 2.5 bhyve device emulation................................8 4.1 ATA/ATAPI overview................................. 11 5.1 NE2000 overview.................................... 22 iii List of Tables 4.1 ATA Bus Master Register Offsets........................... 13 4.2 PCI Compatibility and PCI-Native Mode Bus Master Adapters Configuration Registers......................................... 13 4.3 Physical Region Descriptor Table Entry....................... 16 5.1 NE2000 NIC Register Offsets............................. 24 5.2 NE2000 Receive Ring Header............................. 26 6.1 Hardware configuration................................ 30 iv Chapter 1 Introduction The area of applications using software virtualization has been growing more and more in the last years, virtualization being fundamental for many technologies (for example, cloud computing). Nowadays the main issue is to support many different guest operating systems. There are many types of applications which run on legacy operating systems (FreeBSD 4, Windows XP) and nobody wants to change their setup or to upgrade the operating system. However, they need to migrate toward virtualized hosts. Hence, the solution to this problem is to enhance the hypervisors in order to support such operating systems. This subject is present in all hypervisors but we will focus on the FreeBSD Hypervisor (bhyve). This chapter starts with the motivation of this project which explains the reasoning to develop more device emulations in the bhyve hypervisor, continues with clear objectives regarding the features we implemented and ends with an outline that emphasizes the structure of the thesis. 1.1 Motivation We started by analyzing the key reasons why some older operating systems are not supported in bhyve and what are the critical parts which have to be implemented to improve that. We did this by comparing the FreeBSD 4.0 with the FreeBSD 8.0 release which is the last supported version of FreeBSD i386/amd64 and we noticed that the main differences consisted in the supported hardware devices. On a first sight, we observed some compatibility issues at the media storage devices like hard disks, floppy drives, and optical disc drives. The FreeBSD Hypervisor (bhyve) provides only the emulation of the Advanced Host Controller Interface (AHCI) used by the Serial ATA devices but the FreeBSD 4 has no drivers for that. The class of media storage devices is critical for any hypervisor because it allows to install and boot an operating system. We propose to implement the ATA(AT Attachment) Host Adapter Standard which is supported in the FreeBSD 4.0 release and many other operating systems. Another category of devices in which bhyve does not provide good support for the older op- erating systems are the network card devices. The bhyve hypervisor uses a virtio net device emulation but these operating systems do not have virtio device drivers and are not able to use this emulation. This class of devices is absolutely necessary for any hypervisor because almost all applications require network access. One of the best supported devices, especially in older operating systems, is the NE2000 device. We propose to implement the NE2000 device emulation which will allow a larger number of unmodified guest operating systems to run under bhyve. 1 CHAPTER 1. INTRODUCTION 2 Currently bhyve supports any version of FreeBSD i386/amd64 since the FreeBSD 8.0 release. The "Guest OS Backward Compatibility for the Free BSD Hypervisor" general project is aimed to support guest Operating Systems with older versions such as FreeBSD4/5. In order to help with that, we have implemented the ATA/ATAPI 6 emulation and the NE2000 device emulation. In this work we present two different types of emulations: a generic ATA/ATAPI drive controller which runs attached on both LPC the PCI(through a Host PCI Adapter) buses and the NE2000 device under both PCI and LPC attachments. 1.2 Objectives Analysing the motivation of this project presented in the previous section, we emphasize more precisely the objectives of this project. The main objectives are to implement two device emulations in the FreeBSD hypervisor in order to provide better compatibility with the older operating systems. We start with the first objective where we intend to emulate an ATA disk and an ATAPI cdrom in order to boot a virtual machine and install it to the emulated disk. In order to accomplish this objective there are several requirements to implement: • emulate the I/O ports accesses according to the ATA/ATAPI datasheet specification; • implement the ATA 6 standard and the ATA Packet commands (the ATAPI Packet is used to communicate with the ATAPI cdrom device); • implement the PIO4 and WDMA2 data transfer protocols working at transfer rates of more than 16.700MB/s; • work with both primary and secondary channels where each of them support master and slave drives at the same time; • configure and run the ATA/ATAPI emulation under both PCI and LPC attachments. The second objective is to emulate a NE2000 network card device in order to have Internet connectivity in the guest virtual machine. In order to accomplish this objective, there are several requirements to implement: • emulate the I/O ports accesses according to the NE2000 datasheet specification; • implement the PIO data transfer protocol; • implement the management of the Packet Ring Buffers used in the packets transfer; • find a solution to transfer the Ethernet frames between the NE2000 guest network driver and the host networking stack; • configure and run the NE2000 emulation under both PCI and LPC attachments. Besides these two objectives that are related with the device emulation development, we also intend to have a testing process that will help with the correctness validation and performance evaluation for the ATA/ATAPI and NE2000 implementations. 1.3 Outline The structure of this thesis is as follows. In Chapter 2 we give a short introduction to the background information that is necessary in the understanding of our work in the device em- ulation domain. We prezent some general concepts about virtualization, the hardware speci- fications and protocols related with the ATA/ATAPI and NE2000 devices and an overview of CHAPTER 1. INTRODUCTION 3 the bhyve hypervisor. It is the purpose of Chapter 3 to present the current situation regarding the ATA/ATAPI and NE2000 emulations in the bhyve hypervisor and other emulators