All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Patel via qemu development <qemu-devel@nongnu.org>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	qemu-ppc@nongnu.org, qemu-stable@nongnu.org,
	"Richard Patel" <ripatel@wii.dev>
Subject: [PATCH] host/include/ppc: fix little-endian AES on POWER8
Date: Sun, 29 Nov 2026 09:17:38 -0600	[thread overview]
Message-ID: <20261129151738.53319-1-ripatel@wii.dev> (raw)

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



                 reply	other threads:[~2026-11-29 15:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129151738.53319-1-ripatel@wii.dev \
    --to=qemu-devel@nongnu.org \
    --cc=berrange@redhat.com \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=ripatel@wii.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.