qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, laurent@vivier.eu
Subject: [PATCH v3 26/28] target/i386: Pass host pointer and size to cpu_x86_{fsave, frstor}
Date: Wed, 15 May 2024 17:08:35 +0200	[thread overview]
Message-ID: <20240515150837.259747-27-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240515150837.259747-1-richard.henderson@linaro.org>

We have already validated the memory region in the course of
validating the signal frame.  No need to do it again within
the helper function.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/i386/cpu.h            | 10 ++++++----
 linux-user/i386/signal.c     |  4 ++--
 target/i386/tcg/fpu_helper.c | 26 ++++++++++++++++----------
 3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 4b3bffeb9c..2897faccb9 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2236,11 +2236,13 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
 /* used for debug or cpu save/restore */
 
 /* cpu-exec.c */
-/* the following helpers are only usable in user mode simulation as
-   they can trigger unexpected exceptions */
+/*
+ * The following helpers are only usable in user mode simulation.
+ * The host pointers should come from lock_user().
+ */
 void cpu_x86_load_seg(CPUX86State *s, X86Seg seg_reg, int selector);
-void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32);
-void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32);
+void cpu_x86_fsave(CPUX86State *s, void *host, size_t len);
+void cpu_x86_frstor(CPUX86State *s, void *host, size_t len);
 void cpu_x86_fxsave(CPUX86State *s, target_ulong ptr);
 void cpu_x86_fxrstor(CPUX86State *s, target_ulong ptr);
 void cpu_x86_xsave(CPUX86State *s, target_ulong ptr, uint64_t rbfm);
diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
index 2f93342ade..816e8ab2a9 100644
--- a/linux-user/i386/signal.c
+++ b/linux-user/i386/signal.c
@@ -373,7 +373,7 @@ static void setup_sigcontext(CPUX86State *env,
     __put_user(env->regs[R_ESP], &sc->esp_at_signal);
     __put_user(env->segs[R_SS].selector, (uint32_t *)&sc->ss);
 
-    cpu_x86_fsave(env, fpstate_addr, 1);
+    cpu_x86_fsave(env, fpstate, sizeof(*fpstate));
     fpstate->status = fpstate->swd;
     magic = (fpkind == FPSTATE_FSAVE ? 0 : 0xffff);
     __put_user(magic, &fpstate->magic);
@@ -702,7 +702,7 @@ static bool frstor_sigcontext(CPUX86State *env, FPStateKind fpkind,
      * the merge within ENV by loading XSTATE/FXSTATE first, then
      * overriding with the FSTATE afterward.
      */
-    cpu_x86_frstor(env, fpstate_addr, 1);
+    cpu_x86_frstor(env, fpstate, sizeof(*fpstate));
     return true;
 }
 #endif
diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c
index 1ac61c5d7d..05db16a152 100644
--- a/target/i386/tcg/fpu_helper.c
+++ b/target/i386/tcg/fpu_helper.c
@@ -3017,22 +3017,28 @@ void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm)
 }
 
 #if defined(CONFIG_USER_ONLY)
-void cpu_x86_fsave(CPUX86State *env, target_ulong ptr, int data32)
+void cpu_x86_fsave(CPUX86State *env, void *host, size_t len)
 {
-    int size = (14 << data32) + 80;
-    X86Access ac;
+    X86Access ac = {
+        .haddr1 = host,
+        .size = 4 * 7 + 8 * 10,
+        .env = env,
+    };
 
-    access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, 0);
-    do_fsave(&ac, ptr, data32);
+    assert(ac.size <= len);
+    do_fsave(&ac, 0, true);
 }
 
-void cpu_x86_frstor(CPUX86State *env, target_ulong ptr, int data32)
+void cpu_x86_frstor(CPUX86State *env, void *host, size_t len)
 {
-    int size = (14 << data32) + 80;
-    X86Access ac;
+    X86Access ac = {
+        .haddr1 = host,
+        .size = 4 * 7 + 8 * 10,
+        .env = env,
+    };
 
-    access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, 0);
-    do_frstor(&ac, ptr, data32);
+    assert(ac.size <= len);
+    do_frstor(&ac, 0, true);
 }
 
 void cpu_x86_fxsave(CPUX86State *env, target_ulong ptr)
