1ae115bc7Smrj /* 2ae115bc7Smrj * CDDL HEADER START 3ae115bc7Smrj * 4ae115bc7Smrj * 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. 7ae115bc7Smrj * 8ae115bc7Smrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9ae115bc7Smrj * or http://www.opensolaris.org/os/licensing. 10ae115bc7Smrj * See the License for the specific language governing permissions 11ae115bc7Smrj * and limitations under the License. 12ae115bc7Smrj * 13ae115bc7Smrj * When distributing Covered Code, include this CDDL HEADER in each 14ae115bc7Smrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15ae115bc7Smrj * If applicable, add the following below this CDDL HEADER, with the 16ae115bc7Smrj * fields enclosed by brackets "[]" replaced with your own identifying 17ae115bc7Smrj * information: Portions Copyright [yyyy] [name of copyright owner] 18ae115bc7Smrj * 19ae115bc7Smrj * CDDL HEADER END 20ae115bc7Smrj */ 21ae115bc7Smrj 22ae115bc7Smrj /* 23*6eaf49dbSStan Studzinski * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24ae115bc7Smrj * Use is subject to license terms. 25ae115bc7Smrj */ 26ae115bc7Smrj 27ae115bc7Smrj #include <sys/hold_page.h> 28ae115bc7Smrj 29843e1988Sjohnlev #if defined(__xpv) 30843e1988Sjohnlev #include <sys/hypervisor.h> 31843e1988Sjohnlev #endif 32843e1988Sjohnlev 33ae115bc7Smrj int 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 } 73ae115bc7Smrj 74ae115bc7Smrj void 75ae115bc7Smrj plat_release_page(page_t *pp) 76ae115bc7Smrj { 77843e1988Sjohnlev ASSERT((pp != NULL) && PAGE_LOCKED(pp)); 78843e1988Sjohnlev page_unlock(pp); 79ae115bc7Smrj } 80