From owner-freebsd-emulation@FreeBSD.ORG Sun Jan 23 15:03:50 2011 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 26A4E10656CE for ; Sun, 23 Jan 2011 15:03:50 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id A498C8FC25 for ; Sun, 23 Jan 2011 15:03:49 +0000 (UTC) Received: by fxm16 with SMTP id 16so3493940fxm.13 for ; Sun, 23 Jan 2011 07:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:message-id:user-agent :mime-version:content-type; bh=nn/vtFP6yKz4TPT9uENg9bV2rfBnrtXCLOTlXQqpz+w=; b=LJ6720EwKNU5kYpEnHPBl7yyv+LVZ9TO5CXk5EFgcVYf2eME+IVncFbrW04OyPYlIo PhIF22uqA23sd9fFC4Bkg2+KFIzBOJ5Wm4sED5fdLmgGvwAsF44zkn59i6zmqXLrYmt4 ZdSNqcsLhM7ww5mzFOSboaAyepAnSiHwfE7vQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; b=rm+PHWzv10SRk2KZCEZlLa7keJw2IZoV43NjdSvkgw+YiPs6gCsa5zgzgmW23N9wog YU5UrYYN9jlStPeuiC2o48LShVl6DTUgCOm/h5gKG3/aLaRWtBSovg8K4ZQH8TzZnzpS ugSk+tl10msNgfQF13TazwFOuQQPXiyDQc5nY= Received: by 10.223.86.196 with SMTP id t4mr3049464fal.34.1295793191579; Sun, 23 Jan 2011 06:33:11 -0800 (PST) Received: from localhost ([95.69.174.185]) by mx.google.com with ESMTPS id r24sm4223665fax.27.2011.01.23.06.33.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 23 Jan 2011 06:33:10 -0800 (PST) From: Mikolaj Golub To: freebsd-virtualization@FreeBSD.org, freebsd-emulation@freebsd.org Date: Sun, 23 Jan 2011 16:33:07 +0200 Message-ID: <86oc77heqk.fsf@kopusha.home.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Cc: Subject: VirtualBox + VIMAGE X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jan 2011 15:03:50 -0000 --=-=-= Hi, Sorry for cross posting, but this question concerns both VirtualBox and VIMAGE :-). I would like to be able to run VirtualBox on my desktop, with kernel compilled with VIMAGE, so I would use light vnet jails for FreeBSD VMs and VirtualBox for other OSes. Currently the system will crash if you try to use VirtualBox bridged networking under VIMAGE kernel. The crash may look like below: db> bt Tracing pid 2349 tid 100239 td 0xc984b2d0 ifunit(c7e3b9ac,6f,c129e970,f8089984,c08d6dc0,...) at ifunit+0x33 vboxNetFltOsInitInstance(c7e3b810,0,8,7,c9aa6ae0,...) at vboxNetFltOsInitInstance+0x31 vboxNetFltFactoryCreateAndConnect(c9aa8cc8,c96636d4,c9664010,0,c966403c,...) at vboxNetFltFactory CreateAndConnect+0x1f7 _end(c7b11810,c962c238,3,c962c2b8,0,...) at 0xc9c0114f _end(c7b11810,c962c22c,f20,c0d31268,f8089a90,...) at 0xc9c01265 _end(c962c22c,0,0,c7b11810,c0cfe2fe,...) at 0xc9bbc775 _end(f808a000,fffffffd,28,c962c22c,0,...) at 0xc9bbd086 supdrvIOCtl(c10c5607,c12a0a40,c7b11810,c962c200,c0e81df8,...) at supdrvIOCtl+0x1af1 VBoxDrvFreeBSDIOCtl(c94efb00,c10c5607,c962c200,3,c984b2d0,...) at VBoxDrvFreeBSDIOCtl+0x1ea devfs_ioctl_f(c8e70118,c10c5607,c962c200,c9a82900,c984b2d0,...) at devfs_ioctl_f+0x10b kern_ioctl(c984b2d0,e,c10c5607,c962c200,1089cec,...) at kern_ioctl+0x1fd ioctl(c984b2d0,f8089cec,2b077000,1,c94ed2a8,...) at ioctl+0x134 syscallenter(c984b2d0,f8089ce4,c0c20e2d,c0e83290,0,...) at syscallenter+0x2a6 syscall(f8089d28) at syscall+0x4f Xint0x80_syscall() at Xint0x80_syscall+0x21 --- syscall (54, FreeBSD ELF32, ioctl), eip = 0x282ae093, esp = 0xbf8b980c, ebp = 0xbf8b9828 --- So it crashes when a function (ifunit in this case) tries to access virtualized variable (V_ifnet in this case). The macro uses td->td_vnet for this, which should be set to current vnet, but for VBox driver threads it is NULL. As a quick fix I added in VBoxNetFlt-freebsd.c in all "problem" functions CURVNET_SET_QUIET(vnet0) macro, which sets td->td_vnet to default vnet (see the attached patch). This has fixed the issue for me and now I am happily running both VNET jails and VirtualBox machines on my desktop. But the way I fixed the issue looks hackish for me. Could someone suggest a better solution? In case someone is interested in trying this patch, below are the instructions how to build "VIMAGE safe" vbox driver from ports: cd /usr/ports/emulators/virtualbox-ose-kmod make patch cd work patch -p0 < /path/to/VirtualBox-3.2.12.VIMAGE.patch cd .. VIMAGE=1 make -- Mikolaj Golub --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=VirtualBox-3.2.12.VIMAGE.patch diff -rpu VirtualBox-3.2.12_OSE.orig/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile VirtualBox-3.2.12_OSE/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile --- VirtualBox-3.2.12_OSE.orig/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile 2010-12-01 19:09:33.000000000 +0200 +++ VirtualBox-3.2.12_OSE/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile 2011-01-23 12:44:24.000000000 +0200 @@ -26,6 +26,10 @@ CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DI CFLAGS += -DRT_ARCH_AMD64 .endif +.if defined(VIMAGE) + CFLAGS += -DVIMAGE +.endif + SRCS = \ VBoxNetFlt-freebsd.c \ VBoxNetFlt.c \ diff -rpu VirtualBox-3.2.12_OSE.orig/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c VirtualBox-3.2.12_OSE/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c --- VirtualBox-3.2.12_OSE.orig/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c 2010-12-01 19:09:33.000000000 +0200 +++ VirtualBox-3.2.12_OSE/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c 2011-01-23 12:14:19.000000000 +0200 @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -322,6 +323,7 @@ static int ng_vboxnetflt_rcvdata(hook_p struct m_tag *mtag; bool fActive; + CURVNET_SET_QUIET(vnet0); fActive = vboxNetFltTryRetainBusyActive(pThis); NGI_GET_M(item, m); @@ -346,6 +348,7 @@ static int ng_vboxnetflt_rcvdata(hook_p ether_demux(ifp, m); if (fActive) vboxNetFltRelease(pThis, true /*fBusy*/); + CURVNET_RESTORE(); return (0); } mtx_lock_spin(&pThis->u.s.inq.ifq_mtx); @@ -363,6 +366,7 @@ static int ng_vboxnetflt_rcvdata(hook_p int rc = ether_output_frame(ifp, m); if (fActive) vboxNetFltRelease(pThis, true /*fBusy*/); + CURVNET_RESTORE(); return rc; } mtx_lock_spin(&pThis->u.s.outq.ifq_mtx); @@ -377,6 +381,7 @@ static int ng_vboxnetflt_rcvdata(hook_p if (fActive) vboxNetFltRelease(pThis, true /*fBusy*/); + CURVNET_RESTORE(); return (0); } @@ -409,6 +414,7 @@ static void vboxNetFltFreeBSDinput(void bool fDropIt = false, fActive; PINTNETSG pSG; + CURVNET_SET_QUIET(vnet0); vboxNetFltRetain(pThis, true /* fBusy */); for (;;) { @@ -438,6 +444,7 @@ static void vboxNetFltFreeBSDinput(void ether_demux(ifp, m); } vboxNetFltRelease(pThis, true /* fBusy */); + CURVNET_RESTORE(); } /** @@ -452,6 +459,7 @@ static void vboxNetFltFreeBSDoutput(void bool fDropIt = false, fActive; PINTNETSG pSG; + CURVNET_SET_QUIET(vnet0); vboxNetFltRetain(pThis, true /* fBusy */); for (;;) { @@ -481,6 +489,7 @@ static void vboxNetFltFreeBSDoutput(void ether_output_frame(ifp, m); } vboxNetFltRelease(pThis, true /* fBusy */); + CURVNET_RESTORE(); } /** @@ -497,6 +506,7 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS bool fActive; int error; + CURVNET_SET_QUIET(vnet0); ifp = (void *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.ifp); if (fDst & INTNETTRUNKDIR_WIRE) @@ -539,6 +549,7 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS m->m_pkthdr.rcvif = ifp; ifp->if_input(ifp, m); } + CURVNET_RESTORE(); return VINF_SUCCESS; } @@ -556,6 +567,7 @@ int vboxNetFltOsInitInstance(PVBOXNETFLT node_p node; RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; + CURVNET_SET_QUIET(vnet0); NOREF(pvContext); ifp = ifunit(pThis->szName); if (ifp == NULL) @@ -602,6 +614,7 @@ int vboxNetFltOsInitInstance(PVBOXNETFLT pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */); vboxNetFltRelease(pThis, true /*fBusy*/); } + CURVNET_RESTORE(); return VINF_SUCCESS; } @@ -610,6 +623,7 @@ bool vboxNetFltOsMaybeRediscovered(PVBOX { struct ifnet *ifp, *ifp0; + CURVNET_SET_QUIET(vnet0); ifp = (struct ifnet *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.ifp); /* * Attempt to check if the interface is still there and re-initialize if @@ -628,6 +642,7 @@ bool vboxNetFltOsMaybeRediscovered(PVBOX vboxNetFltOsDeleteInstance(pThis); vboxNetFltOsInitInstance(pThis, NULL); } + CURVNET_RESTORE() return !ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost); } @@ -667,6 +682,7 @@ void vboxNetFltPortOsSetActive(PVBOXNETF char path[NG_PATHSIZ]; Log(("%s: fActive:%d\n", __func__, fActive)); + CURVNET_SET_QUIET(vnet0); ifp = (struct ifnet *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.ifp); node = (node_p)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.node); @@ -742,6 +758,7 @@ void vboxNetFltPortOsSetActive(PVBOXNETF strlcpy(rm->ourhook, "output", NG_HOOKSIZ); NG_SEND_MSG_PATH(error, node, msg, path, 0); } + CURVNET_RESTORE(); } int vboxNetFltOsDisconnectIt(PVBOXNETFLTINS pThis) --=-=-=--