From owner-freebsd-net@FreeBSD.ORG Wed Oct 20 17:52:06 2010 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B19EF1065675 for ; Wed, 20 Oct 2010 17:52:06 +0000 (UTC) (envelope-from bschmidt@techwires.net) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id 777AB8FC22 for ; Wed, 20 Oct 2010 17:52:06 +0000 (UTC) Received: by qwe4 with SMTP id 4so2509486qwe.13 for ; Wed, 20 Oct 2010 10:52:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.95.66 with SMTP id c2mr6752712qcn.85.1287597125485; Wed, 20 Oct 2010 10:52:05 -0700 (PDT) Sender: bschmidt@techwires.net Received: by 10.229.41.198 with HTTP; Wed, 20 Oct 2010 10:52:05 -0700 (PDT) X-Originating-IP: [84.180.206.219] In-Reply-To: References: Date: Wed, 20 Oct 2010 19:52:05 +0200 X-Google-Sender-Auth: w87cfAwpicUhMo5pbl50LqsV0Dk Message-ID: From: Bernhard Schmidt To: Paul B Mahol Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: net@freebsd.org Subject: Re: ndis: patch for review X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Oct 2010 17:52:06 -0000 9, 2010 at 23:53, Paul B Mahol wrote: > Hi, > > First: we should pin curthread on CPU before we check on which CPU is cur= thread. > > Second: instead of sti & cli use critical sections when saving %fs regist= er. > > Third: I do not know what happens if we get preempted while windows > code were running, > so leave critical section only _after_ executing windows code. Do you have a test case for that? If so, can you post it? > diff --git a/sys/compat/ndis/kern_windrv.c b/sys/compat/ndis/kern_windrv.= c > index f231863..ba29fd2 100644 > --- a/sys/compat/ndis/kern_windrv.c > +++ b/sys/compat/ndis/kern_windrv.c > @@ -613,8 +613,6 @@ struct gdt { > =A0extern uint16_t =A0 =A0 =A0 =A0x86_getfs(void); > =A0extern void x86_setfs(uint16_t); > =A0extern void *x86_gettid(void); > -extern void x86_critical_enter(void); > -extern void x86_critical_exit(void); > =A0extern void x86_getldt(struct gdt *, uint16_t *); > =A0extern void x86_setldt(struct gdt *, uint16_t); > > @@ -668,8 +666,10 @@ extern void x86_setldt(struct gdt *, uint16_t); > =A0void > =A0ctxsw_utow(void) > =A0{ > - =A0 =A0 =A0 struct tid =A0 =A0 =A0 =A0 =A0 =A0 =A0*t; > + =A0 =A0 =A0 struct tid *t; > > + =A0 =A0 =A0 sched_pin(); > + =A0 =A0 =A0 critical_enter(); > =A0 =A0 =A0 =A0t =3D &my_tids[curthread->td_oncpu]; > > =A0 =A0 =A0 =A0/* > @@ -685,12 +685,9 @@ ctxsw_utow(void) > =A0 =A0 =A0 =A0if (t->tid_self !=3D t) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0x86_newldt(NULL); > > - =A0 =A0 =A0 x86_critical_enter(); > =A0 =A0 =A0 =A0t->tid_oldfs =3D x86_getfs(); > =A0 =A0 =A0 =A0t->tid_cpu =3D curthread->td_oncpu; > - =A0 =A0 =A0 sched_pin(); > =A0 =A0 =A0 =A0x86_setfs(SEL_TO_FS(t->tid_selector)); > - =A0 =A0 =A0 x86_critical_exit(); > > =A0 =A0 =A0 =A0/* Now entering Windows land, population: you. */ > =A0} > @@ -706,11 +703,10 @@ ctxsw_wtou(void) > =A0{ > =A0 =A0 =A0 =A0struct tid =A0 =A0 =A0 =A0 =A0 =A0 =A0*t; > > - =A0 =A0 =A0 x86_critical_enter(); > =A0 =A0 =A0 =A0t =3D x86_gettid(); > =A0 =A0 =A0 =A0x86_setfs(t->tid_oldfs); > + =A0 =A0 =A0 critical_exit(); > =A0 =A0 =A0 =A0sched_unpin(); > - =A0 =A0 =A0 x86_critical_exit(); > > =A0 =A0 =A0 =A0/* Welcome back to UNIX land, we missed you. */ > > diff --git a/sys/compat/ndis/winx32_wrap.S b/sys/compat/ndis/winx32_wrap.= S > index c051504..fa4aa87 100644 > --- a/sys/compat/ndis/winx32_wrap.S > +++ b/sys/compat/ndis/winx32_wrap.S > @@ -375,11 +375,3 @@ ENTRY(x86_setfs) > =A0ENTRY(x86_gettid) > =A0 =A0 =A0 =A0mov =A0 =A0 %fs:12,%eax > =A0 =A0 =A0 =A0ret > - > -ENTRY(x86_critical_enter) > - =A0 =A0 =A0 cli > - =A0 =A0 =A0 ret > - > -ENTRY(x86_critical_exit) > - =A0 =A0 =A0 sti > - =A0 =A0 =A0 ret > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" > --=20 Bernhard