From patchwork Mon May 27 00:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 799203 Delivered-To: patch@linaro.org Received: by 2002:a5d:6a47:0:b0:354:fb4b:99cd with SMTP id t7csp1658536wrw; Sun, 26 May 2024 17:55:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXEL1YYgFDtI+PYKOg46BCOy5eNoHRrHhCSCNGXi0GVkRvJIIji/VypU6UenwbSPGLEi6zialw9t9d6rV/GGNLz X-Google-Smtp-Source: AGHT+IHzdCkQCMdX3AIFenR15Fw8jF1JcnnMpOTjRKrAbf3LeCHBj3xzJB8kuS0ObIIRn/Tn+Rz3 X-Received: by 2002:a5d:6909:0:b0:354:fc1a:2396 with SMTP id ffacd0b85a97d-35526c6a202mr5597855f8f.30.1716771313230; Sun, 26 May 2024 17:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716771313; cv=none; d=google.com; s=arc-20160816; b=sjYPx7EtIURb3hie/biOOHuky0naqnggLL61X6r0NFYY0wIl89ZYtTGkO0140bkRWY UxLWciyIfYXZgx3iPuype11q3U3QI/SFOrXJs9a3DlTNZqVCSX8+tSXZiapdMu7rad60 wuTizNXx+TBMgifrfKoQ8/f0iDap9xJOR7sMxGAIRZTLVO7IgXQfhuiOhuGxOY0gamL8 dRNu3fXBCHLwIAhyvSp/MRZTylHzIYY0s6VBMe+2MrKMoQGIXh1+6AblFA/ER4Ajxnep a0vHbecTPb0+9TvYkGCp3dw/3lqNH5Z2G7VESBp6/j7mIQQLN0BMXXafyf8GNQdl07kS 7zcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AI7rkjN7jKkGsGrZZgvFmIRDSXmmUvcz3SoDTGqstLM=; fh=OTkfrEnbNDInppsfj4HB8z6V33zCj7LOct256XBfW6M=; b=W0b05WJiEAXxk+7Q6I3/2GnkSiSPRgexUYbeKelDsfyegCr8hV+ChMwEd/3Oube9MN pBcycDPWo1cD2D2+ny6EpHAkHIhS0oFBXLGggSIqjJ3yqqr3OhaksFLG+HRVekAhKk+6 SAhIYY8zqdLtmEOnYA0Wxq5wpaUxQHXDTt+m7vzCGYP3LqAdqmKDzJJuM5vMR1cGIHxE L5zTZCE3YX2CdXZ8LAIoV7Q5nTQFFvy1HJADSL3Icm5wq8fLjuMAo6X+t0o69aclIQbf nIjBY/U8b8iNUnhityB7NToi6g6NLUXrQ0PjMMf+/esOKv6Cu2FPOFJ57o+ZZrVHOpgr kZWw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nRCqcQgL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ffacd0b85a97d-3557a1c57e4si3440783f8f.308.2024.05.26.17.55.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 May 2024 17:55:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nRCqcQgL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBOZU-0007O3-BE; Sun, 26 May 2024 20:50:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBOZO-0007J4-W0 for qemu-devel@nongnu.org; Sun, 26 May 2024 20:50:35 -0400 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBOZJ-0003hy-0S for qemu-devel@nongnu.org; Sun, 26 May 2024 20:50:34 -0400 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-24c9f91242dso1435287fac.2 for ; Sun, 26 May 2024 17:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716771023; x=1717375823; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AI7rkjN7jKkGsGrZZgvFmIRDSXmmUvcz3SoDTGqstLM=; b=nRCqcQgLlgM56jfQb+Lu9xkcfy5ZxlvFXE/oumjmU+oDZjg1l7/d61zHuzrbYGwvqw 8ud5O7E8q/3YtvpQgPlFAqO4u07ggr5ZQAOJvEbtjVOCCT8uZhlifJVx3Y2IUvOECO0A ykscQ0qX6AOcoo27/c4P94O7w4g8vVtbFfpxfdiAWHSCMJaL410OzI8SRLTfainaSQHO A71Y5KMgav8r4ld5A1SbVFhvzY8y2WdXg6fwu4P+tktR5fvvyts+75l8RBO1PoravpWH o9julVcIg7eOitcrEgdd2D/NXm+zSve/w90FD63MCq01PiNBOWJMS2vRNGbMr2/lhVLb LdWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716771023; x=1717375823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AI7rkjN7jKkGsGrZZgvFmIRDSXmmUvcz3SoDTGqstLM=; b=gD4A3A4Y/fnSfnkR7357v/acyu9prtkEvJpz6Ocxr0OHcgyjbbPZrR0s9H6zMpKTVQ LHfU9gMPTztexoWf/g5iREWjMbx9QPOELrdwTKSlUvzzziM7yhQdb82vbRvvT/693w65 fyHuyDwU+dsqB2iZtnbUppmQUPLp6FVfyl3mx/0bKwU9GHr3kBjGFqWNGHSAv6l4WC+K xmoIhnEb69+q+WM7ao5LB5JZSmBmcs1XoA6F37He0Y8b9af1TgBSrNaY5d9x3lMUqbgr 048gcIuxdHwxb32OJpaX8tlmpcd+Q2dOl+RRpt352zFiSHh5oNxAarXjbbAkOz6/7l5+ ft+g== X-Gm-Message-State: AOJu0Yxo1+4yP4CPh8/6hgfM4JBKH4GzDTZan1643Hb1UiWu1rKGJQe4 k3jZn4FA7X51exkCuQtKj85tz0j+I/c62+2Ll9wh26k6FTcN/pAb7fZfAnaQrdcPiYBiNTD1HP8 g X-Received: by 2002:a05:6870:718b:b0:24f:e0d2:7ee7 with SMTP id 586e51a60fabf-24fe0d27f78mr4301383fac.15.1716771023741; Sun, 26 May 2024 17:50:23 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fd6d7598sm3942958b3a.220.2024.05.26.17.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 17:50:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Paolo Bonzini Subject: [PULL 26/28] target/i386: Pass host pointer and size to cpu_x86_{fsave, frstor} Date: Sun, 26 May 2024 17:49:59 -0700 Message-Id: <20240527005001.642825-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240527005001.642825-1-richard.henderson@linaro.org> References: <20240527005001.642825-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2a; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x2a.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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 Signed-off-by: Richard Henderson --- 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 fdd318963a..f6020e0b6b 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2266,11 +2266,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 ab760db5ea..dfbb811b56 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)