On 16/11/26 10:13, Philippe Mathieu-Daudé wrote:
On 13/11/26 22:45, Kirill A. Korinsky wrote:
From: "Kirill A. Korinsky" <[email protected]>

The xuseg and xsseg checks only tested UX and SX respectively; kernel
and supervisor accesses must instead use the mode bit that applies to
the current execution mode.

Allow supervisor and kernel mode to use xuseg when SX or KX is set, and
allow kernel mode to use xsseg when KX is set.

Signed-off-by: Kirill A. Korinsky <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>

Now that I found the Octeon CN71XX manual I couldn't verify this claim
so I'm putting this patch on hold (along with my R-b).

(I had the description reworded as:)

  target/mips: Fix MIPS64 xuseg/xsseg access checks per mode

  xuseg and xsseg checked only UX and SX, regardless of mode. Check
  the extension bit that matches the current mode: UX for user, SX for
  supervisor, KX for kernel (xuseg), and SX or KX as above for xsseg.

  Commit 480e79aedd32 fixed xkphys but left these two segments
  unchanged.

---
  target/mips/system/physaddr.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/target/mips/system/physaddr.c b/target/mips/system/ physaddr.c
index 523197f020..b9f44c27bc 100644
--- a/target/mips/system/physaddr.c
+++ b/target/mips/system/physaddr.c
@@ -145,7 +145,9 @@ int get_physical_address(const CPUMIPSState *env, hwaddr *physical,
  #if defined(TARGET_MIPS64)
      } else if (address < 0x4000000000000000ULL) {
          /* xuseg */
-        if (UX && address <= (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {
+        if (((user_mode && UX) || (supervisor_mode && SX) ||
+             (kernel_mode && KX)) &&
+            address <= (0x3FFFFFFFFFFFFFFFULL & env->SEGMask)) {
              ret = env->tlb->map_address(env, physical, prot,
                                          real_address, access_type);
          } else {
@@ -153,8 +155,8 @@ int get_physical_address(const CPUMIPSState *env, hwaddr *physical,
          }
      } else if (address < 0x8000000000000000ULL) {
          /* xsseg */
-        if ((supervisor_mode || kernel_mode) &&
-            SX && address <= (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {
+        if (((supervisor_mode && SX) || (kernel_mode && KX)) &&
+            address <= (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) {
              ret = env->tlb->map_address(env, physical, prot,
                                          real_address, access_type);
          } else {




Reply via email to