public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0
@ 2026-03-30 10:54 Sebastian Ene
  2026-03-31  2:41 ` Vincent Donnefort
  2026-04-02 13:35 ` Marc Zyngier
  0 siblings, 2 replies; 4+ messages in thread
From: Sebastian Ene @ 2026-03-30 10:54 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, linux-kernel, android-kvm
  Cc: catalin.marinas, joey.gouly, mark.rutland, maz, oupton,
	sebastianene, suzuki.poulose, tabba, vdonnefort, will, yuzenghui

The ARM Service Calling Convention (SMCCC) specifies that the function
identifier and parameters should be passed in registers, leaving the
16-bit immediate field un-handled in pKVM when an SMC instruction is
trapped.
Since the HVC is a private interface between EL2 and the host,
enforce the host kernel running under pKVM to use an immediate value
of 0 only when using SMCs to make it clear for non-compliant software
talking to Trustzone that we only use SMCCC.

Signed-off-by: Sebastian Ene <sebastianene@google.com>
---
v2 -> current:
 - move the ESR decoding of the imm16 in the handle_host_smc where it
   was supposed to be
 - updated the commit message to include the reason behind while we are
   not doing for HVCs as well
 - updated the commit message to clarify that pKVM is not handling the
   imm16

v1 -> v2:
 - Dropped injecting an UNDEF and return an error instead
   (SMCCC_RET_NOT_SUPPORTED)
 - Used the mask ESR_ELx_xVC_IMM_MASK instead of masking with U16_MAX
 - Updated the title of the commit message from:
   "[PATCH] KVM: arm64: Inject UNDEF when host is executing an
    smc with imm16 != 0"

Link to v2:
https://lore.kernel.org/all/20260325113138.4171430-1-sebastianene@google.com/
Link to v1:
https://lore.kernel.org/all/20260324135728.3532400-1-sebastianene@google.com/

---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index e7790097db93..461cf5cb5ac7 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -676,8 +676,14 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt)
 static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
 {
 	DECLARE_REG(u64, func_id, host_ctxt, 0);
+	u64 esr = read_sysreg_el2(SYS_ESR);
 	bool handled;
 
+	if (esr & ESR_ELx_xVC_IMM_MASK) {
+		cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED;
+		goto exit_skip_instr;
+	}
+
 	func_id &= ~ARM_SMCCC_CALL_HINTS;
 
 	handled = kvm_host_psci_handler(host_ctxt, func_id);
@@ -686,6 +692,7 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
 	if (!handled)
 		default_host_smc_handler(host_ctxt);
 
+exit_skip_instr:
 	/* SMC was trapped, move ELR past the current PC. */
 	kvm_skip_host_instr();
 }
