Skip to contentSkip to conversation

powerpc/pseries: new character devices for system parameters and VPD

PATCH Superseded Nathan Lynch 1 participant 9 messages Oct 13, 2023 – Oct 16, 2023

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover powerpc/pseries: new character devices for system parameters and VPD

Add character devices that expose PAPR-specific system parameters and VPD to user space.

The problem: important platform features are enabled on Linux VMs through the powerpc-specific rtas() syscall in combination with writeable mappings of /dev/mem. In typical usage, this is encapsulated behind APIs provided by the librtas library. This paradigm is incompatible with lockdown, which prohibits /dev/mem access. It also is too low-level in many cases: a single logical operation may require multiple sys_rtas() calls in succession to complete. This carries the risk that a process may exit while leaving an operation unfinished. It also means that callers must coordinate their use of the syscall for functions that cannot tolerate multiple concurrent clients, such as ibm,get-vpd.

The solution presented here is to add a pair of small pseries-specific "drivers," one for VPD and one for system parameters. The new drivers expose these facilities to user space in ways that are compatible with lockdown and require no coordination between their clients.

Both drivers could potentially support poll() methods to notify clients of changes to parameters or VPD that happen due to partition migration and other events. But that should be safe to leave for later, assuming there's any interest.

I have made changes to librtas to prefer the new interfaces and verified that existing clients work correctly with the new code. A draft PR for that work is here:

https://github.com/ibm-power-utilities/librtas/pull/36

I expect to propose at least one more small driver in this style for platform dump retrieval in a separate submission in the future.

---
Changes in v2:
- Fix unused-but-set variable warning in papr-sysparm code.
- Rebase on powerpc/next branch.
- Link to v1: https://lore.kernel.org/r/20231006-papr-sys_rtas-vs-lockdown-v1-0-3a36bfb66e2e@linux.ibm.com

Changes in v1 vs initial RFC:
- Add papr-sysparm driver and tests.
- Add a papr-miscdev.h uapi header.
- Prevent sys_rtas() from interfering with papr-vpd call sequences.
- Handle -4 ("VPD changed") status in papr-vpd.
- Include string_helpers.h in papr-vpd.c, per Michal Suchánek
- Link to RFC: https://lore.kernel.org/r/20230822-papr-sys_rtas-vs-lockdown-v1-0-932623cf3c7b@linux.ibm.com

---
Nathan Lynch (7):
powerpc/uapi: export papr-miscdev.h header powerpc/pseries: papr-vpd char driver for VPD retrieval powerpc/rtas: serialize ibm,get-vpd service with papr-vpd sequences powerpc/pseries/papr-sysparm: validate buffer object lengths powerpc/pseries/papr-sysparm: expose chardev API to user space powerpc/selftests: add test for papr-vpd powerpc/selftests: add test for papr-sysparm

 Documentation/userspace-api/ioctl/ioctl-number.rst |   4 +
 arch/powerpc/include/asm/papr-sysparm.h            |  17 +-
 arch/powerpc/include/asm/papr-vpd.h                |  18 +
 arch/powerpc/include/uapi/asm/papr-miscdev.h       |   9 +
 arch/powerpc/include/uapi/asm/papr-sysparm.h       |  58 +++
 arch/powerpc/include/uapi/asm/papr-vpd.h           |  22 +
 arch/powerpc/kernel/rtas.c                         |  26 +
 arch/powerpc/platforms/pseries/Makefile            |   1 +
 arch/powerpc/platforms/pseries/papr-sysparm.c      | 201 +++++++-
 arch/powerpc/platforms/pseries/papr-vpd.c          | 542 +++++++++++++++++++++
 tools/testing/selftests/powerpc/Makefile           |   2 +
 .../selftests/powerpc/papr_sysparm/.gitignore      |   1 +
 .../selftests/powerpc/papr_sysparm/Makefile        |  12 +
 .../selftests/powerpc/papr_sysparm/papr_sysparm.c  | 164 +++++++
 .../testing/selftests/powerpc/papr_vpd/.gitignore  |   1 +
 tools/testing/selftests/powerpc/papr_vpd/Makefile  |  12 +
 .../testing/selftests/powerpc/papr_vpd/papr_vpd.c  | 352 +++++++++++++
 17 files changed, 1434 insertions(+), 8 deletions(-)

