From nobody@FreeBSD.org  Sat Nov 17 08:12:03 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id DBB1D37B416
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 17 Nov 2001 08:11:57 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id fAHGBvg51632;
	Sat, 17 Nov 2001 08:11:57 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200111171611.fAHGBvg51632@freefall.freebsd.org>
Date: Sat, 17 Nov 2001 08:11:57 -0800 (PST)
From: SAKIYAMA Nobuo <sakichan@sakichan.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Linux kernel module (linux.ko) fails to load in -CURRENT
X-Send-Pr-Version: www-1.0

>Number:         32059
>Category:       kern
>Synopsis:       Linux kernel module (linux.ko) fails to load in -CURRENT
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    dillon
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 17 08:20:01 PST 2001
>Closed-Date:    Sun Nov 18 10:55:34 PST 2001
>Last-Modified:  Sun Nov 18 11:02:18 PST 2001
>Originator:     SAKIYAMA Nobuo
>Release:        FreeBSD 5.0-CURRENT
>Organization:
>Environment:
FreeBSD castor.sakichan.org 5.0-CURRENT FreeBSD 5.0-CURRENT #16: Sun Nov 18 00:42:32 JST 2001   root@castor.sakichan.org:/usr/obj/usr/src/sys/CASTOR  i386
>Description:
src/sys/kern/uipc_syscalls.c:1.99 removes holdsock(),
but src/sys/compat/linux-socket.c use that,
so loading of linux kernel module fails.

>How-To-Repeat:
kldload linux.ko

>Fix:
Following patch will be good.

--- sys/compat/linux/linux_socket.c     26 Oct 2001 23:10:08 -0000      1.30
+++ sys/compat/linux/linux_socket.c     17 Nov 2001 15:35:56 -0000
@@ -416,7 +416,7 @@
                int namelen;
        } */ bsd_args;
        struct socket *so;
-       struct file *fp;
+       unsigned int flag;
        int error;
 
 #ifdef __alpha__
@@ -438,17 +438,16 @@
         * when on a non-blocking socket. Instead it returns the
         * error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD.
         */
-       error = holdsock(td->td_proc->p_fd, linux_args.s, &fp);
+       error = fgetsock(td, linux_args.s, &so, &flag);
        if (error)
                return (error);
        error = EISCONN;
-       if (fp->f_flag & FNONBLOCK) {
-               so = (struct socket *)fp->f_data;
+       if (flag & FNONBLOCK) {
                if (so->so_emuldata == 0)
                        error = so->so_error;
                so->so_emuldata = (void *)1;
        }
-       fdrop(fp, td);
+       fputsock(so);
        return (error);
 }

>Release-Note:
>Audit-Trail:

From: SAKIYAMA Nobuo <sakichan@sakichan.org>
To: freebsd-gnats-submit@FreeBSD.org, 
Cc: SAKIYAMA Nobuo <sakichan@sakichan.org>
Subject: Re: kern/32059: Linux kernel module (linux.ko) fails to load in -CURRENT
Date: Sun, 18 Nov 2001 03:37:24 +0900

 My patch was incomplete, because that lacks a lock.
 Following patch  will be correct.
 
 --- sys/compat/linux/linux_socket.c     26 Oct 2001 23:10:08 -0000      1.30
 +++ sys/compat/linux/linux_socket.c     17 Nov 2001 18:27:20 -0000
 @@ -416,7 +416,7 @@
                 int namelen;
         } */ bsd_args;
         struct socket *so;
 -       struct file *fp;
 +       unsigned int flag;
         int error;
  
  #ifdef __alpha__
 @@ -438,17 +438,20 @@
          * when on a non-blocking socket. Instead it returns the
          * error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD.
          */
 -       error = holdsock(td->td_proc->p_fd, linux_args.s, &fp);
 -       if (error)
 +       mtx_lock(&Giant);
 +       error = fgetsock(td, linux_args.s, &so, &flag);
 +       if (error) {
 +               mtx_unlock(&Giant);
                 return (error);
 +       }
         error = EISCONN;
 -       if (fp->f_flag & FNONBLOCK) {
 -               so = (struct socket *)fp->f_data;
 +       if (flag & FNONBLOCK) {
                 if (so->so_emuldata == 0)
                         error = so->so_error;
                 so->so_emuldata = (void *)1;
         }
 -       fdrop(fp, td);
 +       fputsock(so);
 +       mtx_unlock(&Giant);
         return (error);
  }
Responsible-Changed-From-To: freebsd-bugs->dillon 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Sun Nov 18 03:42:10 PST 2001 
Responsible-Changed-Why:  
I think Matt may just have fixed this, but I'll asign it to him 
so he can look over the patch (it's a holdsock->fgetsock patch). 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32059 
State-Changed-From-To: open->closed 
State-Changed-By: dillon 
State-Changed-When: Sun Nov 18 10:55:34 PST 2001 
State-Changed-Why:  
This should be fixed now.  We do not need to get Giant in this case 
because the linux system call definition in i386/linux/syscalls.master 
is not marked as being MP safe (i.e. it's STD instead of MSTD).  So 
the syscall code gets Giant for us. 


http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32059 
>Unformatted:
