public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
@ 2025-10-14 18:20 Nathan Chancellor
  2025-10-14 19:13 ` Bjorn Helgaas
  2025-12-18  5:23 ` Manivannan Sadhasivam
  0 siblings, 2 replies; 7+ messages in thread
From: Nathan Chancellor @ 2025-10-14 18:20 UTC (permalink / raw)
  To: Marek Vasut, Yoshihiro Shimoda, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Manivannan Sadhasivam, Rob Herring,
	Bjorn Helgaas
  Cc: Geert Uytterhoeven, Magnus Damm, Kees Cook, Peter Zijlstra,
	linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot, Nathan Chancellor

After commit 894af4a1cde6 ("objtool: Validate kCFI calls"), compile
testing pcie-rcar-host.c with CONFIG_FINEIBT=y and CONFIG_OF=n results
in a no-cfi objtool warning in rcar_pcie_probe():

  $ cat allno.config
  CONFIG_CFI=y
  CONFIG_COMPILE_TEST=y
  CONFIG_CPU_MITIGATIONS=y
  CONFIG_GENERIC_PHY=y
  CONFIG_MITIGATION_RETPOLINE=y
  CONFIG_MODULES=y
  CONFIG_PCI=y
  CONFIG_PCI_MSI=y
  CONFIG_PCIE_RCAR_HOST=y
  CONFIG_X86_KERNEL_IBT=y

  $ make -skj"$(nproc)" ARCH=x86_64 KCONFIG_ALLCONFIG=1 LLVM=1 clean allnoconfig vmlinux
  vmlinux.o: warning: objtool: rcar_pcie_probe+0x191: no-cfi indirect call!

When CONFIG_OF is unset, of_device_get_match_data() returns NULL, so
LLVM knows this indirect call has no valid destination and drops the
kCFI setup before the call, triggering the objtool check that makes sure
all indirect calls have kCFI setup.

This driver depends on OF for probing with non-NULL data for every match
so this call will never be NULL in practice. Add a hard Kconfig
dependency on OF to avoid the warning.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202510092124.O2IX0Jek-lkp@intel.com/
Closes: https://github.com/ClangBuiltLinux/linux/issues/2134
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Changes in v2:
- Switch from NULL check to avoiding CONFIG_OF=n case altogether (Mani,
  Geert).
- Drop Peter and Kees's reviews, as solution is not the same.
- Link to v1: https://patch.msgid.link/20251013-rcar_pcie_probe-avoid-nocfi-objtool-warning-v1-1-552876b94f04@kernel.org
---
 drivers/pci/controller/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
index 41748d083b93..d8688abc5b27 100644
--- a/drivers/pci/controller/Kconfig
+++ b/drivers/pci/controller/Kconfig
@@ -243,6 +243,7 @@ config PCI_TEGRA
 config PCIE_RCAR_HOST
 	bool "Renesas R-Car PCIe controller (host mode)"
 	depends on ARCH_RENESAS || COMPILE_TEST
+	depends on OF
 	depends on PCI_MSI
 	select IRQ_MSI_LIB
 	help

---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251013-rcar_pcie_probe-avoid-nocfi-objtool-warning-1a975accb6b6

