Skip to content

Commit 18374d8

Browse files
Suresh SiddhaH. Peter Anvin
authored andcommitted
x86, irq: Allow 0xff for /proc/irq/[n]/smp_affinity on an 8-cpu system
John Blackwood reported: > on an older Dell PowerEdge 6650 system with 8 cpus (4 are hyper-threaded), > and 32 bit (x86) kernel, once you change the irq smp_affinity of an irq > to be less than all cpus in the system, you can never change really the > irq smp_affinity back to be all cpus in the system (0xff) again, > even though no error status is returned on the "/bin/echo ff > > /proc/irq/[n]/smp_affinity" operation. > > This is due to that fact that BAD_APICID has the same value as > all cpus (0xff) on 32bit kernels, and thus the value returned from > set_desc_affinity() via the cpu_mask_to_apicid_and() function is treated > as a failure in set_ioapic_affinity_irq_desc(), and no affinity changes > are made. set_desc_affinity() is already checking if the incoming cpu mask intersects with the cpu online mask or not. So there is no need for the apic op cpu_mask_to_apicid_and() to check again and return BAD_APICID. Remove the BAD_APICID return value from cpu_mask_to_apicid_and() and also fix set_desc_affinity() to return -1 instead of using BAD_APICID to represent error conditions (as cpu_mask_to_apicid_and() can return logical or physical apicid values and BAD_APICID is really to represent bad physical apic id). Reported-by: John Blackwood <john.blackwood@ccur.com> Root-caused-by: John Blackwood <john.blackwood@ccur.com> Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> LKML-Reference: <1261103386.2535.409.camel@sbs-t61> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 06b5dc6 commit 18374d8

8 files changed

Lines changed: 22 additions & 41 deletions

File tree

‎arch/x86/include/asm/hw_irq.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ extern int assign_irq_vector(int, struct irq_cfg *, const struct cpumask *);
103103
extern void send_cleanup_vector(struct irq_cfg *);
104104

105105
struct irq_desc;
106-
extern unsigned int set_desc_affinity(struct irq_desc *, const struct cpumask *);
106+
extern unsigned int set_desc_affinity(struct irq_desc *, const struct cpumask *,
107+
unsigned int *dest_id);
107108
extern int IO_APIC_get_PCI_irq_vector(int bus, int devfn, int pin, struct io_apic_irq_attr *irq_attr);
108109
extern void setup_ioapic_dest(void);
109110

‎arch/x86/kernel/apic/apic_flat_64.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,7 @@ physflat_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
306306
if (cpumask_test_cpu(cpu, cpu_online_mask))
307307
break;
308308
}
309-
if (cpu < nr_cpu_ids)
310-
return per_cpu(x86_cpu_to_apicid, cpu);
311-
312-
return BAD_APICID;
309+
return per_cpu(x86_cpu_to_apicid, cpu);
313310
}
314311

315312
struct apic apic_physflat = {

‎arch/x86/kernel/apic/bigsmp_32.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ static unsigned int bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
131131
if (cpumask_test_cpu(cpu, cpu_online_mask))
132132
break;
133133
}
134-
if (cpu < nr_cpu_ids)
135-
return bigsmp_cpu_to_logical_apicid(cpu);
136-
137-
return BAD_APICID;
134+
return bigsmp_cpu_to_logical_apicid(cpu);
138135
}
139136

140137
static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)

‎arch/x86/kernel/apic/io_apic.c‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,26 +2276,28 @@ static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq
22762276

22772277
/*
22782278
* Either sets desc->affinity to a valid value, and returns
2279-
* ->cpu_mask_to_apicid of that, or returns BAD_APICID and
2279+
* ->cpu_mask_to_apicid of that in dest_id, or returns -1 and
22802280
* leaves desc->affinity untouched.
22812281
*/
22822282
unsigned int
2283-
set_desc_affinity(struct irq_desc *desc, const struct cpumask *mask)
2283+
set_desc_affinity(struct irq_desc *desc, const struct cpumask *mask,
2284+
unsigned int *dest_id)
22842285
{
22852286
struct irq_cfg *cfg;
22862287
unsigned int irq;
22872288

22882289
if (!cpumask_intersects(mask, cpu_online_mask))
2289-
return BAD_APICID;
2290+
return -1;
22902291

22912292
irq = desc->irq;
22922293
cfg = desc->chip_data;
22932294
if (assign_irq_vector(irq, cfg, mask))
2294-
return BAD_APICID;
2295+
return -1;
22952296

22962297
cpumask_copy(desc->affinity, mask);
22972298

2298-
return apic->cpu_mask_to_apicid_and(desc->affinity, cfg->domain);
2299+
*dest_id = apic->cpu_mask_to_apicid_and(desc->affinity, cfg->domain);
2300+
return 0;
22992301
}
23002302

23012303
static int
@@ -2311,12 +2313,11 @@ set_ioapic_affinity_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
23112313
cfg = desc->chip_data;
23122314

23132315
spin_lock_irqsave(&ioapic_lock, flags);
2314-
dest = set_desc_affinity(desc, mask);
2315-
if (dest != BAD_APICID) {
2316+
ret = set_desc_affinity(desc, mask, &dest);
2317+
if (!ret) {
23162318
/* Only the high 8 bits are valid. */
23172319
dest = SET_APIC_LOGICAL_ID(dest);
23182320
__target_IO_APIC_irq(irq, dest, cfg);
2319-
ret = 0;
23202321
}
23212322
spin_unlock_irqrestore(&ioapic_lock, flags);
23222323

@@ -3351,8 +3352,7 @@ static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
33513352
struct msi_msg msg;
33523353
unsigned int dest;
33533354

3354-
dest = set_desc_affinity(desc, mask);
3355-
if (dest == BAD_APICID)
3355+
if (set_desc_affinity(desc, mask, &dest))
33563356
return -1;
33573357

33583358
cfg = desc->chip_data;
@@ -3384,8 +3384,7 @@ ir_set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
33843384
if (get_irte(irq, &irte))
33853385
return -1;
33863386

3387-
dest = set_desc_affinity(desc, mask);
3388-
if (dest == BAD_APICID)
3387+
if (set_desc_affinity(desc, mask, &dest))
33893388
return -1;
33903389

33913390
irte.vector = cfg->vector;
@@ -3567,8 +3566,7 @@ static int dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
35673566
struct msi_msg msg;
35683567
unsigned int dest;
35693568

3570-
dest = set_desc_affinity(desc, mask);
3571-
if (dest == BAD_APICID)
3569+
if (set_desc_affinity(desc, mask, &dest))
35723570
return -1;
35733571

35743572
cfg = desc->chip_data;
@@ -3623,8 +3621,7 @@ static int hpet_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
36233621
struct msi_msg msg;
36243622
unsigned int dest;
36253623

3626-
dest = set_desc_affinity(desc, mask);
3627-
if (dest == BAD_APICID)
3624+
if (set_desc_affinity(desc, mask, &dest))
36283625
return -1;
36293626

36303627
cfg = desc->chip_data;
@@ -3730,8 +3727,7 @@ static int set_ht_irq_affinity(unsigned int irq, const struct cpumask *mask)
37303727
struct irq_cfg *cfg;
37313728
unsigned int dest;
37323729

3733-
dest = set_desc_affinity(desc, mask);
3734-
if (dest == BAD_APICID)
3730+
if (set_desc_affinity(desc, mask, &dest))
37353731
return -1;
37363732

37373733
cfg = desc->chip_data;

‎arch/x86/kernel/apic/x2apic_cluster.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
148148
break;
149149
}
150150

151-
if (cpu < nr_cpu_ids)
152-
return per_cpu(x86_cpu_to_logical_apicid, cpu);
153-
154-
return BAD_APICID;
151+
return per_cpu(x86_cpu_to_logical_apicid, cpu);
155152
}
156153

157154
static unsigned int x2apic_cluster_phys_get_apic_id(unsigned long x)

‎arch/x86/kernel/apic/x2apic_phys.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@ x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
146146
break;
147147
}
148148

149-
if (cpu < nr_cpu_ids)
150-
return per_cpu(x86_cpu_to_apicid, cpu);
151-
152-
return BAD_APICID;
149+
return per_cpu(x86_cpu_to_apicid, cpu);
153150
}
154151

155152
static unsigned int x2apic_phys_get_apic_id(unsigned long x)

‎arch/x86/kernel/apic/x2apic_uv_x.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ uv_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
225225
if (cpumask_test_cpu(cpu, cpu_online_mask))
226226
break;
227227
}
228-
if (cpu < nr_cpu_ids)
229-
return per_cpu(x86_cpu_to_apicid, cpu);
230-
231-
return BAD_APICID;
228+
return per_cpu(x86_cpu_to_apicid, cpu);
232229
}
233230

234231
static unsigned int x2apic_get_apic_id(unsigned long x)

‎arch/x86/kernel/uv_irq.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ static int uv_set_irq_affinity(unsigned int irq, const struct cpumask *mask)
215215
unsigned long mmr_offset;
216216
unsigned mmr_pnode;
217217

218-
dest = set_desc_affinity(desc, mask);
219-
if (dest == BAD_APICID)
218+
if (set_desc_affinity(desc, mask, &dest))
220219
return -1;
221220

222221
mmr_value = 0;

0 commit comments

Comments
 (0)