* [PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc
@ 2025-02-10 21:01 Alex Williamson
2025-02-10 22:00 ` Oleg Nesterov
0 siblings, 1 reply; 4+ messages in thread
From: Alex Williamson @ 2025-02-10 21:01 UTC (permalink / raw)
To: bhelgaas
Cc: Alex Williamson, linux-pci, linux-kernel, mitchell.augustin,
ilpo.jarvinen, Oleg Nesterov
As reported in the below link, it seems older versions of gcc cannot
determine that the howmany variable is known for all callers. Include
a test so that newer compilers can still enforce this sanity check and
older compilers can still work.
Fixes: 4453f360862e ("PCI: Batch BAR sizing operations")
Link: https://lore.kernel.org/all/20250209154512.GA18688@redhat.com
Reported-by: Oleg Nesterov <oleg@redhat.com>
Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
Verified against gcc 14.2.1 to still trigger a build error if called
with a constant value greater than 6, Oleg to confirm build issue is
resolved for gcc 5.3.1.
drivers/pci/probe.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b6536ed599c3..1bde89d0dc0d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -345,7 +345,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
unsigned int pos, reg;
u16 orig_cmd;
- BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
+ BUILD_BUG_ON(__builtin_constant_p(howmany) &&
+ howmany > PCI_STD_NUM_BARS);
if (dev->non_compliant_bars)
return;
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc
2025-02-10 21:01 [PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc Alex Williamson
@ 2025-02-10 22:00 ` Oleg Nesterov
2025-02-11 10:05 ` Oleg Nesterov
0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2025-02-10 22:00 UTC (permalink / raw)
To: Alex Williamson
Cc: bhelgaas, linux-pci, linux-kernel, mitchell.augustin,
ilpo.jarvinen
On 02/10, Alex Williamson wrote:
>
> As reported in the below link, it seems older versions of gcc cannot
> determine that the howmany variable is known for all callers. Include
> a test so that newer compilers can still enforce this sanity check and
> older compilers can still work.
>
> Fixes: 4453f360862e ("PCI: Batch BAR sizing operations")
> Link: https://lore.kernel.org/all/20250209154512.GA18688@redhat.com
> Reported-by: Oleg Nesterov <oleg@redhat.com>
> Suggested-by: Oleg Nesterov <oleg@redhat.com>
^^^^^^^^^^^^
Well, thanks, but I didn't ;)
> @@ -345,7 +345,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
> unsigned int pos, reg;
> u16 orig_cmd;
>
> - BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
> + BUILD_BUG_ON(__builtin_constant_p(howmany) &&
> + howmany > PCI_STD_NUM_BARS);
Thanks!
Tested-by: Oleg Nesterov <oleg@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc
2025-02-10 22:00 ` Oleg Nesterov
@ 2025-02-11 10:05 ` Oleg Nesterov
2025-02-11 22:38 ` Mitchell Augustin
0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2025-02-11 10:05 UTC (permalink / raw)
To: Alex Williamson
Cc: bhelgaas, linux-pci, linux-kernel, mitchell.augustin,
ilpo.jarvinen, David Laight
On 02/10, Oleg Nesterov wrote:
>
> On 02/10, Alex Williamson wrote:
> >
> > @@ -345,7 +345,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
> > unsigned int pos, reg;
> > u16 orig_cmd;
> >
> > - BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
> > + BUILD_BUG_ON(__builtin_constant_p(howmany) &&
> > + howmany > PCI_STD_NUM_BARS);
>
> Thanks!
>
> Tested-by: Oleg Nesterov <oleg@redhat.com>
Just in case... I agree with David, statically_true() looks a bit
better and
BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
also works for me, so if you decide to update this patch feel free
to keep my Tested-by.
Oleg.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc
2025-02-11 10:05 ` Oleg Nesterov
@ 2025-02-11 22:38 ` Mitchell Augustin
0 siblings, 0 replies; 4+ messages in thread
From: Mitchell Augustin @ 2025-02-11 22:38 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Alex Williamson, bhelgaas, linux-pci, linux-kernel, ilpo.jarvinen,
David Laight
On Ubuntu's (modern) GCC 13.3.0-6ubuntu2~24.04, both proposed options
also build as expected for me when howmany is set correctly, and fail
as expected when I force howmany = 7.
Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
On Tue, Feb 11, 2025 at 4:05 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> On 02/10, Oleg Nesterov wrote:
> >
> > On 02/10, Alex Williamson wrote:
> > >
> > > @@ -345,7 +345,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
> > > unsigned int pos, reg;
> > > u16 orig_cmd;
> > >
> > > - BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
> > > + BUILD_BUG_ON(__builtin_constant_p(howmany) &&
> > > + howmany > PCI_STD_NUM_BARS);
> >
> > Thanks!
> >
> > Tested-by: Oleg Nesterov <oleg@redhat.com>
>
> Just in case... I agree with David, statically_true() looks a bit
> better and
>
> BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
>
> also works for me, so if you decide to update this patch feel free
> to keep my Tested-by.
>
> Oleg.
>
--
Mitchell Augustin
Software Engineer - Ubuntu Partner Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-11 22:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 21:01 [PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc Alex Williamson
2025-02-10 22:00 ` Oleg Nesterov
2025-02-11 10:05 ` Oleg Nesterov
2025-02-11 22:38 ` Mitchell Augustin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox