xpc_partition.c
来自「底层驱动开发」· C语言 代码 · 共 987 行 · 第 1/2 页
C
987 行
* assumed to be of size XPC_VARS_ALIGNED_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, ia64_tpa((u64) remote_vars), XPC_VARS_ALIGNED_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;}/* * Prior code has determine 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_rsvd_page_pa; u64 remote_vars_pa; 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_rsvd_page_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; 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 (part->act_state == XPC_P_INACTIVE) { part->remote_rp_pa = remote_rsvd_page_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); xpc_activate_partition(part); } else if (part->remote_amos_page_pa != remote_vars->amos_page_pa || !XPC_HB_ALLOWED(sn_partition_id, remote_vars)) { part->reactivate_nasid = nasid; XPC_DEACTIVATE_PARTITION(part, xpcReactivating); }}/* * 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; struct xpc_rsvd_page *rp = (struct xpc_rsvd_page *) xpc_rsvd_page; act_amos = xpc_vars->act_amos; /* scan through act AMO variable looking for non-zero entries */ for (word = 0; word < XP_NASID_MASK_WORDS; word++) { nasid_mask = xpc_IPI_receive(&act_amos[word]); if (nasid_mask == 0) { /* no IRQs from nasids in this variable */ continue; } dev_dbg(xpc_part, "AMO[%d] gave back 0x%lx\n", word, nasid_mask); /* * If this nasid has been added to the machine since * our partition was reset, this will retain the * remote nasid in our reserved pages machine mask. * This is used in the event of module reload. */ rp->mach_nasids[word] |= nasid_mask; /* locate the nasid(s) which sent interrupts */ for (bit = 0; bit < (8 * sizeof(u64)); bit++) { if (nasid_mask & (1UL << bit)) { n_IRQs_detected++; nasid = XPC_NASID_FROM_W_B(word, bit); dev_dbg(xpc_part, "interrupt from nasid %ld\n", nasid); xpc_identify_act_IRQ_req(nasid); } } } return n_IRQs_detected;}/* * Mark specified partition as active. */enum xpc_retvalxpc_mark_partition_active(struct xpc_partition *part){ unsigned long irq_flags; enum xpc_retval ret; dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part)); spin_lock_irqsave(&part->act_lock, irq_flags); if (part->act_state == XPC_P_ACTIVATING) { part->act_state = XPC_P_ACTIVE; ret = xpcSuccess; } else { DBUG_ON(part->reason == xpcSuccess); ret = part->reason; } spin_unlock_irqrestore(&part->act_lock, irq_flags); return ret;}/* * Notify XPC that the partition is down. */voidxpc_deactivate_partition(const int line, struct xpc_partition *part, enum xpc_retval reason){ unsigned long irq_flags; partid_t partid = XPC_PARTID(part); spin_lock_irqsave(&part->act_lock, irq_flags); if (part->act_state == XPC_P_INACTIVE) { XPC_SET_REASON(part, reason, line); spin_unlock_irqrestore(&part->act_lock, irq_flags); if (reason == xpcReactivating) { /* we interrupt ourselves to reactivate partition */ xpc_IPI_send_reactivate(part); } return; } if (part->act_state == XPC_P_DEACTIVATING) { if ((part->reason == xpcUnloading && reason != xpcUnloading) || reason == xpcReactivating) { XPC_SET_REASON(part, reason, line); } spin_unlock_irqrestore(&part->act_lock, irq_flags); return; } part->act_state = XPC_P_DEACTIVATING; XPC_SET_REASON(part, reason, line); spin_unlock_irqrestore(&part->act_lock, irq_flags); XPC_DISALLOW_HB(partid, xpc_vars); dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n", partid, reason); xpc_partition_down(part, reason);}/* * Mark specified partition as active. */voidxpc_mark_partition_inactive(struct xpc_partition *part){ unsigned long irq_flags; dev_dbg(xpc_part, "setting partition %d to INACTIVE\n", XPC_PARTID(part)); spin_lock_irqsave(&part->act_lock, irq_flags); part->act_state = XPC_P_INACTIVE; spin_unlock_irqrestore(&part->act_lock, irq_flags); part->remote_rp_pa = 0;}/* * SAL has provided a partition and machine mask. The partition mask * contains a bit for each even nasid in our partition. The machine * mask contains a bit for each even nasid in the entire machine. * * Using those two bit arrays, we can determine which nasids are * known in the machine. Each should also have a reserved page * initialized if they are available for partitioning. */voidxpc_discovery(void){ void *remote_rp_base; struct xpc_rsvd_page *remote_rp; struct xpc_vars *remote_vars; u64 remote_rsvd_page_pa; u64 remote_vars_pa; int region; int max_regions; int nasid; struct xpc_rsvd_page *rp; partid_t partid; struct xpc_partition *part; u64 *discovered_nasids; enum xpc_retval ret; remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RSVD_PAGE_ALIGNED_SIZE, GFP_KERNEL, &remote_rp_base); if (remote_rp == NULL) { return; } remote_vars = (struct xpc_vars *) remote_rp; discovered_nasids = kmalloc(sizeof(u64) * XP_NASID_MASK_WORDS, GFP_KERNEL); if (discovered_nasids == NULL) { kfree(remote_rp_base); return; } memset(discovered_nasids, 0, sizeof(u64) * XP_NASID_MASK_WORDS); rp = (struct xpc_rsvd_page *) xpc_rsvd_page; /* * The term 'region' in this context refers to the minimum number of * nodes that can comprise an access protection grouping. The access * protection is in regards to memory, IOI and IPI. *///>>> move the next two #defines into either include/asm-ia64/sn/arch.h or//>>> include/asm-ia64/sn/addrs.h#define SH1_MAX_REGIONS 64#define SH2_MAX_REGIONS 256 max_regions = is_shub2() ? SH2_MAX_REGIONS : SH1_MAX_REGIONS; for (region = 0; region < max_regions; region++) { if ((volatile int) xpc_exiting) { break; } dev_dbg(xpc_part, "searching region %d\n", region); for (nasid = (region * sn_region_size * 2); nasid < ((region + 1) * sn_region_size * 2); nasid += 2) { if ((volatile int) xpc_exiting) { break; } dev_dbg(xpc_part, "checking nasid %d\n", nasid); if (XPC_NASID_IN_ARRAY(nasid, rp->part_nasids)) { dev_dbg(xpc_part, "PROM indicates Nasid %d is " "part of the local partition; skipping " "region\n", nasid); break; } if (!(XPC_NASID_IN_ARRAY(nasid, rp->mach_nasids))) { dev_dbg(xpc_part, "PROM indicates Nasid %d was " "not on Numa-Link network at reset\n", nasid); continue; } if (XPC_NASID_IN_ARRAY(nasid, discovered_nasids)) { dev_dbg(xpc_part, "Nasid %d is part of a " "partition which was previously " "discovered\n", nasid); continue; } /* pull over the reserved page structure */ ret = xpc_get_remote_rp(nasid, discovered_nasids, remote_rp, &remote_rsvd_page_pa); if (ret != xpcSuccess) { dev_dbg(xpc_part, "unable to get reserved page " "from nasid %d, reason=%d\n", nasid, ret); if (ret == xpcLocalPartid) { break; } continue; } remote_vars_pa = remote_rp->vars_pa; partid = remote_rp->partid; part = &xpc_partitions[partid]; /* pull over the cross partition variables */ ret = xpc_get_remote_vars(remote_vars_pa, remote_vars); if (ret != xpcSuccess) { dev_dbg(xpc_part, "unable to get XPC variables " "from nasid %d, reason=%d\n", nasid, ret); XPC_DEACTIVATE_PARTITION(part, ret); continue; } if (part->act_state != XPC_P_INACTIVE) { dev_dbg(xpc_part, "partition %d on nasid %d is " "already activating\n", partid, nasid); break; } /* * Register the remote partition's AMOs with SAL so it * can handle and cleanup errors within that address * range should the remote partition go down. We don't * unregister this range because it is difficult to * tell when outstanding writes to the remote partition * are finished and thus when it is thus safe to * unregister. This should not result in wasted space * in the SAL xp_addr_region table because we should * get the same page for remote_act_amos_pa after * module reloads and system reboots. */ if (sn_register_xp_addr_region( remote_vars->amos_page_pa, PAGE_SIZE, 1) < 0) { dev_dbg(xpc_part, "partition %d failed to " "register xp_addr region 0x%016lx\n", partid, remote_vars->amos_page_pa); XPC_SET_REASON(part, xpcPhysAddrRegFailed, __LINE__); break; } /* * The remote nasid is valid and available. * Send an interrupt to that nasid to notify * it that we are ready to begin activation. */ dev_dbg(xpc_part, "sending an interrupt to AMO 0x%lx, " "nasid %d, phys_cpuid 0x%x\n", remote_vars->amos_page_pa, remote_vars->act_nasid, remote_vars->act_phys_cpuid); xpc_IPI_send_activate(remote_vars); } } kfree(discovered_nasids); kfree(remote_rp_base);}/* * Given a partid, get the nasids owned by that partition from the * remote partition's reserved page. */enum xpc_retvalxpc_initiate_partid_to_nasids(partid_t partid, void *nasid_mask){ struct xpc_partition *part; u64 part_nasid_pa; int bte_res; part = &xpc_partitions[partid]; if (part->remote_rp_pa == 0) { return xpcPartitionDown; } part_nasid_pa = part->remote_rp_pa + (u64) &((struct xpc_rsvd_page *) 0)->part_nasids; bte_res = xp_bte_copy(part_nasid_pa, ia64_tpa((u64) nasid_mask), L1_CACHE_ALIGN(XP_NASID_MASK_BYTES), (BTE_NOTIFY | BTE_WACQUIRE), NULL); return xpc_map_bte_errors(bte_res);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?