Patchwork [15/17] powerpc: crypto: sysfs routines and docs for the nx device driver

login
register
mail settings
Submitter Kent Yoder
Date March 21, 2012, 9:41 p.m.
Message ID <1332366080.3858.52.camel@key-ThinkPad-W510>
Download mbox | patch
Permalink /patch/148113/
State Changes Requested
Headers show

Comments

Kent Yoder - March 21, 2012, 9:41 p.m.
These routines add sysfs files supporting the Power7+ in-Nest encryption
accelerator driver.

Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com>
---
 Documentation/powerpc/pfo-nx-crypto.txt |   52 ++++++++
 arch/powerpc/crypto/nx/nx_sysfs.c       |  194 +++++++++++++++++++++++++++++++
 2 files changed, 246 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/powerpc/pfo-nx-crypto.txt
 create mode 100644 arch/powerpc/crypto/nx/nx_sysfs.c
Kent Yoder - March 21, 2012, 10:46 p.m.
Hi Greg,

On Wed, 2012-03-21 at 15:11 -0700, Greg KH wrote:
> On Wed, Mar 21, 2012 at 04:41:20PM -0500, Kent Yoder wrote:
> > These routines add sysfs files supporting the Power7+ in-Nest encryption
> > accelerator driver.
> > 
> > Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com>
> > ---
> >  Documentation/powerpc/pfo-nx-crypto.txt |   52 ++++++++
> 
> Please put sysfs file information in Documentation/ABI/ where it
> belongs.

  Will do, I see debugfs docs in there too.

> Shouldn't the first just be debugfs files, as no "normal" user will ever
> care about such a thing?
> 
> Actually, why are these sysfs files at all, how about all of this going
> into debugfs?

  Yes, that's fine.  These really are just for checking 'am I really
doing hardware encryption' and debugging any return codes that may come
back from the hcall. The error return is probably more easily dev_err'd
though.

> 
> > +Error Detection
> > +===============
> 
> <snip>
> 
> What can anyone do with any of these files?  What use are they to users?
> 
> > +Device Use
> > +==========
> 
> Again, what does a user care about these items for?
> 
> > +int
> > +nx_sysfs_init(struct device_driver *drv)
> > +{
> > +	int rc;
> > +
> > +	rc = driver_create_file(drv, &driver_attr_aes_ops);
> > +	if (rc)
> > +		goto out;
> 
> <snip>
> 
> Oh, ${DIETY}, no.  Please don't create files one by one, we do have
> functions that do all of this for you automatically, why aren't you
> using them?

  Ok, I'll go look for some debugfs wrappers.

> > +void
> > +nx_sysfs_fini(struct device_driver *drv)
> > +{
> > +	driver_remove_file(drv, &driver_attr_sync_ops);
> > +	driver_remove_file(drv, &driver_attr_aes_bytes);
> > +	driver_remove_file(drv, &driver_attr_aes_ops);
> > +	driver_remove_file(drv, &driver_attr_sha256_bytes);
> > +	driver_remove_file(drv, &driver_attr_sha256_ops);
> > +	driver_remove_file(drv, &driver_attr_sha512_bytes);
> > +	driver_remove_file(drv, &driver_attr_sha512_ops);
> 
> Same here, don't do this, do it all at once.
> 
> > +}
> 
> Who is calling these functions?  Where in the device lifecycle are the
> files being created?  Did you just race userspace with how they are
> created, or are you doing it "properly"?  (hint, odds are, as you are
> trying to manually create and remove these by hand, you aren't doing it
> properly...)

  We're not racing here, other than with cat.  Just so an admin can see
his workload is getting offloaded.

Thanks,
Kent

> thanks,
> 
> greg k-h
>

Patch

diff --git a/Documentation/powerpc/pfo-nx-crypto.txt b/Documentation/powerpc/pfo-nx-crypto.txt
new file mode 100644
index 0000000..63440d3
--- /dev/null
+++ b/Documentation/powerpc/pfo-nx-crypto.txt
@@ -0,0 +1,52 @@ 
+
+Documentation for the sysfs interfaces provided by the nx-crypto driver, built
+in arch/powerpc/crypto/nx.
+
+The driver provides 2 sets of sysfs files, 1 for confirming that the device is
+actually being used and 1 for error detection.
+
+All sysfs files can be found in:
+
+	/sys/bus/vio/drivers/nx
+
+Error Detection
+===============
+
+errors:
+- A u32 providing a total count of errors since the driver was loaded. The
+only errors counted here are those returned from the hcall, H_COP_OP.
+
+last_error:
+- The most recent non-zero return code from the H_COP_OP hcall. -EBUSY is not
+recorded here (the hcall will retry until -EBUSY goes away).
+
+last_error_pid:
+- The process ID of the process who received the most recent error from the
+hcall.
+
+Notes on error detection:
+  H_RH_PARM (invalid hardware resource ID) and H_HARDWARE (hardware failure)
+are not recorded in the errors or last_error sysfs files, since they are
+signals to the driver to fall back to software.
+
+Device Use
+==========
+
+aes_bytes:
+- The total number of bytes encrypted using AES in any of the driver's
+supported modes.
+
+aes_ops:
+- The total number of AES operations submitted to the hardware.
+
+sha256_bytes:
+- The total number of bytes hashed by the hardware using SHA-256.
+
+sha256_ops:
+- The total number of SHA-256 operations submitted to the hardware.
+
+sha512_bytes:
+- The total number of bytes hashed by the hardware using SHA-512.
+
+sha512_ops:
+- The total number of SHA-512 operations submitted to the hardware.
diff --git a/arch/powerpc/crypto/nx/nx_sysfs.c b/arch/powerpc/crypto/nx/nx_sysfs.c
new file mode 100644
index 0000000..02c84e7
--- /dev/null
+++ b/arch/powerpc/crypto/nx/nx_sysfs.c
@@ -0,0 +1,194 @@ 
+/**
+ * sysfs routines supporting the Power 7+ Nest Accelerators driver
+ *
+ * Copyright (C) 2011-2012 International Business Machines Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 only.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Kent Yoder <yoder1@us.ibm.com>
+ */
+
+#include <linux/device.h>
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/crypto.h>
+#include <crypto/hash.h>
+#include <asm/vio.h>
+
+#include "nx_csbcpb.h"
+#include "nx.h"
+
+
+/* sysfs attributes and callbacks
+ *
+ * For documentation on these attributes, please see:
+ *
+ * Documentation/powerpc/pfo-nx-crypto.txt
+ */
+static ssize_t
+nx_attr_show_sha256_ops(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&nx_driver.stats.sha256_ops));
+}
+static DRIVER_ATTR(sha256_ops, S_IRUGO, nx_attr_show_sha256_ops, NULL);
+
+static ssize_t
+nx_attr_show_sha256_bytes(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%ld\n",
+		       atomic64_read(&nx_driver.stats.sha256_bytes));
+}
+static DRIVER_ATTR(sha256_bytes, S_IRUGO, nx_attr_show_sha256_bytes, NULL);
+
+static ssize_t
+nx_attr_show_sha512_ops(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&nx_driver.stats.sha512_ops));
+}
+static DRIVER_ATTR(sha512_ops, S_IRUGO, nx_attr_show_sha512_ops, NULL);
+
+static ssize_t
+nx_attr_show_sha512_bytes(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%ld\n",
+		       atomic64_read(&nx_driver.stats.sha512_bytes));
+}
+static DRIVER_ATTR(sha512_bytes, S_IRUGO, nx_attr_show_sha512_bytes, NULL);
+
+static ssize_t
+nx_attr_show_aes_ops(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&nx_driver.stats.aes_ops));
+}
+static DRIVER_ATTR(aes_ops, S_IRUGO, nx_attr_show_aes_ops, NULL);
+
+static ssize_t
+nx_attr_show_aes_bytes(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%ld\n", atomic64_read(&nx_driver.stats.aes_bytes));
+}
+static DRIVER_ATTR(aes_bytes, S_IRUGO, nx_attr_show_aes_bytes, NULL);
+
+static ssize_t
+nx_attr_show_sync_ops(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&nx_driver.stats.sync_ops));
+}
+static DRIVER_ATTR(sync_ops, S_IRUGO, nx_attr_show_sync_ops, NULL);
+
+static ssize_t
+nx_attr_show_errors(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&nx_driver.stats.errors));
+}
+static DRIVER_ATTR(errors, S_IRUGO, nx_attr_show_errors, NULL);
+
+static ssize_t
+nx_attr_show_last_error(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n", atomic_read(&nx_driver.stats.last_error));
+}
+static DRIVER_ATTR(last_error, S_IRUGO, nx_attr_show_last_error, NULL);
+
+static ssize_t
+nx_attr_show_last_error_pid(struct device_driver *driver, char *buf)
+{
+	return sprintf(buf, "%d\n",
+		       atomic_read(&nx_driver.stats.last_error_pid));
+}
+static DRIVER_ATTR(last_error_pid, S_IRUGO, nx_attr_show_last_error_pid, NULL);
+
+int
+nx_sysfs_init(struct device_driver *drv)
+{
+	int rc;
+
+	rc = driver_create_file(drv, &driver_attr_aes_ops);
+	if (rc)
+		goto out;
+
+	rc = driver_create_file(drv, &driver_attr_aes_bytes);
+	if (rc)
+		goto out2_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_sync_ops);
+	if (rc)
+		goto out3_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_sha256_ops);
+	if (rc)
+		goto out4_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_sha256_bytes);
+	if (rc)
+		goto out5_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_sha512_ops);
+	if (rc)
+		goto out6_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_sha512_bytes);
+	if (rc)
+		goto out7_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_errors);
+	if (rc)
+		goto out8_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_last_error);
+	if (rc)
+		goto out9_unreg;
+
+	rc = driver_create_file(drv, &driver_attr_last_error_pid);
+	if (rc)
+		goto out10_unreg;
+
+	goto out;
+
+out10_unreg:
+	driver_remove_file(drv, &driver_attr_last_error);
+out9_unreg:
+	driver_remove_file(drv, &driver_attr_errors);
+out8_unreg:
+	driver_remove_file(drv, &driver_attr_sha512_bytes);
+out7_unreg:
+	driver_remove_file(drv, &driver_attr_sha512_ops);
+out6_unreg:
+	driver_remove_file(drv, &driver_attr_sha256_bytes);
+out5_unreg:
+	driver_remove_file(drv, &driver_attr_sha256_ops);
+out4_unreg:
+	driver_remove_file(drv, &driver_attr_sync_ops);
+out3_unreg:
+	driver_remove_file(drv, &driver_attr_aes_bytes);
+out2_unreg:
+	driver_remove_file(drv, &driver_attr_aes_ops);
+out:
+	return rc;
+}
+
+void
+nx_sysfs_fini(struct device_driver *drv)
+{
+	driver_remove_file(drv, &driver_attr_sync_ops);
+	driver_remove_file(drv, &driver_attr_aes_bytes);
+	driver_remove_file(drv, &driver_attr_aes_ops);
+	driver_remove_file(drv, &driver_attr_sha256_bytes);
+	driver_remove_file(drv, &driver_attr_sha256_ops);
+	driver_remove_file(drv, &driver_attr_sha512_bytes);
+	driver_remove_file(drv, &driver_attr_sha512_ops);
+}