Re: [PATCH] KVM: arm64: Keep firmware Spectre-v4 mitigation on for protected guests

From: Fuad Tabba

Date: Mon Nov 16 2026 - 02:42:23 EST


Hi Marc,

On Sat, 14 Nov 2026 15:33:44 +0000, Marc Zyngier <maz@xxxxxxxxxx> wrote:
[...]
> > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
[...]
> > @@ -30,6 +31,8 @@
> >
> > DEFINE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
> >
> > +static DEFINE_PER_CPU(bool, host_ssbd_disabled);
> > +
>
> Why do we need yet another set of per-CPU booleans to track the host
> state that is supposed to be stored in kvm_host_data? We already have
> a metric bazillion of flags for any odd state tracking, and I really
> can't see why this should be an exception.

I'll use a kvm_host_data flag in v2.

[...]
> > @@ -940,6 +943,17 @@ DEFINE_KVM_HOST_HCALL(int, __kvm_vcpu_run, struct kvm_vcpu __kern *, vcpu)
> > return ret;
> > }
> >
> > + /*
> > + * Firmware Spectre-v4 mitigation can be advertised to a
> > + * protected guest as permanent. The host kernel runs with it
> > + * enabled, so nothing is restored on exit.
>
> I don't understand this. If the host is supposed to run with the
> mitigation enabled, how did we get here with the mitigation disabled?
> It's not like we can get here directly from userspace...
>
> So either the reasoning in the comment is wrong (and therefore needs
> fixing), or this is a buggy (malicious?) host that tries to trick the
> hypervisor (and then I question whether we should even try to continue
> running the guest).

It's the second. The host kernel enables the mitigation on every entry
from userspace, so only a misbehaving host gets here with it disabled.
I'll say so in the comment.

I had EL2 enable it again so that the NOT_REQUIRED it returns to the
guest holds whatever the host does, but failing the run does that too.
I'll do that in v2, like the SVCR check above.

[...]
> > @@ -1671,6 +1685,12 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
> > goto exit_skip_instr;
> > }
> >
> > + if (func_id == ARM_SMCCC_ARCH_WORKAROUND_2) {
> > + /* Drop the hints, so that the firmware decodes the ID as EL2 did. */
> > + cpu_reg(host_ctxt, 0) = func_id;
> > + __this_cpu_write(host_ssbd_disabled, !lower_32_bits(cpu_reg(host_ctxt, 1)));
> > + }
> > +
>
> This should be pushed into default_host_smc_handler() rather than left
> dangling here (it is pretty obvious that it has nothing to do with
> PSCI or FFA).

I put it there since that's where the function ID is decoded, but I'll
move it into default_host_smc_handler() and pass the ID in.

Cheers,
/fuad