All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] host/include/ppc: fix little-endian AES on POWER8
@ 2026-11-29 15:17 Richard Patel via qemu development
  0 siblings, 0 replies; only message in thread
From: Richard Patel via qemu development @ 2026-11-29 15:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Daniel P. Berrangé, Richard Henderson, qemu-ppc, qemu-stable,
	Richard Patel

aes_accel_{ld,st} produced incorrect AES results on a little-
endian POWER8 host with little-endian guests.

Update the POWER8 code path to match POWER9.

Also prevent the register allocator from overlapping r and rev.

Fixes: 57357322e4bd ("host/include/ppc: Implement aes-round.h")
Signed-off-by: Richard Patel <ripatel@wii.dev>
---
 host/include/ppc64/host/crypto/aes-round.h | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/host/include/ppc64/host/crypto/aes-round.h b/host/include/ppc64/host/crypto/aes-round.h
index 8062d2a537..06db35a58c 100644
--- a/host/include/ppc64/host/crypto/aes-round.h
+++ b/host/include/ppc64/host/crypto/aes-round.h
@@ -34,14 +34,17 @@ static inline AESStateVec aes_accel_ld(const AESState *p, bool be)
         };
         asm("lvx %0, 0, %1\n\t"
             "vperm %0, %0, %0, %2"
-            : "=v"(r) : "r"(p), "v"(rev), "m"(*p));
+            : "=&v"(r) : "r"(p), "v"(rev), "m"(*p));
     } else {
 #ifdef __POWER9_VECTOR__
         asm("lxvb16x %x0, 0, %1" : "=v"(r) : "r"(p), "m"(*p));
 #else
-        asm("lxvd2x %x0, 0, %1\n\t"
-            "xxpermdi %x0, %x0, %x0, 2"
-            : "=v"(r) : "r"(p), "m"(*p));
+        AESStateVec rev = {
+            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+        };
+        asm("lvx %0, 0, %1\n\t"
+            "vperm %0, %0, %0, %2"
+            : "=&v"(r) : "r"(p), "v"(rev), "m"(*p));
 #endif
     }
     return r;
@@ -62,9 +65,12 @@ static void aes_accel_st(AESState *p, AESStateVec r, bool be)
 #ifdef __POWER9_VECTOR__
         asm("stxvb16x %x1, 0, %2" : "=m"(*p) : "v"(r), "r"(p));
 #else
-        asm("xxpermdi %x1, %x1, %x1, 2\n\t"
-            "stxvd2x %x1, 0, %2"
-            : "=m"(*p), "+v"(r) : "r"(p));
+        AESStateVec rev = {
+            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+        };
+        asm("vperm %1, %1, %1, %2\n\t"
+            "stvx %1, 0, %3"
+            : "=m"(*p), "+v"(r) : "v"(rev), "r"(p));
 #endif
     }
 }
-- 
2.56.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-29 15:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 15:17 [PATCH] host/include/ppc: fix little-endian AES on POWER8 Richard Patel via qemu development

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.