Skip to content

Commit d7b6ba9

Browse files
kelleymhliuw
authored andcommitted
x86/hyperv: Add callback filter to cpumask_to_vpset()
When copying CPUs from a Linux cpumask to a Hyper-V VPset, cpumask_to_vpset() currently has a "_noself" variant that doesn't copy the current CPU to the VPset. Generalize this variant by replacing it with a "_skip" variant having a callback function that is invoked for each CPU to decide if that CPU should be copied. Update the one caller of cpumask_to_vpset_noself() to use the new "_skip" variant instead. No functional change. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/1679922967-26582-2-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 9a6b1a1 commit d7b6ba9

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

arch/x86/hyperv/hv_apic.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ static void hv_apic_eoi_write(u32 reg, u32 val)
9696
wrmsr(HV_X64_MSR_EOI, val, 0);
9797
}
9898

99+
static bool cpu_is_self(int cpu)
100+
{
101+
return cpu == smp_processor_id();
102+
}
103+
99104
/*
100105
* IPI implementation on Hyper-V.
101106
*/
@@ -128,10 +133,9 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector,
128133
*/
129134
if (!cpumask_equal(mask, cpu_present_mask) || exclude_self) {
130135
ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K;
131-
if (exclude_self)
132-
nr_bank = cpumask_to_vpset_noself(&(ipi_arg->vp_set), mask);
133-
else
134-
nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask);
136+
137+
nr_bank = cpumask_to_vpset_skip(&(ipi_arg->vp_set), mask,
138+
exclude_self ? cpu_is_self : NULL);
135139

136140
/*
137141
* 'nr_bank <= 0' means some CPUs in cpumask can't be

include/asm-generic/mshyperv.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number)
210210

211211
static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
212212
const struct cpumask *cpus,
213-
bool exclude_self)
213+
bool (*func)(int cpu))
214214
{
215215
int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1;
216-
int this_cpu = smp_processor_id();
217216
int max_vcpu_bank = hv_max_vp_index / HV_VCPUS_PER_SPARSE_BANK;
218217

219218
/* vpset.valid_bank_mask can represent up to HV_MAX_SPARSE_VCPU_BANKS banks */
@@ -232,7 +231,7 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
232231
* Some banks may end up being empty but this is acceptable.
233232
*/
234233
for_each_cpu(cpu, cpus) {
235-
if (exclude_self && cpu == this_cpu)
234+
if (func && func(cpu))
236235
continue;
237236
vcpu = hv_cpu_number_to_vp_number(cpu);
238237
if (vcpu == VP_INVAL)
@@ -248,17 +247,24 @@ static inline int __cpumask_to_vpset(struct hv_vpset *vpset,
248247
return nr_bank;
249248
}
250249

250+
/*
251+
* Convert a Linux cpumask into a Hyper-V VPset. In the _skip variant,
252+
* 'func' is called for each CPU present in cpumask. If 'func' returns
253+
* true, that CPU is skipped -- i.e., that CPU from cpumask is *not*
254+
* added to the Hyper-V VPset. If 'func' is NULL, no CPUs are
255+
* skipped.
256+
*/
251257
static inline int cpumask_to_vpset(struct hv_vpset *vpset,
252258
const struct cpumask *cpus)
253259
{
254-
return __cpumask_to_vpset(vpset, cpus, false);
260+
return __cpumask_to_vpset(vpset, cpus, NULL);
255261
}
256262

257-
static inline int cpumask_to_vpset_noself(struct hv_vpset *vpset,
258-
const struct cpumask *cpus)
263+
static inline int cpumask_to_vpset_skip(struct hv_vpset *vpset,
264+
const struct cpumask *cpus,
265+
bool (*func)(int cpu))
259266
{
260-
WARN_ON_ONCE(preemptible());
261-
return __cpumask_to_vpset(vpset, cpus, true);
267+
return __cpumask_to_vpset(vpset, cpus, func);
262268
}
263269

264270
void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die);

0 commit comments

Comments
 (0)