Bug 256505

Summary: emulators/virtualbox-ose: rc script vboxnet hangs FreeBSD
Product: Ports & Packages Reporter: O. Hartmann <ohartmann>
Component: Individual Port(s)Assignee: Virtualbox Team (Nobody) <vbox>
Status: Closed FIXED    
Severity: Affects Only Me CC: grahamperrin, junchoon, madpilot, xxjack12xx
Priority: --- Flags: madpilot: maintainer-feedback+
madpilot: merge-quarterly+
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
kldload patch none

Description O. Hartmann 2021-06-09 17:23:41 UTC
Running recent CURRENT and 13-STABLE on several boxes, we realised that in case where /etc/rc.conf.local has vboxnet_enable="YES" or exists "kld_list"... vboxnet" FreeBSD 13-STABLE or 14-CURRENT hangs idefinitely, hitting Ctrl-C on console exits the rogue script and booting proceeds.

CURRENT is FreeBSD 14.0-CURRENT #30 main-n247192-002cbc89c36: Sat Jun  5 20:31:11 CEST 2021 and recent of today, 13-STABLE also from today.
Comment 1 Guido Falsi freebsd_committer freebsd_triage 2021-06-09 18:36:52 UTC
Hi,

I'm observing the same. If you interrupt the loading and then launch it again it works fine afterwards. I wrote to the mailing lists about this:

https://lists.freebsd.org/archives/freebsd-emulation/2021-June/000004.html

Unluckily I got no reply.

I also have no clue what could be causing this.

Maybe a kernel bisect could help identify what change causes this. I'm unable to perform this at present.
Comment 2 Tomoaki AOKI 2021-06-10 13:51:44 UTC
just a thought, as I have not enough time to bisect, but maybe

  (For stable/13) git 620a48f64d08
  (For main) git e266a0f7f001

broke this.

In /usr/local/etc/rc.d/vboxnet function vboxnet_start(), components in
vboxnet_modules="vboxdrv vboxnetflt:ng_vboxnetflt vboxnetadp"
are expanded to

 (for vboxdrv)
  _k= vboxdrv
  _m= vboxdrv

 (for vboxnetflt:ng_vboxnetflt)
  _k= vboxnetflt
  _m= ng_vboxnetflt

 (for vboxnetadp)
  _k= vboxnetadp
  _m= vboxnetadp

and only `kldstat -m ng_vboxnetflt` fails even if vboxnetflt.ko is loaded.

