Re: [PATCH] crypto: prevent nx 842 load if no hw driver

2015-06-03 Thread Dan Streetman
On Wed, Jun 3, 2015 at 1:08 AM, Herbert Xu herb...@gondor.apana.org.au wrote:
 On Thu, May 28, 2015 at 04:21:31PM -0400, Dan Streetman wrote:
 Change the nx-842 common driver to wait for loading of both platform
 drivers, and fail loading if the platform driver pointer is not set.
 Add an independent platform driver pointer, that the platform drivers
 set if they find they are able to load (i.e. if they find their platform
 devicetree node(s)).

 The problem is currently, the main nx-842 driver will stay loaded even
 if there is no platform driver and thus no possible way it can do any
 compression or decompression.  This allows the crypto 842-nx driver
 to load even if it won't actually work.  For crypto compression users
 (e.g. zswap) that expect an available crypto compression driver to
 actually work, this is bad.  This patch fixes that, so the 842-nx crypto
 compression driver won't load if it doesn't have the driver and hardware
 available to perform the compression.

 Signed-off-by: Dan Streetman ddstr...@ieee.org

 Applied.  Though I had to do the Makefile bit by hand because
 it contains references to nx-compress-test which doesn't exist
 in my tree.

Oops sorry, I forgot to remove that old test module patch from my tree.

Thanks.


 --
 Email: Herbert Xu herb...@gondor.apana.org.au
 Home Page: http://gondor.apana.org.au/~herbert/
 PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
 --
 To unsubscribe from this list: send the line unsubscribe linux-crypto in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] crypto: prevent nx 842 load if no hw driver

2015-06-02 Thread Herbert Xu
On Thu, May 28, 2015 at 04:21:31PM -0400, Dan Streetman wrote:
 Change the nx-842 common driver to wait for loading of both platform
 drivers, and fail loading if the platform driver pointer is not set.
 Add an independent platform driver pointer, that the platform drivers
 set if they find they are able to load (i.e. if they find their platform
 devicetree node(s)).
 
 The problem is currently, the main nx-842 driver will stay loaded even
 if there is no platform driver and thus no possible way it can do any
 compression or decompression.  This allows the crypto 842-nx driver
 to load even if it won't actually work.  For crypto compression users
 (e.g. zswap) that expect an available crypto compression driver to
 actually work, this is bad.  This patch fixes that, so the 842-nx crypto
 compression driver won't load if it doesn't have the driver and hardware
 available to perform the compression.
 
 Signed-off-by: Dan Streetman ddstr...@ieee.org

Applied.  Though I had to do the Makefile bit by hand because
it contains references to nx-compress-test which doesn't exist
in my tree.
-- 
Email: Herbert Xu herb...@gondor.apana.org.au
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: prevent nx 842 load if no hw driver

2015-05-28 Thread Dan Streetman
Change the nx-842 common driver to wait for loading of both platform
drivers, and fail loading if the platform driver pointer is not set.
Add an independent platform driver pointer, that the platform drivers
set if they find they are able to load (i.e. if they find their platform
devicetree node(s)).

The problem is currently, the main nx-842 driver will stay loaded even
if there is no platform driver and thus no possible way it can do any
compression or decompression.  This allows the crypto 842-nx driver
to load even if it won't actually work.  For crypto compression users
(e.g. zswap) that expect an available crypto compression driver to
actually work, this is bad.  This patch fixes that, so the 842-nx crypto
compression driver won't load if it doesn't have the driver and hardware
available to perform the compression.

Signed-off-by: Dan Streetman ddstr...@ieee.org
---
 drivers/crypto/nx/Makefile  |   3 +-
 drivers/crypto/nx/nx-842-platform.c |  84 +++
 drivers/crypto/nx/nx-842-powernv.c  |  17 +++--
 drivers/crypto/nx/nx-842-pseries.c  |  33 ++---
 drivers/crypto/nx/nx-842.c  | 130 ++--
 drivers/crypto/nx/nx-842.h  |  16 ++---
 6 files changed, 148 insertions(+), 135 deletions(-)
 create mode 100644 drivers/crypto/nx/nx-842-platform.c

diff --git a/drivers/crypto/nx/Makefile b/drivers/crypto/nx/Makefile
index 8e3512d..9d56205 100644
--- a/drivers/crypto/nx/Makefile
+++ b/drivers/crypto/nx/Makefile
@@ -10,12 +10,13 @@ nx-crypto-objs := nx.o \
  nx-sha256.o \
  nx-sha512.o
 
-obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS) += nx-compress.o
+obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS) += nx-compress.o nx-compress-platform.o
 obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o
 obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o
 obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_CRYPTO) += nx-compress-crypto.o
 obj-$(CONFIG_CRYPTO_DEV_NX_SELFTEST) += nx-compress-test.o
 nx-compress-objs := nx-842.o
+nx-compress-platform-objs := nx-842-platform.o
 nx-compress-pseries-objs := nx-842-pseries.o
 nx-compress-powernv-objs := nx-842-powernv.o
 nx-compress-crypto-objs := nx-842-crypto.o
diff --git a/drivers/crypto/nx/nx-842-platform.c 
b/drivers/crypto/nx/nx-842-platform.c
new file mode 100644
index 000..664f13d
--- /dev/null
+++ b/drivers/crypto/nx/nx-842-platform.c
@@ -0,0 +1,84 @@
+
+#include nx-842.h
+
+/* this is needed, separate from the main nx-842.c driver, because that main
+ * driver loads the platform drivers during its init(), and it expects one
+ * (or none) of the platform drivers to set this pointer to its driver.
+ * That means this pointer can't be in the main nx-842 driver, because it
+ * wouldn't be accessible until after the main driver loaded, which wouldn't
+ * be possible as it's waiting for the platform driver to load.  So place it
+ * here.
+ */
+static struct nx842_driver *driver;
+static DEFINE_SPINLOCK(driver_lock);
+
+struct nx842_driver *nx842_platform_driver(void)
+{
+   return driver;
+}
+EXPORT_SYMBOL_GPL(nx842_platform_driver);
+
+bool nx842_platform_driver_set(struct nx842_driver *_driver)
+{
+   bool ret = false;
+
+   spin_lock(driver_lock);
+
+   if (!driver) {
+   driver = _driver;
+   ret = true;
+   } else
+   WARN(1, can't set platform driver, already set to %s\n,
+driver-name);
+
+   spin_unlock(driver_lock);
+   return ret;
+}
+EXPORT_SYMBOL_GPL(nx842_platform_driver_set);
+
+/* only call this from the platform driver exit function */
+void nx842_platform_driver_unset(struct nx842_driver *_driver)
+{
+   spin_lock(driver_lock);
+
+   if (driver == _driver)
+   driver = NULL;
+   else if (driver)
+   WARN(1, can't unset platform driver %s, currently set to %s\n,
+_driver-name, driver-name);
+   else
+   WARN(1, can't unset platform driver, already unset\n);
+
+   spin_unlock(driver_lock);
+}
+EXPORT_SYMBOL_GPL(nx842_platform_driver_unset);
+
+bool nx842_platform_driver_get(void)
+{
+   bool ret = false;
+
+   spin_lock(driver_lock);
+
+   if (driver)
+   ret = try_module_get(driver-owner);
+
+   spin_unlock(driver_lock);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(nx842_platform_driver_get);
+
+void nx842_platform_driver_put(void)
+{
+   spin_lock(driver_lock);
+
+   if (driver)
+   module_put(driver-owner);
+
+   spin_unlock(driver_lock);
+}
+EXPORT_SYMBOL_GPL(nx842_platform_driver_put);
+
+MODULE_LICENSE(GPL);
+MODULE_AUTHOR(Dan Streetman ddstr...@ieee.org);
+MODULE_DESCRIPTION(842 H/W Compression platform driver);
diff --git a/drivers/crypto/nx/nx-842-powernv.c 
b/drivers/crypto/nx/nx-842-powernv.c
index 6a9fb8b..c388dba 100644
--- a/drivers/crypto/nx/nx-842-powernv.c
+++ b/drivers/crypto/nx/nx-842-powernv.c
@@ -23,7 +23,6 @@
 #include