Commit c0f1eaeb authored by Paolo Bonzini's avatar Paolo Bonzini

Merge branch 'kvm-hv-xmm-hypercall-fixes' into HEAD

The fixes for 5.17 conflict with cleanups made in the same area
earlier in the 5.18 development cycle.
parents 4dfc4ec2 47d3e5cd
...@@ -1770,9 +1770,11 @@ struct kvm_hv_hcall { ...@@ -1770,9 +1770,11 @@ struct kvm_hv_hcall {
}; };
static u64 kvm_get_sparse_vp_set(struct kvm *kvm, struct kvm_hv_hcall *hc, static u64 kvm_get_sparse_vp_set(struct kvm *kvm, struct kvm_hv_hcall *hc,
int consumed_xmm_halves,
u64 *sparse_banks, gpa_t offset) u64 *sparse_banks, gpa_t offset)
{ {
u16 var_cnt; u16 var_cnt;
int i;
if (hc->var_cnt > 64) if (hc->var_cnt > 64)
return -EINVAL; return -EINVAL;
...@@ -1780,13 +1782,29 @@ static u64 kvm_get_sparse_vp_set(struct kvm *kvm, struct kvm_hv_hcall *hc, ...@@ -1780,13 +1782,29 @@ static u64 kvm_get_sparse_vp_set(struct kvm *kvm, struct kvm_hv_hcall *hc,
/* Ignore banks that cannot possibly contain a legal VP index. */ /* Ignore banks that cannot possibly contain a legal VP index. */
var_cnt = min_t(u16, hc->var_cnt, KVM_HV_MAX_SPARSE_VCPU_SET_BITS); var_cnt = min_t(u16, hc->var_cnt, KVM_HV_MAX_SPARSE_VCPU_SET_BITS);
if (hc->fast) {
/*
* Each XMM holds two sparse banks, but do not count halves that
* have already been consumed for hypercall parameters.
*/
if (hc->var_cnt > 2 * HV_HYPERCALL_MAX_XMM_REGISTERS - consumed_xmm_halves)
return HV_STATUS_INVALID_HYPERCALL_INPUT;
for (i = 0; i < var_cnt; i++) {
int j = i + consumed_xmm_halves;
if (j % 2)
sparse_banks[i] = sse128_hi(hc->xmm[j / 2]);
else
sparse_banks[i] = sse128_lo(hc->xmm[j / 2]);
}
return 0;
}
return kvm_read_guest(kvm, hc->ingpa + offset, sparse_banks, return kvm_read_guest(kvm, hc->ingpa + offset, sparse_banks,
var_cnt * sizeof(*sparse_banks)); 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)
{ {
int i;
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;
...@@ -1803,7 +1821,8 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1803,7 +1821,8 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool
*/ */
BUILD_BUG_ON(KVM_HV_MAX_SPARSE_VCPU_SET_BITS > 64); BUILD_BUG_ON(KVM_HV_MAX_SPARSE_VCPU_SET_BITS > 64);
if (!ex) { if (hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST ||
hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE) {
if (hc->fast) { if (hc->fast) {
flush.address_space = hc->ingpa; flush.address_space = hc->ingpa;
flush.flags = hc->outgpa; flush.flags = hc->outgpa;
...@@ -1859,17 +1878,7 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1859,17 +1878,7 @@ static u64 kvm_hv_flush_tlb(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->fast) { if (kvm_get_sparse_vp_set(kvm, hc, 2, sparse_banks,
if (hc->var_cnt > HV_HYPERCALL_MAX_XMM_REGISTERS - 1)
return HV_STATUS_INVALID_HYPERCALL_INPUT;
for (i = 0; i < hc->var_cnt; i += 2) {
sparse_banks[i] = sse128_lo(hc->xmm[i / 2 + 1]);
sparse_banks[i + 1] = sse128_hi(hc->xmm[i / 2 + 1]);
}
goto do_flush;
}
if (kvm_get_sparse_vp_set(kvm, hc, sparse_banks,
offsetof(struct hv_tlb_flush_ex, offsetof(struct hv_tlb_flush_ex,
hv_vp_set.bank_contents))) hv_vp_set.bank_contents)))
return HV_STATUS_INVALID_HYPERCALL_INPUT; return HV_STATUS_INVALID_HYPERCALL_INPUT;
...@@ -1913,7 +1922,7 @@ static void kvm_send_ipi_to_many(struct kvm *kvm, u32 vector, ...@@ -1913,7 +1922,7 @@ static void kvm_send_ipi_to_many(struct kvm *kvm, u32 vector,
} }
} }
static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ex) static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc)
{ {
struct kvm *kvm = vcpu->kvm; struct kvm *kvm = vcpu->kvm;
struct hv_send_ipi_ex send_ipi_ex; struct hv_send_ipi_ex send_ipi_ex;
...@@ -1924,7 +1933,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1924,7 +1933,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool
u32 vector; u32 vector;
bool all_cpus; bool all_cpus;
if (!ex) { if (hc->code == HVCALL_SEND_IPI) {
if (!hc->fast) { if (!hc->fast) {
if (unlikely(kvm_read_guest(kvm, hc->ingpa, &send_ipi, if (unlikely(kvm_read_guest(kvm, hc->ingpa, &send_ipi,
sizeof(send_ipi)))) sizeof(send_ipi))))
...@@ -1943,9 +1952,15 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1943,9 +1952,15 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool
trace_kvm_hv_send_ipi(vector, sparse_banks[0]); trace_kvm_hv_send_ipi(vector, sparse_banks[0]);
} else { } else {
if (unlikely(kvm_read_guest(kvm, hc->ingpa, &send_ipi_ex, if (!hc->fast) {
sizeof(send_ipi_ex)))) if (unlikely(kvm_read_guest(kvm, hc->ingpa, &send_ipi_ex,
return HV_STATUS_INVALID_HYPERCALL_INPUT; sizeof(send_ipi_ex))))
return HV_STATUS_INVALID_HYPERCALL_INPUT;
} else {
send_ipi_ex.vector = (u32)hc->ingpa;
send_ipi_ex.vp_set.format = hc->outgpa;
send_ipi_ex.vp_set.valid_bank_mask = sse128_lo(hc->xmm[0]);
}
trace_kvm_hv_send_ipi_ex(send_ipi_ex.vector, trace_kvm_hv_send_ipi_ex(send_ipi_ex.vector,
send_ipi_ex.vp_set.format, send_ipi_ex.vp_set.format,
...@@ -1964,7 +1979,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc, bool ...@@ -1964,7 +1979,7 @@ 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 (kvm_get_sparse_vp_set(kvm, hc, sparse_banks, if (kvm_get_sparse_vp_set(kvm, hc, 1, sparse_banks,
offsetof(struct hv_send_ipi_ex, offsetof(struct hv_send_ipi_ex,
vp_set.bank_contents))) vp_set.bank_contents)))
return HV_STATUS_INVALID_HYPERCALL_INPUT; return HV_STATUS_INVALID_HYPERCALL_INPUT;
...@@ -2126,6 +2141,7 @@ static bool is_xmm_fast_hypercall(struct kvm_hv_hcall *hc) ...@@ -2126,6 +2141,7 @@ static bool is_xmm_fast_hypercall(struct kvm_hv_hcall *hc)
case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE:
case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX:
case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX: case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX:
case HVCALL_SEND_IPI_EX:
return true; return true;
} }
...@@ -2283,46 +2299,43 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) ...@@ -2283,46 +2299,43 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
kvm_hv_hypercall_complete_userspace; kvm_hv_hypercall_complete_userspace;
return 0; return 0;
case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST:
if (unlikely(!hc.rep_cnt || hc.rep_idx || hc.var_cnt)) { if (unlikely(hc.var_cnt)) {
ret = HV_STATUS_INVALID_HYPERCALL_INPUT; ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
break; break;
} }
ret = kvm_hv_flush_tlb(vcpu, &hc, false); fallthrough;
break; case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX:
case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: if (unlikely(!hc.rep_cnt || hc.rep_idx)) {
if (unlikely(hc.rep || hc.var_cnt)) {
ret = HV_STATUS_INVALID_HYPERCALL_INPUT; ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
break; break;
} }
ret = kvm_hv_flush_tlb(vcpu, &hc, false); ret = kvm_hv_flush_tlb(vcpu, &hc);
break; break;
case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX: case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE:
if (unlikely(!hc.rep_cnt || hc.rep_idx)) { if (unlikely(hc.var_cnt)) {
ret = HV_STATUS_INVALID_HYPERCALL_INPUT; ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
break; break;
} }
ret = kvm_hv_flush_tlb(vcpu, &hc, true); fallthrough;
break;
case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX: case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX:
if (unlikely(hc.rep)) { if (unlikely(hc.rep)) {
ret = HV_STATUS_INVALID_HYPERCALL_INPUT; ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
break; break;
} }
ret = kvm_hv_flush_tlb(vcpu, &hc, true); ret = kvm_hv_flush_tlb(vcpu, &hc);
break; break;
case HVCALL_SEND_IPI: case HVCALL_SEND_IPI:
if (unlikely(hc.rep || hc.var_cnt)) { if (unlikely(hc.var_cnt)) {
ret = HV_STATUS_INVALID_HYPERCALL_INPUT; ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
break; break;
} }
ret = kvm_hv_send_ipi(vcpu, &hc, false); fallthrough;
break;
case HVCALL_SEND_IPI_EX: case HVCALL_SEND_IPI_EX:
if (unlikely(hc.fast || hc.rep)) { if (unlikely(hc.rep)) {
ret = HV_STATUS_INVALID_HYPERCALL_INPUT; ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
break; break;
} }
ret = kvm_hv_send_ipi(vcpu, &hc, true); ret = kvm_hv_send_ipi(vcpu, &hc);
break; break;
case HVCALL_POST_DEBUG_DATA: case HVCALL_POST_DEBUG_DATA:
case HVCALL_RETRIEVE_DEBUG_DATA: case HVCALL_RETRIEVE_DEBUG_DATA:
......
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