Commit a0dd008f authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Add a helper to get the sparse VP_SET for IPIs and TLB flushes

Add a helper, kvm_get_sparse_vp_set(), to handle sanity checks related to
the VARHEAD field and reading the sparse banks of a VP_SET.  A future
commit to reduce the memory footprint of sparse_banks will introduce more
common code to the sparse bank retrieval.

No functional change intended.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20211207220926.718794-5-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 25af9081
...@@ -1754,10 +1754,19 @@ struct kvm_hv_hcall { ...@@ -1754,10 +1754,19 @@ struct kvm_hv_hcall {
sse128_t xmm[HV_HYPERCALL_MAX_XMM_REGISTERS]; sse128_t xmm[HV_HYPERCALL_MAX_XMM_REGISTERS];
}; };
static u64 kvm_get_sparse_vp_set(struct kvm *kvm, struct kvm_hv_hcall *hc,
u64 *sparse_banks, gpa_t offset)
{
if (hc->var_cnt > 64)
return -EINVAL;
return kvm_read_guest(kvm, hc->ingpa + offset, sparse_banks,
hc->var_cnt * sizeof(*sparse_banks));
}
static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ex) static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ex)
{ {
int i; int i;
gpa_t gpa;
struct kvm *kvm = vcpu->kvm; struct kvm *kvm = vcpu->kvm;
struct hv_tlb_flush_ex flush_ex; struct hv_tlb_flush_ex flush_ex;
struct hv_tlb_flush flush; struct hv_tlb_flush flush;
...@@ -1834,13 +1843,9 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1834,13 +1843,9 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool
goto do_flush; goto do_flush;
} }
if (hc->var_cnt > 64) if (kvm_get_sparse_vp_set(kvm, hc, sparse_banks,
return HV_STATUS_INVALID_HYPERCALL_INPUT; offsetof(struct hv_tlb_flush_ex,
hv_vp_set.bank_contents)))
gpa = hc->ingpa + offsetof(struct hv_tlb_flush_ex,
hv_vp_set.bank_contents);
if (unlikely(kvm_read_guest(kvm, gpa, sparse_banks,
hc->var_cnt * sizeof(sparse_banks[0]))))
return HV_STATUS_INVALID_HYPERCALL_INPUT; return HV_STATUS_INVALID_HYPERCALL_INPUT;
} }
...@@ -1937,14 +1942,9 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1937,14 +1942,9 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool
if (!hc->var_cnt) if (!hc->var_cnt)
goto ret_success; goto ret_success;
if (hc->var_cnt > 64) if (kvm_get_sparse_vp_set(kvm, hc, sparse_banks,
return HV_STATUS_INVALID_HYPERCALL_INPUT; offsetof(struct hv_send_ipi_ex,
vp_set.bank_contents)))
if (kvm_read_guest(kvm,
hc->ingpa + offsetof(struct hv_send_ipi_ex,
vp_set.bank_contents),
sparse_banks,
hc->var_cnt * sizeof(sparse_banks[0])))
return HV_STATUS_INVALID_HYPERCALL_INPUT; return HV_STATUS_INVALID_HYPERCALL_INPUT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment