tandasat / Hypervisor-101-in-Rust

The materials of "Hypervisor 101 in Rust", a one-day long course, to quickly learn hardware-assisted virtualization technology and its application for high-performance fuzzing on Intel/AMD processors.
https://tandasat.github.io/Hypervisor-101-in-Rust/
MIT License
982 stars 66 forks source link

Problem starting with bochs - "connection refused" #2

Closed Ben-Lichtman closed 1 year ago

Ben-Lichtman commented 1 year ago

I compiled bochs from the provided repo and got the following message:

Connection failed: Connection refused
telnet: Unable to connect to remote host: Connection refused
   0: Trying ::1...
   0: Trying 127.0.0.1...
00000000000i[      ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/local/lib/bochs/plugins'
00000000000i[      ] debugger using rc file './bochs/dbg_command.txt'.
00000000000i[      ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
00000000000e[SIM   ] get_param_bool(unmapped) could not find a parameter
Connection failed: Connection refused
telnet: Unable to connect to remote host: Connection refused
   0: Trying ::1...
   0: Trying 127.0.0.1...
Connection failed: Connection refused
telnet: Unable to connect to remote host: Connection refused
   0: Trying ::1...
   0: Trying 127.0.0.1...
Connection failed: Connection refused

This connection failure repeated forever until I killed the script.

Any idea what may be causing this?

Ben-Lichtman commented 1 year ago

Seems that I'm somehow managing to segfault bochs...?

I tried replicating what the script command is doing on the bochs side:

❯ Bochs/bochs/bochs -q -unlock -rc tests/bochs/dbg_command.txt -f tests/bochs/linux_amd.bxrc               
00000000000i[      ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/local/lib/bochs/plugins'
========================================================================
                      Bochs x86 Emulator 2.7.svn
               Built from SVN snapshot after release 2.7
                  Compiled on Feb 15 2023 at 11:02:57
========================================================================
00000000000i[      ] debugger using rc file 'tests/bochs/dbg_command.txt'.
00000000000i[      ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
00000000000e[SIM   ] get_param_bool(unmapped) could not find a parameter
zsh: segmentation fault (core dumped)  Bochs/bochs/bochs -q -unlock -rc tests/bochs/dbg_command.txt -f 

(here that bochs path is the executable built from your patched gcc branch)

Ben-Lichtman commented 1 year ago

Turns out I wasn't accounting for libraries that would be installed using make install - I solved this by using CONFIGURE_ARGS=--prefix=$HOME/bochs_install sh .conf.linux when building so it would install to a discrete directory

mrlongsword commented 1 year ago

I got a similar error yesterday in class.

[CPU0  ]i| RDMSR: Read 00000000:fee00900 from MSR_APICBASE
[CPU0  ]i| RDMSR: Read 00000000:fee00900 from MSR_APICBASE
[CPU0  ]i| RDMSR: Read 00000000:fee00900 from MSR_APICBASE
[CPU0  ]i| RDMSR: Read 00000000:fee00900 from MSR_APICBASE
telnet: Unable to connect to remote host: Connection refused
   0: Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
   0: Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
   0: Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
   0: Trying 127.0.0.1...

The solution was to kill an earlier bochs process:

wenyi@LAPTOP-KO2DFVQ8:~$ ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.0   2824  1812 ?        Sl   00:17   0:20 /init
root         7  0.0  0.0   1820    88 ?        Ss   00:17   0:00 /init
root         8  0.0  0.0   1820   104 ?        S    00:17   0:03 /init
wenyi        9  0.0  0.0   6328  5368 pts/0    Ss+  00:17   0:00 -bash
wenyi    27577 99.9  1.4 1149456 119248 pts/0  R    02:51  60:41 bochs -q -unlock -rc ./bochs/dbg_command.txt -f ./bochs
root     28094  0.0  0.0   2688   460 ?        Ss   03:19   0:00 /init
root     28095  0.0  0.0   2688   460 ?        S    03:19   0:00 /init
wenyi    28096  0.0  0.0   6200  5428 pts/2    Ss+  03:19   0:00 -bash
root     29031  0.0  0.0   2824   604 ?        Ss   03:51   0:00 /init
root     29032  0.0  0.0   2824   604 ?        R    03:51   0:00 /init
wenyi    29033  0.1  0.0   6200  5080 pts/1    Ss   03:51   0:00 -bash
wenyi    29046  0.0  0.0   7780  3172 pts/1    R+   03:51   0:00 ps -aux
wenyi@LAPTOP-KO2DFVQ8:~$ kill -9 27577

After that I was able to successfully build:

UEFI Interactive Shell v2.2
  12: EDK II
  12: UEFI v2.70 (EDK II, 0x00010000)
  12: Mapping table
  12:       FS0: Alias(s):F0a:;BLK0:
  12:           PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
Press ESC in 1 seconds to skip startup.nsh or any other key to continue.
  14: Shell> fs0:
  14: FS0:\> copy -q fs1:rhv.efi rhv.efi
  14: cp: File not found - 'fs1:rhv.efi'
  14: FS0:\> rhv.efi snapshot.img snapshot_patch_empty.json corpus

Hope this helps :wink: