diff options
author | Surya Prakki <Surya.Prakki@Sun.COM> | 2009-07-15 00:07:13 -0700 |
---|---|---|
committer | Surya Prakki <Surya.Prakki@Sun.COM> | 2009-07-15 00:07:13 -0700 |
commit | fb9b0aa8c76ff829a7069d38161a2cecc656b091 (patch) | |
tree | e37522fcc8f760240b049c073ab359eaf817c2e6 /usr/src | |
parent | c946faca5d4627284fb79c6b04e652b471034495 (diff) | |
download | illumos-gate-fb9b0aa8c76ff829a7069d38161a2cecc656b091.tar.gz |
6757037 Zone-spawned LWP needs to be able to run on a processor set
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/psrset/psrset.c | 147 | ||||
-rw-r--r-- | usr/src/lib/libc/common/sys/_pset.s | 4 | ||||
-rw-r--r-- | usr/src/lib/libc/port/llib-lc | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/port/mapfile-vers | 1 | ||||
-rw-r--r-- | usr/src/lib/libc/port/sys/psetsys.c | 20 | ||||
-rw-r--r-- | usr/src/lib/libproc/common/libproc.h | 2 | ||||
-rw-r--r-- | usr/src/lib/libproc/common/llib-lproc | 3 | ||||
-rw-r--r-- | usr/src/lib/libproc/common/mapfile-vers | 1 | ||||
-rw-r--r-- | usr/src/lib/libproc/common/pr_pbind.c | 72 | ||||
-rw-r--r-- | usr/src/uts/common/sys/pset.h | 7 | ||||
-rw-r--r-- | usr/src/uts/common/syscall/pset.c | 63 |
11 files changed, 112 insertions, 210 deletions
diff --git a/usr/src/cmd/psrset/psrset.c b/usr/src/cmd/psrset/psrset.c index 162366553a..35585499a9 100644 --- a/usr/src/cmd/psrset/psrset.c +++ b/usr/src/cmd/psrset/psrset.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * psrset - create and manage processor sets */ @@ -44,7 +41,6 @@ #include <procfs.h> #include <libproc.h> #include <stdarg.h> -#include <priv.h> #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ @@ -107,14 +103,10 @@ die(char *format, ...) exit(ERR_FAIL); } -static prpriv_t *orig_priv; - static struct ps_prochandle * grab_proc(id_t pid) { int ret; - prpriv_t *new_priv; - priv_set_t *eff_set, *perm_set; struct ps_prochandle *Pr; if ((Pr = Pgrab(pid, 0, &ret)) == NULL) { @@ -124,66 +116,6 @@ grab_proc(id_t pid) return (NULL); } - /* - * If target process does not have required PRIV_SYS_RES_CONFIG - * privilege, assign it temporarily to that process' effective - * and permitted sets so that it can call pset_bind(2). - */ - if ((new_priv = proc_get_priv(pid)) == NULL) { - warn(gettext("unable to get privileges for process %d: %s\n"), - pid, strerror(errno)); - errors = ERR_FAIL; - Prelease(Pr, 0); - return (NULL); - } - - if (Pcreate_agent(Pr) != 0) { - warn(gettext("cannot control process %d\n"), (int)pid); - errors = ERR_FAIL; - Prelease(Pr, 0); - free(new_priv); - return (NULL); - } - - eff_set = (priv_set_t *)&new_priv->pr_sets[new_priv->pr_setsize * - priv_getsetbyname(PRIV_EFFECTIVE)]; - perm_set = (priv_set_t *)&new_priv->pr_sets[new_priv->pr_setsize * - priv_getsetbyname(PRIV_PERMITTED)]; - if (!priv_ismember(eff_set, PRIV_SYS_RES_CONFIG)) { - /* - * Save original privileges - */ - if ((orig_priv = proc_get_priv(pid)) == NULL) { - warn(gettext("unable to get privileges for " - "process %d: %s\n"), pid, strerror(errno)); - errors = ERR_FAIL; - Pdestroy_agent(Pr); - Prelease(Pr, 0); - free(new_priv); - return (NULL); - } - (void) priv_addset(eff_set, PRIV_SYS_RES_CONFIG); - (void) priv_addset(perm_set, PRIV_SYS_RES_CONFIG); - /* - * We don't want to leave a process with elevated privileges, - * so make sure the process dies if we exit unexpectedly. - */ - if (Psetflags(Pr, PR_KLC) != 0 || - Psetpriv(Pr, new_priv) != 0) { - warn(gettext("unable to set process privileges for " - "process %d: %s\n"), pid, strerror(errno)); - (void) Punsetflags(Pr, PR_KLC); - free(new_priv); - free(orig_priv); - Pdestroy_agent(Pr); - Prelease(Pr, 0); - orig_priv = NULL; - errors = ERR_FAIL; - return (NULL); - } - } - free(new_priv); - return (Pr); } @@ -192,28 +124,6 @@ rele_proc(struct ps_prochandle *Pr) { if (Pr == NULL) return; - if (orig_priv != NULL) { - if (Psetpriv(Pr, orig_priv) != 0) { - /* - * If this fails, we can't leave a process with - * elevated privileges, so we have to release the - * process from libproc, knowing that it will - * be killed (since we set the PR_KLC flag). - */ - Pdestroy_agent(Pr); - warn(gettext("cannot relinquish privileges for " - "process %d. The process was killed\n"), - Ppsinfo(Pr)->pr_pid); - errors = ERR_FAIL; - } else { - (void) Punsetflags(Pr, PR_KLC); - Pdestroy_agent(Pr); - } - free(orig_priv); - orig_priv = NULL; - } else { - Pdestroy_agent(Pr); - } Prelease(Pr, 0); } @@ -351,29 +261,30 @@ bind_out(id_t pid, id_t lwpid, psetid_t old, psetid_t new) if (old == PS_NONE) { if (new == PS_NONE) (void) printf(gettext("%s id %s: was not bound, " - "now not bound\n"), proclwp, pidstr); + "now not bound\n"), proclwp, pidstr); else (void) printf(gettext("%s id %s: was not bound, " - "now %d\n"), proclwp, pidstr, new); + "now %d\n"), proclwp, pidstr, new); } else { if (new == PS_NONE) (void) printf(gettext("%s id %s: was %d, " - "now not bound\n"), proclwp, pidstr, old); + "now not bound\n"), proclwp, pidstr, old); else (void) printf(gettext("%s id %s: was %d, " - "now %d\n"), proclwp, pidstr, old, new); + "now %d\n"), proclwp, pidstr, old, new); } } static void -bind_lwp(struct ps_prochandle *Pr, id_t pid, id_t lwpid, psetid_t pset) +bind_lwp(id_t pid, id_t lwpid, psetid_t pset) { psetid_t old_pset; - if (pr_pset_bind(Pr, pset, P_LWPID, lwpid, &old_pset) < 0) { + if (pset_bind_lwp(pset, lwpid, pid, &old_pset) != 0) { bind_err(pset, pid, lwpid, errno); errors = ERR_FAIL; - } else { + } + if (errors != ERR_FAIL) { if (qflag) query_out(pid, lwpid, old_pset); else @@ -621,22 +532,22 @@ int usage(void) { (void) fprintf(stderr, gettext( - "usage: \n" - "\t%1$s -c [-F] [processor_id ...]\n" - "\t%1$s -d processor_set_id ...\n" - "\t%1$s -n processor_set_id\n" - "\t%1$s -f processor_set_id\n" - "\t%1$s -e processor_set_id command [argument(s)...]\n" - "\t%1$s -a [-F] processor_set_id processor_id ...\n" - "\t%1$s -r [-F] processor_id ...\n" - "\t%1$s -p [processorid ...]\n" - "\t%1$s -b processor_set_id pid[/lwpids] ...\n" - "\t%1$s -u pid[/lwpids] ...\n" - "\t%1$s -q [pid[/lwpids] ...]\n" - "\t%1$s -U [processor_set_id] ...\n" - "\t%1$s -Q [processor_set_id] ...\n" - "\t%1$s [-i] [processor_set_id ...]\n"), - progname); + "usage: \n" + "\t%1$s -c [-F] [processor_id ...]\n" + "\t%1$s -d processor_set_id ...\n" + "\t%1$s -n processor_set_id\n" + "\t%1$s -f processor_set_id\n" + "\t%1$s -e processor_set_id command [argument(s)...]\n" + "\t%1$s -a [-F] processor_set_id processor_id ...\n" + "\t%1$s -r [-F] processor_id ...\n" + "\t%1$s -p [processorid ...]\n" + "\t%1$s -b processor_set_id pid[/lwpids] ...\n" + "\t%1$s -u pid[/lwpids] ...\n" + "\t%1$s -q [pid[/lwpids] ...]\n" + "\t%1$s -U [processor_set_id] ...\n" + "\t%1$s -Q [processor_set_id] ...\n" + "\t%1$s [-i] [processor_set_id ...]\n"), + progname); return (ERR_USAGE); } @@ -699,7 +610,7 @@ do_lwps(id_t pid, const char *range, psetid_t pset) continue; found++; if (bflag || uflag) - bind_lwp(Pr, pid, lwp->pr_lwpid, pset); + bind_lwp(pid, lwp->pr_lwpid, pset); else if (binding != PBIND_NONE) query_out(pid, lwp->pr_lwpid, binding); } @@ -960,7 +871,7 @@ main(int argc, char *argv[]) pid = (id_t)strtol(*argv, &errptr, 10); if (errno != 0 || (errptr != NULL && *errptr != '\0' && - *errptr != '/')) { + *errptr != '/')) { warn(gettext("invalid process ID: %s\n"), *argv); continue; diff --git a/usr/src/lib/libc/common/sys/_pset.s b/usr/src/lib/libc/common/sys/_pset.s index 1f07c80267..64d243959e 100644 --- a/usr/src/lib/libc/common/sys/_pset.s +++ b/usr/src/lib/libc/common/sys/_pset.s @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -32,7 +32,7 @@ * _pset(int subcode, long arg1, long arg2, long arg3, long arg4) * * Syscall entry point for pset_create, pset_assign, pset_destroy, - * pset_bind, and pset_info. + * pset_bind, pset_bind_lwp and pset_info. */ SYSCALL2_RVAL1(_pset,pset) RETC diff --git a/usr/src/lib/libc/port/llib-lc b/usr/src/lib/libc/port/llib-lc index 1f5ed5c517..ffd9185d61 100644 --- a/usr/src/lib/libc/port/llib-lc +++ b/usr/src/lib/libc/port/llib-lc @@ -1347,6 +1347,8 @@ int pset_assign(psetid_t pset, processorid_t cpu, psetid_t *opset); int pset_assign_forced(psetid_t pset, processorid_t cpu, psetid_t *opset); int pset_info(psetid_t pset, int *type, u_int *numcpus, processorid_t *cpulist); int pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset); +int pset_bind_lwp(psetid_t pset, id_t id, pid_t, psetid_t *opset); + /* rctlsys.c */ int getrctl(const char *name, rctlblk_t *old_rblk, rctlblk_t *new_rblk, diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index 35861f0f73..d893f8bc0d 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -1605,6 +1605,7 @@ SUNWprivate_1.1 { __priv_bracket; __priv_relinquish; pset_assign_forced; + pset_bind_lwp; _psignal; _pthread_setcleanupinit; __putwchar_xpg5; diff --git a/usr/src/lib/libc/port/sys/psetsys.c b/usr/src/lib/libc/port/sys/psetsys.c index 05ee9a78e4..871a1c1941 100644 --- a/usr/src/lib/libc/port/sys/psetsys.c +++ b/usr/src/lib/libc/port/sys/psetsys.c @@ -20,22 +20,10 @@ */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -#pragma weak _pset_create = pset_create -#pragma weak _pset_destroy = pset_destroy -#pragma weak _pset_assign = pset_assign -#pragma weak _pset_info = pset_info -#pragma weak _pset_bind = pset_bind -#pragma weak _pset_getloadavg = pset_getloadavg -#pragma weak _pset_list = pset_list -#pragma weak _pset_setattr = pset_setattr -#pragma weak _pset_getattr = pset_getattr - #include "lint.h" #include <sys/types.h> #include <sys/procset.h> @@ -84,6 +72,12 @@ pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset) return (_pset(PSET_BIND, pset, idtype, id, opset)); } +int +pset_bind_lwp(psetid_t pset, id_t id, pid_t pid, psetid_t *opset) +{ + return (_pset(PSET_BIND_LWP, pset, id, pid, opset)); +} + /* * Get the per-processor-set load average. */ diff --git a/usr/src/lib/libproc/common/libproc.h b/usr/src/lib/libproc/common/libproc.h index c9807a4da7..a425d3c211 100644 --- a/usr/src/lib/libproc/common/libproc.h +++ b/usr/src/lib/libproc/common/libproc.h @@ -354,8 +354,6 @@ extern int pr_getsockopt(struct ps_prochandle *, int, int, int, void *, int *); extern int pr_processor_bind(struct ps_prochandle *, idtype_t, id_t, int, int *); -extern int pr_pset_bind(struct ps_prochandle *, - int, idtype_t, id_t, int *); /* * Function prototypes for accessing per-LWP register information. diff --git a/usr/src/lib/libproc/common/llib-lproc b/usr/src/lib/libproc/common/llib-lproc index 2faf27865d..9626e80024 100644 --- a/usr/src/lib/libproc/common/llib-lproc +++ b/usr/src/lib/libproc/common/llib-lproc @@ -22,7 +22,7 @@ /* PROTOLIB1 */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #include "libproc.h" @@ -304,7 +304,6 @@ int pr_access(struct ps_prochandle *Pr, const char *path, int amode); /* pr_pbind.c */ int pr_processor_bind(struct ps_prochandle *Pr, idtype_t, id_t, int, int *); -int pr_pset_bind(struct ps_prochandle *Pr, int, idtype_t, id_t, int *); /* pr_rename.c */ int pr_rename(struct ps_prochandle *Pr, const char *old, const char *new); diff --git a/usr/src/lib/libproc/common/mapfile-vers b/usr/src/lib/libproc/common/mapfile-vers index 555ad60c31..8fff0bb1aa 100644 --- a/usr/src/lib/libproc/common/mapfile-vers +++ b/usr/src/lib/libproc/common/mapfile-vers @@ -220,7 +220,6 @@ SUNWprivate_1.1 { proc_walk; pr_open; pr_processor_bind; - pr_pset_bind; pr_rename; pr_setitimer; pr_setprojrctl; diff --git a/usr/src/lib/libproc/common/pr_pbind.c b/usr/src/lib/libproc/common/pr_pbind.c index 1a9f6de689..889a493eaa 100644 --- a/usr/src/lib/libproc/common/pr_pbind.c +++ b/usr/src/lib/libproc/common/pr_pbind.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #include <sys/procset.h> #include <sys/processor.h> @@ -90,66 +87,3 @@ pr_processor_bind(struct ps_prochandle *Pr, idtype_t idtype, id_t id, } return (rval.sys_rval1); } - -int -pr_pset_bind(struct ps_prochandle *Pr, int pset, idtype_t idtype, id_t id, - int *opset) -{ - sysret_t rval; /* return value */ - argdes_t argd[5]; /* arg descriptors */ - argdes_t *adp = &argd[0]; /* first argument */ - int error; - - if (Pr == NULL) /* no subject process */ - return (pset_bind(pset, idtype, id, opset)); - - adp->arg_value = PSET_BIND; /* PSET_BIND */ - adp->arg_object = NULL; - adp->arg_type = AT_BYVAL; - adp->arg_inout = AI_INPUT; - adp->arg_size = 0; - adp++; - - adp->arg_value = pset; /* pset */ - adp->arg_object = NULL; - adp->arg_type = AT_BYVAL; - adp->arg_inout = AI_INPUT; - adp->arg_size = 0; - adp++; - - adp->arg_value = idtype; /* idtype */ - adp->arg_object = NULL; - adp->arg_type = AT_BYVAL; - adp->arg_inout = AI_INPUT; - adp->arg_size = 0; - adp++; - - adp->arg_value = id; /* id */ - adp->arg_object = NULL; - adp->arg_type = AT_BYVAL; - adp->arg_inout = AI_INPUT; - adp->arg_size = 0; - adp++; - - if (opset == NULL) { - adp->arg_value = 0; /* opset */ - adp->arg_object = NULL; - adp->arg_type = AT_BYVAL; - adp->arg_inout = AI_INPUT; - adp->arg_size = 0; - } else { - adp->arg_value = 0; - adp->arg_object = opset; - adp->arg_type = AT_BYREF; - adp->arg_inout = AI_INOUT; - adp->arg_size = sizeof (int); - } - - error = Psyscall(Pr, &rval, SYS_pset, 5, &argd[0]); - - if (error) { - errno = (error < 0)? ENOSYS : error; - return (-1); - } - return (rval.sys_rval1); -} diff --git a/usr/src/uts/common/sys/pset.h b/usr/src/uts/common/sys/pset.h index f98e327620..bf6562bb4e 100644 --- a/usr/src/uts/common/sys/pset.h +++ b/usr/src/uts/common/sys/pset.h @@ -19,15 +19,13 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _SYS_PSET_H #define _SYS_PSET_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifdef __cplusplus extern "C" { #endif @@ -60,6 +58,7 @@ extern int pset_destroy(psetid_t); extern int pset_assign(psetid_t, processorid_t, psetid_t *); extern int pset_info(psetid_t, int *, uint_t *, processorid_t *); extern int pset_bind(psetid_t, idtype_t, id_t, psetid_t *); +extern int pset_bind_lwp(psetid_t, id_t, pid_t, psetid_t *); extern int pset_getloadavg(psetid_t, double [], int); extern int pset_list(psetid_t *, uint_t *); extern int pset_setattr(psetid_t, uint_t); @@ -72,6 +71,7 @@ extern int pset_destroy(); extern int pset_assign(); extern int pset_info(); extern int pset_bind(); +extern int pset_bind_lwp(); extern int pset_getloadavg(); extern int pset_list(); extern int pset_setattr(); @@ -93,6 +93,7 @@ extern int pset_getattr(); #define PSET_SETATTR 7 #define PSET_GETATTR 8 #define PSET_ASSIGN_FORCED 9 +#define PSET_BIND_LWP 10 /* attribute bits */ #define PSET_NOESCAPE 0x0001 diff --git a/usr/src/uts/common/syscall/pset.c b/usr/src/uts/common/syscall/pset.c index 4c1aef27c5..ce49082d4d 100644 --- a/usr/src/uts/common/syscall/pset.c +++ b/usr/src/uts/common/syscall/pset.c @@ -470,6 +470,66 @@ pset_bind_contract(cont_process_t *ctp, psetid_t pset, psetid_t *oldpset, return (error); } +/* + * Bind the lwp:id of process:pid to processor set: pset + */ +static int +pset_bind_lwp(psetid_t pset, id_t id, pid_t pid, psetid_t *opset) +{ + kthread_t *tp; + proc_t *pp; + psetid_t oldpset; + void *projbuf, *zonebuf; + int error = 0; + + pool_lock(); + mutex_enter(&cpu_lock); + projbuf = fss_allocbuf(FSS_NPROJ_BUF, FSS_ALLOC_PROJ); + zonebuf = fss_allocbuf(FSS_NPROJ_BUF, FSS_ALLOC_ZONE); + + mutex_enter(&pidlock); + if ((pid == P_MYID && id == P_MYID) || + (pid == curproc->p_pid && id == P_MYID)) { + pp = curproc; + tp = curthread; + mutex_enter(&pp->p_lock); + } else { + if (pid == P_MYID) { + pp = curproc; + } else if ((pp = prfind(pid)) == NULL) { + error = ESRCH; + goto err; + } + if (pp != curproc && id == P_MYID) { + error = EINVAL; + goto err; + } + mutex_enter(&pp->p_lock); + if ((tp = idtot(pp, id)) == NULL) { + mutex_exit(&pp->p_lock); + error = ESRCH; + goto err; + } + } + + error = pset_bind_thread(tp, pset, &oldpset, projbuf, zonebuf); + mutex_exit(&pp->p_lock); +err: + mutex_exit(&pidlock); + + fss_freebuf(projbuf, FSS_ALLOC_PROJ); + fss_freebuf(zonebuf, FSS_ALLOC_ZONE); + mutex_exit(&cpu_lock); + pool_unlock(); + if (opset != NULL) { + if (copyout(&oldpset, opset, sizeof (psetid_t)) != 0) + return (set_errno(EFAULT)); + } + if (error != 0) + return (set_errno(error)); + return (0); +} + static int pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset) { @@ -797,6 +857,9 @@ pset(int subcode, long arg1, long arg2, long arg3, long arg4) case PSET_BIND: return (pset_bind((psetid_t)arg1, (idtype_t)arg2, (id_t)arg3, (psetid_t *)arg4)); + case PSET_BIND_LWP: + return (pset_bind_lwp((psetid_t)arg1, (id_t)arg2, + (pid_t)arg3, (psetid_t *)arg4)); case PSET_GETLOADAVG: return (pset_getloadavg((psetid_t)arg1, (int *)arg2, (int)arg3)); |