Skip to content

Commit 4d0b829

Browse files
smaeulMarc Zyngier
authored andcommitted
genirq: Return a const cpumask from irq_data_get_affinity_mask
Now that the irq_data_update_affinity helper exists, enforce its use by returning a a const cpumask from irq_data_get_affinity_mask. Since the previous commit already updated places that needed to call irq_data_update_affinity, this commit updates the remaining code that either did not modify the cpumask or immediately passed the modified mask to irq_set_affinity. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 073352e commit 4d0b829

File tree

10 files changed

+39
-31
lines changed

10 files changed

+39
-31
lines changed

arch/mips/cavium-octeon/octeon-irq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int next_cpu_for_irq(struct irq_data *data)
263263

264264
#ifdef CONFIG_SMP
265265
int cpu;
266-
struct cpumask *mask = irq_data_get_affinity_mask(data);
266+
const struct cpumask *mask = irq_data_get_affinity_mask(data);
267267
int weight = cpumask_weight(mask);
268268
struct octeon_ciu_chip_data *cd = irq_data_get_irq_chip_data(data);
269269

@@ -758,7 +758,7 @@ static void octeon_irq_cpu_offline_ciu(struct irq_data *data)
758758
{
759759
int cpu = smp_processor_id();
760760
cpumask_t new_affinity;
761-
struct cpumask *mask = irq_data_get_affinity_mask(data);
761+
const struct cpumask *mask = irq_data_get_affinity_mask(data);
762762

763763
if (!cpumask_test_cpu(cpu, mask))
764764
return;

arch/sh/kernel/irq.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,17 @@ void migrate_irqs(void)
230230
struct irq_data *data = irq_get_irq_data(irq);
231231

232232
if (irq_data_get_node(data) == cpu) {
233-
struct cpumask *mask = irq_data_get_affinity_mask(data);
233+
const struct cpumask *mask = irq_data_get_affinity_mask(data);
234234
unsigned int newcpu = cpumask_any_and(mask,
235235
cpu_online_mask);
236236
if (newcpu >= nr_cpu_ids) {
237237
pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
238238
irq, cpu);
239239

240-
cpumask_setall(mask);
240+
irq_set_affinity(irq, cpu_all_mask);
241+
} else {
242+
irq_set_affinity(irq, mask);
241243
}
242-
irq_set_affinity(irq, mask);
243244
}
244245
}
245246
}

arch/x86/hyperv/irqdomain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
192192
struct pci_dev *dev;
193193
struct hv_interrupt_entry out_entry, *stored_entry;
194194
struct irq_cfg *cfg = irqd_cfg(data);
195-
cpumask_t *affinity;
195+
const cpumask_t *affinity;
196196
int cpu;
197197
u64 status;
198198

arch/xtensa/kernel/irq.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void migrate_irqs(void)
169169

170170
for_each_active_irq(i) {
171171
struct irq_data *data = irq_get_irq_data(i);
172-
struct cpumask *mask;
172+
const struct cpumask *mask;
173173
unsigned int newcpu;
174174

175175
if (irqd_is_per_cpu(data))
@@ -185,9 +185,10 @@ void migrate_irqs(void)
185185
pr_info_ratelimited("IRQ%u no longer affine to CPU%u\n",
186186
i, cpu);
187187

188-
cpumask_setall(mask);
188+
irq_set_affinity(i, cpu_all_mask);
189+
} else {
190+
irq_set_affinity(i, mask);
189191
}
190-
irq_set_affinity(i, mask);
191192
}
192193
}
193194
#endif /* CONFIG_HOTPLUG_CPU */

drivers/iommu/hyperv-iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ hyperv_root_ir_compose_msi_msg(struct irq_data *irq_data, struct msi_msg *msg)
194194
u32 vector;
195195
struct irq_cfg *cfg;
196196
int ioapic_id;
197-
struct cpumask *affinity;
197+
const struct cpumask *affinity;
198198
int cpu;
199199
struct hv_interrupt_entry entry;
200200
struct hyperv_root_ir_data *data = irq_data->chip_data;

drivers/pci/controller/pci-hyperv.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static void hv_arch_irq_unmask(struct irq_data *data)
642642
struct hv_retarget_device_interrupt *params;
643643
struct tran_int_desc *int_desc;
644644
struct hv_pcibus_device *hbus;
645-
struct cpumask *dest;
645+
const struct cpumask *dest;
646646
cpumask_var_t tmp;
647647
struct pci_bus *pbus;
648648
struct pci_dev *pdev;
@@ -1613,7 +1613,7 @@ static void hv_pci_compose_compl(void *context, struct pci_response *resp,
16131613
}
16141614

16151615
static u32 hv_compose_msi_req_v1(
1616-
struct pci_create_interrupt *int_pkt, struct cpumask *affinity,
1616+
struct pci_create_interrupt *int_pkt, const struct cpumask *affinity,
16171617
u32 slot, u8 vector, u8 vector_count)
16181618
{
16191619
int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE;
@@ -1641,7 +1641,7 @@ static int hv_compose_msi_req_get_cpu(struct cpumask *affinity)
16411641
}
16421642

16431643
static u32 hv_compose_msi_req_v2(
1644-
struct pci_create_interrupt2 *int_pkt, struct cpumask *affinity,
1644+
struct pci_create_interrupt2 *int_pkt, const struct cpumask *affinity,
16451645
u32 slot, u8 vector, u8 vector_count)
16461646
{
16471647
int cpu;
@@ -1660,7 +1660,7 @@ static u32 hv_compose_msi_req_v2(
16601660
}
16611661

16621662
static u32 hv_compose_msi_req_v3(
1663-
struct pci_create_interrupt3 *int_pkt, struct cpumask *affinity,
1663+
struct pci_create_interrupt3 *int_pkt, const struct cpumask *affinity,
16641664
u32 slot, u32 vector, u8 vector_count)
16651665
{
16661666
int cpu;
@@ -1697,7 +1697,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
16971697
struct hv_pci_dev *hpdev;
16981698
struct pci_bus *pbus;
16991699
struct pci_dev *pdev;
1700-
struct cpumask *dest;
1700+
const struct cpumask *dest;
17011701
struct compose_comp_ctxt comp;
17021702
struct tran_int_desc *int_desc;
17031703
struct msi_desc *msi_desc;

include/linux/irq.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ static inline int irq_data_get_node(struct irq_data *d)
879879
return irq_common_data_get_node(d->common);
880880
}
881881

882-
static inline struct cpumask *irq_data_get_affinity_mask(struct irq_data *d)
882+
static inline
883+
const struct cpumask *irq_data_get_affinity_mask(struct irq_data *d)
883884
{
884885
return d->common->affinity;
885886
}
@@ -890,7 +891,7 @@ static inline void irq_data_update_affinity(struct irq_data *d,
890891
cpumask_copy(d->common->affinity, m);
891892
}
892893

893-
static inline struct cpumask *irq_get_affinity_mask(int irq)
894+
static inline const struct cpumask *irq_get_affinity_mask(int irq)
894895
{
895896
struct irq_data *d = irq_get_irq_data(irq);
896897

@@ -899,7 +900,7 @@ static inline struct cpumask *irq_get_affinity_mask(int irq)
899900

900901
#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
901902
static inline
902-
struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
903+
const struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
903904
{
904905
return d->common->effective_affinity;
905906
}
@@ -914,13 +915,14 @@ static inline void irq_data_update_effective_affinity(struct irq_data *d,
914915
{
915916
}
916917
static inline
917-
struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
918+
const struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
918919
{
919920
return irq_data_get_affinity_mask(d);
920921
}
921922
#endif
922923

923-
static inline struct cpumask *irq_get_effective_affinity_mask(unsigned int irq)
924+
static inline
925+
const struct cpumask *irq_get_effective_affinity_mask(unsigned int irq)
924926
{
925927
struct irq_data *d = irq_get_irq_data(irq);
926928

kernel/irq/chip.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ enum {
188188

189189
#ifdef CONFIG_SMP
190190
static int
191-
__irq_startup_managed(struct irq_desc *desc, struct cpumask *aff, bool force)
191+
__irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff,
192+
bool force)
192193
{
193194
struct irq_data *d = irq_desc_get_irq_data(desc);
194195

@@ -224,7 +225,8 @@ __irq_startup_managed(struct irq_desc *desc, struct cpumask *aff, bool force)
224225
}
225226
#else
226227
static __always_inline int
227-
__irq_startup_managed(struct irq_desc *desc, struct cpumask *aff, bool force)
228+
__irq_startup_managed(struct irq_desc *desc, const struct cpumask *aff,
229+
bool force)
228230
{
229231
return IRQ_STARTUP_NORMAL;
230232
}
@@ -252,7 +254,7 @@ static int __irq_startup(struct irq_desc *desc)
252254
int irq_startup(struct irq_desc *desc, bool resend, bool force)
253255
{
254256
struct irq_data *d = irq_desc_get_irq_data(desc);
255-
struct cpumask *aff = irq_data_get_affinity_mask(d);
257+
const struct cpumask *aff = irq_data_get_affinity_mask(d);
256258
int ret = 0;
257259

258260
desc->depth = 0;

kernel/irq/debugfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void irq_debug_show_bits(struct seq_file *m, int ind, unsigned int state,
3030
static void irq_debug_show_masks(struct seq_file *m, struct irq_desc *desc)
3131
{
3232
struct irq_data *data = irq_desc_get_irq_data(desc);
33-
struct cpumask *msk;
33+
const struct cpumask *msk;
3434

3535
msk = irq_data_get_affinity_mask(data);
3636
seq_printf(m, "affinity: %*pbl\n", cpumask_pr_args(msk));

kernel/irq/ipi.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ int irq_reserve_ipi(struct irq_domain *domain,
115115
int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest)
116116
{
117117
struct irq_data *data = irq_get_irq_data(irq);
118-
struct cpumask *ipimask = data ? irq_data_get_affinity_mask(data) : NULL;
118+
const struct cpumask *ipimask;
119119
struct irq_domain *domain;
120120
unsigned int nr_irqs;
121121

122-
if (!irq || !data || !ipimask)
122+
if (!irq || !data)
123123
return -EINVAL;
124124

125125
domain = data->domain;
@@ -131,7 +131,8 @@ int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest)
131131
return -EINVAL;
132132
}
133133

134-
if (WARN_ON(!cpumask_subset(dest, ipimask)))
134+
ipimask = irq_data_get_affinity_mask(data);
135+
if (!ipimask || WARN_ON(!cpumask_subset(dest, ipimask)))
135136
/*
136137
* Must be destroying a subset of CPUs to which this IPI
137138
* was set up to target
@@ -162,12 +163,13 @@ int irq_destroy_ipi(unsigned int irq, const struct cpumask *dest)
162163
irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu)
163164
{
164165
struct irq_data *data = irq_get_irq_data(irq);
165-
struct cpumask *ipimask = data ? irq_data_get_affinity_mask(data) : NULL;
166+
const struct cpumask *ipimask;
166167

167-
if (!data || !ipimask || cpu >= nr_cpu_ids)
168+
if (!data || cpu >= nr_cpu_ids)
168169
return INVALID_HWIRQ;
169170

170-
if (!cpumask_test_cpu(cpu, ipimask))
171+
ipimask = irq_data_get_affinity_mask(data);
172+
if (!ipimask || !cpumask_test_cpu(cpu, ipimask))
171173
return INVALID_HWIRQ;
172174

173175
/*
@@ -186,7 +188,7 @@ EXPORT_SYMBOL_GPL(ipi_get_hwirq);
186188
static int ipi_send_verify(struct irq_chip *chip, struct irq_data *data,
187189
const struct cpumask *dest, unsigned int cpu)
188190
{
189-
struct cpumask *ipimask = irq_data_get_affinity_mask(data);
191+
const struct cpumask *ipimask = irq_data_get_affinity_mask(data);
190192

191193
if (!chip || !ipimask)
192194
return -EINVAL;

0 commit comments

Comments
 (0)