From owner-svn-src-user@FreeBSD.ORG Tue Dec 17 10:03:06 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 984BB674; Tue, 17 Dec 2013 10:03:06 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8402A1126; Tue, 17 Dec 2013 10:03:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBHA36dg004064; Tue, 17 Dec 2013 10:03:06 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBHA354W004055; Tue, 17 Dec 2013 10:03:05 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312171003.rBHA354W004055@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Tue, 17 Dec 2013 10:03:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259501 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Dec 2013 10:03:06 -0000 Author: ae Date: Tue Dec 17 10:03:04 2013 New Revision: 259501 URL: http://svnweb.freebsd.org/changeset/base/259501 Log: Application can specify outgoing interface using setsockopt, this way affects all packets on the socket. This also called "sticky" options. And second way - specify the same options using ancillary data (using sendmsg(2)). This method overrides sticky options and affects only those datagrams, for which it was specified. Ancillary data can be used only with UDP and RAW sockets. Make sin6_scope_id check and initialization a bit later, when ancillary data is already parsed and we know specified outgoing interface. Also rename sa6_checkzone_pcb() function into sa6_checkzone_opts(), and use output options determined from sticky socket option or from ancillary data. Move sa6_checkzone_opts() declaration into ip6_var.h. Reported by: melifaro Tested with: rtadvd Modified: user/ae/inet6/sys/netinet6/in6_pcb.c user/ae/inet6/sys/netinet6/ip6_var.h user/ae/inet6/sys/netinet6/raw_ip6.c user/ae/inet6/sys/netinet6/scope6.c user/ae/inet6/sys/netinet6/scope6_var.h user/ae/inet6/sys/netinet6/send.c user/ae/inet6/sys/netinet6/udp6_usrreq.c Modified: user/ae/inet6/sys/netinet6/in6_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_pcb.c Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/in6_pcb.c Tue Dec 17 10:03:04 2013 (r259501) @@ -138,7 +138,8 @@ in6_pcbbind(struct inpcb *inp, struct so if (nam->sa_family != AF_INET6) return (EAFNOSUPPORT); /* Check sin6_scope_id. The caller must set it properly. */ - if ((error = sa6_checkzone_pcb(inp, sin6)) != 0) + if ((error = sa6_checkzone_opts(inp->in6p_outputopts, + inp->in6p_moptions, sin6)) != 0) return (error); if ((error = prison_local_ip6(cred, &sin6->sin6_addr, @@ -323,7 +324,8 @@ in6_pcbconnect_mbuf(register struct inpc /* * Check sin6_scope_id and automatically fill it, if possible. */ - error = sa6_checkzone_pcb(inp, sin6); + error = sa6_checkzone_opts(inp->in6p_outputopts, + inp->in6p_moptions, sin6); if (error != 0) return (error); if ((error = prison_remote_ip6(inp->inp_cred, &sin6->sin6_addr)) != 0) Modified: user/ae/inet6/sys/netinet6/ip6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/ip6_var.h Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/ip6_var.h Tue Dec 17 10:03:04 2013 (r259501) @@ -398,6 +398,8 @@ int ip6_setpktopts(struct mbuf *, struct void ip6_clearpktopts(struct ip6_pktopts *, int); struct ip6_pktopts *ip6_copypktopts(struct ip6_pktopts *, int); int ip6_optlen(struct inpcb *); +int sa6_checkzone_opts(struct ip6_pktopts *, struct ip6_moptions *, + struct sockaddr_in6 *); int route6_input(struct mbuf **, int *, int); Modified: user/ae/inet6/sys/netinet6/raw_ip6.c ============================================================================== --- user/ae/inet6/sys/netinet6/raw_ip6.c Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/raw_ip6.c Tue Dec 17 10:03:04 2013 (r259501) @@ -430,6 +430,13 @@ rip6_output(struct mbuf *m, ...) optp = in6p->in6p_outputopts; /* + * Application must provide a proper zone ID or the use of + * default zone IDs should be enabled. + */ + error = sa6_checkzone_opts(optp, in6p->in6p_moptions, dstsock); + if (error != 0) + goto bad; + /* * For an ICMPv6 packet, we should know its type and code to update * statistics. */ @@ -738,7 +745,8 @@ rip6_bind(struct socket *so, struct sock if (TAILQ_EMPTY(&V_ifnet) || addr->sin6_family != AF_INET6) return (EADDRNOTAVAIL); INP_RLOCK(inp); - error = sa6_checkzone_pcb(inp, addr); + error = sa6_checkzone_opts(inp->in6p_outputopts, + inp->in6p_moptions, addr); INP_RUNLOCK(inp); if (error != 0) return (error); @@ -782,7 +790,8 @@ rip6_connect(struct socket *so, struct s if (addr->sin6_family != AF_INET6) return (EAFNOSUPPORT); INP_RLOCK(inp); - error = sa6_checkzone_pcb(inp, addr); + error = sa6_checkzone_opts(inp->in6p_outputopts, + inp->in6p_moptions, addr); INP_RUNLOCK(inp); if (error != 0) return (error); @@ -877,17 +886,6 @@ rip6_send(struct socket *so, int flags, m_freem(m); return(EAFNOSUPPORT); } - /* - * Application must provide a proper zone ID or the use of - * default zone IDs should be enabled. - */ - INP_RLOCK(inp); - ret = sa6_checkzone_pcb(inp, dst); - INP_RUNLOCK(inp); - if (ret != 0) { - m_freem(m); - return (ret); - } } ret = rip6_output(m, so, dst, control); return (ret); Modified: user/ae/inet6/sys/netinet6/scope6.c ============================================================================== --- user/ae/inet6/sys/netinet6/scope6.c Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/scope6.c Tue Dec 17 10:03:04 2013 (r259501) @@ -521,7 +521,8 @@ sa6_checkzone_ifp(struct ifnet *ifp, str } int -sa6_checkzone_pcb(struct inpcb *inp, struct sockaddr_in6 *sa6) +sa6_checkzone_opts(struct ip6_pktopts *opts, struct ip6_moptions *mopts, + struct sockaddr_in6 *sa6) { struct in6_pktinfo *pi; int scope; @@ -537,22 +538,39 @@ sa6_checkzone_pcb(struct inpcb *inp, str * socket options. * XXX: we will do this again in the in6_selectsrc(). */ - INP_LOCK_ASSERT(inp); - if (inp->in6p_outputopts != NULL) { - pi = inp->in6p_outputopts->ip6po_pktinfo; + /* + * RFC 3542 p6.7: + * If an interface is specified in an IPV6_PKTINFO + * ancillary data item, the interface is used. + */ + if (opts != NULL) { + pi = opts->ip6po_pktinfo; if (pi != NULL && pi->ipi6_ifindex != 0) { /* XXX: in6_getscopezone */ sa6->sin6_scope_id = pi->ipi6_ifindex; return (0); } } - if (inp->in6p_moptions != NULL && - inp->in6p_moptions->im6o_multicast_ifp != NULL) { + /* + * If the destination address is a multicast + * address and the IPV6_MULTICAST_IF socket option is + * specified for the socket, the interface is used. + */ + if (mopts != NULL && + mopts->im6o_multicast_ifp != NULL) { sa6->sin6_scope_id = in6_getscopezone( - inp->in6p_moptions->im6o_multicast_ifp, - scope); + mopts->im6o_multicast_ifp, scope); return (0); } + /* + * If an IPV6_NEXTHOP ancillary data item is + * specified, the interface to the next hop is used. + * + * This option does not have any meaning for multicast + * destinations. In such a case, the specified next hop + * will be ignored. + * XXX: handle IPV6_NEXTHOP + */ } } return (sa6_checkzone(sa6)); Modified: user/ae/inet6/sys/netinet6/scope6_var.h ============================================================================== --- user/ae/inet6/sys/netinet6/scope6_var.h Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/scope6_var.h Tue Dec 17 10:03:04 2013 (r259501) @@ -57,7 +57,6 @@ int sa6_embedscope(struct sockaddr_in6 * int sa6_recoverscope(struct sockaddr_in6 *); int sa6_checkzone(struct sockaddr_in6 *); int sa6_checkzone_ifp(struct ifnet *, struct sockaddr_in6 *); -int sa6_checkzone_pcb(struct inpcb *, struct sockaddr_in6 *); int in6_setscope(struct in6_addr *, struct ifnet *, u_int32_t *); int in6_clearscope(struct in6_addr *); uint16_t in6_getscope(struct in6_addr *); Modified: user/ae/inet6/sys/netinet6/send.c ============================================================================== --- user/ae/inet6/sys/netinet6/send.c Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/send.c Tue Dec 17 10:03:04 2013 (r259501) @@ -54,7 +54,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include static MALLOC_DEFINE(M_SEND, "send", "Secure Neighbour Discovery"); Modified: user/ae/inet6/sys/netinet6/udp6_usrreq.c ============================================================================== --- user/ae/inet6/sys/netinet6/udp6_usrreq.c Tue Dec 17 09:22:25 2013 (r259500) +++ user/ae/inet6/sys/netinet6/udp6_usrreq.c Tue Dec 17 10:03:04 2013 (r259501) @@ -631,9 +631,6 @@ udp6_output(struct inpcb *inp, struct mb INP_WLOCK_ASSERT(inp); INP_HASH_WLOCK_ASSERT(inp->inp_pcbinfo); - bzero(&ro, sizeof(ro)); - /* addr6 has been validated in udp6_send(). */ - sin6 = (struct sockaddr_in6 *)addr6; if (control) { if ((error = ip6_setpktopts(control, &opt, inp->in6p_outputopts, td->td_ucred, IPPROTO_UDP)) != 0) @@ -642,6 +639,18 @@ udp6_output(struct inpcb *inp, struct mb } else optp = inp->in6p_outputopts; + bzero(&ro, sizeof(ro)); + if (addr6 != NULL) { + /* + * Application must provide a proper zone ID or the use of + * default zone IDs should be enabled. + */ + ro.ro_dst = *(struct sockaddr_in6 *)addr6; + sin6 = &ro.ro_dst; + error = sa6_checkzone_opts(optp, inp->in6p_moptions, sin6); + if (error != 0) + goto release; + } if (sin6) { faddr = &sin6->sin6_addr; @@ -1075,7 +1084,6 @@ static int udp6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, struct mbuf *control, struct thread *td) { - struct sockaddr_in6 tmp; struct inpcb *inp; int error = 0; @@ -1092,15 +1100,6 @@ udp6_send(struct socket *so, int flags, error = EAFNOSUPPORT; goto bad; } - /* - * Application must provide a proper zone ID or the use of - * default zone IDs should be enabled. - */ - tmp = *(struct sockaddr_in6 *)addr; - addr = (struct sockaddr *)&tmp; - error = sa6_checkzone_pcb(inp, &tmp); - if (error != 0) - goto bad; } #ifdef INET From owner-svn-src-user@FreeBSD.ORG Tue Dec 17 18:44:47 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B0AAF2DE; Tue, 17 Dec 2013 18:44:47 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 98E1410A2; Tue, 17 Dec 2013 18:44:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBHIil3B095299; Tue, 17 Dec 2013 18:44:47 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBHIilLt095297; Tue, 17 Dec 2013 18:44:47 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201312171844.rBHIilLt095297@svn.freebsd.org> From: Peter Holm Date: Tue, 17 Dec 2013 18:44:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259524 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Dec 2013 18:44:47 -0000 Author: pho Date: Tue Dec 17 18:44:46 2013 New Revision: 259524 URL: http://svnweb.freebsd.org/changeset/base/259524 Log: Added two fifo regression tests. Sponsored by: EMC / Isilon storage division Added: user/pho/stress2/misc/fifo.sh (contents, props changed) user/pho/stress2/misc/fifo2.sh (contents, props changed) Added: user/pho/stress2/misc/fifo.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/fifo.sh Tue Dec 17 18:44:46 2013 (r259524) @@ -0,0 +1,87 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Page fault seen. +# http://people.freebsd.org/~pho/stress/log/kostik652.txt +# Fixed by r259522. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fifo.c +rm -f /tmp/fifo +cc -o fifo -Wall -Wextra -O2 -g fifo.c || exit 1 +rm -f fifo.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +(cd $mntpoint; /tmp/fifo) + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint && mdconfig -d -u $mdstart && break + sleep 10 +done +rm -f /tmp/fifo +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int +main(void) +{ + int fd; + + if (mkfifo("fifo", 0644) == -1) + err(1, "mkfifo"); + + fd = open("fifo", O_RDWR | O_SHLOCK | O_EXLOCK); + fd = open("fifo", 0x60e9f2, 0xc74c65b1db4be370, 0xb64a34df72368759); + + return (0); +} Added: user/pho/stress2/misc/fifo2.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/fifo2.sh Tue Dec 17 18:44:46 2013 (r259524) @@ -0,0 +1,215 @@ +#!/bin/sh + +# +# Copyright (c) 2013 EMC Corp. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Page fault seen +# http://people.freebsd.org/~pho/stress/log/kostik654.txt +# Fixed by r259521. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +killall 2>&1 | grep -q q && q="-q" +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > fifo2.c +rm -f /tmp/fifo2 +cc -o fifo2 -Wall -Wextra -O2 -g fifo2.c -lpthread || exit 1 +rm -f fifo2.c + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto +newfs $newfs_flags md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint +mkfifo $mntpoint/f +chmod 777 $mntpoint/f + +sleeptime=12 +st=`date '+%s'` +while [ $((`date '+%s'` - st)) -lt $((10 * sleeptime)) ]; do + (cd $mntpoint; /tmp/fifo2) & + start=`date '+%s'` + while [ $((`date '+%s'` - start)) -lt $sleeptime ]; do + ps aux | grep -v grep | egrep -q "fifo2$" || break + sleep .5 + done + if ps aux | grep -v grep | egrep -q "fifo2$"; then + killall $q fifo2 + ps aux | grep -v grep | egrep -q "fifo2 " && + killall $q -9 fifo2 + fi + wait +done +killall $q -9 fifo2 +ps aux | grep -v grep | egrep -v "\.sh" | grep -q fifo2 && + killall $q -9 fifo2 + +for i in `jot 10`; do + mount | grep -q md${mdstart}$part && \ + umount $mntpoint > /dev/null 2>&1 && + mdconfig -d -u $mdstart && break + sleep 10 +done +mount | grep -q md${mdstart}$part && echo "umount $mntpoint failed" +rm -f /tmp/fifo2 +exit +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define N (128 * 1024 / (int)sizeof(u_int32_t)) +u_int32_t r[N]; + +static void +hand(int i __unused) { /* handler */ + _exit(1); +} + +unsigned long +makearg(void) +{ + unsigned int i; + unsigned long val; + + val = arc4random(); + i = arc4random() % 100; + if (i < 20) + val = val & 0xff; + if (i >= 20 && i < 40) + val = val & 0xffff; + if (i >= 40 && i < 60) + val = (unsigned long)(r) | (val & 0xffff); +#if defined(__LP64__) + if (i >= 60) { + val = (val << 32) | arc4random(); + if (i > 80) + val = val & 0x00007fffffffffffUL; + } +#endif + + return(val); +} + +void * +calls(void *arg __unused) +{ + int i, num; + unsigned long arg1, arg2, arg3, arg4, arg5, arg6, arg7; + + for (i = 0;; i++) { + arg1 = (unsigned long)(void *)"f"; + arg2 = makearg(); + arg3 = makearg(); + arg4 = makearg(); + arg5 = makearg(); + arg6 = makearg(); + arg7 = makearg(); + +#if 0 + fprintf(stderr, "%2d : syscall(%3d, %lx, %lx, %lx, %lx, %lx, %lx, %lx)\n", + i, SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + usleep(100000); +#endif + alarm(1); + syscall(SYS_open, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + num = 0; + } + + return (0); +} + +int +main(void) +{ + struct passwd *pw; + struct rlimit limit; + pthread_t cp[50]; + time_t start; + int j; + + if ((pw = getpwnam("nobody")) == NULL) + err(1, "no such user: nobody"); + + if (setgroups(1, &pw->pw_gid) || + setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + err(1, "Can't drop privileges to \"nobody\""); + endpwent(); + + limit.rlim_cur = limit.rlim_max = 1000; + if (setrlimit(RLIMIT_NPTS, &limit) < 0) + err(1, "setrlimit"); + + signal(SIGALRM, hand); + signal(SIGILL, hand); + signal(SIGFPE, hand); + signal(SIGSEGV, hand); + signal(SIGBUS, hand); + signal(SIGURG, hand); + signal(SIGSYS, hand); + signal(SIGTRAP, hand); + + start = time(NULL); + while ((time(NULL) - start) < 120) { + if (fork() == 0) { + arc4random_stir(); + for (j = 0; j < 1; j++) + if (pthread_create(&cp[j], NULL, calls, NULL) != 0) + perror("pthread_create"); + + for (j = 0; j < 1; j++) + pthread_join(cp[j], NULL); + _exit(0); + } + wait(NULL); + } + + return (0); +} From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 14:36:45 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 59AF3D34; Wed, 18 Dec 2013 14:36:45 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 451DF137C; Wed, 18 Dec 2013 14:36:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIEajV1030762; Wed, 18 Dec 2013 14:36:45 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIEajVG030760; Wed, 18 Dec 2013 14:36:45 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181436.rBIEajVG030760@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 14:36:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259551 - in user/ae/inet6/sys: kern sys X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 14:36:45 -0000 Author: ae Date: Wed Dec 18 14:36:44 2013 New Revision: 259551 URL: http://svnweb.freebsd.org/changeset/base/259551 Log: Use struct sockaddr_in6 to keep IPv6 addresses in jail code. Since IPv6 LLAs use zone indexes in addition to the struct in6_addr, we couldn't use these addresses in jails (actually we could use them, but LLAs from different zones were the same for jail). The JAIL_API_VERSION now is 3. And the kernel will reject IPv6 addresses, if they are passed from userland in old format. All prison_xxx_ip6() functions were changed to take struct sockaddr_in6 instead of in6_addr. One new function prison_check_in6() added, it takes struct in6_addr and zone index. In some places the const qualifier was added. Modified: user/ae/inet6/sys/kern/kern_jail.c user/ae/inet6/sys/sys/jail.h Modified: user/ae/inet6/sys/kern/kern_jail.c ============================================================================== --- user/ae/inet6/sys/kern/kern_jail.c Wed Dec 18 12:53:48 2013 (r259550) +++ user/ae/inet6/sys/kern/kern_jail.c Wed Dec 18 14:36:44 2013 (r259551) @@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include #ifdef INET6 #include +#include #endif /* INET6 */ #endif /* DDB */ @@ -139,8 +140,11 @@ static int _prison_check_ip4(const struc static int prison_restrict_ip4(struct prison *pr, struct in_addr *newip4); #endif #ifdef INET6 -static int _prison_check_ip6(struct prison *pr, struct in6_addr *ia6); -static int prison_restrict_ip6(struct prison *pr, struct in6_addr *newip6); +static int _prison_check_ip6(struct prison *, const struct sockaddr_in6 *); +static int prison_restrict_ip6(struct prison *, struct sockaddr_in6 *); +#define SA6_ARE_ADDR_EQUAL(a, b) \ + (IN6_ARE_ADDR_EQUAL(&(a)->sin6_addr, &(b)->sin6_addr) && \ + (a)->sin6_scope_id == (b)->sin6_scope_id) #endif /* Flags for prison_deref */ @@ -268,17 +272,25 @@ qcmp_v4(const void *ip1, const void *ip2 static int qcmp_v6(const void *ip1, const void *ip2) { - const struct in6_addr *ia6a, *ia6b; + const struct sockaddr_in6 *ip6a, *ip6b; int i, rc; - ia6a = (const struct in6_addr *)ip1; - ia6b = (const struct in6_addr *)ip2; + ip6a = (const struct sockaddr_in6 *)ip1; + ip6b = (const struct sockaddr_in6 *)ip2; rc = 0; for (i = 0; rc == 0 && i < sizeof(struct in6_addr); i++) { - if (ia6a->s6_addr[i] > ia6b->s6_addr[i]) + if (ip6a->sin6_addr.s6_addr[i] > + ip6b->sin6_addr.s6_addr[i]) rc = 1; - else if (ia6a->s6_addr[i] < ia6b->s6_addr[i]) + else if (ip6a->sin6_addr.s6_addr[i] < + ip6b->sin6_addr.s6_addr[i]) + rc = -1; + } + if (rc == 0) { + if (ip6a->sin6_scope_id > ip6b->sin6_scope_id) + rc = 1; + else if (ip6a->sin6_scope_id < ip6b->sin6_scope_id) rc = -1; } return (rc); @@ -327,6 +339,7 @@ sys_jail(struct thread *td, struct jail_ case 2: /* JAIL_API_VERSION */ /* FreeBSD multi-IPv4/IPv6,noIP jails. */ + case 3: /* in6_addr -> sockaddr_in6 */ error = copyin(uap->jail, &j, sizeof(struct jail)); if (error) return (error); @@ -358,7 +371,7 @@ kern_jail(struct thread *td, struct jail struct in_addr *u_ip4; #endif #ifdef INET6 - struct in6_addr *u_ip6; + struct sockaddr_in6 *u_ip6; #endif size_t tmplen; int error, enforce_statfs, fi; @@ -403,9 +416,16 @@ kern_jail(struct thread *td, struct jail return (EINVAL); #endif #ifdef INET6 + /* + * We don't support the old way, when the list of IPv6 addresses + * is specified via struct in6_addr. + * XXX: in some case we can (i.e. until LLA isn't used). + */ + if (j->version < 3) + return (EINVAL); if (j->ip6s > jail_max_af_ips) return (EINVAL); - tmplen += j->ip6s * sizeof(struct in6_addr); + tmplen += j->ip6s * sizeof(struct sockaddr_in6); #else if (j->ip6s > 0) return (EINVAL); @@ -418,9 +438,9 @@ kern_jail(struct thread *td, struct jail #endif #ifdef INET6 #ifdef INET - u_ip6 = (struct in6_addr *)(u_ip4 + ip4s); + u_ip6 = (struct sockaddr_in6 *)(u_ip4 + ip4s); #else - u_ip6 = (struct in6_addr *)(u_name + MAXHOSTNAMELEN); + u_ip6 = (struct sockaddr_in6 *)(u_name + MAXHOSTNAMELEN); #endif #endif optiov[opt.uio_iovcnt].iov_base = "path"; @@ -480,7 +500,7 @@ kern_jail(struct thread *td, struct jail optiov[opt.uio_iovcnt].iov_len = sizeof("ip6.addr"); opt.uio_iovcnt++; optiov[opt.uio_iovcnt].iov_base = u_ip6; - optiov[opt.uio_iovcnt].iov_len = j->ip6s * sizeof(struct in6_addr); + optiov[opt.uio_iovcnt].iov_len = j->ip6s * sizeof(struct sockaddr_in6); error = copyin(j->ip6, u_ip6, optiov[opt.uio_iovcnt].iov_len); if (error) { free(u_path, M_TEMP); @@ -529,7 +549,7 @@ kern_jail_set(struct thread *td, struct struct in_addr *ip4; #endif #ifdef INET6 - struct in6_addr *ip6; + struct sockaddr_in6 *ip6; #endif struct vfsopt *opt; struct vfsoptlist *opts; @@ -881,14 +901,21 @@ kern_jail_set(struct thread *td, struct if (ip6s > 1) qsort(ip6 + 1, ip6s - 1, sizeof(*ip6), qcmp_v6); for (ii = 0; ii < ip6s; ii++) { - if (IN6_IS_ADDR_UNSPECIFIED(&ip6[ii])) { + if (IN6_IS_ADDR_UNSPECIFIED(&ip6[ii].sin6_addr)) { error = EINVAL; goto done_free; } - if ((ii+1) < ip6s && - (IN6_ARE_ADDR_EQUAL(&ip6[0], &ip6[ii+1]) || - IN6_ARE_ADDR_EQUAL(&ip6[ii], &ip6[ii+1]))) - { + if (ip6[ii].sin6_family != AF_INET6 || + ip6[ii].sin6_len != sizeof(*ip6) || + sa6_checkzone(&ip6[ii]) != 0) { + error = EINVAL; + goto done_free; + } + if ((ii + 1) < ip6s && ( + SA6_ARE_ADDR_EQUAL(&ip6[0], + &ip6[ii + 1]) || + SA6_ARE_ADDR_EQUAL(&ip6[ii], + &ip6[ii + 1]))) { error = EINVAL; goto done_free; } @@ -1272,8 +1299,8 @@ kern_jail_set(struct thread *td, struct if (ppr->pr_ip6 != NULL) { pr->pr_ip6s = ppr->pr_ip6s; pr->pr_ip6 = malloc(pr->pr_ip6s * - sizeof(struct in6_addr), M_PRISON, - M_WAITOK); + sizeof(struct sockaddr_in6), + M_PRISON, M_WAITOK); bcopy(ppr->pr_ip6, pr->pr_ip6, pr->pr_ip6s * sizeof(*pr->pr_ip6)); } @@ -1465,7 +1492,7 @@ kern_jail_set(struct thread *td, struct * subset of the parent's list. */ for (ij = 0; ij < ppr->pr_ip6s; ij++) - if (IN6_ARE_ADDR_EQUAL(&ip6[0], + if (SA6_ARE_ADDR_EQUAL(&ip6[0], &ppr->pr_ip6[ij])) break; if (ij == ppr->pr_ip6s) { @@ -1474,11 +1501,11 @@ kern_jail_set(struct thread *td, struct } if (ip6s > 1) { for (ii = ij = 1; ii < ip6s; ii++) { - if (IN6_ARE_ADDR_EQUAL(&ip6[ii], - &ppr->pr_ip6[0])) + if (SA6_ARE_ADDR_EQUAL(&ip6[ii], + &ppr->pr_ip6[0])) continue; for (; ij < ppr->pr_ip6s; ij++) - if (IN6_ARE_ADDR_EQUAL( + if (SA6_ARE_ADDR_EQUAL( &ip6[ii], &ppr->pr_ip6[ij])) break; if (ij == ppr->pr_ip6s) @@ -2989,7 +3016,7 @@ prison_check_ip4(const struct ucred *cre #ifdef INET6 static int -prison_restrict_ip6(struct prison *pr, struct in6_addr *newip6) +prison_restrict_ip6(struct prison *pr, struct sockaddr_in6 *newip6) { int ii, ij, used; struct prison *ppr; @@ -3031,7 +3058,7 @@ prison_restrict_ip6(struct prison *pr, s } else if (pr->pr_ip6s > 0) { /* Remove addresses that aren't in the parent. */ for (ij = 0; ij < ppr->pr_ip6s; ij++) - if (IN6_ARE_ADDR_EQUAL(&pr->pr_ip6[0], + if (SA6_ARE_ADDR_EQUAL(&pr->pr_ip6[0], &ppr->pr_ip6[ij])) break; if (ij < ppr->pr_ip6s) @@ -3042,12 +3069,12 @@ prison_restrict_ip6(struct prison *pr, s ii = 0; } for (ij = 1; ii < pr->pr_ip6s; ) { - if (IN6_ARE_ADDR_EQUAL(&pr->pr_ip6[ii], + if (SA6_ARE_ADDR_EQUAL(&pr->pr_ip6[ii], &ppr->pr_ip6[0])) { ii++; continue; } - switch (ij >= ppr->pr_ip4s ? -1 : + switch (ij >= ppr->pr_ip6s ? -1 : qcmp_v6(&pr->pr_ip6[ii], &ppr->pr_ip6[ij])) { case -1: bcopy(pr->pr_ip6 + ii + 1, pr->pr_ip6 + ii, @@ -3072,6 +3099,16 @@ prison_restrict_ip6(struct prison *pr, s } /* + * Copy only significant fields of struct sockaddr_in6. + */ +static void +prison_copy_ip6(const struct sockaddr_in6 *src, struct sockaddr_in6 *dst) +{ + + dst->sin6_addr = src->sin6_addr; + dst->sin6_scope_id = src->sin6_scope_id; +} +/* * Pass back primary IPv6 address for this jail. * * If not restricted return success but do not alter the address. Caller has @@ -3080,7 +3117,7 @@ prison_restrict_ip6(struct prison *pr, s * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. */ int -prison_get_ip6(struct ucred *cred, struct in6_addr *ia6) +prison_get_ip6(struct ucred *cred, struct sockaddr_in6 *ia6) { struct prison *pr; @@ -3100,7 +3137,7 @@ prison_get_ip6(struct ucred *cred, struc return (EAFNOSUPPORT); } - bcopy(&pr->pr_ip6[0], ia6, sizeof(struct in6_addr)); + prison_copy_ip6(&pr->pr_ip6[0], ia6); mtx_unlock(&pr->pr_mtx); return (0); } @@ -3113,10 +3150,10 @@ prison_get_ip6(struct ucred *cred, struc * Return EAFNOSUPPORT, in case this jail does not allow IPv6. */ int -prison_saddrsel_ip6(struct ucred *cred, struct in6_addr *ia6) +prison_saddrsel_ip6(struct ucred *cred, struct sockaddr_in6 *ia6) { + struct sockaddr_in6 addr; struct prison *pr; - struct in6_addr lia6; int error; KASSERT(cred != NULL, ("%s: cred is NULL", __func__)); @@ -3129,14 +3166,14 @@ prison_saddrsel_ip6(struct ucred *cred, if (pr->pr_flags & PR_IP6_SADDRSEL) return (1); - lia6 = in6addr_any; - error = prison_get_ip6(cred, &lia6); + addr = sa6_any; + error = prison_get_ip6(cred, &addr); if (error) return (error); - if (IN6_IS_ADDR_UNSPECIFIED(&lia6)) + if (IN6_IS_ADDR_UNSPECIFIED(&addr.sin6_addr)) return (1); - bcopy(&lia6, ia6, sizeof(struct in6_addr)); + prison_copy_ip6(&addr, ia6); return (0); } @@ -3176,7 +3213,7 @@ prison_equal_ip6(struct prison *pr1, str * doesn't allow IPv6. */ int -prison_local_ip6(struct ucred *cred, struct in6_addr *ia6, int v6only) +prison_local_ip6(struct ucred *cred, struct sockaddr_in6 *ia6, int v6only) { struct prison *pr; int error; @@ -3197,19 +3234,19 @@ prison_local_ip6(struct ucred *cred, str return (EAFNOSUPPORT); } - if (IN6_IS_ADDR_LOOPBACK(ia6)) { - bcopy(&pr->pr_ip6[0], ia6, sizeof(struct in6_addr)); + if (IN6_IS_ADDR_LOOPBACK(&ia6->sin6_addr)) { + prison_copy_ip6(&pr->pr_ip6[0], ia6); mtx_unlock(&pr->pr_mtx); return (0); } - if (IN6_IS_ADDR_UNSPECIFIED(ia6)) { + if (IN6_IS_ADDR_UNSPECIFIED(&ia6->sin6_addr)) { /* * In case there is only 1 IPv6 address, and v6only is true, * then bind directly. */ if (v6only != 0 && pr->pr_ip6s == 1) - bcopy(&pr->pr_ip6[0], ia6, sizeof(struct in6_addr)); + prison_copy_ip6(&pr->pr_ip6[0], ia6); mtx_unlock(&pr->pr_mtx); return (0); } @@ -3225,7 +3262,7 @@ prison_local_ip6(struct ucred *cred, str * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. */ int -prison_remote_ip6(struct ucred *cred, struct in6_addr *ia6) +prison_remote_ip6(struct ucred *cred, struct sockaddr_in6 *ia6) { struct prison *pr; @@ -3245,8 +3282,8 @@ prison_remote_ip6(struct ucred *cred, st return (EAFNOSUPPORT); } - if (IN6_IS_ADDR_LOOPBACK(ia6)) { - bcopy(&pr->pr_ip6[0], ia6, sizeof(struct in6_addr)); + if (IN6_IS_ADDR_LOOPBACK(&ia6->sin6_addr)) { + prison_copy_ip6(&pr->pr_ip6[0], ia6); mtx_unlock(&pr->pr_mtx); return (0); } @@ -3266,14 +3303,14 @@ prison_remote_ip6(struct ucred *cred, st * doesn't allow IPv6. */ static int -_prison_check_ip6(struct prison *pr, struct in6_addr *ia6) +_prison_check_ip6(struct prison *pr, const struct sockaddr_in6 *ia6) { int i, a, z, d; /* * Check the primary IP. */ - if (IN6_ARE_ADDR_EQUAL(&pr->pr_ip6[0], ia6)) + if (SA6_ARE_ADDR_EQUAL(&pr->pr_ip6[0], ia6)) return (0); /* @@ -3296,7 +3333,7 @@ _prison_check_ip6(struct prison *pr, str } int -prison_check_ip6(struct ucred *cred, struct in6_addr *ia6) +prison_check_ip6(struct ucred *cred, const struct sockaddr_in6 *ia6) { struct prison *pr; int error; @@ -3321,6 +3358,20 @@ prison_check_ip6(struct ucred *cred, str mtx_unlock(&pr->pr_mtx); return (error); } + +int +prison_check_in6(struct ucred *cred, const struct in6_addr *ia6, + uint32_t zoneid) +{ + struct sockaddr_in6 addr; + + /* XXX: do we need better initialization? */ + addr.sin6_addr = *ia6; + if (IN6_IS_ADDR_LINKLOCAL(ia6)) + addr.sin6_scope_id = zoneid; + return (prison_check_ip6(cred, &addr)); +} + #endif /* @@ -3388,13 +3439,10 @@ prison_check_af(struct ucred *cred, int * the jail doesn't allow the address family. IPv4 Address passed in in NBO. */ int -prison_if(struct ucred *cred, struct sockaddr *sa) +prison_if(struct ucred *cred, const struct sockaddr *sa) { #ifdef INET - struct sockaddr_in *sai; -#endif -#ifdef INET6 - struct sockaddr_in6 *sai6; + const struct sockaddr_in *sai; #endif int error; @@ -3411,14 +3459,14 @@ prison_if(struct ucred *cred, struct soc { #ifdef INET case AF_INET: - sai = (struct sockaddr_in *)sa; + sai = (const struct sockaddr_in *)sa; error = prison_check_ip4(cred, &sai->sin_addr); break; #endif #ifdef INET6 case AF_INET6: - sai6 = (struct sockaddr_in6 *)sa; - error = prison_check_ip6(cred, &sai6->sin6_addr); + error = prison_check_ip6(cred, + (const struct sockaddr_in6 *)sa); break; #endif default: @@ -4033,7 +4081,7 @@ sysctl_jail_list(SYSCTL_HANDLER_ARGS) int ip4s = 0; #endif #ifdef INET6 - struct in6_addr *ip6 = NULL; + struct sockaddr_in6 *ip6 = NULL; int ip6s = 0; #endif int descend, error; @@ -4065,12 +4113,12 @@ sysctl_jail_list(SYSCTL_HANDLER_ARGS) if (ip6s < cpr->pr_ip6s) { ip6s = cpr->pr_ip6s; mtx_unlock(&cpr->pr_mtx); - ip6 = realloc(ip6, ip6s * - sizeof(struct in6_addr), M_TEMP, M_WAITOK); + ip6 = realloc(ip6, ip6s * sizeof(*ip6), + M_TEMP, M_WAITOK); goto again; } bcopy(cpr->pr_ip6, ip6, - cpr->pr_ip6s * sizeof(struct in6_addr)); + cpr->pr_ip6s * sizeof(*ip6)); } #endif if (cpr->pr_ref == 0) { @@ -4106,7 +4154,7 @@ sysctl_jail_list(SYSCTL_HANDLER_ARGS) #ifdef INET6 if (xp->pr_ip6s > 0) { error = SYSCTL_OUT(req, ip6, - xp->pr_ip6s * sizeof(struct in6_addr)); + xp->pr_ip6s * sizeof(*ip6)); if (error) break; } @@ -4364,8 +4412,8 @@ SYSCTL_JAIL_PARAM(_ip4, saddrsel, CTLTYP #ifdef INET6 SYSCTL_JAIL_PARAM_SYS_NODE(ip6, CTLFLAG_RDTUN, "Jail IPv6 address virtualization"); -SYSCTL_JAIL_PARAM_STRUCT(_ip6, addr, CTLFLAG_RW, sizeof(struct in6_addr), - "S,in6_addr,a", "Jail IPv6 addresses"); +SYSCTL_JAIL_PARAM_STRUCT(_ip6, addr, CTLFLAG_RW, sizeof(struct sockaddr_in6), + "S,sockaddr_in6,a", "Jail IPv6 addresses"); SYSCTL_JAIL_PARAM(_ip6, saddrsel, CTLTYPE_INT | CTLFLAG_RW, "B", "Do (not) use IPv6 source address selection rather than the " "primary jail IPv6 address."); @@ -4630,9 +4678,10 @@ db_show_prison(struct prison *pr) #ifdef INET6 db_printf(" ip6s = %d\n", pr->pr_ip6s); for (ii = 0; ii < pr->pr_ip6s; ii++) - db_printf(" %s %s\n", + db_printf(" %s %s%%%d\n", ii == 0 ? "ip6.addr =" : " ", - ip6_sprintf(ip6buf, &pr->pr_ip6[ii])); + ip6_sprintf(ip6buf, &pr->pr_ip6[ii].sin6_addr), + pr->pr_ip6[ii].sin6_scope_id); #endif } Modified: user/ae/inet6/sys/sys/jail.h ============================================================================== --- user/ae/inet6/sys/sys/jail.h Wed Dec 18 12:53:48 2013 (r259550) +++ user/ae/inet6/sys/sys/jail.h Wed Dec 18 14:36:44 2013 (r259551) @@ -47,9 +47,9 @@ struct jail { uint32_t ip4s; uint32_t ip6s; struct in_addr *ip4; - struct in6_addr *ip6; + struct sockaddr_in6 *ip6; }; -#define JAIL_API_VERSION 2 +#define JAIL_API_VERSION 3 /* * For all xprison structs, always keep the pr_version an int and @@ -81,7 +81,7 @@ struct xprison { * IPv4 and IPv6 addesses. Offsets are based numbers of addresses. */ struct in_addr pr_ip4[]; - struct in6_addr pr_ip6[]; + struct sockaddr_in6 pr_ip6[]; #endif }; #define XPRISON_VERSION 3 @@ -168,7 +168,7 @@ struct prison { int pr_ip4s; /* (p) number of v4 IPs */ int pr_ip6s; /* (p) number of v6 IPs */ struct in_addr *pr_ip4; /* (p) v4 IPs of jail */ - struct in6_addr *pr_ip6; /* (p) v6 IPs of jail */ + struct sockaddr_in6 *pr_ip6; /* (p) v6 IPs of jail */ struct prison_racct *pr_prison_racct; /* (c) racct jail proxy */ void *pr_sparep[3]; int pr_childcount; /* (a) number of child jails */ @@ -387,15 +387,18 @@ int prison_remote_ip4(struct ucred *cred int prison_check_ip4(const struct ucred *, const struct in_addr *); int prison_saddrsel_ip4(struct ucred *, struct in_addr *); #ifdef INET6 +struct in6_addr; +struct sockaddr_in6; int prison_equal_ip6(struct prison *, struct prison *); -int prison_get_ip6(struct ucred *, struct in6_addr *); -int prison_local_ip6(struct ucred *, struct in6_addr *, int); -int prison_remote_ip6(struct ucred *, struct in6_addr *); -int prison_check_ip6(struct ucred *, struct in6_addr *); -int prison_saddrsel_ip6(struct ucred *, struct in6_addr *); +int prison_get_ip6(struct ucred *, struct sockaddr_in6 *); +int prison_local_ip6(struct ucred *, struct sockaddr_in6 *, int); +int prison_remote_ip6(struct ucred *, struct sockaddr_in6 *); +int prison_check_ip6(struct ucred *, const struct sockaddr_in6 *); +int prison_check_in6(struct ucred *, const struct in6_addr *, uint32_t); +int prison_saddrsel_ip6(struct ucred *, struct sockaddr_in6 *); #endif int prison_check_af(struct ucred *cred, int af); -int prison_if(struct ucred *cred, struct sockaddr *sa); +int prison_if(struct ucred *cred, const struct sockaddr *sa); char *prison_name(struct prison *, struct prison *); int prison_priv_check(struct ucred *cred, int priv); int sysctl_jail_param(SYSCTL_HANDLER_ARGS); From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 14:40:33 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 806A6E62; Wed, 18 Dec 2013 14:40:33 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6DB5C13DB; Wed, 18 Dec 2013 14:40:33 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIEeX0U032007; Wed, 18 Dec 2013 14:40:33 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIEeXGo032006; Wed, 18 Dec 2013 14:40:33 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181440.rBIEeXGo032006@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 14:40:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259552 - user/ae/inet6/sys/kern X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 14:40:33 -0000 Author: ae Date: Wed Dec 18 14:40:32 2013 New Revision: 259552 URL: http://svnweb.freebsd.org/changeset/base/259552 Log: Initialize sin6_scope_id for global addresses. Modified: user/ae/inet6/sys/kern/kern_jail.c Modified: user/ae/inet6/sys/kern/kern_jail.c ============================================================================== --- user/ae/inet6/sys/kern/kern_jail.c Wed Dec 18 14:36:44 2013 (r259551) +++ user/ae/inet6/sys/kern/kern_jail.c Wed Dec 18 14:40:32 2013 (r259552) @@ -3369,6 +3369,8 @@ prison_check_in6(struct ucred *cred, con addr.sin6_addr = *ia6; if (IN6_IS_ADDR_LINKLOCAL(ia6)) addr.sin6_scope_id = zoneid; + else + addr.sin6_scope_id = 0; return (prison_check_ip6(cred, &addr)); } From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 14:45:03 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AB041F9B; Wed, 18 Dec 2013 14:45:03 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7DEFE1441; Wed, 18 Dec 2013 14:45:03 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIEj3VR034146; Wed, 18 Dec 2013 14:45:03 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIEj3TE034145; Wed, 18 Dec 2013 14:45:03 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181445.rBIEj3TE034145@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 14:45:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259553 - user/ae/inet6/sys/net X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 14:45:03 -0000 Author: ae Date: Wed Dec 18 14:45:03 2013 New Revision: 259553 URL: http://svnweb.freebsd.org/changeset/base/259553 Log: Update rtsock code to use sockaddr_in6 with jail's functions. Modified: user/ae/inet6/sys/net/rtsock.c Modified: user/ae/inet6/sys/net/rtsock.c ============================================================================== --- user/ae/inet6/sys/net/rtsock.c Wed Dec 18 14:40:32 2013 (r259552) +++ user/ae/inet6/sys/net/rtsock.c Wed Dec 18 14:45:03 2013 (r259553) @@ -508,7 +508,6 @@ rtm_get_jailed(struct rt_addrinfo *info, #ifdef INET6 case AF_INET6: { - struct in6_addr ia6; struct ifaddr *ifa; int found; @@ -519,35 +518,30 @@ rtm_get_jailed(struct rt_addrinfo *info, */ IF_ADDR_RLOCK(ifp); TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { - struct sockaddr *sa; - sa = ifa->ifa_addr; - if (sa->sa_family != AF_INET6) + if (ifa->ifa_addr->sa_family != AF_INET6) continue; - bcopy(&((struct sockaddr_in6 *)sa)->sin6_addr, - &ia6, sizeof(struct in6_addr)); - if (prison_check_ip6(cred, &ia6) == 0) { + if (prison_if(cred, ifa->ifa_addr) == 0) { found = 1; break; } } IF_ADDR_RUNLOCK(ifp); + bzero(&saun->sin6, sizeof(struct sockaddr_in6)); + saun->sin6.sin6_len = sizeof(struct sockaddr_in6); + saun->sin6.sin6_family = AF_INET6; if (!found) { /* * As a last resort return the 'default' jail address. */ - ia6 = ((struct sockaddr_in6 *)rt->rt_ifa->ifa_addr)-> - sin6_addr; - if (prison_get_ip6(cred, &ia6) != 0) + if (prison_get_ip6(cred, &saun->sin6) != 0) return (ESRCH); + } else { + struct sockaddr_in6 *sin6; + + sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; + saun->sin6.sin6_addr = sin6->sin6_addr; + saun->sin6.sin6_scope_id = sin6->sin6_scope_id; } - bzero(&saun->sin6, sizeof(struct sockaddr_in6)); - saun->sin6.sin6_len = sizeof(struct sockaddr_in6); - saun->sin6.sin6_family = AF_INET6; - bcopy(&ia6, &saun->sin6.sin6_addr, sizeof(struct in6_addr)); - /* - saun->sin6.sin6_sin6_scope_id = in6_getscopezone(ifp, - in6_addrscope(&ia6)); - */ info->rti_info[RTAX_IFA] = (struct sockaddr *)&saun->sin6; break; } From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 14:46:14 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C263D118; Wed, 18 Dec 2013 14:46:14 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A2A2A1449; Wed, 18 Dec 2013 14:46:14 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIEkEJT034321; Wed, 18 Dec 2013 14:46:14 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIEkEiW034317; Wed, 18 Dec 2013 14:46:14 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181446.rBIEkEiW034317@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 14:46:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259554 - user/ae/inet6/sys/netinet X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 14:46:14 -0000 Author: ae Date: Wed Dec 18 14:46:13 2013 New Revision: 259554 URL: http://svnweb.freebsd.org/changeset/base/259554 Log: Update code in sys/netinet to use sockaddr_in6 with jail's functions. Modified: user/ae/inet6/sys/netinet/sctp_pcb.c user/ae/inet6/sys/netinet/sctp_usrreq.c user/ae/inet6/sys/netinet/tcp_usrreq.c Modified: user/ae/inet6/sys/netinet/sctp_pcb.c ============================================================================== --- user/ae/inet6/sys/netinet/sctp_pcb.c Wed Dec 18 14:45:03 2013 (r259553) +++ user/ae/inet6/sys/netinet/sctp_pcb.c Wed Dec 18 14:46:13 2013 (r259554) @@ -2803,7 +2803,7 @@ sctp_inpcb_bind(struct socket *so, struc * will transmute the ipv6 address to the * proper value. */ - if (p && (error = prison_local_ip6(p->td_ucred, &sin6->sin6_addr, + if (p && (error = prison_local_ip6(p->td_ucred, sin6, (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, error); return (error); Modified: user/ae/inet6/sys/netinet/sctp_usrreq.c ============================================================================== --- user/ae/inet6/sys/netinet/sctp_usrreq.c Wed Dec 18 14:45:03 2013 (r259553) +++ user/ae/inet6/sys/netinet/sctp_usrreq.c Wed Dec 18 14:46:13 2013 (r259554) @@ -5304,7 +5304,7 @@ sctp_setopt(struct socket *so, int optna error = EINVAL; break; } - if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr), + if (td != NULL && (error = prison_local_ip6(td->td_ucred, (struct sockaddr_in6 *)(addrs->addr), (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); break; @@ -5350,7 +5350,7 @@ sctp_setopt(struct socket *so, int optna } if (td != NULL && (error = prison_local_ip6(td->td_ucred, - &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr), + (struct sockaddr_in6 *)(addrs->addr), (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); break; @@ -5928,7 +5928,7 @@ sctp_connect(struct socket *so, struct s return (EINVAL); } sin6p = (struct sockaddr_in6 *)addr; - if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) { + if (p != NULL && (error = prison_remote_ip6(p->td_ucred, sin6p)) != 0) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); return (error); } Modified: user/ae/inet6/sys/netinet/tcp_usrreq.c ============================================================================== --- user/ae/inet6/sys/netinet/tcp_usrreq.c Wed Dec 18 14:45:03 2013 (r259553) +++ user/ae/inet6/sys/netinet/tcp_usrreq.c Wed Dec 18 14:46:13 2013 (r259554) @@ -549,7 +549,7 @@ tcp6_usr_connect(struct socket *so, stru inp->inp_vflag &= ~INP_IPV4; inp->inp_vflag |= INP_IPV6; inp->inp_inc.inc_flags |= INC_ISIPV6; - if ((error = prison_remote_ip6(td->td_ucred, &sin6p->sin6_addr)) != 0) + if ((error = prison_remote_ip6(td->td_ucred, sin6p)) != 0) goto out; if ((error = tcp6_connect(tp, nam, td)) != 0) goto out; From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 15:05:35 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A6F036C6; Wed, 18 Dec 2013 15:05:35 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9406215CC; Wed, 18 Dec 2013 15:05:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIF5Zri041541; Wed, 18 Dec 2013 15:05:35 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIF5ZP5041539; Wed, 18 Dec 2013 15:05:35 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181505.rBIF5ZP5041539@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 15:05:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259556 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 15:05:35 -0000 Author: ae Date: Wed Dec 18 15:05:35 2013 New Revision: 259556 URL: http://svnweb.freebsd.org/changeset/base/259556 Log: Remove prison_remote_ip6() call. in6_pcbconnect will check this. Modified: user/ae/inet6/sys/netinet6/udp6_usrreq.c Modified: user/ae/inet6/sys/netinet6/udp6_usrreq.c ============================================================================== --- user/ae/inet6/sys/netinet6/udp6_usrreq.c Wed Dec 18 14:53:36 2013 (r259555) +++ user/ae/inet6/sys/netinet6/udp6_usrreq.c Wed Dec 18 15:05:35 2013 (r259556) @@ -1010,9 +1010,6 @@ udp6_connect(struct socket *so, struct s } inp->inp_vflag &= ~INP_IPV4; inp->inp_vflag |= INP_IPV6; - error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr); - if (error != 0) - goto out; INP_HASH_WLOCK(&V_udbinfo); error = in6_pcbconnect(inp, nam, td->td_ucred); INP_HASH_WUNLOCK(&V_udbinfo); From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 15:13:31 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 19E2D98B; Wed, 18 Dec 2013 15:13:31 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0671B167C; Wed, 18 Dec 2013 15:13:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIFDUPl045181; Wed, 18 Dec 2013 15:13:30 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIFDUtg045180; Wed, 18 Dec 2013 15:13:30 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181513.rBIFDUtg045180@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 15:13:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259557 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 15:13:31 -0000 Author: ae Date: Wed Dec 18 15:13:30 2013 New Revision: 259557 URL: http://svnweb.freebsd.org/changeset/base/259557 Log: s/in6_addr/sockaddr_in6/ for prison_xxx_ip6 calls. Modified: user/ae/inet6/sys/netinet6/in6.c Modified: user/ae/inet6/sys/netinet6/in6.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6.c Wed Dec 18 15:05:35 2013 (r259556) +++ user/ae/inet6/sys/netinet6/in6.c Wed Dec 18 15:13:30 2013 (r259557) @@ -437,7 +437,7 @@ in6_control(struct socket *so, u_long cm if (error != 0) return (error); if (td != NULL && (error = prison_check_ip6(td->td_ucred, - &sa6->sin6_addr)) != 0) + sa6)) != 0) return (error); ia = in6ifa_ifpwithaddr(ifp, &sa6->sin6_addr); } else From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 16:12:52 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 273CCED9; Wed, 18 Dec 2013 16:12:52 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 13CDE1AE2; Wed, 18 Dec 2013 16:12:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIGCpZO066935; Wed, 18 Dec 2013 16:12:51 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIGCpKK066934; Wed, 18 Dec 2013 16:12:51 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181612.rBIGCpKK066934@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 16:12:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259559 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 16:12:52 -0000 Author: ae Date: Wed Dec 18 16:12:51 2013 New Revision: 259559 URL: http://svnweb.freebsd.org/changeset/base/259559 Log: Use sockaddr_in6 in prison_check_ip6. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Dec 18 15:27:48 2013 (r259558) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Dec 18 16:12:51 2013 (r259559) @@ -196,7 +196,7 @@ srcaddrcmp(struct srcaddr_choice *c, str if (!V_ip6_use_deprecated && IFA6_IS_DEPRECATED(ia)) return (-1); /* If jailed, only take addresses of the jail into account. */ - if (cred != NULL && prison_check_ip6(cred, IA6_IN6(ia)) != 0) + if (cred != NULL && prison_check_ip6(cred, IA6_SIN6(ia)) != 0) return (-1); /* Source address can not break the destination zone */ srcscope = in6_srcaddrscope(IA6_IN6(ia)); @@ -838,10 +838,12 @@ in6_pcbsetport(struct in6_addr *laddr, s INP_WLOCK_ASSERT(inp); INP_HASH_WLOCK_ASSERT(pcbinfo); +#if 0 error = prison_local_ip6(cred, laddr, ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)); if (error) return(error); +#endif /* XXX: this is redundant when called from in6_pcbbind */ if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0) From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 16:14:36 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 76D2BFC9; Wed, 18 Dec 2013 16:14:36 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 63DC61AED; Wed, 18 Dec 2013 16:14:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIGEa23067218; Wed, 18 Dec 2013 16:14:36 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIGEa9q067217; Wed, 18 Dec 2013 16:14:36 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312181614.rBIGEa9q067217@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 16:14:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259560 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 16:14:36 -0000 Author: ae Date: Wed Dec 18 16:14:35 2013 New Revision: 259560 URL: http://svnweb.freebsd.org/changeset/base/259560 Log: Try to use sticky output options when they aren't specified. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Dec 18 16:12:51 2013 (r259559) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Dec 18 16:14:35 2013 (r259560) @@ -587,6 +587,8 @@ in6_selectsrc(struct sockaddr_in6 *dst, INP_LOCK_ASSERT(inp); mopts = inp->in6p_moptions; fibnum = inp->inp_inc.inc_fibnum; + if (opts == NULL) + opts = inp->in6p_outputopts; } else { mopts = NULL; fibnum = RT_DEFAULT_FIB; From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 20:11:02 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 10006F84; Wed, 18 Dec 2013 20:11:02 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id F12461FEF; Wed, 18 Dec 2013 20:11:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBIKB14v054004; Wed, 18 Dec 2013 20:11:01 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBIKB1AX054003; Wed, 18 Dec 2013 20:11:01 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201312182011.rBIKB1AX054003@svn.freebsd.org> From: Peter Holm Date: Wed, 18 Dec 2013 20:11:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259567 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 20:11:02 -0000 Author: pho Date: Wed Dec 18 20:11:01 2013 New Revision: 259567 URL: http://svnweb.freebsd.org/changeset/base/259567 Log: Limit run time and be less verbose. Sponsored by: EMC / Isilon storage division Modified: user/pho/stress2/misc/md.sh Modified: user/pho/stress2/misc/md.sh ============================================================================== --- user/pho/stress2/misc/md.sh Wed Dec 18 20:04:04 2013 (r259566) +++ user/pho/stress2/misc/md.sh Wed Dec 18 20:11:01 2013 (r259567) @@ -47,8 +47,8 @@ export RUNDIR=${mntpoint}/stressX export KBLOCKS=30000 # Exaggerate disk capacity export INODES=8000 -for i in `jot 500`; do - (cd ../testcases/rw;./rw -t 2m -i 20) +for i in `jot 20`; do + (cd ../testcases/rw;./rw -t 2m -i 20 > /dev/null 2>&1) done while mount | grep -q ${mntpoint}; do From owner-svn-src-user@FreeBSD.ORG Wed Dec 18 21:29:24 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 274AE62C; Wed, 18 Dec 2013 21:29:24 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 11C7A1674; Wed, 18 Dec 2013 21:29:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBILTNEu080296; Wed, 18 Dec 2013 21:29:23 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBILTNhb080295; Wed, 18 Dec 2013 21:29:23 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201312182129.rBILTNhb080295@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 18 Dec 2013 21:29:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259575 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Dec 2013 21:29:24 -0000 Author: ae Date: Wed Dec 18 21:29:23 2013 New Revision: 259575 URL: http://svnweb.freebsd.org/changeset/base/259575 Log: If socket is already bound to the source, no need to apply jail's restrictions to it. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Dec 18 21:23:16 2013 (r259574) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Dec 18 21:29:23 2013 (r259575) @@ -677,13 +677,6 @@ in6_selectsrc(struct sockaddr_in6 *dst, * Otherwise, if the socket has already bound the source, just use it. */ if (inp != NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) { -#if 0 /* XXX: Jail support. */ - if (cred != NULL && - (error = prison_local_ip6(cred, &inp->in6p_laddr, - ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) - return (error); - bcopy(&inp->in6p_laddr, srcp, sizeof(*srcp)); -#endif if (ro == &ro6) RO_RTFREE(ro); *srcp = inp->in6p_laddr; From owner-svn-src-user@FreeBSD.ORG Thu Dec 19 10:28:55 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0D2F0CE4; Thu, 19 Dec 2013 10:28:55 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E183A11D1; Thu, 19 Dec 2013 10:28:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBJASsjr066009; Thu, 19 Dec 2013 10:28:54 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBJASsk7066008; Thu, 19 Dec 2013 10:28:54 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201312191028.rBJASsk7066008@svn.freebsd.org> From: Peter Holm Date: Thu, 19 Dec 2013 10:28:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259611 - user/pho/stress2/misc X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Dec 2013 10:28:55 -0000 Author: pho Date: Thu Dec 19 10:28:54 2013 New Revision: 259611 URL: http://svnweb.freebsd.org/changeset/base/259611 Log: Improved error reporting a bit. Sponsored by: EMC / Isilon storage division Modified: user/pho/stress2/misc/rename9.sh Modified: user/pho/stress2/misc/rename9.sh ============================================================================== --- user/pho/stress2/misc/rename9.sh Thu Dec 19 09:46:14 2013 (r259610) +++ user/pho/stress2/misc/rename9.sh Thu Dec 19 10:28:54 2013 (r259611) @@ -45,12 +45,15 @@ mount | grep $mntpoint | grep -q /dev/md mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart mdconfig -a -t swap -s 2g -u $mdstart bsdlabel -w md$mdstart auto -newfs -U md${mdstart}$part > /dev/null +newfs $newfs_flags md${mdstart}$part > /dev/null mount /dev/md${mdstart}$part $mntpoint rm -rf $mntpoint/.snap chmod 777 $mntpoint +(while true; do ls -lRi $mntpoint > /dev/null 2>&1; done) & su ${testuser} -c "cd $mntpoint; /tmp/rename9" +kill $! > /dev/null 2>&1 +wait ls -ilR $mntpoint | egrep -v "^total " while mount | grep -q md${mdstart}$part; do @@ -76,8 +79,8 @@ EOF #include pid_t spid; -char *logfile = "test.log"; -char new[128]; +char *fromFile = "fromFile.log"; +char toFile[128]; void cleanup() @@ -85,106 +88,73 @@ cleanup() kill(spid, SIGINT); } -static int -xstat(char *file, struct stat *s) -{ - int fd, r; - - if ((fd = open(file, O_RDONLY)) == -1) - return (-1); - r = fstat(fd, s); - - close(fd); - return (r); -} - static void -Stat() +statFrom() { struct stat sb; - int i; setproctitle("Stat"); for (;;) { - for (i = 0; i < 1000; i++) { - /* No problem if using open/fstat */ - if (0) - xstat(logfile, &sb); - else - stat(logfile, &sb); - stat(new, &sb); - } - usleep(100); + stat(fromFile, &sb); } } int main(void) { - struct stat sb1, sb2, sb3; - int fd, i, r1, r2, r3; + struct stat fb, tb, fa, ta; + int fd, i; if ((spid = fork()) == 0) - Stat(); + statFrom(); setproctitle("main"); atexit(cleanup); - for (i = 0; i < 200000; i++) { - bzero(&sb1, sizeof(sb1)); - bzero(&sb2, sizeof(sb2)); - if ((fd = open(logfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) - err(1, "creat(%s)", logfile); + for (i = 0;i < 100000; i++) { + bzero(&fb, sizeof(fb)); + bzero(&tb, sizeof(tb)); + bzero(&fa, sizeof(fa)); + bzero(&ta, sizeof(ta)); + + if ((fd = open(fromFile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) + err(1, "creat(%s)", fromFile); close(fd); - sprintf(new, "test.log.%05d", i); - if ((fd = open(new, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) - err(1, "creat(%s)", new); + sprintf(toFile, "toFile.log.%05d", i); + if ((fd = open(toFile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) + err(1, "creat(%s)", toFile); write(fd, "xxx", 3); close(fd); - if ((r3 = stat(new, &sb3)) == -1) - err(1, "stat(%s)", new); -#if 1 - if (rename(logfile, new) == -1) - warn("rename(%s, %s)", logfile, new); -#else - /* No cache problem is seen */ - if (link(logfile, new) == -1) - err(1, "link(%s, %s)", logfile, new); - if (unlink(logfile) == -1) - err(1, "unlink(%s)", logfile); -#endif - /* - * stat() for logfile and new will be identical sometimes, - * but only when Stat() is running. - */ - r1 = stat(logfile, &sb1); - r2 = stat(new, &sb2); - if (r1 == 0 && r2 == 0 && - bcmp(&sb1, &sb2, sizeof(sb1)) == 0) { - fprintf(stderr, "FAIL 1\n"); - fprintf(stderr, "%-15s: ino = %4d, nlink = %d, size = %jd\n", - logfile, sb1.st_ino, sb1.st_nlink, sb1.st_blocks); - fprintf(stderr, "%-15s: ino = %4d, nlink = %d, size = %jd\n", - new , sb2.st_ino, sb2.st_nlink, sb2.st_blocks); - } - if (sb2.st_ino == sb3.st_ino) { - fprintf(stderr, "FAIL 2\n"); - if (r1 == 0) - fprintf(stderr, - "sb1: %-15s: ino = %4d, nlink = %d, size = %jd\n", - logfile, sb1.st_ino, sb1.st_nlink, sb1.st_blocks); - if (r2 == 0) - fprintf(stderr, - "sb2: %-15s: ino = %4d, nlink = %d, size = %jd\n", - new, sb2.st_ino, sb2.st_nlink, sb2.st_blocks); - if (r3 == 0) + + stat(fromFile, &fb); + stat(toFile, &tb); + if (rename(fromFile, toFile) == -1) + warn("rename(%s, %s)", fromFile, toFile); + stat(fromFile, &fa); + if (stat(toFile, &ta) == -1) + err(1, "stat(%s)", toFile); + + if (tb.st_ino == ta.st_ino) { + fprintf(stderr, "FAIL: old and new \"To\" inode number is identical\n"); + fprintf(stderr, "stat() before the rename():\n"); + fprintf(stderr, + "%-16s: ino = %4d, nlink = %d, size = %jd\n", + fromFile, fb.st_ino, fb.st_nlink, fb.st_blocks); + fprintf(stderr, + "%-16s: ino = %4d, nlink = %d, size = %jd\n", + toFile, tb.st_ino, tb.st_nlink, tb.st_blocks); + fprintf(stderr, "\nstat() after the rename():\n"); + if (fa.st_ino != 0) fprintf(stderr, - "sb3: %-15s: ino = %4d, nlink = %d, size = %jd\n", - new , sb3.st_ino, sb3.st_nlink, sb3.st_blocks); + "%-16s: ino = %4d, nlink = %d, size = %jd\n", + fromFile, fa.st_ino, fa.st_nlink, fa.st_blocks); + fprintf(stderr, + "%-16s: ino = %4d, nlink = %d, size = %jd\n", + toFile, ta.st_ino, ta.st_nlink, ta.st_blocks); kill(spid, SIGINT); exit(1); } - unlink(new); + unlink(toFile); } kill(spid, SIGINT); From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 17:24:31 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B7BF4865; Sat, 21 Dec 2013 17:24:31 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8B3F71348; Sat, 21 Dec 2013 17:24:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLHOVg5030515; Sat, 21 Dec 2013 17:24:31 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLHOVL2030514; Sat, 21 Dec 2013 17:24:31 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211724.rBLHOVL2030514@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 17:24:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259687 - user/nwhitehorn/mips_pic_if X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 17:24:31 -0000 Author: nwhitehorn Date: Sat Dec 21 17:24:31 2013 New Revision: 259687 URL: http://svnweb.freebsd.org/changeset/base/259687 Log: Branch sys to convert MIPS to using pic_if.m for more flexible interrupt handling. Added: - copied from r259686, head/sys/ Directory Properties: user/nwhitehorn/mips_pic_if/ (props changed) From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 17:25:59 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2AC83963; Sat, 21 Dec 2013 17:25:59 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 13FB11352; Sat, 21 Dec 2013 17:25:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLHPxZb030725; Sat, 21 Dec 2013 17:25:59 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLHPuEL030706; Sat, 21 Dec 2013 17:25:56 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211725.rBLHPuEL030706@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 17:25:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259688 - in user/nwhitehorn/mips_pic_if: conf mips/adm5120 mips/alchemy mips/atheros mips/beri mips/include mips/malta mips/mips X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 17:25:59 -0000 Author: nwhitehorn Date: Sat Dec 21 17:25:55 2013 New Revision: 259688 URL: http://svnweb.freebsd.org/changeset/base/259688 Log: Make MALTA work using an adapted version of the PowerPC pic_if.m code. Every other kernel is broken for now, but the rest should be fairly mechanical. Added: user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c - copied, changed from r259687, user/nwhitehorn/mips_pic_if/mips/mips/intr_machdep.c user/nwhitehorn/mips_pic_if/mips/mips/pic_if.m - copied unchanged from r259684, head/sys/powerpc/powerpc/pic_if.m Replaced: user/nwhitehorn/mips_pic_if/mips/mips/intr_machdep.c - copied, changed from r259684, head/sys/powerpc/powerpc/intr_machdep.c Modified: user/nwhitehorn/mips_pic_if/conf/files.mips user/nwhitehorn/mips_pic_if/mips/adm5120/files.adm5120 user/nwhitehorn/mips_pic_if/mips/alchemy/files.alchemy user/nwhitehorn/mips_pic_if/mips/atheros/files.ar71xx user/nwhitehorn/mips_pic_if/mips/beri/files.beri user/nwhitehorn/mips_pic_if/mips/include/intr_machdep.h user/nwhitehorn/mips_pic_if/mips/malta/files.malta user/nwhitehorn/mips_pic_if/mips/mips/autoconf.c user/nwhitehorn/mips_pic_if/mips/mips/cpu.c user/nwhitehorn/mips_pic_if/mips/mips/machdep.c user/nwhitehorn/mips_pic_if/mips/mips/nexus.c Modified: user/nwhitehorn/mips_pic_if/conf/files.mips ============================================================================== --- user/nwhitehorn/mips_pic_if/conf/files.mips Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/conf/files.mips Sat Dec 21 17:25:55 2013 (r259688) @@ -22,14 +22,17 @@ mips/mips/fp.S standard mips/mips/freebsd32_machdep.c optional compat_freebsd32 mips/mips/gdb_machdep.c standard mips/mips/in_cksum.c optional inet +mips/mips/intr_machdep.c standard mips/mips/libkern_machdep.c standard mips/mips/locore.S standard no-obj mips/mips/machdep.c standard mips/mips/mem.c optional mem +mips/mips/mips_ic.c standard mips/mips/minidump_machdep.c standard mips/mips/mp_machdep.c optional smp mips/mips/mpboot.S optional smp mips/mips/nexus.c standard +mips/mips/pic_if.m standard mips/mips/pm_machdep.c standard mips/mips/pmap.c standard mips/mips/ptrace_machdep.c standard Modified: user/nwhitehorn/mips_pic_if/mips/adm5120/files.adm5120 ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/adm5120/files.adm5120 Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/adm5120/files.adm5120 Sat Dec 21 17:25:55 2013 (r259688) @@ -9,5 +9,4 @@ mips/adm5120/obio.c standard mips/adm5120/uart_bus_adm5120.c optional uart mips/adm5120/uart_cpu_adm5120.c optional uart mips/adm5120/uart_dev_adm5120.c optional uart -mips/mips/intr_machdep.c standard mips/mips/tick.c standard Modified: user/nwhitehorn/mips_pic_if/mips/alchemy/files.alchemy ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/alchemy/files.alchemy Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/alchemy/files.alchemy Sat Dec 21 17:25:55 2013 (r259688) @@ -5,5 +5,4 @@ mips/alchemy/alchemy_machdep.c standard mips/alchemy/obio.c standard mips/alchemy/uart_bus_alchemy.c optional uart mips/alchemy/uart_cpu_alchemy.c optional uart -mips/mips/intr_machdep.c standard mips/mips/tick.c standard Modified: user/nwhitehorn/mips_pic_if/mips/atheros/files.ar71xx ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/atheros/files.ar71xx Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/atheros/files.ar71xx Sat Dec 21 17:25:55 2013 (r259688) @@ -18,7 +18,6 @@ mips/atheros/uart_bus_ar933x.c optional mips/atheros/uart_cpu_ar933x.c optional uart_ar933x mips/atheros/uart_dev_ar933x.c optional uart_ar933x mips/atheros/ar71xx_bus_space_reversed.c standard -mips/mips/intr_machdep.c standard mips/mips/tick.c standard mips/atheros/ar71xx_setup.c standard mips/atheros/ar71xx_chip.c standard Modified: user/nwhitehorn/mips_pic_if/mips/beri/files.beri ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/beri/files.beri Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/beri/files.beri Sat Dec 21 17:25:55 2013 (r259688) @@ -18,5 +18,4 @@ dev/terasic/mtl/terasic_mtl_syscons.c op dev/terasic/mtl/terasic_mtl_text.c optional terasic_mtl mips/beri/beri_machdep.c standard mips/beri/beri_pic.c optional fdt -mips/mips/intr_machdep.c standard mips/mips/tick.c standard Modified: user/nwhitehorn/mips_pic_if/mips/include/intr_machdep.h ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/include/intr_machdep.h Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/include/intr_machdep.h Sat Dec 21 17:25:55 2013 (r259688) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2004 Juli Mallett + * Copyright (C) 2002 Benno Rice. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -11,17 +11,16 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ @@ -29,46 +28,28 @@ #ifndef _MACHINE_INTR_MACHDEP_H_ #define _MACHINE_INTR_MACHDEP_H_ -#include +#define INTR_VECTORS 256 -#if defined(CPU_RMI) || defined(CPU_NLM) -#define XLR_MAX_INTR 64 -#else -#define NHARD_IRQS 6 -#define NSOFT_IRQS 2 -#endif +extern device_t root_pic; struct trapframe; -void cpu_init_interrupts(void); -void cpu_establish_hardintr(const char *, driver_filter_t *, driver_intr_t *, - void *, int, int, void **); -void cpu_establish_softintr(const char *, driver_filter_t *, void (*)(void*), - void *, int, int, void **); -void cpu_intr(struct trapframe *); - -/* - * Allow a platform to override the default hard interrupt mask and unmask - * functions. The 'arg' can be cast safely to an 'int' and holds the mips - * hard interrupt number to mask or unmask. - */ -typedef void (*cpu_intr_mask_t)(void *arg); -typedef void (*cpu_intr_unmask_t)(void *arg); -void cpu_set_hardintr_mask_func(cpu_intr_mask_t func); -void cpu_set_hardintr_unmask_func(cpu_intr_unmask_t func); +driver_filter_t mips_ipi_handler; -/* - * Opaque datatype that represents intr counter - */ -typedef unsigned long* mips_intrcnt_t; +void intrcnt_add(const char *name, u_long **countp); + +void mips_register_pic(device_t, uint32_t, u_int, u_int); +u_int mips_get_irq(uint32_t, u_int); + +void mips_dispatch_intr(u_int, struct trapframe *); +int mips_enable_intr(void); +int mips_setup_intr(const char *, u_int, driver_filter_t, driver_intr_t, + void *, enum intr_type, void **); +int mips_teardown_intr(void *); +int mips_bind_intr(u_int irq, u_char cpu); +int mips_config_intr(int, enum intr_trigger, enum intr_polarity); +int mips_fw_config_intr(int irq, int sense_code); -mips_intrcnt_t mips_intrcnt_create(const char *); -void mips_intrcnt_setname(mips_intrcnt_t, const char *); +void cpu_intr(struct trapframe *tf); -static __inline void -mips_intrcnt_inc(mips_intrcnt_t counter) -{ - if (counter) - atomic_add_long(counter, 1); -} -#endif /* !_MACHINE_INTR_MACHDEP_H_ */ +#endif /* _MACHINE_INTR_MACHDEP_H_ */ Modified: user/nwhitehorn/mips_pic_if/mips/malta/files.malta ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/malta/files.malta Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/malta/files.malta Sat Dec 21 17:25:55 2013 (r259688) @@ -8,5 +8,4 @@ mips/malta/uart_bus_maltausart.c optiona dev/uart/uart_dev_ns8250.c optional uart mips/malta/malta_machdep.c standard mips/malta/yamon.c standard -mips/mips/intr_machdep.c standard mips/mips/tick.c standard Modified: user/nwhitehorn/mips_pic_if/mips/mips/autoconf.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/autoconf.c Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/mips/autoconf.c Sat Dec 21 17:25:55 2013 (r259688) @@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include static void configure_first(void *); @@ -102,6 +103,12 @@ static void configure_final(dummy) void *dummy; { + /* + * Now that we're guaranteed to have a PIC driver (or we'll never + * have one), program it with all the previously setup interrupts. + */ + mips_enable_intr(); + intr_enable(); cninit_finish(); Modified: user/nwhitehorn/mips_pic_if/mips/mips/cpu.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/cpu.c Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/mips/cpu.c Sat Dec 21 17:25:55 2013 (r259688) @@ -427,8 +427,8 @@ cpu_setup_intr(device_t dev, device_t ch intr = rman_get_start(res); - cpu_establish_hardintr(device_get_nameunit(child), filt, handler, arg, - intr, flags, cookiep); + mips_setup_intr(device_get_nameunit(child), intr, filt, handler, arg, + flags, cookiep); device_printf(child, "established CPU interrupt %d\n", intr); return (0); } Copied and modified: user/nwhitehorn/mips_pic_if/mips/mips/intr_machdep.c (from r259684, head/sys/powerpc/powerpc/intr_machdep.c) ============================================================================== --- head/sys/powerpc/powerpc/intr_machdep.c Sat Dec 21 15:40:36 2013 (r259684, copy source) +++ user/nwhitehorn/mips_pic_if/mips/mips/intr_machdep.c Sat Dec 21 17:25:55 2013 (r259688) @@ -60,8 +60,6 @@ * $FreeBSD$ */ -#include "opt_isa.h" - #include #include #include @@ -88,10 +86,11 @@ #include "pic_if.h" #define MAX_STRAY_LOG 5 +#define MAX_PICS 5 static MALLOC_DEFINE(M_INTR, "intr", "interrupt handler data"); -struct powerpc_intr { +struct mips_intr { struct intr_event *event; long *cntp; u_int irq; @@ -115,15 +114,11 @@ struct pic { static u_int intrcnt_index = 0; static struct mtx intr_table_lock; -static struct powerpc_intr *powerpc_intrs[INTR_VECTORS]; +static struct mips_intr *mips_intrs[INTR_VECTORS]; static struct pic piclist[MAX_PICS]; static u_int nvectors; /* Allocated vectors */ static u_int npics; /* PICs registered */ -#ifdef DEV_ISA -static u_int nirqs = 16; /* Allocated IRQS (ISA pre-allocated). */ -#else static u_int nirqs = 0; /* Allocated IRQs. */ -#endif static u_int stray_count; device_t root_pic; @@ -144,11 +139,11 @@ SYSINIT(intr_init, SI_SUB_INTR, SI_ORDER static void smp_intr_init(void *dummy __unused) { - struct powerpc_intr *i; + struct mips_intr *i; int vector; for (vector = 0; vector < nvectors; vector++) { - i = powerpc_intrs[vector]; + i = mips_intrs[vector]; if (i != NULL && i->pic == root_pic) PIC_BIND(i->pic, i->intline, i->cpu); } @@ -174,16 +169,16 @@ intrcnt_add(const char *name, u_long **c intrcnt_setname(name, idx); } -static struct powerpc_intr * +static struct mips_intr * intr_lookup(u_int irq) { char intrname[16]; - struct powerpc_intr *i, *iscan; + struct mips_intr *i, *iscan; int vector; mtx_lock(&intr_table_lock); for (vector = 0; vector < nvectors; vector++) { - i = powerpc_intrs[vector]; + i = mips_intrs[vector]; if (i != NULL && i->irq == irq) { mtx_unlock(&intr_table_lock); return (i); @@ -212,7 +207,7 @@ intr_lookup(u_int irq) for (vector = 0; vector < INTR_VECTORS && vector <= nvectors; vector++) { - iscan = powerpc_intrs[vector]; + iscan = mips_intrs[vector]; if (iscan != NULL && iscan->irq == irq) break; if (iscan == NULL && i->vector == -1) @@ -221,7 +216,7 @@ intr_lookup(u_int irq) } if (iscan == NULL && i->vector != -1) { - powerpc_intrs[i->vector] = i; + mips_intrs[i->vector] = i; i->cntindex = atomic_fetchadd_int(&intrcnt_index, 1); i->cntp = &intrcnt[i->cntindex]; sprintf(intrname, "irq%u:", i->irq); @@ -239,7 +234,7 @@ intr_lookup(u_int irq) } static int -powerpc_map_irq(struct powerpc_intr *i) +mips_map_irq(struct mips_intr *i) { struct pic *p; u_int cnt; @@ -265,35 +260,35 @@ powerpc_map_irq(struct powerpc_intr *i) } static void -powerpc_intr_eoi(void *arg) +mips_intr_eoi(void *arg) { - struct powerpc_intr *i = arg; + struct mips_intr *i = arg; PIC_EOI(i->pic, i->intline); } static void -powerpc_intr_pre_ithread(void *arg) +mips_intr_pre_ithread(void *arg) { - struct powerpc_intr *i = arg; + struct mips_intr *i = arg; PIC_MASK(i->pic, i->intline); PIC_EOI(i->pic, i->intline); } static void -powerpc_intr_post_ithread(void *arg) +mips_intr_post_ithread(void *arg) { - struct powerpc_intr *i = arg; + struct mips_intr *i = arg; PIC_UNMASK(i->pic, i->intline); } static int -powerpc_assign_intr_cpu(void *arg, u_char cpu) +mips_assign_intr_cpu(void *arg, u_char cpu) { #ifdef SMP - struct powerpc_intr *i = arg; + struct mips_intr *i = arg; if (cpu == NOCPU) i->cpu = all_cpus; @@ -310,8 +305,7 @@ powerpc_assign_intr_cpu(void *arg, u_cha } void -powerpc_register_pic(device_t dev, uint32_t node, u_int irqs, u_int ipis, - u_int atpic) +mips_register_pic(device_t dev, uint32_t node, u_int irqs, u_int ipis) { struct pic *p; u_int irq; @@ -319,7 +313,7 @@ powerpc_register_pic(device_t dev, uint3 mtx_lock(&intr_table_lock); - /* XXX see powerpc_get_irq(). */ + /* XXX see mips_get_irq(). */ for (idx = 0; idx < npics; idx++) { p = &piclist[idx]; if (p->node != node) @@ -334,11 +328,7 @@ powerpc_register_pic(device_t dev, uint3 p->irqs = irqs; p->ipis = ipis; if (idx == npics) { -#ifdef DEV_ISA - p->base = (atpic) ? 0 : nirqs; -#else p->base = nirqs; -#endif irq = p->base + irqs + ipis; nirqs = MAX(nirqs, irq); npics++; @@ -348,7 +338,7 @@ powerpc_register_pic(device_t dev, uint3 } u_int -powerpc_get_irq(uint32_t node, u_int pin) +mips_get_irq(uint32_t node, u_int pin) { int idx; @@ -383,9 +373,9 @@ powerpc_get_irq(uint32_t node, u_int pin } int -powerpc_enable_intr(void) +mips_enable_intr(void) { - struct powerpc_intr *i; + struct mips_intr *i; int error, vector; #ifdef SMP int n; @@ -407,9 +397,9 @@ powerpc_enable_intr(void) KASSERT(piclist[n].ipis != 0, ("%s: SMP root PIC does not supply any IPIs", __func__)); - error = powerpc_setup_intr("IPI", + error = mips_setup_intr("IPI", MAP_IRQ(piclist[n].node, piclist[n].irqs), - powerpc_ipi_handler, NULL, NULL, + mips_ipi_handler, NULL, NULL, INTR_TYPE_MISC | INTR_EXCL, &ipi_cookie); if (error) { printf("unable to setup IPI handler\n"); @@ -420,11 +410,11 @@ powerpc_enable_intr(void) #endif for (vector = 0; vector < nvectors; vector++) { - i = powerpc_intrs[vector]; + i = mips_intrs[vector]; if (i == NULL) continue; - error = powerpc_map_irq(i); + error = mips_map_irq(i); if (error) continue; @@ -443,10 +433,10 @@ powerpc_enable_intr(void) } int -powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter, +mips_setup_intr(const char *name, u_int irq, driver_filter_t filter, driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep) { - struct powerpc_intr *i; + struct mips_intr *i; int error, enable = 0; i = intr_lookup(irq); @@ -455,8 +445,8 @@ powerpc_setup_intr(const char *name, u_i if (i->event == NULL) { error = intr_event_create(&i->event, (void *)i, 0, irq, - powerpc_intr_pre_ithread, powerpc_intr_post_ithread, - powerpc_intr_eoi, powerpc_assign_intr_cpu, "irq%u:", irq); + mips_intr_pre_ithread, mips_intr_post_ithread, + mips_intr_eoi, mips_assign_intr_cpu, "irq%u:", irq); if (error) return (error); @@ -471,7 +461,7 @@ powerpc_setup_intr(const char *name, u_i mtx_unlock(&intr_table_lock); if (!cold) { - error = powerpc_map_irq(i); + error = mips_map_irq(i); if (!error) { if (i->trig == -1) @@ -493,7 +483,7 @@ powerpc_setup_intr(const char *name, u_i } int -powerpc_teardown_intr(void *cookie) +mips_teardown_intr(void *cookie) { return (intr_event_remove_handler(cookie)); @@ -501,9 +491,9 @@ powerpc_teardown_intr(void *cookie) #ifdef SMP int -powerpc_bind_intr(u_int irq, u_char cpu) +mips_bind_intr(u_int irq, u_char cpu) { - struct powerpc_intr *i; + struct mips_intr *i; i = intr_lookup(irq); if (i == NULL) @@ -514,9 +504,9 @@ powerpc_bind_intr(u_int irq, u_char cpu) #endif int -powerpc_fw_config_intr(int irq, int sense_code) +mips_fw_config_intr(int irq, int sense_code) { - struct powerpc_intr *i; + struct mips_intr *i; i = intr_lookup(irq); if (i == NULL) @@ -536,9 +526,9 @@ powerpc_fw_config_intr(int irq, int sens } int -powerpc_config_intr(int irq, enum intr_trigger trig, enum intr_polarity pol) +mips_config_intr(int irq, enum intr_trigger trig, enum intr_polarity pol) { - struct powerpc_intr *i; + struct mips_intr *i; i = intr_lookup(irq); if (i == NULL) @@ -554,12 +544,12 @@ powerpc_config_intr(int irq, enum intr_t } void -powerpc_dispatch_intr(u_int vector, struct trapframe *tf) +mips_dispatch_intr(u_int vector, struct trapframe *tf) { - struct powerpc_intr *i; + struct mips_intr *i; struct intr_event *ie; - i = powerpc_intrs[vector]; + i = mips_intrs[vector]; if (i == NULL) goto stray; @@ -585,3 +575,16 @@ stray: if (i != NULL) PIC_MASK(i->pic, i->intline); } + +void +cpu_intr(struct trapframe *tf) +{ + + PIC_DISPATCH(root_pic, tf); + +#ifdef HWPMC_HOOKS + if (pmc_hook && (PCPU_GET(curthread)->td_pflags & TDP_CALLCHAIN)) + pmc_hook(PCPU_GET(curthread), PMC_FN_USER_CALLCHAIN, tf); +#endif +} + Modified: user/nwhitehorn/mips_pic_if/mips/mips/machdep.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/machdep.c Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/mips/machdep.c Sat Dec 21 17:25:55 2013 (r259688) @@ -213,7 +213,6 @@ cpu_startup(void *dummy) printf("avail memory = %ju (%juMB)\n", ptoa((uintmax_t)cnt.v_free_count), ptoa((uintmax_t)cnt.v_free_count) / 1048576); - cpu_init_interrupts(); /* * Set up buffers, so they can be used to read disk labels. Copied and modified: user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c (from r259687, user/nwhitehorn/mips_pic_if/mips/mips/intr_machdep.c) ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/intr_machdep.c Sat Dec 21 17:24:31 2013 (r259687, copy source) +++ user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c Sat Dec 21 17:25:55 2013 (r259688) @@ -29,14 +29,13 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_hwpmc_hooks.h" - #include #include +#include #include -#include -#include -#include +#include +#include +#include #include #include @@ -48,182 +47,99 @@ __FBSDID("$FreeBSD$"); #include #include -static struct intr_event *hardintr_events[NHARD_IRQS]; -static struct intr_event *softintr_events[NSOFT_IRQS]; -static mips_intrcnt_t mips_intr_counters[NSOFT_IRQS + NHARD_IRQS]; - -static int intrcnt_index; - -static cpu_intr_mask_t hardintr_mask_func; -static cpu_intr_unmask_t hardintr_unmask_func; - -mips_intrcnt_t -mips_intrcnt_create(const char* name) -{ - mips_intrcnt_t counter = &intrcnt[intrcnt_index++]; +#include "pic_if.h" - mips_intrcnt_setname(counter, name); - return counter; -} - -void -mips_intrcnt_setname(mips_intrcnt_t counter, const char *name) -{ - int idx = counter - intrcnt; - - KASSERT(counter != NULL, ("mips_intrcnt_setname: NULL counter")); - - snprintf(intrnames + (MAXCOMLEN + 1) * idx, - MAXCOMLEN + 1, "%-*s", MAXCOMLEN, name); -} - -static void -mips_mask_hard_irq(void *source) -{ - uintptr_t irq = (uintptr_t)source; +static void mips_ic_identify(driver_t *driver, device_t parent); +static int mips_ic_probe(device_t); +static int mips_ic_attach(device_t); + +static void mips_ic_dispatch(device_t, struct trapframe *); +static void mips_ic_enable(device_t, u_int, u_int); +#ifdef NOTYET +static void mips_ic_ipi(device_t, u_int); +#endif +static void mips_ic_mask(device_t, u_int); +static void mips_ic_unmask(device_t, u_int); - mips_wr_status(mips_rd_status() & ~(((1 << irq) << 8) << 2)); -} +struct mips_ic_softc { + u_int vectors[6]; +}; + +static device_method_t mips_ic_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, mips_ic_identify), + DEVMETHOD(device_probe, mips_ic_probe), + DEVMETHOD(device_attach, mips_ic_attach), + + /* PIC interface */ + DEVMETHOD(pic_dispatch, mips_ic_dispatch), + DEVMETHOD(pic_enable, mips_ic_enable), + //DEVMETHOD(pic_ipi, mips_ic_ipi), + DEVMETHOD(pic_mask, mips_ic_mask), + DEVMETHOD(pic_unmask, mips_ic_unmask), + + DEVMETHOD_END, +}; + +static driver_t mips_ic_driver = { + "mipsic", + mips_ic_methods, + sizeof(struct mips_ic_softc) +}; -static void -mips_unmask_hard_irq(void *source) -{ - uintptr_t irq = (uintptr_t)source; +static devclass_t mips_ic_devclass; - mips_wr_status(mips_rd_status() | (((1 << irq) << 8) << 2)); -} +EARLY_DRIVER_MODULE(mipsic, nexus, mips_ic_driver, mips_ic_devclass, 0, 0, + BUS_PASS_INTERRUPT); static void -mips_mask_soft_irq(void *source) +mips_ic_identify(driver_t *driver, device_t parent) { - uintptr_t irq = (uintptr_t)source; - mips_wr_status(mips_rd_status() & ~((1 << irq) << 8)); + if (device_find_child(parent, "mipsic", -1) == NULL) + BUS_ADD_CHILD(parent, 0, "mipsic", 0); } -static void -mips_unmask_soft_irq(void *source) +static int +mips_ic_probe(device_t dev) { - uintptr_t irq = (uintptr_t)source; - mips_wr_status(mips_rd_status() | ((1 << irq) << 8)); + device_set_desc(dev, "MIPS Root Interrupt Controller"); + return (BUS_PROBE_NOWILDCARD); } -/* - * Perform initialization of interrupts prior to setting - * handlings - */ -void -cpu_init_interrupts() +static int +mips_ic_attach(device_t dev) { - int i; - char name[MAXCOMLEN + 1]; - /* - * Initialize all available vectors so spare IRQ - * would show up in systat output - */ - for (i = 0; i < NSOFT_IRQS; i++) { - snprintf(name, MAXCOMLEN + 1, "sint%d:", i); - mips_intr_counters[i] = mips_intrcnt_create(name); - } - - for (i = 0; i < NHARD_IRQS; i++) { - snprintf(name, MAXCOMLEN + 1, "int%d:", i); - mips_intr_counters[NSOFT_IRQS + i] = mips_intrcnt_create(name); - } -} + mips_register_pic(dev, 0, 6, 1); -void -cpu_set_hardintr_mask_func(cpu_intr_mask_t func) -{ - - hardintr_mask_func = func; + return (0); } -void -cpu_set_hardintr_unmask_func(cpu_intr_unmask_t func) +static void +mips_ic_mask(device_t dev, u_int irq) { - hardintr_unmask_func = func; + mips_wr_status(mips_rd_status() & ~(((1 << irq) << 8) << 2)); } -void -cpu_establish_hardintr(const char *name, driver_filter_t *filt, - void (*handler)(void*), void *arg, int irq, int flags, void **cookiep) +static void +mips_ic_unmask(device_t dev, u_int irq) { - struct intr_event *event; - int error; - - /* - * We have 6 levels, but thats 0 - 5 (not including 6) - */ - if (irq < 0 || irq >= NHARD_IRQS) - panic("%s called for unknown hard intr %d", __func__, irq); - - if (hardintr_mask_func == NULL) - hardintr_mask_func = mips_mask_hard_irq; - - if (hardintr_unmask_func == NULL) - hardintr_unmask_func = mips_unmask_hard_irq; - - event = hardintr_events[irq]; - if (event == NULL) { - error = intr_event_create(&event, (void *)(uintptr_t)irq, 0, - irq, hardintr_mask_func, hardintr_unmask_func, - NULL, NULL, "int%d", irq); - if (error) - return; - hardintr_events[irq] = event; - mips_unmask_hard_irq((void*)(uintptr_t)irq); - } - - intr_event_add_handler(event, name, filt, handler, arg, - intr_priority(flags), flags, cookiep); - - mips_intrcnt_setname(mips_intr_counters[NSOFT_IRQS + irq], - event->ie_fullname); -} - -void -cpu_establish_softintr(const char *name, driver_filter_t *filt, - void (*handler)(void*), void *arg, int irq, int flags, - void **cookiep) -{ - struct intr_event *event; - int error; - -#if 0 - printf("Establish SOFT IRQ %d: filt %p handler %p arg %p\n", - irq, filt, handler, arg); -#endif - if (irq < 0 || irq > NSOFT_IRQS) - panic("%s called for unknown hard intr %d", __func__, irq); - event = softintr_events[irq]; - if (event == NULL) { - error = intr_event_create(&event, (void *)(uintptr_t)irq, 0, - irq, mips_mask_soft_irq, mips_unmask_soft_irq, - NULL, NULL, "sint%d:", irq); - if (error) - return; - softintr_events[irq] = event; - mips_unmask_soft_irq((void*)(uintptr_t)irq); - } - - intr_event_add_handler(event, name, filt, handler, arg, - intr_priority(flags), flags, cookiep); - - mips_intrcnt_setname(mips_intr_counters[irq], event->ie_fullname); + mips_wr_status(mips_rd_status() | (((1 << irq) << 8) << 2)); } void -cpu_intr(struct trapframe *tf) +mips_ic_dispatch(device_t dev, struct trapframe *tf) { - struct intr_event *event; + struct mips_ic_softc *sc; register_t cause, status; int hard, i, intr; + sc = device_get_softc(dev); + critical_enter(); cause = mips_rd_cause(); @@ -238,6 +154,7 @@ cpu_intr(struct trapframe *tf) while ((i = fls(intr)) != 0) { intr &= ~(1 << (i - 1)); switch (i) { +#ifdef NOTYET case 1: case 2: /* Software interrupt. */ i--; /* Get a 0-offset interrupt. */ @@ -245,34 +162,29 @@ cpu_intr(struct trapframe *tf) event = softintr_events[i]; mips_intrcnt_inc(mips_intr_counters[i]); break; +#endif default: /* Hardware interrupt. */ i -= 2; /* Trim software interrupt bits. */ i--; /* Get a 0-offset interrupt. */ hard = 1; - event = hardintr_events[i]; - mips_intrcnt_inc(mips_intr_counters[NSOFT_IRQS + i]); + mips_dispatch_intr(sc->vectors[i], tf); break; } - - if (!event || TAILQ_EMPTY(&event->ie_handlers)) { - printf("stray %s interrupt %d\n", - hard ? "hard" : "soft", i); - continue; - } - - if (intr_event_handle(event, tf) != 0) { - printf("stray %s interrupt %d\n", - hard ? "hard" : "soft", i); - } } KASSERT(i == 0, ("all interrupts handled")); critical_exit(); +} -#ifdef HWPMC_HOOKS - if (pmc_hook && (PCPU_GET(curthread)->td_pflags & TDP_CALLCHAIN)) - pmc_hook(PCPU_GET(curthread), PMC_FN_USER_CALLCHAIN, tf); -#endif +static void +mips_ic_enable(device_t dev, u_int irq, u_int vector) +{ + struct mips_ic_softc *sc; + + sc = device_get_softc(dev); + sc->vectors[irq] = vector; + mips_ic_unmask(dev, irq); } + Modified: user/nwhitehorn/mips_pic_if/mips/mips/nexus.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/nexus.c Sat Dec 21 17:24:31 2013 (r259687) +++ user/nwhitehorn/mips_pic_if/mips/mips/nexus.c Sat Dec 21 17:25:55 2013 (r259688) @@ -432,19 +432,16 @@ nexus_setup_intr(device_t dev, device_t driver_filter_t *filt, driver_intr_t *intr, void *arg, void **cookiep) { register_t s; - int irq; + int irq, error; + error = 0; s = intr_disable(); irq = rman_get_start(res); - if (irq >= NUM_MIPS_IRQS) { - intr_restore(s); - return (0); - } - cpu_establish_hardintr(device_get_nameunit(child), filt, intr, arg, - irq, flags, cookiep); + error = mips_setup_intr(device_get_nameunit(child), irq, filt, intr, + arg, flags, cookiep); intr_restore(s); - return (0); + return (error); } static int @@ -508,4 +505,5 @@ nexus_hinted_child(device_t bus, const c } } -DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0); +EARLY_DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0, + BUS_PASS_BUS); Copied: user/nwhitehorn/mips_pic_if/mips/mips/pic_if.m (from r259684, head/sys/powerpc/powerpc/pic_if.m) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/nwhitehorn/mips_pic_if/mips/mips/pic_if.m Sat Dec 21 17:25:55 2013 (r259688, copy of r259684, head/sys/powerpc/powerpc/pic_if.m) @@ -0,0 +1,98 @@ +#- +# Copyright (c) 1998 Doug Rabson +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# from: src/sys/kern/bus_if.m,v 1.21 2002/04/21 11:16:10 markm Exp +# $FreeBSD$ +# + +#include +#include +#include + +INTERFACE pic; + +CODE { + static pic_translate_code_t pic_translate_code_default; + + static void pic_translate_code_default(device_t dev, u_int irq, + int code, enum intr_trigger *trig, enum intr_polarity *pol) + { + *trig = INTR_TRIGGER_CONFORM; + *pol = INTR_POLARITY_CONFORM; + } +}; + +METHOD void bind { + device_t dev; + u_int irq; + cpuset_t cpumask; +}; + +METHOD void translate_code { + device_t dev; + u_int irq; + int code; + enum intr_trigger *trig; + enum intr_polarity *pol; +} DEFAULT pic_translate_code_default; + +METHOD void config { + device_t dev; + u_int irq; + enum intr_trigger trig; + enum intr_polarity pol; +}; + +METHOD void dispatch { + device_t dev; + struct trapframe *tf; +}; + +METHOD void enable { + device_t dev; + u_int irq; + u_int vector; +}; + +METHOD void eoi { + device_t dev; + u_int irq; +}; + +METHOD void ipi { + device_t dev; + u_int cpu; +}; + +METHOD void mask { + device_t dev; + u_int irq; +}; + +METHOD void unmask { + device_t dev; + u_int irq; +}; + *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 17:36:33 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 362E0BC1; Sat, 21 Dec 2013 17:36:33 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 22BFB1450; Sat, 21 Dec 2013 17:36:33 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLHaXpn034239; Sat, 21 Dec 2013 17:36:33 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLHaWoS034238; Sat, 21 Dec 2013 17:36:32 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211736.rBLHaWoS034238@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 17:36:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259689 - user/nwhitehorn/mips_pic_if/mips/mips X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 17:36:33 -0000 Author: nwhitehorn Date: Sat Dec 21 17:36:32 2013 New Revision: 259689 URL: http://svnweb.freebsd.org/changeset/base/259689 Log: Make sure the CPU PIC is the root pic. Modified: user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c Modified: user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c Sat Dec 21 17:25:55 2013 (r259688) +++ user/nwhitehorn/mips_pic_if/mips/mips/mips_ic.c Sat Dec 21 17:36:32 2013 (r259689) @@ -113,6 +113,7 @@ mips_ic_attach(device_t dev) { mips_register_pic(dev, 0, 6, 1); + root_pic = dev; return (0); } From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 17:43:23 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E0354D9A; Sat, 21 Dec 2013 17:43:23 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B3D22152D; Sat, 21 Dec 2013 17:43:23 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLHhNrv037284; Sat, 21 Dec 2013 17:43:23 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLHhNf8037283; Sat, 21 Dec 2013 17:43:23 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211743.rBLHhNf8037283@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 17:43:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259690 - user/nwhitehorn/mips_pic_if/mips/mips X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 17:43:23 -0000 Author: nwhitehorn Date: Sat Dec 21 17:43:23 2013 New Revision: 259690 URL: http://svnweb.freebsd.org/changeset/base/259690 Log: Support interrupt allocation in multiple domains. Modified: user/nwhitehorn/mips_pic_if/mips/mips/nexus.c Modified: user/nwhitehorn/mips_pic_if/mips/mips/nexus.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/mips/nexus.c Sat Dec 21 17:36:32 2013 (r259689) +++ user/nwhitehorn/mips_pic_if/mips/mips/nexus.c Sat Dec 21 17:43:23 2013 (r259690) @@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$"); #ifdef FDT #include +#include +#include "ofw_bus_if.h" #endif #undef NEXUS_DEBUG @@ -113,6 +115,14 @@ static int nexus_setup_intr(device_t dev driver_intr_t *intr, void *arg, void **cookiep); static int nexus_teardown_intr(device_t, device_t, struct resource *, void *); +#ifdef SMP +static bus_bind_intr_t nexus_bind_intr; +#endif +static bus_config_intr_t nexus_config_intr; +#ifdef FDT +static ofw_bus_map_intr_t nexus_ofw_map_intr; +static ofw_bus_config_intr_t nexus_ofw_config_intr; +#endif static device_method_t nexus_methods[] = { #ifndef FDT @@ -135,6 +145,14 @@ static device_method_t nexus_methods[] = DEVMETHOD(bus_activate_resource,nexus_activate_resource), DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), DEVMETHOD(bus_hinted_child, nexus_hinted_child), +#ifdef SMP + DEVMETHOD(bus_bind_intr, nexus_bind_intr), +#endif + DEVMETHOD(bus_config_intr, nexus_config_intr), +#ifdef FDT + DEVMETHOD(ofw_bus_map_intr, nexus_ofw_map_intr), + DEVMETHOD(ofw_bus_config_intr, nexus_ofw_config_intr), +#endif { 0, 0 } }; @@ -505,5 +523,39 @@ nexus_hinted_child(device_t bus, const c } } +#ifdef SMP +static int +nexus_bind_intr(device_t bus __unused, device_t child __unused, + struct resource *r, int cpu) +{ + + return (powerpc_bind_intr(rman_get_start(r), cpu)); +} +#endif + +static int +nexus_config_intr(device_t dev, int irq, enum intr_trigger trig, + enum intr_polarity pol) +{ + + return (mips_config_intr(irq, trig, pol)); +} + +#ifdef FDT +static int +nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int irq) +{ + + return (mips_get_irq(iparent, irq)); +} + +static int +nexus_ofw_config_intr(device_t dev, device_t child, int irq, int sense) +{ + + return (mips_fw_config_intr(irq, sense)); +} +#endif + EARLY_DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0, BUS_PASS_BUS); From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 18:01:02 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E185DFF; Sat, 21 Dec 2013 18:01:02 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id CDC36168D; Sat, 21 Dec 2013 18:01:02 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLI12JX044041; Sat, 21 Dec 2013 18:01:02 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLI12xi044040; Sat, 21 Dec 2013 18:01:02 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211801.rBLI12xi044040@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 18:01:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259691 - user/nwhitehorn/mips_pic_if/mips/beri X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 18:01:02 -0000 Author: nwhitehorn Date: Sat Dec 21 18:01:02 2013 New Revision: 259691 URL: http://svnweb.freebsd.org/changeset/base/259691 Log: Make this compile, but not work. Some XXX notes at the bottom for what needs to be implemented, which I couldn't figure out. Modified: user/nwhitehorn/mips_pic_if/mips/beri/beri_pic.c Modified: user/nwhitehorn/mips_pic_if/mips/beri/beri_pic.c ============================================================================== --- user/nwhitehorn/mips_pic_if/mips/beri/beri_pic.c Sat Dec 21 17:43:23 2013 (r259690) +++ user/nwhitehorn/mips_pic_if/mips/beri/beri_pic.c Sat Dec 21 18:01:02 2013 (r259691) @@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$"); #include -#include "fdt_ic_if.h" +#include "pic_if.h" struct beripic_softc; @@ -57,27 +57,10 @@ static void bp_write_cfg(struct beripic_ static void bp_detach_resources(device_t); static char *bp_strconfig(uint64_t, char *, size_t); static void bp_config_source(device_t, int, int, u_long, u_long); -#ifdef __mips__ -static void bp_set_counter_name(device_t, device_t, int); -#endif static int beripic_fdt_probe(device_t); static int beripic_fdt_attach(device_t); -static int beripic_activate_intr(device_t, struct resource *); -static struct resource * - beripic_alloc_intr(device_t, device_t, int *, u_long, u_int); -static int beripic_config_intr(device_t, int, enum intr_trigger, - enum intr_polarity); -static int beripic_release_intr(device_t, struct resource *); -static int beripic_setup_intr(device_t, device_t, struct resource *, - int, driver_filter_t *, driver_intr_t *, void *, void **); -static int beripic_teardown_intr(device_t, device_t, struct resource *, - void *); - -static int beripic_filter(void *); -static void beripic_intr(void *); - #define BP_MAX_HARD_IRQS 6 #define BP_FIRST_SOFT 64 @@ -113,29 +96,9 @@ struct beripic_softc { int bp_nsrcs; struct rman bp_src_rman; -#ifdef __mips__ - mips_intrcnt_t *bp_counters; -#endif - struct mtx bp_cfgmtx; }; -struct beripic_intr_arg { - driver_filter_t *filter; - driver_intr_t *intr; - void *arg; - struct resource *irq; -#ifdef __mips__ - mips_intrcnt_t counter; -#endif -}; - -struct beripic_cookie { - struct beripic_intr_arg *bpia; - struct resource *hirq; - void *cookie; -}; - #define BP_CFG_MASK_E 0x80000000ull #define BP_CFG_SHIFT_E 31 #define BP_CFG_MASK_TID 0x7FFFFF00ull /* Depends on CPU */ @@ -231,25 +194,6 @@ bp_config_source(device_t ic, int src, i bp_write_cfg(sc, src, config); } -#ifdef __mips__ -static void -bp_set_counter_name(device_t ic, device_t child, int src) -{ - struct beripic_softc *sc; - char name[MAXCOMLEN + 1]; - - sc = device_get_softc(ic); - - if (snprintf(name, sizeof(name), "bp%dsrc%d%s%s%s", - device_get_unit(ic), src, src < sc->bp_nhard ? "" : "s", - child == NULL ? "" : " ", - child == NULL ? " " : device_get_nameunit(child)) >= sizeof(name)) - name[sizeof(name) - 2] = '+'; - - mips_intrcnt_setname(sc->bp_counters[src], name); -} -#endif - static int beripic_fdt_probe(device_t dev) { @@ -266,7 +210,6 @@ beripic_fdt_attach(device_t dev) { char configstr[64]; struct beripic_softc *sc; - struct fdt_ic *fic; pcell_t nhard, nsoft; phandle_t ph; int error, i, src; @@ -352,7 +295,7 @@ beripic_fdt_attach(device_t dev) } sc->bp_nirqs = i; - ph = ofw_bus_gen_get_node(device_get_parent(dev), dev); + ph = ofw_bus_get_node(dev); #ifndef SMP sc->bp_nthreads = 1; @@ -390,15 +333,6 @@ beripic_fdt_attach(device_t dev) device_printf(dev, "%d hard and %d soft sources\n", sc->bp_nhard, sc->bp_nsoft); -#ifdef __mips__ - sc->bp_counters = malloc(sizeof(*sc->bp_counters) * sc->bp_nsrcs, - M_BERIPIC, M_WAITOK|M_ZERO); - for (i = 0; i < sc->bp_nsrcs; i++) { - sc->bp_counters[i] = mips_intrcnt_create(""); - bp_set_counter_name(dev, NULL, i); - } -#endif - sc->bp_src_rman.rm_start = 0; sc->bp_src_rman.rm_end = sc->bp_nsrcs - 1; sc->bp_src_rman.rm_type = RMAN_ARRAY; @@ -436,10 +370,7 @@ beripic_fdt_attach(device_t dev) bp_config_source(dev, src, 0, 0, 0); } - fic = malloc(sizeof(*fic), M_BERIPIC, M_WAITOK|M_ZERO); - fic->iph = ph; - fic->dev = dev; - SLIST_INSERT_HEAD(&fdt_ic_list_head, fic, fdt_ics); + mips_register_pic(dev, 0, nhard + nsoft, ph); return (0); err: @@ -448,184 +379,33 @@ err: return (error); } -static struct resource * -beripic_alloc_intr(device_t ic, device_t child, int *rid, u_long irq, - u_int flags) -{ - struct beripic_softc *sc; - struct resource *rv; - - sc = device_get_softc(ic); - - rv = rman_reserve_resource(&(sc->bp_src_rman), irq, irq, 1, flags, - child); - if (rv == NULL) - printf("%s: could not reserve source interrupt for %s\n", - __func__, device_get_nameunit(child)); - rman_set_rid(rv, *rid); - - if ((flags & RF_ACTIVE) && - beripic_activate_intr(ic, rv) != 0) { - printf("%s: could not activate interrupt\n", __func__); - rman_release_resource(rv); - return (NULL); - } - - return (rv); -} - -static int -beripic_release_intr(device_t ic, struct resource *r) -{ - - return (rman_release_resource(r)); -} - -static int -beripic_activate_intr(device_t ic, struct resource *r) -{ - - return (rman_activate_resource(r)); -} - -static int -beripic_deactivate_intr(device_t ic, struct resource *r) -{ - - return (rman_deactivate_resource(r)); -} - -static int -beripic_config_intr(device_t dev, int irq, enum intr_trigger trig, +static void +beripic_config_intr(device_t dev, u_int irq, enum intr_trigger trig, enum intr_polarity pol) { - - if (trig != INTR_TRIGGER_CONFORM || pol != INTR_POLARITY_CONFORM) - return (EINVAL); - - return (0); } -static int -beripic_setup_intr(device_t ic, device_t child, struct resource *irq, - int flags, driver_filter_t *filter, driver_intr_t *intr, void *arg, - void **cookiep) +static void +beripic_enable(device_t ic, u_int irq, u_int vector) { struct beripic_softc *sc; - struct beripic_intr_arg *bpia; - struct beripic_cookie *bpc; - int error; - u_long hirq, src, tid; + u_long tid; sc = device_get_softc(ic); - src = rman_get_start(irq); - - KASSERT(src < sc->bp_nsrcs, ("source (%lu) out of range 0-%d", - src, sc->bp_nsrcs - 1)); - - bpia = malloc(sizeof(*bpia), M_BERIPIC, M_WAITOK|M_ZERO); - bpia->filter = filter; - bpia->intr = intr; - bpia->arg = arg; - bpia->irq = irq; -#ifdef __mips__ - bpia->counter = sc->bp_counters[src]; - bp_set_counter_name(ic, child, src); -#endif - - bpc = malloc(sizeof(*bpc), M_BERIPIC, M_WAITOK|M_ZERO); - bpc->bpia = bpia; - mtx_lock(&(sc->bp_cfgmtx)); - bpc->hirq = sc->bp_irqs[sc->bp_next_irq]; - hirq = rman_get_start(bpc->hirq); tid = sc->bp_next_tid; - error = BUS_SETUP_INTR(device_get_parent(ic), ic, bpc->hirq, flags, - beripic_filter, intr == NULL ? NULL : beripic_intr, bpia, - &(bpc->cookie)); - if (error != 0) - goto err; - #ifdef NOTYET #ifdef SMP - /* XXX: bind ithread to cpu */ + /* implement bind operation */ sc->bp_next_tid++; if (sc->bp_next_tid >= sc->bp_nthreads) sc->bp_next_tid = 0; #endif #endif - if (sc->bp_next_tid == 0) { - sc->bp_next_irq++; - if (sc->bp_next_irq >= sc->bp_nirqs) - sc->bp_next_irq = 0; - } + bp_config_source(ic, irq, 1, tid, vector); mtx_unlock(&(sc->bp_cfgmtx)); - - *cookiep = bpc; - - bp_config_source(ic, rman_get_start(irq), 1, tid, hirq); - - return (0); -err: - free(bpc, M_BERIPIC); - free(bpia, M_BERIPIC); - - return (error); -} - -static int -beripic_teardown_intr(device_t dev, device_t child, struct resource *irq, - void *cookie) -{ - struct beripic_cookie *bpc; - int error; - - bpc = cookie; - - bp_config_source(dev, rman_get_start(irq), 0, 0, 0); - - free(bpc->bpia, M_BERIPIC); - - error = BUS_TEARDOWN_INTR(device_get_parent(dev), dev, bpc->hirq, - bpc->cookie); - - free(bpc, M_BERIPIC); - - return (error); -} - -static int -beripic_filter(void *arg) -{ - struct beripic_intr_arg *bpic; - - bpic = arg; - -#ifdef __mips__ - mips_intrcnt_inc(bpic->counter); -#endif - - /* XXX: Add a check that our source is high */ - - if (bpic->filter == NULL) - return (FILTER_SCHEDULE_THREAD); - - return (bpic->filter(bpic->arg)); -} - -static void -beripic_intr(void *arg) -{ - struct beripic_intr_arg *bpic; - - bpic = arg; - - KASSERT(bpic->intr != NULL, - ("%s installed, but no child intr", __func__)); - - bpic->intr(bpic->arg); } #ifdef SMP @@ -667,6 +447,30 @@ beripic_clear_ipi(device_t ic, u_int tid } #endif +static void +beripic_dispatch(device_t dev, struct trapframe *tf) +{ + /* XXX figure out which line fired, call mips_dispatch_intr(vector) + * for each. Should call this from a filter handler for the beripic's + * interrupt + */ +} + +static void +beripic_mask(device_t dev, u_int irq) +{ +} + +static void +beripic_unmask(device_t dev, u_int irq) +{ +} + +static void +beripic_eoi(device_t dev, u_int irq) +{ +} + devclass_t beripic_devclass; static device_method_t beripic_fdt_methods[] = { @@ -674,19 +478,16 @@ static device_method_t beripic_fdt_metho DEVMETHOD(device_probe, beripic_fdt_probe), DEVMETHOD(device_attach, beripic_fdt_attach), - DEVMETHOD(fdt_ic_activate_intr, beripic_activate_intr), - DEVMETHOD(fdt_ic_alloc_intr, beripic_alloc_intr), - DEVMETHOD(fdt_ic_config_intr, beripic_config_intr), - DEVMETHOD(fdt_ic_deactivate_intr, beripic_deactivate_intr), - DEVMETHOD(fdt_ic_release_intr, beripic_release_intr), - DEVMETHOD(fdt_ic_setup_intr, beripic_setup_intr), - DEVMETHOD(fdt_ic_teardown_intr, beripic_teardown_intr), - + /* PIC interface */ + DEVMETHOD(pic_dispatch, beripic_dispatch), + DEVMETHOD(pic_enable, beripic_enable), + DEVMETHOD(pic_config, beripic_config_intr), #ifdef SMP - DEVMETHOD(fdt_ic_setup_ipi, beripic_setup_ipi), - DEVMETHOD(fdt_ic_clear_ipi, beripic_clear_ipi), - DEVMETHOD(fdt_ic_send_ipi, beripic_send_ipi), + DEVMETHOD(pic_ipi, beripic_send_ipi), #endif + DEVMETHOD(pic_mask, beripic_mask), + DEVMETHOD(pic_unmask, beripic_unmask), + DEVMETHOD(pic_eoi, beripic_eoi), { 0, 0 }, }; From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 18:16:43 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 814DD57E; Sat, 21 Dec 2013 18:16:43 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6209517A9; Sat, 21 Dec 2013 18:16:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLIGhfN048710; Sat, 21 Dec 2013 18:16:43 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLIGhaf048709; Sat, 21 Dec 2013 18:16:43 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211816.rBLIGhaf048709@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 18:16:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259692 - user/nwhitehorn/mips_pic_if/dev/fdt X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 18:16:43 -0000 Author: nwhitehorn Date: Sat Dec 21 18:16:42 2013 New Revision: 259692 URL: http://svnweb.freebsd.org/changeset/base/259692 Log: New simpler version of simple bus that participates in the standard ofw_bus interrupt mapping scheme. Modified: user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c Modified: user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c ============================================================================== --- user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c Sat Dec 21 18:01:02 2013 (r259691) +++ user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c Sat Dec 21 18:16:42 2013 (r259692) @@ -1,10 +1,7 @@ /*- - * Copyright (c) 2009-2010 The FreeBSD Foundation + * Copyright (c) 2013 Nathan Whitehorn * All rights reserved. * - * This software was developed by Semihalf under sponsorship from - * the FreeBSD Foundation. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -17,7 +14,7 @@ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -29,97 +26,85 @@ #include __FBSDID("$FreeBSD$"); - -#include "opt_platform.h" #include #include -#include -#include #include #include +#include +#include #include -#include - -#include +#include #include #include -#include - -#include "fdt_common.h" -#include "fdt_ic_if.h" -#include "ofw_bus_if.h" - -#ifdef DEBUG -#define debugf(fmt, args...) do { printf("%s(): ", __func__); \ - printf(fmt,##args); } while (0) -#else -#define debugf(fmt, args...) -#endif -static MALLOC_DEFINE(M_SIMPLEBUS, "simplebus", "simplebus devices information"); +struct simplebus_range { + uint64_t bus; + uint64_t host; + uint64_t size; +}; struct simplebus_softc { - int sc_addr_cells; - int sc_size_cells; + device_t dev; + phandle_t node; + + struct simplebus_range *ranges; + int nranges; + + pcell_t acells, scells; }; struct simplebus_devinfo { - struct ofw_bus_devinfo di_ofw; - struct resource_list di_res; - - /* Interrupts sense-level info for this device */ - struct fdt_sense_level di_intr_sl[DI_MAX_INTR_NUM]; + struct ofw_bus_devinfo obdinfo; + struct resource_list rl; }; /* - * Prototypes. + * Bus interface. */ -static int simplebus_probe(device_t); -static int simplebus_attach(device_t); - -static int simplebus_print_child(device_t, device_t); -static int simplebus_setup_intr(device_t, device_t, struct resource *, int, - driver_filter_t *, driver_intr_t *, void *, void **); -static int simplebus_teardown_intr(device_t, device_t, struct resource *, - void *); - -static int simplebus_activate_resource(device_t, device_t, int, int, - struct resource *); +static int simplebus_probe(device_t dev); +static int simplebus_attach(device_t dev); static struct resource *simplebus_alloc_resource(device_t, device_t, int, int *, u_long, u_long, u_long, u_int); -static int simplebus_deactivate_resource(device_t, device_t, int, int, - struct resource *); -static int simplebus_release_resource(device_t, device_t, int, int, - struct resource *); -static device_t simplebus_get_interrupt_parent(device_t); -static struct resource_list *simplebus_get_resource_list(device_t, device_t); +static void simplebus_probe_nomatch(device_t bus, device_t child); +static int simplebus_print_child(device_t bus, device_t child); + +/* + * ofw_bus interface + */ +static const struct ofw_bus_devinfo *simplebus_get_devinfo(device_t bus, + device_t child); + +/* + * local methods + */ -static ofw_bus_get_devinfo_t simplebus_get_devinfo; +static int simplebus_fill_ranges(phandle_t node, + struct simplebus_softc *sc); +static struct simplebus_devinfo *simplebus_setup_dinfo(device_t dev, + phandle_t node); /* - * Bus interface definition. + * Driver methods. */ -static device_method_t simplebus_methods[] = { +static device_method_t simplebus_methods[] = { /* Device interface */ DEVMETHOD(device_probe, simplebus_probe), DEVMETHOD(device_attach, simplebus_attach), - DEVMETHOD(device_detach, bus_generic_detach), - DEVMETHOD(device_shutdown, bus_generic_shutdown), - DEVMETHOD(device_suspend, bus_generic_suspend), - DEVMETHOD(device_resume, bus_generic_resume), /* Bus interface */ DEVMETHOD(bus_print_child, simplebus_print_child), + DEVMETHOD(bus_probe_nomatch, simplebus_probe_nomatch), + DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), + DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), DEVMETHOD(bus_alloc_resource, simplebus_alloc_resource), - DEVMETHOD(bus_release_resource, simplebus_release_resource), - DEVMETHOD(bus_activate_resource, simplebus_activate_resource), - DEVMETHOD(bus_deactivate_resource, simplebus_deactivate_resource), - DEVMETHOD(bus_setup_intr, simplebus_setup_intr), - DEVMETHOD(bus_teardown_intr, simplebus_teardown_intr), - DEVMETHOD(bus_get_resource_list, simplebus_get_resource_list), + DEVMETHOD(bus_release_resource, bus_generic_release_resource), + DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), + DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource), + DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str), - /* OFW bus interface */ + /* ofw_bus interface */ DEVMETHOD(ofw_bus_get_devinfo, simplebus_get_devinfo), DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat), DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model), @@ -127,7 +112,7 @@ static device_method_t simplebus_methods DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node), DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type), - { 0, 0 } + DEVMETHOD_END }; static driver_t simplebus_driver = { @@ -135,18 +120,15 @@ static driver_t simplebus_driver = { simplebus_methods, sizeof(struct simplebus_softc) }; - -devclass_t simplebus_devclass; - +static devclass_t simplebus_devclass; DRIVER_MODULE(simplebus, nexus, simplebus_driver, simplebus_devclass, 0, 0); -DRIVER_MODULE(simplebus, simplebus, simplebus_driver, simplebus_devclass, 0, - 0); static int simplebus_probe(device_t dev) { - - if (!ofw_bus_is_compatible(dev, "simple-bus")) + + if (!ofw_bus_is_compatible(dev, "simple-bus") && + (ofw_bus_get_type(dev) == NULL || strcmp(ofw_bus_get_type(dev), "soc") != 0)) return (ENXIO); device_set_desc(dev, "Flattened device tree simple bus"); @@ -157,102 +139,189 @@ simplebus_probe(device_t dev) static int simplebus_attach(device_t dev) { - device_t dev_child; - struct simplebus_devinfo *di; - struct simplebus_softc *sc; - phandle_t dt_node, dt_child; + struct simplebus_softc *sc; + struct simplebus_devinfo *di; + phandle_t node; + device_t cdev; + node = ofw_bus_get_node(dev); sc = device_get_softc(dev); + sc->dev = dev; + sc->node = node; + /* - * Walk simple-bus and add direct subordinates as our children. + * Some important numbers */ - dt_node = ofw_bus_get_node(dev); - for (dt_child = OF_child(dt_node); dt_child != 0; - dt_child = OF_peer(dt_child)) { - - /* Check and process 'status' property. */ - if (!(fdt_is_enabled(dt_child))) - continue; + sc->acells = 2; + OF_getencprop(node, "#address-cells", &sc->acells, sizeof(sc->acells)); + sc->scells = 1; + OF_getencprop(node, "#size-cells", &sc->scells, sizeof(sc->scells)); - if (!(fdt_pm_is_enabled(dt_child))) - continue; + if (simplebus_fill_ranges(node, sc) < 0) { + device_printf(dev, "could not get ranges\n"); + return (ENXIO); + } - di = malloc(sizeof(*di), M_SIMPLEBUS, M_WAITOK | M_ZERO); + /* + * In principle, simplebus could have an interrupt map, but ignore that + * for now + */ - if (ofw_bus_gen_setup_devinfo(&di->di_ofw, dt_child) != 0) { - free(di, M_SIMPLEBUS); - device_printf(dev, "could not set up devinfo\n"); + for (node = OF_child(node); node > 0; node = OF_peer(node)) { + if ((di = simplebus_setup_dinfo(dev, node)) == NULL) continue; - } - - resource_list_init(&di->di_res); - if (fdt_reg_to_rl(dt_child, &di->di_res)) { - device_printf(dev, - "%s: could not process 'reg' " - "property\n", di->di_ofw.obd_name); - ofw_bus_gen_destroy_devinfo(&di->di_ofw); - free(di, M_SIMPLEBUS); + cdev = device_add_child(dev, NULL, -1); + if (cdev == NULL) { + device_printf(dev, "<%s>: device_add_child failed\n", + di->obdinfo.obd_name); + resource_list_free(&di->rl); + ofw_bus_gen_destroy_devinfo(&di->obdinfo); + free(di, M_DEVBUF); continue; } + device_set_ivars(cdev, di); + } - if (fdt_intr_to_rl(dt_child, &di->di_res, di->di_intr_sl)) { - device_printf(dev, "%s: could not process " - "'interrupts' property\n", di->di_ofw.obd_name); - resource_list_free(&di->di_res); - ofw_bus_gen_destroy_devinfo(&di->di_ofw); - free(di, M_SIMPLEBUS); - continue; - } + return (bus_generic_attach(dev)); +} - /* Add newbus device for this FDT node */ - dev_child = device_add_child(dev, NULL, -1); - if (dev_child == NULL) { - device_printf(dev, "could not add child: %s\n", - di->di_ofw.obd_name); - resource_list_free(&di->di_res); - ofw_bus_gen_destroy_devinfo(&di->di_ofw); - free(di, M_SIMPLEBUS); - continue; +static int +simplebus_fill_ranges(phandle_t node, struct simplebus_softc *sc) +{ + int host_address_cells; + cell_t *base_ranges; + ssize_t nbase_ranges; + int err; + int i, j, k; + + err = OF_searchencprop(OF_parent(node), "#address-cells", + &host_address_cells, sizeof(host_address_cells)); + if (err <= 0) + return (-1); + + nbase_ranges = OF_getproplen(node, "ranges"); + if (nbase_ranges < 0) + return (-1); + sc->nranges = nbase_ranges / sizeof(cell_t) / + (sc->acells + host_address_cells + sc->scells); + if (sc->nranges == 0) + return (0); + + sc->ranges = malloc(sc->nranges * sizeof(sc->ranges[0]), + M_DEVBUF, M_WAITOK); + base_ranges = malloc(nbase_ranges, M_DEVBUF, M_WAITOK); + OF_getencprop(node, "ranges", base_ranges, nbase_ranges); + + for (i = 0, j = 0; i < sc->nranges; i++) { + sc->ranges[i].bus = 0; + for (k = 0; k < sc->acells; k++) { + sc->ranges[i].bus <<= 32; + sc->ranges[i].bus |= base_ranges[j++]; + } + sc->ranges[i].host = 0; + for (k = 0; k < host_address_cells; k++) { + sc->ranges[i].host <<= 32; + sc->ranges[i].host |= base_ranges[j++]; + } + sc->ranges[i].size = 0; + for (k = 0; k < sc->scells; k++) { + sc->ranges[i].size <<= 32; + sc->ranges[i].size |= base_ranges[j++]; } -#ifdef DEBUG - device_printf(dev, "added child: %s\n\n", di->di_ofw.obd_name); -#endif - device_set_ivars(dev_child, di); } - return (bus_generic_attach(dev)); + free(base_ranges, M_DEVBUF); + return (sc->nranges); } -static int -simplebus_print_child(device_t dev, device_t child) +static struct simplebus_devinfo * +simplebus_setup_dinfo(device_t dev, phandle_t node) { - device_t ip; - struct simplebus_devinfo *di; - struct resource_list *rl; - int rv; + struct simplebus_softc *sc; + struct simplebus_devinfo *ndi; + uint32_t *reg, *intr, icells; + uint64_t phys, size; + phandle_t iparent; + int i, j, k; + int nintr; + int nreg; - di = device_get_ivars(child); - rl = &di->di_res; + sc = device_get_softc(dev); - rv = 0; - rv += bus_print_child_header(dev, child); - rv += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx"); - rv += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld"); - if ((ip = simplebus_get_interrupt_parent(child)) != NULL) - rv += printf(" (%s)", device_get_nameunit(ip)); - rv += bus_print_child_footer(dev, child); + ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO); + if (ofw_bus_gen_setup_devinfo(&ndi->obdinfo, node) != 0) { + free(ndi, M_DEVBUF); + return (NULL); + } - return (rv); + resource_list_init(&ndi->rl); + nreg = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)®); + if (nreg == -1) + nreg = 0; + if (nreg % (sc->acells + sc->scells) != 0) { + if (bootverbose) + device_printf(dev, "Malformed reg property on <%s>\n", + ndi->obdinfo.obd_name); + nreg = 0; + } + + for (i = 0, k = 0; i < nreg; i += sc->acells + sc->scells, k++) { + phys = size = 0; + for (j = 0; j < sc->acells; j++) { + phys <<= 32; + phys |= reg[i + j]; + } + for (j = 0; j < sc->scells; j++) { + size <<= 32; + size |= reg[i + sc->acells + j]; + } + + resource_list_add(&ndi->rl, SYS_RES_MEMORY, k, + phys, phys + size - 1, size); + } + free(reg, M_OFWPROP); + + nintr = OF_getencprop_alloc(node, "interrupts", sizeof(*intr), + (void **)&intr); + if (nintr > 0) { + iparent = 0; + OF_searchencprop(node, "interrupt-parent", &iparent, + sizeof(iparent)); + OF_searchencprop(OF_xref_phandle(iparent), "#interrupt-cells", + &icells, sizeof(icells)); + for (i = 0, k = 0; i < nintr; i += icells, k++) { + intr[i] = ofw_bus_map_intr(dev, iparent, intr[i]); + resource_list_add(&ndi->rl, SYS_RES_IRQ, k, intr[i], + intr[i], 1); + if (icells > 1) + ofw_bus_config_intr(dev, intr[i], intr[i+1]); + } + free(intr, M_OFWPROP); + } + + return (ndi); +} + +static const struct ofw_bus_devinfo * +simplebus_get_devinfo(device_t bus __unused, device_t child) +{ + struct simplebus_devinfo *ndi; + + ndi = device_get_ivars(child); + return (&ndi->obdinfo); } static struct resource * simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { - device_t ic; + struct simplebus_softc *sc; struct simplebus_devinfo *di; struct resource_list_entry *rle; + int j; + + sc = device_get_softc(bus); /* * Request for the default allocation with a given rid: use resource @@ -265,7 +334,7 @@ simplebus_alloc_resource(device_t bus, d if (type == SYS_RES_IOPORT) type = SYS_RES_MEMORY; - rle = resource_list_find(&di->di_res, type, *rid); + rle = resource_list_find(&di->rl, type, *rid); if (rle == NULL) { if (bootverbose) device_printf(bus, "no default resources for " @@ -275,153 +344,69 @@ simplebus_alloc_resource(device_t bus, d start = rle->start; end = rle->end; count = rle->count; - } + } - if (type == SYS_RES_IRQ && - (ic = simplebus_get_interrupt_parent(child)) != NULL) - return(FDT_IC_ALLOC_INTR(ic, child, rid, start, flags)); + if (type == SYS_RES_MEMORY) { + /* Remap through ranges property */ + for (j = 0; j < sc->nranges; j++) { + if (start >= sc->ranges[j].bus && end < + sc->ranges[j].bus + sc->ranges[j].size) { + start -= sc->ranges[j].bus; + start += sc->ranges[j].host; + end -= sc->ranges[j].bus; + end += sc->ranges[j].host; + break; + } + } + if (j == sc->nranges && sc->nranges != 0) { + if (bootverbose) + device_printf(bus, "Could not map resource " + "%#lx-%#lx\n", start, end); + + return (NULL); + } + } return (bus_generic_alloc_resource(bus, child, type, rid, start, end, count, flags)); } static int -simplebus_activate_resource(device_t dev, device_t child, int type, int rid, - struct resource *r) -{ - device_t ic; - - if (type == SYS_RES_IRQ && - (ic = simplebus_get_interrupt_parent(child)) != NULL) - return (FDT_IC_ACTIVATE_INTR(ic, r)); - - return (bus_generic_activate_resource(dev, child, type, rid, r)); -} - -static int -simplebus_deactivate_resource(device_t dev, device_t child, int type, int rid, - struct resource *r) -{ - device_t ic; - - if (type == SYS_RES_IRQ && - (ic = simplebus_get_interrupt_parent(child)) != NULL) - return (FDT_IC_DEACTIVATE_INTR(ic, r)); - - return (bus_generic_deactivate_resource(dev, child, type, rid, r)); -} - -static int -simplebus_release_resource(device_t dev, device_t child, int type, int rid, - struct resource *r) -{ - device_t ic; - - if (type == SYS_RES_IRQ && - (ic = simplebus_get_interrupt_parent(child)) != NULL) - return (FDT_IC_RELEASE_INTR(ic, r)); - - return (bus_generic_release_resource(dev, child, type, rid, r)); -} - -static struct resource_list * -simplebus_get_resource_list(device_t bus, device_t child) -{ - struct simplebus_devinfo *di; - - di = device_get_ivars(child); - return (&di->di_res); -} - -static device_t -simplebus_get_interrupt_parent(device_t dev) +simplebus_print_res(struct simplebus_devinfo *di) { - struct simplebus_devinfo *di; - struct fdt_ic *ic; - device_t ip; - phandle_t ph, iph; - - ip = NULL; - - di = device_get_ivars(dev); - if (di == NULL) - return (NULL); + int rv; - if (OF_getencprop(di->di_ofw.obd_node, "interrupt-parent", &iph, - sizeof(iph)) > 0) { - ph = OF_xref_phandle(iph); - SLIST_FOREACH(ic, &fdt_ic_list_head, fdt_ics) { - if (ic->iph == ph) { - ip = ic->dev; - break; - } - } - } - return (ip); + rv = 0; + rv += resource_list_print_type(&di->rl, "mem", SYS_RES_MEMORY, "%#lx"); + rv += resource_list_print_type(&di->rl, "irq", SYS_RES_IRQ, "%ld"); + return (rv); } -static int -simplebus_setup_intr(device_t bus, device_t child, struct resource *res, - int flags, driver_filter_t *filter, driver_intr_t *ihand, void *arg, - void **cookiep) +static void +simplebus_probe_nomatch(device_t bus, device_t child) { - struct simplebus_devinfo *di; - device_t ic; - enum intr_trigger trig; - enum intr_polarity pol; - int error, irq, rid; + const char *name, *type; - di = device_get_ivars(child); - if (di == NULL) - return (ENXIO); - - if (res == NULL) - return (EINVAL); + if (!bootverbose) + return; - rid = rman_get_rid(res); - if (rid >= DI_MAX_INTR_NUM) - return (ENOENT); - - ic = simplebus_get_interrupt_parent(child); - - trig = di->di_intr_sl[rid].trig; - pol = di->di_intr_sl[rid].pol; - if (trig != INTR_TRIGGER_CONFORM || pol != INTR_POLARITY_CONFORM) { - irq = rman_get_start(res); - if (ic != NULL) - error = FDT_IC_CONFIG_INTR(ic, irq, trig, pol); - else - error = bus_generic_config_intr(bus, irq, trig, pol); - if (error) - return (error); - } + name = ofw_bus_get_name(child); + type = ofw_bus_get_type(child); - if (ic != NULL) - error = FDT_IC_SETUP_INTR(ic, child, res, flags, filter, - ihand, arg, cookiep); - else - error = bus_generic_setup_intr(bus, child, res, flags, filter, - ihand, arg, cookiep); - return (error); + device_printf(bus, "<%s>", name != NULL ? name : "unknown"); + simplebus_print_res(device_get_ivars(child)); + printf(" type %s (no driver attached)\n", + type != NULL ? type : "unknown"); } static int -simplebus_teardown_intr(device_t bus, device_t child, struct resource *res, - void *cookie) +simplebus_print_child(device_t bus, device_t child) { - device_t ic; - - if ((ic = simplebus_get_interrupt_parent(child)) != NULL) - return (FDT_IC_TEARDOWN_INTR(ic, child, res, cookie)); + int rv; - return (bus_generic_teardown_intr(bus, child, res, cookie)); + rv = bus_print_child_header(bus, child); + rv += simplebus_print_res(device_get_ivars(child)); + rv += bus_print_child_footer(bus, child); + return (rv); } -static const struct ofw_bus_devinfo * -simplebus_get_devinfo(device_t bus, device_t child) -{ - struct simplebus_devinfo *di; - - di = device_get_ivars(child); - return (&di->di_ofw); -} From owner-svn-src-user@FreeBSD.ORG Sat Dec 21 18:17:42 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4FE59679; Sat, 21 Dec 2013 18:17:42 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3C4B917B3; Sat, 21 Dec 2013 18:17:42 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBLIHg9e048855; Sat, 21 Dec 2013 18:17:42 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBLIHg4V048854; Sat, 21 Dec 2013 18:17:42 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201312211817.rBLIHg4V048854@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 21 Dec 2013 18:17:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r259693 - user/nwhitehorn/mips_pic_if/dev/fdt X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Dec 2013 18:17:42 -0000 Author: nwhitehorn Date: Sat Dec 21 18:17:41 2013 New Revision: 259693 URL: http://svnweb.freebsd.org/changeset/base/259693 Log: style(9) Modified: user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c Modified: user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c ============================================================================== --- user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c Sat Dec 21 18:16:42 2013 (r259692) +++ user/nwhitehorn/mips_pic_if/dev/fdt/simplebus.c Sat Dec 21 18:17:41 2013 (r259693) @@ -128,7 +128,8 @@ simplebus_probe(device_t dev) { if (!ofw_bus_is_compatible(dev, "simple-bus") && - (ofw_bus_get_type(dev) == NULL || strcmp(ofw_bus_get_type(dev), "soc") != 0)) + (ofw_bus_get_type(dev) == NULL || strcmp(ofw_bus_get_type(dev), + "soc") != 0)) return (ENXIO); device_set_desc(dev, "Flattened device tree simple bus");