public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, mitchell.augustin@canonical.com,
	ilpo.jarvinen@linux.intel.com
Subject: Re: [PATCH v2] PCI: Batch BAR sizing operations
Date: Mon, 10 Feb 2025 09:36:41 -0700	[thread overview]
Message-ID: <20250210093641.0be242ae.alex.williamson@redhat.com> (raw)
In-Reply-To: <20250209154512.GA18688@redhat.com>

On Sun, 9 Feb 2025 16:45:12 +0100
Oleg Nesterov <oleg@redhat.com> wrote:

> On 01/20, Alex Williamson wrote:
> >
> >  static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
> >  {
> > +	u32 rombar, stdbars[PCI_STD_NUM_BARS];
> >  	unsigned int pos, reg;
> > +	u16 orig_cmd;
> > +
> > +	BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);  
> 
> FYI, I can't build the kernel after this patch:
> 
> 	$ make drivers/pci/probe.o
> 	  UPD     include/config/kernel.release
> 	  UPD     include/generated/utsrelease.h
> 	  CALL    scripts/checksyscalls.sh
> 	  DESCEND objtool
> 	  INSTALL libsubcmd_headers
> 	  CC      drivers/pci/probe.o
> 	In file included from <command-line>:0:0:
> 	drivers/pci/probe.c: In function ‘pci_read_bases’:
> 	././include/linux/compiler_types.h:542:38: error: call to ‘__compiletime_assert_338’ declared with attribute error: BUILD_BUG_ON failed: howmany > PCI_STD_NUM_BARS
> 	  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> 					      ^
> 	././include/linux/compiler_types.h:523:4: note: in definition of macro ‘__compiletime_assert’
> 	    prefix ## suffix();    \
> 	    ^
> 	././include/linux/compiler_types.h:542:2: note: in expansion of macro ‘_compiletime_assert’
> 	  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> 	  ^
> 	./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
> 	 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> 					     ^
> 	./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
> 	  BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
> 	  ^
> 	drivers/pci/probe.c:348:2: note: in expansion of macro ‘BUILD_BUG_ON’
> 	  BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
> 
> Yes, my gcc version 5.3.1 is very old, but according to Documentation/process/changes.rst
> it should still be supported, the minimal version is 5.1.

While I try to setup an environment with an old gcc, can we do something
with __builtin_constant_p() to only evaluate this on versions of gcc
that can determine howmany is constant?  Ex.

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b6536ed599c3..c70cb480125e 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);
+	if (__builtin_constant_p(howmany))
+		BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
 
 	if (dev->non_compliant_bars)
 		return;

I welcome other suggestions too.  Thanks,

Alex


  reply	other threads:[~2025-02-10 16:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 18:21 [PATCH v2] PCI: Batch BAR sizing operations Alex Williamson
2025-01-20 22:44 ` Bjorn Helgaas
2025-01-21 19:01   ` Mitchell Augustin
2025-01-23 12:15 ` Ilpo Järvinen
2025-02-09 15:45 ` Oleg Nesterov
2025-02-10 16:36   ` Alex Williamson [this message]
2025-02-10 19:56     ` Oleg Nesterov
2025-02-10 20:08       ` Oleg Nesterov
2025-02-10 20:48         ` Alex Williamson
2025-02-10 22:11           ` David Laight
2025-02-10 22:46             ` Oleg Nesterov

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=20250210093641.0be242ae.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mitchell.augustin@canonical.com \
    --cc=oleg@redhat.com \
    /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