Skip to contentSkip to conversation

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

PATCH Superseded Nathan Lynch 2 participants 14 messages Oct 26, 2023 – Nov 13, 2023

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 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.

Since the ibm,get-vpd call sequence performed by the papr-vpd driver must be serialized against all other uses of the function, the series begins by adding some new APIs to the core RTAS support code for this purpose.

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

The user-space ABI has not changed since v1 of this series.

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 v3:
- Add new rtas_function_lock()/unlock() APIs and convert existing code
to use them.
- Convert papr-vpd to use rtas_function_lock()/unlock() instead of
having sys_rtas() obtain a driver-private mutex.
- Rebase on current powerpc/next.
- Link to v2: https://lore.kernel.org/r/20231013-papr-sys_rtas-vs-lockdown-v2-0-ead01ce01722@linux.ibm.com

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 (10):
powerpc/rtas: Factor out function descriptor lookup powerpc/rtas: Facilitate high-level call sequences powerpc/rtas: Serialize firmware activation sequences powerpc/rtas: Warn if per-function lock isn't held powerpc/uapi: Export papr-miscdev.h header powerpc/pseries: Add papr-vpd character driver for VPD retrieval powerpc/pseries/papr-sysparm: Validate buffer object lengths powerpc/pseries/papr-sysparm: Expose character device 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/rtas.h                    |   2 +
 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                         | 157 ++++++-
 arch/powerpc/platforms/pseries/Makefile            |   1 +
 arch/powerpc/platforms/pseries/papr-sysparm.c      | 201 +++++++-
 arch/powerpc/platforms/pseries/papr-vpd.c          | 522 +++++++++++++++++++++
 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, 1503 insertions(+), 34 deletions(-)

---
base-commit: 36e826b568e412f61d68fedc02a67b4d8b7583cc
change-id: 20230817-papr-sys_rtas-vs-lockdown-5c54505db792

Best regards,

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

PATCH v3 1/10 powerpc/rtas: Factor out function descriptor lookup

Move the function descriptor table lookup out of rtas_function_token() into a separate routine for use in new code to follow. No functional change.

---
 arch/powerpc/kernel/rtas.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)
