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 519f92332Sml93401 * Common Development and Distribution License (the "License"). 619f92332Sml93401 * 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 /* 2219f92332Sml93401 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/project.h> 297c478bd9Sstevel@tonic-gate #include <sys/modhash.h> 307c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 317c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 327c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 337c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 347c478bd9Sstevel@tonic-gate #include <sys/proc.h> 357c478bd9Sstevel@tonic-gate #include <sys/rctl.h> 367c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 377c478bd9Sstevel@tonic-gate #include <sys/fss.h> 387c478bd9Sstevel@tonic-gate #include <sys/systm.h> 397c478bd9Sstevel@tonic-gate #include <sys/ipc_impl.h> 407c478bd9Sstevel@tonic-gate #include <sys/port_kernel.h> 417c478bd9Sstevel@tonic-gate #include <sys/task.h> 427c478bd9Sstevel@tonic-gate #include <sys/zone.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate int project_hash_size = 64; 457c478bd9Sstevel@tonic-gate static kmutex_t project_hash_lock; 467c478bd9Sstevel@tonic-gate static kmutex_t projects_list_lock; 477c478bd9Sstevel@tonic-gate static mod_hash_t *projects_hash; 487c478bd9Sstevel@tonic-gate static kproject_t *projects_list; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_cpu_shares; 517c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_nlwps; 527c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_ntasks; 537c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_msgmni; 547c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_semmni; 557c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_shmmax; 567c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_shmmni; 577c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_portids; 58*c6939658Ssl108498 rctl_hndl_t rc_project_locked_mem; 597c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_contract; 607c478bd9Sstevel@tonic-gate rctl_hndl_t rc_project_crypto_mem; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Dummy structure used when comparing projects. This structure must be kept 647c478bd9Sstevel@tonic-gate * identical to the first two fields of kproject_t. 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate struct project_zone { 677c478bd9Sstevel@tonic-gate projid_t kpj_id; 687c478bd9Sstevel@tonic-gate zoneid_t kpj_zoneid; 697c478bd9Sstevel@tonic-gate }; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * Projects 737c478bd9Sstevel@tonic-gate * 747c478bd9Sstevel@tonic-gate * A dictionary of all active projects is maintained by the kernel so that we 757c478bd9Sstevel@tonic-gate * may track project usage and limits. (By an active project, we mean a 767c478bd9Sstevel@tonic-gate * project associated with one or more task, and therefore with one or more 777c478bd9Sstevel@tonic-gate * processes.) We build the dictionary on top of the mod_hash facility, since 787c478bd9Sstevel@tonic-gate * project additions and deletions are relatively rare events. An 797c478bd9Sstevel@tonic-gate * integer-to-pointer mapping is maintained within the hash, representing the 807c478bd9Sstevel@tonic-gate * map from project id to project structure. All projects, including the 817c478bd9Sstevel@tonic-gate * primordial "project 0", are allocated via the project_hold_by_id() 827c478bd9Sstevel@tonic-gate * interface. 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * Currently, the project contains a reference count; the project ID, which is 857c478bd9Sstevel@tonic-gate * examined by the extended accounting subsystem as well as /proc; a resource 867c478bd9Sstevel@tonic-gate * control set, which contains the allowable values (and actions on exceeding 877c478bd9Sstevel@tonic-gate * those values) for controlled project-level resources on the system; and a 887c478bd9Sstevel@tonic-gate * number of CPU shares, which is used by the fair share scheduling class 897c478bd9Sstevel@tonic-gate * (FSS) to support its proportion-based scheduling algorithm. 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * Reference counting convention 927c478bd9Sstevel@tonic-gate * The dictionary entry does not itself count as a reference--only references 937c478bd9Sstevel@tonic-gate * outside of the subsystem are tallied. At the drop of the final external 947c478bd9Sstevel@tonic-gate * reference, the project entry is removed. The reference counter keeps 957c478bd9Sstevel@tonic-gate * track of the number of threads *and* tasks within a project. 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * Locking 987c478bd9Sstevel@tonic-gate * Walking the doubly-linked project list must be done while holding 997c478bd9Sstevel@tonic-gate * projects_list_lock. Thus, any dereference of kpj_next or kpj_prev must be 1007c478bd9Sstevel@tonic-gate * under projects_list_lock. 1017c478bd9Sstevel@tonic-gate * 1027c478bd9Sstevel@tonic-gate * If both the hash lock, project_hash_lock, and the list lock are to be 1037c478bd9Sstevel@tonic-gate * acquired, the hash lock is to be acquired first. 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate static void 1087c478bd9Sstevel@tonic-gate project_data_init(kproject_data_t *data) 1097c478bd9Sstevel@tonic-gate { 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * Initialize subsystem-specific data 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate data->kpd_shmmax = 0; 114824c205fSml93401 data->kpd_ipc.ipcq_shmmni = 0; 115824c205fSml93401 data->kpd_ipc.ipcq_semmni = 0; 116824c205fSml93401 data->kpd_ipc.ipcq_msgmni = 0; 117*c6939658Ssl108498 data->kpd_locked_mem = 0; 118*c6939658Ssl108498 data->kpd_locked_mem_ctl = UINT64_MAX; 1197c478bd9Sstevel@tonic-gate data->kpd_contract = 0; 1207c478bd9Sstevel@tonic-gate data->kpd_crypto_mem = 0; 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1247c478bd9Sstevel@tonic-gate static uint_t 1257c478bd9Sstevel@tonic-gate project_hash_by_id(void *hash_data, mod_hash_key_t key) 1267c478bd9Sstevel@tonic-gate { 1277c478bd9Sstevel@tonic-gate struct project_zone *pz = key; 1287c478bd9Sstevel@tonic-gate uint_t mykey; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Merge the zoneid and projectid together to a 32-bit quantity, and 1327c478bd9Sstevel@tonic-gate * then pass that in to the existing idhash. 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate mykey = (pz->kpj_zoneid << 16) | pz->kpj_id; 1357c478bd9Sstevel@tonic-gate return (mod_hash_byid(hash_data, (mod_hash_key_t)(uintptr_t)mykey)); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate static int 1397c478bd9Sstevel@tonic-gate project_hash_key_cmp(mod_hash_key_t key1, mod_hash_key_t key2) 1407c478bd9Sstevel@tonic-gate { 1417c478bd9Sstevel@tonic-gate struct project_zone *pz1 = key1, *pz2 = key2; 1427c478bd9Sstevel@tonic-gate int retval; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate return ((int)((retval = pz1->kpj_id - pz2->kpj_id) != 0 ? retval : 1457c478bd9Sstevel@tonic-gate pz1->kpj_zoneid - pz2->kpj_zoneid)); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate static void 1497c478bd9Sstevel@tonic-gate project_hash_val_dtor(mod_hash_val_t val) 1507c478bd9Sstevel@tonic-gate { 1517c478bd9Sstevel@tonic-gate kproject_t *kp = (kproject_t *)val; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate ASSERT(kp->kpj_count == 0); 1547c478bd9Sstevel@tonic-gate kmem_free(kp, sizeof (kproject_t)); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * kproject_t *project_hold(kproject_t *) 1597c478bd9Sstevel@tonic-gate * 1607c478bd9Sstevel@tonic-gate * Overview 1617c478bd9Sstevel@tonic-gate * Record that an additional reference on the indicated project has been 1627c478bd9Sstevel@tonic-gate * taken. 1637c478bd9Sstevel@tonic-gate * 1647c478bd9Sstevel@tonic-gate * Return values 1657c478bd9Sstevel@tonic-gate * A pointer to the indicated project. 1667c478bd9Sstevel@tonic-gate * 1677c478bd9Sstevel@tonic-gate * Caller's context 1687c478bd9Sstevel@tonic-gate * project_hash_lock must not be held across the project_hold() call. 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate kproject_t * 1717c478bd9Sstevel@tonic-gate project_hold(kproject_t *p) 1727c478bd9Sstevel@tonic-gate { 1737c478bd9Sstevel@tonic-gate mutex_enter(&project_hash_lock); 1747c478bd9Sstevel@tonic-gate ASSERT(p != NULL); 1757c478bd9Sstevel@tonic-gate p->kpj_count++; 1767c478bd9Sstevel@tonic-gate ASSERT(p->kpj_count != 0); 1777c478bd9Sstevel@tonic-gate mutex_exit(&project_hash_lock); 1787c478bd9Sstevel@tonic-gate return (p); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate /* 1827c478bd9Sstevel@tonic-gate * kproject_t *project_hold_by_id(projid_t, zoneid_t, int) 1837c478bd9Sstevel@tonic-gate * 1847c478bd9Sstevel@tonic-gate * Overview 1857c478bd9Sstevel@tonic-gate * project_hold_by_id() performs a look-up in the dictionary of projects 1867c478bd9Sstevel@tonic-gate * active on the system by specified project ID + zone ID and puts a hold on 1877c478bd9Sstevel@tonic-gate * it. The third argument defines the desired behavior in the case when 1887c478bd9Sstevel@tonic-gate * project with given project ID cannot be found: 1897c478bd9Sstevel@tonic-gate * 1907c478bd9Sstevel@tonic-gate * PROJECT_HOLD_INSERT New entry is made in dictionary and the project 1917c478bd9Sstevel@tonic-gate * is added to the global list. 1927c478bd9Sstevel@tonic-gate * 1937c478bd9Sstevel@tonic-gate * PROJECT_HOLD_FIND Return NULL. 1947c478bd9Sstevel@tonic-gate * 1957c478bd9Sstevel@tonic-gate * The project is returned with its reference count incremented by one. 1967c478bd9Sstevel@tonic-gate * A new project derives its resource controls from those of project 0. 1977c478bd9Sstevel@tonic-gate * 1987c478bd9Sstevel@tonic-gate * Return values 1997c478bd9Sstevel@tonic-gate * A pointer to the held project. 2007c478bd9Sstevel@tonic-gate * 2017c478bd9Sstevel@tonic-gate * Caller's context 2027c478bd9Sstevel@tonic-gate * Caller must be in a context suitable for KM_SLEEP allocations. 2037c478bd9Sstevel@tonic-gate */ 2047c478bd9Sstevel@tonic-gate kproject_t * 2057c478bd9Sstevel@tonic-gate project_hold_by_id(projid_t id, zoneid_t zoneid, int flag) 2067c478bd9Sstevel@tonic-gate { 2077c478bd9Sstevel@tonic-gate kproject_t *spare_p; 2087c478bd9Sstevel@tonic-gate kproject_t *p; 2097c478bd9Sstevel@tonic-gate mod_hash_hndl_t hndl; 2107c478bd9Sstevel@tonic-gate rctl_set_t *set; 2117c478bd9Sstevel@tonic-gate rctl_alloc_gp_t *gp; 2127c478bd9Sstevel@tonic-gate rctl_entity_p_t e; 2137c478bd9Sstevel@tonic-gate struct project_zone pz; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate pz.kpj_id = id; 2167c478bd9Sstevel@tonic-gate pz.kpj_zoneid = zoneid; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate if (flag == PROJECT_HOLD_FIND) { 2197c478bd9Sstevel@tonic-gate mutex_enter(&project_hash_lock); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate if (mod_hash_find(projects_hash, (mod_hash_key_t)&pz, 2227c478bd9Sstevel@tonic-gate (mod_hash_val_t)&p) == MH_ERR_NOTFOUND) 2237c478bd9Sstevel@tonic-gate p = NULL; 2247c478bd9Sstevel@tonic-gate else 2257c478bd9Sstevel@tonic-gate p->kpj_count++; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate mutex_exit(&project_hash_lock); 2287c478bd9Sstevel@tonic-gate return (p); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate ASSERT(flag == PROJECT_HOLD_INSERT); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate spare_p = kmem_zalloc(sizeof (kproject_t), KM_SLEEP); 2347c478bd9Sstevel@tonic-gate set = rctl_set_create(); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate gp = rctl_set_init_prealloc(RCENTITY_PROJECT); 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate (void) mod_hash_reserve(projects_hash, &hndl); 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate mutex_enter(&curproc->p_lock); 2417c478bd9Sstevel@tonic-gate mutex_enter(&project_hash_lock); 2427c478bd9Sstevel@tonic-gate if (mod_hash_find(projects_hash, (mod_hash_key_t)&pz, 2437c478bd9Sstevel@tonic-gate (mod_hash_val_t *)&p) == MH_ERR_NOTFOUND) { 2447c478bd9Sstevel@tonic-gate p = spare_p; 2457c478bd9Sstevel@tonic-gate p->kpj_id = id; 2467c478bd9Sstevel@tonic-gate p->kpj_zoneid = zoneid; 2477c478bd9Sstevel@tonic-gate p->kpj_count = 0; 2487c478bd9Sstevel@tonic-gate p->kpj_shares = 1; 2497c478bd9Sstevel@tonic-gate p->kpj_nlwps = 0; 2507c478bd9Sstevel@tonic-gate p->kpj_ntasks = 0; 2517c478bd9Sstevel@tonic-gate p->kpj_nlwps_ctl = INT_MAX; 2527c478bd9Sstevel@tonic-gate p->kpj_ntasks_ctl = INT_MAX; 2537c478bd9Sstevel@tonic-gate project_data_init(&p->kpj_data); 2547c478bd9Sstevel@tonic-gate e.rcep_p.proj = p; 2557c478bd9Sstevel@tonic-gate e.rcep_t = RCENTITY_PROJECT; 2567c478bd9Sstevel@tonic-gate p->kpj_rctls = rctl_set_init(RCENTITY_PROJECT, curproc, &e, 2577c478bd9Sstevel@tonic-gate set, gp); 2587c478bd9Sstevel@tonic-gate mutex_exit(&curproc->p_lock); 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate if (mod_hash_insert_reserve(projects_hash, (mod_hash_key_t)p, 2617c478bd9Sstevel@tonic-gate (mod_hash_val_t)p, hndl)) 2627c478bd9Sstevel@tonic-gate panic("unable to insert project %d(%p)", id, (void *)p); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * Insert project into global project list. 2667c478bd9Sstevel@tonic-gate */ 2677c478bd9Sstevel@tonic-gate mutex_enter(&projects_list_lock); 2687c478bd9Sstevel@tonic-gate if (id != 0 || zoneid != GLOBAL_ZONEID) { 2697c478bd9Sstevel@tonic-gate p->kpj_next = projects_list; 2707c478bd9Sstevel@tonic-gate p->kpj_prev = projects_list->kpj_prev; 2717c478bd9Sstevel@tonic-gate p->kpj_prev->kpj_next = p; 2727c478bd9Sstevel@tonic-gate projects_list->kpj_prev = p; 2737c478bd9Sstevel@tonic-gate } else { 2747c478bd9Sstevel@tonic-gate /* 2757c478bd9Sstevel@tonic-gate * Special case: primordial hold on project 0. 2767c478bd9Sstevel@tonic-gate */ 2777c478bd9Sstevel@tonic-gate p->kpj_next = p; 2787c478bd9Sstevel@tonic-gate p->kpj_prev = p; 2797c478bd9Sstevel@tonic-gate projects_list = p; 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate mutex_exit(&projects_list_lock); 2827c478bd9Sstevel@tonic-gate } else { 2837c478bd9Sstevel@tonic-gate mutex_exit(&curproc->p_lock); 2847c478bd9Sstevel@tonic-gate mod_hash_cancel(projects_hash, &hndl); 2857c478bd9Sstevel@tonic-gate kmem_free(spare_p, sizeof (kproject_t)); 2867c478bd9Sstevel@tonic-gate rctl_set_free(set); 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate rctl_prealloc_destroy(gp); 2907c478bd9Sstevel@tonic-gate p->kpj_count++; 2917c478bd9Sstevel@tonic-gate mutex_exit(&project_hash_lock); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate return (p); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* 2987c478bd9Sstevel@tonic-gate * void project_rele(kproject_t *) 2997c478bd9Sstevel@tonic-gate * 3007c478bd9Sstevel@tonic-gate * Overview 3017c478bd9Sstevel@tonic-gate * Advertise that one external reference to this project is no longer needed. 3027c478bd9Sstevel@tonic-gate * 3037c478bd9Sstevel@tonic-gate * Return values 3047c478bd9Sstevel@tonic-gate * None. 3057c478bd9Sstevel@tonic-gate * 3067c478bd9Sstevel@tonic-gate * Caller's context 3077c478bd9Sstevel@tonic-gate * No restriction on context. 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate void 3107c478bd9Sstevel@tonic-gate project_rele(kproject_t *p) 3117c478bd9Sstevel@tonic-gate { 3127c478bd9Sstevel@tonic-gate mutex_enter(&project_hash_lock); 3137c478bd9Sstevel@tonic-gate ASSERT(p->kpj_count != 0); 3147c478bd9Sstevel@tonic-gate p->kpj_count--; 3157c478bd9Sstevel@tonic-gate if (p->kpj_count == 0) { 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate /* 3187c478bd9Sstevel@tonic-gate * Remove project from global list. 3197c478bd9Sstevel@tonic-gate */ 3207c478bd9Sstevel@tonic-gate mutex_enter(&projects_list_lock); 3217c478bd9Sstevel@tonic-gate p->kpj_next->kpj_prev = p->kpj_prev; 3227c478bd9Sstevel@tonic-gate p->kpj_prev->kpj_next = p->kpj_next; 3237c478bd9Sstevel@tonic-gate if (projects_list == p) 3247c478bd9Sstevel@tonic-gate projects_list = p->kpj_next; 3257c478bd9Sstevel@tonic-gate mutex_exit(&projects_list_lock); 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate rctl_set_free(p->kpj_rctls); 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate if (mod_hash_destroy(projects_hash, (mod_hash_key_t)p)) 3307c478bd9Sstevel@tonic-gate panic("unable to delete project %d zone %d", p->kpj_id, 3317c478bd9Sstevel@tonic-gate p->kpj_zoneid); 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate mutex_exit(&project_hash_lock); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate /* 3387c478bd9Sstevel@tonic-gate * int project_walk_all(zoneid_t, int (*)(kproject_t *, void *), void *) 3397c478bd9Sstevel@tonic-gate * 3407c478bd9Sstevel@tonic-gate * Overview 3417c478bd9Sstevel@tonic-gate * Walk the project list for the given zoneid with a callback. 3427c478bd9Sstevel@tonic-gate * 3437c478bd9Sstevel@tonic-gate * Return values 3447c478bd9Sstevel@tonic-gate * -1 for an invalid walk, number of projects visited otherwise. 3457c478bd9Sstevel@tonic-gate * 3467c478bd9Sstevel@tonic-gate * Caller's context 3477c478bd9Sstevel@tonic-gate * projects_list_lock must not be held, as it is acquired by 3487c478bd9Sstevel@tonic-gate * project_walk_all(). Accordingly, callbacks may not perform KM_SLEEP 3497c478bd9Sstevel@tonic-gate * allocations. 3507c478bd9Sstevel@tonic-gate */ 3517c478bd9Sstevel@tonic-gate int 3527c478bd9Sstevel@tonic-gate project_walk_all(zoneid_t zoneid, int (*cb)(kproject_t *, void *), 3537c478bd9Sstevel@tonic-gate void *walk_data) 3547c478bd9Sstevel@tonic-gate { 3557c478bd9Sstevel@tonic-gate int cnt = 0; 3567c478bd9Sstevel@tonic-gate kproject_t *kp = proj0p; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate mutex_enter(&projects_list_lock); 3597c478bd9Sstevel@tonic-gate do { 3607c478bd9Sstevel@tonic-gate if (zoneid != ALL_ZONES && kp->kpj_zoneid != zoneid) 3617c478bd9Sstevel@tonic-gate continue; 3627c478bd9Sstevel@tonic-gate if (cb(kp, walk_data) == -1) { 3637c478bd9Sstevel@tonic-gate cnt = -1; 3647c478bd9Sstevel@tonic-gate break; 3657c478bd9Sstevel@tonic-gate } else { 3667c478bd9Sstevel@tonic-gate cnt++; 3677c478bd9Sstevel@tonic-gate } 3687c478bd9Sstevel@tonic-gate } while ((kp = kp->kpj_next) != proj0p); 3697c478bd9Sstevel@tonic-gate mutex_exit(&projects_list_lock); 3707c478bd9Sstevel@tonic-gate return (cnt); 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate /* 3747c478bd9Sstevel@tonic-gate * projid_t curprojid(void) 3757c478bd9Sstevel@tonic-gate * 3767c478bd9Sstevel@tonic-gate * Overview 3777c478bd9Sstevel@tonic-gate * Return project ID of the current thread 3787c478bd9Sstevel@tonic-gate * 3797c478bd9Sstevel@tonic-gate * Caller's context 3807c478bd9Sstevel@tonic-gate * No restrictions. 3817c478bd9Sstevel@tonic-gate */ 3827c478bd9Sstevel@tonic-gate projid_t 3837c478bd9Sstevel@tonic-gate curprojid() 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate return (ttoproj(curthread)->kpj_id); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate /* 3897c478bd9Sstevel@tonic-gate * project.cpu-shares resource control support. 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3927c478bd9Sstevel@tonic-gate static rctl_qty_t 3937c478bd9Sstevel@tonic-gate project_cpu_shares_usage(rctl_t *rctl, struct proc *p) 3947c478bd9Sstevel@tonic-gate { 3957c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 3967c478bd9Sstevel@tonic-gate return (p->p_task->tk_proj->kpj_shares); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4007c478bd9Sstevel@tonic-gate static int 4017c478bd9Sstevel@tonic-gate project_cpu_shares_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e, 4027c478bd9Sstevel@tonic-gate rctl_qty_t nv) 4037c478bd9Sstevel@tonic-gate { 4047c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 4057c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 4067c478bd9Sstevel@tonic-gate if (e->rcep_p.proj == NULL) 4077c478bd9Sstevel@tonic-gate return (0); 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate e->rcep_p.proj->kpj_shares = nv; 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate return (0); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate static rctl_ops_t project_cpu_shares_ops = { 4167c478bd9Sstevel@tonic-gate rcop_no_action, 4177c478bd9Sstevel@tonic-gate project_cpu_shares_usage, 4187c478bd9Sstevel@tonic-gate project_cpu_shares_set, 4197c478bd9Sstevel@tonic-gate rcop_no_test 4207c478bd9Sstevel@tonic-gate }; 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4237c478bd9Sstevel@tonic-gate static rctl_qty_t 4247c478bd9Sstevel@tonic-gate project_lwps_usage(rctl_t *r, proc_t *p) 4257c478bd9Sstevel@tonic-gate { 4267c478bd9Sstevel@tonic-gate kproject_t *pj; 4277c478bd9Sstevel@tonic-gate rctl_qty_t nlwps; 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 4307c478bd9Sstevel@tonic-gate pj = p->p_task->tk_proj; 4317c478bd9Sstevel@tonic-gate mutex_enter(&p->p_zone->zone_nlwps_lock); 4327c478bd9Sstevel@tonic-gate nlwps = pj->kpj_nlwps; 4337c478bd9Sstevel@tonic-gate mutex_exit(&p->p_zone->zone_nlwps_lock); 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate return (nlwps); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4397c478bd9Sstevel@tonic-gate static int 4407c478bd9Sstevel@tonic-gate project_lwps_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e, rctl_val_t *rcntl, 4417c478bd9Sstevel@tonic-gate rctl_qty_t incr, uint_t flags) 4427c478bd9Sstevel@tonic-gate { 4437c478bd9Sstevel@tonic-gate rctl_qty_t nlwps; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 446*c6939658Ssl108498 ASSERT(MUTEX_HELD(&p->p_zone->zone_nlwps_lock)); 4477c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 4487c478bd9Sstevel@tonic-gate if (e->rcep_p.proj == NULL) 4497c478bd9Sstevel@tonic-gate return (0); 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate nlwps = e->rcep_p.proj->kpj_nlwps; 4527c478bd9Sstevel@tonic-gate if (nlwps + incr > rcntl->rcv_value) 4537c478bd9Sstevel@tonic-gate return (1); 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate return (0); 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4597c478bd9Sstevel@tonic-gate static int 4607c478bd9Sstevel@tonic-gate project_lwps_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e, 4617c478bd9Sstevel@tonic-gate rctl_qty_t nv) { 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 4647c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 4657c478bd9Sstevel@tonic-gate if (e->rcep_p.proj == NULL) 4667c478bd9Sstevel@tonic-gate return (0); 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate e->rcep_p.proj->kpj_nlwps_ctl = nv; 4697c478bd9Sstevel@tonic-gate return (0); 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate static rctl_ops_t project_lwps_ops = { 4737c478bd9Sstevel@tonic-gate rcop_no_action, 4747c478bd9Sstevel@tonic-gate project_lwps_usage, 4757c478bd9Sstevel@tonic-gate project_lwps_set, 4767c478bd9Sstevel@tonic-gate project_lwps_test, 4777c478bd9Sstevel@tonic-gate }; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4807c478bd9Sstevel@tonic-gate static rctl_qty_t 4817c478bd9Sstevel@tonic-gate project_ntasks_usage(rctl_t *r, proc_t *p) 4827c478bd9Sstevel@tonic-gate { 4837c478bd9Sstevel@tonic-gate kproject_t *pj; 4847c478bd9Sstevel@tonic-gate rctl_qty_t ntasks; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 4877c478bd9Sstevel@tonic-gate pj = p->p_task->tk_proj; 4887c478bd9Sstevel@tonic-gate mutex_enter(&p->p_zone->zone_nlwps_lock); 4897c478bd9Sstevel@tonic-gate ntasks = pj->kpj_ntasks; 4907c478bd9Sstevel@tonic-gate mutex_exit(&p->p_zone->zone_nlwps_lock); 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate return (ntasks); 4937c478bd9Sstevel@tonic-gate } 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4967c478bd9Sstevel@tonic-gate static int 4977c478bd9Sstevel@tonic-gate project_ntasks_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e, rctl_val_t *rcntl, 4987c478bd9Sstevel@tonic-gate rctl_qty_t incr, uint_t flags) 4997c478bd9Sstevel@tonic-gate { 5007c478bd9Sstevel@tonic-gate rctl_qty_t ntasks; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 5037c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 5047c478bd9Sstevel@tonic-gate ntasks = e->rcep_p.proj->kpj_ntasks; 5057c478bd9Sstevel@tonic-gate if (ntasks + incr > rcntl->rcv_value) 5067c478bd9Sstevel@tonic-gate return (1); 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate return (0); 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5127c478bd9Sstevel@tonic-gate static int 5137c478bd9Sstevel@tonic-gate project_ntasks_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e, 5147c478bd9Sstevel@tonic-gate rctl_qty_t nv) { 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 5177c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 5187c478bd9Sstevel@tonic-gate e->rcep_p.proj->kpj_ntasks_ctl = nv; 5197c478bd9Sstevel@tonic-gate return (0); 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate static rctl_ops_t project_tasks_ops = { 5237c478bd9Sstevel@tonic-gate rcop_no_action, 5247c478bd9Sstevel@tonic-gate project_ntasks_usage, 5257c478bd9Sstevel@tonic-gate project_ntasks_set, 5267c478bd9Sstevel@tonic-gate project_ntasks_test, 5277c478bd9Sstevel@tonic-gate }; 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate /* 5307c478bd9Sstevel@tonic-gate * project.max-shm-memory resource control support. 5317c478bd9Sstevel@tonic-gate */ 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5347c478bd9Sstevel@tonic-gate static int 5357c478bd9Sstevel@tonic-gate project_shmmax_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e, 5367c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags) 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate rctl_qty_t v; 5397c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 5407c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 5417c478bd9Sstevel@tonic-gate v = e->rcep_p.proj->kpj_data.kpd_shmmax + inc; 5427c478bd9Sstevel@tonic-gate if (v > rval->rcv_value) 5437c478bd9Sstevel@tonic-gate return (1); 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate return (0); 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate static rctl_ops_t project_shmmax_ops = { 5497c478bd9Sstevel@tonic-gate rcop_no_action, 5507c478bd9Sstevel@tonic-gate rcop_no_usage, 5517c478bd9Sstevel@tonic-gate rcop_no_set, 5527c478bd9Sstevel@tonic-gate project_shmmax_test 5537c478bd9Sstevel@tonic-gate }; 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /* 5567c478bd9Sstevel@tonic-gate * project.max-shm-ids resource control support. 5577c478bd9Sstevel@tonic-gate */ 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5607c478bd9Sstevel@tonic-gate static int 5617c478bd9Sstevel@tonic-gate project_shmmni_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e, 5627c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags) 5637c478bd9Sstevel@tonic-gate { 5647c478bd9Sstevel@tonic-gate rctl_qty_t v; 5657c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 5667c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 567824c205fSml93401 v = e->rcep_p.proj->kpj_data.kpd_ipc.ipcq_shmmni + inc; 5687c478bd9Sstevel@tonic-gate if (v > rval->rcv_value) 5697c478bd9Sstevel@tonic-gate return (1); 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate return (0); 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate static rctl_ops_t project_shmmni_ops = { 5757c478bd9Sstevel@tonic-gate rcop_no_action, 5767c478bd9Sstevel@tonic-gate rcop_no_usage, 5777c478bd9Sstevel@tonic-gate rcop_no_set, 5787c478bd9Sstevel@tonic-gate project_shmmni_test 5797c478bd9Sstevel@tonic-gate }; 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * project.max-sem-ids resource control support. 5837c478bd9Sstevel@tonic-gate */ 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5867c478bd9Sstevel@tonic-gate static int 5877c478bd9Sstevel@tonic-gate project_semmni_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e, 5887c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags) 5897c478bd9Sstevel@tonic-gate { 5907c478bd9Sstevel@tonic-gate rctl_qty_t v; 5917c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 5927c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 593824c205fSml93401 v = e->rcep_p.proj->kpj_data.kpd_ipc.ipcq_semmni + inc; 5947c478bd9Sstevel@tonic-gate if (v > rval->rcv_value) 5957c478bd9Sstevel@tonic-gate return (1); 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate return (0); 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate static rctl_ops_t project_semmni_ops = { 6017c478bd9Sstevel@tonic-gate rcop_no_action, 6027c478bd9Sstevel@tonic-gate rcop_no_usage, 6037c478bd9Sstevel@tonic-gate rcop_no_set, 6047c478bd9Sstevel@tonic-gate project_semmni_test 6057c478bd9Sstevel@tonic-gate }; 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate /* 6087c478bd9Sstevel@tonic-gate * project.max-msg-ids resource control support. 6097c478bd9Sstevel@tonic-gate */ 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6127c478bd9Sstevel@tonic-gate static int 6137c478bd9Sstevel@tonic-gate project_msgmni_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e, 6147c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags) 6157c478bd9Sstevel@tonic-gate { 6167c478bd9Sstevel@tonic-gate rctl_qty_t v; 6177c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 6187c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 619824c205fSml93401 v = e->rcep_p.proj->kpj_data.kpd_ipc.ipcq_msgmni + inc; 6207c478bd9Sstevel@tonic-gate if (v > rval->rcv_value) 6217c478bd9Sstevel@tonic-gate return (1); 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate return (0); 6247c478bd9Sstevel@tonic-gate } 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate static rctl_ops_t project_msgmni_ops = { 6277c478bd9Sstevel@tonic-gate rcop_no_action, 6287c478bd9Sstevel@tonic-gate rcop_no_usage, 6297c478bd9Sstevel@tonic-gate rcop_no_set, 6307c478bd9Sstevel@tonic-gate project_msgmni_test 6317c478bd9Sstevel@tonic-gate }; 6327c478bd9Sstevel@tonic-gate 633*c6939658Ssl108498 /*ARGSUSED*/ 634*c6939658Ssl108498 static rctl_qty_t 635*c6939658Ssl108498 project_locked_mem_usage(rctl_t *rctl, struct proc *p) 636*c6939658Ssl108498 { 637*c6939658Ssl108498 rctl_qty_t q; 638*c6939658Ssl108498 ASSERT(MUTEX_HELD(&p->p_lock)); 639*c6939658Ssl108498 mutex_enter(&p->p_zone->zone_rctl_lock); 640*c6939658Ssl108498 q = p->p_task->tk_proj->kpj_data.kpd_locked_mem; 641*c6939658Ssl108498 mutex_exit(&p->p_zone->zone_rctl_lock); 642*c6939658Ssl108498 return (q); 643*c6939658Ssl108498 } 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6467c478bd9Sstevel@tonic-gate static int 647*c6939658Ssl108498 project_locked_mem_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e, 6487c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags) 6497c478bd9Sstevel@tonic-gate { 650*c6939658Ssl108498 rctl_qty_t q; 6517c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 652*c6939658Ssl108498 ASSERT(MUTEX_HELD(&p->p_zone->zone_rctl_lock)); 653*c6939658Ssl108498 q = p->p_task->tk_proj->kpj_data.kpd_locked_mem; 654*c6939658Ssl108498 if (q + inc > rval->rcv_value) 6557c478bd9Sstevel@tonic-gate return (1); 6567c478bd9Sstevel@tonic-gate return (0); 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate 659*c6939658Ssl108498 /*ARGSUSED*/ 660*c6939658Ssl108498 static int 661*c6939658Ssl108498 project_locked_mem_set(rctl_t *rctl, struct proc *p, rctl_entity_p_t *e, 662*c6939658Ssl108498 rctl_qty_t nv) { 663*c6939658Ssl108498 664*c6939658Ssl108498 ASSERT(MUTEX_HELD(&p->p_lock)); 665*c6939658Ssl108498 ASSERT(e->rcep_t == RCENTITY_PROJECT); 666*c6939658Ssl108498 if (e->rcep_p.proj == NULL) 667*c6939658Ssl108498 return (0); 668*c6939658Ssl108498 669*c6939658Ssl108498 e->rcep_p.proj->kpj_data.kpd_locked_mem_ctl = nv; 670*c6939658Ssl108498 return (0); 671*c6939658Ssl108498 } 672*c6939658Ssl108498 673*c6939658Ssl108498 static rctl_ops_t project_locked_mem_ops = { 6747c478bd9Sstevel@tonic-gate rcop_no_action, 675*c6939658Ssl108498 project_locked_mem_usage, 676*c6939658Ssl108498 project_locked_mem_set, 677*c6939658Ssl108498 project_locked_mem_test 6787c478bd9Sstevel@tonic-gate }; 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate /* 6817c478bd9Sstevel@tonic-gate * project.max-contracts resource control support. 6827c478bd9Sstevel@tonic-gate */ 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6857c478bd9Sstevel@tonic-gate static int 6867c478bd9Sstevel@tonic-gate project_contract_test(struct rctl *rctl, struct proc *p, rctl_entity_p_t *e, 6877c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t inc, uint_t flags) 6887c478bd9Sstevel@tonic-gate { 6897c478bd9Sstevel@tonic-gate rctl_qty_t v; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 6927c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate v = e->rcep_p.proj->kpj_data.kpd_contract + inc; 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if ((p->p_task != NULL) && (p->p_task->tk_proj) != NULL && 6977c478bd9Sstevel@tonic-gate (v > rval->rcv_value)) 6987c478bd9Sstevel@tonic-gate return (1); 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate return (0); 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate static rctl_ops_t project_contract_ops = { 7047c478bd9Sstevel@tonic-gate rcop_no_action, 7057c478bd9Sstevel@tonic-gate rcop_no_usage, 7067c478bd9Sstevel@tonic-gate rcop_no_set, 7077c478bd9Sstevel@tonic-gate project_contract_test 7087c478bd9Sstevel@tonic-gate }; 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7117c478bd9Sstevel@tonic-gate static int 7127c478bd9Sstevel@tonic-gate project_crypto_test(rctl_t *r, proc_t *p, rctl_entity_p_t *e, 7137c478bd9Sstevel@tonic-gate rctl_val_t *rval, rctl_qty_t incr, uint_t flags) 7147c478bd9Sstevel@tonic-gate { 7157c478bd9Sstevel@tonic-gate rctl_qty_t v; 7167c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&p->p_lock)); 7177c478bd9Sstevel@tonic-gate ASSERT(e->rcep_t == RCENTITY_PROJECT); 7187c478bd9Sstevel@tonic-gate v = e->rcep_p.proj->kpj_data.kpd_crypto_mem + incr; 7197c478bd9Sstevel@tonic-gate if (v > rval->rcv_value) 7207c478bd9Sstevel@tonic-gate return (1); 7217c478bd9Sstevel@tonic-gate return (0); 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate static rctl_ops_t project_crypto_mem_ops = { 7257c478bd9Sstevel@tonic-gate rcop_no_action, 7267c478bd9Sstevel@tonic-gate rcop_no_usage, 7277c478bd9Sstevel@tonic-gate rcop_no_set, 7287c478bd9Sstevel@tonic-gate project_crypto_test 7297c478bd9Sstevel@tonic-gate }; 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* 7327c478bd9Sstevel@tonic-gate * void project_init(void) 7337c478bd9Sstevel@tonic-gate * 7347c478bd9Sstevel@tonic-gate * Overview 7357c478bd9Sstevel@tonic-gate * Initialize the project subsystem, including the primordial project 0 entry. 7367c478bd9Sstevel@tonic-gate * Register generic project resource controls, if any. 7377c478bd9Sstevel@tonic-gate * 7387c478bd9Sstevel@tonic-gate * Return values 7397c478bd9Sstevel@tonic-gate * None. 7407c478bd9Sstevel@tonic-gate * 7417c478bd9Sstevel@tonic-gate * Caller's context 7427c478bd9Sstevel@tonic-gate * Safe for KM_SLEEP allocations. 7437c478bd9Sstevel@tonic-gate */ 7447c478bd9Sstevel@tonic-gate void 7457c478bd9Sstevel@tonic-gate project_init(void) 7467c478bd9Sstevel@tonic-gate { 7477c478bd9Sstevel@tonic-gate rctl_qty_t shmmni, shmmax, qty; 7487c478bd9Sstevel@tonic-gate boolean_t check; 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate projects_hash = mod_hash_create_extended("projects_hash", 7517c478bd9Sstevel@tonic-gate project_hash_size, mod_hash_null_keydtor, project_hash_val_dtor, 7527c478bd9Sstevel@tonic-gate project_hash_by_id, 7537c478bd9Sstevel@tonic-gate (void *)(uintptr_t)mod_hash_iddata_gen(project_hash_size), 7547c478bd9Sstevel@tonic-gate project_hash_key_cmp, KM_SLEEP); 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate rc_project_cpu_shares = rctl_register("project.cpu-shares", 7577c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_SIGNAL_NEVER | 7587c478bd9Sstevel@tonic-gate RCTL_GLOBAL_DENY_NEVER | RCTL_GLOBAL_NOBASIC | 75919f92332Sml93401 RCTL_GLOBAL_COUNT | RCTL_GLOBAL_SYSLOG_NEVER, 76019f92332Sml93401 FSS_MAXSHARES, FSS_MAXSHARES, 7617c478bd9Sstevel@tonic-gate &project_cpu_shares_ops); 7627c478bd9Sstevel@tonic-gate rctl_add_default_limit("project.cpu-shares", 1, RCPRIV_PRIVILEGED, 7637c478bd9Sstevel@tonic-gate RCTL_LOCAL_NOACTION); 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate rc_project_nlwps = rctl_register("project.max-lwps", RCENTITY_PROJECT, 7667c478bd9Sstevel@tonic-gate RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_NOBASIC | RCTL_GLOBAL_COUNT, 7677c478bd9Sstevel@tonic-gate INT_MAX, INT_MAX, &project_lwps_ops); 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate rc_project_ntasks = rctl_register("project.max-tasks", RCENTITY_PROJECT, 7707c478bd9Sstevel@tonic-gate RCTL_GLOBAL_NOACTION | RCTL_GLOBAL_NOBASIC | RCTL_GLOBAL_COUNT, 7717c478bd9Sstevel@tonic-gate INT_MAX, INT_MAX, &project_tasks_ops); 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate /* 7747c478bd9Sstevel@tonic-gate * This rctl handle is used by /dev/crypto. It is here rather than 7757c478bd9Sstevel@tonic-gate * in misc/kcf or the drv/crypto module because resource controls 7767c478bd9Sstevel@tonic-gate * currently don't allow modules to be unloaded, and the control 7777c478bd9Sstevel@tonic-gate * must be registered before init starts. 7787c478bd9Sstevel@tonic-gate */ 7797c478bd9Sstevel@tonic-gate rc_project_crypto_mem = rctl_register("project.max-crypto-memory", 7807c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | 7817c478bd9Sstevel@tonic-gate RCTL_GLOBAL_BYTES, UINT64_MAX, UINT64_MAX, 7827c478bd9Sstevel@tonic-gate &project_crypto_mem_ops); 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate /* 7857c478bd9Sstevel@tonic-gate * Default to a quarter of the machine's memory 7867c478bd9Sstevel@tonic-gate */ 7877c478bd9Sstevel@tonic-gate qty = availrmem_initial << (PAGESHIFT - 2); 7887c478bd9Sstevel@tonic-gate rctl_add_default_limit("project.max-crypto-memory", qty, 7897c478bd9Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY); 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate /* 7927c478bd9Sstevel@tonic-gate * System V IPC resource controls 7937c478bd9Sstevel@tonic-gate */ 7947c478bd9Sstevel@tonic-gate rc_project_semmni = rctl_register("project.max-sem-ids", 7957c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | 7967c478bd9Sstevel@tonic-gate RCTL_GLOBAL_COUNT, IPC_IDS_MAX, IPC_IDS_MAX, &project_semmni_ops); 7977c478bd9Sstevel@tonic-gate rctl_add_legacy_limit("project.max-sem-ids", "semsys", 7987c478bd9Sstevel@tonic-gate "seminfo_semmni", 128, IPC_IDS_MAX); 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate rc_project_msgmni = rctl_register("project.max-msg-ids", 8017c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | 8027c478bd9Sstevel@tonic-gate RCTL_GLOBAL_COUNT, IPC_IDS_MAX, IPC_IDS_MAX, &project_msgmni_ops); 8037c478bd9Sstevel@tonic-gate rctl_add_legacy_limit("project.max-msg-ids", "msgsys", 8047c478bd9Sstevel@tonic-gate "msginfo_msgmni", 128, IPC_IDS_MAX); 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate rc_project_shmmni = rctl_register("project.max-shm-ids", 8077c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | 8087c478bd9Sstevel@tonic-gate RCTL_GLOBAL_COUNT, IPC_IDS_MAX, IPC_IDS_MAX, &project_shmmni_ops); 8097c478bd9Sstevel@tonic-gate rctl_add_legacy_limit("project.max-shm-ids", "shmsys", 8107c478bd9Sstevel@tonic-gate "shminfo_shmmni", 128, IPC_IDS_MAX); 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate rc_project_shmmax = rctl_register("project.max-shm-memory", 8137c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | 8147c478bd9Sstevel@tonic-gate RCTL_GLOBAL_BYTES, UINT64_MAX, UINT64_MAX, &project_shmmax_ops); 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate check = B_FALSE; 8177c478bd9Sstevel@tonic-gate if (!mod_sysvar("shmsys", "shminfo_shmmni", &shmmni)) 8187c478bd9Sstevel@tonic-gate shmmni = 100; 8197c478bd9Sstevel@tonic-gate else 8207c478bd9Sstevel@tonic-gate check = B_TRUE; 8217c478bd9Sstevel@tonic-gate if (!mod_sysvar("shmsys", "shminfo_shmmax", &shmmax)) 8227c478bd9Sstevel@tonic-gate shmmax = 0x800000; 8237c478bd9Sstevel@tonic-gate else 8247c478bd9Sstevel@tonic-gate check = B_TRUE; 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate /* 8277c478bd9Sstevel@tonic-gate * Default to a quarter of the machine's memory 8287c478bd9Sstevel@tonic-gate */ 8297c478bd9Sstevel@tonic-gate qty = availrmem_initial << (PAGESHIFT - 2); 8307c478bd9Sstevel@tonic-gate if (check) { 8317c478bd9Sstevel@tonic-gate if ((shmmax > 0) && (UINT64_MAX / shmmax <= shmmni)) 8327c478bd9Sstevel@tonic-gate qty = UINT64_MAX; 8337c478bd9Sstevel@tonic-gate else if (shmmni * shmmax > qty) 8347c478bd9Sstevel@tonic-gate qty = shmmni * shmmax; 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate rctl_add_default_limit("project.max-shm-memory", qty, 8377c478bd9Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY); 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate /* 8407c478bd9Sstevel@tonic-gate * Event Ports resource controls 8417c478bd9Sstevel@tonic-gate */ 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate rc_project_portids = rctl_register("project.max-port-ids", 8447c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | 8457c478bd9Sstevel@tonic-gate RCTL_GLOBAL_COUNT, PORT_MAX_PORTS, PORT_MAX_PORTS, 8467c478bd9Sstevel@tonic-gate &rctl_absolute_ops); 8477c478bd9Sstevel@tonic-gate rctl_add_default_limit("project.max-port-ids", PORT_DEFAULT_PORTS, 8487c478bd9Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY); 8497c478bd9Sstevel@tonic-gate 8507c478bd9Sstevel@tonic-gate /* 8517c478bd9Sstevel@tonic-gate * Resource control for locked memory 8527c478bd9Sstevel@tonic-gate */ 853*c6939658Ssl108498 rc_project_locked_mem = rctl_register( 854*c6939658Ssl108498 "project.max-locked-memory", RCENTITY_PROJECT, 8557c478bd9Sstevel@tonic-gate RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_NOBASIC | RCTL_GLOBAL_BYTES, 856*c6939658Ssl108498 UINT64_MAX, UINT64_MAX, &project_locked_mem_ops); 8577c478bd9Sstevel@tonic-gate 858*c6939658Ssl108498 /* Default value equals that of max-shm-memory. */ 859*c6939658Ssl108498 rctl_add_default_limit("project.max-locked-memory", qty, 8607c478bd9Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY); 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate /* 8637c478bd9Sstevel@tonic-gate * Per project limit on contracts. 8647c478bd9Sstevel@tonic-gate */ 8657c478bd9Sstevel@tonic-gate rc_project_contract = rctl_register("project.max-contracts", 8667c478bd9Sstevel@tonic-gate RCENTITY_PROJECT, RCTL_GLOBAL_DENY_ALWAYS | RCTL_GLOBAL_COUNT, 8677c478bd9Sstevel@tonic-gate INT_MAX, INT_MAX, &project_contract_ops); 8687c478bd9Sstevel@tonic-gate rctl_add_default_limit("project.max-contracts", 10000, 8697c478bd9Sstevel@tonic-gate RCPRIV_PRIVILEGED, RCTL_LOCAL_DENY); 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate t0.t_proj = proj0p = project_hold_by_id(0, GLOBAL_ZONEID, 8727c478bd9Sstevel@tonic-gate PROJECT_HOLD_INSERT); 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate mutex_enter(&p0.p_lock); 8757c478bd9Sstevel@tonic-gate proj0p->kpj_nlwps = p0.p_lwpcnt; 8767c478bd9Sstevel@tonic-gate mutex_exit(&p0.p_lock); 8777c478bd9Sstevel@tonic-gate proj0p->kpj_ntasks = 1; 8787c478bd9Sstevel@tonic-gate } 879