forked from OP-TEE/optee_os
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: riscv: Support Privileged Access Never by CSR status.SUM bit
The SUM (Supervisor User Memory access) bit modifies the privilege with which S-mode loads and stores the user virtual memory. When SUM bit is 0, S-mode accesses to pages whose U bit of corresponding PTE is set will fault. When SUM bit is 1, these accesses are permitted. When CFG_PAN is disabled in RISC-V architecture, the status.SUM bit is initialized as 1 by default. Therefore all accesses to user pages will succeed. When CFG_PAN is enabled, the status.SUM bit is initialized as 0, and only set to 1 when kernel needs to access user pages. Signed-off-by: Alvin Chang <alvinga@andestech.com> Tested-by: Marouene Boubakri <marouene.boubakri@nxp.com>
- Loading branch information
Showing
4 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2023 Andes Technology Corporation | ||
* Copyright (c) 2023, Amazon.com Inc. or its affiliates. All rights Reserved. | ||
*/ | ||
|
||
#ifndef __KERNEL_USER_ACCESS_ARCH_H | ||
#define __KERNEL_USER_ACCESS_ARCH_H | ||
|
||
#include <riscv.h> | ||
|
||
#ifdef CFG_PAN | ||
/* Enter a section where user mode access is temporarily enabled. */ | ||
static inline void enter_user_access(void) {} | ||
static inline void enter_user_access(void) | ||
{ | ||
set_csr(CSR_XSTATUS, CSR_XSTATUS_SUM); | ||
} | ||
|
||
/* Exit from the section where user mode access was temporarily enabled. */ | ||
static inline void exit_user_access(void) | ||
{ | ||
clear_csr(CSR_XSTATUS, CSR_XSTATUS_SUM); | ||
} | ||
#else | ||
static inline void enter_user_access(void) {} | ||
static inline void exit_user_access(void) {} | ||
#endif /* CFG_PAN */ | ||
|
||
#endif /* __KERNEL_USER_ACCESS_ARCH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters