From owner-freebsd-emulation@FreeBSD.ORG Tue Jan 25 21:07:00 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 9180810657F0; Tue, 25 Jan 2011 21:07:00 +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 C03E38FC1F; Tue, 25 Jan 2011 21:06:59 +0000 (UTC) Received: by fxm16 with SMTP id 16so237834fxm.13 for ; Tue, 25 Jan 2011 13:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:references:x-comment-to:date :in-reply-to:message-id:user-agent:mime-version:content-type; bh=/nocpxit+w7vDvB9ObYdfyfGHM+8HG/4MJxyrIgFcGU=; b=QEK0SPUYjHcbJn2VNhOoUQDD6F5WJw9SIHONXs/rH8wYk9v+KghfVyCymRdkiNSloP w2Wx6wx413ZVcDIjTV3TMtr9tduVnWwZUl+ikI6MmiQcAOpn6tICwqpilrXYb5dmbDBX zGakzSyklEiCZ4UoKAxumgcfIHbumLaTt7IHA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:x-comment-to:date:in-reply-to :message-id:user-agent:mime-version:content-type; b=C03qhSeY67oO5YNMN6tZNLux9fg08FFFKCp948vKnTQGH0awSNwqVsTZv/NkcRn8yg ZWCCKZGkiwNIq9LtA1yi7UcBSRxc9PD+gxnbhaZO1LaHsGx+M0RYyf2xzkC08IDuCH7G Zz/MGb2CqP3k4z0I2c48Btv54KwSIvdpNzvoc= Received: by 10.223.86.80 with SMTP id r16mr836761fal.81.1295989618697; Tue, 25 Jan 2011 13:06:58 -0800 (PST) Received: from localhost ([95.69.174.185]) by mx.google.com with ESMTPS id y1sm5252357fak.15.2011.01.25.13.06.52 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 25 Jan 2011 13:06:54 -0800 (PST) From: Mikolaj Golub To: Julian Elischer References: <86oc77heqk.fsf@kopusha.home.net> <4D3D2DE9.2060004@freebsd.org> X-Comment-To: Julian Elischer Date: Tue, 25 Jan 2011 23:06:51 +0200 In-Reply-To: <4D3D2DE9.2060004@freebsd.org> (Julian Elischer's message of "Sun, 23 Jan 2011 23:44:41 -0800") Message-ID: <86tygwy9p0.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: freebsd-emulation@freebsd.org, freebsd-virtualization@freebsd.org Subject: Re: 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: Tue, 25 Jan 2011 21:07:00 -0000 --=-=-= On Sun, 23 Jan 2011 23:44:41 -0800 Julian Elischer wrote: JE> On 1/23/11 6:33 AM, Mikolaj Golub wrote: >> 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? JE> this is probably at east partially the correct solution. JE> Usually you should also set the value back to its previous value when JE> you leave that code as well. Thank you for the comments. Actually the patch contained CURVNET_RESTORE() too. I just did not mentioned it :-). So if it looks like right solution here is an "improved" version of the patch: vnet to switch is taken from thread's ucred (on interface initialization) or from ifp->if_vnet. >> 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: attachment; filename=VirtualBox-3.2.12.VIMAGE.1.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-25 22:48:26.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-25 22:48:26.000000000 +0200 @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ #include #include #include +#include #include #include @@ -322,6 +324,7 @@ static int ng_vboxnetflt_rcvdata(hook_p struct m_tag *mtag; bool fActive; + CURVNET_SET_QUIET(ifp->if_vnet); fActive = vboxNetFltTryRetainBusyActive(pThis); NGI_GET_M(item, m); @@ -346,6 +349,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 +367,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 +382,7 @@ static int ng_vboxnetflt_rcvdata(hook_p if (fActive) vboxNetFltRelease(pThis, true /*fBusy*/); + CURVNET_RESTORE(); return (0); } @@ -409,6 +415,7 @@ static void vboxNetFltFreeBSDinput(void bool fDropIt = false, fActive; PINTNETSG pSG; + CURVNET_SET_QUIET(ifp->if_vnet); vboxNetFltRetain(pThis, true /* fBusy */); for (;;) { @@ -438,6 +445,7 @@ static void vboxNetFltFreeBSDinput(void ether_demux(ifp, m); } vboxNetFltRelease(pThis, true /* fBusy */); + CURVNET_RESTORE(); } /** @@ -452,6 +460,7 @@ static void vboxNetFltFreeBSDoutput(void bool fDropIt = false, fActive; PINTNETSG pSG; + CURVNET_SET_QUIET(ifp->if_vnet); vboxNetFltRetain(pThis, true /* fBusy */); for (;;) { @@ -481,6 +490,7 @@ static void vboxNetFltFreeBSDoutput(void ether_output_frame(ifp, m); } vboxNetFltRelease(pThis, true /* fBusy */); + CURVNET_RESTORE(); } /** @@ -498,6 +508,7 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS int error; ifp = (void *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.ifp); + CURVNET_SET_QUIET(ifp->if_vnet); if (fDst & INTNETTRUNKDIR_WIRE) { @@ -539,6 +550,7 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS m->m_pkthdr.rcvif = ifp; ifp->if_input(ifp, m); } + CURVNET_RESTORE(); return VINF_SUCCESS; } @@ -556,6 +568,7 @@ int vboxNetFltOsInitInstance(PVBOXNETFLT node_p node; RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; + CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); NOREF(pvContext); ifp = ifunit(pThis->szName); if (ifp == NULL) @@ -602,6 +615,7 @@ int vboxNetFltOsInitInstance(PVBOXNETFLT pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */); vboxNetFltRelease(pThis, true /*fBusy*/); } + CURVNET_RESTORE(); return VINF_SUCCESS; } @@ -611,6 +625,7 @@ bool vboxNetFltOsMaybeRediscovered(PVBOX struct ifnet *ifp, *ifp0; ifp = (struct ifnet *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.ifp); + CURVNET_SET_QUIET(ifp->if_vnet); /* * Attempt to check if the interface is still there and re-initialize if * something has changed. @@ -628,6 +643,7 @@ bool vboxNetFltOsMaybeRediscovered(PVBOX vboxNetFltOsDeleteInstance(pThis); vboxNetFltOsInitInstance(pThis, NULL); } + CURVNET_RESTORE() return !ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost); } @@ -669,6 +685,7 @@ void vboxNetFltPortOsSetActive(PVBOXNETF Log(("%s: fActive:%d\n", __func__, fActive)); ifp = (struct ifnet *)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.ifp); + CURVNET_SET_QUIET(ifp->if_vnet); node = (node_p)ASMAtomicUoReadPtr((void * volatile *)&pThis->u.s.node); memset(&ifreq, 0, sizeof(struct ifreq)); @@ -742,6 +759,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) --=-=-=--