mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-06-17 16:41:19 +01:00
a8be5e9478
Fix the following issues with misaligned vector load/store: a. Stack overflow: the mask[VLEN_MAX / 8] variable consumes 8K stack space, given VLEN_MAX=65536, overflowing the default-sized stack. There's no need to fetch the whole mask in one go, instead, make it on-demand. Use a 128-byte mask as local buffer to hold the sliding window of mask. For rvv load, this is allowed -- from the spec: "The destination vector register group for a masked vector instruction cannot overlap the source mask register (v0), unless the destination vector register is being written with a mask value (e.g., compares) or the scalar result of a reduction" We don't need to worry about the mask getting overwritten. b. Maintain the value of vstart upon abort (uptrap) to avoid duplicate work. After fault resolution, the instruction can restart from the faulting vstart. For Fault-Only-First loads, reset vstart to 0, as previously done so, to conform to spec. c. Explicitly set VS dirty in VSSTATUS with SET_VS_DIRTY() if faulting from V=1, and if any vector register, including vstart/vl/vtype, gets changed in the handler. It can add 1 unnecessary op to set VS dirty in M/SSTATUS (not VSSTATUS), where the HW already did, but for code simplicity, do it anyway. The overhead should be negligible. Signed-off-by: Bo Gan <ganboing@gmail.com> Tested-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260609060024.706-5-ganboing@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
47 lines
991 B
C
47 lines
991 B
C
/*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright (c) 2026 RISCstar Solutions.
|
|
*
|
|
* Authors:
|
|
* Dave Patel <dave.patel@riscstar.com>
|
|
*/
|
|
|
|
#ifndef __SBI_VECTOR_H__
|
|
#define __SBI_VECTOR_H__
|
|
|
|
#include <sbi/sbi_types.h>
|
|
|
|
struct sbi_vector_context {
|
|
unsigned long vcsr;
|
|
unsigned long vstart;
|
|
|
|
/* size depends on VLEN */
|
|
uint8_t vregs[];
|
|
};
|
|
|
|
#define SET_VS_DIRTY(regs) do { \
|
|
if (sbi_regs_from_virt(regs)) \
|
|
csr_set(CSR_VSSTATUS, MSTATUS_VS); \
|
|
regs->mstatus |= MSTATUS_VS; \
|
|
} while(0)
|
|
|
|
#ifdef OPENSBI_CC_SUPPORT_VECTOR
|
|
void sbi_vector_save(struct sbi_vector_context *dst);
|
|
void sbi_vector_restore(const struct sbi_vector_context *src);
|
|
size_t sbi_vector_context_size(void);
|
|
#else
|
|
static inline void sbi_vector_save(struct sbi_vector_context *dst)
|
|
{
|
|
}
|
|
static inline void sbi_vector_restore(const struct sbi_vector_context *src)
|
|
{
|
|
}
|
|
static inline size_t sbi_vector_context_size(void)
|
|
{
|
|
return 0;
|
|
}
|
|
#endif /* OPENSBI_CC_SUPPORT_VECTOR */
|
|
|
|
#endif /* __SBI_VECTOR_H__ */
|