Best regards,
--  
Nathan Chancellor <nathan@kernel.org>


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
  2025-10-14 18:20 [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning Nathan Chancellor
@ 2025-10-14 19:13 ` Bjorn Helgaas
  2025-10-14 19:47   ` Peter Zijlstra
  2025-12-18  5:23 ` Manivannan Sadhasivam
  1 sibling, 1 reply; 7+ messages in thread
From: Bjorn Helgaas @ 2025-10-14 19:13 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Marek Vasut, Yoshihiro Shimoda, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Manivannan Sadhasivam, Rob Herring,
	Bjorn Helgaas, Geert Uytterhoeven, Magnus Damm, Kees Cook,
	Peter Zijlstra, linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot

On Tue, Oct 14, 2025 at 11:20:27AM -0700, Nathan Chancellor wrote:
> After commit 894af4a1cde6 ("objtool: Validate kCFI calls"), compile
> testing pcie-rcar-host.c with CONFIG_FINEIBT=y and CONFIG_OF=n results
> in a no-cfi objtool warning in rcar_pcie_probe():
> 
>   $ cat allno.config
>   CONFIG_CFI=y
>   CONFIG_COMPILE_TEST=y
>   CONFIG_CPU_MITIGATIONS=y
>   CONFIG_GENERIC_PHY=y
>   CONFIG_MITIGATION_RETPOLINE=y
>   CONFIG_MODULES=y
>   CONFIG_PCI=y
>   CONFIG_PCI_MSI=y
>   CONFIG_PCIE_RCAR_HOST=y
>   CONFIG_X86_KERNEL_IBT=y
> 
>   $ make -skj"$(nproc)" ARCH=x86_64 KCONFIG_ALLCONFIG=1 LLVM=1 clean allnoconfig vmlinux
>   vmlinux.o: warning: objtool: rcar_pcie_probe+0x191: no-cfi indirect call!
> 
> When CONFIG_OF is unset, of_device_get_match_data() returns NULL, so
> LLVM knows this indirect call has no valid destination and drops the
> kCFI setup before the call, triggering the objtool check that makes sure
> all indirect calls have kCFI setup.
> 
> This driver depends on OF for probing with non-NULL data for every match
> so this call will never be NULL in practice. Add a hard Kconfig
> dependency on OF to avoid the warning.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202510092124.O2IX0Jek-lkp@intel.com/
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2134
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> Changes in v2:
> - Switch from NULL check to avoiding CONFIG_OF=n case altogether (Mani,
>   Geert).
> - Drop Peter and Kees's reviews, as solution is not the same.
> - Link to v1: https://patch.msgid.link/20251013-rcar_pcie_probe-avoid-nocfi-objtool-warning-v1-1-552876b94f04@kernel.org
> ---
>  drivers/pci/controller/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
> index 41748d083b93..d8688abc5b27 100644
> --- a/drivers/pci/controller/Kconfig
> +++ b/drivers/pci/controller/Kconfig
> @@ -243,6 +243,7 @@ config PCI_TEGRA
>  config PCIE_RCAR_HOST
>  	bool "Renesas R-Car PCIe controller (host mode)"
>  	depends on ARCH_RENESAS || COMPILE_TEST
> +	depends on OF

Ugh.  This might be the best solution, but it's a bit problematic
without a hint about why "depends on OF" is here.  Theoretically there
are stubs for everything to make COMPILE_TEST work, so I think we're
about to drop all the dependencies on OF.

This dependency to avoid a no-cfi warning looks like the kind of thing
that could someday go away if the tools get smarter.  Maybe we can add
a Kconfig comment here, but I don't really know enough to write one.
Something like this?

  depends on OF   # avoid no-cfi warning https://lore.kernel.org/r/202510092124.O2IX0Jek-lkp@intel.com/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
  2025-10-14 19:13 ` Bjorn Helgaas
@ 2025-10-14 19:47   ` Peter Zijlstra
  2025-10-14 22:25     ` Nathan Chancellor
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2025-10-14 19:47 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Nathan Chancellor, Marek Vasut, Yoshihiro Shimoda,
	Lorenzo Pieralisi, Krzysztof Wilczy??ski, Manivannan Sadhasivam,
	Rob Herring, Bjorn Helgaas, Geert Uytterhoeven, Magnus Damm,
	Kees Cook, linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot

On Tue, Oct 14, 2025 at 02:13:30PM -0500, Bjorn Helgaas wrote:

> Ugh.  This might be the best solution, but it's a bit problematic
> without a hint about why "depends on OF" is here.  Theoretically there
> are stubs for everything to make COMPILE_TEST work, so I think we're
> about to drop all the dependencies on OF.

Its those stubs are exactly the problem.

> This dependency to avoid a no-cfi warning looks like the kind of thing
> that could someday go away if the tools get smarter.  Maybe we can add
> a Kconfig comment here, but I don't really know enough to write one.
> Something like this?

Its not a CFI warning per-se, the compiler is hitting known UB
(unconditional NULL deref) and is currently emitting a NULL pointer
indirect call, but given how aggressive clang has been on encountering
UB it might just stop code-gen entirely and generate fall-through
warnings (been there done that).

Smarter compiler here is only going to make this worse.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
  2025-10-14 19:47   ` Peter Zijlstra
@ 2025-10-14 22:25     ` Nathan Chancellor
  2025-10-27 12:26       ` Manivannan Sadhasivam
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2025-10-14 22:25 UTC (permalink / raw)
  To: Peter Zijlstra, Bjorn Helgaas
  Cc: Marek Vasut, Yoshihiro Shimoda, Lorenzo Pieralisi,
	Krzysztof Wilczy??ski, Manivannan Sadhasivam, Rob Herring,
	Bjorn Helgaas, Geert Uytterhoeven, Magnus Damm, Kees Cook,
	linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot

On Tue, Oct 14, 2025 at 09:47:28PM +0200, Peter Zijlstra wrote:
> On Tue, Oct 14, 2025 at 02:13:30PM -0500, Bjorn Helgaas wrote:
> 
> > Ugh.  This might be the best solution, but it's a bit problematic
> > without a hint about why "depends on OF" is here.  Theoretically there
> > are stubs for everything to make COMPILE_TEST work, so I think we're
> > about to drop all the dependencies on OF.
> 
> Its those stubs are exactly the problem.

Yeah and I had thought about changing of_device_get_match_data() to use
something like ERR_PTR() in the !OF case but that does not fix the issue
since the call destination is still going to be invalid. To me, this is
just one of the sharp edges of compile testing: you give up some code or
configuration cleanliness/expectations for the flexibility of build
testing.

> > This dependency to avoid a no-cfi warning looks like the kind of thing
> > that could someday go away if the tools get smarter.  Maybe we can add
> > a Kconfig comment here, but I don't really know enough to write one.
> > Something like this?
> 
> Its not a CFI warning per-se, the compiler is hitting known UB
> (unconditional NULL deref) and is currently emitting a NULL pointer
> indirect call, but given how aggressive clang has been on encountering
> UB it might just stop code-gen entirely and generate fall-through
> warnings (been there done that).
> 
> Smarter compiler here is only going to make this worse.

Yeah, we are lucky that this is all LLVM does with this code.

For what it's worth, there is plenty of "depends on OF" that appears
across the tree and I see exactly one instance that has a comment above
it (none with the comment on the same line). Perhaps these are all
historical if there was a point where stubs were not provided for !OF. I
do not mind adding a comment if really so desired but this driver does
not do anything without CONFIG_OF so it feels like the dependency is
natural anyways.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
  2025-10-14 22:25     ` Nathan Chancellor
@ 2025-10-27 12:26       ` Manivannan Sadhasivam
  0 siblings, 0 replies; 7+ messages in thread
From: Manivannan Sadhasivam @ 2025-10-27 12:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Nathan Chancellor
  Cc: Peter Zijlstra, Bjorn Helgaas, Marek Vasut, Yoshihiro Shimoda,
	Lorenzo Pieralisi, Krzysztof Wilczy??ski, Rob Herring,
	Bjorn Helgaas, Geert Uytterhoeven, Magnus Damm, Kees Cook,
	linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot

On Tue, Oct 14, 2025 at 03:25:24PM -0700, Nathan Chancellor wrote:
> On Tue, Oct 14, 2025 at 09:47:28PM +0200, Peter Zijlstra wrote:
> > On Tue, Oct 14, 2025 at 02:13:30PM -0500, Bjorn Helgaas wrote:
> > 
> > > Ugh.  This might be the best solution, but it's a bit problematic
> > > without a hint about why "depends on OF" is here.  Theoretically there
> > > are stubs for everything to make COMPILE_TEST work, so I think we're
> > > about to drop all the dependencies on OF.
> > 
> > Its those stubs are exactly the problem.
> 
> Yeah and I had thought about changing of_device_get_match_data() to use
> something like ERR_PTR() in the !OF case but that does not fix the issue
> since the call destination is still going to be invalid. To me, this is
> just one of the sharp edges of compile testing: you give up some code or
> configuration cleanliness/expectations for the flexibility of build
> testing.
> 
> > > This dependency to avoid a no-cfi warning looks like the kind of thing
> > > that could someday go away if the tools get smarter.  Maybe we can add
> > > a Kconfig comment here, but I don't really know enough to write one.
> > > Something like this?
> > 
> > Its not a CFI warning per-se, the compiler is hitting known UB
> > (unconditional NULL deref) and is currently emitting a NULL pointer
> > indirect call, but given how aggressive clang has been on encountering
> > UB it might just stop code-gen entirely and generate fall-through
> > warnings (been there done that).
> > 
> > Smarter compiler here is only going to make this worse.
> 
> Yeah, we are lucky that this is all LLVM does with this code.
> 
> For what it's worth, there is plenty of "depends on OF" that appears
> across the tree and I see exactly one instance that has a comment above
> it (none with the comment on the same line). Perhaps these are all
> historical if there was a point where stubs were not provided for !OF. I
> do not mind adding a comment if really so desired but this driver does
> not do anything without CONFIG_OF so it feels like the dependency is
> natural anyways.
> 

@Bjorn: Do you still want to add a comment for the dependency?

- Mani

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
  2025-10-14 18:20 [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning Nathan Chancellor
  2025-10-14 19:13 ` Bjorn Helgaas
@ 2025-12-18  5:23 ` Manivannan Sadhasivam
  2025-12-26 23:46   ` Bjorn Helgaas
  1 sibling, 1 reply; 7+ messages in thread
From: Manivannan Sadhasivam @ 2025-12-18  5:23 UTC (permalink / raw)
  To: Marek Vasut, Yoshihiro Shimoda, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
	Nathan Chancellor
  Cc: Geert Uytterhoeven, Magnus Damm, Kees Cook, Peter Zijlstra,
	linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot


On Tue, 14 Oct 2025 11:20:27 -0700, Nathan Chancellor wrote:
> After commit 894af4a1cde6 ("objtool: Validate kCFI calls"), compile
> testing pcie-rcar-host.c with CONFIG_FINEIBT=y and CONFIG_OF=n results
> in a no-cfi objtool warning in rcar_pcie_probe():
> 
>   $ cat allno.config
>   CONFIG_CFI=y
>   CONFIG_COMPILE_TEST=y
>   CONFIG_CPU_MITIGATIONS=y
>   CONFIG_GENERIC_PHY=y
>   CONFIG_MITIGATION_RETPOLINE=y
>   CONFIG_MODULES=y
>   CONFIG_PCI=y
>   CONFIG_PCI_MSI=y
>   CONFIG_PCIE_RCAR_HOST=y
>   CONFIG_X86_KERNEL_IBT=y
> 
> [...]

Applied, thanks!

[1/1] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
      commit: 57833f84f6f5967134c9c1119289f7acdd1c93e9

Best regards,
-- 
Manivannan Sadhasivam <mani@kernel.org>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
  2025-12-18  5:23 ` Manivannan Sadhasivam
@ 2025-12-26 23:46   ` Bjorn Helgaas
  0 siblings, 0 replies; 7+ messages in thread
From: Bjorn Helgaas @ 2025-12-26 23:46 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: Marek Vasut, Yoshihiro Shimoda, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
	Nathan Chancellor, Geert Uytterhoeven, Magnus Damm, Kees Cook,
	Peter Zijlstra, linux-pci, linux-renesas-soc, linux-kernel, llvm,
	kernel test robot

On Thu, Dec 18, 2025 at 10:53:00AM +0530, Manivannan Sadhasivam wrote:
> On Tue, 14 Oct 2025 11:20:27 -0700, Nathan Chancellor wrote:
> > After commit 894af4a1cde6 ("objtool: Validate kCFI calls"), compile
> > testing pcie-rcar-host.c with CONFIG_FINEIBT=y and CONFIG_OF=n results
> > in a no-cfi objtool warning in rcar_pcie_probe():
> > 
> >   $ cat allno.config
> >   CONFIG_CFI=y
> >   CONFIG_COMPILE_TEST=y
> >   CONFIG_CPU_MITIGATIONS=y
> >   CONFIG_GENERIC_PHY=y
> >   CONFIG_MITIGATION_RETPOLINE=y
> >   CONFIG_MODULES=y
> >   CONFIG_PCI=y
> >   CONFIG_PCI_MSI=y
> >   CONFIG_PCIE_RCAR_HOST=y
> >   CONFIG_X86_KERNEL_IBT=y
> > 
> > [...]
> 
> Applied, thanks!
> 
> [1/1] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning
>       commit: 57833f84f6f5967134c9c1119289f7acdd1c93e9

Is this v6.19 material?  The patch is old, 894af4a1cde6 appeared in
v6.18, and it's not really a regression, but it only affects
PCIE_RCAR_HOST and it looks like it papers over a headache for static
analysis.

Bjorn

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-26 23:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 18:20 [PATCH v2] PCI: rcar-host: Add OF Kconfig dependency to avoid objtool no-cfi warning Nathan Chancellor
2025-10-14 19:13 ` Bjorn Helgaas
2025-10-14 19:47   ` Peter Zijlstra
2025-10-14 22:25     ` Nathan Chancellor
2025-10-27 12:26       ` Manivannan Sadhasivam
2025-12-18  5:23 ` Manivannan Sadhasivam
2025-12-26 23:46   ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox