mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Roberts <ryan.roberts@arm.com>
To: Fuad Tabba <fuad.tabba@linux.dev>
Cc: maz@kernel.org, oupton@kernel.org, kvmarm@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, catalin.marinas@arm.com,
	will@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com,
	suzuki.poulose@arm.com, yuzenghui@huawei.com,
	mark.rutland@arm.com, steven.price@arm.com,
	vdonnefort@google.com, qperret@google.com
Subject: Re: [PATCH v4 09/18] KVM: arm64: Implement HVC handling for protected guests at EL2
Date: Wed, 11 Nov 2026 17:50:31 +0000	[thread overview]
Message-ID: <c426f5a3-d161-476d-8911-99903ecf8e46@arm.com> (raw)
In-Reply-To: <CA+EHjTyCcGPMte9=HuqyvCS7CCCt80Lc_JQuA+1e3ZE+3A0zqQ@mail.gmail.com>

On 11/11/2026 16:45, Fuad Tabba wrote:
> Hi Ryan,
> 
> On Wed, 11 Nov 2026 13:59:17 +0000, Ryan Roberts <ryan.roberts@arm.com> wrote:
> [...]
>>> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> [...]
>>> @@ -2622,6 +2622,10 @@ static void kvm_hyp_init_symbols(void)
>>>          kvm_nvhe_sym(__icache_flags) = __icache_flags;
>>>          kvm_nvhe_sym(kvm_arm_vmid_bits) = kvm_arm_vmid_bits;
>>>
>>> +        kvm_nvhe_sym(spectre_v2_state) = arm64_get_spectre_v2_state();
>>> +        kvm_nvhe_sym(spectre_v4_state) = arm64_get_spectre_v4_state();
>>> +        kvm_nvhe_sym(spectre_bhb_state) = arm64_get_spectre_bhb_state();
>>
>> Is it really correct to snapshot this state then use it at runtime assuming its
>> still accurate? See below...
> 
> These can't change after this point: update_mitigation_state() doesn't
> update a state once system_capabilities_finalized() is true, and
> kvm_arm_init() runs after that.
> 
> [...]
>>> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> [...]
>>> @@ -1181,8 +1187,70 @@ bool kvm_handle_pvm_hvc64(struct kvm_vcpu *vcpu, u64 *exit_code)
> [...]
>>> +        case ARM_SMCCC_ARCH_FEATURES_FUNC_ID:
>>> +                /* The workaround calls themselves are handled on hyp entry. */
>>> +                val[0] = SMCCC_RET_NOT_SUPPORTED;
> [...]
>>> +                case ARM_SMCCC_ARCH_WORKAROUND_2:
>>> +                        switch (spectre_v4_state) {
>>> +                        case SPECTRE_VULNERABLE:
>>> +                                break;
>>> +                        case SPECTRE_MITIGATED:
>>> +                                /* With SSBS advertised the guest's default is safe. */
>>> +                                if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, SSBS, IMP))
>>> +                                        break;
>>
>> For this case (and the break immediately above) you return val[0] =
>> SMCCC_RET_INVALID_PARAMETER (from init at top of this function). But the
>> kernel's kvm_smccc_call_handler() returns val[0] = SMCCC_RET_NOT_SUPPORTED in
>> these cases (which seems more likely to be correct). Does this violate the ABI?
> 
> Both return NOT_SUPPORTED. val[0] is set to it at the top of the
> ARM_SMCCC_ARCH_FEATURES_FUNC_ID case.

Ahh missed that oops!

> 
>>
>>> +                                fallthrough;
>>> +                        case SPECTRE_UNAFFECTED:
>>> +                                val[0] = SMCCC_RET_NOT_REQUIRED;
>>
>> Is it possible that the (compromised) kernel could have disabled the mitigation
>> after the state snapshot was taken? I.e. spectre_v4_state == SPECTRE_MITIGATED
>> and the VM doesn't advertise SSBS so it returns SMCCC_RET_NOT_REQUIRED here. But
>> the kernel has since turned off the mitigation?
> 
> Yes, where the mitigation is the firmware one. The host can disable it
> with an ARM_SMCCC_ARCH_WORKAROUND_2 call, which EL2 forwards, and EL2
> doesn't enable it again before running the guest. With TF-A that's
> only on a Cortex-A76 without SSBS, the only CPU it implements the
> dynamic workaround for.

If the mitigation is via SSBS but SSBS is not exposed to the guest, I'm guessing
this is safe because the guest is expected to set SSBS=0 in this case?

Thanks,
Ryan

> 
> I'll send out a fix. Thanks for spotting this!
> 
> Cheers,
> /fuad


  reply	other threads:[~2026-11-11 17:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 13:56 [PATCH v4 00/18] KVM: arm64: Confine protected VM vCPU state to EL2 Fuad Tabba
2026-10-01 13:56 ` [PATCH v4 01/18] KVM: arm64: Sync HCR_EL2.VSE back to the host vCPU under pKVM Fuad Tabba
2026-10-01 13:56 ` [PATCH v4 02/18] KVM: arm64: Validate the host vCPU's VM before reading it " Fuad Tabba
2026-10-01 13:56 ` [PATCH v4 03/18] KVM: arm64: Pin the host vCPU before adjusting its PC " Fuad Tabba
2026-10-01 13:56 ` [PATCH v4 04/18] KVM: arm64: Disable steal time for protected VMs Fuad Tabba
2026-10-01 13:56 ` [PATCH v4 05/18] KVM: arm64: Introduce per-EC entry handlers for pKVM Fuad Tabba
2026-10-01 13:56 ` [PATCH v4 06/18] KVM: arm64: Skip fixed-feature state flush for protected vCPUs Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 07/18] KVM: arm64: Add {flush,sync}_hyp_timer_state() primitives Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 08/18] KVM: arm64: Add system register reset framework for protected VMs Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 09/18] KVM: arm64: Implement HVC handling for protected guests at EL2 Fuad Tabba
2026-11-11 13:59   ` Ryan Roberts
2026-11-11 16:45     ` Fuad Tabba
2026-11-11 17:50       ` Ryan Roberts [this message]
2026-11-11 18:06         ` Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 10/18] KVM: arm64: Handle PSCI calls for protected VMs " Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 11/18] KVM: arm64: Restrict KVM_ARM_VCPU_INIT and PSCI version for protected VMs Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 12/18] KVM: arm64: Prevent host PC adjustments for protected vCPUs Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 13/18] KVM: arm64: Inject an UNDEF at EL2 for unhandled protected guest exits Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 14/18] KVM: arm64: Add per-EC entry/exit state marshalling for protected guests Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 15/18] KVM: arm64: Reject host access to protected VM private state Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 16/18] KVM: arm64: Reject host power-on of a vCPU that EL2 holds powered off Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 17/18] KVM: arm64: Advertise the capabilities that protected VMs support Fuad Tabba
2026-10-01 13:57 ` [PATCH v4 18/18] KVM: arm64: Document the protected VM userspace API Fuad Tabba
2026-10-01 14:31 ` [PATCH v4 00/18] KVM: arm64: Confine protected VM vCPU state to EL2 Fuad Tabba
2026-10-02 15:55 ` Marc Zyngier
2026-10-03  6:57   ` Fuad Tabba
2026-10-03  8:38     ` Marc Zyngier

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=c426f5a3-d161-476d-8911-99903ecf8e46@arm.com \
    --to=ryan.roberts@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=qperret@google.com \
    --cc=seiden@linux.ibm.com \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.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®