diff mbox series

[v4,04/13] KVM: arm64: Capture VM's first run

Message ID 20220224172559.4170192-5-rananta@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Add support for hypercall services selection | expand

Commit Message

Raghavendra Rao Ananta Feb. 24, 2022, 5:25 p.m. UTC
Capture the first run of the KVM VM, which is basically the
first KVM_RUN issued for any vCPU. This state of the VM is
helpful in the upcoming patches to prevent user-space from
configuring certain VM features, such as the feature bitmap
exposed by the psuedo-firmware registers, after the VM has
started running.

Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
 arch/arm64/include/asm/kvm_host.h | 9 +++++++++
 arch/arm64/kvm/arm.c              | 2 ++
 2 files changed, 11 insertions(+)

Comments

Oliver Upton March 14, 2022, 6:02 p.m. UTC | #1
Hi Raghavendra,

On Thu, Feb 24, 2022 at 05:25:50PM +0000, Raghavendra Rao Ananta wrote:
> Capture the first run of the KVM VM, which is basically the
> first KVM_RUN issued for any vCPU. This state of the VM is
> helpful in the upcoming patches to prevent user-space from
> configuring certain VM features, such as the feature bitmap
> exposed by the psuedo-firmware registers, after the VM has
> started running.
> 
> Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>

I believe this patch is superseded by commit:

  5177fe91e4cf ("KVM: arm64: Do not change the PMU event filter after a VCPU has run")

on kvmarm/next.

--
Thanks,
Oliver
Raghavendra Rao Ananta March 14, 2022, 11:12 p.m. UTC | #2
On Mon, Mar 14, 2022 at 11:02 AM Oliver Upton <oupton@google.com> wrote:
Hi Oliver,
>
> Hi Raghavendra,
>
> On Thu, Feb 24, 2022 at 05:25:50PM +0000, Raghavendra Rao Ananta wrote:
> > Capture the first run of the KVM VM, which is basically the
> > first KVM_RUN issued for any vCPU. This state of the VM is
> > helpful in the upcoming patches to prevent user-space from
> > configuring certain VM features, such as the feature bitmap
> > exposed by the psuedo-firmware registers, after the VM has
> > started running.
> >
> > Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
>
> I believe this patch is superseded by commit:
>
>   5177fe91e4cf ("KVM: arm64: Do not change the PMU event filter after a VCPU has run")
>
> on kvmarm/next.
>
Perfect! Just what we needed. I'll drop this patch.

Regards,
Raghavendra
>
> --
> Thanks,
> Oliver
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 657733554d98..e823571e50cc 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -139,6 +139,9 @@  struct kvm_arch {
 
 	/* Register scoping enabled for KVM registers */
 	bool reg_scope_enabled;
+
+	/* Capture first run of the VM */
+	bool has_run_once;
 };
 
 struct kvm_vcpu_fault_info {
@@ -796,6 +799,12 @@  bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);
 int kvm_trng_call(struct kvm_vcpu *vcpu);
 int kvm_arm_reg_id_encode_scope(struct kvm_vcpu *vcpu, u64 *reg_id);
 void kvm_arm_reg_id_clear_scope(struct kvm_vcpu *vcpu, u64 *reg_id);
+
+static inline bool kvm_arm_vm_has_run_once(struct kvm_arch *kvm_arch)
+{
+	return kvm_arch->has_run_once;
+}
+
 #ifdef CONFIG_KVM
 extern phys_addr_t hyp_mem_base;
 extern phys_addr_t hyp_mem_size;
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 107977c82c6c..f61cd8d57eae 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -635,6 +635,8 @@  int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
 	if (kvm_vm_is_protected(kvm))
 		kvm_call_hyp_nvhe(__pkvm_vcpu_init_traps, vcpu);
 
+	kvm->arch.has_run_once = true;
+
 	return ret;
 }