mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Weiss <thnkslprpt@gmail.com>
To: Fei Li <fei1.li@intel.com>
Cc: Shuo Liu <shuo.a.liu@intel.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] virt: acrn: stop CPU removal when offlining fails
Date: Fri, 30 Oct 2026 13:33:25 +0200	[thread overview]
Message-ID: <20261030113324.2265585-2-thnkslprpt@gmail.com> (raw)

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


                 reply	other threads:[~2026-10-30 11:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261030113324.2265585-2-thnkslprpt@gmail.com \
    --to=thnkslprpt@gmail.com \
    --cc=fei1.li@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shuo.a.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®