-- 
2.53.0.1018.g2bb0e51243-goog



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0
  2026-03-30 10:54 [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0 Sebastian Ene
@ 2026-03-31  2:41 ` Vincent Donnefort
  2026-03-31  9:28   ` Sebastian Ene
  2026-04-02 13:35 ` Marc Zyngier
  1 sibling, 1 reply; 4+ messages in thread
From: Vincent Donnefort @ 2026-03-31  2:41 UTC (permalink / raw)
  To: Sebastian Ene
  Cc: kvmarm, linux-arm-kernel, linux-kernel, android-kvm,
	catalin.marinas, joey.gouly, mark.rutland, maz, oupton,
	suzuki.poulose, tabba, will, yuzenghui

On Mon, Mar 30, 2026 at 10:54:41AM +0000, Sebastian Ene wrote:
> The ARM Service Calling Convention (SMCCC) specifies that the function
> identifier and parameters should be passed in registers, leaving the
> 16-bit immediate field un-handled in pKVM when an SMC instruction is
> trapped.
> Since the HVC is a private interface between EL2 and the host,
> enforce the host kernel running under pKVM to use an immediate value
> of 0 only when using SMCs to make it clear for non-compliant software
> talking to Trustzone that we only use SMCCC.
> 
> Signed-off-by: Sebastian Ene <sebastianene@google.com>

Reviewed-by: Vincent Donnefort <vdonnefort@google.com>

> ---
> v2 -> current:
>  - move the ESR decoding of the imm16 in the handle_host_smc where it
>    was supposed to be
>  - updated the commit message to include the reason behind while we are
>    not doing for HVCs as well
>  - updated the commit message to clarify that pKVM is not handling the
>    imm16
> 
> v1 -> v2:
>  - Dropped injecting an UNDEF and return an error instead
>    (SMCCC_RET_NOT_SUPPORTED)
>  - Used the mask ESR_ELx_xVC_IMM_MASK instead of masking with U16_MAX
>  - Updated the title of the commit message from:
>    "[PATCH] KVM: arm64: Inject UNDEF when host is executing an
>     smc with imm16 != 0"
> 
> Link to v2:
> https://lore.kernel.org/all/20260325113138.4171430-1-sebastianene@google.com/
> Link to v1:
> https://lore.kernel.org/all/20260324135728.3532400-1-sebastianene@google.com/
> 
> ---
>  arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> index e7790097db93..461cf5cb5ac7 100644
> --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> @@ -676,8 +676,14 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt)
>  static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
>  {
>  	DECLARE_REG(u64, func_id, host_ctxt, 0);
> +	u64 esr = read_sysreg_el2(SYS_ESR);
>  	bool handled;
>  
> +	if (esr & ESR_ELx_xVC_IMM_MASK) {
> +		cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED;
> +		goto exit_skip_instr;
> +	}
> +
>  	func_id &= ~ARM_SMCCC_CALL_HINTS;
>  
>  	handled = kvm_host_psci_handler(host_ctxt, func_id);
> @@ -686,6 +692,7 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
>  	if (!handled)
>  		default_host_smc_handler(host_ctxt);
>  
> +exit_skip_instr:
>  	/* SMC was trapped, move ELR past the current PC. */
>  	kvm_skip_host_instr();
>  }
> -- 
> 2.53.0.1018.g2bb0e51243-goog
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0
  2026-03-31  2:41 ` Vincent Donnefort
@ 2026-03-31  9:28   ` Sebastian Ene
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Ene @ 2026-03-31  9:28 UTC (permalink / raw)
  To: Vincent Donnefort
  Cc: kvmarm, linux-arm-kernel, linux-kernel, android-kvm,
	catalin.marinas, joey.gouly, mark.rutland, maz, oupton,
	suzuki.poulose, tabba, will, yuzenghui

On Tue, Mar 31, 2026 at 3:41 AM Vincent Donnefort <vdonnefort@google.com> wrote:
>
> On Mon, Mar 30, 2026 at 10:54:41AM +0000, Sebastian Ene wrote:
> > The ARM Service Calling Convention (SMCCC) specifies that the function
> > identifier and parameters should be passed in registers, leaving the
> > 16-bit immediate field un-handled in pKVM when an SMC instruction is
> > trapped.
> > Since the HVC is a private interface between EL2 and the host,
> > enforce the host kernel running under pKVM to use an immediate value
> > of 0 only when using SMCs to make it clear for non-compliant software
> > talking to Trustzone that we only use SMCCC.
> >
> > Signed-off-by: Sebastian Ene <sebastianene@google.com>
>

Hello,

> Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
>

Thanks for reviewing,
Sebastian

> > ---
> > v2 -> current:
> >  - move the ESR decoding of the imm16 in the handle_host_smc where it
> >    was supposed to be
> >  - updated the commit message to include the reason behind while we are
> >    not doing for HVCs as well
> >  - updated the commit message to clarify that pKVM is not handling the
> >    imm16
> >
> > v1 -> v2:
> >  - Dropped injecting an UNDEF and return an error instead
> >    (SMCCC_RET_NOT_SUPPORTED)
> >  - Used the mask ESR_ELx_xVC_IMM_MASK instead of masking with U16_MAX
> >  - Updated the title of the commit message from:
> >    "[PATCH] KVM: arm64: Inject UNDEF when host is executing an
> >     smc with imm16 != 0"
> >
> > Link to v2:
> > https://lore.kernel.org/all/20260325113138.4171430-1-sebastianene@google.com/
> > Link to v1:
> > https://lore.kernel.org/all/20260324135728.3532400-1-sebastianene@google.com/
> >
> > ---
> >  arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> > index e7790097db93..461cf5cb5ac7 100644
> > --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> > @@ -676,8 +676,14 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt)
> >  static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
> >  {
> >       DECLARE_REG(u64, func_id, host_ctxt, 0);
> > +     u64 esr = read_sysreg_el2(SYS_ESR);
> >       bool handled;
> >
> > +     if (esr & ESR_ELx_xVC_IMM_MASK) {
> > +             cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED;
> > +             goto exit_skip_instr;
> > +     }
> > +
> >       func_id &= ~ARM_SMCCC_CALL_HINTS;
> >
> >       handled = kvm_host_psci_handler(host_ctxt, func_id);
> > @@ -686,6 +692,7 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
> >       if (!handled)
> >               default_host_smc_handler(host_ctxt);
> >
> > +exit_skip_instr:
> >       /* SMC was trapped, move ELR past the current PC. */
> >       kvm_skip_host_instr();
> >  }
> > --
> > 2.53.0.1018.g2bb0e51243-goog
> >


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0
  2026-03-30 10:54 [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0 Sebastian Ene
  2026-03-31  2:41 ` Vincent Donnefort
@ 2026-04-02 13:35 ` Marc Zyngier
  1 sibling, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2026-04-02 13:35 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, linux-kernel, android-kvm,
	Sebastian Ene
  Cc: catalin.marinas, joey.gouly, mark.rutland, oupton, suzuki.poulose,
	tabba, vdonnefort, will, yuzenghui

On Mon, 30 Mar 2026 10:54:41 +0000, Sebastian Ene wrote:
> The ARM Service Calling Convention (SMCCC) specifies that the function
> identifier and parameters should be passed in registers, leaving the
> 16-bit immediate field un-handled in pKVM when an SMC instruction is
> trapped.
> Since the HVC is a private interface between EL2 and the host,
> enforce the host kernel running under pKVM to use an immediate value
> of 0 only when using SMCs to make it clear for non-compliant software
> talking to Trustzone that we only use SMCCC.
> 
> [...]

Applied to next, thanks!

[1/1] KVM: arm64: Prevent the host from using an smc with imm16 != 0
      commit: cf6348af645bd8e38758114e6afcc406c5bb515f

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-02 13:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 10:54 [PATCH v3] KVM: arm64: Prevent the host from using an smc with imm16 != 0 Sebastian Ene
2026-03-31  2:41 ` Vincent Donnefort
2026-03-31  9:28   ` Sebastian Ene
2026-04-02 13:35 ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox