* [PATCH 1/2] powerpc/rtasd: Use struct_size() to simplify log_rtas_len()
@ 2026-06-26 18:47 Thorsten Blum
2026-06-26 18:47 ` [PATCH 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo() Thorsten Blum
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-06-26 18:47 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Tyrel Datwyler, Mahesh Salgaonkar,
Haren Myneni
Cc: Thorsten Blum, linuxppc-dev, linux-kernel
Now that struct rtas_error_log uses a flexible array member for the
extended log buffer, use struct_size() to calculate the total RTAS error
log size and avoid using the hard-coded header size of 8 bytes.
Use min() to replace the open-coded implementation while at it.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/powerpc/kernel/rtasd.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/arch/powerpc/kernel/rtasd.c b/arch/powerpc/kernel/rtasd.c
index 6336ec9aedd0..fd40864bdb70 100644
--- a/arch/powerpc/kernel/rtasd.c
+++ b/arch/powerpc/kernel/rtasd.c
@@ -10,6 +10,7 @@
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/of.h>
+#include <linux/overflow.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
@@ -160,25 +161,17 @@ static void printk_log_rtas(char *buf, int len)
static int log_rtas_len(char * buf)
{
- int len;
+ size_t len;
struct rtas_error_log *err;
- uint32_t extended_log_length;
+ u32 extended_log_length;
- /* rtas fixed header */
- len = 8;
err = (struct rtas_error_log *)buf;
- extended_log_length = rtas_error_extended_log_length(err);
- if (rtas_error_extended(err) && extended_log_length) {
-
- /* extended header */
- len += extended_log_length;
- }
+ extended_log_length = rtas_error_extended(err) ? rtas_error_extended_log_length(err) : 0;
+ len = struct_size(err, buffer, extended_log_length);
if (rtas_error_log_max == 0)
rtas_error_log_max = rtas_get_error_log_max();
-
- if (len > rtas_error_log_max)
- len = rtas_error_log_max;
+ len = min(len, rtas_error_log_max);
return len;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo()
2026-06-26 18:47 [PATCH 1/2] powerpc/rtasd: Use struct_size() to simplify log_rtas_len() Thorsten Blum
@ 2026-06-26 18:47 ` Thorsten Blum
2026-06-26 19:25 ` Thorsten Blum
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-06-26 18:47 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP)
Cc: Thorsten Blum, linuxppc-dev, linux-kernel
Now that struct rtas_error_log uses a flexible array member for the
extended log buffer, use struct_size() to calculate the total RTAS error
log size and avoid using the hard-coded header size of 8 bytes.
Use memcpy_and_pad() instead of memset() and memcpy() while at it.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/powerpc/platforms/pseries/ras.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index adafd593d9d3..d54030fd2324 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -7,6 +7,7 @@
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/of.h>
+#include <linux/overflow.h>
#include <linux/fs.h>
#include <linux/reboot.h>
#include <linux/irq_work.h>
@@ -440,6 +441,8 @@ static __be64 *fwnmi_get_savep(struct pt_regs *regs)
static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
{
struct rtas_error_log *h;
+ u32 extended_log_length;
+ size_t len;
__be64 *savep;
savep = fwnmi_get_savep(regs);
@@ -449,17 +452,11 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */
h = (struct rtas_error_log *)&savep[1];
+ extended_log_length = rtas_error_extended(h) ? rtas_error_extended_log_length(h) : 0;
+ len = struct_size(h, buffer, extended_log_length);
+ len = min(len, RTAS_ERROR_LOG_MAX);
/* Use the per cpu buffer from paca to store rtas error log */
- memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
- if (!rtas_error_extended(h)) {
- memcpy(local_paca->mce_data_buf, h, sizeof(__u64));
- } else {
- int len, error_log_length;
-
- error_log_length = 8 + rtas_error_extended_log_length(h);
- len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
- memcpy(local_paca->mce_data_buf, h, len);
- }
+ memcpy_and_pad(local_paca->mce_data_buf, RTAS_ERROR_LOG_MAX, h, len, 0);
return (struct rtas_error_log *)local_paca->mce_data_buf;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo()
2026-06-26 18:47 ` [PATCH 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo() Thorsten Blum
@ 2026-06-26 19:25 ` Thorsten Blum
0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-06-26 19:25 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP)
Cc: linuxppc-dev, linux-kernel
On Fri, Jun 26, 2026 at 08:47:50PM +0200, Thorsten Blum wrote:
> Now that struct rtas_error_log uses a flexible array member for the
> extended log buffer, use struct_size() to calculate the total RTAS error
> log size and avoid using the hard-coded header size of 8 bytes.
>
> Use memcpy_and_pad() instead of memset() and memcpy() while at it.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> arch/powerpc/platforms/pseries/ras.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
> index adafd593d9d3..d54030fd2324 100644
> --- a/arch/powerpc/platforms/pseries/ras.c
> +++ b/arch/powerpc/platforms/pseries/ras.c
> @@ -7,6 +7,7 @@
> #include <linux/interrupt.h>
> #include <linux/irq.h>
> #include <linux/of.h>
> +#include <linux/overflow.h>
> #include <linux/fs.h>
> #include <linux/reboot.h>
> #include <linux/irq_work.h>
> @@ -440,6 +441,8 @@ static __be64 *fwnmi_get_savep(struct pt_regs *regs)
> static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
> {
> struct rtas_error_log *h;
> + u32 extended_log_length;
> + size_t len;
> __be64 *savep;
>
> savep = fwnmi_get_savep(regs);
> @@ -449,17 +452,11 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
> regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */
>
> h = (struct rtas_error_log *)&savep[1];
> + extended_log_length = rtas_error_extended(h) ? rtas_error_extended_log_length(h) : 0;
> + len = struct_size(h, buffer, extended_log_length);
> + len = min(len, RTAS_ERROR_LOG_MAX);
> /* Use the per cpu buffer from paca to store rtas error log */
> - memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX);
> - if (!rtas_error_extended(h)) {
> - memcpy(local_paca->mce_data_buf, h, sizeof(__u64));
> - } else {
> - int len, error_log_length;
> -
> - error_log_length = 8 + rtas_error_extended_log_length(h);
> - len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX);
> - memcpy(local_paca->mce_data_buf, h, len);
> - }
> + memcpy_and_pad(local_paca->mce_data_buf, RTAS_ERROR_LOG_MAX, h, len, 0);
Sashiko found that memcpy_and_pad() isn't safe here because
fwnmi_get_errinfo() is part of a real-mode path:
https://sashiko.dev/#/patchset/20260626184750.166642-3-thorsten.blum%40linux.dev
I'll send a v2 and keep memset() and memcpy() separate.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-26 19:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26 18:47 [PATCH 1/2] powerpc/rtasd: Use struct_size() to simplify log_rtas_len() Thorsten Blum
2026-06-26 18:47 ` [PATCH 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo() Thorsten Blum
2026-06-26 19:25 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox