https://github.com/hegdebhavya/virtualization-assignment-2
To Modify the CPUID emulation code in KVM to report back additional information when special CPUID leaf nodes are requested.
https://github.com/hegdebhavya/virtualization-assignment-2
cpuid kvm virtualization
Last synced: 3 months ago
JSON representation
To Modify the CPUID emulation code in KVM to report back additional information when special CPUID leaf nodes are requested.
- Host: GitHub
- URL: https://github.com/hegdebhavya/virtualization-assignment-2
- Owner: hegdebhavya
- Created: 2022-11-21T01:52:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-12T01:30:49.000Z (almost 3 years ago)
- Last Synced: 2025-05-22T11:35:13.770Z (5 months ago)
- Topics: cpuid, kvm, virtualization
- Language: C
- Homepage:
- Size: 181 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CMPE283-Assignment-2
Student Name : Bhavya Hegde
email : bhavya.hegde@sjsu.edu## Modify the CPUID emulation code in KVM to report back additional information when special CPUID leaf nodes are requested.
### Implementation of CPUID leaf nodes 0x4FFFFFFC and 0x4FFFFFFD
### Question 2:
#### Steps used to complete this assignment :Following are the development steps I have followed to develop the solution for assignment-2: Adding leaf nodes 0x4ffffffc and 0x4ffffffd to the CPUID emulation code in KVM.
* Fork the Linux Kernel https://github.com/torvalds/linux.git
* Checkout the linux kernel code from my github repository
git clone https://github.com/hegdebhavya/linux.gitThe new kernel code that is checked-out here is **6.1.0-rc6+**

The current Linux Kernel version is as below,

* We now install all the libraries and tools we would need to build the new Linux Kernel.
```
sudo apt install gcc make bison flex pkg-config
sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools g++ libelf-dev```
* Next we make the config file for our kernel build
```
make xconfig
```* I have selected the default options for xconfig. Once this command is executed we start the make process
```
make
```* Once the make is complete,
```
sudo make modules_install
sudo make install
```
* Next, we configure the grub loader, to check the exact kernel version name you can navigate to the /lib/modules directory and get the version, with this you can run commands below,```
sudo update-initramfs -c -k 6.1.0-rc6+
sudo update-grub```

* Next, we reboot the system and run **uname -r** to check the new linux kernel version

We observe that the Linux version has been upgraded to **6.1.0-rc6+** from the previous **5.15.0-53-generic**.
* Next, I have modified the files /linux/arch/x86/kvm/cpuid.c and /linux/arch/x86/kvm/vmx/vmx.c to add the required variables and logic to add support for cpuid leaf nodes 0x4ffffffc and 0x4ffffffd. These changes are committed to the current GitHub repository and commits can be seen [here](https://github.com/hegdebhavya/linux/commit/b0f1c18a54b1e92549034ab453affeccfb367bf0)
* After the files are modified we build the modules again by running following commands
```
make modules
```
* Once make completes please install the modules using command below,
```
make INSTALL_MOD_STRIP=1 modules_install
```* We then reload the kvm modules using following commands
```
sudo rmmod kvm_intel
sudo rmmod kvm
sudo modprobe kvm_intel
sudo modprobe kvm
```
* To test the cpuid modifications we will now install virt-manager and run a 32-bit Ubuntu Virtual machine
```
sudo apt install virt-manager
```* Once virt-manager is installed we can launch the virtual machine manager by running command **virt-manager** ; create a new 32-bit VM in my case I have tested with Ubuntu

We can see the 32-bit inner VM in the screenshot below,

* Next, we can download a test program to test the cpuid leaf nodes by downloading cpuid from,
http://archive.ubuntu.com/ubuntu/pool/universe/c/cpuid/cpuid_20170122.orig.tar.gz into this new 32-bit Ubuntu VM* Once the archive is extracted we can navigate to the extracted directory and run the make command to build the program.
## Output
* To check the Total number of Exits we can run the cpuid command with leadnode 0x4FFFFFFC with command below,
```
./cpuid -l 0x4ffffffc
```
Here, the leaf node is specified with ā-lā argument.

We see the total number of exit counts increasing and the values are returned in the eax register. The leafnode and the increasing exit counts are highlighted in the screenshot above.
* To check the Total time taken to process these exits we can run the cpuid command with leafnode 0x4FFFFFFD with command below,
```
./cpuid -l 0x4ffffffd
```

We see the total processing time for exits increasing and the values are returned in registers ebx and ecx. The leafnode and the increasing values returned are highlighted in the screenshot above. The high 32-bits of total time spent are returned in register ebx and the low 32-bit of the total time spent are returned in the register ecx.