arch/powerpc/kernel/rtas.c +19 -12
index eddc031c4b95..e2fac171bf69 100644
@@ -464,29 +464,36 @@ static struct rtas_function rtas_function_table[] __ro_after_init = {
 static DEFINE_RAW_SPINLOCK(rtas_lock);
 static struct rtas_args rtas_args;
 
-/**
- * rtas_function_token() - RTAS function token lookup.
- * @handle: Function handle, e.g. RTAS_FN_EVENT_SCAN.
- *
- * Context: Any context.
- * Return: the token value for the function if implemented by this platform,
- *         otherwise RTAS_UNKNOWN_SERVICE.
- */
-s32 rtas_function_token(const rtas_fn_handle_t handle)
+static struct rtas_function *rtas_function_lookup(const rtas_fn_handle_t handle)
 {
 	const size_t index = handle.index;
 	const bool out_of_bounds = index >= ARRAY_SIZE(rtas_function_table);
 
 	if (WARN_ONCE(out_of_bounds, "invalid function index %zu", index))
-		return RTAS_UNKNOWN_SERVICE;
+		return NULL;
 	/*
 	 * Various drivers attempt token lookups on non-RTAS
 	 * platforms.
 	 */
 	if (!rtas.dev)
-		return RTAS_UNKNOWN_SERVICE;
+		return NULL;
+
+	return &rtas_function_table[index];
+}
+
+/**
+ * rtas_function_token() - RTAS function token lookup.
+ * @handle: Function handle, e.g. RTAS_FN_EVENT_SCAN.
+ *
+ * Context: Any context.
+ * Return: the token value for the function if implemented by this platform,
+ *         otherwise RTAS_UNKNOWN_SERVICE.
+ */
+s32 rtas_function_token(const rtas_fn_handle_t handle)
+{
+	const struct rtas_function *func = rtas_function_lookup(handle);
 
-	return rtas_function_table[index].token;
+	return func ? func->token : RTAS_UNKNOWN_SERVICE;
 }
 EXPORT_SYMBOL_GPL(rtas_function_token);
 
Signature · 1 line
2.41.0
#2 lore raw

PATCH v3 2/10 powerpc/rtas: Facilitate high-level call sequences

In reply to Nathan Lynch

On RTAS platforms there is a general restriction that the OS must not enter RTAS on more than one CPU at a time. This low-level serialization requirement is satisfied by holding a spin lock (rtas_lock) across most RTAS function invocations.

However, some pseries RTAS functions require multiple successive calls to complete a logical operation. Beginning a new call sequence for such a function may disrupt any other sequences of that function already in progress. Safe and reliable use of these functions effectively requires higher-level serialization beyond what is already done at the level of RTAS entry and exit.

Where a sequence-based RTAS function is invoked only through sys_rtas(), with no in-kernel users, there is no issue as far as the kernel is concerned. User space is responsible for appropriately serializing its call sequences. (Whether user space code actually takes measures to prevent sequence interleaving is another matter.) Examples of such functions currently include ibm,platform-dump and ibm,get-vpd.

But where a sequence-based RTAS function has both user space and in-kernel uesrs, there is a hazard. Even if the in-kernel call sites of such a function serialize their sequences correctly, a user of sys_rtas() can invoke the same function at any time, potentially disrupting a sequence in progress.

So in order to prevent disruption of kernel-based RTAS call sequences, they must serialize not only with themselves but also with sys_rtas() users, somehow. Preferably without adding global locks or adding more function-specific hacks to sys_rtas(). This is a prerequisite for adding an in-kernel call sequence of ibm,get-vpd, which is in a change to follow.

Note that it has never been feasible for the kernel to prevent sys_rtas()-based sequences from being disrupted because control returns to user space on every call. sys_rtas()-based users of these functions have always been, and continue to be, responsible for coordinating their call sequences with other users, even those which may invoke the RTAS functions through less direct means than sys_rtas(). This is an unavoidable consequence of exposing sequence-based RTAS functions through sys_rtas().

* Add new rtas_function_lock() and rtas_function_unlock() APIs for use with sequence-based RTAS functions.

* Add an optional per-function mutex to struct rtas_function. When this member is set, kernel-internal callers of the RTAS function are required to guard their call sequences with rtas_function_lock() and rtas_function_unlock(). This requirement will be enforced in a later change, after all affected call sites are updated.

* Populate the lock members of function table entries where serialization of call sequences is known to be necessary, along with justifying commentary.

* In sys_rtas(), acquire the per-function mutex when it is present.

There should be no perceivable change introduced here except that concurrent callers of the same RTAS function via sys_rtas() may block on a mutex instead of spinning on rtas_lock. Changes to follow will add rtas_function_lock()/unlock() pairs to kernel-based call sequences.

---
 arch/powerpc/include/asm/rtas.h |   2 +
 arch/powerpc/kernel/rtas.c      | 101 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 101 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/rtas.h +2 -0
index c697c3c74694..382627854034 100644
@@ -408,6 +408,8 @@ static inline bool rtas_function_implemented(const rtas_fn_handle_t handle)
 {
 	return rtas_function_token(handle) != RTAS_UNKNOWN_SERVICE;
 }
+void rtas_function_lock(rtas_fn_handle_t handle);
+void rtas_function_unlock(rtas_fn_handle_t handle);
 extern int rtas_token(const char *service);
 extern int rtas_service_present(const char *service);
 extern int rtas_call(int token, int, int, int *, ...);
arch/powerpc/kernel/rtas.c +99 -2

194 lines not on this page · raw message

Signature · 1 line
2.41.0
#3 lore raw

PATCH v3 3/10 powerpc/rtas: Serialize firmware activation sequences

In reply to Nathan Lynch

Use the function lock API to prevent interleaving call sequences of the ibm,activate-firmware RTAS function, which typically requires multiple calls to complete the update. While the spec does not specifically prohibit interleaved sequences, there's almost certainly no advantage to allowing them.

---
 arch/powerpc/kernel/rtas.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/kernel/rtas.c +4 -0
index 579a2c475bb6..864d140e7247 100644
@@ -1738,10 +1738,14 @@ void rtas_activate_firmware(void)
 		return;
 	}
 
+	rtas_function_lock(RTAS_FN_IBM_ACTIVATE_FIRMWARE);
+
 	do {
 		fwrc = rtas_call(token, 0, 1, NULL);
 	} while (rtas_busy_delay(fwrc));
 
+	rtas_function_unlock(RTAS_FN_IBM_ACTIVATE_FIRMWARE);
+
 	if (fwrc)
 		pr_err("ibm,activate-firmware failed (%i)\n", fwrc);
 }
Signature · 1 line
2.41.0
#4 lore raw

PATCH v3 4/10 powerpc/rtas: Warn if per-function lock isn't held

In reply to Nathan Lynch

