Skip to contentSkip to conversation

virt: acrn: stop CPU removal when offlining fails

PATCH New Avi Weiss 1 participant 1 message Oct 30 Acrn hypervisor service module

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 virt: acrn: stop CPU removal when offlining fails

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")

---
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(-)
drivers/virt/acrn/hsm.c +9 -3
index f170ff4617fdd..79f8e50f0ac5c 100644
@@ -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

Signature · 1 line
2.43.0