---
base-commit: 0ebc7feae79ac07772a20382eebd8c3503313714
change-id: 20230817-papr-sys_rtas-vs-lockdown-5c54505db792

Best regards,

Signature · 1 line
Nathan Lynch <[email protected]>
#1 lore raw

PATCH v2 1/7 powerpc/uapi: export papr-miscdev.h header

Allocate one identifying code (the first column of the ioctl-number table) for the collection of PAPR miscdev drivers to share.

---
 arch/powerpc/include/uapi/asm/papr-miscdev.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/powerpc/include/uapi/asm/papr-miscdev.h new file +9 -0
new file mode 100644
index 000000000000..49a2a270b7f3
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_PAPR_MISCDEV_H_
+#define _UAPI_PAPR_MISCDEV_H_
+
+enum {
+	PAPR_MISCDEV_IOC_ID = 0xb2,
+};
+
+#endif /* _UAPI_PAPR_MISCDEV_H_ */
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/7 powerpc/pseries: papr-vpd char driver for VPD retrieval

In reply to Nathan Lynch

PowerVM LPARs may retrieve Vital Product Data (VPD) for system components using the ibm,get-vpd RTAS function.

We can expose this to user space with a /dev/papr-vpd character device, where the programming model is:

  struct papr_location_code plc = { .str = "", }; /* obtain all VPD */
  int devfd = open("/dev/papr-vpd", O_RDONLY);
  int vpdfd = ioctl(devfd, PAPR_VPD_CREATE_HANDLE, &plc);
  size_t size = lseek(vpdfd, 0, SEEK_END);
  char *buf = malloc(size);
  pread(devfd, buf, size, 0);

When a file descriptor is obtained from ioctl(PAPR_VPD_CREATE_HANDLE), the file contains the result of a complete ibm,get-vpd sequence. The file contents are immutable from the POV of user space. To get a new view of the VPD, the client must create a new handle.

This design choice insulates user space from most of the complexities that ibm,get-vpd brings:

* ibm,get-vpd must be called more than once to obtain complete results.

* Only one ibm,get-vpd call sequence should be in progress at a time; interleaved sequences will disrupt each other. Callers must have a protocol for serializing their use of the function.

* A call sequence in progress may receive a "VPD changed, try again" status, requiring the client to abandon the sequence and start over.

The memory required for the VPD buffers seems acceptable, around 20KB for all VPD on one of my systems. And the value of the /rtas/ibm,vpd-size DT property (the estimated maximum size of VPD) is consistently 300KB across various systems I've checked.

I've implemented support for this new ABI in the rtas_get_vpd() function in librtas, which the vpdupdate command currently uses to populate its VPD database. I've verified that an unmodified vpdupdate binary generates an identical database when using a librtas.so that prefers the new ABI.

Note that the driver needs to serialize its call sequences with legacy sys_rtas(ibm,get-vpd) callers, so it exposes its internal lock for sys_rtas.

---
 Documentation/userspace-api/ioctl/ioctl-number.rst |   2 +
 arch/powerpc/include/asm/papr-vpd.h                |  18 +
 arch/powerpc/include/uapi/asm/papr-vpd.h           |  22 +
 arch/powerpc/platforms/pseries/Makefile            |   1 +
 arch/powerpc/platforms/pseries/papr-vpd.c          | 542 +++++++++++++++++++++
 5 files changed, 585 insertions(+)
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
index 4ea5b837399a..a950545bf7cd 100644
@@ -349,6 +349,8 @@ Code  Seq#    Include File                                           Comments
                                                                      <mailto:[email protected]>
 0xB1  00-1F                                                          PPPoX
                                                                      <mailto:[email protected]>
+0xB2  00     arch/powerpc/include/uapi/asm/papr-vpd.h                powerpc/pseries VPD API
+                                                                     <mailto:linuxppc-dev>
 0xB3  00     linux/mmc/ioctl.h
 0xB4  00-0F  linux/gpio.h                                            <mailto:[email protected]>
 0xB5  00-0F  uapi/linux/rpmsg.h                                      <mailto:[email protected]>
arch/powerpc/include/asm/papr-vpd.h new file +18 -0
new file mode 100644
index 000000000000..bce13e63ae6b
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _ASM_POWERPC_PAPR_VPD_H
+#define _ASM_POWERPC_PAPR_VPD_H
+
+/*
+ * This is here only so sys_rtas() can avoid disrupting VPD sequences
+ * in progress in the papr-vpd driver. There's no other reason that
+ * the rest of the kernel should call into papr-vpd.
+ */
+#ifdef CONFIG_PPC_PSERIES
+void papr_vpd_mutex_lock(void);
+void papr_vpd_mutex_unlock(void);
+#else  /* CONFIG_PPC_PSERIES */
+static inline void papr_vpd_mutex_lock(void) {}
+static inline void papr_vpd_mutex_unlock(void) {}
+#endif /* CONFIG_PPC_PSERIES */
+
+#endif /* _ASM_POWERPC_PAPR_VPD_H */
arch/powerpc/include/uapi/asm/papr-vpd.h new file +22 -0
new file mode 100644
index 000000000000..b62e4f897a70
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_PAPR_VPD_H_
+#define _UAPI_PAPR_VPD_H_
+
+#include <asm/ioctl.h>
+#include <asm/papr-miscdev.h>
+
+struct papr_location_code {
+	/*
+	 * PAPR+ 12.3.2.4 Converged Location Code Rules - Length
+	 * Restrictions. 79 characters plus nul.
+	 */
+	char str[80];
+};
+
+/*
+ * ioctl for /dev/papr-vpd. Returns a VPD handle fd corresponding to
+ * the location code.
+ */
+#define PAPR_VPD_IOC_CREATE_HANDLE _IOW(PAPR_MISCDEV_IOC_ID, 0, struct papr_location_code)
+
+#endif /* _UAPI_PAPR_VPD_H_ */
arch/powerpc/platforms/pseries/Makefile +1 -0
index 53c3b91af2f7..cbcaa102e2b4 100644
@@ -4,6 +4,7 @@ ccflags-$(CONFIG_PPC_PSERIES_DEBUG)	+= -DDEBUG
 
 obj-y			:= lpar.o hvCall.o nvram.o reconfig.o \
 			   of_helpers.o rtas-work-area.o papr-sysparm.o \
+			   papr-vpd.o \
 			   setup.o iommu.o event_sources.o ras.o \
 			   firmware.o power.o dlpar.o mobility.o rng.o \
 			   pci.o pci_dlpar.o eeh_pseries.o msi.o \
arch/powerpc/platforms/pseries/papr-vpd.c new file +542 -0

542 lines not on this page · raw message

Signature · 1 line
2.41.0
#3 lore raw

PATCH v2 3/7 powerpc/rtas: serialize ibm,get-vpd service with papr-vpd sequences

In reply to Nathan Lynch

Take the papr-vpd driver's internal mutex when sys_rtas performs ibm,get-vpd calls. This prevents sys_rtas(ibm,get-vpd) calls from interleaving with sequences performed by the driver, ensuring that such sequences are not disrupted.

However, it cannot prevent the driver from interleaving with sequences that are initiated via sys_rtas, since control returns to user space with each sys_rtas(ibm,get-vpd) call.

Emit a notice on first use of sys_rtas(ibm,get-vpd) encouraging users to migrate to /dev/papr-vpd.

---
 arch/powerpc/kernel/rtas.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
arch/powerpc/kernel/rtas.c +26 -0
index eddc031c4b95..70ae118d2a13 100644
@@ -37,6 +37,7 @@
 #include <asm/machdep.h>
 #include <asm/mmu.h>
 #include <asm/page.h>
+#include <asm/papr-vpd.h>
 #include <asm/rtas-work-area.h>
 #include <asm/rtas.h>
 #include <asm/time.h>
@@ -1861,6 +1862,28 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
 		goto copy_return;
 	}
 
+	if (token == rtas_function_token(RTAS_FN_IBM_GET_VPD)) {
+		/*
+		 * ibm,get-vpd potentially needs to be invoked
+		 * multiple times to obtain complete results.
+		 * Interleaved ibm,get-vpd sequences disrupt each
+		 * other.
+		 *
+		 * /dev/papr-vpd doesn't have this problem and users
+		 * do not need to be aware of each other to use it
+		 * safely.
+		 *
+		 * We can prevent this call from disrupting a
+		 * /dev/papr-vpd-initiated sequence in progress by
+		 * reaching into the driver to take its internal
+		 * lock. Unfortunately there is no way to prevent
+		 * interference in the other direction without
+		 * resorting to even worse hacks.
+		 */
+		pr_notice_once("Calling ibm,get-vpd via sys_rtas is allowed but deprecated. Use /dev/papr-vpd instead.\n");
+		papr_vpd_mutex_lock();
+	}
+
 	buff_copy = get_errorlog_buffer();
 
 	raw_spin_lock_irqsave(&rtas_lock, flags);
@@ -1870,6 +1893,9 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
 	do_enter_rtas(&rtas_args);
 	args = rtas_args;
 
+	if (token == rtas_function_token(RTAS_FN_IBM_GET_VPD))
+		papr_vpd_mutex_unlock();
+
 	/* A -1 return code indicates that the last command couldn't
 	   be completed due to a hardware error. */
 	if (be32_to_cpu(args.rets[0]) == -1)
Signature · 1 line
2.41.0
#4 lore raw

Re: [PATCH v2 3/7] powerpc/rtas: serialize ibm,get-vpd service with papr-vpd sequences

Quoted 5 lines

Take the papr-vpd driver's internal mutex when sys_rtas performs ibm,get-vpd calls. This prevents sys_rtas(ibm,get-vpd) calls from interleaving with sequences performed by the driver, ensuring that such sequences are not disrupted.

....

Quoted 30 lines
arch/powerpc/kernel/rtas.c +22 -0
@@ -1861,6 +1862,28 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
 		goto copy_return;
 	}
 
+	if (token == rtas_function_token(RTAS_FN_IBM_GET_VPD)) {
+		/*
+		 * ibm,get-vpd potentially needs to be invoked
+		 * multiple times to obtain complete results.
+		 * Interleaved ibm,get-vpd sequences disrupt each
+		 * other.
+		 *
+		 * /dev/papr-vpd doesn't have this problem and users
+		 * do not need to be aware of each other to use it
+		 * safely.
+		 *
+		 * We can prevent this call from disrupting a
+		 * /dev/papr-vpd-initiated sequence in progress by
+		 * reaching into the driver to take its internal
+		 * lock. Unfortunately there is no way to prevent
+		 * interference in the other direction without
+		 * resorting to even worse hacks.
+		 */
+		pr_notice_once("Calling ibm,get-vpd via sys_rtas is allowed but deprecated. Use /dev/papr-vpd instead.\n");
+		papr_vpd_mutex_lock();
+	}
+
 	buff_copy = get_errorlog_buffer();
 
 	raw_spin_lock_irqsave(&rtas_lock, flags);

arch/powerpc/kernel/rtas.c SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) · line 1898

Quoted 6 lines
arch/powerpc/kernel/rtas.c +3 -0
@@ -1870,6 +1893,9 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
 	do_enter_rtas(&rtas_args);
 	args = rtas_args;
 
+	if (token == rtas_function_token(RTAS_FN_IBM_GET_VPD))
+		papr_vpd_mutex_unlock();
+

The mutex ought to nest entirely outside rtas_lock, this releases it too early.

Anyway, I'm considering a different way to get the synchronization right between drivers like papr-vpd and sys_rtas. Instead of having sys_rtas acquire the driver's internal lock, rtas.c should provide a way for code like papr-vpd to temporarily lock the syscall path.

Something like this:

// rtas.c

+ static DEFINE_MUTEX(rtas_syscall_lock);
+ void rtas_syscall_lock(void) { mutex_lock(&rtas_syscall_lock); }
+ void rtas_syscall_unlock(void) { mutex_unlock(&rtas_syscall_lock); }

SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) {
+ rtas_syscall_lock();

         ...

         do_enter_rtas(&rtas_args);

         ...

+ rtas_syscall_unlock();

         return 0;

}

// papr-vpd.c

static void vpd_sequence_begin(struct vpd_sequence *seq,
const struct papr_location_code *loc_code)

  {
          static struct papr_location_code static_loc_code;
          papr_vpd_mutex_lock();
+         rtas_syscall_lock();
          static_loc_code = *loc_code;
          *seq = (struct vpd_sequence) {
                  .params = {
                          .work_area = rtas_work_area_alloc(SZ_4K),
                          .loc_code = &static_loc_code,
                          .sequence = 1,
                  },
          };

}

/**
* vpd_sequence_end() - Finalize a VPD retrieval sequence.
* @seq: Sequence state.
*
* Releases resources obtained by vpd_sequence_begin(). */
static void vpd_sequence_end(struct vpd_sequence *seq)

  {
          rtas_work_area_free(seq->params.work_area);
+         rtas_syscall_unlock();
          papr_vpd_mutex_unlock();

}