If the function descriptor has a populated lock member, then callers are required to hold it across calls. Now that the firmware activation sequence is appropriately guarded, we can warn when the requirement isn't satisfied.

__do_enter_rtas_trace() gets reorganized a bit as a result of performing the function descriptor lookup unconditionally now.

---
 arch/powerpc/kernel/rtas.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
arch/powerpc/kernel/rtas.c +9 -12
index 864d140e7247..0a0ae81fac99 100644
@@ -670,28 +670,25 @@ static void __do_enter_rtas(struct rtas_args *args)
 
 static void __do_enter_rtas_trace(struct rtas_args *args)
 {
-	const char *name = NULL;
+	struct rtas_function *func = rtas_token_to_function(be32_to_cpu(args->token));
 
-	if (args == &rtas_args)
-		lockdep_assert_held(&rtas_lock);
 	/*
-	 * If the tracepoints that consume the function name aren't
-	 * active, avoid the lookup.
+	 * If there is a per-function lock, it must be held by the
+	 * caller.
 	 */
-	if ((trace_rtas_input_enabled() || trace_rtas_output_enabled())) {
-		const s32 token = be32_to_cpu(args->token);
-		const struct rtas_function *func = rtas_token_to_function(token);
+	if (func->lock)
+		WARN_ON(!mutex_is_locked(func->lock));
 
-		name = func->name;
-	}
+	if (args == &rtas_args)
+		lockdep_assert_held(&rtas_lock);
 
-	trace_rtas_input(args, name);
+	trace_rtas_input(args, func->name);
 	trace_rtas_ll_entry(args);
 
 	__do_enter_rtas(args);
 
 	trace_rtas_ll_exit(args);
-	trace_rtas_output(args, name);
+	trace_rtas_output(args, func->name);
 }
 
 static void do_enter_rtas(struct rtas_args *args)
Signature · 1 line
2.41.0
#5 lore raw

PATCH v3 5/10 powerpc/uapi: Export papr-miscdev.h header

In reply to Nathan Lynch

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
#6 lore raw

PATCH v3 6/10 powerpc/pseries: Add papr-vpd character 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/uapi/asm/papr-vpd.h           |  22 +
 arch/powerpc/platforms/pseries/Makefile            |   1 +
 arch/powerpc/platforms/pseries/papr-vpd.c          | 522 +++++++++++++++++++++
 4 files changed, 547 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/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 +522 -0

522 lines not on this page · raw message

Signature · 1 line
2.41.0
#7 lore raw

PATCH v3 7/10 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
#8 lore raw

PATCH v3 8/10 powerpc/pseries/papr-sysparm: Expose character device 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
#9 lore raw

PATCH v3 9/10 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 7ea42fa02eab..05fc68d446c2 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
#10 lore raw

PATCH v3 10/10 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 05fc68d446c2..c376151982c4 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
#11 lore raw
In reply to Nathan Lynch

Nathan Lynch via B4 Relay <[email protected]>

Quoted 2 lines · writes:

I have made changes to librtas to prefer the new interfaces and verified that existing clients work correctly with the new code.

Unfortunately I made a mistake in testing this time and introduced a boot-time oops:

