xen/acpi: only evaluate Processor objects matching online CPUs

Current Xen Processor driver will evaluate any Processor object on the
ACPI tables regardless of whether the processor is online or not.
Avoid doing so for processors that are not online, as evaluating
methods of processors that are not online could lead to accesses to
invalid memory, and in any case the data that the driver fetches from
the Processor ACPI object only makes sense for processors that are
online.

Note the CPU related data fetched from Xen using XENPF_get_cpuinfo
hypercall could be cached, I leave that as a future optimization.

Sponsored by: Citrix Systems R&D
Fixes: b93f47eaee ('xen/acpi: upload Cx and Px data to Xen')
This commit is contained in:
Roger Pau Monné 2022-11-29 16:21:51 +01:00
parent bad602850e
commit bc9a5b0497

View File

@ -506,6 +506,31 @@ xen_acpi_cpu_probe(device_t dev)
return (BUS_PROBE_SPECIFIC);
}
static bool
is_processor_online(unsigned int acpi_id)
{
unsigned int i, maxid;
struct xen_platform_op op = {
.cmd = XENPF_get_cpuinfo,
};
int ret = HYPERVISOR_platform_op(&op);
if (ret)
return (false);
maxid = op.u.pcpu_info.max_present;
for (i = 0; i <= maxid; i++) {
op.u.pcpu_info.xen_cpuid = i;
ret = HYPERVISOR_platform_op(&op);
if (ret)
continue;
if (op.u.pcpu_info.acpi_id == acpi_id)
return (op.u.pcpu_info.flags & XEN_PCPU_FLAGS_ONLINE);
}
return (false);
}
static int
xen_acpi_cpu_attach(device_t dev)
{
@ -544,6 +569,10 @@ xen_acpi_cpu_attach(device_t dev)
}
}
if (!is_processor_online(sc->cpu_acpi_id))
/* Processor is not online, attach the driver and ignore it. */
return (0);
/*
* Install the notify handler now: even if we fail to parse or upload
* the states it shouldn't prevent us from attempting to parse further