/* * Hyper-V specific APIC code. * * Copyright (C) 2018, Microsoft, Inc. * * Author : K. Y. Srinivasan <kys@microsoft.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or * NON INFRINGEMENT. See the GNU General Public License for more * details. *
*/
/* * Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET * when the IPI is sent to all currently present CPUs.
*/ if (!cpumask_equal(mask, cpu_present_mask) || exclude_self) {
ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
/* * 'nr_bank <= 0' means some CPUs in cpumask can't be * represented in VP_SET. Return an error and fall back to * native (architectural) method of sending IPIs.
*/ if (nr_bank <= 0) goto ipi_mask_ex_done;
} else {
ipi_arg->vp_set.format = HV_GENERIC_SET_ALL;
}
/* * For this hypercall, Hyper-V treats the valid_bank_mask field * of ipi_arg->vp_set as part of the fixed size input header. * So the variable input header size is equal to nr_bank.
*/
status = hv_do_rep_hypercall(HVCALL_SEND_IPI_EX, 0, nr_bank,
ipi_arg, NULL);
/* * Do nothing if * 1. the mask is empty * 2. the mask only contains self when exclude_self is true
*/ if (weight == 0 ||
(exclude_self && weight == 1 && cpumask_test_cpu(this_cpu, mask))) returntrue;
/* A fully enlightened TDX VM uses GHCI rather than hv_hypercall_pg. */ if (!hv_hypercall_pg) { if (ms_hyperv.paravisor_present || !hv_isolation_type_tdx()) returnfalse;
}
if (vector < HV_IPI_LOW_VECTOR || vector > HV_IPI_HIGH_VECTOR) returnfalse;
/* * From the supplied CPU set we need to figure out if we can get away * with cheaper HVCALL_SEND_IPI hypercall. This is possible when the * highest VP number in the set is < 64. As VP numbers are usually in * ascending order and match Linux CPU ids, here is an optimization: * we check the VP number for the highest bit in the supplied set first * so we can quickly find out if using HVCALL_SEND_IPI_EX hypercall is * a must. We will also check all VP numbers when walking the supplied * CPU set to remain correct in all cases.
*/ if (hv_cpu_number_to_vp_number(cpumask_last(mask)) >= 64) goto do_ex_hypercall;
ipi_arg.vector = vector;
ipi_arg.cpu_mask = 0;
for_each_cpu(cur_cpu, mask) { if (exclude_self && cur_cpu == this_cpu) continue;
vcpu = hv_cpu_number_to_vp_number(cur_cpu); if (vcpu == VP_INVAL) returnfalse;
/* * This particular version of the IPI hypercall can * only target up to 64 CPUs.
*/ if (vcpu >= 64) goto do_ex_hypercall;
staticbool __send_ipi_one(int cpu, int vector)
{ int vp = hv_cpu_number_to_vp_number(cpu);
u64 status;
trace_hyperv_send_ipi_one(cpu, vector);
if (vp == VP_INVAL) returnfalse;
/* A fully enlightened TDX VM uses GHCI rather than hv_hypercall_pg. */ if (!hv_hypercall_pg) { if (ms_hyperv.paravisor_present || !hv_isolation_type_tdx()) returnfalse;
}
if (vector < HV_IPI_LOW_VECTOR || vector > HV_IPI_HIGH_VECTOR) returnfalse;
if (vp >= 64) return __send_ipi_mask_ex(cpumask_of(cpu), vector, false);
status = hv_do_fast_hypercall16(HVCALL_SEND_IPI, vector, BIT_ULL(vp)); return hv_result_success(status);
}
staticvoid hv_send_ipi(int cpu, int vector)
{ if (!__send_ipi_one(cpu, vector))
orig_apic.send_IPI(cpu, vector);
}
staticvoid hv_send_ipi_mask(conststruct cpumask *mask, int vector)
{ if (!__send_ipi_mask(mask, vector, false))
orig_apic.send_IPI_mask(mask, vector);
}
staticvoid hv_send_ipi_mask_allbutself(conststruct cpumask *mask, int vector)
{ if (!__send_ipi_mask(mask, vector, true))
orig_apic.send_IPI_mask_allbutself(mask, vector);
}
if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) {
pr_info("Hyper-V: Using enlightened APIC (%s mode)",
x2apic_enabled() ? "x2apic" : "xapic"); /* * When in x2apic mode, don't use the Hyper-V specific APIC * accessors since the field layout in the ICR register is * different in x2apic mode. Furthermore, the architectural * x2apic MSRs function just as well as the Hyper-V * synthetic APIC MSRs, so there's no benefit in having * separate Hyper-V accessors for x2apic mode. The only * exception is hv_apic_eoi_write, because it benefits from * lazy EOI when available, but the same accessor works for * both xapic and x2apic because the field layout is the same.
*/
apic_update_callback(eoi, hv_apic_eoi_write); if (!x2apic_enabled()) {
apic_update_callback(read, hv_apic_read);
apic_update_callback(write, hv_apic_write);
apic_update_callback(icr_write, hv_apic_icr_write);
apic_update_callback(icr_read, hv_apic_icr_read);
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.