xen/riscv: refactor decode_trap_cause()

Use array_access_nospec() to prevent guest speculation.

Avoid double access of trap_causes[cause].

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Oleksii Kurochko authored and Jan Beulich committed 2024-08-06 08:36:29 +02:00
1 parent cddbee85d0
commit 10eccbb821
1 file changed
+6 -3
+6 -3
View File
@@ -6,6 +6,7 @@
*/
#include <xen/lib.h>
#include <xen/nospec.h>
#include <xen/sched.h>
#include <asm/processor.h>
@@ -47,9 +48,11 @@ static const char *decode_trap_cause(unsigned long cause)
[CAUSE_STORE_GUEST_PAGE_FAULT] = "Guest Store/AMO Page Fault",
};
if ( cause < ARRAY_SIZE(trap_causes) && trap_causes[cause] )
return trap_causes[cause];
return "UNKNOWN";
const char *res = cause < ARRAY_SIZE(trap_causes)
? array_access_nospec(trap_causes, cause)
: NULL;
return res ?: "UNKNOWN";
}
static const char *decode_reserved_interrupt_cause(unsigned long irq_cause)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.