qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: danielhb413@gmail.com,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org,
	clg@kaod.org, Matheus Ferst <matheus.ferst@eldorado.org.br>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PULL 09/25] linux-user/ppc: Fix XER access in save/restore_user_regs
Date: Thu, 21 Oct 2021 15:20:11 +1100	[thread overview]
Message-ID: <20211021042027.345405-10-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20211021042027.345405-1-david@gibson.dropbear.id.au>

From: Matheus Ferst <matheus.ferst@eldorado.org.br>

We should use cpu_read_xer/cpu_write_xer to save/restore the complete
register since some of its bits are in other fields of CPUPPCState. A
test is added to prevent future regressions.

Fixes: da91a00f191f ("target-ppc: Split out SO, OV, CA fields from XER")
Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
Message-Id: <20211014223234.127012-2-matheus.ferst@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 linux-user/ppc/signal.c                     |  9 +++--
 tests/tcg/ppc64/Makefile.target             |  2 +
 tests/tcg/ppc64le/Makefile.target           |  2 +
 tests/tcg/ppc64le/signal_save_restore_xer.c | 42 +++++++++++++++++++++
 4 files changed, 52 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/ppc64le/signal_save_restore_xer.c

diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
index c37744c8fc..90a0369632 100644
--- a/linux-user/ppc/signal.c
+++ b/linux-user/ppc/signal.c
@@ -242,7 +242,7 @@ static void save_user_regs(CPUPPCState *env, struct target_mcontext *frame)
     __put_user(env->nip, &frame->mc_gregs[TARGET_PT_NIP]);
     __put_user(env->ctr, &frame->mc_gregs[TARGET_PT_CTR]);
     __put_user(env->lr, &frame->mc_gregs[TARGET_PT_LNK]);
