* [PATCH] virt: acrn: stop CPU removal when offlining fails
@ 2026-10-30 11:33 Avi Weiss
0 siblings, 0 replies; only message in thread
From: Avi Weiss @ 2026-10-30 11:33 UTC (permalink / raw)
To: Fei Li; +Cc: Shuo Liu, linux-kernel
remove_cpu_store() ignores errors from remove_cpu() and calls
hcall_sos_remove_cpu() even when Linux cannot offline the CPU.
This can leave Linux and ACRN with inconsistent CPU ownership.
Return the offlining error before issuing the hypercall. If the
hypercall subsequently fails, bring the CPU back online only when
it was online before the removal attempt.
Fixes: 279dcf693ac76 ("virt: acrn: Introduce an interface for Service VM to control vCPU")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
Compile-tested CONFIG_ACRN_HSM=m with W=1; no ACRN Service VM runtime test.
drivers/virt/acrn/hsm.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c
index f170ff4617fdd..79f8e50f0ac5c 100644
--- a/drivers/virt/acrn/hsm.c
+++ b/drivers/virt/acrn/hsm.c
@@ -437,6 +437,7 @@ static ssize_t remove_cpu_store(struct device *dev,
const char *buf, size_t count)
{
u64 cpu, lapicid;
+ bool was_online;
int ret;
if (kstrtoull(buf, 0, &cpu) < 0)
@@ -445,8 +446,12 @@ static ssize_t remove_cpu_store(struct device *dev,
if (cpu >= num_possible_cpus() || cpu == 0 || !cpu_is_hotpluggable(cpu))
return -EINVAL;
- if (cpu_online(cpu))
- remove_cpu(cpu);
+ was_online = cpu_online(cpu);
+ if (was_online) {
+ ret = remove_cpu(cpu);
+ if (ret)
+ return ret;
+ }
lapicid = cpu_data(cpu).topo.apicid;
dev_dbg(dev, "Try to remove cpu %lld with lapicid %lld\n", cpu, lapicid);
@@ -459,7 +464,8 @@ static ssize_t remove_cpu_store(struct device *dev,
return count;
fail_remove:
- add_cpu(cpu);
+ if (was_online)
+ add_cpu(cpu);
return ret;
}
static DEVICE_ATTR_WO(remove_cpu);
base-commit: d89e1d186ec9271bf78e62771779e9fc03bf0fc3
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-30 11:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30 11:33 [PATCH] virt: acrn: stop CPU removal when offlining fails Avi Weiss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®