Skip to content

Commit 1037e4c

Browse files
kirylbp3tk0v
authored andcommitted
cpu/hotplug: Add support for declaring CPU offlining not supported
The ACPI MADT mailbox wakeup method doesn't allow to offline a CPU after it has been woken up. Currently, offlining is prevented based on the confidential computing attribute which is set for Intel TDX. But TDX is not the only possible user of the wake up method. The MADT wakeup can be implemented outside of a confidential computing environment. Offline support is a property of the wakeup method, not the CoCo implementation. Introduce cpu_hotplug_disable_offlining() that can be called to indicate that CPU offlining should be disabled. This function is going to replace CC_ATTR_HOTPLUG_DISABLED for ACPI MADT wakeup method. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Tao Liu <ltao@redhat.com> Link: https://lore.kernel.org/r/20240614095904.1345461-4-kirill.shutemov@linux.intel.com
1 parent 24dd05d commit 1037e4c

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

include/linux/cpuhplock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void cpus_read_lock(void);
2121
void cpus_read_unlock(void);
2222
int cpus_read_trylock(void);
2323
void lockdep_assert_cpus_held(void);
24+
void cpu_hotplug_disable_offlining(void);
2425
void cpu_hotplug_disable(void);
2526
void cpu_hotplug_enable(void);
2627
void clear_tasks_mm_cpumask(int cpu);
@@ -36,6 +37,7 @@ static inline void cpus_read_lock(void) { }
3637
static inline void cpus_read_unlock(void) { }
3738
static inline int cpus_read_trylock(void) { return true; }
3839
static inline void lockdep_assert_cpus_held(void) { }
40+
static inline void cpu_hotplug_disable_offlining(void) { }
3941
static inline void cpu_hotplug_disable(void) { }
4042
static inline void cpu_hotplug_enable(void) { }
4143
static inline int remove_cpu(unsigned int cpu) { return -EPERM; }

kernel/cpu.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ static int cpu_hotplug_disabled;
483483

484484
DEFINE_STATIC_PERCPU_RWSEM(cpu_hotplug_lock);
485485

486+
static bool cpu_hotplug_offline_disabled __ro_after_init;
487+
486488
void cpus_read_lock(void)
487489
{
488490
percpu_down_read(&cpu_hotplug_lock);
@@ -542,6 +544,14 @@ static void lockdep_release_cpus_lock(void)
542544
rwsem_release(&cpu_hotplug_lock.dep_map, _THIS_IP_);
543545
}
544546

547+
/* Declare CPU offlining not supported */
548+
void cpu_hotplug_disable_offlining(void)
549+
{
550+
cpu_maps_update_begin();
551+
cpu_hotplug_offline_disabled = true;
552+
cpu_maps_update_done();
553+
}
554+
545555
/*
546556
* Wait for currently running CPU hotplug operations to complete (if any) and
547557
* disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects
@@ -1471,7 +1481,8 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
14711481
* If the platform does not support hotplug, report it explicitly to
14721482
* differentiate it from a transient offlining failure.
14731483
*/
1474-
if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED))
1484+
if (cc_platform_has(CC_ATTR_HOTPLUG_DISABLED) ||
1485+
cpu_hotplug_offline_disabled)
14751486
return -EOPNOTSUPP;
14761487
if (cpu_hotplug_disabled)
14771488
return -EBUSY;

0 commit comments

Comments
 (0)