From: Will Deacon <will@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
maz@kernel.org, oliver.upton@linux.dev, mark.rutland@arm.com,
joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com,
catalin.marinas@arm.com, broonie@kernel.org, qperret@google.com,
vdonnefort@google.com
Subject: Re: [PATCH v1 3/3] KVM: arm64: Create each pKVM hyp vcpu after its corresponding host vcpu
Date: Mon, 17 Feb 2025 15:30:31 +0000 [thread overview]
Message-ID: <20250217153031.GA16398@willie-the-truck> (raw)
In-Reply-To: <20250214150258.464798-4-tabba@google.com>
On Fri, Feb 14, 2025 at 03:02:58PM +0000, Fuad Tabba wrote:
> Instead of creating and initializing _all_ hyp vcpus in pKVM when
> the first host vcpu runs for the first time, initialize _each_
> hyp vcpu in conjunction with its corresponding host vcpu.
>
> Some of the host vcpu state (e.g., system registers and traps
> values) are not initialized until the first time the host vcpu is
> run. Therefore, initializing a hyp vcpu before its corresponding
> host vcpu has run for the first time might not view the complete
> host state of these vcpus.
>
> Additionally, this behavior is inline with non-protected modes.
>
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
> arch/arm64/include/asm/kvm_host.h | 2 +
> arch/arm64/include/asm/kvm_pkvm.h | 1 +
> arch/arm64/kvm/arm.c | 4 ++
> arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 6 ---
> arch/arm64/kvm/hyp/nvhe/pkvm.c | 54 +++++++++++++++-----------
> arch/arm64/kvm/pkvm.c | 28 ++++++-------
> 6 files changed, 53 insertions(+), 42 deletions(-)
[...]
> static int init_pkvm_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu,
> struct pkvm_hyp_vm *hyp_vm,
> - struct kvm_vcpu *host_vcpu,
> - unsigned int vcpu_idx)
> + struct kvm_vcpu *host_vcpu)
> {
> int ret = 0;
>
> if (hyp_pin_shared_mem(host_vcpu, host_vcpu + 1))
> return -EBUSY;
>
> - if (host_vcpu->vcpu_idx != vcpu_idx) {
> - ret = -EINVAL;
> - goto done;
> - }
> -
> hyp_vcpu->host_vcpu = host_vcpu;
>
> hyp_vcpu->vcpu.kvm = &hyp_vm->kvm;
> hyp_vcpu->vcpu.vcpu_id = READ_ONCE(host_vcpu->vcpu_id);
> - hyp_vcpu->vcpu.vcpu_idx = vcpu_idx;
> + hyp_vcpu->vcpu.vcpu_idx = READ_ONCE(host_vcpu->vcpu_idx);
>
> hyp_vcpu->vcpu.arch.hw_mmu = &hyp_vm->kvm.arch.mmu;
> hyp_vcpu->vcpu.arch.cflags = READ_ONCE(host_vcpu->arch.cflags);
> @@ -687,27 +689,28 @@ int __pkvm_init_vcpu(pkvm_handle_t handle, struct kvm_vcpu *host_vcpu,
> goto unlock;
> }
>
> - idx = hyp_vm->nr_vcpus;
> + ret = init_pkvm_hyp_vcpu(hyp_vcpu, hyp_vm, host_vcpu);
> + if (ret)
> + goto unlock;
> +
> + idx = hyp_vcpu->vcpu.vcpu_idx;
> if (idx >= hyp_vm->kvm.created_vcpus) {
> ret = -EINVAL;
> goto unlock;
> }
>
> - ret = init_pkvm_hyp_vcpu(hyp_vcpu, hyp_vm, host_vcpu, idx);
> - if (ret)
> + if (hyp_vm->vcpus[idx]) {
> + ret = -EINVAL;
> goto unlock;
> + }
I'm not sure how much we care at EL2, but it looks like there's a
potential spectre gadget here given that 'idx' is now untrusted.
Perhaps chuck something like:
idx = array_index_nospec(idx, hyp_vm->kvm.created_vcpus);
before indexing into 'hyp_vm->vcpus[]'?
Either way:
Acked-by: Will Deacon <will@kernel.org>
Will
next prev parent reply other threads:[~2025-02-17 15:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 15:02 [PATCH v1 0/3] KVM: arm64: Fix initializing HCRX_EL2 and other traps in pKVM Fuad Tabba
2025-02-14 15:02 ` [PATCH v1 1/3] KVM: arm64: Initialize HCRX_EL2 " Fuad Tabba
2025-02-26 10:07 ` Oliver Upton
2025-02-26 10:45 ` Marc Zyngier
2025-02-26 12:44 ` Fuad Tabba
2025-02-26 15:28 ` Marc Zyngier
2025-02-26 18:53 ` Oliver Upton
2025-02-26 18:54 ` Fuad Tabba
2025-02-26 12:36 ` Fuad Tabba
2025-02-14 15:02 ` [PATCH v1 2/3] KVM: arm64: Factor out pkvm hyp vcpu creation to separate function Fuad Tabba
2025-02-14 15:02 ` [PATCH v1 3/3] KVM: arm64: Create each pKVM hyp vcpu after its corresponding host vcpu Fuad Tabba
2025-02-17 15:30 ` Will Deacon [this message]
2025-02-17 15:41 ` Fuad Tabba
2025-02-17 15:56 ` Fuad Tabba
2025-02-18 9:27 ` Will Deacon
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=20250217153031.GA16398@willie-the-truck \
--to=will@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vdonnefort@google.com \
--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