Message ID | 20220802230718.1891356-5-mizhang@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix a race between posted interrupt delivery and migration in a nested VM | expand |
On Tue, Aug 02, 2022, Mingwei Zhang wrote: > Add support for posted interrupt handling in L2. This is done by adding > needed data structures in vmx_pages and APIs to allow an L2 receive posted > interrupts > > Cc: Jim Mattson <jmattson@google.com> > Signed-off-by: Mingwei Zhang <mizhang@google.com> > --- > tools/testing/selftests/kvm/include/x86_64/vmx.h | 10 ++++++++++ > tools/testing/selftests/kvm/lib/x86_64/vmx.c | 16 ++++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h > index 7d8c980317f7..3449ae8ab282 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h > +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h > @@ -579,6 +579,14 @@ struct vmx_pages { > void *apic_access_hva; > uint64_t apic_access_gpa; > void *apic_access; > + > + void *virtual_apic_hva; > + uint64_t virtual_apic_gpa; > + void *virtual_apic; > + > + void *posted_intr_desc_hva; > + uint64_t posted_intr_desc_gpa; > + void *posted_intr_desc; > }; > > union vmx_basic { > @@ -622,5 +630,7 @@ void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm, > void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm, > uint32_t eptp_memslot); > void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm); > +void prepare_virtual_apic(struct vmx_pages *vmx, struct kvm_vm *vm); > +void prepare_posted_intr_desc(struct vmx_pages *vmx, struct kvm_vm *vm); > > #endif /* SELFTEST_KVM_VMX_H */ > diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/selftests/kvm/lib/x86_64/vmx.c > index 80a568c439b8..7d65bee37b9f 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c > @@ -556,3 +556,19 @@ void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm) > vmx->apic_access_hva = addr_gva2hva(vm, (uintptr_t)vmx->apic_access); > vmx->apic_access_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->apic_access); > } > + > +void prepare_virtual_apic(struct vmx_pages *vmx, struct kvm_vm *vm) > +{ > + vmx->virtual_apic = (void *)vm_vaddr_alloc_page(vm); > + vmx->virtual_apic_hva = addr_gva2hva(vm, (uintptr_t)vmx->virtual_apic); > + vmx->virtual_apic_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->virtual_apic); > +} > + > +void prepare_posted_intr_desc(struct vmx_pages *vmx, struct kvm_vm *vm) > +{ > + vmx->posted_intr_desc = (void *)vm_vaddr_alloc_page(vm); > + vmx->posted_intr_desc_hva = > + addr_gva2hva(vm, (uintptr_t)vmx->posted_intr_desc); > + vmx->posted_intr_desc_gpa = > + addr_gva2gpa(vm, (uintptr_t)vmx->posted_intr_desc); Let these poke out, or capture the field in a local var. Actually, posted_intr_desc is a void *, is casting even necessary? > +} > -- > 2.37.1.455.g008518b4e5-goog >
On Thu, Aug 25, 2022, Sean Christopherson wrote: > > + > > +void prepare_virtual_apic(struct vmx_pages *vmx, struct kvm_vm *vm) > > +{ > > + vmx->virtual_apic = (void *)vm_vaddr_alloc_page(vm); > > + vmx->virtual_apic_hva = addr_gva2hva(vm, (uintptr_t)vmx->virtual_apic); > > + vmx->virtual_apic_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->virtual_apic); > > +} > > + > > +void prepare_posted_intr_desc(struct vmx_pages *vmx, struct kvm_vm *vm) > > +{ > > + vmx->posted_intr_desc = (void *)vm_vaddr_alloc_page(vm); > > + vmx->posted_intr_desc_hva = > > + addr_gva2hva(vm, (uintptr_t)vmx->posted_intr_desc); > > + vmx->posted_intr_desc_gpa = > > + addr_gva2gpa(vm, (uintptr_t)vmx->posted_intr_desc); > > Let these poke out, or capture the field in a local var. Actually, posted_intr_desc > is a void *, is casting even necessary? > Will do. Yeah, casting is necessary here because add_ga2gpa takes 'vm_vaddr_t' which is the 'long unsigned int', so we have to cast it. > > > +} > > -- > > 2.37.1.455.g008518b4e5-goog > >
diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h index 7d8c980317f7..3449ae8ab282 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -579,6 +579,14 @@ struct vmx_pages { void *apic_access_hva; uint64_t apic_access_gpa; void *apic_access; + + void *virtual_apic_hva; + uint64_t virtual_apic_gpa; + void *virtual_apic; + + void *posted_intr_desc_hva; + uint64_t posted_intr_desc_gpa; + void *posted_intr_desc; }; union vmx_basic { @@ -622,5 +630,7 @@ void nested_identity_map_1g(struct vmx_pages *vmx, struct kvm_vm *vm, void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm, uint32_t eptp_memslot); void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm); +void prepare_virtual_apic(struct vmx_pages *vmx, struct kvm_vm *vm); +void prepare_posted_intr_desc(struct vmx_pages *vmx, struct kvm_vm *vm); #endif /* SELFTEST_KVM_VMX_H */ diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/selftests/kvm/lib/x86_64/vmx.c index 80a568c439b8..7d65bee37b9f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -556,3 +556,19 @@ void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm) vmx->apic_access_hva = addr_gva2hva(vm, (uintptr_t)vmx->apic_access); vmx->apic_access_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->apic_access); } + +void prepare_virtual_apic(struct vmx_pages *vmx, struct kvm_vm *vm) +{ + vmx->virtual_apic = (void *)vm_vaddr_alloc_page(vm); + vmx->virtual_apic_hva = addr_gva2hva(vm, (uintptr_t)vmx->virtual_apic); + vmx->virtual_apic_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->virtual_apic); +} + +void prepare_posted_intr_desc(struct vmx_pages *vmx, struct kvm_vm *vm) +{ + vmx->posted_intr_desc = (void *)vm_vaddr_alloc_page(vm); + vmx->posted_intr_desc_hva = + addr_gva2hva(vm, (uintptr_t)vmx->posted_intr_desc); + vmx->posted_intr_desc_gpa = + addr_gva2gpa(vm, (uintptr_t)vmx->posted_intr_desc); +}
Add support for posted interrupt handling in L2. This is done by adding needed data structures in vmx_pages and APIs to allow an L2 receive posted interrupts Cc: Jim Mattson <jmattson@google.com> Signed-off-by: Mingwei Zhang <mizhang@google.com> --- tools/testing/selftests/kvm/include/x86_64/vmx.h | 10 ++++++++++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+)