+++ /dev/null
-From a4e3cd2c82d58d88a15524a8b3191b2f31038695 Mon Sep 17 00:00:00 2001
-From: Sasha Levin <sashal@kernel.org>
-Date: Fri, 10 Feb 2023 19:03:52 +1100
-Subject: powerpc/pseries: Implement signed update for PLPKS objects
-
-From: Nayna Jain <nayna@linux.ibm.com>
-
-[ Upstream commit 899d9b8fee66da820eadc60b2a70090eb83db761 ]
-
-The Platform Keystore provides a signed update interface which can be used
-to create, replace or append to certain variables in the PKS in a secure
-fashion, with the hypervisor requiring that the update be signed using the
-Platform Key.
-
-Implement an interface to the H_PKS_SIGNED_UPDATE hcall in the plpks
-driver to allow signed updates to PKS objects.
-
-(The plpks driver doesn't need to do any cryptography or otherwise handle
-the actual signed variable contents - that will be handled by userspace
-tooling.)
-
-Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
-[ajd: split patch, add timeout handling and misc cleanups]
-Co-developed-by: Andrew Donnellan <ajd@linux.ibm.com>
-Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
-Signed-off-by: Russell Currey <ruscur@russell.cc>
-Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
-Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-Link: https://lore.kernel.org/r/20230210080401.345462-18-ajd@linux.ibm.com
-Stable-dep-of: 784354349d2c ("powerpc/pseries: make max polling consistent for longer H_CALLs")
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- arch/powerpc/include/asm/hvcall.h | 1 +
- arch/powerpc/platforms/pseries/plpks.c | 74 ++++++++++++++++++++++++--
- arch/powerpc/platforms/pseries/plpks.h | 5 ++
- 3 files changed, 75 insertions(+), 5 deletions(-)
-
-diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
-index 95fd7f9485d55..c099780385dd3 100644
---- a/arch/powerpc/include/asm/hvcall.h
-+++ b/arch/powerpc/include/asm/hvcall.h
-@@ -335,6 +335,7 @@
- #define H_RPT_INVALIDATE 0x448
- #define H_SCM_FLUSH 0x44C
- #define H_GET_ENERGY_SCALE_INFO 0x450
-+#define H_PKS_SIGNED_UPDATE 0x454
- #define H_WATCHDOG 0x45C
- #define MAX_HCALL_OPCODE H_WATCHDOG
-
-diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c
-index 06b52fe12c88b..3efbfd25d35d0 100644
---- a/arch/powerpc/platforms/pseries/plpks.c
-+++ b/arch/powerpc/platforms/pseries/plpks.c
-@@ -74,6 +74,12 @@ static int pseries_status_to_err(int rc)
- err = -ENOENT;
- break;
- case H_BUSY:
-+ case H_LONG_BUSY_ORDER_1_MSEC:
-+ case H_LONG_BUSY_ORDER_10_MSEC:
-+ case H_LONG_BUSY_ORDER_100_MSEC:
-+ case H_LONG_BUSY_ORDER_1_SEC:
-+ case H_LONG_BUSY_ORDER_10_SEC:
-+ case H_LONG_BUSY_ORDER_100_SEC:
- err = -EBUSY;
- break;
- case H_AUTHORITY:
-@@ -174,14 +180,17 @@ static struct label *construct_label(char *component, u8 varos, u8 *name,
- u16 namelen)
- {
- struct label *label;
-- size_t slen;
-+ size_t slen = 0;
-
- if (!name || namelen > PLPKS_MAX_NAME_SIZE)
- return ERR_PTR(-EINVAL);
-
-- slen = strlen(component);
-- if (component && slen > sizeof(label->attr.prefix))
-- return ERR_PTR(-EINVAL);
-+ // Support NULL component for signed updates
-+ if (component) {
-+ slen = strlen(component);
-+ if (slen > sizeof(label->attr.prefix))
-+ return ERR_PTR(-EINVAL);
-+ }
-
- label = kzalloc(sizeof(*label), GFP_KERNEL);
- if (!label)
-@@ -264,6 +273,61 @@ static int plpks_confirm_object_flushed(struct label *label,
- return rc;
- }
-
-+int plpks_signed_update_var(struct plpks_var *var, u64 flags)
-+{
-+ unsigned long retbuf[PLPAR_HCALL9_BUFSIZE] = {0};
-+ int rc;
-+ struct label *label;
-+ struct plpks_auth *auth;
-+ u64 continuetoken = 0;
-+ u64 timeout = 0;
-+
-+ if (!var->data || var->datalen <= 0 || var->namelen > PLPKS_MAX_NAME_SIZE)
-+ return -EINVAL;
-+
-+ if (!(var->policy & PLPKS_SIGNEDUPDATE))
-+ return -EINVAL;
-+
-+ // Signed updates need the component to be NULL.
-+ if (var->component)
-+ return -EINVAL;
-+
-+ auth = construct_auth(PLPKS_OS_OWNER);
-+ if (IS_ERR(auth))
-+ return PTR_ERR(auth);
-+
-+ label = construct_label(var->component, var->os, var->name, var->namelen);
-+ if (IS_ERR(label)) {
-+ rc = PTR_ERR(label);
-+ goto out;
-+ }
-+
-+ do {
-+ rc = plpar_hcall9(H_PKS_SIGNED_UPDATE, retbuf,
-+ virt_to_phys(auth), virt_to_phys(label),
-+ label->size, var->policy, flags,
-+ virt_to_phys(var->data), var->datalen,
-+ continuetoken);
-+
-+ continuetoken = retbuf[0];
-+ if (pseries_status_to_err(rc) == -EBUSY) {
-+ int delay_ms = get_longbusy_msecs(rc);
-+ mdelay(delay_ms);
-+ timeout += delay_ms;
-+ }
-+ rc = pseries_status_to_err(rc);
-+ } while (rc == -EBUSY && timeout < PLPKS_MAX_TIMEOUT);
-+
-+ if (!rc)
-+ rc = plpks_confirm_object_flushed(label, auth);
-+
-+ kfree(label);
-+out:
-+ kfree(auth);
-+
-+ return rc;
-+}
-+
- int plpks_write_var(struct plpks_var var)
- {
- unsigned long retbuf[PLPAR_HCALL_BUFSIZE] = { 0 };
-@@ -314,7 +378,7 @@ int plpks_remove_var(char *component, u8 varos, struct plpks_var_name vname)
- struct label *label;
- int rc;
-
-- if (!component || vname.namelen > PLPKS_MAX_NAME_SIZE)
-+ if (vname.namelen > PLPKS_MAX_NAME_SIZE)
- return -EINVAL;
-
- auth = construct_auth(PLPKS_OS_OWNER);
-diff --git a/arch/powerpc/platforms/pseries/plpks.h b/arch/powerpc/platforms/pseries/plpks.h
-index 6afb44ee74a16..ccbec26fcbd8b 100644
---- a/arch/powerpc/platforms/pseries/plpks.h
-+++ b/arch/powerpc/platforms/pseries/plpks.h
-@@ -66,6 +66,11 @@ struct plpks_var_name_list {
- struct plpks_var_name varlist[];
- };
-
-+/**
-+ * Updates the authenticated variable. It expects NULL as the component.
-+ */
-+int plpks_signed_update_var(struct plpks_var *var, u64 flags);
-+
- /**
- * Writes the specified var and its data to PKS.
- * Any caller of PKS driver should present a valid component type for
---
-2.43.0
-
Link: https://msgid.link/20240418031230.170954-1-nayna@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
- arch/powerpc/platforms/pseries/plpks.c | 10 +++++-----
- arch/powerpc/platforms/pseries/plpks.h | 5 ++---
- 2 files changed, 7 insertions(+), 8 deletions(-)
+ arch/powerpc/platforms/pseries/plpks.c | 3 +--
+ arch/powerpc/platforms/pseries/plpks.h | 5 ++---
+ 2 files changed, 3 insertions(+), 5 deletions(-)
-diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c
-index 3efbfd25d35d0..453c3cdd81fb8 100644
--- a/arch/powerpc/platforms/pseries/plpks.c
+++ b/arch/powerpc/platforms/pseries/plpks.c
-@@ -263,8 +263,7 @@ static int plpks_confirm_object_flushed(struct label *label,
+@@ -254,8 +254,7 @@ static int plpks_confirm_object_flushed(
if (!rc && status == 1)
break;
timeout = timeout + PLPKS_FLUSH_SLEEP;
} while (timeout < PLPKS_MAX_TIMEOUT);
-@@ -311,9 +310,10 @@ int plpks_signed_update_var(struct plpks_var *var, u64 flags)
-
- continuetoken = retbuf[0];
- if (pseries_status_to_err(rc) == -EBUSY) {
-- int delay_ms = get_longbusy_msecs(rc);
-- mdelay(delay_ms);
-- timeout += delay_ms;
-+ int delay_us = get_longbusy_msecs(rc) * 1000;
-+
-+ fsleep(delay_us);
-+ timeout += delay_us;
- }
- rc = pseries_status_to_err(rc);
- } while (rc == -EBUSY && timeout < PLPKS_MAX_TIMEOUT);
-diff --git a/arch/powerpc/platforms/pseries/plpks.h b/arch/powerpc/platforms/pseries/plpks.h
-index ccbec26fcbd8b..b3c3538b229c6 100644
--- a/arch/powerpc/platforms/pseries/plpks.h
+++ b/arch/powerpc/platforms/pseries/plpks.h
@@ -42,9 +42,8 @@
struct plpks_var {
char *component;
---
-2.43.0
-