Bug 200793 - PCI: read-write config operation doesn't look like SMP safe
Summary: PCI: read-write config operation doesn't look like SMP safe
Status: NEW
Alias: None
Product: Drivers
Classification: Unclassified
Component: PCI (show other bugs)
Hardware: All Linux
: P1 enhancement
Assignee: drivers_pci@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-10 13:51 UTC by Hari Kishore Vyas
Modified: 2018-08-16 16:00 UTC (History)
2 users (show)

See Also:
Kernel Version: 4.17,4.18
Subsystem:
Regression: No
Bisected commit-id:


Attachments
Proposed fix for config write race condition in smp environment (4.18 KB, patch)
2018-08-16 10:32 UTC, Hari Kishore Vyas
Details | Diff

Description Hari Kishore Vyas 2018-08-10 13:51:28 UTC
While checking one concern raised by my colleague Srinath https://lkml.org/lkml/2017/9/15/193 Re: [PATCH] Revert "PCI: Avoid race while enabling upstream bridges", found that current read-write config operations are not safe in SMP environment.

Raised concern was correct but fix was just reverted due to some reason. 
If we check write on pci configuration register(ex: PCI_COMMAND which has bit fields), two threads running in different CPUs may produce wrong results as described in patch. Intention was to set master bit by one thread and memory bit by another thread but result was only master bit set but could be reverse also in race condition.

Better we introduce a new routine in struct pci_ops like  (int (*modify_safe)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 old, u32 diff or new);
where we read current value and apply diff. Believe this should help in resolving race condition.

Please comment.
Comment 1 Bjorn Helgaas 2018-08-10 14:07:44 UTC
Can you please post this question to linux-pci@vger.kernel.org, so we can have a discussion there?  The ideal form would be a patch that actually adds the new routine you propose, and the changelog can reference the previous related commits and this bugzilla.
Comment 2 Hari Kishore Vyas 2018-08-13 10:07:26 UTC
(In reply to Bjorn Helgaas from comment #1)
> Can you please post this question to linux-pci@vger.kernel.org, so we can
> have a discussion there?  The ideal form would be a patch that actually adds
> the new routine you propose, and the changelog can reference the previous
> related commits and this bugzilla.

Hi Bjorn,
Thanks for your comment. Will make a formal patch and revert. Hope that should be fine.

Regards,
hari
Comment 3 Hari Kishore Vyas 2018-08-16 10:32:13 UTC
Created attachment 277885 [details]
Proposed fix for config write race condition in smp environment

Proposed simple fix for config write race condition in smp environment.
Basically it locks for modify operation and avoid race between read-write and read-write in two threads
Comment 4 Bjorn Helgaas 2018-08-16 14:10:11 UTC
If you want this patch to be considered, be sure to post it to the linux-pci@vger.kernel.org mailing list.
Comment 5 Hari Kishore Vyas 2018-08-16 16:00:45 UTC
(In reply to Bjorn Helgaas from comment #4)
> If you want this patch to be considered, be sure to post it to the
> linux-pci@vger.kernel.org mailing list.

Sure. Will post it right after its proper testing. Discussed with my colleague. Though code perspective, it looks an issue but better issue be reproduced without my changes and fixed with my changes.

Note You need to log in before you can comment on or make changes to this bug.