xref: /illumos-gate/usr/src/uts/i86pc/os/hold_page.c (revision 6eaf49db)
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
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * 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  */
21ae115bc7Smrj 
227c478bd9Sstevel@tonic-gate /*
23*6eaf49dbSStan Studzinski  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27ae115bc7Smrj #include <sys/hold_page.h>
287c478bd9Sstevel@tonic-gate 
29843e1988Sjohnlev #if defined(__xpv)
30843e1988Sjohnlev #include <sys/hypervisor.h>
31843e1988Sjohnlev #endif
32843e1988Sjohnlev 
33ae115bc7Smrj int
plat_hold_page(pfn_t pfn,int lock,page_t ** pp_ret)34ae115bc7Smrj plat_hold_page(pfn_t pfn, int lock, page_t **pp_ret)
35ae115bc7Smrj {
36843e1988Sjohnlev 	page_t *pp = page_numtopp_nolock(pfn);
37843e1988Sjohnlev 
38843e1988Sjohnlev 	if (pp == NULL)
39843e1988Sjohnlev 		return (PLAT_HOLD_FAIL);
40843e1988Sjohnlev 
41*6eaf49dbSStan Studzinski #if !defined(__xpv)
42*6eaf49dbSStan Studzinski 	/*
43*6eaf49dbSStan Studzinski 	 * Pages are locked SE_SHARED because some hypervisors
44*6eaf49dbSStan Studzinski 	 * like xVM ESX reclaim Guest OS memory by locking
45*6eaf49dbSStan Studzinski 	 * it SE_EXCL so we want to leave these pages alone.
46*6eaf49dbSStan Studzinski 	 */
47*6eaf49dbSStan Studzinski 	if (lock == PLAT_HOLD_LOCK) {
48*6eaf49dbSStan Studzinski 		ASSERT(pp_ret != NULL);
49*6eaf49dbSStan Studzinski 		if (page_trylock(pp, SE_SHARED) == 0)
50*6eaf49dbSStan Studzinski 			return (PLAT_HOLD_FAIL);
51*6eaf49dbSStan Studzinski 	}
52*6eaf49dbSStan Studzinski #else	/* __xpv */
53843e1988Sjohnlev 	if (lock == PLAT_HOLD_LOCK) {
54843e1988Sjohnlev 		ASSERT(pp_ret != NULL);
55843e1988Sjohnlev 		if (page_trylock(pp, SE_EXCL) == 0)
56843e1988Sjohnlev 			return (PLAT_HOLD_FAIL);
57843e1988Sjohnlev 	}
58843e1988Sjohnlev 
59843e1988Sjohnlev 	if (mfn_list[pfn] == MFN_INVALID) {
60843e1988Sjohnlev 		/* We failed - release the lock if we grabbed it earlier */
61843e1988Sjohnlev 		if (lock == PLAT_HOLD_LOCK) {
62843e1988Sjohnlev 			page_unlock(pp);
63843e1988Sjohnlev 		}
64843e1988Sjohnlev 		return (PLAT_HOLD_FAIL);
65843e1988Sjohnlev 	}
66*6eaf49dbSStan Studzinski #endif	/* __xpv */
67*6eaf49dbSStan Studzinski 
68843e1988Sjohnlev 	if (lock == PLAT_HOLD_LOCK)
69843e1988Sjohnlev 		*pp_ret = pp;
70843e1988Sjohnlev 
71ae115bc7Smrj 	return (PLAT_HOLD_OK);
72ae115bc7Smrj }
737c478bd9Sstevel@tonic-gate 
74ae115bc7Smrj void
plat_release_page(page_t * pp)75ae115bc7Smrj plat_release_page(page_t *pp)
76ae115bc7Smrj {
77843e1988Sjohnlev 	ASSERT((pp != NULL) && PAGE_LOCKED(pp));
78843e1988Sjohnlev 	page_unlock(pp);
79ae115bc7Smrj }
80