From owner-svn-soc-all@FreeBSD.ORG Sun Jun 26 19:13:40 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 3E8D9106566C for ; Sun, 26 Jun 2011 19:13:38 +0000 (UTC) (envelope-from kibab@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 26 Jun 2011 19:13:38 +0000 Date: Sun, 26 Jun 2011 19:13:38 +0000 From: kibab@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110626191338.3E8D9106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r223744 - soc2011/kibab/freebsd-src-head/etc/sendmail X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2011 19:13:40 -0000 Author: kibab Date: Sun Jun 26 19:13:38 2011 New Revision: 223744 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223744 Log: Added files that were missing because of WITHOUT_SENDMAIL, but were required by installworld due to some unknown reason Added: soc2011/kibab/freebsd-src-head/etc/sendmail/freebsd.cf soc2011/kibab/freebsd-src-head/etc/sendmail/freebsd.submit.cf Added: soc2011/kibab/freebsd-src-head/etc/sendmail/freebsd.cf ============================================================================== Added: soc2011/kibab/freebsd-src-head/etc/sendmail/freebsd.submit.cf ============================================================================== From owner-svn-soc-all@FreeBSD.ORG Sun Jun 26 19:14:23 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8927D106564A for ; Sun, 26 Jun 2011 19:14:21 +0000 (UTC) (envelope-from kibab@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 26 Jun 2011 19:14:21 +0000 Date: Sun, 26 Jun 2011 19:14:21 +0000 From: kibab@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110626191421.8927D106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r223745 - soc2011/kibab/freebsd-src-head/sys/amd64/conf X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2011 19:14:23 -0000 Author: kibab Date: Sun Jun 26 19:14:21 2011 New Revision: 223745 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223745 Log: options CAPABILITIES is included into kernel configuration Modified: soc2011/kibab/freebsd-src-head/sys/amd64/conf/CAPSICUM Modified: soc2011/kibab/freebsd-src-head/sys/amd64/conf/CAPSICUM ============================================================================== --- soc2011/kibab/freebsd-src-head/sys/amd64/conf/CAPSICUM Sun Jun 26 19:13:38 2011 (r223744) +++ soc2011/kibab/freebsd-src-head/sys/amd64/conf/CAPSICUM Sun Jun 26 19:14:21 2011 (r223745) @@ -63,6 +63,7 @@ options MAC # TrustedBSD MAC Framework options KDTRACE_FRAME # Ensure frames are compiled in options KDTRACE_HOOKS # Kernel DTrace hooks +options CAPABILITIES # Support for Capsicum options INCLUDE_CONFIG_FILE # Include this file in kernel # Debugging for use in -current From owner-svn-soc-all@FreeBSD.ORG Sun Jun 26 19:22:04 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8D460106564A for ; Sun, 26 Jun 2011 19:22:02 +0000 (UTC) (envelope-from kibab@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 26 Jun 2011 19:22:02 +0000 Date: Sun, 26 Jun 2011 19:22:02 +0000 From: kibab@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110626192202.8D460106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r223746 - soc2011/kibab/freebsd-src-head/usr.sbin/syslogd X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2011 19:22:04 -0000 Author: kibab Date: Sun Jun 26 19:22:02 2011 New Revision: 223746 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223746 Log: Task-9: Initial support of capabilities usage in syslogd Modified: soc2011/kibab/freebsd-src-head/usr.sbin/syslogd/syslogd.c Modified: soc2011/kibab/freebsd-src-head/usr.sbin/syslogd/syslogd.c ============================================================================== --- soc2011/kibab/freebsd-src-head/usr.sbin/syslogd/syslogd.c Sun Jun 26 19:14:21 2011 (r223745) +++ soc2011/kibab/freebsd-src-head/usr.sbin/syslogd/syslogd.c Sun Jun 26 19:22:02 2011 (r223746) @@ -75,6 +75,7 @@ #define TIMERINTVL 30 /* interval for checking flush, mark */ #define TTYMSGTIME 1 /* timeout passed to ttymsg */ +#include #include #include #include @@ -303,6 +304,7 @@ static int needdofsync = 0; /* Are any file(s) waiting to be fsynced? */ static struct pidfh *pfh; +static int child_pid = 0; /* For parent process, child PID */ volatile sig_atomic_t MarkSet, WantDie; static int allowaddr(char *); @@ -337,6 +339,9 @@ static void timedout(int); static void double_rbuf(int); +static void parent_huphdl(int); +static void parent_duty(int); + int main(int argc, char *argv[]) { @@ -495,6 +500,29 @@ if (NumAllowed) endservent(); + int fork_count = 0; /* XXX For debug purposes only, remove in production code! */ + int chpid; + if(feature_present("security_capabilities")) { + dprintf("Running with Capsicum support!\n"); + do { + chpid = fork(); + fork_count++; + + if(chpid) { /* Parent process */ + child_pid = chpid; /* Init global variable */ + (void)signal(SIGHUP, parent_huphdl); + /* tuck my process id away */ + pidfile_write(pfh); + + parent_duty(chpid); + } else { /* Child process */ + setproctitle("child process (capability mode)"); + } + if(fork_count>10) + errx(1, "ACHTUNG, high fork count"); + } while(chpid); + dprintf("Child continued to run as usual!\n"); + } consfile.f_type = F_CONSOLE; (void)strlcpy(consfile.f_un.f_fname, ctty + sizeof _PATH_DEV - 1, sizeof(consfile.f_un.f_fname)); @@ -570,11 +598,22 @@ dprintf("can't open %s (%d)\n", _PATH_KLOG, errno); /* tuck my process id away */ - pidfile_write(pfh); + /* + * pidfile_write(pfh); this should be done earlier if forking. + * Without forking it doesn't hurt to do it earlier anyway + */ dprintf("off & running....\n"); init(0); + + /* Revoke ambient privs */ + if(cap_enter() < 0) { + err(32, "Could not enter capability mode!"); + } else { + dprintf("FreeBSD capability mode enabled!\n"); + } + /* prevent SIGHUP and SIGCHLD handlers from running in parallel */ sigemptyset(&mask); sigaddset(&mask, SIGCHLD); @@ -677,6 +716,36 @@ free(fdsr); } +/** + * Set up as SIGHUP handler in the parent process + */ +static void parent_huphdl(int signo) { + dprintf("SIGHUP handler called, trying to kill the child\n"); + if(kill(child_pid, SIGTERM) < 0) { + warnx("Cannot SIGTERM child process, WTF?!"); + } +} + +/** + * Watch after child process + */ +static void parent_duty(int ch_pid) { + int status = 0; + + setproctitle("master process"); + dprintf("Parent: waiting for child...\n"); + if(waitpid(child_pid, &status, 0) <0) { + errx(1, "waitpid() is unsuccessful, exiting"); + }; + + /* Examine the exit cause */ + if(WIFSIGNALED(status)) + dprintf("Child exited due to signal -- this is suspicious, as all expected signals might have been intercepted by the child?!\n"); + if(WIFEXITED(status)) + dprintf("Child exited normally\n"); + /* XXX Maybe we should check for special return code that indicates misconfiguration? */ +} + static void unmapped(struct sockaddr *sa) { From owner-svn-soc-all@FreeBSD.ORG Mon Jun 27 15:12:33 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id B69C01065676 for ; Mon, 27 Jun 2011 15:12:31 +0000 (UTC) (envelope-from xxp@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 27 Jun 2011 15:12:31 +0000 Date: Mon, 27 Jun 2011 15:12:31 +0000 From: xxp@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110627151231.B69C01065676@hub.freebsd.org> Cc: Subject: socsvn commit: r223767 - in soc2011/xxp/xxp-head/lib: libc/amd64/gen libc/amd64/sys msun/amd64 X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jun 2011 15:12:33 -0000 Author: xxp Date: Mon Jun 27 15:12:31 2011 New Revision: 223767 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223767 Log: Annotate libc, msun for amd64 Modified: soc2011/xxp/xxp-head/lib/libc/amd64/gen/_setjmp.S soc2011/xxp/xxp-head/lib/libc/amd64/gen/rfork_thread.S soc2011/xxp/xxp-head/lib/libc/amd64/gen/setjmp.S soc2011/xxp/xxp-head/lib/libc/amd64/gen/sigsetjmp.S soc2011/xxp/xxp-head/lib/libc/amd64/sys/brk.S soc2011/xxp/xxp-head/lib/libc/amd64/sys/cerror.S soc2011/xxp/xxp-head/lib/libc/amd64/sys/exect.S soc2011/xxp/xxp-head/lib/libc/amd64/sys/getcontext.S soc2011/xxp/xxp-head/lib/libc/amd64/sys/sbrk.S soc2011/xxp/xxp-head/lib/libc/amd64/sys/vfork.S soc2011/xxp/xxp-head/lib/msun/amd64/s_llrintl.S soc2011/xxp/xxp-head/lib/msun/amd64/s_lrintl.S Modified: soc2011/xxp/xxp-head/lib/libc/amd64/gen/_setjmp.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/gen/_setjmp.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/gen/_setjmp.S Mon Jun 27 15:12:31 2011 (r223767) @@ -48,6 +48,7 @@ ENTRY(_setjmp) movq %rdi,%rax + cfi_register(%rdi, $rax) movq 0(%rsp),%rdx /* retval */ movq %rdx, 0(%rax) /* 0; retval */ movq %rbx, 8(%rax) /* 1; rbx */ @@ -67,6 +68,7 @@ .set CNAME(_longjmp),CNAME(___longjmp) ENTRY(___longjmp) movq %rdi,%rdx + cfi_register(%rdi, $rdx) /* Restore the mxcsr, but leave exception flags intact. */ stmxcsr -4(%rsp) movl 68(%rdx),%eax @@ -77,6 +79,7 @@ movl %edi,-4(%rsp) ldmxcsr -4(%rsp) movq %rsi,%rax /* retval */ + cfi_register(%rsi, $rax) movq 0(%rdx),%rcx movq 8(%rdx),%rbx movq 16(%rdx),%rsp Modified: soc2011/xxp/xxp-head/lib/libc/amd64/gen/rfork_thread.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/gen/rfork_thread.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/gen/rfork_thread.S Mon Jun 27 15:12:31 2011 (r223767) @@ -46,7 +46,9 @@ ENTRY(rfork_thread) pushq %rbx + cfi_adjust_cfa_offset(8) pushq %r12 + cfi_adjust_cfa_offset(8) movq %rdx, %rbx movq %rcx, %r12 @@ -63,7 +65,9 @@ cmpl $0, %edx jnz 1f popq %r12 + cfi_adjust_cfa_offset(-8) popq %rbx + cfi_adjust_cfa_offset(-8) ret /* @@ -92,7 +96,9 @@ */ 2: popq %r12 + cfi_adjust_cfa_offset(-8) popq %rbx + cfi_adjust_cfa_offset(-8) #ifdef PIC movq PIC_GOT(HIDENAME(cerror)), %rdx jmp *%rdx Modified: soc2011/xxp/xxp-head/lib/libc/amd64/gen/setjmp.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/gen/setjmp.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/gen/setjmp.S Mon Jun 27 15:12:31 2011 (r223767) @@ -50,12 +50,14 @@ ENTRY(setjmp) pushq %rdi + cfi_adjust_cfa_offset(8) movq %rdi,%rcx movq $1,%rdi /* SIG_BLOCK */ movq $0,%rsi /* (sigset_t*)set */ leaq 72(%rcx),%rdx /* 9,10; (sigset_t*)oset */ call PIC_PLT(CNAME(_sigprocmask)) popq %rdi + cfi_adjust_cfa_offset(-8) movq %rdi,%rcx movq 0(%rsp),%rdx /* retval */ movq %rdx, 0(%rcx) /* 0; retval */ @@ -76,14 +78,18 @@ .set CNAME(longjmp),CNAME(__longjmp) ENTRY(__longjmp) pushq %rdi + cfi_adjust_cfa_offset(8) pushq %rsi + cfi_adjust_cfa_offset(8) movq %rdi,%rdx movq $3,%rdi /* SIG_SETMASK */ leaq 72(%rdx),%rsi /* (sigset_t*)set */ movq $0,%rdx /* (sigset_t*)oset */ call PIC_PLT(CNAME(_sigprocmask)) popq %rsi + cfi_adjust_cfa_offset(-8) popq %rdi /* jmpbuf */ + cfi_adjust_cfa_offset(-8) movq %rdi,%rdx /* Restore the mxcsr, but leave exception flags intact. */ stmxcsr -4(%rsp) Modified: soc2011/xxp/xxp-head/lib/libc/amd64/gen/sigsetjmp.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/gen/sigsetjmp.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/gen/sigsetjmp.S Mon Jun 27 15:12:31 2011 (r223767) @@ -58,12 +58,14 @@ testl %esi,%esi jz 2f pushq %rdi + cfi_adjust_cfa_offset(8) movq %rdi,%rcx movq $1,%rdi /* SIG_BLOCK */ movq $0,%rsi /* (sigset_t*)set */ leaq 72(%rcx),%rdx /* 9,10 (sigset_t*)oset */ call PIC_PLT(CNAME(_sigprocmask)) popq %rdi + cfi_adjust_cfa_offset(-8) 2: movq %rdi,%rcx movq 0(%rsp),%rdx /* retval */ movq %rdx, 0(%rcx) /* 0; retval */ @@ -86,13 +88,17 @@ jz 2f movq %rdi,%rdx pushq %rdi + cfi_adjust_cfa_offset(8) pushq %rsi + cfi_adjust_cfa_offset(8) movq $3,%rdi /* SIG_SETMASK */ leaq 72(%rdx),%rsi /* (sigset_t*)set */ movq $0,%rdx /* (sigset_t*)oset */ call PIC_PLT(CNAME(_sigprocmask)) popq %rsi + cfi_adjust_cfa_offset(-8) popq %rdi /* jmpbuf */ + cfi_adjust_cfa_offset(-8) 2: movq %rdi,%rdx movq %rsi,%rax /* retval */ movq 0(%rdx),%rcx Modified: soc2011/xxp/xxp-head/lib/libc/amd64/sys/brk.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/sys/brk.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/sys/brk.S Mon Jun 27 15:12:31 2011 (r223767) @@ -42,12 +42,15 @@ .globl HIDENAME(minbrk) ENTRY(_brk) pushq %rdi + cfi_adjust_cfa_offset(8) jmp ok END(_brk) ENTRY(brk) pushq %rdi + cfi_adjust_cfa_offset(8) movq %rdi,%rax + cfi_register(%rdi, %rax) #ifdef PIC movq PIC_GOT(HIDENAME(minbrk)),%rdx cmpq %rax,(%rdx) @@ -73,9 +76,11 @@ #endif movq $0,%rax popq %rdi + cfi_restore(%rdi) ret err: addq $8, %rsp + cfi_adjust_cfa_offset(-8) #ifdef PIC movq PIC_GOT(HIDENAME(cerror)),%rdx jmp *%rdx Modified: soc2011/xxp/xxp-head/lib/libc/amd64/sys/cerror.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/sys/cerror.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/sys/cerror.S Mon Jun 27 15:12:31 2011 (r223767) @@ -49,8 +49,10 @@ .type CNAME(__error),@function HIDENAME(cerror): pushq %rax + cfi_adjust_cfa_offset(8) call PIC_PLT(CNAME(__error)) popq %rcx + cfi_adjust_cfa_offset(-8) movl %ecx,(%rax) movq $-1,%rax movq $-1,%rdx Modified: soc2011/xxp/xxp-head/lib/libc/amd64/sys/exect.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/sys/exect.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/sys/exect.S Mon Jun 27 15:12:31 2011 (r223767) @@ -42,10 +42,14 @@ ENTRY(exect) movq $SYS_execve,%rax pushfq + cfi_adjust_cfa_offset(8) popq %r8 + cfi_adjust_cfa_offset(-8) orq $PSL_T,%r8 pushq %r8 + cfi_adjust_cfa_offset(8) popfq + cfi_adjust_cfa_offset(-8) KERNCALL #ifdef PIC movq PIC_GOT(HIDENAME(cerror)),%rdx Modified: soc2011/xxp/xxp-head/lib/libc/amd64/sys/getcontext.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/sys/getcontext.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/sys/getcontext.S Mon Jun 27 15:12:31 2011 (r223767) @@ -44,6 +44,7 @@ KERNCALL jb 1f addq $8,%rsp /* remove stale (setcontext) return address */ + cfi_adjust_cfa_offset(-8) jmp *%rsi /* restore return address */ 1: #ifdef PIC Modified: soc2011/xxp/xxp-head/lib/libc/amd64/sys/sbrk.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/sys/sbrk.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/sys/sbrk.S Mon Jun 27 15:12:31 2011 (r223767) @@ -49,7 +49,9 @@ ENTRY(sbrk) pushq %rdi + cfi_adjust_cfa_offset(8) movq %rdi,%rcx + cif_register(%rdi, %rcx) #ifdef PIC movq PIC_GOT(HIDENAME(curbrk)),%rdx movq (%rdx),%rax @@ -76,9 +78,11 @@ #endif back: addq $8, %rsp + cfi_adjust_cfa_offset(-8) ret err: addq $8, %rsp + cfi_adjust_cfa_offset(-8) #ifdef PIC movq PIC_GOT(HIDENAME(cerror)),%rdx jmp *%rdx Modified: soc2011/xxp/xxp-head/lib/libc/amd64/sys/vfork.S ============================================================================== --- soc2011/xxp/xxp-head/lib/libc/amd64/sys/vfork.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/libc/amd64/sys/vfork.S Mon Jun 27 15:12:31 2011 (r223767) @@ -44,12 +44,14 @@ .set vfork,__sys_vfork ENTRY(__sys_vfork) popq %rsi /* fetch return address (%rsi preserved) */ + cfi_adjust_cfa_offset(-8) mov $SYS_vfork,%rax KERNCALL jb 1f jmp *%rsi 1: pushq %rsi + cfi_adjust_cfa_offset(8) #ifdef PIC movq PIC_GOT(HIDENAME(cerror)),%rdx jmp *%rdx Modified: soc2011/xxp/xxp-head/lib/msun/amd64/s_llrintl.S ============================================================================== --- soc2011/xxp/xxp-head/lib/msun/amd64/s_llrintl.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/msun/amd64/s_llrintl.S Mon Jun 27 15:12:31 2011 (r223767) @@ -30,8 +30,10 @@ ENTRY(llrintl) fldt 8(%rsp) subq $8,%rsp + cfi_adjust_cfa_offset(8) fistpll (%rsp) popq %rax + cfi_adjust_cfa_offset(-8) ret .section .note.GNU-stack,"",%progbits Modified: soc2011/xxp/xxp-head/lib/msun/amd64/s_lrintl.S ============================================================================== --- soc2011/xxp/xxp-head/lib/msun/amd64/s_lrintl.S Mon Jun 27 13:58:24 2011 (r223766) +++ soc2011/xxp/xxp-head/lib/msun/amd64/s_lrintl.S Mon Jun 27 15:12:31 2011 (r223767) @@ -30,8 +30,10 @@ ENTRY(lrintl) fldt 8(%rsp) subq $8,%rsp + cfi_adjust_cfa_offset(8) fistpll (%rsp) popq %rax + cfi_adjust_cfa_offset(-8) ret .section .note.GNU-stack,"",%progbits From owner-svn-soc-all@FreeBSD.ORG Sat Jul 2 10:57:16 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 8775A106564A for ; Sat, 2 Jul 2011 10:57:14 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sat, 02 Jul 2011 10:57:14 +0000 Date: Sat, 02 Jul 2011 10:57:14 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110702105714.8775A106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r223888 - soc2011/rudot/kern X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jul 2011 10:57:16 -0000 Author: rudot Date: Sat Jul 2 10:57:13 2011 New Revision: 223888 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223888 Log: threads that wake up try to preempt a lower priority running thread Modified: soc2011/rudot/kern/sched_fbfs.c Modified: soc2011/rudot/kern/sched_fbfs.c ============================================================================== --- soc2011/rudot/kern/sched_fbfs.c Sat Jul 2 00:38:10 2011 (r223887) +++ soc2011/rudot/kern/sched_fbfs.c Sat Jul 2 10:57:13 2011 (r223888) @@ -116,6 +116,8 @@ static struct thread *edf_choose(struct rqhead * rqh); static struct thread *runq_choose_bfs(struct runq * rq); +static int preempt_lastcpu(struct thread *td); +static struct thread *worst_running_thread(void); SYSINIT(sched_setup, SI_SUB_RUN_QUEUE, SI_ORDER_FIRST, sched_setup, NULL); SYSINIT(sched_initticks, SI_SUB_CLOCKS, SI_ORDER_THIRD, sched_initticks, NULL); @@ -138,7 +140,7 @@ SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD, 0, "Scheduler"); -SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD, "4BSD", 0, +SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD, "FBFS", 0, "Scheduler name"); SYSCTL_INT(_kern_sched, OID_AUTO, slice, CTLFLAG_RW, &sched_slice, 0, @@ -592,10 +594,90 @@ MPASS(td->td_lock == &sched_lock); } +int +preempt_lastcpu(struct thread *td) +{ + int cpri; + struct pcpu * pcpu; + struct td_sched *ts; + struct td_sched *tsc; + u_char c; + + c = td->td_lastcpu; + if (c == NOCPU) + return (0); + pcpu = pcpu_find(c); + if (pcpu->pc_curthread == pcpu->pc_idlethread) { + if (PCPU_GET(cpuid) != c) + ipi_cpu(c, IPI_AST); + return (1); + } + cpri = pcpu->pc_curthread->td_priority; + if (cpri < td->td_priority) + return (0); + if (cpri > td->td_priority) { + pcpu->pc_curthread->td_flags |= TDF_NEEDRESCHED; + if (PCPU_GET(cpuid) != c) + ipi_cpu(c, IPI_AST); + return (1); + } + ts = td->td_sched; + tsc = pcpu->pc_curthread->td_sched; + if ((td->td_pri_class == PRI_TIMESHARE) || + (td->td_pri_class == PRI_IDLE)) { + if (ts->ts_vdeadline >= tsc->ts_vdeadline) + return (0); + } else + return (0); + /* + * Here, the priorities of td, and current thread on td_lastcpu are + * equal. And their scheduling class is PRI_IDLE or PRI_TIMESHARE + * Further, the virtual deadline of td is lower. Therefore we + * reschedule the td_lastcpu. + */ + pcpu->pc_curthread->td_flags |= TDF_NEEDRESCHED; + if (PCPU_GET(cpuid) != c) + ipi_cpu(c, IPI_AST); + + return (1); +} + +struct thread * +worst_running_thread(void) +{ + struct td_sched *ts, *ts2; + struct thread *max_thread, *cthr; + struct pcpu *pc; + u_char max_prio; + + max_thread = curthread; + max_prio = max_thread->td_priority; + ts = max_thread->td_sched; + SLIST_FOREACH(pc, &cpuhead, pc_allcpu) { + cthr = pc->pc_curthread; + if (max_prio < cthr->td_priority) { + max_thread = cthr; + max_prio = max_thread->td_priority; + ts = max_thread->td_sched; + } else if (max_prio == cthr->td_priority) { + ts2 = cthr->td_sched; + if (ts->ts_vdeadline > ts2->ts_vdeadline) { + max_thread = cthr; + ts = ts2; + } + } + } + + return (max_thread); +} + void sched_wakeup(struct thread *td) { struct td_sched *ts; + struct thread *thr_worst; + cpumask_t dontuse, map, me; + u_char c; THREAD_LOCK_ASSERT(td, MA_OWNED); ts = td->td_sched; @@ -603,6 +685,44 @@ td->td_slptick = 0; ts->ts_slptime = 0; sched_add(td, SRQ_BORING); + + me = PCPU_GET(cpumask); + dontuse = me | stopped_cpus | hlt_cpus_mask; + map = idle_cpus_mask & ~dontuse; + + /* + * Firstly check if we should reschedule the last cpu the thread + * run on. + */ + if (preempt_lastcpu(td)) { + if (map) + ipi_selected(map, IPI_AST); + return; + } + + if (map) { + ipi_selected(map, IPI_AST); + return; + } + + /* We did not wake lastcpu and there is no suitable idle cpu */ + thr_worst = worst_running_thread(); + c = thr_worst->td_oncpu; + if (thr_worst->td_priority < td->td_priority) + return; + if (thr_worst->td_priority > td->td_priority) { + thr_worst->td_flags |= TDF_NEEDRESCHED; + if ((thr_worst != curthread) && (c != NOCPU)) + ipi_cpu(c, IPI_AST); + return; + } + + /* thr_worst->td_priority == td->td_priority */ + if (ts->ts_vdeadline < thr_worst->td_sched->ts_vdeadline) { + thr_worst->td_flags |= TDF_NEEDRESCHED; + if ((thr_worst != curthread) && (c != NOCPU)) + ipi_cpu(c, IPI_AST); + } } void