From owner-p4-projects@FreeBSD.ORG Fri Jun 23 19:12:38 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2D9DA16A49E; Fri, 23 Jun 2006 19:12:38 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E50EB16A492 for ; Fri, 23 Jun 2006 19:12:37 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2D83343D5A for ; Fri, 23 Jun 2006 19:12:32 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k5NJCVN0044241 for ; Fri, 23 Jun 2006 19:12:32 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k5NJCVRS044238 for perforce@freebsd.org; Fri, 23 Jun 2006 19:12:31 GMT (envelope-from jhb@freebsd.org) Date: Fri, 23 Jun 2006 19:12:31 GMT Message-Id: <200606231912.k5NJCVRS044238@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 99888 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jun 2006 19:12:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=99888 Change 99888 by jhb@jhb_mutex on 2006/06/23 19:12:01 - Add an sx lock to protect the list of linux ioctl handlers. - Punt and just hold Giant while calling ioctl handlers for now. - linux_ioctl() is now MPSAFE. Affected files ... .. //depot/projects/smpng/sys/amd64/linux32/syscalls.master#11 edit .. //depot/projects/smpng/sys/compat/linux/linux_ioctl.c#46 edit .. //depot/projects/smpng/sys/i386/linux/syscalls.master#29 edit Differences ... ==== //depot/projects/smpng/sys/amd64/linux32/syscalls.master#11 (text+ko) ==== @@ -113,7 +113,7 @@ 51 AUE_ACCT MNOPROTO { int acct(char *path); } 52 AUE_UMOUNT MSTD { int linux_umount(char *path, l_int flags); } 53 AUE_NULL UNIMPL lock -54 AUE_IOCTL STD { int linux_ioctl(l_uint fd, l_uint cmd, \ +54 AUE_IOCTL MSTD { int linux_ioctl(l_uint fd, l_uint cmd, \ uintptr_t arg); } 55 AUE_FCNTL MSTD { int linux_fcntl(l_uint fd, l_uint cmd, \ uintptr_t arg); } ==== //depot/projects/smpng/sys/compat/linux/linux_ioctl.c#46 (text+ko) ==== @@ -43,7 +43,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -51,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -126,6 +129,8 @@ static TAILQ_HEAD(, handler_element) handlers = TAILQ_HEAD_INITIALIZER(handlers); +static struct sx linux_ioctl_sx; +SX_SYSINIT(linux_ioctl, &linux_ioctl_sx, "linux ioctl handlers"); /* * hdio related ioctls for VMWare support @@ -2571,15 +2576,21 @@ /* Iterate over the ioctl handlers */ cmd = args->cmd & 0xffff; + sx_slock(&linux_ioctl_sx); + mtx_lock(&Giant); TAILQ_FOREACH(he, &handlers, list) { if (cmd >= he->low && cmd <= he->high) { error = (*he->func)(td, args); if (error != ENOIOCTL) { + mtx_unlock(&Giant); + sx_sunlock(&linux_ioctl_sx); fdrop(fp, td); return (error); } } } + mtx_unlock(&Giant); + sx_sunlock(&linux_ioctl_sx); fdrop(fp, td); linux_msg(td, "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented", @@ -2601,6 +2612,7 @@ * Reuse the element if the handler is already on the list, otherwise * create a new element. */ + sx_xlock(&linux_ioctl_sx); TAILQ_FOREACH(he, &handlers, list) { if (he->func == h->func) break; @@ -2621,10 +2633,12 @@ TAILQ_FOREACH(cur, &handlers, list) { if (cur->span > he->span) { TAILQ_INSERT_BEFORE(cur, he, list); + sx_xunlock(&linux_ioctl_sx); return (0); } } TAILQ_INSERT_TAIL(&handlers, he, list); + sx_xunlock(&linux_ioctl_sx); return (0); } @@ -2637,13 +2651,16 @@ if (h == NULL || h->func == NULL) return (EINVAL); + sx_xlock(&linux_ioctl_sx); TAILQ_FOREACH(he, &handlers, list) { if (he->func == h->func) { TAILQ_REMOVE(&handlers, he, list); + sx_xunlock(&linux_ioctl_sx); FREE(he, M_LINUX); return (0); } } + sx_xunlock(&linux_ioctl_sx); return (EINVAL); } ==== //depot/projects/smpng/sys/i386/linux/syscalls.master#29 (text+ko) ==== @@ -113,7 +113,7 @@ 51 AUE_ACCT MNOPROTO { int acct(char *path); } 52 AUE_UMOUNT MSTD { int linux_umount(char *path, l_int flags); } 53 AUE_NULL UNIMPL lock -54 AUE_IOCTL STD { int linux_ioctl(l_uint fd, l_uint cmd, \ +54 AUE_IOCTL MSTD { int linux_ioctl(l_uint fd, l_uint cmd, \ l_ulong arg); } 55 AUE_FCNTL MSTD { int linux_fcntl(l_uint fd, l_uint cmd, \ l_ulong arg); }