Commit bd19c94a authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

x86/hyperv: Introduce HV_MAX_SPARSE_VCPU_BANKS/HV_VCPUS_PER_SPARSE_BANK constants

It may not come clear from where the magical '64' value used in
__cpumask_to_vpset() come from. Moreover, '64' means both the maximum
sparse bank number as well as the number of vCPUs per bank. Add defines
to make things clear. These defines are also going to be used by KVM.

No functional change.
Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221101145426.251680-15-vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent aee73823
...@@ -399,6 +399,11 @@ struct hv_vpset { ...@@ -399,6 +399,11 @@ struct hv_vpset {
u64 bank_contents[]; u64 bank_contents[];
} __packed; } __packed;
/* The maximum number of sparse vCPU banks which can be encoded by 'struct hv_vpset' */
#define HV_MAX_SPARSE_VCPU_BANKS (64)
/* The number of vCPUs in one sparse bank */
#define HV_VCPUS_PER_SPARSE_BANK (64)
/* HvCallSendSyntheticClusterIpi hypercall */ /* HvCallSendSyntheticClusterIpi hypercall */
struct hv_send_ipi { struct hv_send_ipi {
u32 vector; u32 vector;
......
...@@ -211,9 +211,10 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset, ...@@ -211,9 +211,10 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
{ {
int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1; int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1;
int this_cpu = smp_processor_id(); int this_cpu = smp_processor_id();
int max_vcpu_bank = hv_max_vp_index / HV_VCPUS_PER_SPARSE_BANK;
/* valid_bank_mask can represent up to 64 banks */ /* vpset.valid_bank_mask can represent up to HV_MAX_SPARSE_VCPU_BANKS banks */
if (hv_max_vp_index / 64 >= 64) if (max_vcpu_bank >= HV_MAX_SPARSE_VCPU_BANKS)
return 0; return 0;
/* /*
...@@ -221,7 +222,7 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset, ...@@ -221,7 +222,7 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
* structs are not cleared between calls, we risk flushing unneeded * structs are not cleared between calls, we risk flushing unneeded
* vCPUs otherwise. * vCPUs otherwise.
*/ */
for (vcpu_bank = 0; vcpu_bank <= hv_max_vp_index / 64; vcpu_bank++) for (vcpu_bank = 0; vcpu_bank <= max_vcpu_bank; vcpu_bank++)
vpset->bank_contents[vcpu_bank] = 0; vpset->bank_contents[vcpu_bank] = 0;
/* /*
...@@ -233,8 +234,8 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset, ...@@ -233,8 +234,8 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
vcpu = hv_cpu_number_to_vp_number(cpu); vcpu = hv_cpu_number_to_vp_number(cpu);
if (vcpu == VP_INVAL) if (vcpu == VP_INVAL)
return -1; return -1;
vcpu_bank = vcpu / 64; vcpu_bank = vcpu / HV_VCPUS_PER_SPARSE_BANK;
vcpu_offset = vcpu % 64; vcpu_offset = vcpu % HV_VCPUS_PER_SPARSE_BANK;
__set_bit(vcpu_offset, (unsigned long *) __set_bit(vcpu_offset, (unsigned long *)
&vpset->bank_contents[vcpu_bank]); &vpset->bank_contents[vcpu_bank]);
if (vcpu_bank >= nr_bank) if (vcpu_bank >= nr_bank)
......
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