forked from Mirrors/opensbi
		
	lib: Handle page/access fault caused by unpriv load/store
The unpriv load/store instruction from M-mode can cause page/access fault to M-mode if S-mode page table did not have mappings OR it did not have PMP access permission. To tackle this, we redirect trap back to S-mode if unpriv load/store instruction traps in M-mode. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
		@@ -12,11 +12,23 @@
 | 
			
		||||
 | 
			
		||||
#include <sbi/sbi_types.h>
 | 
			
		||||
 | 
			
		||||
#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type) \
 | 
			
		||||
	type load_##type(const type *addr);
 | 
			
		||||
struct sbi_scratch;
 | 
			
		||||
 | 
			
		||||
#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type) \
 | 
			
		||||
	void store_##type(type *addr, type val);
 | 
			
		||||
struct unpriv_trap {
 | 
			
		||||
	unsigned long ilen;
 | 
			
		||||
	unsigned long cause;
 | 
			
		||||
	unsigned long tval;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define DECLARE_UNPRIVILEGED_LOAD_FUNCTION(type)       \
 | 
			
		||||
	type load_##type(const type *addr,             \
 | 
			
		||||
			 struct sbi_scratch *scratch,  \
 | 
			
		||||
			 struct unpriv_trap *trap);
 | 
			
		||||
 | 
			
		||||
#define DECLARE_UNPRIVILEGED_STORE_FUNCTION(type)      \
 | 
			
		||||
	void store_##type(type *addr, type val,        \
 | 
			
		||||
			  struct sbi_scratch *scratch, \
 | 
			
		||||
			  struct unpriv_trap *trap);
 | 
			
		||||
 | 
			
		||||
DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u8)
 | 
			
		||||
DECLARE_UNPRIVILEGED_LOAD_FUNCTION(u16)
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@
 | 
			
		||||
#define SBI_EILL	-10
 | 
			
		||||
#define SBI_ENOSPC	-11
 | 
			
		||||
#define SBI_ENOMEM	-12
 | 
			
		||||
#define SBI_ETRAP	-13
 | 
			
		||||
 | 
			
		||||
/* clang-format on */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@
 | 
			
		||||
#ifndef __SBI_IPI_H__
 | 
			
		||||
#define __SBI_IPI_H__
 | 
			
		||||
 | 
			
		||||
#include <sbi/riscv_unpriv.h>
 | 
			
		||||
#include <sbi/sbi_types.h>
 | 
			
		||||
 | 
			
		||||
/* clang-format off */
 | 
			
		||||
@@ -28,8 +29,8 @@ struct sbi_ipi_data {
 | 
			
		||||
	unsigned long ipi_type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int sbi_ipi_send_many(struct sbi_scratch *scratch, ulong *pmask, u32 event,
 | 
			
		||||
		      void *data);
 | 
			
		||||
int sbi_ipi_send_many(struct sbi_scratch *scratch, struct unpriv_trap *uptrap,
 | 
			
		||||
		      ulong *pmask, u32 event, void *data);
 | 
			
		||||
 | 
			
		||||
void sbi_ipi_clear_smode(struct sbi_scratch *scratch);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user