Re: [RFC] x86/pci: Mark pci_root_ops as const

2018-11-08 Thread Bjorn Helgaas
Hi Zubin,

On Thu, Nov 08, 2018 at 09:11:15AM -0800, Zubin Mithra wrote:
> pci_root_ops is only written to from within intel_mid_pci_init. This
> is linked in only when CONFIG_X86_INTEL_MID is set. If not for this,
> pci_root_ops could be marked as const.
> 
> Fix this by replacing pci_root_ops usage with pci_root_ops_ptr. If
> CONFIG_X86_INTEL_MID is set, pci_root_ops_ptr will be set to
> intel_mid_pci_ops inside intel_mid_pci_init.
> 
> Introduce pci_acpi_set_ops for intel_mid_pci_init to set
> acpi_pci_root_ops.pci_ops.
> 
> This also means that intel_mid_pci_ops cannot be freed after init, hence
> remove __initconst.
> 
> Signed-off-by: Zubin Mithra 
> ---
>  arch/x86/include/asm/pci_x86.h |  4 +++-
>  arch/x86/pci/acpi.c|  5 +
>  arch/x86/pci/common.c  |  5 +++--
>  arch/x86/pci/intel_mid_pci.c   |  5 +++--
>  drivers/pci/access.c   |  4 ++--
>  drivers/pci/probe.c|  4 ++--
>  include/linux/pci-acpi.h   |  2 +-
>  include/linux/pci.h| 11 ++-
>  8 files changed, 25 insertions(+), 15 deletions(-)

Can you:

  - Split this into an x86 patch and a PCI core patch (if possible)?
  - Make the same fixes for other arches?

Bjorn


[RFC] x86/pci: Mark pci_root_ops as const

2018-11-08 Thread Zubin Mithra
pci_root_ops is only written to from within intel_mid_pci_init. This
is linked in only when CONFIG_X86_INTEL_MID is set. If not for this,
pci_root_ops could be marked as const.

Fix this by replacing pci_root_ops usage with pci_root_ops_ptr. If
CONFIG_X86_INTEL_MID is set, pci_root_ops_ptr will be set to
intel_mid_pci_ops inside intel_mid_pci_init.

Introduce pci_acpi_set_ops for intel_mid_pci_init to set
acpi_pci_root_ops.pci_ops.

This also means that intel_mid_pci_ops cannot be freed after init, hence
remove __initconst.

Signed-off-by: Zubin Mithra 
---
 arch/x86/include/asm/pci_x86.h |  4 +++-
 arch/x86/pci/acpi.c|  5 +
 arch/x86/pci/common.c  |  5 +++--
 arch/x86/pci/intel_mid_pci.c   |  5 +++--
 drivers/pci/access.c   |  4 ++--
 drivers/pci/probe.c|  4 ++--
 include/linux/pci-acpi.h   |  2 +-
 include/linux/pci.h| 11 ++-
 8 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
index 959d618dbb17..1e82ddaeb52f 100644
--- a/arch/x86/include/asm/pci_x86.h
+++ b/arch/x86/include/asm/pci_x86.h
@@ -58,7 +58,8 @@ void pcibios_set_cache_line_size(void);
 /* pci-pc.c */
 
 extern int pcibios_last_bus;
-extern struct pci_ops pci_root_ops;
+extern const struct pci_ops pci_root_ops;
+extern const struct pci_ops *pci_root_ops_ptr;
 
 void pcibios_scan_specific_bus(int busn);
 
@@ -122,6 +123,7 @@ extern void __init dmi_check_skip_isa_align(void);
 
 /* some common used subsys_initcalls */
 extern int __init pci_acpi_init(void);
+extern void __init pci_acpi_set_ops(const struct pci_ops *ops);
 extern void __init pcibios_irq_init(void);
 extern int __init pcibios_init(void);
 extern int pci_legacy_init(void);
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 948656069cdd..63ebac5fa212 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -397,6 +397,11 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge 
*bridge)
return 0;
 }
 
+void __init pci_acpi_set_ops(const struct pci_ops *ops)
+{
+   acpi_pci_root_ops.pci_ops = ops;
+}
+
 int __init pci_acpi_init(void)
 {
struct pci_dev *dev = NULL;
diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
index d4ec117c1142..747a8e9fd430 100644
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -67,10 +67,11 @@ static int pci_write(struct pci_bus *bus, unsigned int 
devfn, int where, int siz
  devfn, where, size, value);
 }
 
-struct pci_ops pci_root_ops = {
+const struct pci_ops pci_root_ops = {
.read = pci_read,
.write = pci_write,
 };
+const struct pci_ops *pci_root_ops_ptr = &pci_root_ops;
 
 /*
  * This interrupt-safe spinlock protects all accesses to PCI configuration
@@ -467,7 +468,7 @@ void pcibios_scan_root(int busnum)
sd->node = x86_pci_root_bus_node(busnum);
x86_pci_root_bus_resources(busnum, &resources);
printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
-   bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, sd, &resources);
+   bus = pci_scan_root_bus(NULL, busnum, pci_root_ops_ptr, sd, &resources);
if (!bus) {
pci_free_resource_list(&resources);
kfree(sd);
diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
index 43867bc85368..b79c469afd57 100644
--- a/arch/x86/pci/intel_mid_pci.c
+++ b/arch/x86/pci/intel_mid_pci.c
@@ -280,7 +280,7 @@ static void intel_mid_pci_irq_disable(struct pci_dev *dev)
}
 }
 
-static const struct pci_ops intel_mid_pci_ops __initconst = {
+static const struct pci_ops intel_mid_pci_ops = {
.read = pci_read,
.write = pci_write,
 };
@@ -297,7 +297,8 @@ int __init intel_mid_pci_init(void)
pci_mmcfg_late_init();
pcibios_enable_irq = intel_mid_pci_irq_enable;
pcibios_disable_irq = intel_mid_pci_irq_disable;
-   pci_root_ops = intel_mid_pci_ops;
+   pci_root_ops_ptr = &intel_mid_pci_ops;
+   pci_acpi_set_ops(&intel_mid_pci_ops);
pci_soc_mode = 1;
/* Continue with standard init */
acpi_noirq_set();
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 544922f097c0..ca9d3cbc5541 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -180,9 +180,9 @@ EXPORT_SYMBOL_GPL(pci_generic_config_write32);
  *
  * Return previous raw operations
  */
-struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
+const struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, const struct 
pci_ops *ops)
 {
-   struct pci_ops *old_ops;
+   const struct pci_ops *old_ops;
unsigned long flags;
 
raw_spin_lock_irqsave(&pci_lock, flags);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b1c05b5054a0..c66c84ef070a 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2915,7 +2915,7 @@ void __weak pcibios_remove_bus(struct pci_bus *bus)
 }
 
 struct pci_bus *pci_cre