As there's no ng_vboxnetflt.ko, I suspect vboxnetflt.ko makes simultaneous multiple kldload syscall (not dug into sources, so just a thought) and hit by the commit.
Comment 3 Guido Falsi freebsd_committer freebsd_triage 2021-06-10 15:09:54 UTC
(In reply to Tomoaki AOKI from comment #2)
Thankss, good finding I think you're on to something.

While the ng_ prefix is due to the ko file having a name but registering with another (it actually is a netgraph node after all).

It does perform a kern_kldload() call in it's own module handler.

I'm not a netgraph expert and this requires some studying. Looks like that kern_kldload call needs to be removed in some way.

(relevant file in virtualbox distribution is "src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c")
Comment 4 Guido Falsi freebsd_committer freebsd_triage 2021-06-10 17:40:28 UTC
After some studying, they are using kern_kldload() insside their own module to depend on ng_ether, because that node used to miss versioning and could not be properly depended upon.

This has been fixed a long time ago though, in base 39b553cea050ec

So I guess the correct solution is to use a proper dependency, which is what I'm testing.
Comment 5 Guido Falsi freebsd_committer freebsd_triage 2021-06-11 13:38:44 UTC
Created attachment 225737 [details]
kldload patch

I created review D30722 with the patch.

It works fine for me, but I'd rather have some testing feedback before committing. Could you test it and report back?

I'm also attaching the patch here.
Comment 6 Guido Falsi freebsd_committer freebsd_triage 2021-06-11 13:51:16 UTC
BTW this should also be merged to the quarterly branch, so I'm marking the bug report as such.
Comment 7 Graham Perrin freebsd_committer freebsd_triage 2021-06-12 00:31:51 UTC
Also slightly earlier bug 256501
Comment 8 Tomoaki AOKI 2021-06-12 01:30:23 UTC
(In reply to Guido Falsi from comment #5)

Thanks! This fixed the issue on base stable/13 ca81bcbbf118 for me.
Not tested for other branch, as I have vbox installed only on stable/13.

BTW, actually, I applied slightly fixed (just to be applicable) patch on D30722.
It specified new file name conversion for original, too.
Patch here looks OK.
Comment 9 Tomoaki AOKI 2021-06-12 01:33:55 UTC
(In reply to Graham Perrin from comment #7)

It would be better marked as a duplicate of this.
It has no patch or workaround until now.
Comment 10 Guido Falsi freebsd_committer freebsd_triage 2021-06-12 07:55:53 UTC
*** Bug 256501 has been marked as a duplicate of this bug. ***
Comment 11 Guido Falsi freebsd_committer freebsd_triage 2021-06-12 07:58:50 UTC
(In reply to Tomoaki AOKI from comment #9)

It's actually the same patch, generated from the same git branch, only this is generated with `git patch >file` and the other one was generated by arc, don't know if the two things handle renames differently. Anyway yes, what I put in the review better represents what I'm actually doing.
Comment 12 commit-hook freebsd_committer freebsd_triage 2021-06-14 18:56:31 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=082999790a64a5e64a3faa133e8d2d06bf2aff61

commit 082999790a64a5e64a3faa133e8d2d06bf2aff61
Author:     Guido Falsi <madpilot@FreeBSD.org>
AuthorDate: 2021-06-14 18:47:06 +0000
Commit:     Guido Falsi <madpilot@FreeBSD.org>
CommitDate: 2021-06-14 18:55:28 +0000

    emulators/virtualbox-ose-kmod: Fix hang at module loading time

    After src commit e266a0f7f001 a module is not allowed to call
    kern_kldload while being loaded. The virtualbox module is doing
    exactly this though. virutalbox used to do this because the ng_ether
    netgraph node did not provide version information in the past and
    there was no way to properly depend on it.

    ng_ether has gained versioning information in base r238844 more
    than ten years ago, so we can now unconditionally properly depend
    on it, since this revision is now included in all supported FreeBSD
    versions.

    Thanks to Tomoaki AOKI for identifying the base commuit exposing
    the issue.
    PR:                     256505
    Tested by:              Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
    MFH:                    2021Q2
    Differential Revision:  https://reviews.freebsd.org/D30722

 emulators/virtualbox-ose-kmod/Makefile             |  1 +
 ...rivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c} | 59 ++++++++++++++--------
 2 files changed, 39 insertions(+), 21 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2021-06-14 18:59:33 UTC
A commit in branch 2021Q2 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=758e045e3a8137842c72d35514c76b6d7f31c06b

commit 758e045e3a8137842c72d35514c76b6d7f31c06b
Author:     Guido Falsi <madpilot@FreeBSD.org>
AuthorDate: 2021-06-14 18:47:06 +0000
Commit:     Guido Falsi <madpilot@FreeBSD.org>
CommitDate: 2021-06-14 18:57:31 +0000

    emulators/virtualbox-ose-kmod: Fix hang at module loading time

    After src commit e266a0f7f001 a module is not allowed to call
    kern_kldload while being loaded. The virtualbox module is doing
    exactly this though. virutalbox used to do this because the ng_ether
    netgraph node did not provide version information in the past and
    there was no way to properly depend on it.

    ng_ether has gained versioning information in base r238844 more
    than ten years ago, so we can now unconditionally properly depend
    on it, since this revision is now included in all supported FreeBSD
    versions.

    Thanks to Tomoaki AOKI for identifying the base commuit exposing
    the issue.
    PR:                     256505
    Tested by:              Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
    MFH:                    2021Q2
    Differential Revision:  https://reviews.freebsd.org/D30722

    (cherry picked from commit 082999790a64a5e64a3faa133e8d2d06bf2aff61)

 ...rivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c} | 59 ++++++++++++++--------
 1 file changed, 38 insertions(+), 21 deletions(-)
Comment 14 Guido Falsi freebsd_committer freebsd_triage 2021-06-14 19:00:39 UTC
Patch committed and merged to quarterly.

Thanks for help and testing!
Comment 15 commit-hook freebsd_committer freebsd_triage 2021-06-14 20:02:45 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=354344ce8af17e5b6d85109120af5c6584ae642c

commit 354344ce8af17e5b6d85109120af5c6584ae642c
Author:     Guido Falsi <madpilot@FreeBSD.org>
AuthorDate: 2021-06-14 19:59:05 +0000
Commit:     Guido Falsi <madpilot@FreeBSD.org>
CommitDate: 2021-06-14 20:02:23 +0000

    emulators/virtualbox-ose-kmod-legacy: Fix hang at module loading time

    After src commit e266a0f7f001 a module is not allowed to call
    kern_kldload while being loaded. The virtualbox module is doing
    exactly this though. virutalbox used to do this because the ng_ether
    netgraph node did not provide version information in the past and
    there was no way to properly depend on it.

    ng_ether has gained versioning information in base r238844 more
    than ten years ago, so we can now unconditionally properly depend
    on it, since this revision is now included in all supported FreeBSD
    versions.

    Thanks to Tomoaki AOKI for identifying the base commuit exposing
    the issue.

    Backport fix to legacy port.

    WHile here also merge a double patch for the smae file.

    PR:             256505
    MFH:            2021Q2

 emulators/virtualbox-ose-kmod-legacy/Makefile      |   2 +-
 ...-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c (gone) | 273 -------------------
 ...Drivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c | 292 ++++++++++++++++++++-
 3 files changed, 289 insertions(+), 278 deletions(-)
Comment 16 commit-hook freebsd_committer freebsd_triage 2021-06-14 20:05:48 UTC
A commit in branch 2021Q2 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=68c14fd975f54e546c2bfbe4adc79126be268efe

commit 68c14fd975f54e546c2bfbe4adc79126be268efe
Author:     Guido Falsi <madpilot@FreeBSD.org>
AuthorDate: 2021-06-14 19:59:05 +0000
Commit:     Guido Falsi <madpilot@FreeBSD.org>
CommitDate: 2021-06-14 20:05:17 +0000

    emulators/virtualbox-ose-kmod-legacy: Fix hang at module loading time

    After src commit e266a0f7f001 a module is not allowed to call
    kern_kldload while being loaded. The virtualbox module is doing
    exactly this though. virutalbox used to do this because the ng_ether
    netgraph node did not provide version information in the past and
    there was no way to properly depend on it.

    ng_ether has gained versioning information in base r238844 more
    than ten years ago, so we can now unconditionally properly depend
    on it, since this revision is now included in all supported FreeBSD
    versions.

    Thanks to Tomoaki AOKI for identifying the base commuit exposing
    the issue.

    Backport fix to legacy port.

    WHile here also merge a double patch for the smae file.

    PR:             256505
    MFH:            2021Q2
    (cherry picked from commit 354344ce8af17e5b6d85109120af5c6584ae642c)

 emulators/virtualbox-ose-kmod-legacy/Makefile      |   2 +-
 ...-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c (gone) | 273 -------------------
 ...Drivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c | 292 ++++++++++++++++++++-
 3 files changed, 289 insertions(+), 278 deletions(-)