Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS-7458 bhyve should allow pci_slot addressing for NICs #309

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions usr/src/lib/brand/bhyve/zone/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ add_nets(int *argc, char **argv)
char *nets;
char *net;
char *lasts;
int nextpcifn = 1; /* 0 reserved for primary */
uint_t nextpcifn = 1; /* 0 reserved for primary */
char slotconf[MAXNAMELEN];
char *primary = NULL;

Expand All @@ -433,7 +433,11 @@ add_nets(int *argc, char **argv)

for (net = strtok_r(nets, " ", &lasts); net != NULL;
net = strtok_r(NULL, " ", &lasts)) {
int pcifn;
char *slotstr;
uint_t pcibus = 0;
uint_t pcislot = PCI_SLOT_NICS;
uint_t pcifn;
int ret;

/* zoneadmd is not careful about a trailing delimiter. */
if (net[0] == '\0') {
Expand All @@ -450,14 +454,27 @@ add_nets(int *argc, char **argv)
}
primary = net;
pcifn = 0;
} else if ((slotstr = get_zcfg_var("net", net,
"pci_slot")) != NULL) {
if (parse_pcislot(slotstr, &pcibus, &pcislot,
&pcifn) != 0) {
return (-1);
}
} else {
pcifn = nextpcifn;
nextpcifn++;
}

if (snprintf(slotconf, sizeof (slotconf),
"%d:%d,virtio-net-viona,%s", PCI_SLOT_NICS, pcifn, net) >=
sizeof (slotconf)) {
if (pcibus > 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no way to avoid collisions here?

I can add a nic without pci_slot set and mark it primary and then add a 2nd one set to 0:6:0 an they will end up in the same slot. (Or am I missing a check for that somewhere?

ret = snprintf(slotconf, sizeof (slotconf),
"%u:%u:%u,virtio-net-viona,%s",
pcibus, pcislot, pcifn, net);
} else {
ret = snprintf(slotconf, sizeof (slotconf),
"%u:%u,virtio-net-viona,%s", pcislot, pcifn, net);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also be explicitly set the bus to 0 while we're here?

6919:   bhyve -H -U 99e40ee7-a8f9-4b57-9225-e7bd19f64b07 -B 1,manufacturer=Joyent,produ
argv[0]: bhyve
argv[1]: -H
argv[2]: -U
argv[3]: 99e40ee7-a8f9-4b57-9225-e7bd19f64b07
argv[4]: -B
argv[5]: 1,manufacturer=Joyent,product=SmartDC HVM,version=7.20200529T085640Z,serial=99e40ee7-a8f9-4b57-9225-e7bd19f64b07,sku=001,family=Virtual Machine
argv[6]: -s
argv[7]: 31,lpc
argv[8]: -l
argv[9]: bootrom,/usr/share/bhyve/uefi-rom.bin
argv[10]: -l
argv[11]: com1,/dev/zconsole
argv[12]: -l
argv[13]: com2,socket,/tmp/vm.ttyb
argv[14]: -s
argv[15]: 0,hostbridge,model=i440fx
argv[16]: -c
argv[17]: 4
argv[18]: -m
argv[19]: 4096
argv[20]: -s
argv[21]: 0:4:0,virtio-blk,/dev/zvol/rdsk/zones/99e40ee7-a8f9-4b57-9225-e7bd19f64b07/disk0
argv[22]: -s
argv[23]: 6:0,virtio-net-viona,net0
argv[24]: -s
argv[25]: 6:1,virtio-net-viona,net1
argv[26]: -s
argv[27]: 6:2,virtio-net-viona,net2
argv[28]: -s
argv[29]: 6:3,virtio-net-viona,net3
argv[30]: -s
argv[31]: 6:4,virtio-net-viona,net4
argv[32]: -w
argv[33]: -c
argv[34]: sockets=1,cores=2,threads=2
argv[35]: SYSbhyve-12

Currently the nics are the only one that get passed without the bus, sure bhyve itself wil use 0 in that case. But given we pass it for all other arguments we add, we should be consistant.

}

if (ret >= sizeof (slotconf)) {
(void) printf("Error: net '%s' too long\n", net);
return (-1);
}
Expand Down