This is a sketch to communicate the idea. The locking in the real code could be finer, perhaps a mutex per RTAS function.

#5 lore raw

PATCH v2 4/7 powerpc/pseries/papr-sysparm: validate buffer object lengths

In reply to Nathan Lynch

The ability to get and set system parameters will be exposed to user space, so let's get a little more strict about malformed papr_sysparm_buf objects.

* Create accessors for the length field of struct papr_sysparm_buf. The length is always stored in MSB order and this is better than spreading the necessary conversions all over.

* Reject attempts to submit invalid buffers to RTAS.

* Warn if RTAS returns a buffer with an invalid length, clamping the returned length to a safe value that won't overrun the buffer.

These are meant as precautionary measures to mitigate both firmware and kernel bugs in this area, should they arise, but I am not aware of any.

---
 arch/powerpc/platforms/pseries/papr-sysparm.c | 47 +++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
arch/powerpc/platforms/pseries/papr-sysparm.c +47 -0
index fedc61599e6c..a1e7aeac7416 100644
@@ -23,6 +23,46 @@ void papr_sysparm_buf_free(struct papr_sysparm_buf *buf)
 	kfree(buf);
 }
 
+static size_t papr_sysparm_buf_get_length(const struct papr_sysparm_buf *buf)
+{
+	return be16_to_cpu(buf->len);
+}
+
+static void papr_sysparm_buf_set_length(struct papr_sysparm_buf *buf, size_t length)
+{
+	WARN_ONCE(length > sizeof(buf->val),
+		  "bogus length %zu, clamping to safe value", length);
+	length = min(sizeof(buf->val), length);
+	buf->len = cpu_to_be16(length);
+}
+
+/*
+ * For use on buffers returned from ibm,get-system-parameter before
+ * returning them to callers. Ensures the encoded length of valid data
+ * cannot overrun buf->val[].
+ */
+static void papr_sysparm_buf_clamp_length(struct papr_sysparm_buf *buf)
+{
+	papr_sysparm_buf_set_length(buf, papr_sysparm_buf_get_length(buf));
+}
+
+/*
+ * Perform some basic diligence on the system parameter buffer before
+ * submitting it to RTAS.
+ */
+static bool papr_sysparm_buf_can_submit(const struct papr_sysparm_buf *buf)
+{
+	/*
+	 * Firmware ought to reject buffer lengths that exceed the
+	 * maximum specified in PAPR, but there's no reason for the
+	 * kernel to allow them either.
+	 */
+	if (papr_sysparm_buf_get_length(buf) > sizeof(buf->val))
+		return false;
+
+	return true;
+}
+
 /**
  * papr_sysparm_get() - Retrieve the value of a PAPR system parameter.
  * @param: PAPR system parameter token as described in
@@ -63,6 +103,9 @@ int papr_sysparm_get(papr_sysparm_t param, struct papr_sysparm_buf *buf)
 	if (token == RTAS_UNKNOWN_SERVICE)
 		return -ENOENT;
 
+	if (!papr_sysparm_buf_can_submit(buf))
+		return -EINVAL;
+
 	work_area = rtas_work_area_alloc(sizeof(*buf));
 
 	memcpy(rtas_work_area_raw_buf(work_area), buf, sizeof(*buf));
@@ -77,6 +120,7 @@ int papr_sysparm_get(papr_sysparm_t param, struct papr_sysparm_buf *buf)
 	case 0:
 		ret = 0;
 		memcpy(buf, rtas_work_area_raw_buf(work_area), sizeof(*buf));
+		papr_sysparm_buf_clamp_length(buf);
 		break;
 	case -3: /* parameter not implemented */
 		ret = -EOPNOTSUPP;
@@ -115,6 +159,9 @@ int papr_sysparm_set(papr_sysparm_t param, const struct papr_sysparm_buf *buf)
 	if (token == RTAS_UNKNOWN_SERVICE)
 		return -ENOENT;
 
+	if (!papr_sysparm_buf_can_submit(buf))
+		return -EINVAL;
+
 	work_area = rtas_work_area_alloc(sizeof(*buf));
 
 	memcpy(rtas_work_area_raw_buf(work_area), buf, sizeof(*buf));
Signature · 1 line
2.41.0
#6 lore raw

