Page MenuHomeFreeBSD

Add bhyve uart raw tcp backend
Needs ReviewPublic

Authored by aokblast on May 8 2024, 12:26 PM.
Tags
None
Referenced Files
F89286385: D45120.id139372.diff
Fri, Jul 26, 4:23 AM
Unknown Object (File)
Tue, Jul 16, 12:45 PM
Unknown Object (File)
Wed, Jul 10, 8:25 AM
Unknown Object (File)
Tue, Jul 9, 5:03 PM
Unknown Object (File)
Tue, Jul 9, 5:01 PM
Unknown Object (File)
Tue, Jul 9, 4:59 PM
Unknown Object (File)
Tue, Jul 9, 4:56 PM
Unknown Object (File)
Tue, Jul 9, 4:56 PM

Details

Reviewers
lwhsu
corvink
markj
bz
Group Reviewers
bhyve
Summary

This is a updated patch from this old patch according to the modification from markj on uart part of bhyve.

This patch add raw tcp connection ability on bhyve and has been tested on my own machine.

An example about this is as following:

bhyve -c 2 -m 4G -w -H \
                                       -s 0,hostbridge \
                                       -s 1,virtio-blk,./FreeBSD-14.0-STABLE-amd64-20240118-cef433d3fb38-266364.raw \
                                       -s 30,xhci,tablet \
                                       -s 31,lpc -l com1,tcp=127.0.0.1:8085 \
                                       -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
                                        uefivm

Then we can use nc by:

netcat 127.0.0.1 8085

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 58030
Build 54918: arc lint + arc unit

Event Timeline

aokblast added reviewers: lwhsu, corvink, markj.
aokblast retitled this revision from Add bhyve uart tcp backend to Add bhyve uart raw tcp backend.
usr.sbin/bhyve/uart_backend.c
339

Shouldn't we lock sc->mtx here?

usr.sbin/bhyve/bhyve.8
1134

tcp= ?

bz requested changes to this revision.May 15 2024, 4:54 PM
bz added a subscriber: bz.
bz added inline comments.
usr.sbin/bhyve/uart_backend.c
303

This won't take an IPv6 address?

This revision now requires changes to proceed.May 15 2024, 4:54 PM
usr.sbin/bhyve/uart_backend.c
335

It's better to use C-style comments.

343

I think we should close the descriptor here to avoid leakage.

  • Add bhyve uart tcp backend
  • Add manual page

I fix the previous error previously mentioned, and because uart_tcp_disconnect is a helper function and it parent has already lock it. I add comment to let everyone use this function in the future know this.

  • Add bhyve uart tcp backend
  • Add manual page
usr.sbin/bhyve/bhyve.8
624
626
usr.sbin/bhyve/uart_backend.c
121

What if len < 0?

313

conn_fd is leaked in the error path.

321
438

errx() causes the program to exit. (And, the compiler knows this because of the __dead2 annotation in err.h.) So, we don't need these return statements after. Or, if your intent is to print a message and return, use warnx() instead.

451

Missing a freeaddrinfo() call after the bind().

463

bind_fd is being leaked.

usr.sbin/bhyve/bhyve.8
1125

Also, 0.0.0.0 is not a valid address. Here it really means, "bind to a wildcard address". Probably 127.0.0.1 is a better example.

1134

Above, the syntax is documented as tcp:0.0.0.0:1234, but here it's tcp=0.0.0.0:1234. Which one is right?

1140
usr.sbin/bhyve/uart_backend.c
79

uart_tcp_softc would be a better name in my opinion. ("softc" is an abbreviation for "software context", very common in BSD code.)

438

Discussing in person, since other backends return errors, we should do the same here too.

458

You probably want to set the SO_REUSEADDR socket option. Otherwise, if I use the TCP console and reboot the VM, the previous connection will linger and I hit this error.

Also, just use warn() here, instead of warnx(). Then strerror(errno) is automatically appended to the warning. That is, just write: warn("bind()");.

aokblast marked 13 inline comments as done.
  • Add bhyve uart tcp backend
  • Add manual page
  • Add bhyve uart tcp backend
  • Add manual page
  • Add bhyve uart tcp backend
  • Add manual page
  • Add bhyve uart tcp backend
  • Add manual page
  • Add bhyve uart tcp backend
  • Add manual page