Add character devices for indices, platform-dump and physical-attestation RTAS
Subsystems (2)
v8 cover Add character devices for indices, platform-dump and physical-attestation RTAS
Several APIs such as rtas_get_indices(), rtas_get_dynamic_sensor(), rtas_set_dynamic_indicator(), rtas_platform_dump() and rtas_physical_attestation() provided by librtas library are implemented in user space using rtas syscall in combination with writable mappings of /dev/mem. But this implementation is not compatible with system lockdown which prohibits /dev/mem access. The current kernel already provides char based driver interfaces for several RTAS calls such as VPD and system parameters to support lockdown feature.
This patch series adds new char based drivers, /dev/papr-indices for ibm,get-indices, ibm,get-dynamic-sensor-state and ibm,set-dynamic-indicator RTAS Calls. /dev/papr-platform-dump for ibm,platform-dump and /dev/papr-physical-attestation fir ibm,physical-attestation. Providing the similar open/ioctl/read interfaces to the user space as in the case of VPD and system parameters.
I have made changes to librtas library to use the new kernel interfaces if the corresponding device entry is available.
This patch series has the following patches:
powerpc/pseries: Define common functions for RTAS sequence calls
- For some of sequence based RTAS calls, the OS should not start another sequence with different input until the previous sequence is completed. So the sequence should be completed during ioctl() and expose the entire buffer during read(). ibm,get-indices is sequence based RTAS function similar to ibm,get-vpd and we already have the corresponding implementation for VPD driver. So update papr_rtas_sequence struct for RTAS call specific functions and move the top level sequence functions in to a separate file.
powerpc/pseries: Define papr_indices_io_block for papr-indices ioctls
- /dev/papr-indices driver supports ibm,get-indices, ibm,get-dynamic-sensor-state and ibm,set-dynamic-indicator RTAS Calls. papr-indices.h introduces 3 different ioctls for these RTAS calls and the corresponding ioctl input buffer.
powerpc/pseries: Add papr-indices char driver for ibm,get-indices
- Introduce /dev/papr-indices char based driver and add support for get-indices RTAS function
powerpc/pseries: Add ibm,set-dynamic-indicator RTAS call support
- Update /dev/papr-indices for set-dynamic-indicator RTAS function
powerpc/pseries: Add ibm,get-dynamic-sensor-state RTAS call support
- Update /dev/papr-indices for get-dynamic-sensor-state RTAS function
powerpc/pseries: Add papr-platform-dump character driver for dump
retrieval
- Introduce /dev/papr-platform-dump char driver and adds support for ibm,platform-dump. Received suggestions from the previous post as a separate patch - Updated the patch with invalidating the dump using a separate ioctl.
powerpc/pseries: Add a char driver for papr-physical-attestation RTAS
- Introduce /dev/papr-physical-attestation char driver to provide kernel interface for ibm,physical-attestation RTAS function.
Changelog:
v8:
- Fixed build warnings for the proper function parameter descriptions (vpd_sequence_begin(), few papr_rtas_*() functions, and etc) as reported by kernel test robot <[email protected]>
v7:
- Pass the proper next value to the subsequent RTAS calls for the get-indices sequence RTAS.
(Vasireddy Sathvika found this bug).
v6:
- Define the proper command ID for PAPR_PHY_ATTEST_IOC_HANDLE ioctl
- Update ioctls description in ioctl-number.rst.
v5:
- Return with -EINPROGRESS in papr_platform_dump_invalidate_ioctl() if the complete dump is not read (Suggested by Michal Suchánek).
v4:
- Include patch "Add char driver for papr-physical-attestation RTAS" in this series. ibm,physical-attestation is sequence based RTAS call and the implementation is also similar to ibm,get-vpd and ibm,get-indices.
v3:
- put_unused_fd() only after get_unused_fd() successful for the failure case later ("Add papr-platform-dump character driver for dump retrieval" patch).
v2:
- Added unlock rtas_ibm_set_dynamic_indicator_lock and rtas_ibm_get_dynamic_sensor_state_lock mutex for failure cases as reported by Dan Carpenter
- Fixed build warnings for the proper function parameter descriptions as reported by kernel test robot <[email protected]>
Haren Myneni (7):
powerpc/pseries: Define common functions for RTAS sequence calls powerpc/pseries: Define papr_indices_io_block for papr-indices ioctls powerpc/pseries: Add papr-indices char driver for ibm,get-indices powerpc/pseries: Add ibm,set-dynamic-indicator RTAS call support powerpc/pseries: Add ibm,get-dynamic-sensor-state RTAS call support powerpc/pseries: Add papr-platform-dump character driver for dump
retrieval
powerpc/pseries: Add a char driver for physical-attestation RTAS
.../userspace-api/ioctl/ioctl-number.rst | 6 + arch/powerpc/include/asm/rtas.h | 4 + arch/powerpc/include/uapi/asm/papr-indices.h | 41 ++ .../uapi/asm/papr-physical-attestation.h | 31 ++ .../include/uapi/asm/papr-platform-dump.h | 15 + arch/powerpc/kernel/rtas.c | 8 +- arch/powerpc/platforms/pseries/Makefile | 3 +- arch/powerpc/platforms/pseries/papr-indices.c | 488 ++++++++++++++++++ .../platforms/pseries/papr-phy-attest.c | 288 +++++++++++ .../platforms/pseries/papr-platform-dump.c | 411 +++++++++++++++ .../platforms/pseries/papr-rtas-common.c | 310 +++++++++++ .../platforms/pseries/papr-rtas-common.h | 61 +++ arch/powerpc/platforms/pseries/papr-vpd.c | 351 ++----------- 13 files changed, 1705 insertions(+), 312 deletions(-) create mode 100644 arch/powerpc/include/uapi/asm/papr-indices.h create mode 100644 arch/powerpc/include/uapi/asm/papr-physical-attestation.h create mode 100644 arch/powerpc/include/uapi/asm/papr-platform-dump.h create mode 100644 arch/powerpc/platforms/pseries/papr-indices.c create mode 100644 arch/powerpc/platforms/pseries/papr-phy-attest.c create mode 100644 arch/powerpc/platforms/pseries/papr-platform-dump.c create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-common.c create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-common.h
Signature · 1 line
2.43.5
PATCH v8 1/7 powerpc/pseries: Define common functions for RTAS sequence calls
The RTAS call can be normal where retrieves the data form the hypervisor once or sequence based RTAS call which has to issue multiple times until the complete data is obtained. For some of these sequence RTAS calls, the OS should not interleave calls with different input until the sequence is completed. The data is collected for each call and copy to the buffer for the entire sequence during ioctl() handle and then expose this buffer to the user space with read() handle.
One such sequence RTAS call is ibm,get-vpd and its support is already included in the current code. To add the similar support for other sequence based calls, move the common functions in to separate file and update papr_rtas_sequence struct with the following callbacks so that RTAS call specific code will be defined and executed to complete the sequence.
struct papr_rtas_sequence {
int error;
void params;
void (*begin) (struct papr_rtas_sequence *);
void (*end) (struct papr_rtas_sequence *);
const char * (*work) (struct papr_rtas_sequence *, size_t *);
};params: Input parameters used to pass for RTAS call.
Begin: RTAS call specific function to initialize data
including work area allocation.
End: RTAS call specific function to free up resources
(free work area) after the sequence is completed.
Work: The actual RTAS call specific function which collects
the data from the hypervisor.
--- arch/powerpc/platforms/pseries/Makefile | 2 +- .../platforms/pseries/papr-rtas-common.c | 310 ++++++++++++++++ .../platforms/pseries/papr-rtas-common.h | 61 +++ arch/powerpc/platforms/pseries/papr-vpd.c | 351 +++--------------- 4 files changed, 416 insertions(+), 308 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-common.c create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-common.h
arch/powerpc/platforms/pseries/Makefile +1 -1
@@ -3,7 +3,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 \ + papr-rtas-common.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-rtas-common.c new file +310 -0
310 lines not on this page · raw message
arch/powerpc/platforms/pseries/papr-rtas-common.h new file +61 -0
61 lines not on this page · raw message
arch/powerpc/platforms/pseries/papr-vpd.c +44 -307
441 lines not on this page · raw message
Signature · 1 line
2.43.5
Re: [PATCH v8 1/7] powerpc/pseries: Define common functions for RTAS sequence calls
Quoted 337 lines · Haren Myneni
The RTAS call can be normal where retrieves the data form the hypervisor once or sequence based RTAS call which has to issue multiple times until the complete data is obtained. For some of these sequence RTAS calls, the OS should not interleave calls with different input until the sequence is completed. The data is collected for each call and copy to the buffer for the entire sequence during
ioctl()handle and then expose this buffer to the user space withread()handle.One such sequence RTAS call is ibm,get-vpd and its support is already included in the current code. To add the similar support for other sequence based calls, move the common functions in to separate file and update
papr_rtas_sequencestruct with the following callbacks so that RTAS call specific code will be defined and executed to complete the sequence.struct papr_rtas_sequence { int error; void params; void (*begin) (struct papr_rtas_sequence *); void (*end) (struct papr_rtas_sequence *); const char * (*work) (struct papr_rtas_sequence *, size_t *); };params: Input parameters used to pass for RTAS call.
Begin: RTAS call specific function to initialize data
including work area allocation.
End: RTAS call specific function to free up resources
(free work area) after the sequence is completed.
Work: The actual RTAS call specific function which collects
the data from the hypervisor.Signed-off-by Haren Myneni <[email protected]>--- arch/powerpc/platforms/pseries/Makefile | 2 +- .../platforms/pseries/papr-rtas-common.c | 310 ++++++++++++++++ .../platforms/pseries/papr-rtas-common.h | 61 +++ arch/powerpc/platforms/pseries/papr-vpd.c | 351 +++--------------- 4 files changed, 416 insertions(+), 308 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-common.c create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-common.harch/powerpc/platforms/pseries/Makefile +1
-1@@ -3,7 +3,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 \ + papr-rtas-common.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-rtas-common.c new file +276
-0@@ -0,0 +1,310 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define pr_fmt (fmt) "papr-common: " fmt + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/signal.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/fs.h> +#include <linux/anon_inodes.h> +#include <linux/sched/signal.h> +#include "papr-rtas-common.h" + +/* +* Sequence based RTAS HCALL has to issue multiple times to retrieve +* complete data from the hypervisor. For some of these RTAS calls, +* the OS should not interleave calls with different input until the +* sequence is completed. So data is collected for these calls during +* ioctl handle and export to user space with read() handle. +* This file provides common functions needed for such sequence based +* RTAS calls Ex: ibm,get-vpd and ibm,get-indices. +*/ + +bool papr_rtas_blob_has_data (const struct papr_rtas_blob *blob) +{ +return blob->data && blob->len; +} + +void papr_rtas_blob_free (const struct papr_rtas_blob *blob) +{ +if (blob) { +kvfree (blob->data); +kfree (blob); + } +} + +/** +* papr_rtas_blob_extend() - Append data to a &struct papr_rtas_blob. +* @blob: The blob to extend. +* @data: The new data to append to @blob. +* @len: The length of @data. +* +* Context: May sleep. +* Return: -ENOMEM on allocation failure, 0 otherwise. +*/ +static int papr_rtas_blob_extend (struct papr_rtas_blob *blob, +const char *data,size_t len) +{ +const size_t new_len = blob->len + len; +const size_t old_len = blob->len; +const char *old_ptr = blob->data; +char *new_ptr; + + new_ptr =kvrealloc (old_ptr, new_len,GFP_KERNEL_ACCOUNT ); +if (!new_ptr) +return -ENOMEM ; + +memcpy (&new_ptr[old_len], data, len); + blob->data = new_ptr; + blob->len = new_len; +return 0 ; +} + +/** +* papr_rtas_blob_generate() - Construct a new &struct papr_rtas_blob. +* @seq: work function of the caller that is called to obtain +* data with the caller RTAS call. +* +* The @work callback is invoked until it returns NULL. @seq is +* passed to @work in its first argument on each call. When +* @work returns data, it should store the data length in its +* second argument. +* +* Context: May sleep. +* Return: A completely populated &struct papr_rtas_blob, or NULL on error. +*/ +static const struct papr_rtas_blob * +papr_rtas_blob_generate (struct papr_rtas_sequence *seq) +{ +struct papr_rtas_blob *blob; +const char *buf; +size_t len; +int err =0 ; + + blob =kzalloc (sizeof (*blob),GFP_KERNEL_ACCOUNT ); +if (!blob) +return NULL ; + +if (!seq->work) +return ERR_PTR (-EINVAL ); + + +while (err ==0 && (buf = seq->work (seq, &len))) + err =papr_rtas_blob_extend (blob, buf, len); + +if (err !=0 || !papr_rtas_blob_has_data (blob)) + goto free_blob; + +return blob; +free_blob: +papr_rtas_blob_free (blob); +return NULL ; +} + +int papr_rtas_sequence_set_err (struct papr_rtas_sequence *seq,int err) +{ +/* Preserve the first error recorded. */ +if (seq->error ==0 ) + seq->error = err; + +return seq->error; +} + +/* +* Higher-level retrieval code below. These functions use the +* papr_rtas_blob_* and sequence_* APIs defined above to create fd-based +* handles for consumption by user space. +*/ + +/** +* papr_rtas_run_sequence() - Run a single retrieval sequence. +* @seq: Functions of the caller to complete the sequence +* +* Context: May sleep. Holds a mutex and an RTAS work area for its +* duration. Typically performs multiple sleepable slab +* allocations. +* +* Return: A populated &struct papr_rtas_blob on success. Encoded error +* pointer otherwise. +*/ +static const struct papr_rtas_blob *papr_rtas_run_sequence (struct papr_rtas_sequence *seq) +{ +const struct papr_rtas_blob *blob; + +if (seq->begin) + seq->begin (seq); + + blob =papr_rtas_blob_generate (seq); +if (!blob) +papr_rtas_sequence_set_err (seq, -ENOMEM ); + +if (seq->end) + seq->end (seq); + + +if (seq->error) { +papr_rtas_blob_free (blob); +return ERR_PTR (seq->error); + } + +return blob; +} + +/** +* papr_rtas_retrieve() - Return the data blob that is exposed to +* user space. +* @seq: RTAS call specific functions to be invoked until the +* sequence is completed. +* +* Run sequences against @param until a blob is successfully +* instantiated, or a hard error is encountered, or a fatal signal is +* pending. +* +* Context: May sleep. +* Return: A fully populated data blob when successful. Encoded error +* pointer otherwise. +*/ +const struct papr_rtas_blob *papr_rtas_retrieve (struct papr_rtas_sequence *seq) +{ +const struct papr_rtas_blob *blob; + +/* +* EAGAIN means the sequence returns error with a -4 (data +* changed and need to start the sequence) status from RTAS calls +* and we should attempt a new sequence. PAPR+ (v2.13 R1–7.3.20–5 +* - ibm,get-vpd, R1–7.3.17–6 - ibm,get-indices) indicates that +* this should be a transient condition, not something that +* happens continuously. But we'll stop trying on a fatal signal. +*/ +do { + blob =papr_rtas_run_sequence (seq); +if (!IS_ERR (blob))/* Success. */ +break ; +if (PTR_ERR (blob) != -EAGAIN )/* Hard error. */ +break ; +cond_resched (); + }while (!fatal_signal_pending (current)); + +return blob; +} + +/** +* papr_rtas_setup_file_interface - Complete the sequence and obtain +* the data and export to user space with fd-based handles. Then the +* user spave gets the data with read() handle. +* @seq: RTAS call specific functions to get the data. +* @fops: RTAS call specific file operations such as read(). +* @name: RTAS call specific char device node. +* +* Return: FD handle for consumption by user space +*/ +long papr_rtas_setup_file_interface (struct papr_rtas_sequence *seq, +const struct file_operations *fops, +char *name) +{ +const struct papr_rtas_blob *blob; +struct file *file; +long ret; +int fd; + + blob =papr_rtas_retrieve (seq); +if (IS_ERR (blob)) +return PTR_ERR (blob); + + fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); +if (fd <0 ) { + ret = fd; + goto free_blob; + } + + file =anon_inode_getfile (name, fops, (void *)blob,O_RDONLY ); +if (IS_ERR (file)) { + ret =PTR_ERR (file); + goto put_fd; + } + + file->f_mode |=FMODE_LSEEK |FMODE_PREAD ; +fd_install (fd, file); +return fd; + +put_fd: +put_unused_fd (fd); +free_blob: +papr_rtas_blob_free (blob); +return ret; +} + +/* +* papr_rtas_sequence_should_stop() - Determine whether RTAS retrieval +* sequence should continue. +* +* Examines the sequence error state and outputs of the last call to +* the specific RTAS to determine whether the sequence in progress +* should continue or stop. +* +* Return: True if the sequence has encountered an error or if all data +* for this sequence has been retrieved. False otherwise. +*/ +bool papr_rtas_sequence_should_stop (const struct papr_rtas_sequence *seq, +s32 status,bool init_state) +{ +bool done; + +if (seq->error) +return true; + +switch (status) { +case RTAS_SEQ_COMPLETE : +if (init_state) + done = false;/* Initial state. */ +else + done = true;/* All data consumed. */ +break ; +case RTAS_SEQ_MORE_DATA : + done = false;/* More data available. */ +break ; +default : + done = true;/* Error encountered. */ +break ; + } + +return done; +} + +/*
arch/powerpc/platforms/pseries/papr-rtas-common.c line 286
Quoted 10 lines
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +10
-0+* User space read to retrieve data for the corresponding RTAS call. +* papr_rtas_blob is filled with the data using the corresponding RTAS +* call sequence API. +*/ +ssize_t papr_rtas_common_handle_read (struct file *file, +char __user *buf,size_t size,loff_t *off) +{ +const struct papr_rtas_blob *blob = file->private_data; + +/* bug: we should not instantiate a handle without any data attached. */ if (!papr_rtas_blob_has_data (blob)) {
Line break is missing here.
Quoted 550 lines
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +24
-0+pr_err_once ("handle without data\n" ); +return -EIO ; + } + +return simple_read_from_buffer (buf, size, off, blob->data, blob->len); +} + +int papr_rtas_common_handle_release (struct inode *inode, +struct file *file) +{ +const struct papr_rtas_blob *blob = file->private_data; + +papr_rtas_blob_free (blob); + +return 0 ; +} + +loff_t papr_rtas_common_handle_seek (struct file *file,loff_t off, +int whence) +{ +const struct papr_rtas_blob *blob = file->private_data; + +return fixed_size_llseek (file, off, whence, blob->len); +}arch/powerpc/platforms/pseries/papr-rtas-common.h new file +61
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_POWERPC_PAPR_RTAS_COMMON_H +#define _ASM_POWERPC_PAPR_RTAS_COMMON_H + +#include <linux/types.h> + +/* +* Return codes for sequence based RTAS calls. +* Not listed under PAPR+ v2.13 7.2.8: "Return Codes". +* But defined in the specific section of each RTAS call. +*/ +#define RTAS_SEQ_COMPLETE 0/* All data has been retrieved. */ +#define RTAS_SEQ_MORE_DATA 1/* More data is available */ +#define RTAS_SEQ_START_OVER -4/* Data changed, restart call sequence. */ + +/* +* Internal "blob" APIs for accumulating RTAS call results into +* an immutable buffer to be attached to a file descriptor. +*/ +struct papr_rtas_blob { +const char *data; +size_t len; +}; + +/** +* struct papr_sequence - State for managing a sequence of RTAS calls. +* @error: Shall be zero as long as the sequence has not encountered an error, +* -ve errno otherwise. Use papr_rtas_sequence_set_err() to update. +* @params: Parameter block to pass to rtas_*() calls. +* @begin: Work area allocation and initialize the needed parameter +* values passed to RTAS call +* @end: Free the allocated work area +* @work: Obtain data with RTAS call and invoke it until the sequence is +* completed. +* +*/ +struct papr_rtas_sequence { +int error; +void *params; +void (*begin)(struct papr_rtas_sequence *seq); +void (*end)(struct papr_rtas_sequence *seq); +const char *(*work)(struct papr_rtas_sequence *seq,size_t *len); +}; + +extern bool papr_rtas_blob_has_data (const struct papr_rtas_blob *blob); +extern void papr_rtas_blob_free (const struct papr_rtas_blob *blob); +extern int papr_rtas_sequence_set_err (struct papr_rtas_sequence *seq, +int err); +extern const struct papr_rtas_blob *papr_rtas_retrieve (struct papr_rtas_sequence *seq); +extern long papr_rtas_setup_file_interface (struct papr_rtas_sequence *seq, +const struct file_operations *fops,char *name); +extern bool papr_rtas_sequence_should_stop (const struct papr_rtas_sequence *seq, +s32 status,bool init_state); +extern ssize_t papr_rtas_common_handle_read (struct file *file, +char __user *buf,size_t size,loff_t *off); +extern int papr_rtas_common_handle_release (struct inode *inode, +struct file *file); +extern loff_t papr_rtas_common_handle_seek (struct file *file,loff_t off, +int whence); +#endif /* _ASM_POWERPC_PAPR_RTAS_COMMON_H */ +arch/powerpc/platforms/pseries/papr-vpd.c +44
-307@@ -2,7 +2,6 @@#define pr_fmt (fmt) "papr-vpd: " fmt -#include <linux/anon_inodes.h> #include <linux/build_bug.h> #include <linux/file.h> #include <linux/fs.h> @@ -20,14 +19,7 @@#include <asm/rtas-work-area.h> #include <asm/rtas.h> #include <uapi/asm/papr-vpd.h> - -/* -* Function-specific return values for ibm,get-vpd, derived from PAPR+ -* v2.13 7.3.20 "ibm,get-vpd RTAS Call". -*/ -#define RTAS_IBM_GET_VPD_COMPLETE 0/* All VPD has been retrieved. */ -#define RTAS_IBM_GET_VPD_MORE_DATA 1/* More VPD is available. */ -#define RTAS_IBM_GET_VPD_START_OVER -4/* VPD changed, restart call sequence. */ +#include "papr-rtas-common.h" /** * struct rtas_ibm_get_vpd_params - Parameters (in and out) for ibm,get-vpd. @@ -91,13 +83,14 @@ static int rtas_ibm_get_vpd(struct rtas_ibm_get_vpd_params *params)case RTAS_INVALID_PARAMETER : ret = -EINVAL ;break ; -case RTAS_IBM_GET_VPD_START_OVER : +case RTAS_SEQ_START_OVER : ret = -EAGAIN ; +pr_info_ratelimited ("VPD changed during retrieval, retrying\n" );break ; -case RTAS_IBM_GET_VPD_MORE_DATA : +case RTAS_SEQ_MORE_DATA : params->sequence = rets[0 ]; fallthrough; -case RTAS_IBM_GET_VPD_COMPLETE : +case RTAS_SEQ_COMPLETE : params->written = rets[1 ];/* * Kernel or firmware bug, do not continue. @@ -118,91 +111,6 @@ static int rtas_ibm_get_vpd(struct rtas_ibm_get_vpd_params *params)return ret; } -/* -* Internal VPD "blob" APIs for accumulating ibm,get-vpd results into -* an immutable buffer to be attached to a file descriptor. -*/ -struct vpd_blob { -const char *data; -size_t len; -}; - -static bool vpd_blob_has_data (const struct vpd_blob *blob) -{ -return blob->data && blob->len; -} - -static void vpd_blob_free (const struct vpd_blob *blob) -{ -if (blob) { -kvfree (blob->data); -kfree (blob); - } -} - -/** -* vpd_blob_extend() - Append data to a &struct vpd_blob. -* @blob: The blob to extend. -* @data: The new data to append to @blob. -* @len: The length of @data. -* -* Context: May sleep. -* Return: -ENOMEM on allocation failure, 0 otherwise. -*/ -static int vpd_blob_extend (struct vpd_blob *blob,const char *data,size_t len) -{ -const size_t new_len = blob->len + len; -const size_t old_len = blob->len; -const char *old_ptr = blob->data; -char *new_ptr; - - new_ptr =kvrealloc (old_ptr, new_len,GFP_KERNEL_ACCOUNT ); -if (!new_ptr) -return -ENOMEM ; - -memcpy (&new_ptr[old_len], data, len); - blob->data = new_ptr; - blob->len = new_len; -return 0 ; -} - -/** -* vpd_blob_generate() - Construct a new &struct vpd_blob. -* @generator: Function that supplies the blob data. -* @arg: Context pointer supplied by caller, passed to @generator. -* -* The @generator callback is invoked until it returns NULL. @arg is -* passed to @generator in its first argument on each call. When -* @generator returns data, it should store the data length in its -* second argument. -* -* Context: May sleep. -* Return: A completely populated &struct vpd_blob, or NULL on error. -*/ -static const struct vpd_blob * -vpd_blob_generate (const char * (*generator)(void *,size_t *),void *arg) -{ -struct vpd_blob *blob; -const char *buf; -size_t len; -int err =0 ; - - blob =kzalloc (sizeof (*blob),GFP_KERNEL_ACCOUNT ); -if (!blob) -return NULL ; - -while (err ==0 && (buf =generator (arg, &len))) - err =vpd_blob_extend (blob, buf, len); - -if (err !=0 || !vpd_blob_has_data (blob)) - goto free_blob; - -return blob; -free_blob: -vpd_blob_free (blob); -return NULL ; -} -/* * Internal VPD sequence APIs. A VPD sequence is a series of calls to * ibm,get-vpd for a given location code. The sequence ends when an @@ -210,31 +118,15 @@ vpd_blob_generate(const char * (*generator)(void *, size_t *), void *arg)* returned. */ -/** -* struct vpd_sequence - State for managing a VPD sequence. -* @error: Shall be zero as long as the sequence has not encountered an error, -* -ve errno otherwise. Use vpd_sequence_set_err() to update this. -* @params: Parameter block to pass to rtas_ibm_get_vpd(). -*/ -struct vpd_sequence { -int error; -struct rtas_ibm_get_vpd_params params; -}; -/** * vpd_sequence_begin() - Begin a VPD retrieval sequence. -* @seq: Uninitialized sequence state. -* @loc_code: Location code that defines the scope of the VPD to return. -* -* Initializes @seq with the resources necessary to carry out a VPD -* sequence. Callers must pass @seq to vpd_sequence_end() regardless -* of whether the sequence succeeds. +* @seq: vpd call parameters from sequence struct * * Context: May sleep. */ -static void vpd_sequence_begin (struct vpd_sequence *seq, -const struct papr_location_code *loc_code) +static void vpd_sequence_begin (struct papr_rtas_sequence *seq) { +struct rtas_ibm_get_vpd_params *vpd_params;/* * Use a static data structure for the location code passed to * RTAS to ensure it's in the RMA and avoid a separate work @@ -242,6 +134,7 @@ static void vpd_sequence_begin(struct vpd_sequence *seq,*/ static struct papr_location_code static_loc_code; + vpd_params = (struct rtas_ibm_get_vpd_params *)seq->params;/* * We could allocate the work area before acquiring the * function lock, but that would allow concurrent requests to @@ -249,14 +142,12 @@ static void vpd_sequence_begin(struct vpd_sequence *seq,* allocate the work area under the lock. */ mutex_lock (&rtas_ibm_get_vpd_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 , - }, - }; + static_loc_code = *(struct papr_location_code *)vpd_params->loc_code; + vpd_params = (struct rtas_ibm_get_vpd_params *)seq->params; + vpd_params->work_area =rtas_work_area_alloc (SZ_4K ); + vpd_params->loc_code = &static_loc_code; + vpd_params->sequence =1 ; + vpd_params->status =0 ; }/** @@ -265,180 +156,39 @@ static void vpd_sequence_begin(struct vpd_sequence *seq,* * Releases resources obtained by vpd_sequence_begin(). */ -static void vpd_sequence_end (struct vpd_sequence *seq) -{ -rtas_work_area_free (seq->params.work_area); -mutex_unlock (&rtas_ibm_get_vpd_lock); -} - -/** -* vpd_sequence_should_stop() - Determine whether a VPD retrieval sequence -* should continue. -* @seq: VPD sequence state. -* -* Examines the sequence error state and outputs of the last call to -* ibm,get-vpd to determine whether the sequence in progress should -* continue or stop. -* -* Return: True if the sequence has encountered an error or if all VPD for -* this sequence has been retrieved. False otherwise. -*/ -static bool vpd_sequence_should_stop (const struct vpd_sequence *seq) -{ -bool done; - -if (seq->error) -return true; - -switch (seq->params.status) { -case 0 : -if (seq->params.written ==0 ) - done = false;/* Initial state. */ -else - done = true;/* All data consumed. */ -break ; -case 1 : - done = false;/* More data available. */ -break ; -default : - done = true;/* Error encountered. */ -break ; - } - -return done; -} - -static int vpd_sequence_set_err (struct vpd_sequence *seq,int err) +static void vpd_sequence_end (struct papr_rtas_sequence *seq) { -/* Preserve the first error recorded. */ -if (seq->error ==0 ) - seq->error = err; +struct rtas_ibm_get_vpd_params *vpd_params; -return seq->error; + vpd_params = (struct rtas_ibm_get_vpd_params *)seq->params; +rtas_work_area_free (vpd_params->work_area); +mutex_unlock (&rtas_ibm_get_vpd_lock); }/* -* Generator function to be passed to vpd_blob_generate(). +* Generator function to be passed to papr_rtas_blob_generate(). */ -static const char *vpd_sequence_fill_work_area (void *arg,size_t *len) +static const char *vpd_sequence_fill_work_area (struct papr_rtas_sequence *seq, +size_t *len) { -struct vpd_sequence *seq = arg; -struct rtas_ibm_get_vpd_params *p = &seq->params; +struct rtas_ibm_get_vpd_params *p; +bool init_state; + + p = (struct rtas_ibm_get_vpd_params *)seq->params; + init_state = (p->written ==0 ) ? true : false; -if (vpd_sequence_should_stop (seq)) +if (papr_rtas_sequence_should_stop (seq, p->status, init_state))return NULL ; -if (vpd_sequence_set_err (seq,rtas_ibm_get_vpd (p))) +if (papr_rtas_sequence_set_err (seq,rtas_ibm_get_vpd (p)))return NULL ; *len = p->written;return rtas_work_area_raw_buf (p->work_area); } -/* -* Higher-level VPD retrieval code below. These functions use the -* vpd_blob_* and vpd_sequence_* APIs defined above to create fd-based -* VPD handles for consumption by user space. -*/ - -/** -* papr_vpd_run_sequence() - Run a single VPD retrieval sequence. -* @loc_code: Location code that defines the scope of VPD to return. -* -* Context: May sleep. Holds a mutex and an RTAS work area for its -* duration. Typically performs multiple sleepable slab -* allocations. -* -* Return: A populated &struct vpd_blob on success. Encoded error -* pointer otherwise. -*/ -static const struct vpd_blob *papr_vpd_run_sequence (const struct papr_location_code *loc_code) -{ -const struct vpd_blob *blob; -struct vpd_sequence seq; - -vpd_sequence_begin (&seq, loc_code); - blob =vpd_blob_generate (vpd_sequence_fill_work_area, &seq); -if (!blob) -vpd_sequence_set_err (&seq, -ENOMEM ); -vpd_sequence_end (&seq); - -if (seq.error) { -vpd_blob_free (blob); -return ERR_PTR (seq.error); - } - -return blob; -} - -/** -* papr_vpd_retrieve() - Return the VPD for a location code. -* @loc_code: Location code that defines the scope of VPD to return. -* -* Run VPD sequences against @loc_code until a blob is successfully -* instantiated, or a hard error is encountered, or a fatal signal is -* pending. -* -* Context: May sleep. -* Return: A fully populated VPD blob when successful. Encoded error -* pointer otherwise. -*/ -static const struct vpd_blob *papr_vpd_retrieve (const struct papr_location_code *loc_code) -{ -const struct vpd_blob *blob; - -/* -* EAGAIN means the sequence errored with a -4 (VPD changed) -* status from ibm,get-vpd, and we should attempt a new -* sequence. PAPR+ v2.13 R1–7.3.20–5 indicates that this -* should be a transient condition, not something that happens -* continuously. But we'll stop trying on a fatal signal. -*/ -do { - blob =papr_vpd_run_sequence (loc_code); -if (!IS_ERR (blob))/* Success. */ -break ; -if (PTR_ERR (blob) != -EAGAIN )/* Hard error. */ -break ; -pr_info_ratelimited ("VPD changed during retrieval, retrying\n" ); -cond_resched (); - }while (!fatal_signal_pending (current)); - -return blob; -} - -static ssize_t papr_vpd_handle_read (struct file *file,char __user *buf,size_t size,loff_t *off) -{ -const struct vpd_blob *blob = file->private_data; - -/* bug: we should not instantiate a handle without any data attached. */ -if (!vpd_blob_has_data (blob)) { -pr_err_once ("handle without data\n" ); -return -EIO ; - } - -return simple_read_from_buffer (buf, size, off, blob->data, blob->len); -} - -static int papr_vpd_handle_release (struct inode *inode,struct file *file) -{ -const struct vpd_blob *blob = file->private_data; - -vpd_blob_free (blob); - -return 0 ; -} - -static loff_t papr_vpd_handle_seek (struct file *file,loff_t off,int whence) -{ -const struct vpd_blob *blob = file->private_data; - -return fixed_size_llseek (file, off, whence, blob->len); -} - -static const struct file_operations papr_vpd_handle_ops = { - .read = papr_vpd_handle_read, - .llseek = papr_vpd_handle_seek, - .release = papr_vpd_handle_release, + .read = papr_rtas_common_handle_read, + .llseek = papr_rtas_common_handle_seek, + .release = papr_rtas_common_handle_release, };/** @@ -460,10 +210,9 @@ static const struct file_operations papr_vpd_handle_ops = {*/ static long papr_vpd_create_handle (struct papr_location_code __user *ulc) { +struct rtas_ibm_get_vpd_params vpd_params = {}; +struct papr_rtas_sequence seq = {};struct papr_location_code klc; -const struct vpd_blob *blob; -struct file *file; -long err;int fd;if (copy_from_user (&klc, ulc,sizeof (klc)))@@ -472,31 +221,19 @@ static long papr_vpd_create_handle(struct papr_location_code __user *ulc)if (!string_is_terminated (klc.str,ARRAY_SIZE (klc.str)))return -EINVAL ; - blob =papr_vpd_retrieve (&klc); -if (IS_ERR (blob)) -return PTR_ERR (blob); + seq = (struct papr_rtas_sequence ) { + .begin = vpd_sequence_begin, + .end = vpd_sequence_end, + .work = vpd_sequence_fill_work_area, + }; - fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); -if (fd <0 ) { - err = fd; - goto free_blob; - } + vpd_params.loc_code = &klc; + seq.params = (void *)&vpd_params; - file =anon_inode_getfile ("[papr-vpd]" , &papr_vpd_handle_ops, - (void *)blob,O_RDONLY ); -if (IS_ERR (file)) { - err =PTR_ERR (file); - goto put_fd; - } + fd =papr_rtas_setup_file_interface (&seq, &papr_vpd_handle_ops, +"[papr-vpd]" ); - file->f_mode |=FMODE_LSEEK |FMODE_PREAD ; -fd_install (fd, file);return fd; -put_fd: -put_unused_fd (fd); -free_blob: -vpd_blob_free (blob); -return err; }/* Signature · 1 line
2.43.5
Re: [PATCH v8 1/7] powerpc/pseries: Define common functions for RTAS sequence calls
Quoted 378 lines · Mukesh Kumar Chaurasiya
Quoted 377 lines · Haren Myneni
The RTAS call can be normal where retrieves the data form the hypervisor once or sequence based RTAS call which has to issue multiple times until the complete data is obtained. For some of these sequence RTAS calls, the OS should not interleave calls with different input until the sequence is completed. The data is collected for each call and copy to the buffer for the entire sequence during
ioctl()handle and then expose this buffer to the user space withread()handle.One such sequence RTAS call is ibm,get-vpd and its support is already included in the current code. To add the similar support for other sequence based calls, move the common functions in to separate file and update
papr_rtas_sequencestruct with the following callbacks so that RTAS call specific code will be defined and executed to complete the sequence.struct papr_rtas_sequence { int error; void params; void (*begin) (struct papr_rtas_sequence *); void (*end) (struct papr_rtas_sequence *); const char * (*work) (struct papr_rtas_sequence *, size_t*);
};params: Input parameters used to pass for RTAS call.
Begin: RTAS call specific function to initialize data
including work area allocation.
End: RTAS call specific function to free up resources
(free work area) after the sequence is completed.
Work: The actual RTAS call specific function which collects
the data from the hypervisor.Signed-off-by Haren Myneni <[email protected]>--- arch/powerpc/platforms/pseries/Makefile | 2 +- .../platforms/pseries/papr-rtas-common.c | 310 ++++++++++++++++ .../platforms/pseries/papr-rtas-common.h | 61 +++ arch/powerpc/platforms/pseries/papr-vpd.c | 351 +++----------- ---- 4 files changed, 416 insertions(+), 308 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/papr-rtas- common.c create mode 100644 arch/powerpc/platforms/pseries/papr-rtas-
common.harch/powerpc/platforms/pseries/Makefile +1
-1@@ -3,7 +3,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 \ + papr-rtas-common.o papr-vpd.o \ setup.o iommu.o event_sources.o ras.o \ firmware.o power.o dlpar.o mobility.o rng.o\
arch/powerpc/platforms/pseries/Makefile +0
-0pci.o pci_dlpar.o eeh_pseries.o msi.o \arch/powerpc/platforms/pseries/papr-rtas-common.c new file +16
-0@@ -0,0 +1,310 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define pr_fmt (fmt) "papr-common: " fmt + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/signal.h> +#include <linux/slab.h> +#include <linux/file.h> +#include <linux/fs.h> +#include <linux/anon_inodes.h> +#include <linux/sched/signal.h> +#include "papr-rtas-common.h" + +/* +* Sequence based RTAS HCALL has to issue multiple times to retrieve
+ * complete data from the hypervisor. For some of these RTAS calls,
+ * the OS should not interleave calls with different input until the
+ * sequence is completed. So data is collected for these calls during
+ * ioctl handle and export to user space withread()handle.
+ * This file provides common functions needed for such sequence based
+ * RTAS calls Ex: ibm,get-vpd and ibm,get-indices.
+ */arch/powerpc/platforms/pseries/papr-rtas-common.c new file +16
-0+ +bool papr_rtas_blob_has_data (const struct papr_rtas_blob *blob) +{ +return blob->data && blob->len; +} + +void papr_rtas_blob_free (const struct papr_rtas_blob *blob) +{ +if (blob) { +kvfree (blob->data); +kfree (blob); + } +} + +/** +* papr_rtas_blob_extend() - Append data to a &struct
papr_rtas_blob.
+ * @blob: The blob to extend.
+ * @data: The new data to append to @blob.
+ * @len: The length of @data.
+ *
+ * Context: May sleep.
+ * Return:-ENOMEMon allocation failure, 0 otherwise.
+ */arch/powerpc/platforms/pseries/papr-rtas-common.c new file +20
-0+static int papr_rtas_blob_extend (struct papr_rtas_blob *blob, +const char *data,size_t len) +{ +const size_t new_len = blob->len + len; +const size_t old_len = blob->len; +const char *old_ptr = blob->data; +char *new_ptr; + + new_ptr =kvrealloc (old_ptr, new_len,GFP_KERNEL_ACCOUNT ); +if (!new_ptr) +return -ENOMEM ; + +memcpy (&new_ptr[old_len], data, len); + blob->data = new_ptr; + blob->len = new_len; +return 0 ; +} + +/** +* papr_rtas_blob_generate() - Construct a new &struct
papr_rtas_blob.
+ * @seq: work function of the caller that is called to obtain
+ * data with the caller RTAS call.
+ *
+ * The @work callback is invoked until it returns NULL. @seq is
+ * passed to @work in its first argument on each call. When
+ * @work returns data, it should store the data length in its
+ * second argument.
+ *
+ * Context: May sleep.
+ * Return: A completely populated &structpapr_rtas_blob, or NULL on error.
+ */arch/powerpc/platforms/pseries/papr-rtas-common.c new file +29
-0+static const struct papr_rtas_blob * +papr_rtas_blob_generate (struct papr_rtas_sequence *seq) +{ +struct papr_rtas_blob *blob; +const char *buf; +size_t len; +int err =0 ; + + blob =kzalloc (sizeof (*blob),GFP_KERNEL_ACCOUNT ); +if (!blob) +return NULL ; + +if (!seq->work) +return ERR_PTR (-EINVAL ); + + +while (err ==0 && (buf = seq->work (seq, &len))) + err =papr_rtas_blob_extend (blob, buf, len); + +if (err !=0 || !papr_rtas_blob_has_data (blob)) + goto free_blob; + +return blob; +free_blob: +papr_rtas_blob_free (blob); +return NULL ; +} + +int papr_rtas_sequence_set_err(struct papr_rtas_sequence *seq, interr)
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +11
-0+{ +/* Preserve the first error recorded. */ +if (seq->error ==0 ) + seq->error = err; + +return seq->error; +} + +/* +* Higher-level retrieval code below. These functions use the +* papr_rtas_blob_* and sequence_* APIs defined above to create fd-based
+ * handles for consumption by user space.
+ */arch/powerpc/platforms/pseries/papr-rtas-common.c new file +10
-0+ +/** +* papr_rtas_run_sequence() - Run a single retrieval sequence. +* @seq: Functions of the caller to complete the sequence +* +* Context: May sleep. Holds a mutex and an RTAS work area for its +* duration. Typically performs multiple sleepable slab +* allocations. +* +* Return: A populated &struct papr_rtas_blob on success. Encoded error
+ * pointer otherwise.
+ */
+static const structpapr_rtas_blob*papr_rtas_run_sequence(structpapr_rtas_sequence*seq)arch/powerpc/platforms/pseries/papr-rtas-common.c new file +30
-0+{ +const struct papr_rtas_blob *blob; + +if (seq->begin) + seq->begin (seq); + + blob =papr_rtas_blob_generate (seq); +if (!blob) +papr_rtas_sequence_set_err (seq, -ENOMEM ); + +if (seq->end) + seq->end (seq); + + +if (seq->error) { +papr_rtas_blob_free (blob); +return ERR_PTR (seq->error); + } + +return blob; +} + +/** +* papr_rtas_retrieve() - Return the data blob that is exposed to +* user space. +* @seq: RTAS call specific functions to be invoked until the +* sequence is completed. +* +* Run sequences against @param until a blob is successfully +* instantiated, or a hard error is encountered, or a fatal signal is
+ * pending.
+ *
+ * Context: May sleep.
+ * Return: A fully populated data blob when successful. Encoded error
+ * pointer otherwise.
+ */
+const structpapr_rtas_blob*papr_rtas_retrieve(structpapr_rtas_sequence*seq)arch/powerpc/platforms/pseries/papr-rtas-common.c new file +6
-0+{ +const struct papr_rtas_blob *blob; + +/* +* EAGAIN means the sequence returns error with a -4 (data +* changed and need to start the sequence) status from RTAS calls
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +1
-0+* and we should attempt a new sequence. PAPR+ (v2.13 R1–7.3.20–5
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +3
-0+* - ibm,get-vpd, R1–7.3.17–6 - ibm,get-indices) indicates that +* this should be a transient condition, not something that +* happens continuously. But we'll stop trying on a fatal signal.
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +15
-0+*/ +do { + blob =papr_rtas_run_sequence (seq); +if (!IS_ERR (blob))/* Success. */ +break ; +if (PTR_ERR (blob) != -EAGAIN )/* Hard error. */ +break ; +cond_resched (); + }while (!fatal_signal_pending (current)); + +return blob; +} + +/** +* papr_rtas_setup_file_interface - Complete the sequence and obtain
+ * the data and export to user space with fd-based handles. Then the
+ * user spave gets the data withread()handle.
+ * @seq: RTAS call specific functions to get the data.
+ * @fops: RTAS call specific file operations such asread().
+ * @name: RTAS call specific char device node.
+ *
+ * Return: FD handle for consumption by user space
+ */
+long papr_rtas_setup_file_interface(structpapr_rtas_sequence*seq,arch/powerpc/platforms/pseries/papr-rtas-common.c new file +37
-0+const struct file_operations *fops, + char *name) +{ + const struct papr_rtas_blob *blob; +struct file *file; +long ret; +int fd; + + blob =papr_rtas_retrieve (seq); +if (IS_ERR (blob)) +return PTR_ERR (blob); + + fd =get_unused_fd_flags (O_RDONLY |O_CLOEXEC ); +if (fd <0 ) { + ret = fd; + goto free_blob; + } + + file =anon_inode_getfile (name, fops, (void *)blob,O_RDONLY ); +if (IS_ERR (file)) { + ret =PTR_ERR (file); + goto put_fd; + } + + file->f_mode |=FMODE_LSEEK |FMODE_PREAD ; +fd_install (fd, file); +return fd; + +put_fd: +put_unused_fd (fd); +free_blob: +papr_rtas_blob_free (blob); +return ret; +} + +/* +* papr_rtas_sequence_should_stop() - Determine whether RTAS retrieval
+ * sequence should continue.
+ *
+ * Examines the sequence error state and outputs of the last call to
+ * the specific RTAS to determine whether the sequence in progress
+ * should continue or stop.
+ *
+ * Return: True if the sequence has encountered an error or if all data
+ * for this sequence has been retrieved. False otherwise.
+ */
+bool papr_rtas_sequence_should_stop(const structpapr_rtas_sequence*seq,arch/powerpc/platforms/pseries/papr-rtas-common.c new file +27
-0+ s32 status, bool init_state) +{ + bool done; + +if (seq->error) +return true; + +switch (status) { +case RTAS_SEQ_COMPLETE : +if (init_state) + done = false;/* Initial state. */ +else + done = true;/* All data consumed. */ +break ; +case RTAS_SEQ_MORE_DATA : + done = false;/* More data available. */ +break ; +default : + done = true;/* Error encountered. */ +break ; + } + +return done; +} + +/* +* User space read to retrieve data for the corresponding RTAS call.
+ *papr_rtas_blobis filled with the data using the corresponding RTAS
+ * call sequence API.
+ */
Quoted 8 lines
Quoted 7 lines
arch/powerpc/platforms/pseries/papr-rtas-common.c new file +6
-0+ssize_t papr_rtas_common_handle_read (struct file *file, +char __user *buf,size_t size,loff_t *off) +{ +const struct papr_rtas_blob *blob = file->private_data; + +/* bug: we should not instantiate a handle without any data attached. */ if (!papr_rtas_blob_has_data(blob)) {
Line break is missing here.
Thanks for finding it. I did not find this with checkpatch initially. Looks like made this mistake in v4 revision.
PATCH v8 2/7 powerpc/pseries: Define papr_indices_io_block for papr-indices ioctls
In reply to Haren MyneniTo issue ibm,get-indices, ibm,set-dynamic-indicator and ibm,get-dynamic-sensor-state in the user space, the RMO buffer is allocated for the work area which is restricted under system lockdown. So instead of user space execution, the kernel will provide /dev/papr-indices interface to execute these RTAS calls.
The user space assigns data in papr_indices_io_block struct depends on the specific HCALL and passes to the following ioctls:
PAPR_INDICES_IOC_GET: Use for ibm,get-indices. Returns a
get-indices handle fd to read data.PAPR_DYNAMIC_SENSOR_IOC_GET: Use for ibm,get-dynamic-sensor-state.
Updates the sensor state in papr_indices_io_block.dynamic_param.state
PAPR_DYNAMIC_INDICATOR_IOC_SET: Use for ibm,set-dynamic-indicator.
Sets the new state for the input indicator.
--- .../userspace-api/ioctl/ioctl-number.rst | 2 + arch/powerpc/include/uapi/asm/papr-indices.h | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 arch/powerpc/include/uapi/asm/papr-indices.h
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -363,6 +363,8 @@ Code Seq# Include File Comments <mailto:linuxppc-dev> 0xB2 01-02 arch/powerpc/include/uapi/asm/papr-sysparm.h powerpc/pseries system parameter API <mailto:linuxppc-dev> +0xB2 03-05 arch/powerpc/include/uapi/asm/papr-indices.h powerpc/pseries indices 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-indices.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v8 3/7 powerpc/pseries: Add papr-indices char driver for ibm,get-indices
In reply to Haren MyneniThe RTAS call ibm,get-indices is used to obtain indices and location codes for a specified indicator or sensor token. The current implementation uses rtas_get_indices() API provided by librtas library which allocates RMO buffer and issue this RTAS call in the user space. But writable mapping /dev/mem access by the user space is prohibited under system lockdown.
To overcome the restricted access in the user space, the kernel provide interfaces to collect indices data from the hypervisor. This patch adds papr-indices character driver and expose standard interfaces such as open / ioctl/ read to user space in ways that are compatible with lockdown.
PAPR (2.13 7.3.17 ibm,get-indices RTAS Call) describes the following steps to retrieve all indices data:
- User input parameters to the RTAS call: sensor or indicator, and indice type
- ibm,get-indices is sequence RTAS call which means has to issue multiple times to get the entire list of indicators or sensors of a particular type. The hypervisor expects the first RTAS call with the sequence 1 and the subsequent calls with the sequence number returned from the previous calls.
- The OS may not interleave calls to ibm,get-indices for different indicator or sensor types. Means other RTAS calls with different type should not be issued while the previous type sequence is in progress. So collect the entire list of indices and copied to buffer BLOB during ioctl() and expose this buffer to the user space with the file descriptor.
- The hypervisor fills the work area with a specific format but does not return the number of bytes written to the buffer. Instead of parsing the data for each call to determine the data length, copy the work area size (RTAS_GET_INDICES_BUF_SIZE) to the buffer. Return work-area size of data to the user space for each read() call.
Expose these interfaces to user space with a /dev/papr-indices character device using the following programming model:
int devfd = open("/dev/papr-indices", O_RDONLY);
int fd = ioctl(devfd, PAPR_INDICES_IOC_GET,
struct papr_indices_io_block)
- Collect all indices data for the specified token to the buffer
char *buf = malloc(RTAS_GET_INDICES_BUF_SIZE);
length = read(fd, buf, RTAS_GET_INDICES_BUF_SIZE)
- RTAS_GET_INDICES_BUF_SIZE of data is returned to the user space.
- The user space retrieves the indices and their location codes from the buffer
- Should issue multiple read() calls until reaches the end of BLOB buffer.
The read() should use the file descriptor obtained from ioctl to get the data that is exposed to file descriptor. Implemented support in librtas (rtas_get_indices()) for this new ABI for system lockdown.
--- arch/powerpc/include/asm/rtas.h | 1 + arch/powerpc/kernel/rtas.c | 2 +- arch/powerpc/platforms/pseries/Makefile | 2 +- arch/powerpc/platforms/pseries/papr-indices.c | 301 ++++++++++++++++++ 4 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/papr-indices.c
arch/powerpc/include/asm/rtas.h +1 -0
@@ -515,6 +515,7 @@ extern char rtas_data_buf[RTAS_DATA_BUF_SIZE];extern unsigned long rtas_rmo_buf;extern struct mutex rtas_ibm_get_vpd_lock; +extern struct mutex rtas_ibm_get_indices_lock;#define GLOBAL_INTERRUPT_QUEUE 9005
arch/powerpc/kernel/rtas.c +1 -1
@@ -93,11 +93,11 @@ struct rtas_function {*/ static DEFINE_MUTEX (rtas_ibm_activate_firmware_lock);static DEFINE_MUTEX (rtas_ibm_get_dynamic_sensor_state_lock); -static DEFINE_MUTEX (rtas_ibm_get_indices_lock);static DEFINE_MUTEX (rtas_ibm_lpar_perftools_lock);static DEFINE_MUTEX (rtas_ibm_physical_attestation_lock);static DEFINE_MUTEX (rtas_ibm_set_dynamic_indicator_lock);DEFINE_MUTEX (rtas_ibm_get_vpd_lock); +DEFINE_MUTEX (rtas_ibm_get_indices_lock);static struct rtas_function rtas_function_table[]__ro_after_init = { [RTAS_FNIDX__CHECK_EXCEPTION ] = {
arch/powerpc/platforms/pseries/Makefile +1 -1
@@ -3,7 +3,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-rtas-common.o papr-vpd.o \ + papr-rtas-common.o papr-vpd.o papr-indices.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-indices.c new file +301 -0
301 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v8 4/7 powerpc/pseries: Add ibm,set-dynamic-indicator RTAS call support
In reply to Haren MyneniThe RTAS call ibm,set-dynamic-indicator is used to set the new indicator state identified by a location code. The current implementation uses rtas_set_dynamic_indicator() API provided by librtas library which allocates RMO buffer and issue this RTAS call in the user space. But /dev/mem access by the user space is prohibited under system lockdown.
This patch provides an interface with new ioctl PAPR_DYNAMIC_INDICATOR_IOC_SET to the papr-indices character driver and expose this interface to the user space that is compatible with lockdown.
Refer PAPR 7.3.18 ibm,set-dynamic-indicator for more information on this RTAS call.
- User input parameters to the RTAS call: location code string, indicator token and new state
Expose these interfaces to user space with a /dev/papr-indices character device using the following programming model:
int fd = open("/dev/papr-indices", O_RDWR);
int ret = ioctl(fd, PAPR_DYNAMIC_INDICATOR_IOC_SET,
struct papr_indices_io_block)
- The user space passes input parameters in papr_indices_io_block struct
--- arch/powerpc/include/asm/rtas.h | 1 + arch/powerpc/kernel/rtas.c | 2 +- arch/powerpc/platforms/pseries/papr-indices.c | 120 ++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/rtas.h +1 -0
@@ -516,6 +516,7 @@ extern unsigned long rtas_rmo_buf;extern struct mutex rtas_ibm_get_vpd_lock;extern struct mutex rtas_ibm_get_indices_lock; +extern struct mutex rtas_ibm_set_dynamic_indicator_lock;#define GLOBAL_INTERRUPT_QUEUE 9005
arch/powerpc/kernel/rtas.c +1 -1
@@ -95,9 +95,9 @@ static DEFINE_MUTEX(rtas_ibm_activate_firmware_lock);static DEFINE_MUTEX (rtas_ibm_get_dynamic_sensor_state_lock);static DEFINE_MUTEX (rtas_ibm_lpar_perftools_lock);static DEFINE_MUTEX (rtas_ibm_physical_attestation_lock); -static DEFINE_MUTEX (rtas_ibm_set_dynamic_indicator_lock);DEFINE_MUTEX (rtas_ibm_get_vpd_lock);DEFINE_MUTEX (rtas_ibm_get_indices_lock); +DEFINE_MUTEX (rtas_ibm_set_dynamic_indicator_lock);static struct rtas_function rtas_function_table[]__ro_after_init = { [RTAS_FNIDX__CHECK_EXCEPTION ] = {
arch/powerpc/platforms/pseries/papr-indices.c +120 -0
144 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v8 5/7 powerpc/pseries: Add ibm,get-dynamic-sensor-state RTAS call support
In reply to Haren MyneniThe RTAS call ibm,get-dynamic-sensor-state is used to get the sensor state identified by the location code and the sensor token. The librtas library provides an API rtas_get_dynamic_sensor() which uses /dev/mem access for work area allocation but is restricted under system lockdown.
This patch provides an interface with new ioctl
PAPR_DYNAMIC_SENSOR_IOC_GET to the papr-indices character
driver which executes this HCALL and copies the sensor state in the user specified ioctl buffer.
Refer PAPR 7.3.19 ibm,get-dynamic-sensor-state for more information on this RTAS call.
- User input parameters to the RTAS call: location code string and the sensor token
Expose these interfaces to user space with a /dev/papr-indices character device using the following programming model:
int fd = open("/dev/papr-indices", O_RDWR);
int ret = ioctl(fd, PAPR_DYNAMIC_SENSOR_IOC_GET,
struct papr_indices_io_block)
- The user space specifies input parameters in papr_indices_io_block struct
- Returned state for the specified sensor is copied to papr_indices_io_block.dynamic_param.state
--- arch/powerpc/include/asm/rtas.h | 1 + arch/powerpc/kernel/rtas.c | 2 +- arch/powerpc/platforms/pseries/papr-indices.c | 67 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/rtas.h +1 -0
@@ -517,6 +517,7 @@ extern unsigned long rtas_rmo_buf;extern struct mutex rtas_ibm_get_vpd_lock;extern struct mutex rtas_ibm_get_indices_lock;extern struct mutex rtas_ibm_set_dynamic_indicator_lock; +extern struct mutex rtas_ibm_get_dynamic_sensor_state_lock;#define GLOBAL_INTERRUPT_QUEUE 9005
arch/powerpc/kernel/rtas.c +1 -1
@@ -92,12 +92,12 @@ struct rtas_function {* Per-function locks for sequence-based RTAS functions. */ static DEFINE_MUTEX (rtas_ibm_activate_firmware_lock); -static DEFINE_MUTEX (rtas_ibm_get_dynamic_sensor_state_lock);static DEFINE_MUTEX (rtas_ibm_lpar_perftools_lock);static DEFINE_MUTEX (rtas_ibm_physical_attestation_lock);DEFINE_MUTEX (rtas_ibm_get_vpd_lock);DEFINE_MUTEX (rtas_ibm_get_indices_lock);DEFINE_MUTEX (rtas_ibm_set_dynamic_indicator_lock); +DEFINE_MUTEX (rtas_ibm_get_dynamic_sensor_state_lock);static struct rtas_function rtas_function_table[]__ro_after_init = { [RTAS_FNIDX__CHECK_EXCEPTION ] = {
arch/powerpc/platforms/pseries/papr-indices.c +67 -0
85 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v8 6/7 powerpc/pseries: Add papr-platform-dump character driver for dump retrieval
In reply to Haren Myneniibm,platform-dump RTAS call in combination with writable mapping /dev/mem is issued to collect platform dump from the hypervisor and may need multiple calls to get the complete dump. The current implementation uses rtas_platform_dump() API provided by librtas library to issue these RTAS calls. But /dev/mem access by the user space is prohibited under system lockdown.
The solution should be to restrict access to RTAS function in user space and provide kernel interfaces to collect dump. This patch adds papr-platform-dump character driver and expose standard interfaces such as open / ioctl/ read to user space in ways that are compatible with lockdown.
PAPR (7.3.3.4.1 ibm,platform-dump) provides a method to obtain the complete dump:
- Each dump will be identified by ID called dump tag.
- A sequence of RTAS calls have to be issued until retrieve the complete dump. The hypervisor expects the first RTAS call with the sequence 0 and the subsequent calls with the sequence number returned from the previous calls.
- The hypervisor returns "dump complete" status once the complete dump is retrieved. But expects one more RTAS call from the partition with the NULL buffer to invalidate dump which means the dump will be removed in the hypervisor.
- Sequence of calls are allowed with different dump IDs at the same time but not with the same dump ID.
Expose these interfaces to user space with a /dev/papr-platform-dump character device using the following programming model:
int devfd = open("/dev/papr-platform-dump", O_RDONLY); int fd = ioctl(devfd,PAPR_PLATFORM_DUMP_IOC_CREATE_HANDLE, &dump_id)
- Restrict user space to access with the same dump ID. Typically we do not expect user space requests the dump again for the same dump ID.
char *buf = malloc(size);
length = read(fd, buf, size);
- size should be minimum 1K based on PAPR and <= 4K based on RTAS work area size. It will be restrict to RTAS work area size. Using 4K work area based on the current implementation in librtas library
- Each read call issue RTAS call to get the data based on the size requirement and returns bytes returned from the hypervisor
- If the previous call returns dump complete status, the next read returns 0 like EOF.
ret = ioctl(PAPR_PLATFORM_DUMP_IOC_INVALIDATE, &dump_id)
- RTAS call with NULL buffer to invalidates the dump.
The read API should use the file descriptor obtained from ioctl based on dump ID so that gets dump contents for the corresponding dump ID. Implemented support in librtas (rtas_platform_dump()) for this new ABI to support system lockdown.
--- .../userspace-api/ioctl/ioctl-number.rst | 2 + .../include/uapi/asm/papr-platform-dump.h | 15 + arch/powerpc/platforms/pseries/Makefile | 1 + .../platforms/pseries/papr-platform-dump.c | 411 ++++++++++++++++++ 4 files changed, 429 insertions(+) create mode 100644 arch/powerpc/include/uapi/asm/papr-platform-dump.h create mode 100644 arch/powerpc/platforms/pseries/papr-platform-dump.c
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -365,6 +365,8 @@ Code Seq# Include File Comments <mailto:linuxppc-dev> 0xB2 03-05 arch/powerpc/include/uapi/asm/papr-indices.h powerpc/pseries indices API <mailto:linuxppc-dev> +0xB2 06-07 arch/powerpc/include/uapi/asm/papr-platform-dump.h powerpc/pseries Platform Dump 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-platform-dump.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_PAPR_PLATFORM_DUMP_H_ +#define _UAPI_PAPR_PLATFORM_DUMP_H_ + +#include <asm/ioctl.h> +#include <asm/papr-miscdev.h> + +/* +* ioctl for /dev/papr-platform-dump. Returns a platform-dump handle fd +* corresponding to dump tag. +*/ +#define PAPR_PLATFORM_DUMP_IOC_CREATE_HANDLE _IOW(PAPR_MISCDEV_IOC_ID, 6, __u64) +#define PAPR_PLATFORM_DUMP_IOC_INVALIDATE _IOW(PAPR_MISCDEV_IOC_ID, 7, __u64) + +#endif /* _UAPI_PAPR_PLATFORM_DUMP_H_ */
arch/powerpc/platforms/pseries/Makefile +1 -0
@@ -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-rtas-common.o papr-vpd.o papr-indices.o \ + papr-platform-dump.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-platform-dump.c new file +411 -0
411 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v8 7/7 powerpc/pseries: Add a char driver for physical-attestation RTAS
In reply to Haren MyneniThe RTAS call ibm,physical-attestation is used to retrieve information about the trusted boot state of the firmware and hypervisor on the system, and also Trusted Platform Modules (TPM) data if the system is TCG 2.0 compliant.
This RTAS interface expects the caller to define different command structs such as RetrieveTPMLog, RetrievePlatformCertificat and etc, in a work area with a maximum size of 4K bytes and the response buffer will be returned in the same work area.
The current implementation of this RTAS function is in the user space but allocation of the work area is restricted with the system lockdown. So this patch implements this RTAS function in the kernel and expose to the user space with open/ioctl/read interfaces.
PAPR (2.13+ 21.3 ibm,physical-attestation) defines RTAS function:
- Pass the command struct to obtain the response buffer for the specific command.
- This RTAS function is sequence RTAS call and has to issue RTAS call multiple times to get the complete response buffer (max 64K). The hypervisor expects the first RTAS call with the sequence 1 and the subsequent calls with the sequence number returned from the previous calls.
Expose these interfaces to user space with a /dev/papr-physical-attestation character device using the following programming model:
int devfd = open("/dev/papr-physical-attestation"); int fd = ioctl(devfd, PAPR_PHY_ATTEST_IOC_HANDLE,
struct papr_phy_attest_io_block);
- The user space defines the command struct and requests the response for any command.
- Obtain the complete response buffer and returned the buffer as blob to the command specific FD.
size = read(fd, buf, len);
- Can retrieve the response buffer once or multiple times until the end of BLOB buffer.
Implemented this new kernel ABI support in librtas library for system lockdown
--- .../userspace-api/ioctl/ioctl-number.rst | 2 + arch/powerpc/include/asm/rtas.h | 1 + .../uapi/asm/papr-physical-attestation.h | 31 ++ arch/powerpc/kernel/rtas.c | 2 +- arch/powerpc/platforms/pseries/Makefile | 2 +- .../platforms/pseries/papr-phy-attest.c | 288 ++++++++++++++++++ 6 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/include/uapi/asm/papr-physical-attestation.h create mode 100644 arch/powerpc/platforms/pseries/papr-phy-attest.c
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -367,6 +367,8 @@ Code Seq# Include File Comments <mailto:linuxppc-dev> 0xB2 06-07 arch/powerpc/include/uapi/asm/papr-platform-dump.h powerpc/pseries Platform Dump API <mailto:linuxppc-dev> +0xB2 08 arch/powerpc/include/uapi/asm/papr-physical-attestation.h powerpc/pseries Physical Attestation 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/rtas.h +1 -0
@@ -518,6 +518,7 @@ extern struct mutex rtas_ibm_get_vpd_lock;extern struct mutex rtas_ibm_get_indices_lock;extern struct mutex rtas_ibm_set_dynamic_indicator_lock;extern struct mutex rtas_ibm_get_dynamic_sensor_state_lock; +extern struct mutex rtas_ibm_physical_attestation_lock;#define GLOBAL_INTERRUPT_QUEUE 9005
arch/powerpc/include/uapi/asm/papr-physical-attestation.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_PAPR_PHYSICAL_ATTESTATION_H_ +#define _UAPI_PAPR_PHYSICAL_ATTESTATION_H_ + +#include <linux/types.h> +#include <asm/ioctl.h> +#include <asm/papr-miscdev.h> + +#define PAPR_PHYATTEST_MAX_INPUT 4084/* Max 4K buffer: 4K-12 */ + +/* +* Defined in PAPR 2.13+ 21.6 Attestation Command Structures. +* User space pass this struct and the max size should be 4K. +*/ +struct papr_phy_attest_io_block { +__u8 version; +__u8 command; +__u8 TCG_major_ver; +__u8 TCG_minor_ver; +__be32 length; +__be32 correlator; +__u8 payload[PAPR_PHYATTEST_MAX_INPUT ]; +}; + +/* +* ioctl for /dev/papr-physical-attestation. Returns a attestation +* command fd handle +*/ +#define PAPR_PHY_ATTEST_IOC_HANDLE _IOW(PAPR_MISCDEV_IOC_ID, 8, struct papr_phy_attest_io_block) + +#endif /* _UAPI_PAPR_PHYSICAL_ATTESTATION_H_ */
arch/powerpc/kernel/rtas.c +1 -1
@@ -93,7 +93,7 @@ struct rtas_function {*/ static DEFINE_MUTEX (rtas_ibm_activate_firmware_lock);static DEFINE_MUTEX (rtas_ibm_lpar_perftools_lock); -static DEFINE_MUTEX (rtas_ibm_physical_attestation_lock); +DEFINE_MUTEX (rtas_ibm_physical_attestation_lock);DEFINE_MUTEX (rtas_ibm_get_vpd_lock);DEFINE_MUTEX (rtas_ibm_get_indices_lock);DEFINE_MUTEX (rtas_ibm_set_dynamic_indicator_lock);
arch/powerpc/platforms/pseries/Makefile +1 -1
@@ -4,7 +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-rtas-common.o papr-vpd.o papr-indices.o \ - papr-platform-dump.o \ + papr-platform-dump.o papr-phy-attest.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-phy-attest.c new file +288 -0
288 lines not on this page · raw message
Signature · 1 line
2.43.5
Quoted 120 lines · Haren Myneni
Several APIs such as
rtas_get_indices(),rtas_get_dynamic_sensor(),rtas_set_dynamic_indicator(),rtas_platform_dump()andrtas_physical_attestation()provided by librtas library are implemented in user space using rtas syscall in combination with writable mappings of/dev/mem. But this implementation is not compatible with system lockdown which prohibits/dev/memaccess. The current kernel already provides char based driver interfaces for several RTAS calls such as VPD and system parameters to support lockdown feature.This patch series adds new char based drivers,
/dev/papr-indicesfor ibm,get-indices, ibm,get-dynamic-sensor-state and ibm,set-dynamic-indicator RTAS Calls./dev/papr-platform-dumpfor ibm,platform-dump and/dev/papr-physical-attestationfir ibm,physical-attestation. Providing the similar open/ioctl/read interfaces to the user space as in the case of VPD and system parameters.I have made changes to librtas library to use the new kernel interfaces if the corresponding device entry is available.
This patch series has the following patches:
powerpc/pseries: Define common functions for RTAS sequence calls
- For some of sequence based RTAS calls, the OS should not start another sequence with different input until the previous sequence is completed. So the sequence should be completed duringioctl()and expose the entire buffer duringread(). ibm,get-indices is sequence based RTAS function similar to ibm,get-vpd and we already have the corresponding implementation for VPD driver. So updatepapr_rtas_sequencestruct for RTAS call specific functions and move the top level sequence functions in to a separate file.powerpc/pseries: Define
papr_indices_io_blockfor papr-indices ioctls
-/dev/papr-indicesdriver supports ibm,get-indices, ibm,get-dynamic-sensor-state and ibm,set-dynamic-indicator RTAS Calls.papr-indices.hintroduces 3 different ioctls for these RTAS calls and the corresponding ioctl input buffer.powerpc/pseries: Add papr-indices char driver for ibm,get-indices
- Introduce/dev/papr-indiceschar based driver and add support for get-indices RTAS functionpowerpc/pseries: Add ibm,set-dynamic-indicator RTAS call support
- Update/dev/papr-indicesfor set-dynamic-indicator RTAS functionpowerpc/pseries: Add ibm,get-dynamic-sensor-state RTAS call support
- Update/dev/papr-indicesfor get-dynamic-sensor-state RTAS functionpowerpc/pseries: Add papr-platform-dump character driver for dump
retrieval
- Introduce/dev/papr-platform-dumpchar driver and adds support for ibm,platform-dump. Received suggestions from the previous post as a separate patch - Updated the patch with invalidating the dump using a separate ioctl.powerpc/pseries: Add a char driver for papr-physical-attestation RTAS
- Introduce/dev/papr-physical-attestationchar driver to provide kernel interface for ibm,physical-attestation RTAS function.Changelog:
v8:
- Fixed build warnings for the proper function parameter descriptions (vpd_sequence_begin(), few papr_rtas_*() functions, and etc) as reported by kernel test robot <[email protected]>v7:
- Pass the proper next value to the subsequent RTAS calls for the get-indices sequence RTAS.
(Vasireddy Sathvika found this bug).v6:
- Define the proper command ID forPAPR_PHY_ATTEST_IOC_HANDLEioctl
- Update ioctls description inioctl-number.rst.v5:
- Return with-EINPROGRESSinpapr_platform_dump_invalidate_ioctl()if the complete dump is not read (Suggested by Michal Suchánek).v4:
- Include patch "Add char driver for papr-physical-attestation RTAS" in this series. ibm,physical-attestation is sequence based RTAS call and the implementation is also similar to ibm,get-vpd and ibm,get-indices.v3:
-put_unused_fd()only afterget_unused_fd()successful for the failure case later ("Add papr-platform-dump character driver for dump retrieval" patch).v2:
- Added unlockrtas_ibm_set_dynamic_indicator_lockandrtas_ibm_get_dynamic_sensor_state_lockmutex for failure cases as reported by Dan Carpenter
- Fixed build warnings for the proper function parameter descriptions as reported by kernel test robot <[email protected]>Haren Myneni (7):
powerpc/pseries: Define common functions for RTAS sequence calls powerpc/pseries: Definepapr_indices_io_blockfor papr-indices ioctls powerpc/pseries: Add papr-indices char driver for ibm,get-indices powerpc/pseries: Add ibm,set-dynamic-indicator RTAS call support powerpc/pseries: Add ibm,get-dynamic-sensor-state RTAS call support powerpc/pseries: Add papr-platform-dump character driver for dump
retrieval
powerpc/pseries: Add a char driver for physical-attestation RTAS.../userspace-api/ioctl/ioctl-number.rst | 6 + arch/powerpc/include/asm/rtas.h | 4 + arch/powerpc/include/uapi/asm/papr-indices.h | 41 ++ .../uapi/asm/papr-physical-attestation.h | 31 ++ .../include/uapi/asm/papr-platform-dump.h | 15 + arch/powerpc/kernel/rtas.c | 8 +- arch/powerpc/platforms/pseries/Makefile | 3 +- arch/powerpc/platforms/pseries/papr-indices.c | 488 ++++++++++++++++++ .../platforms/pseries/papr-phy-attest.c | 288 +++++++++++ .../platforms/pseries/papr-platform-dump.c | 411 +++++++++++++++ .../platforms/pseries/papr-rtas-common.c | 310 +++++++++++ .../platforms/pseries/papr-rtas-common.h | 61 +++ arch/powerpc/platforms/pseries/papr-vpd.c | 351 ++----------- 13 files changed, 1705 insertions(+), 312 deletions(-)
Quoted 9 lines
create mode 100644
arch/powerpc/include/uapi/asm/papr-indices.hcreate mode 100644arch/powerpc/include/uapi/asm/papr-physical-attestation.hcreate mode 100644arch/powerpc/include/uapi/asm/papr-platform-dump.hcreate mode 100644arch/powerpc/platforms/pseries/papr-indices.ccreate mode 100644arch/powerpc/platforms/pseries/papr-phy-attest.ccreate mode 100644arch/powerpc/platforms/pseries/papr-platform-dump.ccreate mode 100644arch/powerpc/platforms/pseries/papr-rtas-common.ccreate mode 100644arch/powerpc/platforms/pseries/papr-rtas-common.h
Userspace tools that use these interfaces are displaying consistent results across old/new librtas and kernel combinations.
For this series:
Thanks,
Sathvika