Skip to contentSkip to conversation

target/ppc: Fix lxv/stxv MSR facility check

PATCH In review Nicholas Piggin 4 participants 5 messages Feb 13, 2024 – Sep 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc: Fix lxv/stxv MSR facility check

The move to decodetree flipped the inequality test for the VEC / VSX MSR facility check.

This caused application crashes under Linux, where these facility unavailable interrupts are used for lazy-switching of VEC/VSX register sets. Getting the incorrect interrupt would result in wrong registers being loaded, potentially overwriting live values and/or exposing stale ones.

Fixes 70426b5bb738 ("target/ppc: moved stxvx and lxvx from legacy to decodtree")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1769

---
 target/ppc/translate/vsx-impl.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/vsx-impl.c.inc +1 -1
index 6db87ab336..0266f09119 100644
@@ -2268,7 +2268,7 @@ static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ,
 
 static bool do_lstxv_D(DisasContext *ctx, arg_D *a, bool store, bool paired)
 {
-    if (paired || a->rt >= 32) {
+    if (paired || a->rt < 32) {
         REQUIRE_VSX(ctx);
     } else {
         REQUIRE_VECTOR(ctx);
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Nicholas Piggin

The move to decodetree flipped the inequality test for the VEC / VSX MSR facility check.

This caused application crashes under Linux, where these facility unavailable interrupts are used for lazy-switching of VEC/VSX register sets. Getting the incorrect interrupt would result in wrong registers being loaded, potentially overwriting live values and/or exposing stale ones.

Fixes 70426b5bb738 ("target/ppc: moved stxvx and lxvx from legacy to decodtree")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1769

---
  target/ppc/translate/vsx-impl.c.inc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/vsx-impl.c.inc +0 -0
index 6db87ab336..0266f09119 100644

target/ppc/translate/vsx-impl.c.inc static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ, · line 2271

Quoted 5 lines
target/ppc/translate/vsx-impl.c.inc +1 -1
@@ -2268,7 +2268,7 @@ static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ,
 
  static bool do_lstxv_D(DisasContext *ctx, arg_D *a, bool store, bool paired)
  {
-    if (paired || a->rt >= 32) {
+    if (paired || a->rt < 32) {

Thanks for catching this,

Quoted 3 lines
target/ppc/translate/vsx-impl.c.inc +0 -0
          REQUIRE_VSX(ctx);
      } else {
          REQUIRE_VECTOR(ctx);
Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Nicholas Piggin
Quoted 9 lines · Nicholas Piggin

The move to decodetree flipped the inequality test for the VEC / VSX MSR facility check.

This caused application crashes under Linux, where these facility unavailable interrupts are used for lazy-switching of VEC/VSX register sets. Getting the incorrect interrupt would result in wrong registers being loaded, potentially overwriting live values and/or exposing stale ones.

Quoted 6 lines
Fixes 70426b5bb738 ("target/ppc: moved stxvx and lxvx from legacy to decodtree")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1769

with a RHEL9 image.

Thanks,

C.

Quoted 17 lines
---
  target/ppc/translate/vsx-impl.c.inc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/vsx-impl.c.inc +1 -1
index 6db87ab336..0266f09119 100644
@@ -2268,7 +2268,7 @@ static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ,
 
  static bool do_lstxv_D(DisasContext *ctx, arg_D *a, bool store, bool paired)
  {
-    if (paired || a->rt >= 32) {
+    if (paired || a->rt < 32) {
          REQUIRE_VSX(ctx);
      } else {
          REQUIRE_VECTOR(ctx);
#3 lore raw
In reply to Nicholas Piggin
Quoted 24 lines · Nicholas Piggin

The move to decodetree flipped the inequality test for the VEC / VSX MSR facility check.

This caused application crashes under Linux, where these facility unavailable interrupts are used for lazy-switching of VEC/VSX register sets. Getting the incorrect interrupt would result in wrong registers being loaded, potentially overwriting live values and/or exposing stale ones.

Fixes 70426b5bb738 ("target/ppc: moved stxvx and lxvx from legacy to decodtree")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1769

---
 target/ppc/translate/vsx-impl.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/vsx-impl.c.inc +0 -0
index 6db87ab336..0266f09119 100644

target/ppc/translate/vsx-impl.c.inc static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ, · line 2274

Quoted 8 lines
target/ppc/translate/vsx-impl.c.inc +1 -1
@@ -2268,7 +2268,7 @@ static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ,
 
 static bool do_lstxv_D(DisasContext *ctx, arg_D *a, bool store, bool paired)
 {
-    if (paired || a->rt >= 32) {
+    if (paired || a->rt < 32) {
         REQUIRE_VSX(ctx);
     } else {
         REQUIRE_VECTOR(ctx);

What about the X-form down below?

static bool do_lstxv_X(DisasContext *ctx, arg_X *a, bool store, bool paired)

{
    if (paired || a->rt >= 32) {
        REQUIRE_VSX(ctx);
    } else {
        REQUIRE_VECTOR(ctx);
    }

    return do_lstxv(ctx, a->ra, cpu_gpr[a->rb], a->rt, store, paired);
}
#4 lore raw

Hi Fabiano,

Quoted 38 lines · Fabiano Rosas
Quoted 24 lines · Nicholas Piggin

The move to decodetree flipped the inequality test for the VEC / VSX MSR facility check.

This caused application crashes under Linux, where these facility unavailable interrupts are used for lazy-switching of VEC/VSX register sets. Getting the incorrect interrupt would result in wrong registers being loaded, potentially overwriting live values and/or exposing stale ones.

Fixes 70426b5bb738 ("target/ppc: moved stxvx and lxvx from legacy to decodtree")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1769

---
  target/ppc/translate/vsx-impl.c.inc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/vsx-impl.c.inc +0 -0
index 6db87ab336..0266f09119 100644

target/ppc/translate/vsx-impl.c.inc static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ, · line 2274

Quoted 8 lines
target/ppc/translate/vsx-impl.c.inc +1 -1
@@ -2268,7 +2268,7 @@ static bool do_lstxv(DisasContext *ctx, int ra, TCGv displ,
 
  static bool do_lstxv_D(DisasContext *ctx, arg_D *a, bool store, bool paired)
  {
-    if (paired || a->rt >= 32) {
+    if (paired || a->rt < 32) {
          REQUIRE_VSX(ctx);
      } else {
          REQUIRE_VECTOR(ctx);

What about the X-form down below?

static bool do_lstxv_X(DisasContext *ctx, arg_X *a, bool store, bool paired)

Quoted 9 lines
{
     if (paired || a->rt >= 32) {
         REQUIRE_VSX(ctx);
     } else {
         REQUIRE_VECTOR(ctx);
     }

     return do_lstxv(ctx, a->ra, cpu_gpr[a->rb], a->rt, store, paired);
}

Thanks for catching this. I have posted the fix here:
https://lore.kernel.org/qemu-devel/[email protected]/T/#u

regards,
Harsh