From: sashiko-bot@kernel.org
To: "Maurice Hieronymus" <mhi@mailbox.org>
Cc: linux-scsi@vger.kernel.org, ojeda@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 1/2] PCI: Replace pci_dev->is_busmaster with accessors
Date: Sun, 12 Jul 2026 15:21:52 +0000 [thread overview]
Message-ID: <20260712152153.565DF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260711-pci-dev-flags-v1-1-2fcf2811138c@mailbox.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent read-modify-write of the hardware PCI_COMMAND register can lose updates.
--
--- Patch [1]: [PATCH 1/2] PCI: Replace pci_dev->is_busmaster with accessors ---
commit ff1aee4bf47f9e69854d2a3ad6eea071a246ecb1
Author: Maurice Hieronymus <mhi@mailbox.org>
PCI: Replace pci_dev->is_busmaster with accessors
This commit moves the is_busmaster bit from a shared bitfield into a
new flags bitmap using atomic bitops. This prevents concurrent
read-modify-write cycles on the shared software bitfield, explicitly
enabling safe concurrent usage of pci_disable_device() and pci_set_master().
Link: https://lore.kernel.org/rust-for-linux/DJOEYVBS17MJ.1YD3TNGQBWHNK@kernel.org/ [1]
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 77b17b13ee615..c4fd6fe6098d0 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
[ ... ]
> @@ -2205,7 +2205,7 @@ void pci_disable_device(struct pci_dev *dev)
>
> do_pci_disable_device(dev);
>
> - dev->is_busmaster = 0;
> + pci_dev_assign_busmaster(dev, false);
> }
[ ... ]
> @@ -4120,7 +4120,7 @@ static void __pci_set_master(struct pci_dev *dev, bool enable)
> enable ? "enabling" : "disabling");
> pci_write_config_word(dev, PCI_COMMAND, cmd);
> }
> - dev->is_busmaster = enable;
> + pci_dev_assign_busmaster(dev, enable);
> }
[Severity: High]
This is a pre-existing issue, but since the commit message notes that
pci_set_master() and pci_disable_device() can run concurrently to justify
this change, can those concurrent calls also lose updates to the hardware
PCI_COMMAND register?
In __pci_set_master(), there is an unprotected read-modify-write cycle on
the hardware register:
pci_read_config_word(dev, PCI_COMMAND, &old_cmd);
if (enable)
cmd = old_cmd | PCI_COMMAND_MASTER;
else
cmd = old_cmd & ~PCI_COMMAND_MASTER;
if (cmd != old_cmd) {
pci_dbg(dev, "%s bus mastering\n",
enable ? "enabling" : "disabling");
pci_write_config_word(dev, PCI_COMMAND, cmd);
}
Similarly, do_pci_disable_device() (called just before the change in
pci_disable_device() above) performs its own unprotected update:
pci_read_config_word(dev, PCI_COMMAND, &pci_command);
if (pci_command & PCI_COMMAND_MASTER) {
pci_command &= ~PCI_COMMAND_MASTER;
pci_write_config_word(dev, PCI_COMMAND, pci_command);
}
If a Rust guard object calls pci_disable_device() concurrently with
pci_set_master(), could we accidentally clear or set other critical flags
like PCI_COMMAND_INTX_DISABLE or PCI_COMMAND_MEMORY due to the hardware
read-modify-write race?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260711-pci-dev-flags-v1-0-2fcf2811138c@mailbox.org?part=1
next prev parent reply other threads:[~2026-07-12 15:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 15:21 [PATCH 0/2] PCI: Convert bitfield flags to atomic accessors Maurice Hieronymus
2026-07-11 15:21 ` [PATCH 1/2] PCI: Replace pci_dev->is_busmaster with accessors Maurice Hieronymus
2026-07-12 14:28 ` Lukas Wunner
2026-07-12 15:21 ` sashiko-bot [this message]
2026-07-11 15:21 ` [PATCH 2/2] PCI: Replace pci_dev->broken_parity_status " Maurice Hieronymus
2026-07-12 14:55 ` Lukas Wunner
2026-07-12 15:21 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260712152153.565DF1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mhi@mailbox.org \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox