From patchwork Wed May 15 15:08:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796959 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032346wra; Wed, 15 May 2024 08:09:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXbyMXbdKWOzpjlrdijAMgisKJ6t5soVrAGS5fg+CMKGxRBiWrjHjSUfPSH21BZczdYYT77P7PiUaiL5m/Xr2gg X-Google-Smtp-Source: AGHT+IFV+q/DUbb72O86ZKdEuAQAV/NFqkQcpACbuaUvXCb6AaA/+CaYfRhO5+0bft1UvKEX62Ti X-Received: by 2002:a05:6102:c4a:b0:47b:9fd6:233b with SMTP id ada2fe7eead31-48077eae71cmr15344662137.31.1715785789334; Wed, 15 May 2024 08:09:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785789; cv=none; d=google.com; s=arc-20160816; b=0yQpfI5G5BuLUsSoMia2qvRYPjl+qAceIOz7Yf5FFO2WXQ2qg+1GqKxZwqfsAA3d3B SbfMxwoTMUZ1POLVGTVHZYfha7RhlwtnyZ83oHsXUnqjctlW0UIebBIiukua8pBdhuzj eIYi9x3891jz516bTFai4xY/q7p78QuUIzCvTNwH++Ub6mxuOTyIItZyL83/cUu4XGGo uICiCQdTkbx2yfkAutXyRiSw0WRkhSUmwVXTkMl6k6d6ANGJVc4B6v7lt2XpP9mHSg/T /d/AKlveXYOAzD3ekgMbkMGSH546lhj9lT/B5qSMHAiOpkiJiQDGPRHPoHqdxrRZSN4N D8dg== 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=S+rFx22MXTz69amYQHY6y5MWkt0yWCTNmtE/0oYtP34=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=NJWUCOyTTy+Cp85J2r47egL2SGaql2XsuTNohs0NU0+KGSuuV1+Ckch7lzzn9B8jt7 P8nbjZLIgFAUjMxZnaExV/mLdHU4HDAkFUp88TUzHHfte7yyS2fH3xqDl+WTddXx9s7Y 3dSPJLjaCwqkJIXxG2HYmDm3TTstApyPkYfXTLZ7bY6L2LOHqvaBhp9VYbPMLw9z4po9 UBuQyPbs6R51r/aDEg38hUSJeYVozc7hy2gE6VghnORhS14uxyb4oLusluSQY8pbWNPu Ain1vnyiu+OZ0bxjDLhQLoIygtqdK+5g1FMyRbsjG1fQY6Nmuxw54ikAz1+ZgPgJ4tea Ra/w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=g9PK4EhN; 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 ada2fe7eead31-4806cbab808si2644174137.212.2024.05.15.08.09.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:09:49 -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=g9PK4EhN; 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 1s7GFg-0003z0-EM; Wed, 15 May 2024 11:09:08 -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 1s7GFd-0003xw-Ju for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:05 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFb-0003F7-7W for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:05 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-41ff5e3d86aso38691445e9.1 for ; Wed, 15 May 2024 08:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785740; x=1716390540; 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=S+rFx22MXTz69amYQHY6y5MWkt0yWCTNmtE/0oYtP34=; b=g9PK4EhNVC4s8/0zYyGytKl9KdBjgO37U0IwYMeejirbkm8T8xpXjRkzJ3/1AC6PqQ VHF9ZjYo9EiOzn3MfNR2yu+0mt9DebjnGvc7Uiepsmjk/I32lyg6x7aqBpjJoOfVX3ZD T3zceqLubvJS8cZYQDs1ufpT7khc7crkA9aNf5/SP2hoKSf8U5kV06TzO1Vd1fE1HfaI JBL3w3B9iC5H39q30LkFuaOMsAWEuo+L93/YE6mwwQeUzOefRviXMIvVxyMvDCwv2g1n ESRZeQZtL/R8dUNeeaAtU6UDrczyRD00CtwsHD60YqRhVc/Np++mxtznX/b/AQPhiMCX 1hQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785740; x=1716390540; 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=S+rFx22MXTz69amYQHY6y5MWkt0yWCTNmtE/0oYtP34=; b=BLfjL2WIOe8cdCf/2BYSNHaOFGV6wDBoBa+xO50n6WExQLjl0mu3+q9QxogkYvq3hn eseTOnmdqP5phTD4FWA5+6vvSKzDuDIexo0obi/x9KqcncoYPHbRNeGVPXkECqVW0KXB 8SoPBRETg13LnANXZSl8tPypnbgo09/QOFgKrXEQXzwjjgYmFUvJ66HTSUJ4r5R1Mtpv Cs/ukJwiCKMTOulGcYbNLwOZ1hF+31tl19jNMTwYEUhMWzw3AA1Q2U6qTc8C5vLwBFuu w/Ko3A59Tu81LunrauwdNpM+IlZReQoniTtsOhis+to/qpXc2DVZy78jVSCUJnBtYs6e vDIw== X-Gm-Message-State: AOJu0YwtFai5x+r0jdE3SafNu6Yy9iM6VW1oc79wpkF6zNR1w5KHn3nh IUn1Cajs2Jtt3aDq24mxsSMmRT8XE3R/mWiset8vpWanYGj37MWdi9NAEzEkbunAoo1doXZv36X Tb+8= X-Received: by 2002:a05:600c:ac1:b0:416:3f85:d49 with SMTP id 5b1f17b1804b1-41feaa42cd6mr136506845e9.18.1715785740043; Wed, 15 May 2024 08:09:00 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:59 -0700 (PDT) From: Richard Henderson 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 Message-Id: <20240515150837.259747-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515150837.259747-1-richard.henderson@linaro.org> References: <20240515150837.259747-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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 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)