lib: sbi_misaligned_ldst: Set GVA if not emulating
cover lib: sbi_misaligned_ldst: Set GVA if not emulating
Fix of a previous patch 1c4ce74f5128 ("lib: sbi: Set gva when creating sbi_trap_info"), correctly set hstatus.GVA for misaligned loads/stores that cannot be emulated at all.
See: https://lists.infradead.org/pipermail/opensbi/2022-August/003274.html
Vivian Wang (2):
lib: sbi_trap: Add helper to get GVA in sbi_trap_regs
lib: sbi_misaligned_ldst: Set GVA if not emulating
include/sbi/sbi_trap.h | 18 ++++++++++++++++++ lib/sbi/sbi_misaligned_ldst.c | 4 ++-- lib/sbi/sbi_trap.c | 14 +------------- 3 files changed, 21 insertions(+), 15 deletions(-)
Signature · 1 line
2.37.1
cover lib: sbi_misaligned_ldst: Set GVA if not emulating
Fix of a previous patch 1c4ce74f5128 ("lib: sbi: Set gva when creating sbi_trap_info"), correctly set hstatus.GVA for misaligned loads/stores that cannot be emulated at all.
See: https://lists.infradead.org/pipermail/opensbi/2022-August/003274.html
Vivian Wang (2):
lib: sbi_trap: Add helper to get GVA in sbi_trap_regs
lib: sbi_misaligned_ldst: Set GVA if not emulating
include/sbi/sbi_trap.h | 18 ++++++++++++++++++ lib/sbi/sbi_misaligned_ldst.c | 4 ++-- lib/sbi/sbi_trap.c | 14 +------------- 3 files changed, 21 insertions(+), 15 deletions(-)
Signature · 1 line
2.37.1
PATCH 1/2 lib: sbi_trap: Add helper to get GVA in sbi_trap_regs
In reply to Vivian WangThe GVA bit is in mstatus on RV64, and in mstatush in RV32. Refactor code handling this in sbi_trap_handler into a helper function to extract GVA from sbi_trap_regs, so that future code accessing GVA can be XLEN-agnostic.
--- include/sbi/sbi_trap.h | 18 ++++++++++++++++++ lib/sbi/sbi_trap.c | 14 +------------- 2 files changed, 19 insertions(+), 13 deletions(-)
include/sbi/sbi_trap.h +18 -0
@@ -10,6 +10,8 @@#ifndef __SBI_TRAP_H__#define __SBI_TRAP_H__ +#include <sbi/riscv_encoding.h> +/* clang-format off */ /** Index of zero member in sbi_trap_regs */
@@ -206,6 +208,22 @@ struct sbi_trap_info {unsigned long gva; }; +static inline unsigned long sbi_regs_gva (const struct sbi_trap_regs *regs) +{ +/* +* If the hypervisor extension is not implemented, mstatus[h].GVA is a +* WPRI field, which is guaranteed to read as zero. In addition, in this +* case we don't read mstatush and instead pretend it is zero, which +* handles privileged spec version < 1.12. +*/ + +#if __riscv_xlen ==32 +return (regs->mstatusH &MSTATUSH_GVA ) ?1 :0 ; +#else +return (regs->mstatus &MSTATUS_GVA ) ?1 :0 ; +#endif +} +int sbi_trap_redirect (struct sbi_trap_regs *regs,struct sbi_trap_info *trap);
lib/sbi/sbi_trap.c +1 -13
@@ -316,19 +316,7 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) trap.tval = mtval; trap.tval2 = mtval2; trap.tinst = mtinst; - -/* -* If the hypervisor extension is not implemented, -* mstatus[h].GVA is a WPRI field, which is guaranteed to read -* as zero. In addition, in this case we don't read mstatush and -* instead pretend it is zero, which handles privileged spec -* version < 1.12. -*/ -#if __riscv_xlen ==32 - trap.gva = (regs->mstatusH &MSTATUSH_GVA ) ?1 :0 ; -#else - trap.gva = (regs->mstatus &MSTATUS_GVA ) ?1 :0 ; -#endif + trap.gva =sbi_regs_gva (regs); rc =sbi_trap_redirect (regs, &trap);break ;
Signature · 1 line
2.37.1
PATCH 1/2 lib: sbi_trap: Add helper to get GVA in sbi_trap_regs
Quoted 11 lines · Vivian Wang
The GVA bit is in mstatus on RV64, and in mstatush in RV32. Refactor code handling this in
sbi_trap_handlerinto a helper function to extract GVA fromsbi_trap_regs, so that future code accessing GVA can be XLEN-agnostic.Signed-off-by Vivian Wang <[email protected]>--- include/sbi/sbi_trap.h | 18 ++++++++++++++++++ lib/sbi/sbi_trap.c | 14 +------------- 2 files changed, 19 insertions(+), 13 deletions(-)
Anup Patel
AppliedPATCH 1/2 lib: sbi_trap: Add helper to get GVA in sbi_trap_regs
In reply to Vivian WangQuoted 7 lines · Vivian Wang
The GVA bit is in mstatus on RV64, and in mstatush in RV32. Refactor code handling this in
sbi_trap_handlerinto a helper function to extract GVA fromsbi_trap_regs, so that future code accessing GVA can be XLEN-agnostic.Signed-off-by Vivian Wang <[email protected]>
Looks good to me.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 74 lines
--- include/sbi/sbi_trap.h | 18 ++++++++++++++++++ lib/sbi/sbi_trap.c | 14 +------------- 2 files changed, 19 insertions(+), 13 deletions(-)include/sbi/sbi_trap.h +18
-0@@ -10,6 +10,8 @@#ifndef __SBI_TRAP_H__#define __SBI_TRAP_H__ +#include <sbi/riscv_encoding.h> +/* clang-format off */ /** Index of zero member in sbi_trap_regs */ @@ -206,6 +208,22 @@ struct sbi_trap_info {unsigned long gva; }; +static inline unsigned long sbi_regs_gva (const struct sbi_trap_regs *regs) +{ +/* +* If the hypervisor extension is not implemented, mstatus[h].GVA is a +* WPRI field, which is guaranteed to read as zero. In addition, in this +* case we don't read mstatush and instead pretend it is zero, which +* handles privileged spec version < 1.12. +*/ + +#if __riscv_xlen ==32 +return (regs->mstatusH &MSTATUSH_GVA ) ?1 :0 ; +#else +return (regs->mstatus &MSTATUS_GVA ) ?1 :0 ; +#endif +} +int sbi_trap_redirect (struct sbi_trap_regs *regs,struct sbi_trap_info *trap);lib/sbi/sbi_trap.c +1
-14@@ -316,19 +316,7 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) trap.tval = mtval; trap.tval2 = mtval2; trap.tinst = mtinst; - -/* -* If the hypervisor extension is not implemented, -* mstatus[h].GVA is a WPRI field, which is guaranteed to read -* as zero. In addition, in this case we don't read mstatush and -* instead pretend it is zero, which handles privileged spec -* version < 1.12. -*/ -#if __riscv_xlen ==32 - trap.gva = (regs->mstatusH &MSTATUSH_GVA ) ?1 :0 ; -#else - trap.gva = (regs->mstatus &MSTATUS_GVA ) ?1 :0 ; -#endif + trap.gva =sbi_regs_gva (regs); rc =sbi_trap_redirect (regs, &trap);break ; --2.37.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 2/2 lib: sbi_misaligned_ldst: Set GVA if not emulating
In reply to Vivian WangIf a particular misaligned load or store cannot be emulated at all, for the redirected trap, trap.gva is set to 0, but it should be the same as mstatus[h].GVA of the original trap. Fix this so that if the trap is destined for HS-mode, hstatus.GVA is then set correctly.
--- lib/sbi/sbi_misaligned_ldst.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/sbi/sbi_misaligned_ldst.c +2 -2
@@ -129,7 +129,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; - uptrap.gva =0 ; + uptrap.gva =sbi_regs_gva (regs);return sbi_trap_redirect (regs, &uptrap); }
@@ -245,7 +245,7 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; - uptrap.gva =0 ; + uptrap.gva =sbi_regs_gva (regs);return sbi_trap_redirect (regs, &uptrap); }
Signature · 1 line
2.37.1
PATCH 2/2 lib: sbi_misaligned_ldst: Set GVA if not emulating
Quoted 35 lines · Vivian Wang
If a particular misaligned load or store cannot be emulated at all, for the redirected trap, trap.gva is set to 0, but it should be the same as mstatus[h].GVA of the original trap. Fix this so that if the trap is destined for HS-mode, hstatus.GVA is then set correctly.
Fixes 1c4ce74f5128 ("lib: sbi: Set gva when creating sbi_trap_info")Signed-off-by Vivian Wang <[email protected]>--- lib/sbi/sbi_misaligned_ldst.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/sbi/sbi_misaligned_ldst.c +2
-2@@ -129,7 +129,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; - uptrap.gva =0 ; + uptrap.gva =sbi_regs_gva (regs);return sbi_trap_redirect (regs, &uptrap); }@@ -245,7 +245,7 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; - uptrap.gva =0 ; + uptrap.gva =sbi_regs_gva (regs);return sbi_trap_redirect (regs, &uptrap); }Signature · 1 line
2.37.1
Anup Patel
AppliedPATCH 2/2 lib: sbi_misaligned_ldst: Set GVA if not emulating
In reply to Vivian WangQuoted 8 lines · Vivian Wang
If a particular misaligned load or store cannot be emulated at all, for the redirected trap, trap.gva is set to 0, but it should be the same as mstatus[h].GVA of the original trap. Fix this so that if the trap is destined for HS-mode, hstatus.GVA is then set correctly.
Fixes 1c4ce74f5128 ("lib: sbi: Set gva when creating sbi_trap_info")Signed-off-by Vivian Wang <[email protected]>
Looks good to me.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 34 lines
--- lib/sbi/sbi_misaligned_ldst.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/sbi/sbi_misaligned_ldst.c +2
-3@@ -129,7 +129,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; - uptrap.gva =0 ; + uptrap.gva =sbi_regs_gva (regs);return sbi_trap_redirect (regs, &uptrap); }@@ -245,7 +245,7 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; - uptrap.gva =0 ; + uptrap.gva =sbi_regs_gva (regs);return sbi_trap_redirect (regs, &uptrap); } --2.37.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi