17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5d5fbc238Sfr157268 * Common Development and Distribution License (the "License"). 6d5fbc238Sfr157268 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*438076ebSGangadhar Mylapuram * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/types.h> 277c478bd9Sstevel@tonic-gate #include <sys/systm.h> 287c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 297c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 307c478bd9Sstevel@tonic-gate #include <sys/thread.h> 317c478bd9Sstevel@tonic-gate #include <sys/disp.h> 327c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 337c478bd9Sstevel@tonic-gate #include <sys/debug.h> 347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 357c478bd9Sstevel@tonic-gate #include <sys/cpupart.h> 367c478bd9Sstevel@tonic-gate #include <sys/pset.h> 377c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 387c478bd9Sstevel@tonic-gate #include <sys/syscall.h> 397c478bd9Sstevel@tonic-gate #include <sys/task.h> 407c478bd9Sstevel@tonic-gate #include <sys/loadavg.h> 417c478bd9Sstevel@tonic-gate #include <sys/fss.h> 427c478bd9Sstevel@tonic-gate #include <sys/pool.h> 437c478bd9Sstevel@tonic-gate #include <sys/pool_pset.h> 447c478bd9Sstevel@tonic-gate #include <sys/policy.h> 457c478bd9Sstevel@tonic-gate #include <sys/zone.h> 467c478bd9Sstevel@tonic-gate #include <sys/contract/process_impl.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate static int pset(int, long, long, long, long); 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate static struct sysent pset_sysent = { 517c478bd9Sstevel@tonic-gate 5, 527c478bd9Sstevel@tonic-gate SE_ARGC | SE_NOUNLOAD, 537c478bd9Sstevel@tonic-gate (int (*)())pset, 547c478bd9Sstevel@tonic-gate }; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate static struct modlsys modlsys = { 577c478bd9Sstevel@tonic-gate &mod_syscallops, "processor sets", &pset_sysent 587c478bd9Sstevel@tonic-gate }; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL 617c478bd9Sstevel@tonic-gate static struct modlsys modlsys32 = { 627c478bd9Sstevel@tonic-gate &mod_syscallops32, "32-bit pset(2) syscall", &pset_sysent 637c478bd9Sstevel@tonic-gate }; 647c478bd9Sstevel@tonic-gate #endif 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 677c478bd9Sstevel@tonic-gate MODREV_1, 687c478bd9Sstevel@tonic-gate &modlsys, 697c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL 707c478bd9Sstevel@tonic-gate &modlsys32, 717c478bd9Sstevel@tonic-gate #endif 727c478bd9Sstevel@tonic-gate NULL 737c478bd9Sstevel@tonic-gate }; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define PSET_BADATTR(attr) ((~PSET_NOESCAPE) & (attr)) 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate int 787c478bd9Sstevel@tonic-gate _init(void) 797c478bd9Sstevel@tonic-gate { 807c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 817c478bd9Sstevel@tonic-gate } 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate int 847c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 857c478bd9Sstevel@tonic-gate { 867c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 877c478bd9Sstevel@tonic-gate } 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate static int 907c478bd9Sstevel@tonic-gate pset_create(psetid_t *psetp) 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate psetid_t newpset; 937c478bd9Sstevel@tonic-gate int error; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate if (secpolicy_pset(CRED()) != 0) 967c478bd9Sstevel@tonic-gate return (set_errno(EPERM)); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate pool_lock(); 997c478bd9Sstevel@tonic-gate if (pool_state == POOL_ENABLED) { 1007c478bd9Sstevel@tonic-gate pool_unlock(); 1017c478bd9Sstevel@tonic-gate return (set_errno(ENOTSUP)); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate error = cpupart_create(&newpset); 1047c478bd9Sstevel@tonic-gate if (error) { 1057c478bd9Sstevel@tonic-gate pool_unlock(); 1067c478bd9Sstevel@tonic-gate return (set_errno(error)); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate if (copyout(&newpset, psetp, sizeof (psetid_t)) != 0) { 1097c478bd9Sstevel@tonic-gate (void) cpupart_destroy(newpset); 1107c478bd9Sstevel@tonic-gate pool_unlock(); 1117c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate pool_unlock(); 1147c478bd9Sstevel@tonic-gate return (error); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate static int 1187c478bd9Sstevel@tonic-gate pset_destroy(psetid_t pset) 1197c478bd9Sstevel@tonic-gate { 1207c478bd9Sstevel@tonic-gate int error; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate if (secpolicy_pset(CRED()) != 0) 1237c478bd9Sstevel@tonic-gate return (set_errno(EPERM)); 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate pool_lock(); 1267c478bd9Sstevel@tonic-gate if (pool_state == POOL_ENABLED) { 1277c478bd9Sstevel@tonic-gate pool_unlock(); 1287c478bd9Sstevel@tonic-gate return (set_errno(ENOTSUP)); 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate error = cpupart_destroy(pset); 1317c478bd9Sstevel@tonic-gate pool_unlock(); 1327c478bd9Sstevel@tonic-gate if (error) 1337c478bd9Sstevel@tonic-gate return (set_errno(error)); 1347c478bd9Sstevel@tonic-gate else 1357c478bd9Sstevel@tonic-gate return (0); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate static int 1397c478bd9Sstevel@tonic-gate pset_assign(psetid_t pset, processorid_t cpuid, psetid_t *opset, int forced) 1407c478bd9Sstevel@tonic-gate { 1417c478bd9Sstevel@tonic-gate psetid_t oldpset; 1427c478bd9Sstevel@tonic-gate int error = 0; 1437c478bd9Sstevel@tonic-gate cpu_t *cp; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate if (pset != PS_QUERY && secpolicy_pset(CRED()) != 0) 1467c478bd9Sstevel@tonic-gate return (set_errno(EPERM)); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate pool_lock(); 1497c478bd9Sstevel@tonic-gate if (pset != PS_QUERY && pool_state == POOL_ENABLED) { 1507c478bd9Sstevel@tonic-gate pool_unlock(); 1517c478bd9Sstevel@tonic-gate return (set_errno(ENOTSUP)); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 1557c478bd9Sstevel@tonic-gate if ((cp = cpu_get(cpuid)) == NULL) { 1567c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 1577c478bd9Sstevel@tonic-gate pool_unlock(); 1587c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate oldpset = cpupart_query_cpu(cp); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate if (pset != PS_QUERY) 1647c478bd9Sstevel@tonic-gate error = cpupart_attach_cpu(pset, cp, forced); 1657c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 1667c478bd9Sstevel@tonic-gate pool_unlock(); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate if (error) 1697c478bd9Sstevel@tonic-gate return (set_errno(error)); 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate if (opset != NULL) 1727c478bd9Sstevel@tonic-gate if (copyout(&oldpset, opset, sizeof (psetid_t)) != 0) 1737c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate return (0); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate static int 1797c478bd9Sstevel@tonic-gate pset_info(psetid_t pset, int *typep, uint_t *numcpusp, 1807c478bd9Sstevel@tonic-gate processorid_t *cpulistp) 1817c478bd9Sstevel@tonic-gate { 1827c478bd9Sstevel@tonic-gate int pset_type; 1837c478bd9Sstevel@tonic-gate uint_t user_ncpus = 0, real_ncpus, copy_ncpus; 1847c478bd9Sstevel@tonic-gate processorid_t *pset_cpus = NULL; 1857c478bd9Sstevel@tonic-gate int error = 0; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate if (numcpusp != NULL) { 1887c478bd9Sstevel@tonic-gate if (copyin(numcpusp, &user_ncpus, sizeof (uint_t)) != 0) 1897c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate if (user_ncpus > max_ncpus) /* sanity check */ 1937c478bd9Sstevel@tonic-gate user_ncpus = max_ncpus; 1947c478bd9Sstevel@tonic-gate if (user_ncpus != 0 && cpulistp != NULL) 1957c478bd9Sstevel@tonic-gate pset_cpus = kmem_alloc(sizeof (processorid_t) * user_ncpus, 1967c478bd9Sstevel@tonic-gate KM_SLEEP); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate real_ncpus = user_ncpus; 1997c478bd9Sstevel@tonic-gate if ((error = cpupart_get_cpus(&pset, pset_cpus, &real_ncpus)) != 0) 2007c478bd9Sstevel@tonic-gate goto out; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * Now copyout the information about this processor set. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * Get number of cpus to copy back. If the user didn't pass in 2087c478bd9Sstevel@tonic-gate * a big enough buffer, only copy back as many cpus as fits in 2097c478bd9Sstevel@tonic-gate * the buffer but copy back the real number of cpus. 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate if (user_ncpus != 0 && cpulistp != NULL) { 2137c478bd9Sstevel@tonic-gate copy_ncpus = MIN(real_ncpus, user_ncpus); 2147c478bd9Sstevel@tonic-gate if (copyout(pset_cpus, cpulistp, 2157c478bd9Sstevel@tonic-gate sizeof (processorid_t) * copy_ncpus) != 0) { 2167c478bd9Sstevel@tonic-gate error = EFAULT; 2177c478bd9Sstevel@tonic-gate goto out; 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate if (pset_cpus != NULL) 2217c478bd9Sstevel@tonic-gate kmem_free(pset_cpus, sizeof (processorid_t) * user_ncpus); 2227c478bd9Sstevel@tonic-gate if (typep != NULL) { 2237c478bd9Sstevel@tonic-gate if (pset == PS_NONE) 2247c478bd9Sstevel@tonic-gate pset_type = PS_NONE; 2257c478bd9Sstevel@tonic-gate else 2267c478bd9Sstevel@tonic-gate pset_type = PS_PRIVATE; 2277c478bd9Sstevel@tonic-gate if (copyout(&pset_type, typep, sizeof (int)) != 0) 2287c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate if (numcpusp != NULL) 2317c478bd9Sstevel@tonic-gate if (copyout(&real_ncpus, numcpusp, sizeof (uint_t)) != 0) 2327c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 2337c478bd9Sstevel@tonic-gate return (0); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate out: 2367c478bd9Sstevel@tonic-gate if (pset_cpus != NULL) 2377c478bd9Sstevel@tonic-gate kmem_free(pset_cpus, sizeof (processorid_t) * user_ncpus); 2387c478bd9Sstevel@tonic-gate return (set_errno(error)); 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate static int 2427c478bd9Sstevel@tonic-gate pset_bind_thread(kthread_t *tp, psetid_t pset, psetid_t *oldpset, void *projbuf, 2437c478bd9Sstevel@tonic-gate void *zonebuf) 2447c478bd9Sstevel@tonic-gate { 2457c478bd9Sstevel@tonic-gate int error = 0; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate ASSERT(pool_lock_held()); 2487c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 2497c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&ttoproc(tp)->p_lock)); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate *oldpset = tp->t_bind_pset; 2520b70c467Sakolb 2530b70c467Sakolb switch (pset) { 2540b70c467Sakolb case PS_SOFT: 2550b70c467Sakolb TB_PSET_SOFT_SET(tp); 2560b70c467Sakolb break; 2570b70c467Sakolb 2580b70c467Sakolb case PS_HARD: 2590b70c467Sakolb TB_PSET_HARD_SET(tp); 2600b70c467Sakolb break; 2610b70c467Sakolb 2620b70c467Sakolb case PS_QUERY: 2630b70c467Sakolb break; 2640b70c467Sakolb 2650b70c467Sakolb case PS_QUERY_TYPE: 2660b70c467Sakolb *oldpset = TB_PSET_IS_SOFT(tp) ? PS_SOFT : PS_HARD; 2670b70c467Sakolb break; 2680b70c467Sakolb 2690b70c467Sakolb default: 2707c478bd9Sstevel@tonic-gate /* 2717c478bd9Sstevel@tonic-gate * Must have the same UID as the target process or 2727c478bd9Sstevel@tonic-gate * have PRIV_PROC_OWNER privilege. 2737c478bd9Sstevel@tonic-gate */ 2747c478bd9Sstevel@tonic-gate if (!hasprocperm(tp->t_cred, CRED())) 2757c478bd9Sstevel@tonic-gate return (EPERM); 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Unbinding of an unbound thread should always succeed. 2787c478bd9Sstevel@tonic-gate */ 2797c478bd9Sstevel@tonic-gate if (*oldpset == PS_NONE && pset == PS_NONE) 2807c478bd9Sstevel@tonic-gate return (0); 2817c478bd9Sstevel@tonic-gate /* 2827c478bd9Sstevel@tonic-gate * Only privileged processes can move threads from psets with 2837c478bd9Sstevel@tonic-gate * PSET_NOESCAPE attribute. 2847c478bd9Sstevel@tonic-gate */ 2857c478bd9Sstevel@tonic-gate if ((tp->t_cpupart->cp_attr & PSET_NOESCAPE) && 2867c478bd9Sstevel@tonic-gate secpolicy_pset(CRED()) != 0) 2877c478bd9Sstevel@tonic-gate return (EPERM); 2887c478bd9Sstevel@tonic-gate if ((error = cpupart_bind_thread(tp, pset, 0, 2897c478bd9Sstevel@tonic-gate projbuf, zonebuf)) == 0) 2907c478bd9Sstevel@tonic-gate tp->t_bind_pset = pset; 2910b70c467Sakolb 2920b70c467Sakolb break; 2937c478bd9Sstevel@tonic-gate } 2940b70c467Sakolb 2957c478bd9Sstevel@tonic-gate return (error); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate static int 2997c478bd9Sstevel@tonic-gate pset_bind_process(proc_t *pp, psetid_t pset, psetid_t *oldpset, void *projbuf, 3007c478bd9Sstevel@tonic-gate void *zonebuf) 3017c478bd9Sstevel@tonic-gate { 3027c478bd9Sstevel@tonic-gate int error = 0; 3037c478bd9Sstevel@tonic-gate kthread_t *tp; 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate /* skip kernel processes */ 3060b70c467Sakolb if ((pset != PS_QUERY) && pp->p_flag & SSYS) { 3077c478bd9Sstevel@tonic-gate *oldpset = PS_NONE; 308*438076ebSGangadhar Mylapuram return (ENOTSUP); 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 3127c478bd9Sstevel@tonic-gate tp = pp->p_tlist; 3137c478bd9Sstevel@tonic-gate if (tp != NULL) { 3147c478bd9Sstevel@tonic-gate do { 3157c478bd9Sstevel@tonic-gate int rval; 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate rval = pset_bind_thread(tp, pset, oldpset, projbuf, 3187c478bd9Sstevel@tonic-gate zonebuf); 3197c478bd9Sstevel@tonic-gate if (error == 0) 3207c478bd9Sstevel@tonic-gate error = rval; 3217c478bd9Sstevel@tonic-gate } while ((tp = tp->t_forw) != pp->p_tlist); 3227c478bd9Sstevel@tonic-gate } else 3237c478bd9Sstevel@tonic-gate error = ESRCH; 3247c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate return (error); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate static int 3307c478bd9Sstevel@tonic-gate pset_bind_task(task_t *tk, psetid_t pset, psetid_t *oldpset, void *projbuf, 3317c478bd9Sstevel@tonic-gate void *zonebuf) 3327c478bd9Sstevel@tonic-gate { 3337c478bd9Sstevel@tonic-gate int error = 0; 3347c478bd9Sstevel@tonic-gate proc_t *pp; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate if ((pp = tk->tk_memb_list) == NULL) { 3397c478bd9Sstevel@tonic-gate return (ESRCH); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate do { 3437c478bd9Sstevel@tonic-gate int rval; 3447c478bd9Sstevel@tonic-gate 345*438076ebSGangadhar Mylapuram if (!(pp->p_flag & SSYS)) { 346*438076ebSGangadhar Mylapuram rval = pset_bind_process(pp, pset, oldpset, projbuf, 347*438076ebSGangadhar Mylapuram zonebuf); 3487c478bd9Sstevel@tonic-gate if (error == 0) 3497c478bd9Sstevel@tonic-gate error = rval; 350*438076ebSGangadhar Mylapuram } 3517c478bd9Sstevel@tonic-gate } while ((pp = pp->p_tasknext) != tk->tk_memb_list); 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate return (error); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate static int 3577c478bd9Sstevel@tonic-gate pset_bind_project(kproject_t *kpj, psetid_t pset, psetid_t *oldpset, 3587c478bd9Sstevel@tonic-gate void *projbuf, void *zonebuf) 3597c478bd9Sstevel@tonic-gate { 3607c478bd9Sstevel@tonic-gate int error = 0; 3617c478bd9Sstevel@tonic-gate proc_t *pp; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate for (pp = practive; pp != NULL; pp = pp->p_next) { 3667c478bd9Sstevel@tonic-gate if (pp->p_tlist == NULL) 3677c478bd9Sstevel@tonic-gate continue; 368*438076ebSGangadhar Mylapuram if (pp->p_task->tk_proj == kpj && !(pp->p_flag & SSYS)) { 3697c478bd9Sstevel@tonic-gate int rval; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate rval = pset_bind_process(pp, pset, oldpset, projbuf, 3727c478bd9Sstevel@tonic-gate zonebuf); 3737c478bd9Sstevel@tonic-gate if (error == 0) 3747c478bd9Sstevel@tonic-gate error = rval; 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate return (error); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate static int 3827c478bd9Sstevel@tonic-gate pset_bind_zone(zone_t *zptr, psetid_t pset, psetid_t *oldpset, void *projbuf, 3837c478bd9Sstevel@tonic-gate void *zonebuf) 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate int error = 0; 3867c478bd9Sstevel@tonic-gate proc_t *pp; 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate for (pp = practive; pp != NULL; pp = pp->p_next) { 391*438076ebSGangadhar Mylapuram if (pp->p_zone == zptr && !(pp->p_flag & SSYS)) { 3927c478bd9Sstevel@tonic-gate int rval; 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate rval = pset_bind_process(pp, pset, oldpset, projbuf, 3957c478bd9Sstevel@tonic-gate zonebuf); 3967c478bd9Sstevel@tonic-gate if (error == 0) 3977c478bd9Sstevel@tonic-gate error = rval; 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate return (error); 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate /* 4057c478bd9Sstevel@tonic-gate * Unbind all threads from the specified processor set, or from all 4067c478bd9Sstevel@tonic-gate * processor sets. 4077c478bd9Sstevel@tonic-gate */ 4087c478bd9Sstevel@tonic-gate static int 4097c478bd9Sstevel@tonic-gate pset_unbind(psetid_t pset, void *projbuf, void *zonebuf, idtype_t idtype) 4107c478bd9Sstevel@tonic-gate { 4117c478bd9Sstevel@tonic-gate psetid_t olbind; 4127c478bd9Sstevel@tonic-gate kthread_t *tp; 4137c478bd9Sstevel@tonic-gate int error = 0; 4147c478bd9Sstevel@tonic-gate int rval; 4157c478bd9Sstevel@tonic-gate proc_t *pp; 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate if (idtype == P_PSETID && cpupart_find(pset) == NULL) 4207c478bd9Sstevel@tonic-gate return (EINVAL); 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 4237c478bd9Sstevel@tonic-gate for (pp = practive; pp != NULL; pp = pp->p_next) { 4247c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 4257c478bd9Sstevel@tonic-gate tp = pp->p_tlist; 4267c478bd9Sstevel@tonic-gate /* 4277c478bd9Sstevel@tonic-gate * Skip zombies and kernel processes, and processes in 4287c478bd9Sstevel@tonic-gate * other zones, if called from a non-global zone. 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate if (tp == NULL || (pp->p_flag & SSYS) || 4317c478bd9Sstevel@tonic-gate !HASZONEACCESS(curproc, pp->p_zone->zone_id)) { 4327c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 4337c478bd9Sstevel@tonic-gate continue; 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate do { 4367c478bd9Sstevel@tonic-gate if ((idtype == P_PSETID && tp->t_bind_pset != pset) || 4377c478bd9Sstevel@tonic-gate (idtype == P_ALL && tp->t_bind_pset == PS_NONE)) 4387c478bd9Sstevel@tonic-gate continue; 4397c478bd9Sstevel@tonic-gate rval = pset_bind_thread(tp, PS_NONE, &olbind, 4407c478bd9Sstevel@tonic-gate projbuf, zonebuf); 4417c478bd9Sstevel@tonic-gate if (error == 0) 4427c478bd9Sstevel@tonic-gate error = rval; 4437c478bd9Sstevel@tonic-gate } while ((tp = tp->t_forw) != pp->p_tlist); 4447c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 4477c478bd9Sstevel@tonic-gate return (error); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate static int 4517c478bd9Sstevel@tonic-gate pset_bind_contract(cont_process_t *ctp, psetid_t pset, psetid_t *oldpset, 4527c478bd9Sstevel@tonic-gate void *projbuf, void *zonebuf) 4537c478bd9Sstevel@tonic-gate { 4547c478bd9Sstevel@tonic-gate int error = 0; 4557c478bd9Sstevel@tonic-gate proc_t *pp; 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate for (pp = practive; pp != NULL; pp = pp->p_next) { 4607c478bd9Sstevel@tonic-gate if (pp->p_ct_process == ctp) { 4617c478bd9Sstevel@tonic-gate int rval; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate rval = pset_bind_process(pp, pset, oldpset, projbuf, 4647c478bd9Sstevel@tonic-gate zonebuf); 4657c478bd9Sstevel@tonic-gate if (error == 0) 4667c478bd9Sstevel@tonic-gate error = rval; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate return (error); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate static int 4747c478bd9Sstevel@tonic-gate pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset) 4757c478bd9Sstevel@tonic-gate { 4767c478bd9Sstevel@tonic-gate kthread_t *tp; 4777c478bd9Sstevel@tonic-gate proc_t *pp; 4787c478bd9Sstevel@tonic-gate task_t *tk; 4797c478bd9Sstevel@tonic-gate kproject_t *kpj; 4807c478bd9Sstevel@tonic-gate contract_t *ct; 4817c478bd9Sstevel@tonic-gate zone_t *zptr; 4827c478bd9Sstevel@tonic-gate psetid_t oldpset; 4837c478bd9Sstevel@tonic-gate int error = 0; 4847c478bd9Sstevel@tonic-gate void *projbuf, *zonebuf; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate pool_lock(); 4870b70c467Sakolb if ((pset != PS_QUERY) && (pset != PS_SOFT) && 4880b70c467Sakolb (pset != PS_HARD) && (pset != PS_QUERY_TYPE)) { 4897c478bd9Sstevel@tonic-gate /* 4907c478bd9Sstevel@tonic-gate * Check if the set actually exists before checking 4917c478bd9Sstevel@tonic-gate * permissions. This is the historical error 4927c478bd9Sstevel@tonic-gate * precedence. Note that if pset was PS_MYID, the 4937c478bd9Sstevel@tonic-gate * cpupart_get_cpus call will change it to the 4947c478bd9Sstevel@tonic-gate * processor set id of the caller (or PS_NONE if the 4957c478bd9Sstevel@tonic-gate * caller is not bound to a processor set). 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate if (pool_state == POOL_ENABLED) { 4987c478bd9Sstevel@tonic-gate pool_unlock(); 4997c478bd9Sstevel@tonic-gate return (set_errno(ENOTSUP)); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate if (cpupart_get_cpus(&pset, NULL, NULL) != 0) { 5027c478bd9Sstevel@tonic-gate pool_unlock(); 5037c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 5047c478bd9Sstevel@tonic-gate } else if (pset != PS_NONE && secpolicy_pset(CRED()) != 0) { 5057c478bd9Sstevel@tonic-gate pool_unlock(); 5067c478bd9Sstevel@tonic-gate return (set_errno(EPERM)); 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* 5117c478bd9Sstevel@tonic-gate * Pre-allocate enough buffers for FSS for all active projects 5127c478bd9Sstevel@tonic-gate * and for all active zones on the system. Unused buffers will 5137c478bd9Sstevel@tonic-gate * be freed later by fss_freebuf(). 5147c478bd9Sstevel@tonic-gate */ 5157c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 5167c478bd9Sstevel@tonic-gate projbuf = fss_allocbuf(FSS_NPROJ_BUF, FSS_ALLOC_PROJ); 5177c478bd9Sstevel@tonic-gate zonebuf = fss_allocbuf(FSS_NPROJ_BUF, FSS_ALLOC_ZONE); 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate switch (idtype) { 5207c478bd9Sstevel@tonic-gate case P_LWPID: 5217c478bd9Sstevel@tonic-gate pp = curproc; 5227c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 5237c478bd9Sstevel@tonic-gate mutex_enter(&pp->p_lock); 5247c478bd9Sstevel@tonic-gate if (id == P_MYID) { 5257c478bd9Sstevel@tonic-gate tp = curthread; 5267c478bd9Sstevel@tonic-gate } else { 5277c478bd9Sstevel@tonic-gate if ((tp = idtot(pp, id)) == NULL) { 5287c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 5297c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5307c478bd9Sstevel@tonic-gate error = ESRCH; 5317c478bd9Sstevel@tonic-gate break; 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate error = pset_bind_thread(tp, pset, &oldpset, projbuf, zonebuf); 5357c478bd9Sstevel@tonic-gate mutex_exit(&pp->p_lock); 5367c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5377c478bd9Sstevel@tonic-gate break; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate case P_PID: 5407c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 5417c478bd9Sstevel@tonic-gate if (id == P_MYID) { 5427c478bd9Sstevel@tonic-gate pp = curproc; 5437c478bd9Sstevel@tonic-gate } else if ((pp = prfind(id)) == NULL) { 5447c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5457c478bd9Sstevel@tonic-gate error = ESRCH; 5467c478bd9Sstevel@tonic-gate break; 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate error = pset_bind_process(pp, pset, &oldpset, projbuf, zonebuf); 5497c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5507c478bd9Sstevel@tonic-gate break; 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate case P_TASKID: 5537c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 5547c478bd9Sstevel@tonic-gate if (id == P_MYID) 5557c478bd9Sstevel@tonic-gate id = curproc->p_task->tk_tkid; 5567c478bd9Sstevel@tonic-gate if ((tk = task_hold_by_id(id)) == NULL) { 5577c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5587c478bd9Sstevel@tonic-gate error = ESRCH; 5597c478bd9Sstevel@tonic-gate break; 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate error = pset_bind_task(tk, pset, &oldpset, projbuf, zonebuf); 5627c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5637c478bd9Sstevel@tonic-gate task_rele(tk); 5647c478bd9Sstevel@tonic-gate break; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate case P_PROJID: 5670209230bSgjelinek pp = curproc; 5687c478bd9Sstevel@tonic-gate if (id == P_MYID) 5697c478bd9Sstevel@tonic-gate id = curprojid(); 5700209230bSgjelinek if ((kpj = project_hold_by_id(id, pp->p_zone, 5717c478bd9Sstevel@tonic-gate PROJECT_HOLD_FIND)) == NULL) { 5727c478bd9Sstevel@tonic-gate error = ESRCH; 5737c478bd9Sstevel@tonic-gate break; 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 5767c478bd9Sstevel@tonic-gate error = pset_bind_project(kpj, pset, &oldpset, projbuf, 5777c478bd9Sstevel@tonic-gate zonebuf); 5787c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5797c478bd9Sstevel@tonic-gate project_rele(kpj); 5807c478bd9Sstevel@tonic-gate break; 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate case P_ZONEID: 5837c478bd9Sstevel@tonic-gate if (id == P_MYID) 5847c478bd9Sstevel@tonic-gate id = getzoneid(); 5857c478bd9Sstevel@tonic-gate if ((zptr = zone_find_by_id(id)) == NULL) { 5867c478bd9Sstevel@tonic-gate error = ESRCH; 5877c478bd9Sstevel@tonic-gate break; 5887c478bd9Sstevel@tonic-gate } 5897c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 5907c478bd9Sstevel@tonic-gate error = pset_bind_zone(zptr, pset, &oldpset, projbuf, zonebuf); 5917c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 5927c478bd9Sstevel@tonic-gate zone_rele(zptr); 5937c478bd9Sstevel@tonic-gate break; 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate case P_CTID: 5967c478bd9Sstevel@tonic-gate if (id == P_MYID) 5977c478bd9Sstevel@tonic-gate id = PRCTID(curproc); 5987c478bd9Sstevel@tonic-gate if ((ct = contract_type_ptr(process_type, id, 5997c478bd9Sstevel@tonic-gate curproc->p_zone->zone_uniqid)) == NULL) { 6007c478bd9Sstevel@tonic-gate error = ESRCH; 6017c478bd9Sstevel@tonic-gate break; 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 6047c478bd9Sstevel@tonic-gate error = pset_bind_contract(ct->ct_data, pset, &oldpset, projbuf, 6057c478bd9Sstevel@tonic-gate zonebuf); 6067c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 6077c478bd9Sstevel@tonic-gate contract_rele(ct); 6087c478bd9Sstevel@tonic-gate break; 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate case P_PSETID: 6117c478bd9Sstevel@tonic-gate if (id == P_MYID || pset != PS_NONE || !INGLOBALZONE(curproc)) { 6127c478bd9Sstevel@tonic-gate error = EINVAL; 6137c478bd9Sstevel@tonic-gate break; 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate error = pset_unbind(id, projbuf, zonebuf, idtype); 6167c478bd9Sstevel@tonic-gate break; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate case P_ALL: 6197c478bd9Sstevel@tonic-gate if (id == P_MYID || pset != PS_NONE || !INGLOBALZONE(curproc)) { 6207c478bd9Sstevel@tonic-gate error = EINVAL; 6217c478bd9Sstevel@tonic-gate break; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate error = pset_unbind(PS_NONE, projbuf, zonebuf, idtype); 6247c478bd9Sstevel@tonic-gate break; 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate default: 6277c478bd9Sstevel@tonic-gate error = EINVAL; 6287c478bd9Sstevel@tonic-gate break; 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate fss_freebuf(projbuf, FSS_ALLOC_PROJ); 6327c478bd9Sstevel@tonic-gate fss_freebuf(zonebuf, FSS_ALLOC_ZONE); 6337c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 6347c478bd9Sstevel@tonic-gate pool_unlock(); 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate if (error != 0) 6377c478bd9Sstevel@tonic-gate return (set_errno(error)); 6387c478bd9Sstevel@tonic-gate if (opset != NULL) { 6397c478bd9Sstevel@tonic-gate if (copyout(&oldpset, opset, sizeof (psetid_t)) != 0) 6407c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate return (0); 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /* 6467c478bd9Sstevel@tonic-gate * Report load average statistics for the specified processor set. 6477c478bd9Sstevel@tonic-gate */ 6487c478bd9Sstevel@tonic-gate static int 6497c478bd9Sstevel@tonic-gate pset_getloadavg(psetid_t pset, int *buf, int nelem) 6507c478bd9Sstevel@tonic-gate { 651d5fbc238Sfr157268 int loadbuf[LOADAVG_NSTATS]; 6527c478bd9Sstevel@tonic-gate int error = 0; 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate if (nelem < 0) 6557c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate /* 6587c478bd9Sstevel@tonic-gate * We keep the same number of load average statistics for processor 6597c478bd9Sstevel@tonic-gate * sets as we do for the system as a whole. 6607c478bd9Sstevel@tonic-gate */ 6617c478bd9Sstevel@tonic-gate if (nelem > LOADAVG_NSTATS) 6627c478bd9Sstevel@tonic-gate nelem = LOADAVG_NSTATS; 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 6657c478bd9Sstevel@tonic-gate error = cpupart_get_loadavg(pset, loadbuf, nelem); 6667c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 6677c478bd9Sstevel@tonic-gate if (!error && nelem && copyout(loadbuf, buf, nelem * sizeof (int)) != 0) 6687c478bd9Sstevel@tonic-gate error = EFAULT; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate if (error) 6717c478bd9Sstevel@tonic-gate return (set_errno(error)); 6727c478bd9Sstevel@tonic-gate else 6737c478bd9Sstevel@tonic-gate return (0); 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate /* 6787c478bd9Sstevel@tonic-gate * Return list of active processor sets, up to a maximum indicated by 6797c478bd9Sstevel@tonic-gate * numpsets. The total number of processor sets is stored in the 6807c478bd9Sstevel@tonic-gate * location pointed to by numpsets. 6817c478bd9Sstevel@tonic-gate */ 6827c478bd9Sstevel@tonic-gate static int 6837c478bd9Sstevel@tonic-gate pset_list(psetid_t *psetlist, uint_t *numpsets) 6847c478bd9Sstevel@tonic-gate { 6857c478bd9Sstevel@tonic-gate uint_t user_npsets = 0; 6867c478bd9Sstevel@tonic-gate uint_t real_npsets; 6877c478bd9Sstevel@tonic-gate psetid_t *psets = NULL; 6887c478bd9Sstevel@tonic-gate int error = 0; 6897c478bd9Sstevel@tonic-gate 6907c478bd9Sstevel@tonic-gate if (numpsets != NULL) { 6917c478bd9Sstevel@tonic-gate if (copyin(numpsets, &user_npsets, sizeof (uint_t)) != 0) 6927c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate /* 6967c478bd9Sstevel@tonic-gate * Get the list of all processor sets. First we need to find 6977c478bd9Sstevel@tonic-gate * out how many there are, so we can allocate a large enough 6987c478bd9Sstevel@tonic-gate * buffer. 6997c478bd9Sstevel@tonic-gate */ 7007c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 7017c478bd9Sstevel@tonic-gate if (!INGLOBALZONE(curproc) && pool_pset_enabled()) { 7027c478bd9Sstevel@tonic-gate psetid_t psetid = zone_pset_get(curproc->p_zone); 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate if (psetid == PS_NONE) { 7057c478bd9Sstevel@tonic-gate real_npsets = 0; 7067c478bd9Sstevel@tonic-gate } else { 7077c478bd9Sstevel@tonic-gate real_npsets = 1; 7087c478bd9Sstevel@tonic-gate psets = kmem_alloc(real_npsets * sizeof (psetid_t), 7097c478bd9Sstevel@tonic-gate KM_SLEEP); 7107c478bd9Sstevel@tonic-gate psets[0] = psetid; 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate } else { 7137c478bd9Sstevel@tonic-gate real_npsets = cpupart_list(0, NULL, CP_ALL); 7147c478bd9Sstevel@tonic-gate if (real_npsets) { 7157c478bd9Sstevel@tonic-gate psets = kmem_alloc(real_npsets * sizeof (psetid_t), 7167c478bd9Sstevel@tonic-gate KM_SLEEP); 7177c478bd9Sstevel@tonic-gate (void) cpupart_list(psets, real_npsets, CP_ALL); 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate if (user_npsets > real_npsets) 7237c478bd9Sstevel@tonic-gate user_npsets = real_npsets; 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate if (numpsets != NULL) { 7267c478bd9Sstevel@tonic-gate if (copyout(&real_npsets, numpsets, sizeof (uint_t)) != 0) 7277c478bd9Sstevel@tonic-gate error = EFAULT; 7287c478bd9Sstevel@tonic-gate else if (psetlist != NULL && user_npsets != 0) { 7297c478bd9Sstevel@tonic-gate if (copyout(psets, psetlist, 7307c478bd9Sstevel@tonic-gate user_npsets * sizeof (psetid_t)) != 0) 7317c478bd9Sstevel@tonic-gate error = EFAULT; 7327c478bd9Sstevel@tonic-gate } 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate if (real_npsets) 7367c478bd9Sstevel@tonic-gate kmem_free(psets, real_npsets * sizeof (psetid_t)); 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate if (error) 7397c478bd9Sstevel@tonic-gate return (set_errno(error)); 7407c478bd9Sstevel@tonic-gate else 7417c478bd9Sstevel@tonic-gate return (0); 7427c478bd9Sstevel@tonic-gate } 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate static int 7457c478bd9Sstevel@tonic-gate pset_setattr(psetid_t pset, uint_t attr) 7467c478bd9Sstevel@tonic-gate { 7477c478bd9Sstevel@tonic-gate int error; 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate if (secpolicy_pset(CRED()) != 0) 7507c478bd9Sstevel@tonic-gate return (set_errno(EPERM)); 7517c478bd9Sstevel@tonic-gate pool_lock(); 7527c478bd9Sstevel@tonic-gate if (pool_state == POOL_ENABLED) { 7537c478bd9Sstevel@tonic-gate pool_unlock(); 7547c478bd9Sstevel@tonic-gate return (set_errno(ENOTSUP)); 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate if (pset == PS_QUERY || PSET_BADATTR(attr)) { 7577c478bd9Sstevel@tonic-gate pool_unlock(); 7587c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate if ((error = cpupart_setattr(pset, attr)) != 0) { 7617c478bd9Sstevel@tonic-gate pool_unlock(); 7627c478bd9Sstevel@tonic-gate return (set_errno(error)); 7637c478bd9Sstevel@tonic-gate } 7647c478bd9Sstevel@tonic-gate pool_unlock(); 7657c478bd9Sstevel@tonic-gate return (0); 7667c478bd9Sstevel@tonic-gate } 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate static int 7697c478bd9Sstevel@tonic-gate pset_getattr(psetid_t pset, uint_t *attrp) 7707c478bd9Sstevel@tonic-gate { 7717c478bd9Sstevel@tonic-gate int error = 0; 7727c478bd9Sstevel@tonic-gate uint_t attr; 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate if (pset == PS_QUERY) 7757c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 7767c478bd9Sstevel@tonic-gate if ((error = cpupart_getattr(pset, &attr)) != 0) 7777c478bd9Sstevel@tonic-gate return (set_errno(error)); 7787c478bd9Sstevel@tonic-gate if (copyout(&attr, attrp, sizeof (uint_t)) != 0) 7797c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 7807c478bd9Sstevel@tonic-gate return (0); 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate static int 7847c478bd9Sstevel@tonic-gate pset(int subcode, long arg1, long arg2, long arg3, long arg4) 7857c478bd9Sstevel@tonic-gate { 7867c478bd9Sstevel@tonic-gate switch (subcode) { 7877c478bd9Sstevel@tonic-gate case PSET_CREATE: 7887c478bd9Sstevel@tonic-gate return (pset_create((psetid_t *)arg1)); 7897c478bd9Sstevel@tonic-gate case PSET_DESTROY: 7907c478bd9Sstevel@tonic-gate return (pset_destroy((psetid_t)arg1)); 7917c478bd9Sstevel@tonic-gate case PSET_ASSIGN: 7927c478bd9Sstevel@tonic-gate return (pset_assign((psetid_t)arg1, 7937c478bd9Sstevel@tonic-gate (processorid_t)arg2, (psetid_t *)arg3, 0)); 7947c478bd9Sstevel@tonic-gate case PSET_INFO: 7957c478bd9Sstevel@tonic-gate return (pset_info((psetid_t)arg1, (int *)arg2, 7967c478bd9Sstevel@tonic-gate (uint_t *)arg3, (processorid_t *)arg4)); 7977c478bd9Sstevel@tonic-gate case PSET_BIND: 7987c478bd9Sstevel@tonic-gate return (pset_bind((psetid_t)arg1, (idtype_t)arg2, 7997c478bd9Sstevel@tonic-gate (id_t)arg3, (psetid_t *)arg4)); 8007c478bd9Sstevel@tonic-gate case PSET_GETLOADAVG: 8017c478bd9Sstevel@tonic-gate return (pset_getloadavg((psetid_t)arg1, (int *)arg2, 8027c478bd9Sstevel@tonic-gate (int)arg3)); 8037c478bd9Sstevel@tonic-gate case PSET_LIST: 8047c478bd9Sstevel@tonic-gate return (pset_list((psetid_t *)arg1, (uint_t *)arg2)); 8057c478bd9Sstevel@tonic-gate case PSET_SETATTR: 8067c478bd9Sstevel@tonic-gate return (pset_setattr((psetid_t)arg1, (uint_t)arg2)); 8077c478bd9Sstevel@tonic-gate case PSET_GETATTR: 8087c478bd9Sstevel@tonic-gate return (pset_getattr((psetid_t)arg1, (uint_t *)arg2)); 8097c478bd9Sstevel@tonic-gate case PSET_ASSIGN_FORCED: 8107c478bd9Sstevel@tonic-gate return (pset_assign((psetid_t)arg1, 8117c478bd9Sstevel@tonic-gate (processorid_t)arg2, (psetid_t *)arg3, 1)); 8127c478bd9Sstevel@tonic-gate default: 8137c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 8147c478bd9Sstevel@tonic-gate } 8157c478bd9Sstevel@tonic-gate } 816