xref: /onnv-gate/usr/src/uts/common/vm/hat.c (revision 0)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/param.h>
30*0Sstevel@tonic-gate #include <sys/kmem.h>
31*0Sstevel@tonic-gate #include <sys/sysmacros.h>
32*0Sstevel@tonic-gate #include <sys/cmn_err.h>
33*0Sstevel@tonic-gate #include <sys/systm.h>
34*0Sstevel@tonic-gate #include <sys/modctl.h>
35*0Sstevel@tonic-gate #include <sys/kobj.h>
36*0Sstevel@tonic-gate #include <vm/hat.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * PSARC 2004/405 made hat_getkpfnum(9F) obsolete. As part of the
40*0Sstevel@tonic-gate  * obsolecense, the original documented behavior will begin to be
41*0Sstevel@tonic-gate  * enforced in the future; namely, hat_getkpfnum(9F) may _only_
42*0Sstevel@tonic-gate  * be called with device-mapped memory virtual addresses. Since
43*0Sstevel@tonic-gate  * changing hat_getkpfnum(9F) to return PFN_INVALID on kernel memory
44*0Sstevel@tonic-gate  * would break a lot of modules without any warning, we've implemented
45*0Sstevel@tonic-gate  * the following mechanism as a stop-gap. In a future release, this
46*0Sstevel@tonic-gate  * can all be ripped out and hat_getkpfnum(9F) changed to return
47*0Sstevel@tonic-gate  * PFN_INVALID if it isn't called with a device-mapped memory address.
48*0Sstevel@tonic-gate  *
49*0Sstevel@tonic-gate  * We keep track of each module that has used hat_getkpfnum(9F)
50*0Sstevel@tonic-gate  * incorrectly. This allows us to avoid flooding the console/logs
51*0Sstevel@tonic-gate  * with too many warnings about a bad module that has already been
52*0Sstevel@tonic-gate  * flagged.
53*0Sstevel@tonic-gate  *
54*0Sstevel@tonic-gate  * On amd64 hat_getkpfnum() is never supported.
55*0Sstevel@tonic-gate  */
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #if !defined(__amd64)
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate #define	HAT_STACK_MAXDEPTH	15
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate struct badcall_node {
62*0Sstevel@tonic-gate 	char	*bc_modname;
63*0Sstevel@tonic-gate 	int	bc_stackdepth;
64*0Sstevel@tonic-gate 	pc_t	bc_callstack[HAT_STACK_MAXDEPTH];
65*0Sstevel@tonic-gate 	struct badcall_node *bc_linkage;
66*0Sstevel@tonic-gate };
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate static struct badcall_node *bad_getkpfnum_callers;
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate /*
71*0Sstevel@tonic-gate  * Common VM HAT routines.
72*0Sstevel@tonic-gate  */
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate static void
75*0Sstevel@tonic-gate printwarn(struct badcall_node *bc)
76*0Sstevel@tonic-gate {
77*0Sstevel@tonic-gate 	int sf;
78*0Sstevel@tonic-gate 	char *ksym;
79*0Sstevel@tonic-gate 	ulong_t off;
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 	cmn_err(CE_WARN, "Module %s is using the obsolete hat_getkpfnum(9F)",
82*0Sstevel@tonic-gate 	    bc->bc_modname);
83*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "interface in a way that will not be supported in\n");
84*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "a future release of Solaris. Please contact the\n");
85*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "vendor that supplied the module for assistance,\n");
86*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "or consult the Writing Device Drivers guide,\n");
87*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "available from http://www.sun.com for migration\n");
88*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "advice.\n");
89*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "---\n");
90*0Sstevel@tonic-gate 	cmn_err(CE_CONT, "Callstack of bad caller:\n");
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 	for (sf = 0; sf < bc->bc_stackdepth; sf++) {
93*0Sstevel@tonic-gate 		ksym = kobj_getsymname(bc->bc_callstack[sf], &off);
94*0Sstevel@tonic-gate 		cmn_err(CE_CONT, "\t%s+%lx\n", ksym? ksym : "?", off);
95*0Sstevel@tonic-gate 	}
96*0Sstevel@tonic-gate }
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate void
100*0Sstevel@tonic-gate hat_getkpfnum_badcall(void *caller)
101*0Sstevel@tonic-gate {
102*0Sstevel@tonic-gate 	struct badcall_node bcs;
103*0Sstevel@tonic-gate 	char *modname = mod_containing_pc((caddr_t)caller);
104*0Sstevel@tonic-gate 	struct badcall_node *bc;
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate #ifdef	__sparc
107*0Sstevel@tonic-gate 	/*
108*0Sstevel@tonic-gate 	 * This is a hack until the ifb and jfb framebuffer drivers
109*0Sstevel@tonic-gate 	 * are fixed. Right now they use hat_getkpfnum() in a way that
110*0Sstevel@tonic-gate 	 * is really safe but will be incorrectly flagged as being
111*0Sstevel@tonic-gate 	 * buggy.
112*0Sstevel@tonic-gate 	 */
113*0Sstevel@tonic-gate 	if (strcmp(modname, "ifb") == 0 || strcmp(modname, "jfb") == 0)
114*0Sstevel@tonic-gate 		return;
115*0Sstevel@tonic-gate #elif defined(__i386)
116*0Sstevel@tonic-gate 	/*
117*0Sstevel@tonic-gate 	 * This is a hack until these ethernet drivers can be fixed
118*0Sstevel@tonic-gate 	 * or EOL'd.  hat_getkpfnum() will continue to work correctly
119*0Sstevel@tonic-gate 	 * until this list can be removed.
120*0Sstevel@tonic-gate 	 */
121*0Sstevel@tonic-gate 	if (strcmp(modname, "dnet") == 0 || strcmp(modname, "pcn") == 0 ||
122*0Sstevel@tonic-gate 	    strcmp(modname, "adp") == 0 || strcmp(modname, "chs") == 0)
123*0Sstevel@tonic-gate 		return;
124*0Sstevel@tonic-gate #endif	/* __sparc / __i386 */
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	for (bc = bad_getkpfnum_callers; bc != NULL; bc = bc->bc_linkage)
127*0Sstevel@tonic-gate 		if (strcmp(bc->bc_modname, modname) == 0)
128*0Sstevel@tonic-gate 			return;
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate 	/*
131*0Sstevel@tonic-gate 	 * We haven't seen this caller before, so create a log of
132*0Sstevel@tonic-gate 	 * the callstack and module name, and emit a warning to the
133*0Sstevel@tonic-gate 	 * user.
134*0Sstevel@tonic-gate 	 */
135*0Sstevel@tonic-gate 	bc = kmem_zalloc(sizeof (struct badcall_node), KM_NOSLEEP);
136*0Sstevel@tonic-gate 	if (bc != NULL) {
137*0Sstevel@tonic-gate 		bc->bc_linkage = bad_getkpfnum_callers;
138*0Sstevel@tonic-gate 		bc->bc_modname = modname;
139*0Sstevel@tonic-gate 		bad_getkpfnum_callers = bc;
140*0Sstevel@tonic-gate 	} else {
141*0Sstevel@tonic-gate 		bc = &bcs;
142*0Sstevel@tonic-gate 		bc->bc_modname = modname;
143*0Sstevel@tonic-gate 	}
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate 	bc->bc_stackdepth = getpcstack(bc->bc_callstack, HAT_STACK_MAXDEPTH);
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 	printwarn(bc);
148*0Sstevel@tonic-gate }
149*0Sstevel@tonic-gate #endif /* __amd64 */
150