* [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest
@ 2026-05-08 14:35 Thorsten Blum
2026-05-08 14:35 ` [PATCH RESEND 2/2] riscv/purgatory: add asm/purgatory.h Thorsten Blum
2026-05-08 18:41 ` [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Eric Biggers
0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-08 14:35 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Ard Biesheuvel, Eric Biggers
Cc: Thorsten Blum, linux-riscv, linux-kernel
Change the function's return type from int to bool and return the result
of memcmp() directly to simplify the code. While at it, cast ->start to
'const u8 *' to better match the expected type.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/riscv/purgatory/purgatory.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
index bbd5cfa4d741..15c72dafa3d8 100644
--- a/arch/riscv/purgatory/purgatory.c
+++ b/arch/riscv/purgatory/purgatory.c
@@ -17,7 +17,7 @@ u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(".kexec-purgatory");
-static int verify_sha256_digest(void)
+static bool verify_sha256_digest(void)
{
struct kexec_sha_region *ptr, *end;
struct sha256_ctx sctx;
@@ -26,11 +26,10 @@ static int verify_sha256_digest(void)
sha256_init(&sctx);
end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
for (ptr = purgatory_sha_regions; ptr < end; ptr++)
- sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
+ sha256_update(&sctx, (const u8 *)(ptr->start), ptr->len);
sha256_final(&sctx, digest);
- if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0)
- return 1;
- return 0;
+
+ return memcmp(digest, purgatory_sha256_digest, sizeof(digest));
}
/* workaround for a warning with -Wmissing-prototypes */
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH RESEND 2/2] riscv/purgatory: add asm/purgatory.h
2026-05-08 14:35 [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Thorsten Blum
@ 2026-05-08 14:35 ` Thorsten Blum
2026-05-08 18:41 ` [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Eric Biggers
1 sibling, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-08 14:35 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Ard Biesheuvel, Eric Biggers
Cc: Thorsten Blum, linux-riscv, linux-kernel
Add arch/riscv/include/asm/purgatory.h and provide the purgatory()
prototype via the architecture header, mirroring the x86 layout.
Remove the workaround from arch/riscv/purgatory/purgatory.c.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/riscv/include/asm/purgatory.h | 11 +++++++++++
arch/riscv/purgatory/purgatory.c | 5 +----
2 files changed, 12 insertions(+), 4 deletions(-)
create mode 100644 arch/riscv/include/asm/purgatory.h
diff --git a/arch/riscv/include/asm/purgatory.h b/arch/riscv/include/asm/purgatory.h
new file mode 100644
index 000000000000..a63687be2517
--- /dev/null
+++ b/arch/riscv/include/asm/purgatory.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_RISCV_PURGATORY_H
+#define _ASM_RISCV_PURGATORY_H
+
+#ifndef __ASSEMBLER__
+#include <linux/purgatory.h>
+
+extern void purgatory(void);
+#endif /* __ASSEMBLER__ */
+
+#endif /* _ASM_RISCV_PURGATORY_H */
diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
index 15c72dafa3d8..6a6e6f611a56 100644
--- a/arch/riscv/purgatory/purgatory.c
+++ b/arch/riscv/purgatory/purgatory.c
@@ -8,9 +8,9 @@
*
*/
-#include <linux/purgatory.h>
#include <linux/kernel.h>
#include <linux/string.h>
+#include <asm/purgatory.h>
#include <asm/string.h>
u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
@@ -32,9 +32,6 @@ static bool verify_sha256_digest(void)
return memcmp(digest, purgatory_sha256_digest, sizeof(digest));
}
-/* workaround for a warning with -Wmissing-prototypes */
-void purgatory(void);
-
void purgatory(void)
{
if (verify_sha256_digest())
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest
2026-05-08 14:35 [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Thorsten Blum
2026-05-08 14:35 ` [PATCH RESEND 2/2] riscv/purgatory: add asm/purgatory.h Thorsten Blum
@ 2026-05-08 18:41 ` Eric Biggers
2026-05-08 20:20 ` Thorsten Blum
1 sibling, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2026-05-08 18:41 UTC (permalink / raw)
To: Thorsten Blum
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Ard Biesheuvel, linux-riscv, linux-kernel
On Fri, May 08, 2026 at 04:35:44PM +0200, Thorsten Blum wrote:
> Change the function's return type from int to bool and return the result
> of memcmp() directly to simplify the code. While at it, cast ->start to
> 'const u8 *' to better match the expected type.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> arch/riscv/purgatory/purgatory.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
> index bbd5cfa4d741..15c72dafa3d8 100644
> --- a/arch/riscv/purgatory/purgatory.c
> +++ b/arch/riscv/purgatory/purgatory.c
> @@ -17,7 +17,7 @@ u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
>
> struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(".kexec-purgatory");
>
> -static int verify_sha256_digest(void)
> +static bool verify_sha256_digest(void)
> {
> struct kexec_sha_region *ptr, *end;
> struct sha256_ctx sctx;
> @@ -26,11 +26,10 @@ static int verify_sha256_digest(void)
> sha256_init(&sctx);
> end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
> for (ptr = purgatory_sha_regions; ptr < end; ptr++)
> - sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
> + sha256_update(&sctx, (const u8 *)(ptr->start), ptr->len);
> sha256_final(&sctx, digest);
> - if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0)
> - return 1;
> - return 0;
> +
> + return memcmp(digest, purgatory_sha256_digest, sizeof(digest));
> }
So true on failure and false on success? Might make sense to flip that.
- Eric
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest
2026-05-08 18:41 ` [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Eric Biggers
@ 2026-05-08 20:20 ` Thorsten Blum
0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-05-08 20:20 UTC (permalink / raw)
To: Eric Biggers
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Ard Biesheuvel, linux-riscv, linux-kernel
On Fri, May 08, 2026 at 06:41:37PM +0000, Eric Biggers wrote:
> On Fri, May 08, 2026 at 04:35:44PM +0200, Thorsten Blum wrote:
> > Change the function's return type from int to bool and return the result
> > of memcmp() directly to simplify the code. While at it, cast ->start to
> > 'const u8 *' to better match the expected type.
> >
> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > ---
> > arch/riscv/purgatory/purgatory.c | 9 ++++-----
> > 1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
> > index bbd5cfa4d741..15c72dafa3d8 100644
> > --- a/arch/riscv/purgatory/purgatory.c
> > +++ b/arch/riscv/purgatory/purgatory.c
> > @@ -17,7 +17,7 @@ u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
> >
> > struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(".kexec-purgatory");
> >
> > -static int verify_sha256_digest(void)
> > +static bool verify_sha256_digest(void)
> > {
> > struct kexec_sha_region *ptr, *end;
> > struct sha256_ctx sctx;
> > @@ -26,11 +26,10 @@ static int verify_sha256_digest(void)
> > sha256_init(&sctx);
> > end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
> > for (ptr = purgatory_sha_regions; ptr < end; ptr++)
> > - sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
> > + sha256_update(&sctx, (const u8 *)(ptr->start), ptr->len);
> > sha256_final(&sctx, digest);
> > - if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0)
> > - return 1;
> > - return 0;
> > +
> > + return memcmp(digest, purgatory_sha256_digest, sizeof(digest));
> > }
>
> So true on failure and false on success? Might make sense to flip that.
Ahem yes, that should obviously be flipped. I'll send a v2. Thanks!
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-08 20:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08 14:35 [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Thorsten Blum
2026-05-08 14:35 ` [PATCH RESEND 2/2] riscv/purgatory: add asm/purgatory.h Thorsten Blum
2026-05-08 18:41 ` [PATCH RESEND 1/2] riscv/purgatory: return bool from verify_sha256_digest Eric Biggers
2026-05-08 20:20 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox