Message ID | 20250104204652.388720-6-haren@linux.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add character devices for indices and platform-dump RTAS | expand |
Hi Haren, kernel test robot noticed the following build warnings: https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Haren-Myneni/powerpc-pseries-Define-common-functions-for-RTAS-sequence-HCALLs/20250105-045010 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20250104204652.388720-6-haren%40linux.ibm.com patch subject: [PATCH 5/6] powerpc/pseries: Add ibm,get-dynamic-sensor-state RTAS call support config: powerpc64-randconfig-r071-20250108 (https://download.01.org/0day-ci/archive/20250109/202501090552.UzEfb4QU-lkp@intel.com/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 096551537b2a747a3387726ca618ceeb3950e9bc) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org> | Closes: https://lore.kernel.org/r/202501090552.UzEfb4QU-lkp@intel.com/ New smatch warnings: arch/powerpc/platforms/pseries/papr-indices.c:496 papr_dynamic_sensor_ioc_get() warn: inconsistent returns 'global &rtas_ibm_get_dynamic_sensor_state_lock'. Old smatch warnings: arch/powerpc/platforms/pseries/papr-indices.c:438 papr_dynamic_indicator_ioc_set() warn: inconsistent returns 'global &rtas_ibm_set_dynamic_indicator_lock'. vim +496 arch/powerpc/platforms/pseries/papr-indices.c e44fb25ad9fa03 Haren Myneni 2025-01-04 452 static long papr_dynamic_sensor_ioc_get(struct papr_indices_io_block __user *ubuf) e44fb25ad9fa03 Haren Myneni 2025-01-04 453 { e44fb25ad9fa03 Haren Myneni 2025-01-04 454 struct papr_indices_io_block kbuf; e44fb25ad9fa03 Haren Myneni 2025-01-04 455 struct rtas_work_area *work_area; e44fb25ad9fa03 Haren Myneni 2025-01-04 456 s32 fwrc, token, ret; e44fb25ad9fa03 Haren Myneni 2025-01-04 457 u32 rets; e44fb25ad9fa03 Haren Myneni 2025-01-04 458 e44fb25ad9fa03 Haren Myneni 2025-01-04 459 token = rtas_function_token(RTAS_FN_IBM_GET_DYNAMIC_SENSOR_STATE); e44fb25ad9fa03 Haren Myneni 2025-01-04 460 if (token == RTAS_UNKNOWN_SERVICE) e44fb25ad9fa03 Haren Myneni 2025-01-04 461 return -ENOENT; e44fb25ad9fa03 Haren Myneni 2025-01-04 462 e44fb25ad9fa03 Haren Myneni 2025-01-04 463 mutex_lock(&rtas_ibm_get_dynamic_sensor_state_lock); e44fb25ad9fa03 Haren Myneni 2025-01-04 464 work_area = papr_dynamic_indice_buf_from_user(ubuf, &kbuf); e44fb25ad9fa03 Haren Myneni 2025-01-04 465 if (IS_ERR(work_area)) e44fb25ad9fa03 Haren Myneni 2025-01-04 466 return PTR_ERR(work_area); Add an unlock, same as with the _set() function. e44fb25ad9fa03 Haren Myneni 2025-01-04 467 e44fb25ad9fa03 Haren Myneni 2025-01-04 468 do { e44fb25ad9fa03 Haren Myneni 2025-01-04 469 fwrc = rtas_call(token, 2, 2, &rets, e44fb25ad9fa03 Haren Myneni 2025-01-04 470 kbuf.dynamic_param.token, e44fb25ad9fa03 Haren Myneni 2025-01-04 471 rtas_work_area_phys(work_area)); e44fb25ad9fa03 Haren Myneni 2025-01-04 472 } while (rtas_busy_delay(fwrc)); e44fb25ad9fa03 Haren Myneni 2025-01-04 473 e44fb25ad9fa03 Haren Myneni 2025-01-04 474 rtas_work_area_free(work_area); e44fb25ad9fa03 Haren Myneni 2025-01-04 475 mutex_unlock(&rtas_ibm_get_dynamic_sensor_state_lock); e44fb25ad9fa03 Haren Myneni 2025-01-04 476 e44fb25ad9fa03 Haren Myneni 2025-01-04 477 switch (fwrc) { e44fb25ad9fa03 Haren Myneni 2025-01-04 478 case RTAS_IBM_DYNAMIC_INDICE_SUCCESS: e44fb25ad9fa03 Haren Myneni 2025-01-04 479 if (put_user(rets, &ubuf->dynamic_param.state)) e44fb25ad9fa03 Haren Myneni 2025-01-04 480 ret = -EFAULT; e44fb25ad9fa03 Haren Myneni 2025-01-04 481 else e44fb25ad9fa03 Haren Myneni 2025-01-04 482 ret = 0; e44fb25ad9fa03 Haren Myneni 2025-01-04 483 break; e44fb25ad9fa03 Haren Myneni 2025-01-04 484 case RTAS_IBM_DYNAMIC_INDICE_NO_INDICATOR: /* No such indicator */ e44fb25ad9fa03 Haren Myneni 2025-01-04 485 ret = -EOPNOTSUPP; e44fb25ad9fa03 Haren Myneni 2025-01-04 486 break; e44fb25ad9fa03 Haren Myneni 2025-01-04 487 default: e44fb25ad9fa03 Haren Myneni 2025-01-04 488 pr_err("unexpected ibm,get-dynamic-sensor result %d\n", e44fb25ad9fa03 Haren Myneni 2025-01-04 489 fwrc); e44fb25ad9fa03 Haren Myneni 2025-01-04 490 fallthrough; e44fb25ad9fa03 Haren Myneni 2025-01-04 491 case RTAS_IBM_DYNAMIC_INDICE_HW_ERROR: /* Hardware/platform error */ e44fb25ad9fa03 Haren Myneni 2025-01-04 492 ret = -EIO; e44fb25ad9fa03 Haren Myneni 2025-01-04 493 break; e44fb25ad9fa03 Haren Myneni 2025-01-04 494 } e44fb25ad9fa03 Haren Myneni 2025-01-04 495 e44fb25ad9fa03 Haren Myneni 2025-01-04 @496 return ret; e44fb25ad9fa03 Haren Myneni 2025-01-04 497 }
diff --git a/arch/powerpc/include/asm/rtas.h b/arch/powerpc/include/asm/rtas.h index 2da52f59e4c6..fcd822f0e1d7 100644 --- a/arch/powerpc/include/asm/rtas.h +++ b/arch/powerpc/include/asm/rtas.h @@ -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 diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c index 88fa416730af..a4848e7f248e 100644 --- a/arch/powerpc/kernel/rtas.c +++ b/arch/powerpc/kernel/rtas.c @@ -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] = { diff --git a/arch/powerpc/platforms/pseries/papr-indices.c b/arch/powerpc/platforms/pseries/papr-indices.c index 30dfd928d192..079e01d0427c 100644 --- a/arch/powerpc/platforms/pseries/papr-indices.c +++ b/arch/powerpc/platforms/pseries/papr-indices.c @@ -438,6 +438,64 @@ static long papr_dynamic_indicator_ioc_set(struct papr_indices_io_block __user * return ret; } +/** + * papr_dynamic_sensor_ioc_get - ibm,get-dynamic-sensor-state RTAS Call + * PAPR 2.13 7.3.19 + * + * @ubuf: Input parameters to RTAS call such as sensor token + * Copies the state in user space buffer. + * + * + * Returns success or -errno. + */ + +static long papr_dynamic_sensor_ioc_get(struct papr_indices_io_block __user *ubuf) +{ + struct papr_indices_io_block kbuf; + struct rtas_work_area *work_area; + s32 fwrc, token, ret; + u32 rets; + + token = rtas_function_token(RTAS_FN_IBM_GET_DYNAMIC_SENSOR_STATE); + if (token == RTAS_UNKNOWN_SERVICE) + return -ENOENT; + + mutex_lock(&rtas_ibm_get_dynamic_sensor_state_lock); + work_area = papr_dynamic_indice_buf_from_user(ubuf, &kbuf); + if (IS_ERR(work_area)) + return PTR_ERR(work_area); + + do { + fwrc = rtas_call(token, 2, 2, &rets, + kbuf.dynamic_param.token, + rtas_work_area_phys(work_area)); + } while (rtas_busy_delay(fwrc)); + + rtas_work_area_free(work_area); + mutex_unlock(&rtas_ibm_get_dynamic_sensor_state_lock); + + switch (fwrc) { + case RTAS_IBM_DYNAMIC_INDICE_SUCCESS: + if (put_user(rets, &ubuf->dynamic_param.state)) + ret = -EFAULT; + else + ret = 0; + break; + case RTAS_IBM_DYNAMIC_INDICE_NO_INDICATOR: /* No such indicator */ + ret = -EOPNOTSUPP; + break; + default: + pr_err("unexpected ibm,get-dynamic-sensor result %d\n", + fwrc); + fallthrough; + case RTAS_IBM_DYNAMIC_INDICE_HW_ERROR: /* Hardware/platform error */ + ret = -EIO; + break; + } + + return ret; +} + /* * Top-level ioctl handler for /dev/papr-indices. */ @@ -451,6 +509,9 @@ static long papr_indices_dev_ioctl(struct file *filp, unsigned int ioctl, case PAPR_INDICES_IOC_GET: ret = papr_indices_create_handle(argp); break; + case PAPR_DYNAMIC_SENSOR_IOC_GET: + ret = papr_dynamic_sensor_ioc_get(argp); + break; case PAPR_DYNAMIC_INDICATOR_IOC_SET: if (filp->f_mode & FMODE_WRITE) ret = papr_dynamic_indicator_ioc_set(argp); @@ -483,6 +544,9 @@ static __init int papr_indices_init(void) if (!rtas_function_implemented(RTAS_FN_IBM_SET_DYNAMIC_INDICATOR)) return -ENODEV; + if (!rtas_function_implemented(RTAS_FN_IBM_GET_DYNAMIC_SENSOR_STATE)) + return -ENODEV; + return misc_register(&papr_indices_dev); } machine_device_initcall(pseries, papr_indices_init);
The 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 Signed-off-by: Haren Myneni <haren@linux.ibm.com> --- arch/powerpc/include/asm/rtas.h | 1 + arch/powerpc/kernel/rtas.c | 2 +- arch/powerpc/platforms/pseries/papr-indices.c | 64 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-)