xref: /titanic_50/usr/src/uts/common/vm/seg_vn.h (revision d51e90740114c60620c0febffd4d3ce6e280a107)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * University Copyright- Copyright (c) 1982, 1986, 1988
31  * The Regents of the University of California
32  * All Rights Reserved
33  *
34  * University Acknowledgment- Portions of this document are derived from
35  * software developed by the University of California, Berkeley, and its
36  * contributors.
37  */
38 
39 #ifndef	_VM_SEG_VN_H
40 #define	_VM_SEG_VN_H
41 
42 #pragma ident	"%Z%%M%	%I%	%E% SMI"
43 
44 #include <sys/lgrp.h>
45 #include <vm/anon.h>
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * A pointer to this structure is passed to segvn_create().
53  */
54 typedef struct segvn_crargs {
55 	struct	vnode *vp;	/* vnode mapped from */
56 	struct	cred *cred;	/* credentials */
57 	u_offset_t	offset; /* starting offset of vnode for mapping */
58 	uchar_t	type;		/* type of sharing done */
59 	uchar_t	prot;		/* protections */
60 	uchar_t	maxprot;	/* maximum protections */
61 	uint_t	flags;		/* flags */
62 	struct	anon_map *amp;	/* anon mapping to map to */
63 	uint_t	szc;		/* max preferred page size code */
64 	uint_t	lgrp_mem_policy_flags;
65 } segvn_crargs_t;
66 
67 /*
68  * (Semi) private data maintained by the seg_vn driver per segment mapping.
69  *
70  * The read/write segment lock protects all of segvn_data including the
71  * vpage array.  All fields in segvn_data are treated as read-only when
72  * the "read" version of the address space and the segment locks are held.
73  * The "write" version of the segment lock, however, is required in order to
74  * update the following fields:
75  *
76  *	pageprot
77  *	prot
78  *	amp
79  *	vpage
80  *
81  * 	softlockcnt
82  * is written by acquiring either the readers lock on the segment and
83  * freemem lock, or any lock combination which guarantees exclusive use
84  * of this segment (e.g., adress space writers lock,
85  * address space readers lock + segment writers lock).
86  */
87 typedef struct	segvn_data {
88 	krwlock_t lock;		/* protect segvn_data and vpage array */
89 	kmutex_t segp_slock;	/* serialize insertions into seg_pcache */
90 	uchar_t	pageprot;	/* true if per page protections present */
91 	uchar_t	prot;		/* current segment prot if pageprot == 0 */
92 	uchar_t	maxprot;	/* maximum segment protections */
93 	uchar_t	type;		/* type of sharing done */
94 	u_offset_t offset;	/* starting offset of vnode for mapping */
95 	struct	vnode *vp;	/* vnode that segment mapping is to */
96 	ulong_t	anon_index;	/* starting index into anon_map anon array */
97 	struct	anon_map *amp;	/* pointer to anon share structure, if needed */
98 	struct	vpage *vpage;	/* per-page information, if needed */
99 	struct	cred *cred;	/* mapping credentials */
100 	size_t	swresv;		/* swap space reserved for this segment */
101 	uchar_t	advice;		/* madvise flags for segment */
102 	uchar_t	pageadvice;	/* true if per page advice set */
103 	ushort_t flags;		/* flags - from sys/mman.h */
104 	ssize_t	softlockcnt;	/* # of pages SOFTLOCKED in seg */
105 	lgrp_mem_policy_info_t policy_info; /* memory allocation policy */
106 } segvn_data_t;
107 
108 #ifdef _KERNEL
109 
110 /*
111  * Macros for segvn segment driver locking.
112  */
113 #define	SEGVN_LOCK_ENTER(as, lock, type)	rw_enter((lock), (type))
114 #define	SEGVN_LOCK_EXIT(as, lock)		rw_exit((lock))
115 #define	SEGVN_LOCK_DOWNGRADE(as, lock)		rw_downgrade((lock))
116 
117 /*
118  * Macros to test lock states.
119  */
120 #define	SEGVN_LOCK_HELD(as, lock)		RW_LOCK_HELD((lock))
121 #define	SEGVN_READ_HELD(as, lock)		RW_READ_HELD((lock))
122 #define	SEGVN_WRITE_HELD(as, lock)		RW_WRITE_HELD((lock))
123 
124 /*
125  * Macro used to detect the need to Break the sharing of COW pages
126  *
127  * The rw == S_WRITE is for the COW case
128  * rw == S_READ and type == SOFTLOCK is for the physio case
129  * We don't want to share a softlocked page because it can cause problems
130  * with multithreaded apps but if rw == S_READ_NOCOW it's ok to not break
131  * sharing of COW pages even in SOFTLOCK case.
132  */
133 #define	BREAK_COW_SHARE(rw, type, seg_type) ((rw == S_WRITE || \
134 	(type == F_SOFTLOCK && rw != S_READ_NOCOW)) && \
135 	seg_type == MAP_PRIVATE)
136 
137 #define	SEGVN_ZFOD_ARGS(prot, max)	\
138 	{ NULL, NULL, 0, MAP_PRIVATE, prot, max, 0, NULL, 0, 0 }
139 
140 #define	AS_MAP_CHECK_VNODE_LPOOB(crfp, argsp)				\
141 	((crfp) == (int (*)())segvn_create &&				\
142 	(((struct segvn_crargs *)(argsp))->flags &			\
143 	    (MAP_TEXT | MAP_INITDATA)) &&				\
144 	((struct segvn_crargs *)(argsp))->szc == 0 &&			\
145 	((struct segvn_crargs *)(argsp))->vp != NULL)
146 
147 #define	AS_MAP_CHECK_ANON_LPOOB(crfp, argsp)				\
148 	((crfp) == (int (*)())segvn_create &&				\
149 	(((struct segvn_crargs *)(argsp))->szc == 0 ||			\
150 	((struct segvn_crargs *)(argsp))->szc == AS_MAP_HEAP ||		\
151 	((struct segvn_crargs *)(argsp))->szc == AS_MAP_STACK) &&	\
152 	((struct segvn_crargs *)(argsp))->vp == NULL)
153 
154 extern void	segvn_init(void);
155 extern int	segvn_create(struct seg *, void *);
156 
157 extern	struct seg_ops segvn_ops;
158 
159 /*
160  * Provided as shorthand for creating user zfod segments.
161  */
162 extern	caddr_t zfod_argsp;
163 extern	caddr_t kzfod_argsp;
164 extern	caddr_t stack_exec_argsp;
165 extern	caddr_t stack_noexec_argsp;
166 
167 #endif	/* _KERNEL */
168 
169 #ifdef	__cplusplus
170 }
171 #endif
172 
173 #endif	/* _VM_SEG_VN_H */
174