From owner-freebsd-net@FreeBSD.ORG Tue Oct 19 21:53:07 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 DC02F106564A for ; Tue, 19 Oct 2010 21:53:07 +0000 (UTC) (envelope-from onemda@gmail.com) Received: from mail-ew0-f54.google.com (mail-ew0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 71E608FC16 for ; Tue, 19 Oct 2010 21:53:07 +0000 (UTC) Received: by ewy21 with SMTP id 21so2135924ewy.13 for ; Tue, 19 Oct 2010 14:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=rNSTCfEz1Ov4rZg8TvZxJnjj5BCA6Q8yXOEc0Ggjgi0=; b=makUtbXqK0dcDuAC2pxbfbf5qlAwZ3uzpFcK5zcBWn7sHqgdcYxAbo44rQ1wQmky9j cz7lY4Mn4Hkr/0EJgUPkfugHkmVAgI8cpeHh2OuDhwbx8Qm83ax27bELyjMHkdA1eNcK pU+BY3jz79qa2aSu0EW/ydAIsGYpYjJrJ977c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=uiVj7BPZydmfJxjPlcio3KVLgDvbd6fllocJ6FOXcaOzImv5taKANfOrbA9KKljWe3 4TFIH+27i+yTLCisCSO+qAVhOqYCaDDb/6ONb1WQ0kaug2ieBqr3hL9S9diFKejx0Cdk KRxjnfAzQKq+ZB2WC3YC5DOveGfmhcS7/aAwk= MIME-Version: 1.0 Received: by 10.216.50.18 with SMTP id y18mr7246015web.113.1287525184813; Tue, 19 Oct 2010 14:53:04 -0700 (PDT) Received: by 10.216.183.146 with HTTP; Tue, 19 Oct 2010 14:53:04 -0700 (PDT) Date: Tue, 19 Oct 2010 21:53:04 +0000 Message-ID: From: Paul B Mahol To: net@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Cc: Subject: 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: Tue, 19 Oct 2010 21:53:07 -0000 Hi, First: we should pin curthread on CPU before we check on which CPU is curthread. Second: instead of sti & cli use critical sections when saving %fs register. 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. 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 { extern uint16_t x86_getfs(void); extern void x86_setfs(uint16_t); extern void *x86_gettid(void); -extern void x86_critical_enter(void); -extern void x86_critical_exit(void); extern void x86_getldt(struct gdt *, uint16_t *); extern void x86_setldt(struct gdt *, uint16_t); @@ -668,8 +666,10 @@ extern void x86_setldt(struct gdt *, uint16_t); void ctxsw_utow(void) { - struct tid *t; + struct tid *t; + sched_pin(); + critical_enter(); t = &my_tids[curthread->td_oncpu]; /* @@ -685,12 +685,9 @@ ctxsw_utow(void) if (t->tid_self != t) x86_newldt(NULL); - x86_critical_enter(); t->tid_oldfs = x86_getfs(); t->tid_cpu = curthread->td_oncpu; - sched_pin(); x86_setfs(SEL_TO_FS(t->tid_selector)); - x86_critical_exit(); /* Now entering Windows land, population: you. */ } @@ -706,11 +703,10 @@ ctxsw_wtou(void) { struct tid *t; - x86_critical_enter(); t = x86_gettid(); x86_setfs(t->tid_oldfs); + critical_exit(); sched_unpin(); - x86_critical_exit(); /* 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) ENTRY(x86_gettid) mov %fs:12,%eax ret - -ENTRY(x86_critical_enter) - cli - ret - -ENTRY(x86_critical_exit) - sti - ret