linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/powernv: fix pci-cxl.c build when CONFIG_MODULES=n
@ 2016-07-18  7:53 Andrew Donnellan
  2016-07-19  2:33 ` [PATCH v2] " Ian Munsie
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Donnellan @ 2016-07-18  7:53 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: imunsie

From: Ian Munsie <imunsie@au1.ibm.com>

pnv_cxl_enable_phb_kernel_api() grabs a reference to the cxl module to
prevent it from being unloaded after the PHB has been switched to CX4 mode.
This breaks the build when CONFIG_MODULES=n as module_mutex doesn't exist.

However, if we don't have modules, we don't need to protect against the
case of the cxl module being unloaded. As such, split the relevant
code out into a function surrounded with #if IS_MODULE(CXL) so we don't try
to compile it if cxl isn't being compiled as a module.

Fixes: 5918dbc9b4ec ("powerpc/powernv: Add support for the cxl kernel api
on the real phb")
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

---

Compile tested only.
---
 arch/powerpc/platforms/powernv/pci-cxl.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-cxl.c b/arch/powerpc/platforms/powernv/pci-cxl.c
index 1559ca2..40b9d19 100644
--- a/arch/powerpc/platforms/powernv/pci-cxl.c
+++ b/arch/powerpc/platforms/powernv/pci-cxl.c
@@ -166,6 +166,23 @@ int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
 }
 EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
 
+#if IS_MODULE(cxl)
+static inline void get_cxl_module(void)
+{
+       struct module *cxl_module;
+
+       mutex_lock(&module_mutex);
+       cxl_module = find_module("cxl");
+       if (cxl_module)
+              __module_get(cxl_module);
+       mutex_unlock(&module_mutex);
+       if (!cxl_module)
+              return -ENODEV;
+}
+#else
+static inline void get_cxl_module(void) {}
+#endif
+
 /*
  * Sets flags and switches the controller ops to enable the cxl kernel api.
  * Original the cxl kernel API operated on a virtual PHB, but certain cards
@@ -175,7 +192,6 @@ EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
 int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable)
 {
 	struct pnv_phb *phb = hose->private_data;
-	struct module *cxl_module;
 
 	if (!enable) {
 		/*
@@ -194,13 +210,7 @@ int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable)
 	 * long as we are in this mode (and since we can't safely disable this
 	 * mode once enabled...).
 	 */
-	mutex_lock(&module_mutex);
-	cxl_module = find_module("cxl");
-	if (cxl_module)
-		__module_get(cxl_module);
-	mutex_unlock(&module_mutex);
-	if (!cxl_module)
-		return -ENODEV;
+	get_cxl_module();
 
 	phb->flags |= PNV_PHB_FLAG_CXL;
 	hose->controller_ops = pnv_cxl_cx4_ioda_controller_ops;
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

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

* [PATCH v2] powerpc/powernv: fix pci-cxl.c build when CONFIG_MODULES=n
  2016-07-18  7:53 [PATCH] powerpc/powernv: fix pci-cxl.c build when CONFIG_MODULES=n Andrew Donnellan
@ 2016-07-19  2:33 ` Ian Munsie
  2016-07-20  9:10   ` [v2] " Michael Ellerman
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Munsie @ 2016-07-19  2:33 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: Ian Munsie, Andrew Donnellan

From: Ian Munsie <imunsie@au1.ibm.com>

pnv_cxl_enable_phb_kernel_api() grabs a reference to the cxl module to
prevent it from being unloaded after the PHB has been switched to CX4 mode.
This breaks the build when CONFIG_MODULES=n as module_mutex doesn't exist.

However, if we don't have modules, we don't need to protect against the
case of the cxl module being unloaded. As such, split the relevant
code out into a function surrounded with #if IS_MODULE(CXL) so we don't try
to compile it if cxl isn't being compiled as a module.

Fixes: 5918dbc9b4ec ("powerpc/powernv: Add support for the cxl kernel api
on the real phb")
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

---

Changes since v1:
	- Actually tested now our systems are back online
	- Passed error code back to caller
	- Fixed IS_MODULE(cxl) to IS_MODULE(CONFIG_CXL)
	- Face was introduced to palm, several times
---
 arch/powerpc/platforms/powernv/pci-cxl.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-cxl.c b/arch/powerpc/platforms/powernv/pci-cxl.c
index 3f34207..2d67be0 100644
--- a/arch/powerpc/platforms/powernv/pci-cxl.c
+++ b/arch/powerpc/platforms/powernv/pci-cxl.c
@@ -166,6 +166,24 @@ int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
 }
 EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
 
+#if IS_MODULE(CONFIG_CXL)
+static inline int get_cxl_module(void)
+{
+       struct module *cxl_module;
+
+       mutex_lock(&module_mutex);
+       cxl_module = find_module("cxl");
+       if (cxl_module)
+              __module_get(cxl_module);
+       mutex_unlock(&module_mutex);
+       if (!cxl_module)
+              return -ENODEV;
+       return 0;
+}
+#else
+static inline int get_cxl_module(void) { return 0; }
+#endif
+
 /*
  * Sets flags and switches the controller ops to enable the cxl kernel api.
  * Originally the cxl kernel API operated on a virtual PHB, but certain cards
@@ -175,7 +193,7 @@ EXPORT_SYMBOL(pnv_cxl_ioda_msi_setup);
 int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable)
 {
 	struct pnv_phb *phb = hose->private_data;
-	struct module *cxl_module;
+	int rc;
 
 	if (!enable) {
 		/*
@@ -194,13 +212,9 @@ int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable)
 	 * long as we are in this mode (and since we can't safely disable this
 	 * mode once enabled...).
 	 */
-	mutex_lock(&module_mutex);
-	cxl_module = find_module("cxl");
-	if (cxl_module)
-		__module_get(cxl_module);
-	mutex_unlock(&module_mutex);
-	if (!cxl_module)
-		return -ENODEV;
+	rc = get_cxl_module();
+	if (rc)
+		return rc;
 
 	phb->flags |= PNV_PHB_FLAG_CXL;
 	hose->controller_ops = pnv_cxl_cx4_ioda_controller_ops;
-- 
2.8.1

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

* Re: [v2] powerpc/powernv: fix pci-cxl.c build when CONFIG_MODULES=n
  2016-07-19  2:33 ` [PATCH v2] " Ian Munsie
@ 2016-07-20  9:10   ` Michael Ellerman
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2016-07-20  9:10 UTC (permalink / raw)
  To: Ian Munsie, linuxppc-dev; +Cc: Ian Munsie, Andrew Donnellan

On Tue, 2016-19-07 at 02:33:35 UTC, Ian Munsie wrote:
> From: Ian Munsie <imunsie@au1.ibm.com>
> 
> pnv_cxl_enable_phb_kernel_api() grabs a reference to the cxl module to
> prevent it from being unloaded after the PHB has been switched to CX4 mode.
> This breaks the build when CONFIG_MODULES=n as module_mutex doesn't exist.
> 
> However, if we don't have modules, we don't need to protect against the
> case of the cxl module being unloaded. As such, split the relevant
> code out into a function surrounded with #if IS_MODULE(CXL) so we don't try
> to compile it if cxl isn't being compiled as a module.
> 
> Fixes: 5918dbc9b4ec ("powerpc/powernv: Add support for the cxl kernel api
> on the real phb")
> Reported-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/c2ca9f6b4cc4c45eb598b24b8b

cheers

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

end of thread, other threads:[~2016-07-20  9:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-18  7:53 [PATCH] powerpc/powernv: fix pci-cxl.c build when CONFIG_MODULES=n Andrew Donnellan
2016-07-19  2:33 ` [PATCH v2] " Ian Munsie
2016-07-20  9:10   ` [v2] " Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).