PATCH v2 5/7 powerpc/pseries/papr-sysparm: expose chardev API to user space

In reply to Nathan Lynch

Until now the papr_sysparm APIs have been kernel-internal. But user space needs access to PAPR system parameters too. The only method available to user space today to get or set system parameters is using sys_rtas() and /dev/mem to pass RTAS-addressable buffers between user space and firmware. This is incompatible with lockdown and should be deprecated.

So provide an alternative ABI to user space in the form of a /dev/papr-sysparm character device with just two ioctl commands (get and set). The data payloads involved are small enough to fit in the ioctl argument buffer, making the code relatively simple.

Exposing the system parameters through sysfs has been considered but it would be too awkward:

* The kernel currently does not have to contain an exhaustive list of defined system parameters. This is a convenient property to maintain because we don't have to update the kernel whenever a new parameter is added to PAPR. Exporting a named attribute in sysfs for each parameter would negate this.

* Some system parameters are text-based and some are not.

* Retrieval of at least one system parameter requires input data, which a simple read-oriented interface can't support.

---
 Documentation/userspace-api/ioctl/ioctl-number.rst |   2 +
 arch/powerpc/include/asm/papr-sysparm.h            |  17 ++-
 arch/powerpc/include/uapi/asm/papr-sysparm.h       |  58 ++++++++
 arch/powerpc/platforms/pseries/papr-sysparm.c      | 154 ++++++++++++++++++++-
 4 files changed, 223 insertions(+), 8 deletions(-)
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
index a950545bf7cd..d8b6cb1a3636 100644
@@ -351,6 +351,8 @@ Code  Seq#    Include File                                           Comments
                                                                      <mailto:[email protected]>
 0xB2  00     arch/powerpc/include/uapi/asm/papr-vpd.h                powerpc/pseries VPD API
                                                                      <mailto:linuxppc-dev>
+0xB2  01-02  arch/powerpc/include/uapi/asm/papr-sysparm.h            powerpc/pseries system parameter API
+                                                                     <mailto:linuxppc-dev>
 0xB3  00     linux/mmc/ioctl.h
 0xB4  00-0F  linux/gpio.h                                            <mailto:[email protected]>
 0xB5  00-0F  uapi/linux/rpmsg.h                                      <mailto:[email protected]>
arch/powerpc/include/asm/papr-sysparm.h +11 -6
index f5fdbd8ae9db..0dbbff59101d 100644
@@ -2,8 +2,10 @@
 #ifndef _ASM_POWERPC_PAPR_SYSPARM_H
 #define _ASM_POWERPC_PAPR_SYSPARM_H
 
+#include <uapi/asm/papr-sysparm.h>
+
 typedef struct {
-	const u32 token;
+	u32 token;
 } papr_sysparm_t;
 
 #define mk_papr_sysparm(x_) ((papr_sysparm_t){ .token = x_, })
