Skip to contentSkip to conversation

cxl: Incorrect mutex unlock pairing in cxl_pci_mbox_send

BUG REPORT ALOK TIWARI 3 participants 3 messages May 29, 2025

lore
Share & tools
lore
#0 lore raw

It is locked using mutex_lock_io() but unlocked with mutex_unlock().

drivers/cxl/pci.c

377 static int cxl_pci_mbox_send(struct cxl_mailbox *cxl_mbox,
378 struct cxl_mbox_cmd *cmd)
379 {
380 int rc;
381

 382         mutex_lock_io(&cxl_mbox->mbox_mutex);
 383         rc = __cxl_pci_mbox_send_cmd(cxl_mbox, cmd);
 384         mutex_unlock(&cxl_mbox->mbox_mutex);

385
386 return rc;
387 }

Thanks,
Alok

#1 lore raw
Quoted 1 line · ALOK TIWARI

It is locked using mutex_lock_io() but unlocked with mutex_unlock().

Why is this a bug? IIUC the pairing is correct. ie the unlock is done by mutex_unlock() for all flavors of mutex_lock_*()

Quoted 17 lines

drivers/cxl/pci.c

377 static int cxl_pci_mbox_send(struct cxl_mailbox *cxl_mbox,
378 struct cxl_mbox_cmd *cmd)
379 {
380 int rc;
381

 382         mutex_lock_io(&cxl_mbox->mbox_mutex);
 383         rc = __cxl_pci_mbox_send_cmd(cxl_mbox, cmd);
 384         mutex_unlock(&cxl_mbox->mbox_mutex);

385
386 return rc;
387 }

Thanks,
Alok

#2 lore raw
Quoted 5 lines · Alison Schofield
Quoted 1 line · ALOK TIWARI

It is locked using mutex_lock_io() but unlocked with mutex_unlock().

Why is this a bug? IIUC the pairing is correct. ie the unlock is done by mutex_unlock() for all flavors of mutex_lock_*()

While the pairing is correct, the usage of mutex_lock_io() for an MMIO mailbox is pointless. mutex_lock_io() is a filesystem helper to plug block requests while the lock is held.

This code has been confused ever since it originally appeared.

8adaf747c9f0 ("cxl/mem: Find device capabilities")

...and the cargo-culted forward ever since.