BUG: Kernel NULL pointer dereference on read at 0x00000018
Faulting instruction address: 0xc00000000004223c
Oops: Kernel access of bad area, sig: 7 [#1]
LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries
Modules linked in:
CPU: 0 PID: 0 Comm: swapper Tainted: G        W          6.6.0-rc2+ #129
NIP:  c00000000004223c LR: c000000000042238 CTR: 0000000000000000
REGS: c000000002c579d0 TRAP: 0300   Tainted: G        W           (6.6.0-rc2+)
MSR:  8000000000001033 <SF,ME,IR,DR,RI,LE>  CR: 28000284  XER: 00000000
CFAR: c000000000042008 DAR: 0000000000000018 DSISR: 00080000 IRQMASK: 3 

GPR00: c000000000042238 c000000002c57c70 c000000001f5eb00 0000000000000000
GPR04: c00000000294cd08 0000000000000002 c000000002c579b4 0000000000000000
GPR08: 0000000000000000 0000000000000002 c000000002c0da80 0000000000000000
GPR12: 0000000000000000 c000000005e40000 0000000000000000 0000000002097728
GPR16: 0000000000001111 0000000000000001 0000000002097b80 00000000020975b8
GPR20: 00000000020976f0 00000000020974e8 00000000030feb00 00000000030feb00
GPR24: 0000000000002008 0000000000000000 0000000000000001 c0000000028f3d70
GPR28: 0000000002d31020 c000000002cac268 c000000002d31020 0000000000000000 NIP [c00000000004223c] do_enter_rtas+0xcc/0x460
LR [c000000000042238] do_enter_rtas+0xc8/0x460

Call Trace:
[c000000002c57c70] [c000000000042238] do_enter_rtas+0xc8/0x460 (unreliable)
[c000000002c57cc0] [c000000000042e34] rtas_call+0x434/0x490
[c000000002c57d20] [c0000000000fd584] papr_sysparm_get+0xe4/0x230
[c000000002c57db0] [c0000000020267d0] pSeries_probe+0x2f0/0x5fc
[c000000002c57e80] [c00000000200a318] setup_arch+0x11c/0x524
[c000000002c57f10] [c00000000200418c] start_kernel+0xcc/0xc1c
[c000000002c57fe0] [c00000000000e788] start_here_common+0x1c/0x20

This was introduced by patch #4 "powerpc/rtas: Warn if per-function lock isn't held": __do_enter_rtas() is now attempting token -> descriptor lookups unconditionally, before the xarray for that has been initialized.

With that change reverted, the series tests OK.

#12 lore raw

Hello,

Quoted 37 lines · Nathan Lynch

Nathan Lynch via B4 Relay <[email protected]>

Quoted 2 lines · writes:

I have made changes to librtas to prefer the new interfaces and verified that existing clients work correctly with the new code.

Unfortunately I made a mistake in testing this time and introduced a boot-time oops:

BUG: Kernel NULL pointer dereference on read at 0x00000018
Faulting instruction address: 0xc00000000004223c
Oops: Kernel access of bad area, sig: 7 [#1]
LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries
Modules linked in:
CPU: 0 PID: 0 Comm: swapper Tainted: G        W          6.6.0-rc2+ #129
NIP:  c00000000004223c LR: c000000000042238 CTR: 0000000000000000
REGS: c000000002c579d0 TRAP: 0300   Tainted: G        W           (6.6.0-rc2+)
MSR:  8000000000001033 <SF,ME,IR,DR,RI,LE>  CR: 28000284  XER: 00000000
CFAR: c000000000042008 DAR: 0000000000000018 DSISR: 00080000 IRQMASK: 3 

GPR00: c000000000042238 c000000002c57c70 c000000001f5eb00 0000000000000000
GPR04: c00000000294cd08 0000000000000002 c000000002c579b4 0000000000000000
GPR08: 0000000000000000 0000000000000002 c000000002c0da80 0000000000000000
GPR12: 0000000000000000 c000000005e40000 0000000000000000 0000000002097728
GPR16: 0000000000001111 0000000000000001 0000000002097b80 00000000020975b8
GPR20: 00000000020976f0 00000000020974e8 00000000030feb00 00000000030feb00
GPR24: 0000000000002008 0000000000000000 0000000000000001 c0000000028f3d70
GPR28: 0000000002d31020 c000000002cac268 c000000002d31020 0000000000000000 NIP [c00000000004223c] do_enter_rtas+0xcc/0x460
LR [c000000000042238] do_enter_rtas+0xc8/0x460

Call Trace:
[c000000002c57c70] [c000000000042238] do_enter_rtas+0xc8/0x460 (unreliable)
[c000000002c57cc0] [c000000000042e34] rtas_call+0x434/0x490
[c000000002c57d20] [c0000000000fd584] papr_sysparm_get+0xe4/0x230
[c000000002c57db0] [c0000000020267d0] pSeries_probe+0x2f0/0x5fc
[c000000002c57e80] [c00000000200a318] setup_arch+0x11c/0x524
[c000000002c57f10] [c00000000200418c] start_kernel+0xcc/0xc1c
[c000000002c57fe0] [c00000000000e788] start_here_common+0x1c/0x20
Quoted 5 lines

This was introduced by patch #4 "powerpc/rtas: Warn if per-function lock isn't held": __do_enter_rtas() is now attempting token -> descriptor lookups unconditionally, before the xarray for that has been initialized.

With that change reverted, the series tests OK.

What's the status here?

Can this move on with the 4th patch skipped, or is new revision expected?

Thanks

Michal

#13 lore raw
Quoted 4 lines · Michal Suchánek

What's the status here?

Can this move on with the 4th patch skipped, or is new revision expected?

I would like to get some feedback on the idea for coarse per-function locking in patch #2 "Facilitate high-level call sequences" since that is a core change to the RTAS subsystem and new in this revision. But I intend to send a new version (without a boot bug) this week regardless.