Skip to content

Commit 4c16481

Browse files
Sean Andersonsmb49
authored andcommitted
gpio: xilinx: Convert gpio_lock to raw spinlock
BugLink: https://bugs.launchpad.net/bugs/2107449 commit 9860370c2172704b6b4f0075a0c2a29fd84af96a upstream. irq_chip functions may be called in raw spinlock context. Therefore, we must also use a raw spinlock for our own internal locking. This fixes the following lockdep splat: [ 5.349336] ============================= [ 5.353349] [ BUG: Invalid wait context ] [ 5.357361] 6.13.0-rc5+ #69 Tainted: G W [ 5.363031] ----------------------------- [ 5.367045] kworker/u17:1/44 is trying to lock: [ 5.371587] ffffff88018b02c0 (&chip->gpio_lock){....}-{3:3}, at: xgpio_irq_unmask (drivers/gpio/gpio-xilinx.c:433 (discriminator 8)) [ 5.380079] other info that might help us debug this: [ 5.385138] context-{5:5} [ 5.387762] 5 locks held by kworker/u17:1/44: [ 5.392123] #0: ffffff8800014958 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work (kernel/workqueue.c:3204) [ 5.402260] #1: ffffffc082fcbdd8 (deferred_probe_work){+.+.}-{0:0}, at: process_one_work (kernel/workqueue.c:3205) [ 5.411528] #2: ffffff880172c900 (&dev->mutex){....}-{4:4}, at: __device_attach (drivers/base/dd.c:1006) [ 5.419929] #3: ffffff88039c8268 (request_class#2){+.+.}-{4:4}, at: __setup_irq (kernel/irq/internals.h:156 kernel/irq/manage.c:1596) [ 5.428331] #4: ffffff88039c80c8 (lock_class#2){....}-{2:2}, at: __setup_irq (kernel/irq/manage.c:1614) [ 5.436472] stack backtrace: [ 5.439359] CPU: 2 UID: 0 PID: 44 Comm: kworker/u17:1 Tainted: G W 6.13.0-rc5+ #69 [ 5.448690] Tainted: [W]=WARN [ 5.451656] Hardware name: xlnx,zynqmp (DT) [ 5.455845] Workqueue: events_unbound deferred_probe_work_func [ 5.461699] Call trace: [ 5.464147] show_stack+0x18/0x24 C [ 5.467821] dump_stack_lvl (lib/dump_stack.c:123) [ 5.471501] dump_stack (lib/dump_stack.c:130) [ 5.474824] __lock_acquire (kernel/locking/lockdep.c:4828 kernel/locking/lockdep.c:4898 kernel/locking/lockdep.c:5176) [ 5.478758] lock_acquire (arch/arm64/include/asm/percpu.h:40 kernel/locking/lockdep.c:467 kernel/locking/lockdep.c:5851 kernel/locking/lockdep.c:5814) [ 5.482429] _raw_spin_lock_irqsave (include/linux/spinlock_api_smp.h:111 kernel/locking/spinlock.c:162) [ 5.486797] xgpio_irq_unmask (drivers/gpio/gpio-xilinx.c:433 (discriminator 8)) [ 5.490737] irq_enable (kernel/irq/internals.h:236 kernel/irq/chip.c:170 kernel/irq/chip.c:439 kernel/irq/chip.c:432 kernel/irq/chip.c:345) [ 5.494060] __irq_startup (kernel/irq/internals.h:241 kernel/irq/chip.c:180 kernel/irq/chip.c:250) [ 5.497645] irq_startup (kernel/irq/chip.c:270) [ 5.501143] __setup_irq (kernel/irq/manage.c:1807) [ 5.504728] request_threaded_irq (kernel/irq/manage.c:2208) Fixes: a32c7ca ("gpio: gpio-xilinx: Add interrupt support") Signed-off-by: Sean Anderson <sean.anderson@linux.dev> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250110163354.2012654-1-sean.anderson@linux.dev Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CVE-2025-21684 Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent db881da commit 4c16481

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

drivers/gpio/gpio-xilinx.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct xgpio_instance {
6565
DECLARE_BITMAP(state, 64);
6666
DECLARE_BITMAP(last_irq_read, 64);
6767
DECLARE_BITMAP(dir, 64);
68-
spinlock_t gpio_lock; /* For serializing operations */
68+
raw_spinlock_t gpio_lock; /* For serializing operations */
6969
int irq;
7070
DECLARE_BITMAP(enable, 64);
7171
DECLARE_BITMAP(rising_edge, 64);
@@ -179,14 +179,14 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
179179
struct xgpio_instance *chip = gpiochip_get_data(gc);
180180
int bit = xgpio_to_bit(chip, gpio);
181181

182-
spin_lock_irqsave(&chip->gpio_lock, flags);
182+
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
183183

184184
/* Write to GPIO signal and set its direction to output */
185185
__assign_bit(bit, chip->state, val);
186186

187187
xgpio_write_ch(chip, XGPIO_DATA_OFFSET, bit, chip->state);
188188

189-
spin_unlock_irqrestore(&chip->gpio_lock, flags);
189+
raw_spin_unlock_irqrestore(&chip->gpio_lock, flags);
190190
}
191191