-    __put_user(env->xer, &frame->mc_gregs[TARGET_PT_XER]);
+    __put_user(cpu_read_xer(env), &frame->mc_gregs[TARGET_PT_XER]);
 
     for (i = 0; i < ARRAY_SIZE(env->crf); i++) {
         ccr |= env->crf[i] << (32 - ((i + 1) * 4));
@@ -315,6 +315,7 @@ static void restore_user_regs(CPUPPCState *env,
 {
     target_ulong save_r2 = 0;
     target_ulong msr;
+    target_ulong xer;
     target_ulong ccr;
 
     int i;
@@ -330,9 +331,11 @@ static void restore_user_regs(CPUPPCState *env,
     __get_user(env->nip, &frame->mc_gregs[TARGET_PT_NIP]);
     __get_user(env->ctr, &frame->mc_gregs[TARGET_PT_CTR]);
     __get_user(env->lr, &frame->mc_gregs[TARGET_PT_LNK]);
-    __get_user(env->xer, &frame->mc_gregs[TARGET_PT_XER]);
-    __get_user(ccr, &frame->mc_gregs[TARGET_PT_CCR]);
 
+    __get_user(xer, &frame->mc_gregs[TARGET_PT_XER]);
+    cpu_write_xer(env, xer);
+
+    __get_user(ccr, &frame->mc_gregs[TARGET_PT_CCR]);
     for (i = 0; i < ARRAY_SIZE(env->crf); i++) {
         env->crf[i] = (ccr >> (32 - ((i + 1) * 4))) & 0xf;
     }
diff --git a/tests/tcg/ppc64/Makefile.target b/tests/tcg/ppc64/Makefile.target
index a6a4ddaeca..6ab7934fdf 100644
--- a/tests/tcg/ppc64/Makefile.target
+++ b/tests/tcg/ppc64/Makefile.target
@@ -23,4 +23,6 @@ run-plugin-byte_reverse-with-%:
 	$(call skip-test, "RUN of byte_reverse ($*)", "not built")
 endif
 
+PPC64_TESTS += signal_save_restore_xer
+
 TESTS += $(PPC64_TESTS)
diff --git a/tests/tcg/ppc64le/Makefile.target b/tests/tcg/ppc64le/Makefile.target
index c0c14ffbad..5e65b1590d 100644
--- a/tests/tcg/ppc64le/Makefile.target
+++ b/tests/tcg/ppc64le/Makefile.target
@@ -22,4 +22,6 @@ run-plugin-byte_reverse-with-%:
 	$(call skip-test, "RUN of byte_reverse ($*)", "not built")
 endif
 
+PPC64LE_TESTS += signal_save_restore_xer
+
 TESTS += $(PPC64LE_TESTS)
diff --git a/tests/tcg/ppc64le/signal_save_restore_xer.c b/tests/tcg/ppc64le/signal_save_restore_xer.c
new file mode 100644
index 0000000000..e4f8a07dd7
--- /dev/null
+++ b/tests/tcg/ppc64le/signal_save_restore_xer.c
@@ -0,0 +1,42 @@
+#include <assert.h>
+#include <stdint.h>
+#include <signal.h>
+#include <sys/user.h>
+
+#define XER_SO   (1 << 31)
+#define XER_OV   (1 << 30)
+#define XER_CA   (1 << 29)
+#define XER_OV32 (1 << 19)
+#define XER_CA32 (1 << 18)
+
+uint64_t saved;
+
+void sigill_handler(int sig, siginfo_t *si, void *ucontext)
+{
+    ucontext_t *uc = ucontext;
+    uc->uc_mcontext.regs->nip += 4;
+    saved = uc->uc_mcontext.regs->xer;
+    uc->uc_mcontext.regs->xer |= XER_OV | XER_OV32;
+}
+
+int main(void)
+{
+    uint64_t initial = XER_CA | XER_CA32, restored;
+    struct sigaction sa = {
+        .sa_sigaction = sigill_handler,
+        .sa_flags = SA_SIGINFO
+    };
+
+    sigaction(SIGILL, &sa, NULL);
+
+    asm("mtspr 1, %1\n\t"
+        ".long 0x0\n\t"
+        "mfspr %0, 1\n\t"
+        : "=r" (restored)
+        : "r" (initial));
+
+    assert(saved == initial);
+    assert(restored == (XER_OV | XER_OV32 | XER_CA | XER_CA32));
+
+    return 0;
+}
-- 
2.31.1



  parent reply	other threads:[~2021-10-21  4:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21  4:20 [PULL 00/25] ppc-for-6.2 queue 20211021 David Gibson
2021-10-21  4:20 ` [PULL 01/25] spapr/xive: Add source status helpers David Gibson
2021-10-21  4:20 ` [PULL 02/25] target/ppc: Use tcg_constant_i32() in gen_setb() David Gibson
2021-10-21  4:20 ` [PULL 03/25] target/ppc: Use tcg_constant_i64() in gen_brh() David Gibson
2021-10-21  4:20 ` [PULL 04/25] target/ppc: Fix the test raising the decrementer exception David Gibson
2021-10-21  4:20 ` [PULL 05/25] hw/ppc/spapr_softmmu: Reduce include list David Gibson
2021-10-21  4:20 ` [PULL 06/25] spapr/xive: Use xive_esb_rw() to trigger interrupts David Gibson
2021-10-21  4:20 ` [PULL 07/25] hw/ppc: Fix iothread locking in the 405 code David Gibson
2021-10-21  4:20 ` [PULL 08/25] tests/acceptance: Add tests for the ppc405 boards David Gibson
2021-10-21  4:20 ` David Gibson [this message]
2021-10-21  4:20 ` [PULL 10/25] target/ppc: Fix XER access in gdbstub David Gibson
2021-10-21  4:20 ` [PULL 11/25] linux-user: Fix XER access in ppc version of elf_core_copy_regs David Gibson
2021-10-21  4:20 ` [PULL 12/25] target/ppc: Fix XER access in monitor David Gibson
2021-10-21  4:20 ` [PULL 13/25] ppc/pegasos2: Restrict memory to 2 gigabytes David Gibson
2021-10-21  4:20 ` [PULL 14/25] ppc/pegasos2: Warn when using VOF but no kernel is specified David Gibson
2021-11-01 14:23   ` Peter Maydell
2021-10-21  4:20 ` [PULL 15/25] ppc/pegasos2: Implement get-time-of-day RTAS function with VOF David Gibson
2021-10-21  4:20 ` [PULL 16/25] ppc/pegasos2: Access MV64361 registers via their memory region David Gibson
2021-10-21  4:20 ` [PULL 17/25] ppc/pegasos2: Add constants for PCI config addresses David Gibson
2021-10-21  4:20 ` [PULL 18/25] ppc/pegasos2: Implement power-off RTAS function with VOF David Gibson
2021-10-21  4:20 ` [PULL 19/25] tests/acceptance: Add a test for the bamboo ppc board David Gibson
2021-10-21  4:20 ` [PULL 20/25] target/ppc: Filter mtmsr[d] input before setting MSR David Gibson
2021-10-21  4:20 ` [PULL 21/25] target/ppc: add MMCR0 PMCC bits to hflags David Gibson
2021-10-21  4:20 ` [PULL 22/25] target/ppc: add user read/write functions for MMCR0 David Gibson
2021-10-21  4:20 ` [PULL 23/25] target/ppc: add user read/write functions for MMCR2 David Gibson
2021-10-21  4:20 ` [PULL 24/25] target/ppc: adding user read/write functions for PMCs David Gibson
2021-10-21  4:20 ` [PULL 25/25] hw/ppc/ppc4xx_pci: Fix ppc4xx_pci_map_irq() for recent Linux kernels David Gibson
2021-10-21 16:53 ` [PULL 00/25] ppc-for-6.2 queue 20211021 Richard Henderson

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=20211021042027.345405-10-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=groug@kaod.org \
    --cc=matheus.ferst@eldorado.org.br \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).