@@ -20,11 +22,14 @@ typedef struct {
 #define PAPR_SYSPARM_TLB_BLOCK_INVALIDATE_ATTRS    mk_papr_sysparm(50)
 #define PAPR_SYSPARM_LPAR_NAME                     mk_papr_sysparm(55)
 
-enum {
-	PAPR_SYSPARM_MAX_INPUT  = 1024,
-	PAPR_SYSPARM_MAX_OUTPUT = 4000,
-};
-
+/**
+ * struct papr_sysparm_buf - RTAS work area layout for system parameter functions.
+ *
+ * This is the memory layout of the buffers passed to/from
+ * ibm,get-system-parameter and ibm,set-system-parameter. It is
+ * distinct from the papr_sysparm_io_block structure that is passed
+ * between user space and the kernel.
+ */
 struct papr_sysparm_buf {
 	__be16 len;
 	char val[PAPR_SYSPARM_MAX_OUTPUT];
arch/powerpc/include/uapi/asm/papr-sysparm.h new file +58 -0

58 lines not on this page · raw message

arch/powerpc/platforms/pseries/papr-sysparm.c +152 -2

176 lines not on this page · raw message

Signature · 1 line
2.41.0
#7 lore raw

PATCH v2 6/7 powerpc/selftests: add test for papr-vpd

In reply to Nathan Lynch

Add selftests for /dev/papr-vpd, exercising the common expected use cases:

* Retrieve all VPD by passing an empty location code.
* Retrieve the "system VPD" by passing a location code derived from DT root node properties, as done by the vpdupdate command.

The tests also verify that certain intended properties of the driver hold:

* Passing an unterminated location code to PAPR_VPD_CREATE_HANDLE gets EINVAL.
* Passing a NULL location code pointer to PAPR_VPD_CREATE_HANDLE gets EFAULT.
* Closing the device node without first issuing a PAPR_VPD_CREATE_HANDLE command to it succeeds.
* Releasing a handle without first consuming any data from it succeeds.
* Re-reading the contents of a handle returns the same data as the first time.

Some minimal validation of the returned data is performed.

The tests are skipped on systems where the papr-vpd driver does not initialize, making this useful only on PowerVM LPARs at this point.

---
 tools/testing/selftests/powerpc/Makefile           |   1 +
 .../testing/selftests/powerpc/papr_vpd/.gitignore  |   1 +
 tools/testing/selftests/powerpc/papr_vpd/Makefile  |  12 +
 .../testing/selftests/powerpc/papr_vpd/papr_vpd.c  | 352 +++++++++++++++++++++
 4 files changed, 366 insertions(+)
tools/testing/selftests/powerpc/Makefile +1 -0
index 49f2ad1793fd..7de972612786 100644
@@ -32,6 +32,7 @@ SUB_DIRS = alignment		\
 	   vphn         \
 	   math		\
 	   papr_attributes	\
+	   papr_vpd		\
 	   ptrace	\
 	   security	\
 	   mce
tools/testing/selftests/powerpc/papr_vpd/.gitignore new file +1 -0
new file mode 100644
index 000000000000..49285031a656
@@ -0,0 +1 @@
+/papr_vpd
tools/testing/selftests/powerpc/papr_vpd/Makefile new file +12 -0
new file mode 100644
index 000000000000..06b719703bfd
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+noarg:
+	$(MAKE) -C ../
+
+TEST_GEN_PROGS := papr_vpd
+
+top_srcdir = ../../../../..
+include ../../lib.mk
+
+$(TEST_GEN_PROGS): ../harness.c ../utils.c
+
+$(OUTPUT)/papr_vpd: CFLAGS += $(KHDR_INCLUDES)
tools/testing/selftests/powerpc/papr_vpd/papr_vpd.c new file +352 -0

352 lines not on this page · raw message

Signature · 1 line
2.41.0
#8 lore raw

PATCH v2 7/7 powerpc/selftests: add test for papr-sysparm

In reply to Nathan Lynch

Consistently testing system parameter access is a bit difficult by nature -- the set of parameters available depends on the model and system configuration, and updating a parameter should be considered a destructive operation reserved for the admin.

So we validate some of the error paths and retrieve the SPLPAR characteristics string, but not much else.

---
 tools/testing/selftests/powerpc/Makefile           |   1 +
 .../selftests/powerpc/papr_sysparm/.gitignore      |   1 +
 .../selftests/powerpc/papr_sysparm/Makefile        |  12 ++
 .../selftests/powerpc/papr_sysparm/papr_sysparm.c  | 164 +++++++++++++++++++++
 4 files changed, 178 insertions(+)
tools/testing/selftests/powerpc/Makefile +1 -0
index 7de972612786..2f3fa91a1f52 100644
@@ -33,6 +33,7 @@ SUB_DIRS = alignment		\
 	   math		\
 	   papr_attributes	\
 	   papr_vpd		\
+	   papr_sysparm		\
 	   ptrace	\
 	   security	\
 	   mce
tools/testing/selftests/powerpc/papr_sysparm/.gitignore new file +1 -0
new file mode 100644
index 000000000000..f2a69bf59d40
@@ -0,0 +1 @@
+/papr_sysparm
tools/testing/selftests/powerpc/papr_sysparm/Makefile new file +12 -0
new file mode 100644
index 000000000000..7f79e437634a
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+noarg:
+	$(MAKE) -C ../
+
+TEST_GEN_PROGS := papr_sysparm
+
+top_srcdir = ../../../../..
+include ../../lib.mk
+
+$(TEST_GEN_PROGS): ../harness.c ../utils.c
+
+$(OUTPUT)/papr_sysparm: CFLAGS += $(KHDR_INCLUDES)
tools/testing/selftests/powerpc/papr_sysparm/papr_sysparm.c new file +164 -0

164 lines not on this page · raw message

Signature · 1 line
2.41.0