📄 xpc_partition.c
字号:
*/voidxpc_check_remote_hb(void){ struct xpc_vars *remote_vars; struct xpc_partition *part; partid_t partid; bte_result_t bres; remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer; for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) { if (xpc_exiting) { break; } if (partid == sn_partition_id) { continue; } part = &xpc_partitions[partid]; if (part->act_state == XPC_P_INACTIVE || part->act_state == XPC_P_DEACTIVATING) { continue; } /* pull the remote_hb cache line */ bres = xp_bte_copy(part->remote_vars_pa, (u64) remote_vars, XPC_RP_VARS_SIZE, (BTE_NOTIFY | BTE_WACQUIRE), NULL); if (bres != BTE_SUCCESS) { XPC_DEACTIVATE_PARTITION(part, xpc_map_bte_errors(bres)); continue; } dev_dbg(xpc_part, "partid = %d, heartbeat = %ld, last_heartbeat" " = %ld, heartbeat_offline = %ld, HB_mask = 0x%lx\n", partid, remote_vars->heartbeat, part->last_heartbeat, remote_vars->heartbeat_offline, remote_vars->heartbeating_to_mask); if (((remote_vars->heartbeat == part->last_heartbeat) && (remote_vars->heartbeat_offline == 0)) || !xpc_hb_allowed(sn_partition_id, remote_vars)) { XPC_DEACTIVATE_PARTITION(part, xpcNoHeartbeat); continue; } part->last_heartbeat = remote_vars->heartbeat; }}/* * Get a copy of a portion of the remote partition's rsvd page. * * remote_rp points to a buffer that is cacheline aligned for BTE copies and * is large enough to contain a copy of their reserved page header and * part_nasids mask. */static enum xpc_retvalxpc_get_remote_rp(int nasid, u64 *discovered_nasids, struct xpc_rsvd_page *remote_rp, u64 *remote_rp_pa){ int bres, i; /* get the reserved page's physical address */ *remote_rp_pa = xpc_get_rsvd_page_pa(nasid); if (*remote_rp_pa == 0) { return xpcNoRsvdPageAddr; } /* pull over the reserved page header and part_nasids mask */ bres = xp_bte_copy(*remote_rp_pa, (u64) remote_rp, XPC_RP_HEADER_SIZE + xp_nasid_mask_bytes, (BTE_NOTIFY | BTE_WACQUIRE), NULL); if (bres != BTE_SUCCESS) { return xpc_map_bte_errors(bres); } if (discovered_nasids != NULL) { u64 *remote_part_nasids = XPC_RP_PART_NASIDS(remote_rp); for (i = 0; i < xp_nasid_mask_words; i++) { discovered_nasids[i] |= remote_part_nasids[i]; } } /* check that the partid is for another partition */ if (remote_rp->partid < 1 || remote_rp->partid > (XP_MAX_PARTITIONS - 1)) { return xpcInvalidPartid; } if (remote_rp->partid == sn_partition_id) { return xpcLocalPartid; } if (XPC_VERSION_MAJOR(remote_rp->version) != XPC_VERSION_MAJOR(XPC_RP_VERSION)) { return xpcBadVersion; } return xpcSuccess;}/* * Get a copy of the remote partition's XPC variables from the reserved page. * * remote_vars points to a buffer that is cacheline aligned for BTE copies and * assumed to be of size XPC_RP_VARS_SIZE. */static enum xpc_retvalxpc_get_remote_vars(u64 remote_vars_pa, struct xpc_vars *remote_vars){ int bres; if (remote_vars_pa == 0) { return xpcVarsNotSet; } /* pull over the cross partition variables */ bres = xp_bte_copy(remote_vars_pa, (u64) remote_vars, XPC_RP_VARS_SIZE, (BTE_NOTIFY | BTE_WACQUIRE), NULL); if (bres != BTE_SUCCESS) { return xpc_map_bte_errors(bres); } if (XPC_VERSION_MAJOR(remote_vars->version) != XPC_VERSION_MAJOR(XPC_V_VERSION)) { return xpcBadVersion; } return xpcSuccess;}/* * Update the remote partition's info. */static voidxpc_update_partition_info(struct xpc_partition *part, u8 remote_rp_version, struct timespec *remote_rp_stamp, u64 remote_rp_pa, u64 remote_vars_pa, struct xpc_vars *remote_vars){ part->remote_rp_version = remote_rp_version; dev_dbg(xpc_part, " remote_rp_version = 0x%016x\n", part->remote_rp_version); part->remote_rp_stamp = *remote_rp_stamp; dev_dbg(xpc_part, " remote_rp_stamp (tv_sec = 0x%lx tv_nsec = 0x%lx\n", part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec); part->remote_rp_pa = remote_rp_pa; dev_dbg(xpc_part, " remote_rp_pa = 0x%016lx\n", part->remote_rp_pa); part->remote_vars_pa = remote_vars_pa; dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n", part->remote_vars_pa); part->last_heartbeat = remote_vars->heartbeat; dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n", part->last_heartbeat); part->remote_vars_part_pa = remote_vars->vars_part_pa; dev_dbg(xpc_part, " remote_vars_part_pa = 0x%016lx\n", part->remote_vars_part_pa); part->remote_act_nasid = remote_vars->act_nasid; dev_dbg(xpc_part, " remote_act_nasid = 0x%x\n", part->remote_act_nasid); part->remote_act_phys_cpuid = remote_vars->act_phys_cpuid; dev_dbg(xpc_part, " remote_act_phys_cpuid = 0x%x\n", part->remote_act_phys_cpuid); part->remote_amos_page_pa = remote_vars->amos_page_pa; dev_dbg(xpc_part, " remote_amos_page_pa = 0x%lx\n", part->remote_amos_page_pa); part->remote_vars_version = remote_vars->version; dev_dbg(xpc_part, " remote_vars_version = 0x%x\n", part->remote_vars_version);}/* * Prior code has determined the nasid which generated an IPI. Inspect * that nasid to determine if its partition needs to be activated or * deactivated. * * A partition is consider "awaiting activation" if our partition * flags indicate it is not active and it has a heartbeat. A * partition is considered "awaiting deactivation" if our partition * flags indicate it is active but it has no heartbeat or it is not * sending its heartbeat to us. * * To determine the heartbeat, the remote nasid must have a properly * initialized reserved page. */static voidxpc_identify_act_IRQ_req(int nasid){ struct xpc_rsvd_page *remote_rp; struct xpc_vars *remote_vars; u64 remote_rp_pa; u64 remote_vars_pa; int remote_rp_version; int reactivate = 0; int stamp_diff; struct timespec remote_rp_stamp = { 0, 0 }; partid_t partid; struct xpc_partition *part; enum xpc_retval ret; /* pull over the reserved page structure */ remote_rp = (struct xpc_rsvd_page *) xpc_remote_copy_buffer; ret = xpc_get_remote_rp(nasid, NULL, remote_rp, &remote_rp_pa); if (ret != xpcSuccess) { dev_warn(xpc_part, "unable to get reserved page from nasid %d, " "which sent interrupt, reason=%d\n", nasid, ret); return; } remote_vars_pa = remote_rp->vars_pa; remote_rp_version = remote_rp->version; if (XPC_SUPPORTS_RP_STAMP(remote_rp_version)) { remote_rp_stamp = remote_rp->stamp; } partid = remote_rp->partid; part = &xpc_partitions[partid]; /* pull over the cross partition variables */ remote_vars = (struct xpc_vars *) xpc_remote_copy_buffer; ret = xpc_get_remote_vars(remote_vars_pa, remote_vars); if (ret != xpcSuccess) { dev_warn(xpc_part, "unable to get XPC variables from nasid %d, " "which sent interrupt, reason=%d\n", nasid, ret); XPC_DEACTIVATE_PARTITION(part, ret); return; } part->act_IRQ_rcvd++; dev_dbg(xpc_part, "partid for nasid %d is %d; IRQs = %d; HB = " "%ld:0x%lx\n", (int) nasid, (int) partid, part->act_IRQ_rcvd, remote_vars->heartbeat, remote_vars->heartbeating_to_mask); if (xpc_partition_disengaged(part) && part->act_state == XPC_P_INACTIVE) { xpc_update_partition_info(part, remote_rp_version, &remote_rp_stamp, remote_rp_pa, remote_vars_pa, remote_vars); if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)) { if (xpc_partition_disengage_requested(1UL << partid)) { /* * Other side is waiting on us to disengage, * even though we already have. */ return; } } else { /* other side doesn't support disengage requests */ xpc_clear_partition_disengage_request(1UL << partid); } xpc_activate_partition(part); return; } DBUG_ON(part->remote_rp_version == 0); DBUG_ON(part->remote_vars_version == 0); if (!XPC_SUPPORTS_RP_STAMP(part->remote_rp_version)) { DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(part-> remote_vars_version)); if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) { DBUG_ON(XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars-> version)); /* see if the other side rebooted */ if (part->remote_amos_page_pa == remote_vars->amos_page_pa && xpc_hb_allowed(sn_partition_id, remote_vars)) { /* doesn't look that way, so ignore the IPI */ return; } } /* * Other side rebooted and previous XPC didn't support the * disengage request, so we don't need to do anything special. */ xpc_update_partition_info(part, remote_rp_version, &remote_rp_stamp, remote_rp_pa, remote_vars_pa, remote_vars); part->reactivate_nasid = nasid; XPC_DEACTIVATE_PARTITION(part, xpcReactivating); return; } DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version)); if (!XPC_SUPPORTS_RP_STAMP(remote_rp_version)) { DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version)); /* * Other side rebooted and previous XPC did support the * disengage request, but the new one doesn't. */ xpc_clear_partition_engaged(1UL << partid); xpc_clear_partition_disengage_request(1UL << partid); xpc_update_partition_info(part, remote_rp_version, &remote_rp_stamp, remote_rp_pa, remote_vars_pa, remote_vars); reactivate = 1; } else { DBUG_ON(!XPC_SUPPORTS_DISENGAGE_REQUEST(remote_vars->version)); stamp_diff = xpc_compare_stamps(&part->remote_rp_stamp, &remote_rp_stamp); if (stamp_diff != 0) { DBUG_ON(stamp_diff >= 0); /* * Other side rebooted and the previous XPC did support * the disengage request, as does the new one. */ DBUG_ON(xpc_partition_engaged(1UL << partid)); DBUG_ON(xpc_partition_disengage_requested(1UL << partid)); xpc_update_partition_info(part, remote_rp_version, &remote_rp_stamp, remote_rp_pa, remote_vars_pa, remote_vars); reactivate = 1; } } if (part->disengage_request_timeout > 0 && !xpc_partition_disengaged(part)) { /* still waiting on other side to disengage from us */ return; } if (reactivate) { part->reactivate_nasid = nasid; XPC_DEACTIVATE_PARTITION(part, xpcReactivating); } else if (XPC_SUPPORTS_DISENGAGE_REQUEST(part->remote_vars_version) && xpc_partition_disengage_requested(1UL << partid)) { XPC_DEACTIVATE_PARTITION(part, xpcOtherGoingDown); }}/* * Loop through the activation AMO variables and process any bits * which are set. Each bit indicates a nasid sending a partition * activation or deactivation request. * * Return #of IRQs detected. */intxpc_identify_act_IRQ_sender(void){ int word, bit; u64 nasid_mask; u64 nasid; /* remote nasid */ int n_IRQs_detected = 0; AMO_t *act_amos; act_amos = xpc_vars->amos_page + XPC_ACTIVATE_IRQ_AMOS; /* scan through act AMO variable looking for non-zero entries */ for (word = 0; word < xp_nasid_mask_words; word++) { if (xpc_exiting) { break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -