From: Nayna Jain <nayna@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: gjoyce@linux.vnet.ibm.com, erichte@linux.ibm.com,
npiggin@gmail.com, muriloo@linux.ibm.com,
George Wilson <gcwilson@linux.ibm.com>,
bjking1@us.ibmcom
Subject: [PATCH v2 3/3] powerpc/pseries: Override lib/arch_vars.c with PowerPC architecture specific version
Date: Sat, 23 Jul 2022 07:30:48 -0400 [thread overview]
Message-ID: <20220723113048.521744-4-nayna@linux.ibm.com> (raw)
In-Reply-To: <20220723113048.521744-1-nayna@linux.ibm.com>
From: Greg Joyce <gjoyce@linux.vnet.ibm.com>
Self Encrypting Drives(SED) make use of POWER LPAR Platform KeyStore for
storing its variables. Thus the block subsystem needs to access
PowerPC specific functions to read/write objects in PLPKS.
Override the default implementations in lib/arch_vars.c file with
PowerPC specific versions.
Signed-off-by: Greg Joyce <gjoyce@linux.vnet.ibm.com>
---
arch/powerpc/platforms/pseries/Makefile | 1 +
.../platforms/pseries/plpks_arch_ops.c | 166 ++++++++++++++++++
2 files changed, 167 insertions(+)
create mode 100644 arch/powerpc/platforms/pseries/plpks_arch_ops.c
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index 14e143b946a3..3a545422eae5 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_PPC_SPLPAR) += vphn.o
obj-$(CONFIG_PPC_SVM) += svm.o
obj-$(CONFIG_FA_DUMP) += rtas-fadump.o
obj-$(CONFIG_PSERIES_PLPKS) += plpks.o
+obj-$(CONFIG_PSERIES_PLPKS) += plpks_arch_ops.o
obj-$(CONFIG_SUSPEND) += suspend.o
obj-$(CONFIG_PPC_VAS) += vas.o vas-sysfs.o
diff --git a/arch/powerpc/platforms/pseries/plpks_arch_ops.c b/arch/powerpc/platforms/pseries/plpks_arch_ops.c
new file mode 100644
index 000000000000..48fa19f0c9c5
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/plpks_arch_ops.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * POWER Platform arch specific code for SED
+ * Copyright (C) 2022 IBM Corporation
+ *
+ * Define operations for generic kernel subsystems to read/write keys from
+ * POWER LPAR Platform KeyStore(PLPKS).
+ *
+ * List of subsystems/usecase using PLPKS:
+ * - Self Encrypting Drives(SED)
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/ioctl.h>
+#include <uapi/linux/sed-opal.h>
+#include <linux/sed-opal.h>
+#include <linux/arch_vars.h>
+#include "plpks.h"
+
+/*
+ * variable structure that contains all SED data
+ */
+struct plpks_sed_object_data {
+ u_char version;
+ u_char pad1[7];
+ u_long authority;
+ u_long range;
+ u_int key_len;
+ u_char key[32];
+};
+
+/*
+ * ext_type values
+ * 00 no extension exists
+ * 01-1F common
+ * 20-3F AIX
+ * 40-5F Linux
+ * 60-7F IBMi
+ */
+
+/*
+ * This extension is optional for version 1 sed_object_data
+ */
+struct sed_object_extension {
+ u8 ext_type;
+ u8 rsvd[3];
+ u8 ext_data[64];
+};
+
+#define PKS_SED_OBJECT_DATA_V1 1
+#define PKS_SED_MANGLED_LABEL "/default/pri"
+#define PLPKS_SED_COMPONENT "sed-opal"
+#define PLPKS_SED_POLICY WORLDREADABLE
+#define PLPKS_SED_OS_COMMON 4
+
+#ifndef CONFIG_BLK_SED_OPAL
+#define OPAL_AUTH_KEY ""
+#endif
+
+/*
+ * Read the variable data from PKS given the label
+ */
+int arch_read_variable(enum arch_variable_type type, char *varname,
+ void *varbuf, u_int *varlen)
+{
+ struct plpks_var var;
+ struct plpks_sed_object_data *data;
+ u_int offset = 0;
+ char *buf = (char *)varbuf;
+ int ret;
+
+ var.name = varname;
+ var.namelen = strlen(varname);
+ var.policy = PLPKS_SED_POLICY;
+ var.os = PLPKS_SED_OS_COMMON;
+ var.data = NULL;
+ var.datalen = 0;
+
+ switch (type) {
+ case ARCH_VAR_OPAL_KEY:
+ var.component = PLPKS_SED_COMPONENT;
+ if (strcmp(OPAL_AUTH_KEY, varname) == 0) {
+ var.name = PKS_SED_MANGLED_LABEL;
+ var.namelen = strlen(varname);
+ }
+ offset = offsetof(struct plpks_sed_object_data, key);
+ break;
+ case ARCH_VAR_OTHER:
+ var.component = "";
+ break;
+ }
+
+ ret = plpks_read_os_var(&var);
+ if (ret != 0)
+ return ret;
+
+ if (offset > var.datalen)
+ offset = 0;
+
+ switch (type) {
+ case ARCH_VAR_OPAL_KEY:
+ data = (struct plpks_sed_object_data *)var.data;
+ *varlen = data->key_len;
+ break;
+ case ARCH_VAR_OTHER:
+ *varlen = var.datalen;
+ break;
+ }
+
+ if (var.data) {
+ memcpy(varbuf, var.data + offset, var.datalen - offset);
+ buf[*varlen] = '\0';
+ kfree(var.data);
+ }
+
+ return 0;
+}
+
+/*
+ * Write the variable data to PKS given the label
+ */
+int arch_write_variable(enum arch_variable_type type, char *varname,
+ void *varbuf, u_int varlen)
+{
+ struct plpks_var var;
+ struct plpks_sed_object_data data;
+ struct plpks_var_name vname;
+
+ var.name = varname;
+ var.namelen = strlen(varname);
+ var.policy = PLPKS_SED_POLICY;
+ var.os = PLPKS_SED_OS_COMMON;
+ var.datalen = varlen;
+ var.data = varbuf;
+
+ switch (type) {
+ case ARCH_VAR_OPAL_KEY:
+ var.component = PLPKS_SED_COMPONENT;
+ if (strcmp(OPAL_AUTH_KEY, varname) == 0) {
+ var.name = PKS_SED_MANGLED_LABEL;
+ var.namelen = strlen(varname);
+ }
+ var.datalen = sizeof(struct plpks_sed_object_data);
+ var.data = (u8 *)&data;
+
+ /* initialize SED object */
+ data.version = PKS_SED_OBJECT_DATA_V1;
+ data.authority = 0;
+ data.range = 0;
+ data.key_len = varlen;
+ memcpy(data.key, varbuf, varlen);
+ break;
+ case ARCH_VAR_OTHER:
+ var.component = "";
+ break;
+ }
+
+ /* variable update requires delete first */
+ vname.namelen = var.namelen;
+ vname.name = var.name;
+ (void)plpks_remove_var(PLPKS_SED_COMPONENT, PLPKS_SED_OS_COMMON, vname);
+
+ return plpks_write_var(var);
+}
--
2.27.0
next prev parent reply other threads:[~2022-07-23 11:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-23 11:30 [PATCH v2 0/3] Provide PowerVM LPAR Platform KeyStore driver for Self Encrypting Drives Nayna Jain
2022-07-23 11:30 ` [PATCH v2 1/3] powerpc/pseries: define driver for Platform KeyStore Nayna Jain
2022-07-28 14:14 ` Greg Joyce
2022-09-06 21:00 ` Nathan Chancellor
2022-09-06 23:23 ` Michael Ellerman
2022-09-06 23:32 ` Nathan Chancellor
2022-09-07 8:39 ` Michael Ellerman
2022-07-23 11:30 ` [PATCH v2 2/3] lib: define generic accessor functions for arch specific keystore Nayna Jain
2022-07-23 11:30 ` Nayna Jain [this message]
2022-07-29 13:02 ` [PATCH v2 0/3] Provide PowerVM LPAR Platform KeyStore driver for Self Encrypting Drives Michael Ellerman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220723113048.521744-4-nayna@linux.ibm.com \
--to=nayna@linux.ibm.com \
--cc=bjking1@us.ibmcom \
--cc=erichte@linux.ibm.com \
--cc=gcwilson@linux.ibm.com \
--cc=gjoyce@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=muriloo@linux.ibm.com \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.