]> Git Repo - J-linux.git/commitdiff
s390/crypto: Display Query and Query Authentication Information in sysfs
authorFinn Callies <[email protected]>
Wed, 11 Sep 2024 07:21:09 +0000 (09:21 +0200)
committerVasily Gorbik <[email protected]>
Thu, 12 Sep 2024 12:13:27 +0000 (14:13 +0200)
Displays the query (fc=0) and query authentication information (fc=127)
as binary in sysfs per CPACF instruction. Files are located in
/sys/devices/system/cpu/cpacf/. These information can be fetched via
asm already except for PCKMO because this instruction is privileged. To
offer a unified interface all CPACF instructions will have this
information displayed in sysfs in files <instruction>_query_raw and
<instruction>_query_auth_info_raw.

A new tool introduced into s390-tools called cpacfinfo will use this
information to convert and display in human readable form.

Suggested-by: Harald Freudenberger <[email protected]>
Reviewed-by: Harald Freudenberger <[email protected]>
Acked-by: Heiko Carstens <[email protected]>
Signed-off-by: Finn Callies <[email protected]>
Signed-off-by: Vasily Gorbik <[email protected]>
arch/s390/kernel/Makefile
arch/s390/kernel/cpacf.c [new file with mode: 0644]

index 5ceb08b338d32d8d533a2dd625bc4fb5aa2dafb1..48caae8c7e104b25331d4476bc5a843b346aa5a6 100644 (file)
@@ -50,6 +50,7 @@ extra-y                               += vmlinux.lds
 obj-$(CONFIG_SYSFS)            += nospec-sysfs.o
 CFLAGS_REMOVE_nospec-branch.o  += $(CC_FLAGS_EXPOLINE)
 
+obj-$(CONFIG_SYSFS)            += cpacf.o
 obj-$(CONFIG_MODULES)          += module.o
 obj-$(CONFIG_SCHED_TOPOLOGY)   += topology.o hiperdispatch.o
 obj-$(CONFIG_NUMA)             += numa.o
diff --git a/arch/s390/kernel/cpacf.c b/arch/s390/kernel/cpacf.c
new file mode 100644 (file)
index 0000000..c8575db
--- /dev/null
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright IBM Corp. 2024
+ */
+
+#define KMSG_COMPONENT "cpacf"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
+#include <linux/cpu.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <asm/cpacf.h>
+
+#define CPACF_QUERY(name, instruction)                                         \
+static ssize_t name##_query_raw_read(struct file *fp,                          \
+                                    struct kobject *kobj,                      \
+                                    struct bin_attribute *attr,                \
+                                    char *buf, loff_t offs,                    \
+                                    size_t count)                              \
+{                                                                              \
+       cpacf_mask_t mask;                                                      \
+                                                                               \
+       if (!cpacf_query(CPACF_##instruction, &mask))                           \
+               return -EOPNOTSUPP;                                             \
+       return memory_read_from_buffer(buf, count, &offs, &mask, sizeof(mask)); \
+}                                                                              \
+static BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t))
+
+CPACF_QUERY(km, KM);
+CPACF_QUERY(kmc, KMC);
+CPACF_QUERY(kimd, KIMD);
+CPACF_QUERY(klmd, KLMD);
+CPACF_QUERY(kmac, KMAC);
+CPACF_QUERY(pckmo, PCKMO);
+CPACF_QUERY(kmf, KMF);
+CPACF_QUERY(kmctr, KMCTR);
+CPACF_QUERY(kmo, KMO);
+CPACF_QUERY(pcc, PCC);
+CPACF_QUERY(prno, PRNO);
+CPACF_QUERY(kma, KMA);
+CPACF_QUERY(kdsa, KDSA);
+
+#define CPACF_QAI(name, instruction)                           \
+static ssize_t name##_query_auth_info_raw_read(                        \
+       struct file *fp, struct kobject *kobj,                  \
+       struct bin_attribute *attr, char *buf, loff_t offs,     \
+       size_t count)                                           \
+{                                                              \
+       cpacf_qai_t qai;                                        \
+                                                               \
+       if (!cpacf_qai(CPACF_##instruction, &qai))              \
+               return -EOPNOTSUPP;                             \
+       return memory_read_from_buffer(buf, count, &offs, &qai, \
+                                       sizeof(qai));           \
+}                                                              \
+static BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t))
+
+CPACF_QAI(km, KM);
+CPACF_QAI(kmc, KMC);
+CPACF_QAI(kimd, KIMD);
+CPACF_QAI(klmd, KLMD);
+CPACF_QAI(kmac, KMAC);
+CPACF_QAI(pckmo, PCKMO);
+CPACF_QAI(kmf, KMF);
+CPACF_QAI(kmctr, KMCTR);
+CPACF_QAI(kmo, KMO);
+CPACF_QAI(pcc, PCC);
+CPACF_QAI(prno, PRNO);
+CPACF_QAI(kma, KMA);
+CPACF_QAI(kdsa, KDSA);
+
+static struct bin_attribute *cpacf_attrs[] = {
+       &bin_attr_km_query_raw,
+       &bin_attr_kmc_query_raw,
+       &bin_attr_kimd_query_raw,
+       &bin_attr_klmd_query_raw,
+       &bin_attr_kmac_query_raw,
+       &bin_attr_pckmo_query_raw,
+       &bin_attr_kmf_query_raw,
+       &bin_attr_kmctr_query_raw,
+       &bin_attr_kmo_query_raw,
+       &bin_attr_pcc_query_raw,
+       &bin_attr_prno_query_raw,
+       &bin_attr_kma_query_raw,
+       &bin_attr_kdsa_query_raw,
+       &bin_attr_km_query_auth_info_raw,
+       &bin_attr_kmc_query_auth_info_raw,
+       &bin_attr_kimd_query_auth_info_raw,
+       &bin_attr_klmd_query_auth_info_raw,
+       &bin_attr_kmac_query_auth_info_raw,
+       &bin_attr_pckmo_query_auth_info_raw,
+       &bin_attr_kmf_query_auth_info_raw,
+       &bin_attr_kmctr_query_auth_info_raw,
+       &bin_attr_kmo_query_auth_info_raw,
+       &bin_attr_pcc_query_auth_info_raw,
+       &bin_attr_prno_query_auth_info_raw,
+       &bin_attr_kma_query_auth_info_raw,
+       &bin_attr_kdsa_query_auth_info_raw,
+       NULL,
+};
+
+static const struct attribute_group cpacf_attr_grp = {
+       .name = "cpacf",
+       .bin_attrs = cpacf_attrs,
+};
+
+static int __init cpacf_init(void)
+{
+       struct device *cpu_root;
+       int rc = 0;
+
+       cpu_root = bus_get_dev_root(&cpu_subsys);
+       if (cpu_root) {
+               rc = sysfs_create_group(&cpu_root->kobj, &cpacf_attr_grp);
+               put_device(cpu_root);
+       }
+       return rc;
+}
+device_initcall(cpacf_init);
This page took 0.060111 seconds and 4 git commands to generate.