cpr_impl.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Platform specific implementation code
*/
#define SUNDDI_IMPL
#include <sys/prom_isa.h>
#include <sys/prom_plat.h>
#include <vm/hat_sfmmu.h>
#include <vm/seg_kmem.h>
#include <sys/cpu_module.h>
#include <sys/machsystm.h>
#include <sys/archsystm.h>
#include <sys/bootconf.h>
extern void cpr_clear_bitmaps(void);
static void i_cpr_xcall(xcfunc_t);
void i_cpr_storage_free(void);
extern void *i_cpr_data_page;
extern int cpr_test_mode;
extern int cpr_nbitmaps;
extern char cpr_default_path[];
static uint_t sensitive_pages_saved;
static uint_t sensitive_size_saved;
#define MAX_STORAGE_RETRY 3
#define MAX_STORAGE_ALLOC_RETRY 3
#define EXTRA_DESCS 10
#define CPR_NO_STORAGE_DESC 1
#define CPR_NO_STORAGE_DATA 2
#define CIF_SPLICE 0
#define CIF_UNLINK 1
/*
* CPR miscellaneous support routines
*/
/*
*/
static void *ppage_buf;
static pgcnt_t ppage_count;
static pfn_t *pphys_list;
static size_t pphys_list_size;
/*
* private struct for tlb handling
*/
struct cpr_trans_info {
int index;
};
typedef struct cpr_trans_info cti_t;
/*
* special handling for tlb info
*/
#define WITHIN_OFW(va) \
#define IS_BIGKTSB(va) \
(enable_bigktsb && \
/*
* WARNING:
* the text from this file is linked to follow cpr_resume_setup.o;
* only add text between here and i_cpr_end_jumpback when it needs
* to be called during resume before we switch back to the kernel
* trap table. all the text in this range must fit within a page.
*/
/*
* each time a machine is reset, the prom uses an inconsistent set of phys
* pages and the cif cookie may differ as well. so prior to restoring the
* when requesting prom services.
*
* cif_handler starts out as the original prom cookie, and that gets used
* by client_handler() to jump into the prom. here we splice-in a wrapper
* routine by writing cif_handler; client_handler() will now jump to the
* jumps to the new cookie.
*/
void
i_cpr_cif_setup(int action)
{
extern void *i_cpr_orig_cif, *cif_handler;
extern int i_cpr_cif_wrapper(void *);
/*
* save the original cookie and change the current cookie to the
* wrapper routine. later we just restore the original cookie.
*/
if (action == CIF_SPLICE) {
cif_handler = (void *)i_cpr_cif_wrapper;
} else if (action == CIF_UNLINK)
}
/*
* launch slave cpus into kernel text, pause them,
* and restore the original prom pages
*/
void
i_cpr_mp_setup(void)
{
extern void restart_other_cpu(int);
char *str;
/*
* reset cpu_ready_set so x_calls work properly
*/
/*
* and setup tmp handling for calling prom services.
*/
/*
* at this point, only the nucleus and a few cpr pages are
* mapped in. once we switch to the kernel trap table,
* we can access the rest of kernel space.
*/
if (ncpus > 1) {
0, 0, 0, 0);
str = "MP startup...\r\n";
}
/*
* All of the slave cpus are not ready at this time,
* yet the cpu structures have various cpu_flags set;
* clear cpu_flags and mutex_ready.
* Since we are coming up from a CPU suspend, the slave cpus
* are frozen.
*/
}
str = "MP paused...\r\n";
}
} else
i_cpr_clear_entries(0, 0);
/*
* now unlink the cif wrapper; WARNING: do not call any
* prom_xxx() routines until after prom pages are restored.
*/
(void) i_cpr_prom_pages(CPR_PROM_RESTORE);
}
/*
* end marker for jumpback page;
* this symbol is used to check the size of i_cpr_resume_setup()
* and the above text. For simplicity, the Makefile needs to
* link i_cpr_resume_setup.o and cpr_impl.o consecutively.
*/
void
i_cpr_end_jumpback(void)
{
}
/*
* scan tlb entries with reader; when valid entries are found,
*/
static void
{
int tlb_index;
}
}
/*
* and any bigktsb's; these will be reinstalled by cprboot on all cpus
*/
/* ARGSUSED */
static void
{
/*
* record tlb data at ctip->dst; the target tlb index starts
* at the highest tlb offset and moves towards 0. the prom
* reserves both dtlb and itlb index 0. any selected entry
* also gets marked to prevent being flushed during resume
*/
}
}
/*
* some tlb entries are stale, filter for unlocked entries
* within the prom virt range and clear them
*/
static void
{
}
}
/*
* some of the entries installed by cprboot are needed only on a
* short-term basis and need to be flushed to avoid clogging the tlbs.
*/
static void
{
}
}
/* ARGSUSED */
static void
{
extern void demap_all(void);
/*
* for newer cpus that implement DEMAP_ALL_TYPE, demap_all is
* a second label for vtag_flushall. the call is made using
* vtag_flushall() instead of demap_all() due to runtime and
* krtld results with both older and newer cpu modules.
*/
if (&demap_all != 0) {
return;
}
/*
* for older V9 cpus, scan tlbs and clear stale entries
*/
}
/*
* craft tlb info for tmp use during resume; this data gets used by
* cprboot to install tlb entries. we also mark each struct as tmp
* so those tlb entries will get flushed after switching to the kernel
* trap table. no data needs to be recorded for vaddr when it falls
* within the nucleus since we've already recorded nucleus ttes and
* a 8K tte would conflict with a 4MB tte. eg: the cpr module
*/
static void
{
return;
/*
* without any global service available to lookup
* a tte by vaddr, we craft our own here:
*/
}
static void
{
reset_pil = 0;
else {
reset_pil = 1;
}
if (reset_pil)
}
/*
* restart paused slave cpus
*/
void
i_cpr_machdep_setup(void)
{
if (ncpus > 1) {
start_cpus();
}
}
/*
* Stop all interrupt activities in the system
*/
void
i_cpr_stop_intr(void)
{
(void) spl7();
}
/*
* Set machine up to take interrupts
*/
void
i_cpr_enable_intr(void)
{
(void) spl0();
}
/*
* record cpu nodes and ids
*/
static void
i_cpr_save_cpu_info(void)
{
struct sun4u_cpu_info *scip;
do {
scip++;
}
/*
* Write necessary machine dependent information to cpr state file,
* eg. sun4u mmu ctx secondary for the current running process (cpr) ...
*/
int
{
extern uint_t i_cpr_tstack_size;
const char ustr[] = ": unix-tte 2drop false ;";
char *fmt;
int rc;
/*
* ustr[] is used as temporary forth words during
* slave startup sequence, see sfmmu_mp_startup()
*/
return (rc);
}
/*
* m_info is now cleared in i_cpr_dump_setup()
*/
/*
* Set secondary context to INVALID_CONTEXT to force the HAT
* to re-setup the MMU registers and locked TTEs it needs for
* TLB miss handling.
*/
/*
* i_cpr_data_page is comprised of a 4K stack area and a few
* trailing data symbols; the page is shared by the prom and
* kernel during resume. the stack size is recorded here
* and used by cprboot to set %sp
*/
return (rc);
}
fmt = "error writing %s forth info";
return (rc);
}
/*
* Save miscellaneous information which needs to be written to the
* state file. This information is required to re-initialize
*/
void
i_cpr_save_machdep_info(void)
{
/*
* Verify the jumpback code all falls in one page.
*/
}
void
i_cpr_set_tbr(void)
{
}
/*
* cpu0 should contain bootcpu info
*/
cpu_t *
i_cpr_bootcpu(void)
{
return (&cpu0);
}
/*
* Return the virtual address of the mapping area
*/
i_cpr_map_setup(void)
{
/*
* Allocate a virtual memory range spanned by an hmeblk.
* This would be 8 hments or 64k bytes. Starting VA
* must be 64k (8-page) aligned.
*/
return (cpr_vaddr);
}
/*
* create tmp locked tlb entries for a group of phys pages;
*
* i_cpr_mapin/i_cpr_mapout should always be called in pairs,
* otherwise would fill up a tlb with locked entries
*/
void
{
extern pfn_t curthreadpfn;
extern int curthreadremapped;
}
}
void
{
extern int curthreadremapped;
curthreadremapped = 0;
}
/*
* We're done using the mapping area; release virtual space
*/
void
i_cpr_map_destroy(void)
{
}
/* ARGSUSED */
void
i_cpr_handle_xc(int flag)
{
}
/*
* This function takes care of pages which are not in kas or need to be
* taken care of in a special way. For example, panicbuf pages are not
* in kas and their pages are allocated via prom_retain().
*/
{
/*
* Save information about prom retained panicbuf pages
*/
if (bitfunc == cpr_setbit) {
}
/*
* Go through the prom_retain array to tag those pages.
*/
if (pf_is_memory(pfn)) {
if (bitfunc == cpr_setbit) {
total++;
} else
total++;
}
}
}
return (total);
}
/*
* Free up memory-related resources here. We start by freeing buffers
* allocated during suspend initialization. Also, free up the mapping
* resources allocated in cpr_init().
*/
void
{
(void) i_cpr_prom_pages(CPR_PROM_FREE);
}
/*
* Derived from cpr_write_statefile().
* Save the sensitive pages to the storage area and do bookkeeping
* using the sensitive descriptors. Each descriptor will contain no more
* than CPR_MAXCONTIG amount of contiguous pages to match the max amount
* of pages that statefile gets written to disk at each write.
* XXX The CPR_MAXCONTIG can be changed to the size of the compression
* scratch area.
*/
static int
i_cpr_save_to_storage(void)
{
sensitive_size_saved = 0;
}
/*
* This routine allocates space to save the sensitive kernel pages,
* i.e. kernel data nucleus, kvalloc and kvseg segments.
* It's assumed that those segments are the only areas that can be
* contaminated by memory allocations during statefile dumping.
* The space allocated here contains:
* A list of descriptors describing the saved sensitive pages.
* The storage area for saving the compressed sensitive kernel pages.
* Since storage pages are allocated from segkmem, they need to be
* excluded when saving.
*/
int
{
static const char pages_fmt[] = "\n%s %s allocs\n"
" spages %ld, vpages %ld, diff %ld\n";
int retry_cnt;
int error = 0;
char *str;
/*
* Tag sensitive kpages. Allocate space for storage descriptors
* and storage data area based on the resulting bitmaps.
* Note: The storage space will be part of the sensitive
* segment, so we need to tag kpages here before the storage
* is actually allocated just so their space won't be accounted
* for. They will not be part of the statefile although those
* pages will be claimed by cprboot.
*/
str = "i_cpr_save_sensitive_kpages:";
/*
* Allocate space to save the clean sensitive kpages
*/
/*
* Alloc on first pass or realloc if we are retrying because
* of insufficient storage for sensitive pages
*/
if (i_cpr_storage_data_base) {
}
"\n%s can't allocate data storage space!\n",
str));
return (ENOMEM);
}
}
/*
* Allocate on first pass, only realloc if retry is because of
* insufficient descriptors, but reset contents on each pass
* (desc_alloc resets contents as well)
*/
if (error != 0)
return (error);
} else {
}
/*
* We are ready to save the sensitive kpages to storage.
* We cannot trust what's tagged in the bitmaps anymore
* after storage allocations. Clear up the bitmaps and
* retag the sensitive kpages again. The storage pages
* should be untagged.
*/
spages =
/*
* Returns 0 on success, -1 if too few descriptors, and
* ENOMEM if not enough space to save sensitive pages
*/
if (error == 0) {
/* Saving to storage succeeded */
break;
} else if (error == -1)
}
if (error == -1)
return (error);
}
/*
* Estimate how much memory we will need to save
* the sensitive pages with compression.
*/
static caddr_t
{
char *str;
str = "i_cpr_storage_data_alloc:";
if (retry_cnt == 0) {
/*
* common compression ratio is about 3:1
* initial storage allocation is estimated at 40%
* to cover the majority of cases
*/
} else {
/*
* calculate the prior compression percentage (x100)
* from the last attempt to save sensitive pages
*/
ASSERT(sensitive_pages_saved != 0);
/*
* new estimated storage size is based on
* the larger ratio + 5% for each retry:
* pages * (last + [5%, 10%])
*/
(retry_cnt * 5);
}
return (addr);
}
void
i_cpr_storage_free(void)
{
/* Free descriptors */
if (i_cpr_storage_desc_base) {
}
/* Data storage */
if (i_cpr_storage_data_base) {
}
}
/*
* This routine is derived from cpr_compress_and_write().
* 1. Do bookkeeping in the descriptor for the contiguous sensitive chunk.
* 2. Compress and save the clean sensitive pages into the storage area.
*/
int
{
extern caddr_t i_cpr_storage_data_end;
char *datap;
int error;
/*
* Fill next empty storage descriptor
*/
if (descp >= i_cpr_storage_desc_end) {
return (-1);
}
/*
* try compressing pages and copy cpd fields
* pfn is copied for debug use
*/
#ifdef DEBUG
#endif
error = 0;
/*
* Save the raw or compressed data to the storage area pointed to by
* sensitive_write_ptr. Make sure the storage space is big enough to
* hold the result. Otherwise roll back to increase the storage space.
*/
} else {
"space is too small!\ngot %d, want %d\n\n",
#ifdef DEBUG
/*
* Check to see if the content of the sensitive pages that we
* just copied have changed during this small time window.
*/
"Data in the range of pfn 0x%x to pfn "
"0x%x has changed after they are saved "
}
#endif
}
return (error);
}
/*
* This routine is derived from cpr_count_kpages().
* It goes through kernel data nucleus and segkmem segments to select
* pages in use and mark them in the corresponding bitmap.
*/
{
/*
* Kernel data nucleus pages
*/
/*
* kvseg and kvalloc pages
*/
/* segment to support kernel memory usage above 32-bit space (4GB) */
"\tkdata_cnt %ld + segkmem_cnt %ld = %ld pages\n",
return (kdata_cnt + segkmem_cnt);
}
{
if (i_cpr_storage_desc_base) {
}
if (i_cpr_storage_data_base) {
}
return (count);
}
/*
* Derived from cpr_write_statefile().
* Allocate (or reallocate after exhausting the supply) descriptors for each
* chunk of contiguous sensitive kpages.
*/
static int
int retry)
{
int chunks;
char *str = "i_cpr_storage_desc_alloc:";
/*
* On initial allocation, add some extra to cover overhead caused
* by the allocation for the storage area later.
*/
if (retry == 0) {
} else {
}
/* Free old descriptors, if any */
if (*basepp)
return (ENOMEM);
}
return (0);
}
static void
{
/* Initialize the descriptors to something impossible. */
#ifdef DEBUG
/*
* This condition is tested by an ASSERT
*/
#endif
}
int
{
int error = 0;
/*
* These following two variables need to be reinitialized
* for each cpr cycle.
*/
if (i_cpr_storage_desc_base) {
for (descp = i_cpr_storage_desc_base;
return (error);
spin_cnt++;
}
prom_printf(" \b");
}
return (0);
}
/*
* 1. Fill the cpr page descriptor with the info of the dirty pages
* and
* write the descriptor out. It will be used at resume.
* 2. Write the clean data in stead of the dirty data out.
* Note: to save space, the clean data is already compressed.
*/
static int
{
int error = 0;
int clean_compressed;
extern uchar_t cpr_pagecopy[];
/* Fill cpr page descriptor. */
#ifdef DEBUG
#endif
/*
* The sensitive kpages are usually saved with compression
* unless compression could not reduce the size of the data.
* If user choose not to have the statefile compressed,
* we need to decompress the data back before dumping it to disk.
*/
if (clean_compressed)
} else {
if (clean_compressed) {
} else {
}
}
/* Write cpr page descriptor */
if (error) {
#ifdef DEBUG
debug_enter("cpr_dump_sensitive: cpr_write() page "
"descriptor failed!\n");
#endif
return (error);
}
i_cpr_sensitive_bytes_dumped += sizeof (cpd_t);
/* Write page data */
if (error) {
cpd.cpd_length));
#ifdef DEBUG
debug_enter("cpr_dump_sensitive: cpr_write() data failed!\n");
#endif
return (error);
}
return (error);
}
/*
* Sanity check to make sure that we have dumped right amount
* of pages from different sources to statefile.
*/
int
{
if (pgs_expected == total_pgs_dumped)
return (0);
return (EINVAL);
}
int
i_cpr_reusefini(void)
{
char *bufp;
int rc;
if (cpr_reusable_mode)
cpr_reusable_mode = 0;
"(uadmin %d %d)\nmust be done with / mounted "
}
return (rc);
}
if (rc) {
"prom values for %s", cpr_default_path,
} else {
/*
* clean up prom properties
*/
if (rc == 0) {
/*
* invalidate the disk copy and turn off reusable
*/
}
}
}
return (rc);
}
int
i_cpr_reuseinit(void)
{
int rc = 0;
return (rc);
/*
* We need to validate default file
*/
if (rc == 0)
cpr_reusable_mode = 1;
"while / is mounted writeable");
}
(void) cpr_default_setup(0);
return (rc);
}
int
i_cpr_check_cprinfo(void)
{
int rc = 0;
"exist. You must run 'uadmin %d %d' "
"command while / is mounted writeable,\n"
"then reboot and run 'uadmin %d %d' "
"to create a reusable statefile",
return (rc);
}
if (rc) {
"You must run 'uadmin %d %d' while / is mounted "
"writeable, then reboot and run 'uadmin %d %d' "
"to create a reusable statefile\n",
}
return (rc);
}
int
i_cpr_reusable_supported(void)
{
return (1);
}
/*
* find prom phys pages and alloc space for a tmp copy
*/
static int
i_cpr_find_ppages(void)
{
extern struct vnode prom_ppages;
int mapflag;
/*
* there should be a page_t for each phys page used by the kernel;
* set a bit for each phys page not tracked by a page_t
*/
pcnt = 0;
if (page_numtopp_nolock(ppn))
continue;
pcnt++;
}
}
/*
* clear bits for phys pages in each segment
*/
/*
* set bits for phys pages referenced by the prom_ppages vnode;
* these pages are mostly comprised of forthdebug words
*/
vcnt = 0;
vcnt++;
break;
}
/*
* total number of prom pages are:
* (non-page_t pages - seg pages + vnode pages)
*/
/*
* alloc array of pfn_t to store phys page list
*/
if (pphys_list == NULL) {
return (ENOMEM);
}
/*
* phys pages referenced in the bitmap should be
* those used by the prom; scan bitmap and save
* a list of prom phys page numbers
*/
dst = pphys_list;
}
}
}
/*
* allocate space to store prom pages
*/
pphys_list = NULL;
return (ENOMEM);
}
return (0);
}
/*
* save prom pages to kmem pages
*/
static void
i_cpr_save_ppages(void)
{
/*
* map in each prom page and copy to a kmem page
*/
dst += MMU_PAGESIZE;
}
}
/*
* restore prom pages from kmem pages
*/
static void
i_cpr_restore_ppages(void)
{
/*
* map in each prom page and copy from a kmem page
*/
src += MMU_PAGESIZE;
}
}
/*
*/
int
i_cpr_prom_pages(int action)
{
int error;
if (action == CPR_PROM_SAVE) {
if (error = i_cpr_find_ppages())
return (error);
}
} else if (action == CPR_PROM_RESTORE) {
} else if (action == CPR_PROM_FREE) {
if (pphys_list) {
pphys_list = NULL;
pphys_list_size = 0;
}
if (ppage_buf) {
ppage_count = 0;
}
}
return (0);
}
/*
* record tlb data for the nucleus, bigktsb's, and the cpr module;
* when we jump into the cpr module during the resume phase, those
* mappings are needed until switching to the kernel trap table.
* the info recorded prior to saving sensitive pages, otherwise
* all the data would appear as NULLs.
*/
static void
i_cpr_save_tlbinfo(void)
{
/*
* during resume - shortly after jumping into the cpr module,
* sfmmu_load_mmustate() will overwrite any dtlb entry at any
* index used for TSBs; skip is set so that any saved tte will
* target other tlb offsets and prevent being lost during
* resume. now scan the dtlb and save locked entries,
* then add entries for the tmp stack / data page and the
* cpr thread structure.
*/
/*
* scan itlb and save locked entries; add an entry for
* the first text page of the cpr module; cprboot will
* jump to that page after restoring kernel pages.
*/
}
/* ARGSUSED */
int
{
/*
*/
return (0);
}
int
i_cpr_is_supported(void)
{
char es_prop[] = "energystar-v2";
int last;
extern int cpr_supported_override;
extern int cpr_platform_enable;
/*
* The next statement tests if a specific platform has turned off
* cpr support.
*/
return (0);
/*
* Do not inspect energystar-v* property if a platform has
* specifically turned on cpr support
*/
if (cpr_platform_enable)
return (1);
node = prom_rootnode();
return (1);
}
/*
* the actual size of the statefile data isn't known until after all the
* compressed pages are written; even the inode size doesn't reflect the
* data size since there are usually many extra fs blocks. for recording
* the actual data size, the first sector of the statefile is copied to
* a tmp buf, and the copy is later updated and flushed to disk.
*/
int
{
extern int cpr_flush_write(vnode_t *);
static char cpr_sector[DEV_BSIZE];
/*
* this routine is called after cdd_t and csu_md_t are copied
* a dependency on the combined struct size being >= one sector
* or DEV_BSIZE; since introduction in Sol2.7, csu_md_t size is
* over 1K bytes and will probably grow with any changes.
*
* copy when vp is NULL, flush when non-NULL
*/
return (0);
} else {
*blkno = cpr_statefile_offset();
return (cpr_flush_write(vp));
}
}
/*
* Allocate bitmaps according to the phys_install list.
*/
static int
i_cpr_bitmap_setup(void)
{
void *space;
/*
* The number of bitmap descriptors will be the count of
* phys_install ranges plus 1 for a trailing NULL struct.
*/
cpr_nbitmaps = 1;
cpr_nbitmaps++;
return (EFBIG);
}
/* Alloc an array of bitmap descriptors. */
cpr_nbitmaps = 0;
return (ENOMEM);
}
return (ENOMEM);
dp++;
}
/* set magic for the last descriptor */
return (0);
}
void
i_cpr_bitmap_cleanup(void)
{
return;
cpr_nbitmaps = 0;
}
/*
* A "regular" and "volatile" bitmap are created for each range of
* physical memory. The volatile maps are used to count and track pages
* susceptible to heap corruption - caused by drivers that allocate mem
* during VOP_DUMP(); the regular maps are used for all the other non-
* susceptible pages. Before writing the bitmaps to the statefile,
* each bitmap pair gets merged to simplify handling within cprboot.
*/
int
i_cpr_alloc_bitmaps(void)
{
int err;
err = i_cpr_bitmap_setup();
if (err)
return (err);
}