Date: Fri, 23 Jun 2006 19:12:31 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 99888 for review Message-ID: <200606231912.k5NJCVRS044238@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/filedesc.h> #include <sys/filio.h> #include <sys/kbio.h> +#include <sys/kernel.h> #include <sys/linker_set.h> +#include <sys/lock.h> #include <sys/malloc.h> #include <sys/proc.h> #include <sys/sbuf.h> @@ -51,6 +53,7 @@ #include <sys/sockio.h> #include <sys/soundcard.h> #include <sys/stdint.h> +#include <sys/sx.h> #include <sys/tty.h> #include <sys/uio.h> #include <net/if.h> @@ -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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606231912.k5NJCVRS044238>