public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Vincent Donnefort <vdonnefort@google•com>
To: maz@kernel•org, oliver.upton@linux•dev, joey.gouly@arm•com,
	 suzuki.poulose@arm•com, yuzenghui@huawei•com,
	catalin.marinas@arm•com,  will@kernel•org
Cc: linux-arm-kernel@lists•infradead.org, kvmarm@lists•linux.dev,
	 kernel-team@android•com, tabba@google•com,
	 Vincent Donnefort <vdonnefort@google•com>
Subject: [PATCH] KVM: arm64: Set a linux errno on SMCCC error in kvm_call_hyp_nvhe()
Date: Wed,  3 Jun 2026 12:03:12 +0100	[thread overview]
Message-ID: <20260603110312.2909844-1-vdonnefort@google.com> (raw)

If the HVC called in kvm_call_hyp_nvhe() fails with an SMCCC error code,
we WARN. However, the returned value isn't initialized and the caller
might get garbage or 0 which is likely to be interpreted as success.

Set a default -EPERM error value, ensuring all callers get the message
when SMCCC calls fail.

Signed-off-by: Vincent Donnefort <vdonnefort@google•com>

---

I have encountered this issue while working on a follow-up contribution to the
hypervisor tracing. In that case it completely crashed the kernel because
IS_ERR() failed on that res.a1 value.

Now, if it makes that function more robust, I do not believe it is fixing any
existing bug which is why I haven't added a "Fixes:" tag. 

In case we want to stick one, here it is:

Fixes: 054698316d87 ("KVM: arm64: nVHE: Migrate hyp interface to SMCCC")

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index a49042bfa801..6b8fd494792c 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1273,13 +1273,14 @@ void kvm_arm_resume_guest(struct kvm *kvm);
 #define vcpu_has_run_once(vcpu)	(!!READ_ONCE((vcpu)->pid))
 
 #ifndef __KVM_NVHE_HYPERVISOR__
-#define kvm_call_hyp_nvhe(f, ...)						\
+#define kvm_call_hyp_nvhe(f, ...)					\
 	({								\
 		struct arm_smccc_res res;				\
 									\
 		arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(f),		\
 				  ##__VA_ARGS__, &res);			\
-		WARN_ON(res.a0 != SMCCC_RET_SUCCESS);			\
+		if (WARN_ON(res.a0 != SMCCC_RET_SUCCESS))		\
+			res.a1 = -EPERM;				\
 									\
 		res.a1;							\
 	})

base-commit: e43ffb69e0438cddd72aaa30898b4dc446f664f8
-- 
2.54.0.1032.g2f8565e1d1-goog



             reply	other threads:[~2026-06-03 11:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 11:03 Vincent Donnefort [this message]
2026-06-03 11:22 ` [PATCH] KVM: arm64: Set a linux errno on SMCCC error in kvm_call_hyp_nvhe() Fuad Tabba

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=20260603110312.2909844-1-vdonnefort@google.com \
    --to=vdonnefort@google$(echo .)com \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=joey.gouly@arm$(echo .)com \
    --cc=kernel-team@android$(echo .)com \
    --cc=kvmarm@lists$(echo .)linux.dev \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=maz@kernel$(echo .)org \
    --cc=oliver.upton@linux$(echo .)dev \
    --cc=suzuki.poulose@arm$(echo .)com \
    --cc=tabba@google$(echo .)com \
    --cc=will@kernel$(echo .)org \
    --cc=yuzenghui@huawei$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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