Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Oct 2010 19:52:05 +0200
From:      Bernhard Schmidt <bschmidt@freebsd.org>
To:        Paul B Mahol <onemda@gmail.com>
Cc:        net@freebsd.org
Subject:   Re: ndis: patch for review
Message-ID:  <AANLkTikknK1BcUDRWWSsBvOjaRz9ZVwSMAukisNWzyHV@mail.gmail.com>
In-Reply-To: <AANLkTin6Pt-SbUPJ=gdZw=4Fym8MayoQOYkupGrikxMY@mail.gmail.com>
References:  <AANLkTin6Pt-SbUPJ=gdZw=4Fym8MayoQOYkupGrikxMY@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
9, 2010 at 23:53, Paul B Mahol <onemda@gmail.com> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTikknK1BcUDRWWSsBvOjaRz9ZVwSMAukisNWzyHV>