From owner-freebsd-virtualization@FreeBSD.ORG Thu Feb 3 10:51:25 2011 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 108301065670; Thu, 3 Feb 2011 10:51:25 +0000 (UTC) (envelope-from monthadar@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 6C9468FC0A; Thu, 3 Feb 2011 10:51:24 +0000 (UTC) Received: by wwf26 with SMTP id 26so974487wwf.31 for ; Thu, 03 Feb 2011 02:51:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=DU2PNzljiAOOEJ8PbSIiHLerOR3EXyhQIs/OG2WQ3XE=; b=e1UjcChpR3usrVdXy0vyg2H5vHwvjUJk3DeJ71rhWOQ4AAxuiHelX7w+oMZacP48cA iQ6CGi4Q3sX41p9BvfMZHM41vQbDsp1hYJE91zlVWsOvfktmNpg+vCSjI9nD0JpMe+xF MLcGTHuIa7jKtqpc7Yo+n71uS+erHVXigk5t0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=lrUdrBiGn9W1NYVUTnMkaGqSGOaPoZ9JFBz+sxuu3d2UmqL9WMqKf+9B/0B87uPEKj 2CZlXxIi5OTktdI9BtVbXMlMvkMKhXGxNHZzKe7QU1AghSxlynM8DoO0YW3UA+t5Vzxu NIjwFr/cgmURcZng744GR5BBZAyK0AHeW5fXI= MIME-Version: 1.0 Received: by 10.227.143.11 with SMTP id s11mr10442002wbu.21.1296730283145; Thu, 03 Feb 2011 02:51:23 -0800 (PST) Received: by 10.227.134.137 with HTTP; Thu, 3 Feb 2011 02:51:23 -0800 (PST) In-Reply-To: <20110203095019.N80258@maildrop.int.zabbadoz.net> References: <4D484213.6050100@freebsd.org> <4D486108.5060805@freebsd.org> <20110202164827.I80258@maildrop.int.zabbadoz.net> <4D4994CE.2090209@freebsd.org> <4D49AB29.7070909@freebsd.org> <20110203095019.N80258@maildrop.int.zabbadoz.net> Date: Thu, 3 Feb 2011 11:51:23 +0100 Message-ID: From: Monthadar Al Jaberi To: "Bjoern A. Zeeb" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD virtualization mailing list Subject: Re: simulating wireless device (if_alloc panic, VirtualBox, VIMAGE) X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Feb 2011 10:51:25 -0000 On Thu, Feb 3, 2011 at 10:55 AM, Bjoern A. Zeeb wrote: > On Thu, 3 Feb 2011, Monthadar Al Jaberi wrote: > >> On Wed, Feb 2, 2011 at 8:06 PM, Julian Elischer >> wrote: >>> >>> On 2/2/11 10:05 AM, Monthadar Al Jaberi wrote: >>>> >>>> I just tried something that seems to work, but please dont hit me ^^;;= ; >>>> >>>> in wtap_ioctl I assigned curthread->td_vnet myself to point to a VNET >>>> (saved it when the module first loaded) (I have not created any jails >>>> yet)... and it works... I didnt put any CURVNET macros... >>> >>> td->td_vnet is exactly what the CURVNET_SET macro sets. >>> You should use the Macros because we may change the place where we stor= e >>> it. >>> >>> The vnet for the current thread is picked up from several places >>> depending >>> on the context, >>> and it is cleared again when it is not needed. =A0the V_xxx usages in t= he >>> code >>> end up being >>> in effect expanded to curthread->td_vnet.xxx, where each 'xxx' is sort = of >>> like an element in a structure >>> but not quite. >>> >>> Now, theoretically we could just leave it set all the time but then it >>> would >>> be nearly impossible >>> to find places where we should have changed it, but forgot and just got >>> the >>> existing one. >>> >>> if you want to find the correct place to go, then look at the vnet of t= he >>> calling process >>> which should be in the process cred. or just use vnet0. >> >> Can I check it from user space? >> >>> >>> I don't understand why you saw a CRED_TO_VNET of 0 >>> I was under the impression that every process/thread in the system woul= d >>> be >>> on vnet0 >>> in a vimage kernel. >> >> This is how my printf looks like: >> struct thread *td =3D curthread; >> struct vnet *v =3D TD_TO_VNET(td); >> struct ucred *cred =3D CRED_TO_VNET(td->ucred); >> struct vnet *td_vnet =3D td->td_vnet; > > here's your problem: > > strcut vnet *vnet =3D cred->cr_prison->pr_vnet; When I add CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); I get a panic to= o... But your suggestion works if I do like this: curthread->td_vnet =3D curthread->td_ucred->cr_prison->pr_vnet; CRED_TO_VNET(curthread->td_ucred) returns NULL > > >> printf("td=3D%p, td->td_vnet=3D%p, td->td_ucred=3D%p, TD_TO_VNET=3D%p, >> CRED_TO_VNET=3D%p\n", td, td_vnet, td->td_ucred, v, cred); >> >> I made a fast search in /usr/src for "td_vnet" and found it was >> assigned only in >> int fork1(td, flags, pages, procp): >> #ifdef VIMAGE >> =A0 =A0 =A0 =A0td2->td_vnet =3D NULL; >> =A0 =A0 =A0 =A0td2->td_vnet_lpush =3D NULL; >> #endif > > Nice try. =A0Want another search? =A0Hint: there is this in vnet.h: > > #define curvnet curthread->td_vnet > > And then you'll, again, find the CURVNET_SET_* macros. Thank you > > > >> Maybe something wrong with how I declare my wtap_ioctl: >> >> static struct cdevsw wtap_cdevsw =3D { >> =A0 =A0 =A0 =A0.d_version =3D =A0 =A0D_VERSION, >> =A0 =A0 =A0 =A0.d_flags =3D =A0 =A0 =A00, >> =A0 =A0 =A0 =A0.d_ioctl =3D =A0 =A0 =A0wtap_ioctl, >> =A0 =A0 =A0 =A0.d_name =3D =A0 =A0 =A0 "wtapctl", >> }; >> ... >> make_dev(&wtap_cdevsw,0,UID_ROOT,GID_WHEEL,0600,(const char *)"wtapctl")= ; >> >>> >>> your stored vnet idea is ok as well, but may go strange if you load the >>> driver from a vnet jail >>> and then remove the jail. >> >> Ok, will document it in the code for now >> >>> >>> >>> >>> >>>> my assumption is that if ath drivers dont use VNET I shouldnt :P >>>> >>>> What is wrong with this hack? >>>> >>>> br, >>>> >>>> P.S. I have printed "porting to vnet" text to have it always at hand, >>>> but its a bit hard for me... doing my best. >>>> >>>> On Wed, Feb 2, 2011 at 6:30 PM, Julian Elischer >>>> =A0wrote: >>>>> >>>>> On 2/2/11 9:12 AM, Bjoern A. Zeeb wrote: >>>>>> >>>>>> On Wed, 2 Feb 2011, Monthadar Al Jaberi wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>>> Thanx makes more sense, but I have noticed something weired if you >>>>>>> can >>>>>>> shade some light on. >>>>>>> >>>>>>> I added printfs one when the module is first loaded (static int >>>>>>> event_handler(module_t module, int event, void *arg)): >>>>>>> curthread=3D0xc3f95870 >>>>>>> curthread->td_vnet=3D0xc3170e00 >>>>>>> curthread->td_ucred=3D0xc3185d00 >>>>>>> TD_TO_VNET=3D0 >>>>>>> CRED_TO_VNET=3D0 >>>>>> >>>>>> Try to load it from laoder on boot; I think that should work as we a= re >>>>>> setting the curvent for the kernel startup. >>>>>> >>>>>> The problem you are seeing is a bug in the current implementation th= at >>>>>> you cannot add any physical network interface after the kernel >>>>>> started. >>>>>> This applies to cardbus/usb/... as well as any kind of ethernet >>>>>> interface, so a kldload igb should yield it as well. >>>>>> >>>>>> The fix for that is easy and hard at the same time: >>>>>> A) either touch all drivers >>>>>> B) or touch all cloned interfaces and change 3 common lines. >>>>>> =A0 or try to make cloners aware of vimages. >>>>>> >>>>>> Solution B) is sitting in perforce with the entire stuff that it >>>>>> depends >>>>>> on and was started with CH=3D179022,179255 but not limited to that i= f >>>>>> you >>>>>> want to have a peek. >>>>>> >>>>>> What you certainly can do locally to your driver for now is to make = a >>>>>> change like this: >>>>>> >>>>>> +#ifdef VIMAGE >>>>>> + =A0 =A0 =A0 CURVNET_SET(vnet0); >>>>>> +#endif >>>>>> =A0 =A0 =A0 =A0ifp =3D if_alloc(IFT_ETHER); >>>>>> +#ifdef VIMAGE >>>>>> + =A0 =A0 =A0 CURVNET_RESTORE(); >>>>>> +#endif >>>>>> >>>>> you don't really need =A0the #ifdef except for readability as CURVNET= _XXX >>>>> ar >>>>> enot defined for !vnet >>>>> >>>>>> It's the type A) kind of change from above that will break eventuall= y >>>>>> in the future. >>>>>> >>>>>> /bz >>>>>> >>>>> >>>> >>>> >>> >>> >> >> >> >> > > -- > Bjoern A. Zeeb =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 You have to have visions! > =A0 =A0 =A0 =A0 Going to jail sucks -- All my daemons like it! > =A0http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails.html --=20 //Monthadar Al Jaberi