acpi/processor: fix evaluating _PDC method when running as Xen dom0
Subsystems (4)
PATCH v3 1/1 acpi/processor: fix evaluating _PDC method when running as Xen dom0
In ACPI systems, the OS can direct power management, as opposed to the firmware. This OS-directed Power Management is called OSPM. Part of telling the firmware that the OS going to direct power management is making ACPI "_PDC" (Processor Driver Capabilities) calls. These _PDC methods must be evaluated for every processor object. If these _PDC calls are not completed for every processor it can lead to inconsistency and later failures in things like the CPU frequency driver.
In a Xen system, the dom0 kernel is responsible for system-wide power management. The dom0 kernel is in charge of OSPM. However, the number of CPUs available to dom0 can be different than the number of CPUs physically present on the system.
This leads to a problem: the dom0 kernel needs to evaluate _PDC for all the processors, but it can't always see them.
In dom0 kernels, ignore the existing ACPI method for determining if a processor is physically present because it might not be accurate. Instead, ask the hypervisor for this information.
Fix this by introducing a custom function to use when running as Xen dom0 in order to check whether a processor object matches a CPU that's online. Such checking is done using the existing information fetched by the Xen pCPU subsystem, extending it to also store the ACPI ID.
This ensures that _PDC method gets evaluated for all physically online CPUs, regardless of the number of CPUs made available to dom0.
---
Changes since v2:
- Extend and use the existing pcpu functionality.
Changes since v1:
- Reword commit message.
--- arch/x86/include/asm/xen/hypervisor.h | 10 ++++++++++ drivers/acpi/processor_pdc.c | 11 +++++++++++ drivers/xen/pcpu.c | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+)
arch/x86/include/asm/xen/hypervisor.h +10 -0
@@ -63,4 +63,14 @@ void __init xen_pvh_init(struct boot_params *boot_params);void __init mem_map_via_hcall (struct boot_params *boot_params_p);#endif +#ifdef CONFIG_XEN_DOM0 +bool __init xen_processor_present (uint32_t acpi_id); +#else +static inline bool xen_processor_present (uint32_t acpi_id) +{ +BUG (); +return false; +} +#endif +#endif /* _ASM_X86_XEN_HYPERVISOR_H */
drivers/acpi/processor_pdc.c +11 -0
@@ -14,6 +14,8 @@#include <linux/acpi.h> #include <acpi/processor.h> +#include <xen/xen.h> +#include "internal.h" static bool __init processor_physically_present (acpi_handle handle)
@@ -47,6 +49,15 @@ static bool __init processor_physically_present(acpi_handle handle)return false; } +if (xen_initial_domain ()) +/* +* When running as a Xen dom0 the number of processors Linux +* sees can be different from the real number of processors on +* the system, and we still need to execute _PDC for all of +* them. +*/ +return xen_processor_present (acpi_id); + type = (acpi_type ==ACPI_TYPE_DEVICE ) ?1 :0 ; cpuid =acpi_get_cpuid (handle, type, acpi_id);
drivers/xen/pcpu.c +19 -0
@@ -58,6 +58,7 @@ struct pcpu {struct list_head list;struct device dev;uint32_t cpu_id; +uint32_t acpi_id;uint32_t flags; };
@@ -249,6 +250,7 @@ static struct pcpu *create_and_register_pcpu(struct xenpf_pcpuinfo *info)INIT_LIST_HEAD (&pcpu->list); pcpu->cpu_id = info->xen_cpuid; + pcpu->acpi_id = info->acpi_id; pcpu->flags = info->flags;/* Need hold on xen_pcpu_lock before pcpu list manipulations */
@@ -381,3 +383,20 @@ static int __init xen_pcpu_init(void)return ret; }arch_initcall (xen_pcpu_init); + +bool __init xen_processor_present (uint32_t acpi_id) +{ +struct pcpu *pcpu; +bool online = false; + +mutex_lock (&xen_pcpu_lock); +list_for_each_entry (pcpu, &xen_pcpus, list) +if (pcpu->acpi_id == acpi_id) { + online = pcpu->flags &XEN_PCPU_FLAGS_ONLINE ; +break ; + } + +mutex_unlock (&xen_pcpu_lock); + +return online; +}
Signature · 1 line
2.39.0
arch/x86/include/asm/xen/hypervisor.h void __init xen_pvh_init(struct boot_params *boot_params); · line 66
Quoted 7 lines · Roger Pau Monne
arch/x86/include/asm/xen/hypervisor.h +1
-0@@ -63,4 +63,14 @@ void __init xen_pvh_init(struct boot_params *boot_params);void __init mem_map_via_hcall (struct boot_params *boot_params_p);#endif +#ifdef CONFIG_XEN_DOM0
Shouldn't you also check CONFIG_X86 here, seeing the condition for when pcpu.c would be built? Additionally CONFIG_ACPI may want checking, which
- taken together - would amount to checking CONFIG_XEN_ACPI. (For which in turn I find odd that it will also be engaged when !DOM0.)
Quoted 11 lines
arch/x86/include/asm/xen/hypervisor.h +7
-0@@ -381,3 +383,20 @@ static int __init xen_pcpu_init(void)return ret; }arch_initcall (xen_pcpu_init); + +bool __init xen_processor_present (uint32_t acpi_id) +{ +struct pcpu *pcpu; +bool online = false; + +mutex_lock (&xen_pcpu_lock);
arch/x86/include/asm/xen/hypervisor.h static int __init xen_pcpu_init(void) · line 402
Quoted 10 lines
arch/x86/include/asm/xen/hypervisor.h +10
-0+list_for_each_entry (pcpu, &xen_pcpus, list) +if (pcpu->acpi_id == acpi_id) { + online = pcpu->flags &XEN_PCPU_FLAGS_ONLINE ; +break ; + } + +mutex_unlock (&xen_pcpu_lock); + +return online; +}
Since it is neither natural nor obvious that this function takes an ACPI ID as input (could in particular also be an APIC ID), would that perhaps better be expressed in its name?
Jan
Quoted 11 lines · Jan Beulich
arch/x86/include/asm/xen/hypervisor.h void __init xen_pvh_init(struct boot_params *boot_params); · line 66
Quoted 7 lines · Roger Pau Monne
arch/x86/include/asm/xen/hypervisor.h +1
-0@@ -63,4 +63,14 @@ void __init xen_pvh_init(struct boot_params *boot_params);void __init mem_map_via_hcall (struct boot_params *boot_params_p);#endif +#ifdef CONFIG_XEN_DOM0 Shouldn't you also check
CONFIG_X86here, seeing the condition for whenpcpu.cwould be built?
It's in a x86 specific header, so that's enough I think? (note the path of the header)
Quoted 3 lines
Additionally
CONFIG_ACPImay want checking, which
- taken together - would amount to checkingCONFIG_XEN_ACPI. (For which in turn I find odd that it will also be engaged when !DOM0.)
Hm, is it worth making the acpi_id field in struct pcpu or helper conditional to CONFIG_ACPI? It's just data fetched from Xen so it doesn't depend on any of the ACPI functionality in Linux.
IMO I don't think it's worth the extra ifdefs.
Quoted 17 lines
Quoted 17 lines
arch/x86/include/asm/xen/hypervisor.h +13
-0@@ -381,3 +383,20 @@ static int __init xen_pcpu_init(void)return ret; }arch_initcall (xen_pcpu_init); + +bool __init xen_processor_present (uint32_t acpi_id) +{ +struct pcpu *pcpu; +bool online = false; + +mutex_lock (&xen_pcpu_lock); +list_for_each_entry (pcpu, &xen_pcpus, list) +if (pcpu->acpi_id == acpi_id) { + online = pcpu->flags &XEN_PCPU_FLAGS_ONLINE ; +break ; + } +
Quoted 8 lines
arch/x86/include/asm/xen/hypervisor.h static int __init xen_pcpu_init(void) · line 402
Quoted 4 lines
arch/x86/include/asm/xen/hypervisor.h +4
-0+mutex_unlock (&xen_pcpu_lock); + +return online; +}Since it is neither natural nor obvious that this function takes an ACPI ID as input (could in particular also be an APIC ID), would that perhaps better be expressed in its name?
I did wonder the same, but convinced myself that the parameter name being acpi_id was enough of a hint that the function takes an ACPI ID.
Thanks, Roger.
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
arch/x86/include/asm/xen/hypervisor.h +0
-0@@ -63,4 +63,14 @@ void __init xen_pvh_init(struct boot_params *boot_params);void __init mem_map_via_hcall (struct boot_params *boot_params_p);#endif
Quoted 7 lines
Quoted 4 lines
arch/x86/include/asm/xen/hypervisor.h void __init xen_pvh_init(struct boot_params *boot_params); · line 66
Quoted 1 line
arch/x86/include/asm/xen/hypervisor.h +1
-0+#ifdef CONFIG_XEN_DOM0 Shouldn't you also check
CONFIG_X86here, seeing the condition for whenpcpu.cwould be built?It's in a x86 specific header, so that's enough I think? (note the path of the header)
Oh, of course I should have paid attention - I'm sorry. (Then again it's not really logical to live in an arch-dependent header, as the same would be needed elsewhere with ACPI.)
Quoted 9 lines
Quoted 3 lines
Additionally
CONFIG_ACPImay want checking, which
- taken together - would amount to checkingCONFIG_XEN_ACPI. (For which in turn I find odd that it will also be engaged when !DOM0.)Hm, is it worth making the
acpi_idfield in struct pcpu or helper conditional toCONFIG_ACPI? It's just data fetched from Xen so it doesn't depend on any of the ACPI functionality in Linux.IMO I don't think it's worth the extra ifdefs.
I didn't mean to suggest #ifdef for the new struct field. But the helper is of no use without ACPI.
Jan