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