-- 
2.34.1



  parent reply	other threads:[~2024-05-15 15:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15 15:08 [PATCH v3 00/28] linux-user/i386: Properly align signal frame Richard Henderson
2024-05-15 15:08 ` [PATCH v3 01/28] target/i386: Add tcg/access.[ch] Richard Henderson
2024-05-15 15:08 ` [PATCH v3 02/28] target/i386: Convert do_fldt, do_fstt to X86Access Richard Henderson
2024-05-15 15:08 ` [PATCH v3 03/28] target/i386: Convert helper_{fbld, fbst}_ST0 " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 04/28] target/i386: Convert do_fldenv " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 05/28] target/i386: Convert do_fstenv " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 06/28] target/i386: Convert do_fsave, do_frstor " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 07/28] target/i386: Convert do_xsave_{fpu, mxcr, sse} " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 08/28] target/i386: Convert do_xrstor_{fpu, " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 09/28] tagret/i386: Convert do_fxsave, do_fxrstor " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 10/28] target/i386: Convert do_xsave_* " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 11/28] target/i386: Convert do_xrstor_* " Richard Henderson
2024-05-15 15:08 ` [PATCH v3 12/28] target/i386: Split out do_xsave_chk Richard Henderson
2024-05-15 15:08 ` [PATCH v3 13/28] target/i386: Add rbfm argument to cpu_x86_{xsave, xrstor} Richard Henderson
2024-05-15 15:08 ` [PATCH v3 14/28] target/i386: Add {hw, sw}_reserved to X86LegacyXSaveArea Richard Henderson
2024-05-15 15:08 ` [PATCH v3 15/28] linux-user/i386: Drop xfeatures_size from sigcontext arithmetic Richard Henderson
2024-05-15 15:08 ` [PATCH v3 16/28] linux-user/i386: Remove xfeatures from target_fpstate_fxsave Richard Henderson
2024-05-15 15:08 ` [PATCH v3 17/28] linux-user/i386: Replace target_fpstate_fxsave with X86LegacyXSaveArea Richard Henderson
2024-05-15 15:08 ` [PATCH v3 18/28] linux-user/i386: Split out struct target_fregs_state Richard Henderson
2024-05-15 15:08 ` [PATCH v3 19/28] linux-user/i386: Fix -mregparm=3 for signal delivery Richard Henderson
2024-05-15 15:08 ` [PATCH v3 20/28] linux-user/i386: Return boolean success from restore_sigcontext Richard Henderson
2024-05-15 15:08 ` [PATCH v3 21/28] linux-user/i386: Return boolean success from xrstor_sigcontext Richard Henderson
2024-05-15 15:08 ` [PATCH v3 22/28] linux-user/i386: Fix allocation and alignment of fp state Richard Henderson
2024-05-15 15:08 ` [PATCH v3 23/28] target/i386: Honor xfeatures in xrstor_sigcontext Richard Henderson
2024-05-15 15:08 ` [PATCH v3 24/28] target/i386: Convert do_xsave to X86Access Richard Henderson
2024-05-15 15:08 ` [PATCH v3 25/28] target/i386: Convert do_xrstor " Richard Henderson
2024-05-15 15:08 ` Richard Henderson [this message]
2024-05-15 15:08 ` [PATCH v3 27/28] target/i386: Pass host pointer and size to cpu_x86_{fxsave, fxrstor} Richard Henderson
2024-05-15 15:08 ` [PATCH v3 28/28] target/i386: Pass host pointer and size to cpu_x86_{xsave, xrstor} Richard Henderson
2024-06-05 19:06 ` [PATCH v3 00/28] linux-user/i386: Properly align signal frame Philippe Mathieu-Daudé
2024-06-05 19:16   ` Pierrick Bouvier
2024-06-05 19:38     ` 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=20240515150837.259747-27-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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).