192192
/**
@@ -210,15 +210,15 @@ static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
210210
bitmap_remap(hw_mask, mask, chip->sw_map, chip->hw_map, 64);
211211
bitmap_remap(hw_bits, bits, chip->sw_map, chip->hw_map, 64);
212212

213-
spin_lock_irqsave(&chip->gpio_lock, flags);
213+
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
214214

215215
bitmap_replace(state, chip->state, hw_bits, hw_mask, 64);
216216

217217
xgpio_write_ch_all(chip, XGPIO_DATA_OFFSET, state);
218218

219219
bitmap_copy(chip->state, state, 64);
220220

221-
spin_unlock_irqrestore(&chip->gpio_lock, flags);
221+
raw_spin_unlock_irqrestore(&chip->gpio_lock, flags);
222222
}
223223

224224
/**
@@ -236,13 +236,13 @@ static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
236236
struct xgpio_instance *chip = gpiochip_get_data(gc);
237237
int bit = xgpio_to_bit(chip, gpio);
238238

239-
spin_lock_irqsave(&chip->gpio_lock, flags);
239+
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
240240

241241
/* Set the GPIO bit in shadow register and set direction as input */
242242
__set_bit(bit, chip->dir);
243243
xgpio_write_ch(chip, XGPIO_TRI_OFFSET, bit, chip->dir);
244244

245-
spin_unlock_irqrestore(&chip->gpio_lock, flags);
245+
raw_spin_unlock_irqrestore(&chip->gpio_lock, flags);
246246

247247
return 0;
248248
}
@@ -265,7 +265,7 @@ static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
265265
struct xgpio_instance *chip = gpiochip_get_data(gc);
266266
int bit = xgpio_to_bit(chip, gpio);
267267

268-
spin_lock_irqsave(&chip->gpio_lock, flags);
268+
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
269269

270270
/* Write state of GPIO signal */
271271
__assign_bit(bit, chip->state, val);
@@ -275,7 +275,7 @@ static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
275275
__clear_bit(bit, chip->dir);
276276
xgpio_write_ch(chip, XGPIO_TRI_OFFSET, bit, chip->dir);
277277

278-
spin_unlock_irqrestore(&chip->gpio_lock, flags);
278+
raw_spin_unlock_irqrestore(&chip->gpio_lock, flags);
279279

280280
return 0;
281281
}
@@ -401,7 +401,7 @@ static void xgpio_irq_mask(struct irq_data *irq_data)
401401
int bit = xgpio_to_bit(chip, irq_offset);
402402
u32 mask = BIT(bit / 32), temp;
403403

404-
spin_lock_irqsave(&chip->gpio_lock, flags);
404+
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
405405

406406
__clear_bit(bit, chip->enable);
407407

@@ -411,7 +411,7 @@ static void xgpio_irq_mask(struct irq_data *irq_data)
411411
temp &= ~mask;
412412
xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, temp);
413413
}
414-
spin_unlock_irqrestore(&chip->gpio_lock, flags);
414+
raw_spin_unlock_irqrestore(&chip->gpio_lock, flags);
415415

416416
gpiochip_disable_irq(&chip->gc, irq_offset);
417417
}
@@ -431,7 +431,7 @@ static void xgpio_irq_unmask(struct irq_data *irq_data)
431431

432432
gpiochip_enable_irq(&chip->gc, irq_offset);
433433

434-
spin_lock_irqsave(&chip->gpio_lock, flags);
434+
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
435435

436436
__set_bit(bit, chip->enable);
437437

@@ -450,7 +450,7 @@ static void xgpio_irq_unmask(struct irq_data *irq_data)
450450
xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, val);
451451
}
452452

453-
spin_unlock_irqrestore(&chip->gpio_lock, flags);
453+
raw_spin_unlock_irqrestore(&chip->gpio_lock, flags);
454454
}
455455

456456
/**
@@ -515,7 +515,7 @@ static void xgpio_irqhandler(struct irq_desc *desc)
515515

516516
chained_irq_enter(irqchip, desc);
517517

518-
spin_lock(&chip->gpio_lock);
518+
raw_spin_lock(&chip->gpio_lock);
519519

520520
xgpio_read_ch_all(chip, XGPIO_DATA_OFFSET, all);
521521

@@ -532,7 +532,7 @@ static void xgpio_irqhandler(struct irq_desc *desc)
532532
bitmap_copy(chip->last_irq_read, all, 64);
533533
bitmap_or(all, rising, falling, 64);
534534

535-
spin_unlock(&chip->gpio_lock);
535+
raw_spin_unlock(&chip->gpio_lock);
536536

537537
dev_dbg(gc->parent, "IRQ rising %*pb falling %*pb\n", 64, rising, 64, falling);
538538

@@ -623,7 +623,7 @@ static int xgpio_probe(struct platform_device *pdev)
623623
bitmap_set(chip->hw_map, 0, width[0]);
624624
bitmap_set(chip->hw_map, 32, width[1]);
625625

626-
spin_lock_init(&chip->gpio_lock);
626+
raw_spin_lock_init(&chip->gpio_lock);
627627

628628
chip->gc.base = -1;
629629
chip->gc.ngpio = bitmap_weight(chip->hw_map, 64);

0 commit comments

Comments
 (0)