[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6c691bc5-dbfc-46f9-8c09-9c74c51d8708@gmail.com>
Date: Wed, 30 Aug 2023 23:04:21 +0800
From: Like Xu <like.xu.linux@...il.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: kvm@...r.kernel.org, intel-gvt-dev@...ts.freedesktop.org,
intel-gfx@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
Yan Zhao <yan.y.zhao@...el.com>,
Yongwei Ma <yongwei.ma@...el.com>,
Ben Gardon <bgardon@...gle.com>,
Zhenyu Wang <zhenyuw@...ux.intel.com>,
Zhi Wang <zhi.a.wang@...el.com>,
Paolo Bonzini <pbonzini@...hat.com>
Subject: Re: [PATCH v4 16/29] KVM: x86: Reject memslot MOVE operations if
KVMGT is attached
On 2023/7/29 09:35, Sean Christopherson wrote:
> Disallow moving memslots if the VM has external page-track users, i.e. if
> KVMGT is being used to expose a virtual GPU to the guest, as KVMGT doesn't
> correctly handle moving memory regions.
>
> Note, this is potential ABI breakage! E.g. userspace could move regions
> that aren't shadowed by KVMGT without harming the guest. However, the
> only known user of KVMGT is QEMU, and QEMU doesn't move generic memory
This change breaks two kvm selftests:
- set_memory_region_test;
- memslot_perf_test;
Please help confirm if the tests/doc needs to be updated,
or if the assumption needs to be further clarified.
> regions. KVM's own support for moving memory regions was also broken for
> multiple years (albeit for an edge case, but arguably moving RAM is
> itself an edge case), e.g. see commit edd4fa37baa6 ("KVM: x86: Allocate
> new rmap and large page tracking when moving memslot").
>
> Reviewed-by: Yan Zhao <yan.y.zhao@...el.com>
> Tested-by: Yongwei Ma <yongwei.ma@...el.com>
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> ---
> arch/x86/include/asm/kvm_page_track.h | 3 +++
> arch/x86/kvm/mmu/page_track.c | 5 +++++
> arch/x86/kvm/x86.c | 7 +++++++
> 3 files changed, 15 insertions(+)
>
> diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/kvm_page_track.h
> index 8c4d216e3b2b..f744682648e7 100644
> --- a/arch/x86/include/asm/kvm_page_track.h
> +++ b/arch/x86/include/asm/kvm_page_track.h
> @@ -75,4 +75,7 @@ kvm_page_track_unregister_notifier(struct kvm *kvm,
> void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new,
> int bytes);
> void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot);
> +
> +bool kvm_page_track_has_external_user(struct kvm *kvm);
> +
> #endif
> diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c
> index 891e5cc52b45..e6de9638e560 100644
> --- a/arch/x86/kvm/mmu/page_track.c
> +++ b/arch/x86/kvm/mmu/page_track.c
> @@ -303,3 +303,8 @@ void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot)
> n->track_flush_slot(kvm, slot, n);
> srcu_read_unlock(&head->track_srcu, idx);
> }
> +
> +bool kvm_page_track_has_external_user(struct kvm *kvm)
> +{
> + return hlist_empty(&kvm->arch.track_notifier_head.track_notifier_list);
> +}
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 059571d5abed..4394bb49051f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -12606,6 +12606,13 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
> struct kvm_memory_slot *new,
> enum kvm_mr_change change)
> {
> + /*
> + * KVM doesn't support moving memslots when there are external page
> + * trackers attached to the VM, i.e. if KVMGT is in use.
> + */
> + if (change == KVM_MR_MOVE && kvm_page_track_has_external_user(kvm))
> + return -EINVAL;
> +
> if (change == KVM_MR_CREATE || change == KVM_MR_MOVE) {
> if ((new->base_gfn + new->npages - 1) > kvm_mmu_max_gfn())
> return -EINVAL;
Powered by blists - more mailing lists