From patchwork Wed May 15 15:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796962 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032488wra; Wed, 15 May 2024 08:10:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWgvYoXKNy0MEasCnITDm06sJOxMaBzGFFhunXmvnModijXgtFg9xRjXsbdk04NUvvGu3GR41/EMhOYEBmwkowi X-Google-Smtp-Source: AGHT+IHPXukC3FHVZEAfxM9YosNvjcyvUuDt74LozbXJ9fjpWZLtsrXcvgP+4rFPqM908ZUyemEp X-Received: by 2002:aca:1304:0:b0:3c9:92f3:d528 with SMTP id 5614622812f47-3c997036e1emr16415256b6e.12.1715785800287; Wed, 15 May 2024 08:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785800; cv=none; d=google.com; s=arc-20160816; b=xfStXmHhE0E69ZlH0Xnsh5gY7DZQ0uCqo0tDdmdE6qO3j6RZDi3RZCQeLomDe0DMna RkcZ+aAcz19jun4rvps3x6uZMyO76F7Exv7hi/OX6PL9dmusFxuhRpnGaK+zXaDrmJAD H4FAiHOtOxn0PYHWLfthYFlM00e2w1S582B9FZjikzugaf0Cr94x6t6tMZWdDzi4E8aq o7mr+tYEcY6ESkHCGE313B41eXuUu5zw/Sctcul+fLyLqq6629yJIIAMa0cr2/PIiClb iX6zj7jIj71Xv0jFbwFckDl9rKXY/TKab45DKPn4lEKReBWmfCKxIQLaG7tcrRcnJDrw TunA== 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=XQrV4UMaEBl22gT4Xij+bzAgjXuhBjByp/7UaStu/qs=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=r4DrFb36c/4KO6E6j3FQrTtycrbFJpLHsstTy+/H07VIKaiEtazuFkA6ZnMc+Z5+4B TvtT/VAMZ4pYECT/pjqEJjh8kZmXTLgKDnXJVO65foSU2UcZnTIQ7aVHF6DDUptpMrqB xFGRoo4d1uUW6pwTKpTYSRkhgwUzicjNHg2X6h+ALnH/3Jn1+CVx3UDehsOAd+PcAXwO XPHCjr4M5hDokl2PpPrvea0YSYEUjX5jyl2xamp4A+vs4yrlvSHVSw30vcW41mIVDCE3 +NxE6ZPYoVIkpHaZpSu/ePaNZkBhKaeAal3n/wKgFOSy4LVgbtWf9AXyOBMmD39/XdTH rHZw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZFmizw7O; 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=pass (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 a1e0cc1a2514c-7fb7a796326si1440806241.106.2024.05.15.08.10.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:10:00 -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=pass header.i=@linaro.org header.s=google header.b=ZFmizw7O; 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=pass (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 1s7GFK-0003pa-Ns; Wed, 15 May 2024 11:08:46 -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 1s7GFH-0003pK-1z for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:43 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFF-0002ky-15 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:42 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-420104e5336so26608195e9.1 for ; Wed, 15 May 2024 08:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785719; x=1716390519; 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=XQrV4UMaEBl22gT4Xij+bzAgjXuhBjByp/7UaStu/qs=; b=ZFmizw7OMv9hDgaBabULRIXzk/iIjsbaG53ool99QqzU5m7nifO5GhFbzXotPWFhUm UICbofBiNogcFhZ/xp3LWOASCJ7eugMjRxiPzMUDvW475eUMjVoHFY18N68PGcIQHIU1 cXmw7lAS0WL8ky61chd4txx7AraFSp6Y1zEveF8fQ8XBIlMS8cDRfAHXp5M6KbIMJpbG 6nwkjeKiUYUVNThDDtyOwM6t9Qcc7f0CimoG9crSXDznO/xaReR+Xe+vtPFyidHLdPaZ qFes7GdDaMX5WO5GOLP+XWZeqqqMBfLg3zOg/+YkwV9cGzo0CGYzdKs9r+2vShuon+ma spzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785719; x=1716390519; 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=XQrV4UMaEBl22gT4Xij+bzAgjXuhBjByp/7UaStu/qs=; b=FLpq6sZmBMs054KbKbOb2Bs+V/FcnwHfbOs6/AJ/WvLDDJNsvSk+LvHJ0T477ao0RF Ci+eGD9KJw1yQo654znue5fF3oaXeF6wqxqIGovUTjZKMr2n/xd16dp8OTHVl1bZ4hZk Yi20gIIWZzHY2iwfuPId7SjQyf4uRfeU4U0jDV59XTqskygepbc8fTnywBt2awUOr1Ao QZTIdeEHzkAwArHRGQOehlJtejfzVF/TMxSIvf9FRa4ybVookLVQGGwpf+IPWPRwntRb ENiV0xAPUSfbs2inJY0H64Ey/VLoKnxCfGassal3TanuXSNEtInfoQHHWywec4zPIbh+ r7hA== X-Gm-Message-State: AOJu0YxgNdQLRj+AafMjaVgg9hJ9fBlBzuhqmDMZdyry6EraRwvmRdDb cjCWtpxBUFwzOmCXhefteLSkiXPjJ0FOvoGTztBFHWEo3cDeLnpDzCClcig2OCcrAByQgoh8N1I vg2g= X-Received: by 2002:a05:600c:1909:b0:418:9d4a:1ba5 with SMTP id 5b1f17b1804b1-41fbca35c5emr172985375e9.6.1715785719449; Wed, 15 May 2024 08:08:39 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 01/28] target/i386: Add tcg/access.[ch] Date: Wed, 15 May 2024 17:08:10 +0200 Message-Id: <20240515150837.259747-2-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::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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 Provide a method to amortize page lookup across large blocks. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/access.h | 40 +++++++++ target/i386/tcg/access.c | 169 ++++++++++++++++++++++++++++++++++++ target/i386/tcg/meson.build | 1 + 3 files changed, 210 insertions(+) create mode 100644 target/i386/tcg/access.h create mode 100644 target/i386/tcg/access.c diff --git a/target/i386/tcg/access.h b/target/i386/tcg/access.h new file mode 100644 index 0000000000..d70808a3a3 --- /dev/null +++ b/target/i386/tcg/access.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Access guest memory in blocks. */ + +#ifndef X86_TCG_ACCESS_H +#define X86_TCG_ACCESS_H + +/* An access covers at most sizeof(X86XSaveArea), at most 2 pages. */ +typedef struct X86Access { + target_ulong vaddr; + void *haddr1; + void *haddr2; + uint16_t size; + uint16_t size1; + /* + * If we can't access the host page directly, we'll have to do I/O access + * via ld/st helpers. These are internal details, so we store the rest + * to do the access here instead of passing it around in the helpers. + */ + int mmu_idx; + CPUX86State *env; + uintptr_t ra; +} X86Access; + +void access_prepare_mmu(X86Access *ret, CPUX86State *env, + vaddr vaddr, unsigned size, + MMUAccessType type, int mmu_idx, uintptr_t ra); +void access_prepare(X86Access *ret, CPUX86State *env, vaddr vaddr, + unsigned size, MMUAccessType type, uintptr_t ra); + +uint8_t access_ldb(X86Access *ac, vaddr addr); +uint16_t access_ldw(X86Access *ac, vaddr addr); +uint32_t access_ldl(X86Access *ac, vaddr addr); +uint64_t access_ldq(X86Access *ac, vaddr addr); + +void access_stb(X86Access *ac, vaddr addr, uint8_t val); +void access_stw(X86Access *ac, vaddr addr, uint16_t val); +void access_stl(X86Access *ac, vaddr addr, uint32_t val); +void access_stq(X86Access *ac, vaddr addr, uint64_t val); + +#endif diff --git a/target/i386/tcg/access.c b/target/i386/tcg/access.c new file mode 100644 index 0000000000..56a1181ea5 --- /dev/null +++ b/target/i386/tcg/access.c @@ -0,0 +1,169 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Access guest memory in blocks. */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +#include "access.h" + + +void access_prepare_mmu(X86Access *ret, CPUX86State *env, + vaddr vaddr, unsigned size, + MMUAccessType type, int mmu_idx, uintptr_t ra) +{ + int size1, size2; + void *haddr1, *haddr2; + + assert(size > 0 && size <= TARGET_PAGE_SIZE); + + size1 = MIN(size, -(vaddr | TARGET_PAGE_MASK)), + size2 = size - size1; + + memset(ret, 0, sizeof(*ret)); + ret->vaddr = vaddr; + ret->size = size; + ret->size1 = size1; + ret->mmu_idx = mmu_idx; + ret->env = env; + ret->ra = ra; + + haddr1 = probe_access(env, vaddr, size1, type, mmu_idx, ra); + ret->haddr1 = haddr1; + + if (unlikely(size2)) { + haddr2 = probe_access(env, vaddr + size1, size2, type, mmu_idx, ra); + if (haddr2 == haddr1 + size1) { + ret->size1 = size; + } else { +#ifdef CONFIG_USER_ONLY + g_assert_not_reached(); +#else + ret->haddr2 = haddr2; +#endif + } + } +} + +void access_prepare(X86Access *ret, CPUX86State *env, vaddr vaddr, + unsigned size, MMUAccessType type, uintptr_t ra) +{ + int mmu_idx = cpu_mmu_index(env_cpu(env), false); + access_prepare_mmu(ret, env, vaddr, size, type, mmu_idx, ra); +} + +static void *access_ptr(X86Access *ac, vaddr addr, unsigned len) +{ + vaddr offset = addr - ac->vaddr; + + assert(addr >= ac->vaddr); + +#ifdef CONFIG_USER_ONLY + assert(offset <= ac->size1 - len); + return ac->haddr1 + offset; +#else + if (likely(offset <= ac->size1 - len)) { + return ac->haddr1 + offset; + } + assert(offset <= ac->size - len); + /* + * If the address is not naturally aligned, it might span both pages. + * Only return ac->haddr2 if the area is entirely within the second page, + * otherwise fall back to slow accesses. + */ + if (likely(offset >= ac->size1)) { + return ac->haddr2 + (offset - ac->size1); + } + return NULL; +#endif +} + +#ifdef CONFIG_USER_ONLY +# define test_ptr(p) true +#else +# define test_ptr(p) likely(p) +#endif + +uint8_t access_ldb(X86Access *ac, vaddr addr) +{ + void *p = access_ptr(ac, addr, sizeof(uint8_t)); + + if (test_ptr(p)) { + return ldub_p(p); + } + return cpu_ldub_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra); +} + +uint16_t access_ldw(X86Access *ac, vaddr addr) +{ + void *p = access_ptr(ac, addr, sizeof(uint16_t)); + + if (test_ptr(p)) { + return lduw_le_p(p); + } + return cpu_lduw_le_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra); +} + +uint32_t access_ldl(X86Access *ac, vaddr addr) +{ + void *p = access_ptr(ac, addr, sizeof(uint32_t)); + + if (test_ptr(p)) { + return ldl_le_p(p); + } + return cpu_ldl_le_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra); +} + +uint64_t access_ldq(X86Access *ac, vaddr addr) +{ + void *p = access_ptr(ac, addr, sizeof(uint64_t)); + + if (test_ptr(p)) { + return ldq_le_p(p); + } + return cpu_ldq_le_mmuidx_ra(ac->env, addr, ac->mmu_idx, ac->ra); +} + +void access_stb(X86Access *ac, vaddr addr, uint8_t val) +{ + void *p = access_ptr(ac, addr, sizeof(uint8_t)); + + if (test_ptr(p)) { + stb_p(p, val); + } else { + cpu_stb_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra); + } +} + +void access_stw(X86Access *ac, vaddr addr, uint16_t val) +{ + void *p = access_ptr(ac, addr, sizeof(uint16_t)); + + if (test_ptr(p)) { + stw_le_p(p, val); + } else { + cpu_stw_le_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra); + } +} + +void access_stl(X86Access *ac, vaddr addr, uint32_t val) +{ + void *p = access_ptr(ac, addr, sizeof(uint32_t)); + + if (test_ptr(p)) { + stl_le_p(p, val); + } else { + cpu_stl_le_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra); + } +} + +void access_stq(X86Access *ac, vaddr addr, uint64_t val) +{ + void *p = access_ptr(ac, addr, sizeof(uint64_t)); + + if (test_ptr(p)) { + stq_le_p(p, val); + } else { + cpu_stq_le_mmuidx_ra(ac->env, addr, val, ac->mmu_idx, ac->ra); + } +} diff --git a/target/i386/tcg/meson.build b/target/i386/tcg/meson.build index f9110e890c..1105b35d92 100644 --- a/target/i386/tcg/meson.build +++ b/target/i386/tcg/meson.build @@ -1,4 +1,5 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files( + 'access.c', 'bpt_helper.c', 'cc_helper.c', 'excp_helper.c', From patchwork Wed May 15 15:08:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796984 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034600wra; Wed, 15 May 2024 08:13:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXsRLjhXKGlF6nZMvJpsWbTlowqCghuwwZLR4RCY/qPpgkblf/XNHLM9a6ARa9/NlsDpXb1ov6VxwLY2b0bbH3L X-Google-Smtp-Source: AGHT+IFo1fkKrpyqn9P2j39LW7onB9NG261ShpmUxZ3IiLSfdFDe4fJ4bcuhEoe1LMDNfVSnddyT X-Received: by 2002:aca:2203:0:b0:3c9:65a1:8d70 with SMTP id 5614622812f47-3c9970d00b6mr15463414b6e.57.1715786000329; Wed, 15 May 2024 08:13:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715786000; cv=none; d=google.com; s=arc-20160816; b=MZ+6limyJJ25iJl12uj3qr3feB99ai5ziZ7AtQk5/+PRbC0XsgwzE0fXYhC1zKYZA6 fdny6b/T+QURDELAnNOUZnfJ8Cy96OSHoVqZAlnh0O8eTFkTZM7HRMgSTkvDNcEtJozw zOv9fHIfWgvYjhffW1OTrW0sMi4tC47YMHdtdQavrdELFHaitU45nV8FcxAruFD1qqGl stzY8RMqdT5PWdU/Gzj61J8hRv7ktGg0lWkyFv1lbE/Y3A2cAGtFscEQ56JS4G3EcZU6 fscSOuwLWuFtM4pMCMzbtXzg708T3DoM6CQrOHretipKGZILm7uAPGEN9v97jYFs1C2N yS+g== 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=YlnBqdWRAdGOIDkFc78uZlpVYy9Rupt5PRiXjMOq17M=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=w0XXbUbJm5Bft8QYPHTKt+CxmXXAc8JjIVcnVMOPiRyS1dDTeM6dOQqjW1lw2v09t6 T9Zng9IatZ8H1QDpSHJqq/Pdl4eAjYIOZTYhu7ecpElveauRv2h88SbeHo5mcKihNgmg wBdwdTf+BpuDdMRTiGWE2PVqnztQKnT4hs6kz6Yn2mV7RWsOM9rePiQZFw2lwao9hG9t 7uciDFEB4lCiJ1ZYNI9LrcJoHXys4/maqmUgsGLhijMUvyQRnOc6FuFDEvmCnJsz5kds DlAaZD+/V9d9A4UvqMDNd9o2M/qyfCdA2ptQ+HX/y/SB+Oo1pCIQ+bZDFDIuIkwJsb/J R9lA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2gEPD10; 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=pass (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 a1e0cc1a2514c-7fe8c44b6c1si291489241.90.2024.05.15.08.13.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:13:20 -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=pass header.i=@linaro.org header.s=google header.b=M2gEPD10; 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=pass (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 1s7GFO-0003rN-E9; Wed, 15 May 2024 11:08:50 -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 1s7GFL-0003q5-0n for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:48 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFH-0002l6-Ew for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:46 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4201986d60aso21043035e9.3 for ; Wed, 15 May 2024 08:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785720; x=1716390520; 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=YlnBqdWRAdGOIDkFc78uZlpVYy9Rupt5PRiXjMOq17M=; b=M2gEPD10Oiza2L1ULqUV5CbXdkPh2UaSrQUhcPWJz3mdNMZxSCUufEAHCn0KK8UPTs f6Vbyw5VG0wojwWAteRnzGsDC1edrikgqSKNkO8HG5FQ5Yo4pQuFGVJPB6SxUZhtH/i8 DnWqC3QTKoi7dSJpvJgRk62acPI8Uaz/nKvdrKMKYTIHnp3bptz/pjZLQVc4giyIlFqI 2zfgsjE4eN0Ns84TPoDfNDmDdRATyU/ZTz5m6sMLQjZLgav9Is8xnjpv1Shb9SDunbkP 6ailq18Pn5l3ev/lXu2r9OAmVIi4JoW/wlS0+QG6zMRGsfLLOa+tdlVaEiyEtrIRr93G ENEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785720; x=1716390520; 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=YlnBqdWRAdGOIDkFc78uZlpVYy9Rupt5PRiXjMOq17M=; b=HbZRQSNLfryLFgPwKA8ZAXYi09FQOYMe0TG0ePVLGYkj6U9IBxwNG5KNw7Edk3P0XL a6r1sHGFFHHVApFO6sSZKxuTJKnf8bwIS6zFcbA2wwmdA+byQN74vcZHxKe/ZMUo2gZI 7W8mH2nvwIoVUF5L8mS/R0HasnyqfzwI9Z4tvg5kvUItpfkQU/tRP6CsnDYfK3V21lDL 5sqBiHTh0VNU0TBO70VW3pig6V4RnuLQC0h8KNEwGYEaglZkN+J1XIfqnMy+W//2egGd zxhUTXltTOCU6nkaHbQUqAwctR/+yV1M6zMrVNwOz9BLE1Rrp5miLOhbwGlW/X3iJ7So ekqA== X-Gm-Message-State: AOJu0YxLooXid6ZUh8x6KpBNVP6V/Bie2s34mDADtvPHX2UWrWIkXk7Q t4Rmn1yyXSjEpXXdXCK+VdHbFnDs5SLR0jbGvy+HpXWkalLAbrH5KBrLIAC4Z41RTWwl8PA4zTD uRFo= X-Received: by 2002:a05:600c:3548:b0:41a:9a6a:41e1 with SMTP id 5b1f17b1804b1-41feac5a3c3mr103312585e9.29.1715785720182; Wed, 15 May 2024 08:08:40 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 02/28] target/i386: Convert do_fldt, do_fstt to X86Access Date: Wed, 15 May 2024 17:08:11 +0200 Message-Id: <20240515150837.259747-3-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::329; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x329.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 Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 44 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index ece22a3553..1662643a8f 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -27,6 +27,7 @@ #include "fpu/softfloat.h" #include "fpu/softfloat-macros.h" #include "helper-tcg.h" +#include "access.h" /* float macros */ #define FT0 (env->ft0) @@ -84,23 +85,22 @@ static inline void fpop(CPUX86State *env) env->fpstt = (env->fpstt + 1) & 7; } -static floatx80 do_fldt(CPUX86State *env, target_ulong ptr, uintptr_t retaddr) +static floatx80 do_fldt(X86Access *ac, target_ulong ptr) { CPU_LDoubleU temp; - temp.l.lower = cpu_ldq_data_ra(env, ptr, retaddr); - temp.l.upper = cpu_lduw_data_ra(env, ptr + 8, retaddr); + temp.l.lower = access_ldq(ac, ptr); + temp.l.upper = access_ldw(ac, ptr + 8); return temp.d; } -static void do_fstt(CPUX86State *env, floatx80 f, target_ulong ptr, - uintptr_t retaddr) +static void do_fstt(X86Access *ac, target_ulong ptr, floatx80 f) { CPU_LDoubleU temp; temp.d = f; - cpu_stq_data_ra(env, ptr, temp.l.lower, retaddr); - cpu_stw_data_ra(env, ptr + 8, temp.l.upper, retaddr); + access_stq(ac, ptr, temp.l.lower); + access_stw(ac, ptr + 8, temp.l.upper); } /* x87 FPU helpers */ @@ -382,16 +382,22 @@ int64_t helper_fisttll_ST0(CPUX86State *env) void helper_fldt_ST0(CPUX86State *env, target_ulong ptr) { int new_fpstt; + X86Access ac; + + access_prepare(&ac, env, ptr, 10, MMU_DATA_LOAD, GETPC()); new_fpstt = (env->fpstt - 1) & 7; - env->fpregs[new_fpstt].d = do_fldt(env, ptr, GETPC()); + env->fpregs[new_fpstt].d = do_fldt(&ac, ptr); env->fpstt = new_fpstt; env->fptags[new_fpstt] = 0; /* validate stack entry */ } void helper_fstt_ST0(CPUX86State *env, target_ulong ptr) { - do_fstt(env, ST0, ptr, GETPC()); + X86Access ac; + + access_prepare(&ac, env, ptr, 10, MMU_DATA_STORE, GETPC()); + do_fstt(&ac, ptr, ST0); } void helper_fpush(CPUX86State *env) @@ -2460,15 +2466,18 @@ void helper_fldenv(CPUX86State *env, target_ulong ptr, int data32) static void do_fsave(CPUX86State *env, target_ulong ptr, int data32, uintptr_t retaddr) { + X86Access ac; floatx80 tmp; int i; do_fstenv(env, ptr, data32, retaddr); ptr += (target_ulong)14 << data32; + access_prepare(&ac, env, ptr, 80, MMU_DATA_STORE, retaddr); + for (i = 0; i < 8; i++) { tmp = ST(i); - do_fstt(env, tmp, ptr, retaddr); + do_fstt(&ac, ptr, tmp); ptr += 10; } @@ -2483,14 +2492,17 @@ void helper_fsave(CPUX86State *env, target_ulong ptr, int data32) static void do_frstor(CPUX86State *env, target_ulong ptr, int data32, uintptr_t retaddr) { + X86Access ac; floatx80 tmp; int i; do_fldenv(env, ptr, data32, retaddr); ptr += (target_ulong)14 << data32; + access_prepare(&ac, env, ptr, 80, MMU_DATA_LOAD, retaddr); + for (i = 0; i < 8; i++) { - tmp = do_fldt(env, ptr, retaddr); + tmp = do_fldt(&ac, ptr); ST(i) = tmp; ptr += 10; } @@ -2507,6 +2519,7 @@ static void do_xsave_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) { int fpus, fptag, i; target_ulong addr; + X86Access ac; fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; fptag = 0; @@ -2525,9 +2538,11 @@ static void do_xsave_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) cpu_stq_data_ra(env, ptr + XO(legacy.fpdp), 0, ra); /* edp+sel; rdp */ addr = ptr + XO(legacy.fpregs); + access_prepare(&ac, env, addr, 8 * 16, MMU_DATA_STORE, ra); + for (i = 0; i < 8; i++) { floatx80 tmp = ST(i); - do_fstt(env, tmp, addr, ra); + do_fstt(&ac, addr, tmp); addr += 16; } } @@ -2700,6 +2715,7 @@ static void do_xrstor_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) { int i, fpuc, fpus, fptag; target_ulong addr; + X86Access ac; fpuc = cpu_lduw_data_ra(env, ptr + XO(legacy.fcw), ra); fpus = cpu_lduw_data_ra(env, ptr + XO(legacy.fsw), ra); @@ -2712,8 +2728,10 @@ static void do_xrstor_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) } addr = ptr + XO(legacy.fpregs); + access_prepare(&ac, env, addr, 8 * 16, MMU_DATA_LOAD, ra); + for (i = 0; i < 8; i++) { - floatx80 tmp = do_fldt(env, addr, ra); + floatx80 tmp = do_fldt(&ac, addr); ST(i) = tmp; addr += 16; } From patchwork Wed May 15 15:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796958 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032340wra; Wed, 15 May 2024 08:09:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVBcOxYCnPYczZDc49rduZNR0cAD/f4XLIyhvFZXCKr7sh+t46kcnf6ENU0HmlyDJIjzuFFQfU+JLFGQlKzTpKJ X-Google-Smtp-Source: AGHT+IEpd53OGnBSs/I/JOo/fVwfhhutDeAo2eKfstx8pnmDxmrLHnU4rRlSP3TMaVmxO+QUIaJp X-Received: by 2002:a05:6102:3a14:b0:47f:1fbf:f4d with SMTP id ada2fe7eead31-48077e7b72cmr13450215137.23.1715785789140; 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=ZHUOpHQlmhJ+bKzHETlcbnK5HqHy5IxPas88MxRuC0LQzRrlVaoPGonw3CN5wIUWCj BFr4GGX5RtN9WpxSl+VFsQd0IeaCx8P8V+ElEvHTFdM9cPDP8scO3moRKnPmrmPyawt6 zH6BzonpFdyypapbtdzlmy2sjAo8tYqHf0gYdBJ5HY6K+bKEp/gTf25jVZRn8o3CNHBm MR4LGo3fIKtZASfLamPj891KlCvV6FV3ncb6Ycgel30ykN/RCT7OEKQlNI0VbMwhvuqC O+XrkKrFgm7/c9leYbcwdHOrOMV0m2DVRvn9ol46LoJl3Hd1XfGSRVcLqj08Sej0JLTw OJbA== 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=65Gkdr7ftr6lyKPmfr51rDrQ5Maa9PeaHdOx7rkPnQ4=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=FL6XvG8XfE48UwR8QAGC8auVTh04TG8xUFK2T6ua8Dgewk79QAy/lGF/N9UXKRpOTW qWWkvaShgq2suVAVBHGv3XUBd2PZBr9p6s0Qp/mXpQ2AEN55q/jb3WsyFQngkBiEVGsl cohNPoysSwH3ku5nCXYIfZxAhk5337ABCh1uhaG06BIMsBhy9SqoR8dgfacogdX7u67W SV9O17llOyQ/hktW5av9uyLeN5BwYIVqbvekvMhq0uFdzu285aqRdYbEUF8fRweZPiNI iYqrlGK8MSfbX2hiEQ3gnzwYwUTcOpkr78+/b8OVks0Unc3sWCQTRibaoDa74XJ5+cgr ThSA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CC+G5yAZ; 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-4807384b6dcsi2426280137.742.2024.05.15.08.09.48 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=CC+G5yAZ; 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 1s7GFN-0003qY-6w; Wed, 15 May 2024 11:08:49 -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 1s7GFI-0003pT-Dl for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:45 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFG-0002ng-L4 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:44 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2e0933d3b5fso103891461fa.2 for ; Wed, 15 May 2024 08:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785721; x=1716390521; 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=65Gkdr7ftr6lyKPmfr51rDrQ5Maa9PeaHdOx7rkPnQ4=; b=CC+G5yAZSQuIyP5KOiDdRhafBLp4dEwJ1yDQpr9C240Yw1Hj8DPqvD3s/CN5KLqZGA 9bIM0NHR2SvdJ2VEOK9zlad55lZsu3jITlVXZxrKgU2JOLjKK68zzRyuJYPk8yARt1zI r4DKGPNHvj61oUvfWr+D4HTV4DV2oaDJzBMhBbfjEJ9cvzAX3xKMpsR9C/BrVTAZipRc Yw6AssB3Bws3Cv/wckK+YWryjX8BwNfyH3Y+S0EQflXP96bStl3PkQRbBe4ZBalebNM/ stYL4bDZExuHuxOqqXzmQECRdyCiyhOUiQF+NLra+uzGm+S7jyhgqHy/XuPIcuk2ec7L sA9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785721; x=1716390521; 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=65Gkdr7ftr6lyKPmfr51rDrQ5Maa9PeaHdOx7rkPnQ4=; b=dTNLqwXRtxOrtsiHlprqENQrFihEMtkJC8m+jZud/XXQLbdTIOL4hEFxejvta8Ft/I 5HOZ5PN8lNJyNNwi79WvRV64SWtxwBWUmwmxb3gAjR5ix7sl84H7A4yqRQC8/8cmflZn +wj1+vpE+HbgHQ7nG+h4hSQf3kF3AyTiIe17PNbMhjGT8qZ4S2JqrREhISZRdAwKgHo1 /EF07KcS5lnVfkxvN+mnHAHg7TW6InEfgTLuuTYG7uNrM1i9K+cf0QB4P5WVoFe1I5UC sGJPCnv0f/wppYJ5as5HT5+8/vaPS70LEX97iyPdBMlsshUL01Fr/KLnUJv3HiQAA0ym t3TQ== X-Gm-Message-State: AOJu0YwGb33JFWCvHrezK/NKYTLffPOrj/4c3TzY516r+vq9ourJDNTj EOI6nCiWSLuoTFLLDNW0WFdfw4HZ/RroKj6ANfekw3V30ciEv+3vUay4oDRivENiGMaC7V6b6T5 caLc= X-Received: by 2002:a2e:2a83:0:b0:2e2:2791:9842 with SMTP id 38308e7fff4ca-2e5204ac519mr97256021fa.44.1715785720940; Wed, 15 May 2024 08:08:40 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 03/28] target/i386: Convert helper_{fbld, fbst}_ST0 to X86Access Date: Wed, 15 May 2024 17:08:12 +0200 Message-Id: <20240515150837.259747-4-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::232; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x232.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 1662643a8f..6237cd8383 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -773,18 +773,21 @@ void helper_fninit(CPUX86State *env) void helper_fbld_ST0(CPUX86State *env, target_ulong ptr) { + X86Access ac; floatx80 tmp; uint64_t val; unsigned int v; int i; + access_prepare(&ac, env, ptr, 10, MMU_DATA_LOAD, GETPC()); + val = 0; for (i = 8; i >= 0; i--) { - v = cpu_ldub_data_ra(env, ptr + i, GETPC()); + v = access_ldb(&ac, ptr + i); val = (val * 100) + ((v >> 4) * 10) + (v & 0xf); } tmp = int64_to_floatx80(val, &env->fp_status); - if (cpu_ldub_data_ra(env, ptr + 9, GETPC()) & 0x80) { + if (access_ldb(&ac, ptr + 9) & 0x80) { tmp = floatx80_chs(tmp); } fpush(env); @@ -798,7 +801,9 @@ void helper_fbst_ST0(CPUX86State *env, target_ulong ptr) target_ulong mem_ref, mem_end; int64_t val; CPU_LDoubleU temp; + X86Access ac; + access_prepare(&ac, env, ptr, 10, MMU_DATA_STORE, GETPC()); temp.d = ST0; val = floatx80_to_int64(ST0, &env->fp_status); @@ -806,20 +811,20 @@ void helper_fbst_ST0(CPUX86State *env, target_ulong ptr) if (val >= 1000000000000000000LL || val <= -1000000000000000000LL) { set_float_exception_flags(float_flag_invalid, &env->fp_status); while (mem_ref < ptr + 7) { - cpu_stb_data_ra(env, mem_ref++, 0, GETPC()); + access_stb(&ac, mem_ref++, 0); } - cpu_stb_data_ra(env, mem_ref++, 0xc0, GETPC()); - cpu_stb_data_ra(env, mem_ref++, 0xff, GETPC()); - cpu_stb_data_ra(env, mem_ref++, 0xff, GETPC()); + access_stb(&ac, mem_ref++, 0xc0); + access_stb(&ac, mem_ref++, 0xff); + access_stb(&ac, mem_ref++, 0xff); merge_exception_flags(env, old_flags); return; } mem_end = mem_ref + 9; if (SIGND(temp)) { - cpu_stb_data_ra(env, mem_end, 0x80, GETPC()); + access_stb(&ac, mem_end, 0x80); val = -val; } else { - cpu_stb_data_ra(env, mem_end, 0x00, GETPC()); + access_stb(&ac, mem_end, 0x00); } while (mem_ref < mem_end) { if (val == 0) { @@ -828,10 +833,10 @@ void helper_fbst_ST0(CPUX86State *env, target_ulong ptr) v = val % 100; val = val / 100; v = ((v / 10) << 4) | (v % 10); - cpu_stb_data_ra(env, mem_ref++, v, GETPC()); + access_stb(&ac, mem_ref++, v); } while (mem_ref < mem_end) { - cpu_stb_data_ra(env, mem_ref++, 0, GETPC()); + access_stb(&ac, mem_ref++, 0); } merge_exception_flags(env, old_flags); } From patchwork Wed May 15 15:08:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796985 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034722wra; Wed, 15 May 2024 08:13:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXBi/txtoS+esfBwyNUjZayX3mQCBla+arHinGkjl5BA2CcjpxiLVb4loXKCIjFHu1xdvIn0EbkLLVRDdGtJgAn X-Google-Smtp-Source: AGHT+IFDX6ieHqNouKY2BDrYhcIR07AHmRb3aFYmIBi051eWBTTbgJndTl8GYm/Imxv8UMvymFEd X-Received: by 2002:a05:6808:e82:b0:3c9:69b3:8f6a with SMTP id 5614622812f47-3c997055632mr20831741b6e.19.1715786010398; Wed, 15 May 2024 08:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715786010; cv=none; d=google.com; s=arc-20160816; b=MWU/uNCJQIlwW1mJQOcHhZEQt9pUgFk8/o5lR9Vm2gwkWvrrpXG1NclpLS/STkl3yl cz/P+SVlFB3ni1dVCHXGKONIhw7iU6iHfLb20758/osAk/jpZ5VAdSPi0XKtqHJlzflA k8IKhluJAM6msnmIFbqFIdc2EZrtsmU8HloVI6eOoNWuLoiCK5dMVh6JXb022/HxDS2F asZKjzYW0MdKt4k63WH0Jnn0OQICPUFv6rVul5wBq+cDcNrYHhcRmcFNoaLk5iWB9bVa nurqRmX+V3UgFmKMkic6U5GEPU+HlANy3v6HiCet1nut6z0y2fiGaeBOHea4fMQBg/Yw effQ== 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=FRv9/cJI78XP3U2PIccw7jXbddClyYk+zoUNxwDaOdI=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=S/g3tPaNq2kSCjDtH21sMFYbnjD9ev9xof2AI5aQfU62/jzN0t64MXgy/blv0oBwLl JkcPtxZNd/Ardm1erj0iH72tk/7jEFcFN//bDTCgC8FgeAegQa6gxYD7m6b2mz0wWugx pFYVePijl3bfogUTmaoVQDZGTgCYA/2TLLXq1CjWEumClRt1joxUlYSfrrCl5Jxm36YV nokPYvmCW+3Tj/sD52g8ffKIKZnxlO9m7ziyRFcDaoPrtMln+iNH8jUZgBcpYXSuvQvQ Ns44yKpuxRYjhfp2OxNI7Guf4ehaPWPNedLB6WfQvWq3dCuQwVUIQkVoF+IaxejnNyY1 qBbQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Yp/eAH+S"; 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=pass (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 a1e0cc1a2514c-7f9002e6f98si2537255241.199.2024.05.15.08.13.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:13:30 -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=pass header.i=@linaro.org header.s=google header.b="Yp/eAH+S"; 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=pass (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 1s7GFQ-0003sg-Cq; Wed, 15 May 2024 11:08:52 -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 1s7GFO-0003r5-1h for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:50 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFK-0002op-FS for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:47 -0400 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2e4b90b03a9so76895971fa.1 for ; Wed, 15 May 2024 08:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785723; x=1716390523; 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=FRv9/cJI78XP3U2PIccw7jXbddClyYk+zoUNxwDaOdI=; b=Yp/eAH+SVAlZuNlbNNKadAfDh6IierKcj3vOfJdR0reNDmp5eduEbllEb5gGziOZOh ThSDoxMCqtMoOQMVH8qdKZNKFfawhY0EF98rvplA8IzJzBkNYtYnh8kGvjw+hj59o3Vi Oo3HS9dfLERg8LwQkajubTGnd/lHRa8TZ2QO/Uto+KtN5MWDC/FnzXwutJ4t/dzFajFq ktKEH+V3brFRqvcNeELtPptWje8+cYufqcyBHwwE1QiU+kLHk7Otl0KtTEVuMBd7ojYq 6zLeXw8mDwF4ABJaYgI6vdnNOlvk05qUpPh0R7CigdQOeGC58fYtQtTp9DuHDz3Mt71V u9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785724; x=1716390524; 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=FRv9/cJI78XP3U2PIccw7jXbddClyYk+zoUNxwDaOdI=; b=WfreH2LfsKbGjrStOBN1yRBUwZtncgeKch/yoSf6seM6fFhBQszpNldEBBIWSZ1sRM Hs+rubDEFEX/PTsdpplOoaeHEJNlTWGNbDRGdm03VLPCBMDDJeFF3XiogpzChQ++hDHS AudYy54vOO9n7J3cfg04jKsAgyFwQoJst+8JJmm7XyDV6VZqCAGhuEK6MxAusJleaFLJ C1Fb6vm+oTpFS0YUrbn5G6iA5FrioUAST6hONcWSlPZ6djk85zgIPjUFA0esUAEzunLg gEFhPlxE7He5Cvs7A5fyafhpozOSnJwdxqjPeYfIK0WYPW4Xtg8mMQ75OEvey80aNXP4 enJA== X-Gm-Message-State: AOJu0YylmYqmVTk2ODKGMc0/iIbirieggKxP3aSTcsa5Rk6d6NuL7fcF RLKxCadOtBp+hLgqN8p3UzTVf9js6VkLnhzf9wvULGT8CR8Ngn71n/ip6cU+Lwk0Q3BkbY26nT7 WEMY= X-Received: by 2002:a2e:b0f6:0:b0:2e3:5ec2:fdc4 with SMTP id 38308e7fff4ca-2e5205ec225mr95489721fa.53.1715785721688; Wed, 15 May 2024 08:08:41 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 04/28] target/i386: Convert do_fldenv to X86Access Date: Wed, 15 May 2024 17:08:13 +0200 Message-Id: <20240515150837.259747-5-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::22f; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x22f.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 6237cd8383..5ad6e04639 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2442,20 +2442,15 @@ static void cpu_set_fpus(CPUX86State *env, uint16_t fpus) #endif } -static void do_fldenv(CPUX86State *env, target_ulong ptr, int data32, - uintptr_t retaddr) +static void do_fldenv(X86Access *ac, target_ulong ptr, int data32) { int i, fpus, fptag; + CPUX86State *env = ac->env; + + cpu_set_fpuc(env, access_ldw(ac, ptr)); + fpus = access_ldw(ac, ptr + (2 << data32)); + fptag = access_ldw(ac, ptr + (4 << data32)); - if (data32) { - cpu_set_fpuc(env, cpu_lduw_data_ra(env, ptr, retaddr)); - fpus = cpu_lduw_data_ra(env, ptr + 4, retaddr); - fptag = cpu_lduw_data_ra(env, ptr + 8, retaddr); - } else { - cpu_set_fpuc(env, cpu_lduw_data_ra(env, ptr, retaddr)); - fpus = cpu_lduw_data_ra(env, ptr + 2, retaddr); - fptag = cpu_lduw_data_ra(env, ptr + 4, retaddr); - } cpu_set_fpus(env, fpus); for (i = 0; i < 8; i++) { env->fptags[i] = ((fptag & 3) == 3); @@ -2465,7 +2460,10 @@ static void do_fldenv(CPUX86State *env, target_ulong ptr, int data32, void helper_fldenv(CPUX86State *env, target_ulong ptr, int data32) { - do_fldenv(env, ptr, data32, GETPC()); + X86Access ac; + + access_prepare(&ac, env, ptr, 14 << data32, MMU_DATA_STORE, GETPC()); + do_fldenv(&ac, ptr, data32); } static void do_fsave(CPUX86State *env, target_ulong ptr, int data32, @@ -2499,12 +2497,12 @@ static void do_frstor(CPUX86State *env, target_ulong ptr, int data32, { X86Access ac; floatx80 tmp; - int i; + int i, envsize = 14 << data32; - do_fldenv(env, ptr, data32, retaddr); - ptr += (target_ulong)14 << data32; + access_prepare(&ac, env, ptr, envsize + 80, MMU_DATA_LOAD, retaddr); - access_prepare(&ac, env, ptr, 80, MMU_DATA_LOAD, retaddr); + do_fldenv(&ac, ptr, data32); + ptr += envsize; for (i = 0; i < 8; i++) { tmp = do_fldt(&ac, ptr); From patchwork Wed May 15 15:08:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796976 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033691wra; Wed, 15 May 2024 08:11:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXwLcNKvDErSxgPbwMeF23pr4Q8LAitbtQF/Qt2X6fwv6d/SYSmu5m0DHyfjUU3VhEAfeiGg3exeM2LsHPg2+e7 X-Google-Smtp-Source: AGHT+IEO3OE965V7m5ZLaQ4G620vOZQ9il4vX93c/5dv3riXn/kmUEHfxWHSeERCcgxx6hLbhiwk X-Received: by 2002:a05:6122:2a51:b0:4d8:75ca:8cbe with SMTP id 71dfb90a1353d-4df8839a7cemr12921866e0c.16.1715785910834; Wed, 15 May 2024 08:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785910; cv=none; d=google.com; s=arc-20160816; b=OxzLpkgnzpA/dV7Ax0Jm7eyeD6tawVHaNXYvs52XYSPGkRi1G+8LqGfl8GKshHEoxZ C/elv+OtsD/u6TSKDnjN20YwJWOIOzCYlPRj7I9kfUtSUnOkty7dJtZZh3lP9n1bI32X jrMIpoqE8S1egH4SeJJtxgXtYYzNZsNEs8/xg9hOMFI7xj6rv6rtclgYa1zJLbUwhiUk H+e1fWDS9mCagI/c7/432xZ2ma4BoJuuVSynwgXk8pPE1kr9peYFaSCcpoSRWDVMIjYl tuY2s0H7vLAw1ra4gEGXBt1MyxGoM4zkSYAP8C2mRiC4eKM0RQ0MmaYfxr6u4NfPPayf sMVQ== 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=pTjFqZGfIgyyuZashU0miJrDlkwdhgdcBxd/4Tmn0sc=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=ncKPcoP4fvebjVw9zVPhPyBpnW5fXTb9HgiM9Fs4RTBwxLubkoMldRIuYraciPaUdy Wa/gkDb4PRn1ARWmVHfsWOP6V+RifXii4jl/Mo/Z1T2BLGC2Dcm7Dek8t1cKoxScYrIW Zk4Lb4nJNVtbbIXE7+r02n1k87POstNEEn5O2PAiHS4af+cD3ZMFE4ASUqpzDqR4/eAD Jj0wMcGQnaD19YabtJvWMTa/oDMUtXyM0z2Y0emOei6tbrUOU3JZ8VXDACX73Q4pEg3X GDrY9ONYTMDeDXloECjoEC8csPOnuYNAf3tPPJE/Iw09eCzQhHdvKetdmAQIW00E4Srf pfNw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NnQb5Ztn; 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=pass (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 71dfb90a1353d-4df7c05acc8si2162134e0c.147.2024.05.15.08.11.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:50 -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=pass header.i=@linaro.org header.s=google header.b=NnQb5Ztn; 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=pass (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 1s7GFQ-0003sS-2a; Wed, 15 May 2024 11:08:52 -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 1s7GFO-0003r2-0w for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:50 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFK-0002ow-77 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:47 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42011507a57so30811435e9.1 for ; Wed, 15 May 2024 08:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785724; x=1716390524; 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=pTjFqZGfIgyyuZashU0miJrDlkwdhgdcBxd/4Tmn0sc=; b=NnQb5Ztn0eg6ru4YzxlucVxjs6a5MXJwnDEfjeub82qsLSafsyaecMyPsNwMlM1FJx k59bZxwMWPTJ55wIR7s4IVwew4wAtOoyl8DIWefjjAyOfafAnu76j20layKEveM1tM4n gEXiLH4IUdAC28RdAqPTCv1mwoKHUdVUqacqq1vBINpppfdAiz1OPWFyHiXRVdzL4Ctg 7j35ZSGLwmR+IhDKDDgklhHFcrfm/JoM6FbPxKAjeI/px1yJqFmZ0CJQfh30XHqrBAgf E84HJuNlr1obAyP7XUpXalVvz+Cre1nW/oMy0c0F0BE/Nu8sh01e7se8CZ81BDCeuWa4 7blQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785724; x=1716390524; 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=pTjFqZGfIgyyuZashU0miJrDlkwdhgdcBxd/4Tmn0sc=; b=LG4OA8MySxcYbGKXSBOGV1oV3B25gkouHz34vXZj8KKCKK+Gov3bM3XIjYfkPuFZQ3 jWVUHpQ0IZzhDGYQ7tJ6sulWmfnEp6Rixxo20viDAsUVlboemepL8y6q6t282BAd5uqz r3rsNE6N98nwaPD3zNjU+gcajC20MWU0gv+YiP1CH5H7cEds1YBp7LiNHolDL4J9U8NH mLnCItKkmTvviH6IYe/rtnDKf3yDP67UhMaWHM14nLwTKJSqjh+kD3TmWpDaeACu7iB9 XDY4szUdHwJulpqTaTOBBTq4xyXZpVwidsX4PlmMq3BIWS3v8P/0p0hZorfhLJ0t1wGa Zg7A== X-Gm-Message-State: AOJu0Yz8Ry0bh1FfxPSCis7hkCwIddsP5N0FsfDzGeGAm8ZNjbcjUHie 9gbvjgbFvFvM40mdkd+BZ2+ddchknuLpDlCS/WyfnTB2DgnNrxidCMSSmUNUmzaXUm4ANoChxDo ETaM= X-Received: by 2002:a05:600c:3544:b0:41a:b54a:9ad8 with SMTP id 5b1f17b1804b1-41fea52e620mr119039445e9.0.1715785724377; Wed, 15 May 2024 08:08:44 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 05/28] target/i386: Convert do_fstenv to X86Access Date: Wed, 15 May 2024 17:08:14 +0200 Message-Id: <20240515150837.259747-6-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::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 45 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 5ad6e04639..01e9a1fbbf 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2373,9 +2373,9 @@ void helper_fxam_ST0(CPUX86State *env) } } -static void do_fstenv(CPUX86State *env, target_ulong ptr, int data32, - uintptr_t retaddr) +static void do_fstenv(X86Access *ac, target_ulong ptr, int data32) { + CPUX86State *env = ac->env; int fpus, fptag, exp, i; uint64_t mant; CPU_LDoubleU tmp; @@ -2402,28 +2402,31 @@ static void do_fstenv(CPUX86State *env, target_ulong ptr, int data32, } if (data32) { /* 32 bit */ - cpu_stl_data_ra(env, ptr, env->fpuc, retaddr); - cpu_stl_data_ra(env, ptr + 4, fpus, retaddr); - cpu_stl_data_ra(env, ptr + 8, fptag, retaddr); - cpu_stl_data_ra(env, ptr + 12, env->fpip, retaddr); /* fpip */ - cpu_stl_data_ra(env, ptr + 16, env->fpcs, retaddr); /* fpcs */ - cpu_stl_data_ra(env, ptr + 20, env->fpdp, retaddr); /* fpoo */ - cpu_stl_data_ra(env, ptr + 24, env->fpds, retaddr); /* fpos */ + access_stl(ac, ptr, env->fpuc); + access_stl(ac, ptr + 4, fpus); + access_stl(ac, ptr + 8, fptag); + access_stl(ac, ptr + 12, env->fpip); /* fpip */ + access_stl(ac, ptr + 16, env->fpcs); /* fpcs */ + access_stl(ac, ptr + 20, env->fpdp); /* fpoo */ + access_stl(ac, ptr + 24, env->fpds); /* fpos */ } else { /* 16 bit */ - cpu_stw_data_ra(env, ptr, env->fpuc, retaddr); - cpu_stw_data_ra(env, ptr + 2, fpus, retaddr); - cpu_stw_data_ra(env, ptr + 4, fptag, retaddr); - cpu_stw_data_ra(env, ptr + 6, env->fpip, retaddr); - cpu_stw_data_ra(env, ptr + 8, env->fpcs, retaddr); - cpu_stw_data_ra(env, ptr + 10, env->fpdp, retaddr); - cpu_stw_data_ra(env, ptr + 12, env->fpds, retaddr); + access_stw(ac, ptr, env->fpuc); + access_stw(ac, ptr + 2, fpus); + access_stw(ac, ptr + 4, fptag); + access_stw(ac, ptr + 6, env->fpip); + access_stw(ac, ptr + 8, env->fpcs); + access_stw(ac, ptr + 10, env->fpdp); + access_stw(ac, ptr + 12, env->fpds); } } void helper_fstenv(CPUX86State *env, target_ulong ptr, int data32) { - do_fstenv(env, ptr, data32, GETPC()); + X86Access ac; + + access_prepare(&ac, env, ptr, 14 << data32, MMU_DATA_STORE, GETPC()); + do_fstenv(&ac, ptr, data32); } static void cpu_set_fpus(CPUX86State *env, uint16_t fpus) @@ -2471,12 +2474,12 @@ static void do_fsave(CPUX86State *env, target_ulong ptr, int data32, { X86Access ac; floatx80 tmp; - int i; + int i, envsize = 14 << data32; - do_fstenv(env, ptr, data32, retaddr); + access_prepare(&ac, env, ptr, envsize + 80, MMU_DATA_STORE, retaddr); - ptr += (target_ulong)14 << data32; - access_prepare(&ac, env, ptr, 80, MMU_DATA_STORE, retaddr); + do_fstenv(&ac, ptr, data32); + ptr += envsize; for (i = 0; i < 8; i++) { tmp = ST(i); From patchwork Wed May 15 15:08:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796982 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034526wra; Wed, 15 May 2024 08:13:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXqVTPXHcQGDfw15wUbeibTITqiv+3PITD+Q8vsv2AYQcUhMUIjPAWtKJ0FfR9YOtwM81yOPsy/Nmi9Rnuw+EPz X-Google-Smtp-Source: AGHT+IEwdiFtNdEsw9B93OJvrjpS3SVAhupvz7PXf1LE4diWXMOtGDdXdk5Xegkc6SqrPFqGGSw6 X-Received: by 2002:a05:6122:3124:b0:4d4:21cc:5f4f with SMTP id 71dfb90a1353d-4df8833c0bbmr12499025e0c.11.1715785994301; Wed, 15 May 2024 08:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785994; cv=none; d=google.com; s=arc-20160816; b=nfun9YA/CSprZhkrLG3tbgTWvAMyRGjIuFBExxhMv/t8xZZw+MN2Vyi0KbKsUFEB90 G6RwDsRk6Lg/hN1+TvfqbykCfiyRBm9i4xfTgZd5f0RLvbRBZERW2eiBBVPd87k9UKxN Nh+k/2iGh+Sz/AHAE9tb0Qu1BnB87sImclI7gBhoXkmj9sRi1a+jRgowWK+1Ro6N8QrR 5IxcjTuqUwymeqPQawbDqgAaBSRIGJsk+yH07WPs882gbUqvW+5Gex9EMDhWqnJngEMW Q3X5DnUKq+AiM/BASh4J43xfZw0pxAZ/67WkXaRVyxvYm1Kg9Ea9oo5MFlnKuF+NYZnt 7iRw== 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=Qu8at7vOdb1WvbcdbtxhwbQTz1oNXGTTdYMgD98z5zw=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=df10XX+8p/tHgCcrjbpeeP8fY5apC+c5A6m9Etviz0Ym0AAuXDZqPzhCBSBB/e9M3V WXJyJm9d4XGCpjpY6UIyGzVtakqyaJWKclE0HRONX19MCxVRCI2WIhtwiqchqIszM9Qb wsoHNLkbTQHp7XEhMfjFgKA36myxWZc3i4Ic/ZxBJRbC0oNQBwuiDSvKpgUMDmJVgBdu 56VCPBFnlXAVCc/pHPnim06gjXfGkN8l1Kk54cSWp+L+E2ejFweNms7p+t+Cm5y8oFgl ipQffEVtScZpgHLyJNHarTzhzFKRk9p60Nny/zeFjMAhG/HqBlanQZcJHdMPUEZ96qU0 ku7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qh1EWioZ; 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=pass (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 71dfb90a1353d-4df7c0d3826si2102801e0c.313.2024.05.15.08.13.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:13:14 -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=pass header.i=@linaro.org header.s=google header.b=Qh1EWioZ; 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=pass (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 1s7GFO-0003rp-P9; Wed, 15 May 2024 11:08:50 -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 1s7GFN-0003qW-2R for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:49 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFK-0002pi-Jk for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:48 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-420116a6652so29815615e9.2 for ; Wed, 15 May 2024 08:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785725; x=1716390525; 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=Qu8at7vOdb1WvbcdbtxhwbQTz1oNXGTTdYMgD98z5zw=; b=Qh1EWioZt62zrLR2ADmPa0MYokndM0q0NgvQN5GCZmvYMdQMnNlsL4KkOH4hyqNJ5W 7qW/oGgAa9MkERKz5cnUwfp43ErS+UWx9+o1HsIWhZ2p+k3UMriWFQeXOQlXKP9k/oVS i7vjRYUhNDFQWEwCUHo58PjRNPHAStthw3TfyUHtXSk/bgiDUA6ga7052YlfXPI3XYIe eB+qUMPfyCTkGuwymB6iN3azFTUmslsjl5Y0JHN0bJMvRlSnujiOW0ASr0tUghbOF+ea eYSx696nUNLamJavfPBYCsWbPzG1D/3nUU6y54PxEdXVYSSmqmS1+aYU8NVYEbrRcsgF MKFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785725; x=1716390525; 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=Qu8at7vOdb1WvbcdbtxhwbQTz1oNXGTTdYMgD98z5zw=; b=NTvPKL6YUbFSY6aZpuRE+wLnHnd9vKObd9A5VTNtOuGzP1/64v7emOtCnnomdHK8R3 QmALua2ZKIcyi+h9K5SFpcNoETqW/BSq2u7dHKzRFuPh8x01f+yw+3qB0B2nIVFfIki8 rh5R2GG6EVpfFTkWpya1A5UmveUhdmUbmsh+8oTDFO91VTKotp3KqP8mITlSwbajLTd7 kLumL2Xpi6q4shZEGImEcabBfOQ+JAHja6ECc/CMHzVTbK7tV3aWBs3Gh/6SxlakkMMB qULjLhUJ7fQEo/iC0cn65qk4gNmM6y3qX8iRNT1Yb+S5LG8XImRPmR6hrfsiiqrX075C 3QIw== X-Gm-Message-State: AOJu0Ywet1idgMQpYcB9yS0AZt8WHE5EfajE2R+ubqA03cDLnmOeZUne PFsq/g4lMG4Q/ZWxYkUBJYd9ptRybkg5z/KTh/sMOWmPWbqSRSvgk356bt5ma+wOeT3TnHnwRn3 r9ak= X-Received: by 2002:a05:600c:1c9f:b0:41c:35c:2da7 with SMTP id 5b1f17b1804b1-41feac551a0mr124557995e9.30.1715785725094; Wed, 15 May 2024 08:08:45 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 06/28] target/i386: Convert do_fsave, do_frstor to X86Access Date: Wed, 15 May 2024 17:08:15 +0200 Message-Id: <20240515150837.259747-7-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::32e; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32e.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 60 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 01e9a1fbbf..df12eac71e 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2469,21 +2469,16 @@ void helper_fldenv(CPUX86State *env, target_ulong ptr, int data32) do_fldenv(&ac, ptr, data32); } -static void do_fsave(CPUX86State *env, target_ulong ptr, int data32, - uintptr_t retaddr) +static void do_fsave(X86Access *ac, target_ulong ptr, int data32) { - X86Access ac; - floatx80 tmp; - int i, envsize = 14 << data32; + CPUX86State *env = ac->env; - access_prepare(&ac, env, ptr, envsize + 80, MMU_DATA_STORE, retaddr); + do_fstenv(ac, ptr, data32); + ptr += 14 << data32; - do_fstenv(&ac, ptr, data32); - ptr += envsize; - - for (i = 0; i < 8; i++) { - tmp = ST(i); - do_fstt(&ac, ptr, tmp); + for (int i = 0; i < 8; i++) { + floatx80 tmp = ST(i); + do_fstt(ac, ptr, tmp); ptr += 10; } @@ -2492,23 +2487,22 @@ static void do_fsave(CPUX86State *env, target_ulong ptr, int data32, void helper_fsave(CPUX86State *env, target_ulong ptr, int data32) { - do_fsave(env, ptr, data32, GETPC()); + int size = (14 << data32) + 80; + X86Access ac; + + access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, GETPC()); + do_fsave(&ac, ptr, data32); } -static void do_frstor(CPUX86State *env, target_ulong ptr, int data32, - uintptr_t retaddr) +static void do_frstor(X86Access *ac, target_ulong ptr, int data32) { - X86Access ac; - floatx80 tmp; - int i, envsize = 14 << data32; + CPUX86State *env = ac->env; - access_prepare(&ac, env, ptr, envsize + 80, MMU_DATA_LOAD, retaddr); + do_fldenv(ac, ptr, data32); + ptr += 14 << data32; - do_fldenv(&ac, ptr, data32); - ptr += envsize; - - for (i = 0; i < 8; i++) { - tmp = do_fldt(&ac, ptr); + for (int i = 0; i < 8; i++) { + floatx80 tmp = do_fldt(ac, ptr); ST(i) = tmp; ptr += 10; } @@ -2516,7 +2510,11 @@ static void do_frstor(CPUX86State *env, target_ulong ptr, int data32, void helper_frstor(CPUX86State *env, target_ulong ptr, int data32) { - do_frstor(env, ptr, data32, GETPC()); + int size = (14 << data32) + 80; + X86Access ac; + + access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, GETPC()); + do_frstor(&ac, ptr, data32); } #define XO(X) offsetof(X86XSaveArea, X) @@ -2972,12 +2970,20 @@ 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) { - do_fsave(env, ptr, data32, 0); + int size = (14 << data32) + 80; + X86Access ac; + + access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, 0); + do_fsave(&ac, ptr, data32); } void cpu_x86_frstor(CPUX86State *env, target_ulong ptr, int data32) { - do_frstor(env, ptr, data32, 0); + int size = (14 << data32) + 80; + X86Access ac; + + access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, 0); + do_frstor(&ac, ptr, data32); } void cpu_x86_fxsave(CPUX86State *env, target_ulong ptr) From patchwork Wed May 15 15:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796979 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034297wra; Wed, 15 May 2024 08:12:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW867ib/OzTSFcFWZ3oiI8mph5iZRfGjLI9Ga5UmAoR3p+XZTog+ryLGuS8eaJ9U9TeHjgOCE9CoYL5/O1Jtqso X-Google-Smtp-Source: AGHT+IHP1GmUfiunnsFj/RUG+AjfiMV1BBqKeR7EMlPxopYI27Sr/4dHcB2h4EkbiX/Rf/VPNuom X-Received: by 2002:a05:620a:4006:b0:792:db8b:5c6 with SMTP id af79cd13be357-792db8b06b7mr1778658385a.16.1715785972226; Wed, 15 May 2024 08:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785972; cv=none; d=google.com; s=arc-20160816; b=m9EI5Vf98MqOAvPSo6+w5+3vyAYpzYM+ZQ/0mJT7nHui+O6F4jvgrbveKzyvQqkcOS Lo5uXS3xnvx2TR7nhCrvVCvZhEjyXW88G3qYntKvp2FnE6LOdt9d2cLiIwtAwHJjP1Jm KLfEicmLWCdtn8pzRI0/F78tkAA0882e8XF85c6WmjhnmAOC3be/qvG7Ch2KgZvplXJU FaKyFd1oZ+hA/bQU3RyNe6DTu6IJIac3RYYtI3oPaxeLvFNiTWognT8ykMs7xE9xKStt wga04i+y9Wa4xvWYrTjVVR41JRVP+smTwFMnoVKjz4xZ8ZTJK4QtD0oYMwoxqLp6Oa7U ymPA== 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=V9YixNcV0VmfO6aoH+tEoVfr0IpNqbjtk188TFL76t0=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=b5bZfwO882yapMAlCElGY7i6hv899nc/YXCLAXyRAcAOdcG5vXLW69dD3mOzW2MIg1 n/6WPF5tDvxvzI5aKFfHaDbQvoymz/0Z3MQ5iB4suDdQbdSw6F/AbVo+LA95tPoiRUCj n0KsNVIAu/dlgB3JtIowDOXf3wWD727SqRM/YJSae9cENzBRmoWCBxkP2Tk5fG0EnYQb CJ2Rw+KbatyHYRAgPsU7I/DpBM2fE0fxPLdr5O31Jq1gFKzvE05Ukp9gwVBRT4s8qbEI 2wKTBrsQrxk5q/uqrf2TVAl29XL5XQyb2BBczdTkqPiYN8zOW6/FfPc8LTqqDn62JVYy 73Sg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZQ1gxE+R; 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 af79cd13be357-792bf27733fsi18364385a.139.2024.05.15.08.12.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:12:52 -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=ZQ1gxE+R; 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 1s7GFR-0003sk-0l; Wed, 15 May 2024 11:08:53 -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 1s7GFP-0003s5-O8 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:51 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFM-0002pp-QV for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:51 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-420104e5336so26609185e9.1 for ; Wed, 15 May 2024 08:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785726; x=1716390526; 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=V9YixNcV0VmfO6aoH+tEoVfr0IpNqbjtk188TFL76t0=; b=ZQ1gxE+RR0KV5yfEdlM6+b1LMWhZJ0Dd/nCDvwzcx0fjdoVoLCs781RwmzG19QEadC 5YV157AiirWDNTosLpeEtPMQJLTa/BJ0nEyoF1Tm+9vARXvP/NMJ/n0BvuTaCoiZFJ3+ LhzOJS0CfCNbKImTETXvnk6/aRpwKfzikJfO/lMAEqVxX4CNFVRE0A+KPOqDBm/8Ar/G hy221XVLHJ9BHe0i8ZUl5sjKdEhi1EQOtnqkOgxY+gq5QlxS8t1prXTkPGAxuodxEsCv j80oqXqta7pllaF1x/DRfzOB8exmeUT40zmK65MC8/KUL3msHz6SN3bW1uKqigyS56+l Fy0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785726; x=1716390526; 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=V9YixNcV0VmfO6aoH+tEoVfr0IpNqbjtk188TFL76t0=; b=J5JnBYy3E8vS5uGnZWf++pQsf6gKVjDqorwRCn0tqlcQXbXAOlnVe9SNQSfqznQWdA WhxKrX5Ah/PD7MnYKXivrERvikbo/MdBGzN0nE1wX3yGx2G6j0telTetA+YHzoWrsjvg axMGnKqjgn6akZxZKOoXFfLH9UyZnO2lpL/2Ter9XlbYOzrwDXjgVJ+BuY5lJL6Py96u UJEif20d7TdRfQ7t0TEhemolBQDLuVFYD64PkXEz7nRzqo9sFLmfqMlVrcO0nlOnz3Yf +l5Qx23wUdzyecJ20OcL+h6/f+vVxjcspEbosunaB7SPK6wusLwZ5+ZidGacVmARjEeX sFMA== X-Gm-Message-State: AOJu0Yyp8tO1vpxsbWr9t59syr8Aux7629rEZYbCVMr9QBZ/+AKdaqDq hcSLzKurjUKAHwC0Y9fs12WnNMqKTGKu2h4Dr6SxI7fzy/Rl96FB2xnhamWQ33FR8WBoRZ3aS8r Q/3g= X-Received: by 2002:a05:600c:45d4:b0:41b:f4e1:381b with SMTP id 5b1f17b1804b1-41fbc91f5a9mr179585225e9.2.1715785725828; Wed, 15 May 2024 08:08:45 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 07/28] target/i386: Convert do_xsave_{fpu, mxcr, sse} to X86Access Date: Wed, 15 May 2024 17:08:16 +0200 Message-Id: <20240515150837.259747-8-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::32d; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32d.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 52 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index df12eac71e..8fbe6e00ce 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2519,11 +2519,11 @@ void helper_frstor(CPUX86State *env, target_ulong ptr, int data32) #define XO(X) offsetof(X86XSaveArea, X) -static void do_xsave_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_fpu(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; int fpus, fptag, i; target_ulong addr; - X86Access ac; fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; fptag = 0; @@ -2531,35 +2531,37 @@ static void do_xsave_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) fptag |= (env->fptags[i] << i); } - cpu_stw_data_ra(env, ptr + XO(legacy.fcw), env->fpuc, ra); - cpu_stw_data_ra(env, ptr + XO(legacy.fsw), fpus, ra); - cpu_stw_data_ra(env, ptr + XO(legacy.ftw), fptag ^ 0xff, ra); + access_stw(ac, ptr + XO(legacy.fcw), env->fpuc); + access_stw(ac, ptr + XO(legacy.fsw), fpus); + access_stw(ac, ptr + XO(legacy.ftw), fptag ^ 0xff); /* In 32-bit mode this is eip, sel, dp, sel. In 64-bit mode this is rip, rdp. But in either case we don't write actual data, just zeros. */ - cpu_stq_data_ra(env, ptr + XO(legacy.fpip), 0, ra); /* eip+sel; rip */ - cpu_stq_data_ra(env, ptr + XO(legacy.fpdp), 0, ra); /* edp+sel; rdp */ + access_stq(ac, ptr + XO(legacy.fpip), 0); /* eip+sel; rip */ + access_stq(ac, ptr + XO(legacy.fpdp), 0); /* edp+sel; rdp */ addr = ptr + XO(legacy.fpregs); - access_prepare(&ac, env, addr, 8 * 16, MMU_DATA_STORE, ra); for (i = 0; i < 8; i++) { floatx80 tmp = ST(i); - do_fstt(&ac, addr, tmp); + do_fstt(ac, addr, tmp); addr += 16; } } -static void do_xsave_mxcsr(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_mxcsr(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; + update_mxcsr_from_sse_status(env); - cpu_stl_data_ra(env, ptr + XO(legacy.mxcsr), env->mxcsr, ra); - cpu_stl_data_ra(env, ptr + XO(legacy.mxcsr_mask), 0x0000ffff, ra); + access_stl(ac, ptr + XO(legacy.mxcsr), env->mxcsr); + access_stl(ac, ptr + XO(legacy.mxcsr_mask), 0x0000ffff); } -static void do_xsave_sse(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_sse(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; int i, nb_xmm_regs; target_ulong addr; @@ -2571,8 +2573,8 @@ static void do_xsave_sse(CPUX86State *env, target_ulong ptr, uintptr_t ra) addr = ptr + XO(legacy.xmm_regs); for (i = 0; i < nb_xmm_regs; i++) { - cpu_stq_data_ra(env, addr, env->xmm_regs[i].ZMM_Q(0), ra); - cpu_stq_data_ra(env, addr + 8, env->xmm_regs[i].ZMM_Q(1), ra); + access_stq(ac, addr, env->xmm_regs[i].ZMM_Q(0)); + access_stq(ac, addr + 8, env->xmm_regs[i].ZMM_Q(1)); addr += 16; } } @@ -2619,20 +2621,24 @@ static void do_xsave_pkru(CPUX86State *env, target_ulong ptr, uintptr_t ra) static void do_fxsave(CPUX86State *env, target_ulong ptr, uintptr_t ra) { + X86Access ac; + /* The operand must be 16 byte aligned */ if (ptr & 0xf) { raise_exception_ra(env, EXCP0D_GPF, ra); } - do_xsave_fpu(env, ptr, ra); + access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), + MMU_DATA_STORE, ra); + do_xsave_fpu(&ac, ptr); if (env->cr[4] & CR4_OSFXSR_MASK) { - do_xsave_mxcsr(env, ptr, ra); + do_xsave_mxcsr(&ac, ptr); /* Fast FXSAVE leaves out the XMM registers */ if (!(env->efer & MSR_EFER_FFXSR) || (env->hflags & HF_CPL_MASK) || !(env->hflags & HF_LMA_MASK)) { - do_xsave_sse(env, ptr, ra); + do_xsave_sse(&ac, ptr); } } } @@ -2660,6 +2666,7 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uint64_t inuse, uint64_t opt, uintptr_t ra) { uint64_t old_bv, new_bv; + X86Access ac; /* The OS must have enabled XSAVE. */ if (!(env->cr[4] & CR4_OSXSAVE_MASK)) { @@ -2675,15 +2682,18 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, rfbm &= env->xcr0; opt &= rfbm; + access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), + MMU_DATA_STORE, ra); + if (opt & XSTATE_FP_MASK) { - do_xsave_fpu(env, ptr, ra); + do_xsave_fpu(&ac, ptr); } if (rfbm & XSTATE_SSE_MASK) { /* Note that saving MXCSR is not suppressed by XSAVEOPT. */ - do_xsave_mxcsr(env, ptr, ra); + do_xsave_mxcsr(&ac, ptr); } if (opt & XSTATE_SSE_MASK) { - do_xsave_sse(env, ptr, ra); + do_xsave_sse(&ac, ptr); } if (opt & XSTATE_YMM_MASK) { do_xsave_ymmh(env, ptr + XO(avx_state), ra); From patchwork Wed May 15 15:08:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796960 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032344wra; Wed, 15 May 2024 08:09:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVvHD5jrZ7MyM7rW4isLEQLOoOR5xu8YAxH0xc5JfewDvPS7im7e+6Uf1r53AOhztGOsTbM5F1UL8licuCJYcXo X-Google-Smtp-Source: AGHT+IHgG86XZIELgnRncQf7WcisnBemb7jd16d2s8jQy9uZyWgMz4vQuPOjgFYQvSU6MNVTH6R+ X-Received: by 2002:a05:6870:1583:b0:23d:286:a0b5 with SMTP id 586e51a60fabf-24172c0d1d2mr18656774fac.30.1715785789384; 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=In60Wa2cjdJqM9iR14IV4ne8/LLcAdj4pYNbMPP2mBFvVAQQjMMh9bPmQc/ROZTRBG nQ8kDXBgIFYyusO8TfPaSY7LP+79e4WaAFEn6u1rN1EEpTkHG36MAkQ/8FYkMdAp/tta hQ5OgprHDe8zLgAy8Iy2V5h3HX0PQ5zItUWh8B6+a9GbJ5WnMlRSS1Wn1/RcQbI7gKNj 8yp+LP0ZeXcZQ/YRvA/BTOlClX1IXl/HbNRFofUIanheZEYLNIj4gDWI6wefGR8CYMyH 6XCKySwUJ//aJInguS0ANIsUIF8T2DkxYGsVqmOwhzYHd3Y+m123Xa8OsyFhj5cdUCNN 2yLQ== 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=iDW8kJImre1GGGvGAhRzSp3Q8czb8IIa/mCnb39qel0=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=nqnyj4cqb+D3DdvlxaQwpa8w0bhBXaYa6oGyxocwCFJN9FRniIFhJgPPzKAglqkTc3 WUrECC2dAgaGAzUk+VpigEYp0GHGsfcxN/h2ZuosN+l8IRzrx+MxMVfZgwSXBaCRfsjI MA0SUMoNVaQj8fDb7Vmdy5bqy5tBvBIWVP8SP+L5TIAcITwsPDEoUSucM8A5lpEa2mra ZQeEWJ9WO8xXUrlX8tFhujMeKCpYRmXsU+MBR7OoWWO+9cdX7drVMLKMtngvGX8fZz2W zXJzeKHPoZIf7OBxMK9ZHkb7baHDr0s+ouYmUzJI6PXVL1MSiwKaVS+5QN8q99ngsiIo 4roA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hk5OZlsu; 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 71dfb90a1353d-4df7c05a690si2302529e0c.188.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=hk5OZlsu; 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 1s7GFe-0003yO-Fi; Wed, 15 May 2024 11:09:07 -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 1s7GFY-0003vh-A2 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:02 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFM-0002qH-Oj for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:58 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4200ee78e56so31000015e9.3 for ; Wed, 15 May 2024 08:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785726; x=1716390526; 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=iDW8kJImre1GGGvGAhRzSp3Q8czb8IIa/mCnb39qel0=; b=hk5OZlsuBUtsKxLiz2Vr5lVyILKgKFgNSzdCOo3vlj1mDnRD2oO8QFsS4o++2Gg99I x12p6o6U5lJoaF6B38XBg9Yj6n4tUbm05HHXB9ofc4JsWgRLmhlcxDC1zgvxUsL5G+8Q OuIapn+b9vmLjwZvQAfUbJ/r8s/cbcMtl4dJdHbXtI+kyYFfLa0Z8/hHc7SqUNZxx7ox Kr/raagjWKR4qlRJmd3qE9vqpfGI33vmmIRUtsKa2XSsyYslDvpWlY0S2TJ0aTZ+iXCW 4glGKdnvPZxb4Uy906wIBb0STYQtHbMTRLkj6zeP45qJ5ahTVphBY1k+95Vt32KhXe8Y pYPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785726; x=1716390526; 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=iDW8kJImre1GGGvGAhRzSp3Q8czb8IIa/mCnb39qel0=; b=GqSlPF+rcWhVY67+bgfWFhdv1/rsO4MwfnrnZwoZWTM766m/rXtQFSQshXNXwS+33g C+WTUUVDSrpq9GncNIAt7u0LxAZZVSXpLQh1XIpg2p+3NPHvckOcVL0EC+jyRsKpCYVQ pCtzMByEUUvTXu7rG9j4wdejLwbUzJQVZqNEtZ0Qf0wgRJ5oXWnsIQEhtA70m0zXS8lK /eaXglWY5NgladelnNh6ABakkQ9FsnmQE/itPlhW7rfDHc4VBRgTFSHVvDTfTXaJ9oJf eumfwqhXNNJv/9/FCoRXePJDKB1tGg2yJW3b/kz0JfRLFv179QzG6E22nvU76C23413X JhAA== X-Gm-Message-State: AOJu0YzQDJY540vwc+BvZzdMAquoqlYsvbdfSv9yh9H5JOxthgkMuid3 Mnn1WVbX+gyVPBqR1YgY+Qgv7mcYHbVzeDR/k9tsb6v3+zL02XafCkCLv0SZYGUW1LXYjFBu7FN cRwE= X-Received: by 2002:a05:600c:4f06:b0:420:1094:65d with SMTP id 5b1f17b1804b1-42010940753mr97907845e9.12.1715785726480; Wed, 15 May 2024 08:08:46 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 08/28] target/i386: Convert do_xrstor_{fpu, mxcr, sse} to X86Access Date: Wed, 15 May 2024 17:08:17 +0200 Message-Id: <20240515150837.259747-9-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::32d; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32d.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, 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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 46 ++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 8fbe6e00ce..f21cdb45ea 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2725,39 +2725,41 @@ void helper_xsaveopt(CPUX86State *env, target_ulong ptr, uint64_t rfbm) do_xsave(env, ptr, rfbm, inuse, inuse, GETPC()); } -static void do_xrstor_fpu(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_fpu(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; int i, fpuc, fpus, fptag; target_ulong addr; - X86Access ac; - fpuc = cpu_lduw_data_ra(env, ptr + XO(legacy.fcw), ra); - fpus = cpu_lduw_data_ra(env, ptr + XO(legacy.fsw), ra); - fptag = cpu_lduw_data_ra(env, ptr + XO(legacy.ftw), ra); + fpuc = access_ldw(ac, ptr + XO(legacy.fcw)); + fpus = access_ldw(ac, ptr + XO(legacy.fsw)); + fptag = access_ldw(ac, ptr + XO(legacy.ftw)); cpu_set_fpuc(env, fpuc); cpu_set_fpus(env, fpus); + fptag ^= 0xff; for (i = 0; i < 8; i++) { env->fptags[i] = ((fptag >> i) & 1); } addr = ptr + XO(legacy.fpregs); - access_prepare(&ac, env, addr, 8 * 16, MMU_DATA_LOAD, ra); for (i = 0; i < 8; i++) { - floatx80 tmp = do_fldt(&ac, addr); + floatx80 tmp = do_fldt(ac, addr); ST(i) = tmp; addr += 16; } } -static void do_xrstor_mxcsr(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_mxcsr(X86Access *ac, target_ulong ptr) { - cpu_set_mxcsr(env, cpu_ldl_data_ra(env, ptr + XO(legacy.mxcsr), ra)); + CPUX86State *env = ac->env; + cpu_set_mxcsr(env, access_ldl(ac, ptr + XO(legacy.mxcsr))); } -static void do_xrstor_sse(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_sse(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; int i, nb_xmm_regs; target_ulong addr; @@ -2769,8 +2771,8 @@ static void do_xrstor_sse(CPUX86State *env, target_ulong ptr, uintptr_t ra) addr = ptr + XO(legacy.xmm_regs); for (i = 0; i < nb_xmm_regs; i++) { - env->xmm_regs[i].ZMM_Q(0) = cpu_ldq_data_ra(env, addr, ra); - env->xmm_regs[i].ZMM_Q(1) = cpu_ldq_data_ra(env, addr + 8, ra); + env->xmm_regs[i].ZMM_Q(0) = access_ldq(ac, addr); + env->xmm_regs[i].ZMM_Q(1) = access_ldq(ac, addr + 8); addr += 16; } } @@ -2850,20 +2852,24 @@ static void do_xrstor_pkru(CPUX86State *env, target_ulong ptr, uintptr_t ra) static void do_fxrstor(CPUX86State *env, target_ulong ptr, uintptr_t ra) { + X86Access ac; + /* The operand must be 16 byte aligned */ if (ptr & 0xf) { raise_exception_ra(env, EXCP0D_GPF, ra); } - do_xrstor_fpu(env, ptr, ra); + access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), + MMU_DATA_LOAD, ra); + do_xrstor_fpu(&ac, ptr); if (env->cr[4] & CR4_OSFXSR_MASK) { - do_xrstor_mxcsr(env, ptr, ra); + do_xrstor_mxcsr(&ac, ptr); /* Fast FXRSTOR leaves out the XMM registers */ if (!(env->efer & MSR_EFER_FFXSR) || (env->hflags & HF_CPL_MASK) || !(env->hflags & HF_LMA_MASK)) { - do_xrstor_sse(env, ptr, ra); + do_xrstor_sse(&ac, ptr); } } } @@ -2876,6 +2882,7 @@ void helper_fxrstor(CPUX86State *env, target_ulong ptr) static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr_t ra) { uint64_t xstate_bv, xcomp_bv, reserve0; + X86Access ac; rfbm &= env->xcr0; @@ -2914,9 +2921,12 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr raise_exception_ra(env, EXCP0D_GPF, ra); } + access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), + MMU_DATA_LOAD, ra); + if (rfbm & XSTATE_FP_MASK) { if (xstate_bv & XSTATE_FP_MASK) { - do_xrstor_fpu(env, ptr, ra); + do_xrstor_fpu(&ac, ptr); } else { do_fninit(env); memset(env->fpregs, 0, sizeof(env->fpregs)); @@ -2925,9 +2935,9 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr if (rfbm & XSTATE_SSE_MASK) { /* Note that the standard form of XRSTOR loads MXCSR from memory whether or not the XSTATE_BV bit is set. */ - do_xrstor_mxcsr(env, ptr, ra); + do_xrstor_mxcsr(&ac, ptr); if (xstate_bv & XSTATE_SSE_MASK) { - do_xrstor_sse(env, ptr, ra); + do_xrstor_sse(&ac, ptr); } else { do_clear_sse(env); } From patchwork Wed May 15 15:08:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796970 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033340wra; Wed, 15 May 2024 08:11:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCULB2bVsJqIuY1fBdYeLnCobTlnkABROJZhTkHzA29VNxq1F/Yc7zESgje6OtfLWSdgvL5oUyGdVYTyqxYHpWRG X-Google-Smtp-Source: AGHT+IHhPQSkyA3kmyRd/Tdk5GHh4oALE9JaZk4mrXkauQTKU4Sf5fxg+8JGBBUaFsX235o4P42N X-Received: by 2002:a05:6122:1da8:b0:4d8:7339:4c35 with SMTP id 71dfb90a1353d-4df88367d77mr13114705e0c.13.1715785879723; Wed, 15 May 2024 08:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785879; cv=none; d=google.com; s=arc-20160816; b=b8Irf2hjXyEK3wAelhdQfbslfCp1e3w4xQwh3cJldsCqdJ0jXKIvDaDMibipxsKhzm jQbBDWlZsILzHMgWyQ1wS/A+Ww9Nn7cRHD3y422fa0hUmvqWN6ggVyRVxZcgK3JMqoPF zotIXP51lO0LHTh07laxbSpPveSeIG7MjLCKcq03CBa5vC+xJXtvh9XuhcfeAwoPl6oK 4XKcgIlljo20LEJNld+LzZnANQk0oO50dYOshpqxYPemWmWVbmLWpmPjvoEjYG1eT0Pk tJE/IAZotuzley2OALol4ngWMx8nmv9azoprpR3siCM2OaIJFPdj8CAZA9J/uKo9ARpc Mtsw== 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=P6MuOwzw42ZKpRW8ddJXISHZONVvscEtylHvzBQmNeY=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=Wc6k4uLlkJuSftwy2HEtnkNm68PBG9PY06j/N6juM9HBt6kfPTGrmwh2xAktRkLwpR 66HjMb4Zf7TvoEAMHZ2vqcEF/yhTw8UrF9BIGMBIIwI5lLdP2PCBykNrKdIQO6+LArli Z4rKIuqtrAe4r/MKvuyrSfnYG5INQR+dNl/u0q75BLWf+T8TrHYZHrfmxj0UpLD3beGe FaGcFtXonG7a5+PDNfWeoGu2ftR9VjmXXKnlq9bFoNPOHYYIqjxannyqPoejokmE/8Qz VxkxbHD7m7PDGLqOu5fStbyCUkHhzZeTYvzd9b6BUgWCD/Fxr2nc0SWzK7/8CJ4PI9nK +JvA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rxd81C5P; 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=pass (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 71dfb90a1353d-4df7bf4b0f2si2198030e0c.24.2024.05.15.08.11.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:19 -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=pass header.i=@linaro.org header.s=google header.b=Rxd81C5P; 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=pass (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 1s7GFd-0003xx-Ml; Wed, 15 May 2024 11:09:05 -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 1s7GFY-0003vg-9d for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:01 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFM-0002qU-OZ for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:59 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4200ee78f34so31969215e9.3 for ; Wed, 15 May 2024 08:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785727; x=1716390527; 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=P6MuOwzw42ZKpRW8ddJXISHZONVvscEtylHvzBQmNeY=; b=Rxd81C5PmnDnu/YTU3S89svF6GWAHRUfyrp2n1ijvLJUn8XAg1ydr9aqegSL3mqMXw nQyP/rcyimqLbP2fl6a67U3Pzi8r1TLI4VK6PLNd30mInfxdbymDBbVMIePgcpJc8fPV 9Nnnqxi9kQIhtIdZC83omWS8IrIeW+yE2jEhhjKzOxEx45NECsJ/nCZEfL1bVMcudrH7 CJQ+0W4gaqXEvjBqF71IV79ZVzvzm7M+m4oKdodVONXAv016yHF0pDq5yyIkl3t8e3QV xl+DwmZ+fW0r7s9pcaBFK9OfrgwhFB55842qCDDyo2/DSONMGdlXPA/VZyEYXhv8CqYI NWEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785727; x=1716390527; 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=P6MuOwzw42ZKpRW8ddJXISHZONVvscEtylHvzBQmNeY=; b=saQSuTM7sYlFkjyH/3083nG+Yk/NVmsz4JBwD7zUg65LSwDUS5+dm1c5ZwWVpnrdQr 8PV6tUUMjc7qtcceujAIfhLSscFbSzqh44QP4NOYTtzZWAjeoyW4fMJ0yIpLElx267WO kaMraBXMjbd+oBnouFUQlCueq8uqUgEkmA31PHKtBeT0pikHasVu8QtOjSf1NbwysgOt s2bvZ9QDcOS8U3ms+rM1OnPcPWOQi5NWY5Et0dUJupnFSsN5yMjb6b79Kj1Rp8gArSkv QtH1XxSmH+W5HhJGUwRwEF6G8T8O59kxOQi4nIcpnAOlMwTG8Aptg/Y9EGaeG3nScR6v gNQw== X-Gm-Message-State: AOJu0Yzaoq9uqvBo+I8L7nCllW4zkd02M8WlVoeOPmD0nV68ejsPWVKf DJtG+OqOKeG2e/mJvurLG/KJXcfttkQbTF3jjmiffzUzMCXN+VTFhKxSh4/fN3MwQrbYckh4zB3 ayk0= X-Received: by 2002:a05:600c:3ca0:b0:41e:ae29:c807 with SMTP id 5b1f17b1804b1-41feac59cbfmr105771755e9.29.1715785727184; Wed, 15 May 2024 08:08:47 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 09/28] tagret/i386: Convert do_fxsave, do_fxrstor to X86Access Date: Wed, 15 May 2024 17:08:18 +0200 Message-Id: <20240515150837.259747-10-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::336; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x336.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, 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 Move the alignment fault from do_* to helper_*, as it need not apply to usage from within user-only signal handling. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 84 ++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index f21cdb45ea..4dcb0b92ff 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2619,8 +2619,25 @@ static void do_xsave_pkru(CPUX86State *env, target_ulong ptr, uintptr_t ra) cpu_stq_data_ra(env, ptr, env->pkru, ra); } -static void do_fxsave(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_fxsave(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; + + do_xsave_fpu(ac, ptr); + if (env->cr[4] & CR4_OSFXSR_MASK) { + do_xsave_mxcsr(ac, ptr); + /* Fast FXSAVE leaves out the XMM registers */ + if (!(env->efer & MSR_EFER_FFXSR) + || (env->hflags & HF_CPL_MASK) + || !(env->hflags & HF_LMA_MASK)) { + do_xsave_sse(ac, ptr); + } + } +} + +void helper_fxsave(CPUX86State *env, target_ulong ptr) +{ + uintptr_t ra = GETPC(); X86Access ac; /* The operand must be 16 byte aligned */ @@ -2630,22 +2647,7 @@ static void do_fxsave(CPUX86State *env, target_ulong ptr, uintptr_t ra) access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), MMU_DATA_STORE, ra); - do_xsave_fpu(&ac, ptr); - - if (env->cr[4] & CR4_OSFXSR_MASK) { - do_xsave_mxcsr(&ac, ptr); - /* Fast FXSAVE leaves out the XMM registers */ - if (!(env->efer & MSR_EFER_FFXSR) - || (env->hflags & HF_CPL_MASK) - || !(env->hflags & HF_LMA_MASK)) { - do_xsave_sse(&ac, ptr); - } - } -} - -void helper_fxsave(CPUX86State *env, target_ulong ptr) -{ - do_fxsave(env, ptr, GETPC()); + do_fxsave(&ac, ptr); } static uint64_t get_xinuse(CPUX86State *env) @@ -2850,8 +2852,25 @@ static void do_xrstor_pkru(CPUX86State *env, target_ulong ptr, uintptr_t ra) env->pkru = cpu_ldq_data_ra(env, ptr, ra); } -static void do_fxrstor(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_fxrstor(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; + + do_xrstor_fpu(ac, ptr); + if (env->cr[4] & CR4_OSFXSR_MASK) { + do_xrstor_mxcsr(ac, ptr); + /* Fast FXRSTOR leaves out the XMM registers */ + if (!(env->efer & MSR_EFER_FFXSR) + || (env->hflags & HF_CPL_MASK) + || !(env->hflags & HF_LMA_MASK)) { + do_xrstor_sse(ac, ptr); + } + } +} + +void helper_fxrstor(CPUX86State *env, target_ulong ptr) +{ + uintptr_t ra = GETPC(); X86Access ac; /* The operand must be 16 byte aligned */ @@ -2861,22 +2880,7 @@ static void do_fxrstor(CPUX86State *env, target_ulong ptr, uintptr_t ra) access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), MMU_DATA_LOAD, ra); - do_xrstor_fpu(&ac, ptr); - - if (env->cr[4] & CR4_OSFXSR_MASK) { - do_xrstor_mxcsr(&ac, ptr); - /* Fast FXRSTOR leaves out the XMM registers */ - if (!(env->efer & MSR_EFER_FFXSR) - || (env->hflags & HF_CPL_MASK) - || !(env->hflags & HF_LMA_MASK)) { - do_xrstor_sse(&ac, ptr); - } - } -} - -void helper_fxrstor(CPUX86State *env, target_ulong ptr) -{ - do_fxrstor(env, ptr, GETPC()); + do_fxrstor(&ac, ptr); } static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr_t ra) @@ -3008,12 +3012,20 @@ void cpu_x86_frstor(CPUX86State *env, target_ulong ptr, int data32) void cpu_x86_fxsave(CPUX86State *env, target_ulong ptr) { - do_fxsave(env, ptr, 0); + X86Access ac; + + access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), + MMU_DATA_STORE, 0); + do_fxsave(&ac, ptr); } void cpu_x86_fxrstor(CPUX86State *env, target_ulong ptr) { - do_fxrstor(env, ptr, 0); + X86Access ac; + + access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), + MMU_DATA_LOAD, 0); + do_fxrstor(&ac, ptr); } void cpu_x86_xsave(CPUX86State *env, target_ulong ptr) From patchwork Wed May 15 15:08:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796971 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033394wra; Wed, 15 May 2024 08:11:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX3WwpdZ8H0VDr/GHKzoiAF8wdUVKpXQAqF9Px3RtmKKq1Nvy0oafoBWZgsx8DuR1if2rewpYY96oo2DHRwri0u X-Google-Smtp-Source: AGHT+IHtbsR9E8TRzt19d9PwB87GF8pWPv6m4gVfF1T73JllqbhybhmCHQcW76MuUwZzrRHmL1G4 X-Received: by 2002:a05:6122:992:b0:4d4:11a6:a4ff with SMTP id 71dfb90a1353d-4df8829db54mr14391083e0c.3.1715785883672; Wed, 15 May 2024 08:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785883; cv=none; d=google.com; s=arc-20160816; b=nWLI67HImtLUGI0vLZVRngjR0NPTAI+IJ3l7IAn+lkppyF5qKLqpPZtQp4gbCVRJ25 6zFFO5AjG39QqSSy/BtG9KzrPH1WxkGkCUTAwl79tGRgK9ofl/+E9rND+xTyB1o/BG1S shMg101/JbSwkYqVysMyJ8bG8cGZiI015oYq9lpUID7zpqyylpFr0LDuh2qtVvJB0XfL aZWoAu9n7LJd95UQkFfR/aNJcdX5QWJvLB9KvvbdqXWtHz8k7pkjPoSw8nl80TRs8E0Y rr7UwAMHoHDurdIzr4zo4swWtKgPiEZfxTsDUFRyiNJlLvgUwbbEjdkETLvlppd/fXIj 6fBg== 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=8W7kdXBVphE/G8J+gJEIX1gz3O6+dJRyyNI2VZW5z4A=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=pO4VV2wmJONRpDKj7LBSMEjw0vb63aQzRFd0j4jjcJIQMbIYhy2ObKM+3Tz4u/Gk7o SsUySsqYIi7fnykpC9VAHKQ9U7kgdP0jUYRwOsRY1Dho84l4T+3rf3OXUwHaGQcRBJEt qo0+z5sHV2Fw5qGDLHjvICzaJrTVzGs404FMC9YEGFm7MBXY0+wGxbbQgqzpIa9r54Xu d7WtSV4TWGn6QNualeWBamOWBUTYta+wRjfrTa1IcGVcmPcuSfOavVAXD+y5jgk+t6Eb dpd9u8xGVZI4iE371n+bkxtw+nfF7WngxaCw3UGXod2o5GV4HLv3wYE/n08TlajP94SB lt2g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MT8p7SnF; 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=pass (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 71dfb90a1353d-4df7c07f044si2427974e0c.193.2024.05.15.08.11.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:23 -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=pass header.i=@linaro.org header.s=google header.b=MT8p7SnF; 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=pass (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 1s7GFS-0003tO-FN; Wed, 15 May 2024 11:08:54 -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 1s7GFP-0003rs-8a for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:51 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFN-0002qd-EE for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:50 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-41dc9c83e57so45366995e9.0 for ; Wed, 15 May 2024 08:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785728; x=1716390528; 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=8W7kdXBVphE/G8J+gJEIX1gz3O6+dJRyyNI2VZW5z4A=; b=MT8p7SnF6YcdPyP2SRVhF7e3k2T7a3ndnZZdaXC9O8tdaYWwbhE+47NcukEzbkm6Qb 9v+nn7xwvdIEnjz7IP+JHmjc6zrwO78qqUKrHXvzbtZ4V2hE7mF7cij5wDlueJ71TCqd sNcEm0zrcYGkXwwXcGP2wLZIaec3qEgQQtMJ5B/LvSw7dn0K4M2o5zn1Y9OFmSH7mDUe bVRlN6k9Davz0OD8tCXg1Q1FVi9S0u7Dw5z6gEn36jLCmerwSti9ezY4l9PJUgz41LMZ srrtx4UUFWhcjJU0Ery10nvqe4v4aDUqgsJVVGoLqm62tzb7veB7t2jhkWcJwUlH3/2q xSRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785728; x=1716390528; 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=8W7kdXBVphE/G8J+gJEIX1gz3O6+dJRyyNI2VZW5z4A=; b=feag4mSshcN/LEFp7si1K57SHu2IB3kLBatje1cX5DJ8h9TKebJXFiRu7HaAOcHmPi kipWB0deQkCI+uTzHaZpNLSN2OlK2Cv/7uO0IU/pMJJGlRLMsWOehAx0sXre8xwkfCB5 PhHP/EgEfTA1BE8Qkc2/47PYAEF+tPo9/X/sgPqoFXGuNlkBpAtIWTVgqTakpZ+O9xQ1 e6fJAeE9S3fNq4zTA1Ct8t/OKMR1lBxOvixR//zMHSBGXqqvc38S1cxSpDGFBjsP3DET ZaYxDLqGq2RAQLSJecgB6I5/qLfBSXzzYejwYZ9/qiUexVOXALoz5hbSPY/pfr9NX5hD tGwQ== X-Gm-Message-State: AOJu0Yw/l0IrTlZzndTRMTjbjSG2W3XI4WJrpDLW9O5yQRQRs2mehdPT ixYhmNGmubBVPNy8IAim33brzsKnTTRB+c0Ad6dR9BL4B0dlr3IkWVWSUr1VpSR5+BeeqPHKKKd NQxk= X-Received: by 2002:a05:600c:3c83:b0:41b:8041:53c2 with SMTP id 5b1f17b1804b1-41feac51e04mr161177545e9.15.1715785727847; Wed, 15 May 2024 08:08:47 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 10/28] target/i386: Convert do_xsave_* to X86Access Date: Wed, 15 May 2024 17:08:19 +0200 Message-Id: <20240515150837.259747-11-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::32c; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32c.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 The body of do_xsave is now fully converted. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 4dcb0b92ff..356397a4ab 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2579,8 +2579,9 @@ static void do_xsave_sse(X86Access *ac, target_ulong ptr) } } -static void do_xsave_ymmh(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_ymmh(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; int i, nb_xmm_regs; if (env->hflags & HF_CS64_MASK) { @@ -2590,33 +2591,36 @@ static void do_xsave_ymmh(CPUX86State *env, target_ulong ptr, uintptr_t ra) } for (i = 0; i < nb_xmm_regs; i++, ptr += 16) { - cpu_stq_data_ra(env, ptr, env->xmm_regs[i].ZMM_Q(2), ra); - cpu_stq_data_ra(env, ptr + 8, env->xmm_regs[i].ZMM_Q(3), ra); + access_stq(ac, ptr, env->xmm_regs[i].ZMM_Q(2)); + access_stq(ac, ptr + 8, env->xmm_regs[i].ZMM_Q(3)); } } -static void do_xsave_bndregs(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_bndregs(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; target_ulong addr = ptr + offsetof(XSaveBNDREG, bnd_regs); int i; for (i = 0; i < 4; i++, addr += 16) { - cpu_stq_data_ra(env, addr, env->bnd_regs[i].lb, ra); - cpu_stq_data_ra(env, addr + 8, env->bnd_regs[i].ub, ra); + access_stq(ac, addr, env->bnd_regs[i].lb); + access_stq(ac, addr + 8, env->bnd_regs[i].ub); } } -static void do_xsave_bndcsr(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_bndcsr(X86Access *ac, target_ulong ptr) { - cpu_stq_data_ra(env, ptr + offsetof(XSaveBNDCSR, bndcsr.cfgu), - env->bndcs_regs.cfgu, ra); - cpu_stq_data_ra(env, ptr + offsetof(XSaveBNDCSR, bndcsr.sts), - env->bndcs_regs.sts, ra); + CPUX86State *env = ac->env; + + access_stq(ac, ptr + offsetof(XSaveBNDCSR, bndcsr.cfgu), + env->bndcs_regs.cfgu); + access_stq(ac, ptr + offsetof(XSaveBNDCSR, bndcsr.sts), + env->bndcs_regs.sts); } -static void do_xsave_pkru(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xsave_pkru(X86Access *ac, target_ulong ptr) { - cpu_stq_data_ra(env, ptr, env->pkru, ra); + access_stq(ac, ptr, ac->env->pkru); } static void do_fxsave(X86Access *ac, target_ulong ptr) @@ -2669,6 +2673,7 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, { uint64_t old_bv, new_bv; X86Access ac; + unsigned size; /* The OS must have enabled XSAVE. */ if (!(env->cr[4] & CR4_OSXSAVE_MASK)) { @@ -2684,8 +2689,8 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, rfbm &= env->xcr0; opt &= rfbm; - access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), - MMU_DATA_STORE, ra); + size = xsave_area_size(opt, false); + access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, ra); if (opt & XSTATE_FP_MASK) { do_xsave_fpu(&ac, ptr); @@ -2698,22 +2703,22 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, do_xsave_sse(&ac, ptr); } if (opt & XSTATE_YMM_MASK) { - do_xsave_ymmh(env, ptr + XO(avx_state), ra); + do_xsave_ymmh(&ac, ptr + XO(avx_state)); } if (opt & XSTATE_BNDREGS_MASK) { - do_xsave_bndregs(env, ptr + XO(bndreg_state), ra); + do_xsave_bndregs(&ac, ptr + XO(bndreg_state)); } if (opt & XSTATE_BNDCSR_MASK) { - do_xsave_bndcsr(env, ptr + XO(bndcsr_state), ra); + do_xsave_bndcsr(&ac, ptr + XO(bndcsr_state)); } if (opt & XSTATE_PKRU_MASK) { - do_xsave_pkru(env, ptr + XO(pkru_state), ra); + do_xsave_pkru(&ac, ptr + XO(pkru_state)); } /* Update the XSTATE_BV field. */ - old_bv = cpu_ldq_data_ra(env, ptr + XO(header.xstate_bv), ra); + old_bv = access_ldq(&ac, ptr + XO(header.xstate_bv)); new_bv = (old_bv & ~rfbm) | (inuse & rfbm); - cpu_stq_data_ra(env, ptr + XO(header.xstate_bv), new_bv, ra); + access_stq(&ac, ptr + XO(header.xstate_bv), new_bv); } void helper_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) From patchwork Wed May 15 15:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796986 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034825wra; Wed, 15 May 2024 08:13:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUNUt4e5hR058PiOsdimdVPA7p9YHtT96tBqtl+bwlRferU+7rRnOkDB/ey4BYO+gelyOtn9ktDNSaEVgYYP1Og X-Google-Smtp-Source: AGHT+IFJMwmnvgkezwqB+F5OqSGy/rzjdYs+DuUnW4z5t38Zo0j/xpwS2jS8H/PcZYbndXefp1Bd X-Received: by 2002:a25:ef4c:0:b0:de5:c1a4:560c with SMTP id 3f1490d57ef6-dee4f50630emr18664003276.56.1715786022048; Wed, 15 May 2024 08:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715786022; cv=none; d=google.com; s=arc-20160816; b=Sz+bSD/lCQNkMzwqlfZ/lFw1Wo5Xd7YOsJ+6W/H5TYOwWUGKh2hSRLeQT7xM/J4haS AW/+biPoaUNWlePQmhMgZ5IosiJPOyRtl6iy9uUKx5g2qFiwdQjqzh8VExSq5+fI+UrB 09VDj15G8GJHpGwkJGARFFGVggCAutFKUw0VsnisQqIlHWlgUvvpwB1Tjgmp8CAekGXk DMDEp6ybnYRSD6N86xD3j28NA6whLn2VgqhS1N8ZFgLOW/eh7XhUseH2Wqgl+t37ubiT 6zYf9hUxy0Nla3MmbILqJhmNhHg78LzXm+xPigf6IfvR2Mha6fsX0odynjR6xuT3nsvd 2uUw== 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=C6S9A0jxcxnkPHJaqWqoqo+edkANvVkLpXEGqNBGzxw=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=JGjKRkBg10xCVsN+Bdsz+vS7O6QjPQWi36uQyPjQLy2ZqTFVaWeR0OXh5ZDzql0dvN ciE5FdjAq8wgTD5TxctsIbegUFlJhhl//ZGMZQsXwkimYmrrlyK5b+f220pecBKSolYm SqwHSQQvNNvD6FE831leNO07FzJdWDKE+pKX5uPEwfmZWfA1ofKzcrgm9a7Y0fZjtU6s ozElkCMLx9OwH3aIaKNnBgWLHv0tUYejD0+P8zgxunpd9X8H5ajitMwR7n+DFs1kHK/y BbDySmO0wOT+Ug1sc2dKnf08bQuf18pG+RRAarDXr3it7eJMtxRWgkbuhHnhMcCbJzwa yQpQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k2yITbFI; 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=pass (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 a1e0cc1a2514c-7f8ffec6eb1si2213595241.122.2024.05.15.08.13.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:13:42 -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=pass header.i=@linaro.org header.s=google header.b=k2yITbFI; 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=pass (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 1s7GFe-0003y7-5X; Wed, 15 May 2024 11:09:06 -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 1s7GFb-0003wD-QE for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFN-0002qw-SI for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:02 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-41ffad2426eso53208795e9.3 for ; Wed, 15 May 2024 08:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785728; x=1716390528; 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=C6S9A0jxcxnkPHJaqWqoqo+edkANvVkLpXEGqNBGzxw=; b=k2yITbFI/7OwAtb68bTKRPHLiL7JWqxO1U3JbAxEwpeoj2cMARUmsiy9Iixv2weu+C dyXyQd3lbx9OUbF8JaaVcY1ay/AMY6lO5djZiQbhjWkn6LS4LObiR6QUIRwT5kW5u051 x1wSvIzk2I43VIK9QHT/O9U/0wdcQJd18gqv1aGIUdq7OQTJ3lwPka2RyCL0LlVZwb+X YTlPGIKJ0+YEX69eNhL683fT8ZaQEgL7lm2H2fxXnROa9iD0cqDStDn+qM/ekWtslG7I O7QikZflh9mYY7aq/aca2m0tT/GtfSFtZjP/c5+egoiPiUP9SsMUXIyQNFp1k4KWTRN6 bJmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785728; x=1716390528; 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=C6S9A0jxcxnkPHJaqWqoqo+edkANvVkLpXEGqNBGzxw=; b=ZHAvUZicJRL7MC0dZR98THO2mWuNGEgh2A15BCkeA8HjtXpmBQsrKuFq+ULjuhwy4Y 4rpvBY3FkZJQ+Gjx706/RBwSrnzYRKyy2M4j+FeCmPGblD20cKOUrZQ/xWi7DtWNu6JN rJxTQT1CcwjR2D9VBVcJY3de2H9yWYMsZchZWAFXgf2pEHv7DsGxNWTJ9aiMjby/yHaL 6vWNgNTm4OOFo1wAvLwHUG8cWDlz3r0lOF9D9MOJgvDJm2CClN5RrMFZ4Df9vTTyVIL4 OYJx0DSrREobG2XZb4i5+cStahk7s1Lp+lg/Ize5XPfDwX4tB9doW/L8Zw2GdJZCmPWO CKDw== X-Gm-Message-State: AOJu0YxLEvrvOrGarqmHw/0HyBTHF0nRUKYpJDJMRIvL7HPIt3DfXabx a2e89wCFAG1m8U0Ry/QsLGJSg1QjYNzUwye9OaimrwbQOWZJ08wVKKnYdKzskz6rcnrzY0h+aXb s+2o= X-Received: by 2002:a05:600c:26cc:b0:418:4aac:a576 with SMTP id 5b1f17b1804b1-41fead64fdemr151824865e9.39.1715785728563; Wed, 15 May 2024 08:08:48 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 11/28] target/i386: Convert do_xrstor_* to X86Access Date: Wed, 15 May 2024 17:08:20 +0200 Message-Id: <20240515150837.259747-12-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::330; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x330.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 The body of do_xrstor is now fully converted. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 51 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 356397a4ab..7796688514 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2800,8 +2800,9 @@ static void do_clear_sse(CPUX86State *env) } } -static void do_xrstor_ymmh(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_ymmh(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; int i, nb_xmm_regs; if (env->hflags & HF_CS64_MASK) { @@ -2811,8 +2812,8 @@ static void do_xrstor_ymmh(CPUX86State *env, target_ulong ptr, uintptr_t ra) } for (i = 0; i < nb_xmm_regs; i++, ptr += 16) { - env->xmm_regs[i].ZMM_Q(2) = cpu_ldq_data_ra(env, ptr, ra); - env->xmm_regs[i].ZMM_Q(3) = cpu_ldq_data_ra(env, ptr + 8, ra); + env->xmm_regs[i].ZMM_Q(2) = access_ldq(ac, ptr); + env->xmm_regs[i].ZMM_Q(3) = access_ldq(ac, ptr + 8); } } @@ -2832,29 +2833,32 @@ static void do_clear_ymmh(CPUX86State *env) } } -static void do_xrstor_bndregs(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_bndregs(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; target_ulong addr = ptr + offsetof(XSaveBNDREG, bnd_regs); int i; for (i = 0; i < 4; i++, addr += 16) { - env->bnd_regs[i].lb = cpu_ldq_data_ra(env, addr, ra); - env->bnd_regs[i].ub = cpu_ldq_data_ra(env, addr + 8, ra); + env->bnd_regs[i].lb = access_ldq(ac, addr); + env->bnd_regs[i].ub = access_ldq(ac, addr + 8); } } -static void do_xrstor_bndcsr(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_bndcsr(X86Access *ac, target_ulong ptr) { + CPUX86State *env = ac->env; + /* FIXME: Extend highest implemented bit of linear address. */ env->bndcs_regs.cfgu - = cpu_ldq_data_ra(env, ptr + offsetof(XSaveBNDCSR, bndcsr.cfgu), ra); + = access_ldq(ac, ptr + offsetof(XSaveBNDCSR, bndcsr.cfgu)); env->bndcs_regs.sts - = cpu_ldq_data_ra(env, ptr + offsetof(XSaveBNDCSR, bndcsr.sts), ra); + = access_ldq(ac, ptr + offsetof(XSaveBNDCSR, bndcsr.sts)); } -static void do_xrstor_pkru(CPUX86State *env, target_ulong ptr, uintptr_t ra) +static void do_xrstor_pkru(X86Access *ac, target_ulong ptr) { - env->pkru = cpu_ldq_data_ra(env, ptr, ra); + ac->env->pkru = access_ldq(ac, ptr); } static void do_fxrstor(X86Access *ac, target_ulong ptr) @@ -2892,6 +2896,7 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr { uint64_t xstate_bv, xcomp_bv, reserve0; X86Access ac; + unsigned size, size_ext; rfbm &= env->xcr0; @@ -2905,7 +2910,10 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr raise_exception_ra(env, EXCP0D_GPF, ra); } - xstate_bv = cpu_ldq_data_ra(env, ptr + XO(header.xstate_bv), ra); + size = sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader); + access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, ra); + + xstate_bv = access_ldq(&ac, ptr + XO(header.xstate_bv)); if ((int64_t)xstate_bv < 0) { /* FIXME: Compact form. */ @@ -2924,14 +2932,17 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr describes only XCOMP_BV, but the description of the standard form of XRSTOR (Vol 1, Sec 13.8.1) checks bytes 23:8 for zero, which includes the next 64-bit field. */ - xcomp_bv = cpu_ldq_data_ra(env, ptr + XO(header.xcomp_bv), ra); - reserve0 = cpu_ldq_data_ra(env, ptr + XO(header.reserve0), ra); + xcomp_bv = access_ldq(&ac, ptr + XO(header.xcomp_bv)); + reserve0 = access_ldq(&ac, ptr + XO(header.reserve0)); if (xcomp_bv || reserve0) { raise_exception_ra(env, EXCP0D_GPF, ra); } - access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), - MMU_DATA_LOAD, ra); + size_ext = xsave_area_size(rfbm & xstate_bv, false); + if (size < size_ext) { + /* TODO: See if existing page probe has covered extra size. */ + access_prepare(&ac, env, ptr, size_ext, MMU_DATA_LOAD, ra); + } if (rfbm & XSTATE_FP_MASK) { if (xstate_bv & XSTATE_FP_MASK) { @@ -2953,14 +2964,14 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr } if (rfbm & XSTATE_YMM_MASK) { if (xstate_bv & XSTATE_YMM_MASK) { - do_xrstor_ymmh(env, ptr + XO(avx_state), ra); + do_xrstor_ymmh(&ac, ptr + XO(avx_state)); } else { do_clear_ymmh(env); } } if (rfbm & XSTATE_BNDREGS_MASK) { if (xstate_bv & XSTATE_BNDREGS_MASK) { - do_xrstor_bndregs(env, ptr + XO(bndreg_state), ra); + do_xrstor_bndregs(&ac, ptr + XO(bndreg_state)); env->hflags |= HF_MPX_IU_MASK; } else { memset(env->bnd_regs, 0, sizeof(env->bnd_regs)); @@ -2969,7 +2980,7 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr } if (rfbm & XSTATE_BNDCSR_MASK) { if (xstate_bv & XSTATE_BNDCSR_MASK) { - do_xrstor_bndcsr(env, ptr + XO(bndcsr_state), ra); + do_xrstor_bndcsr(&ac, ptr + XO(bndcsr_state)); } else { memset(&env->bndcs_regs, 0, sizeof(env->bndcs_regs)); } @@ -2978,7 +2989,7 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr if (rfbm & XSTATE_PKRU_MASK) { uint64_t old_pkru = env->pkru; if (xstate_bv & XSTATE_PKRU_MASK) { - do_xrstor_pkru(env, ptr + XO(pkru_state), ra); + do_xrstor_pkru(&ac, ptr + XO(pkru_state)); } else { env->pkru = 0; } From patchwork Wed May 15 15:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796965 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032886wra; Wed, 15 May 2024 08:10:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXLkEz+F806VXbDh8+013KCXpOsiRw1k9B4RH2KYdj4c8wvg3tJkjyO2e821mvJ3dbJJWKDEfFgp0Gu+8R66qVA X-Google-Smtp-Source: AGHT+IEy+SFPU2Hlk3ojgRS2oelvsrf+8pFD/Z0BH91C+jaNVECilfkykmaDEQlsOhCYVI9zguTp X-Received: by 2002:a05:6808:424b:b0:3c5:eed2:e244 with SMTP id 5614622812f47-3c99706da4bmr19768935b6e.30.1715785838295; Wed, 15 May 2024 08:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785838; cv=none; d=google.com; s=arc-20160816; b=Yp6OfUP1c1fqEUwqM0STB0Yj8Rj31XqqAyLOud0Fd9hwFNM+gy4+9ymKS8N/PqlxRt ykyy+lLFXqG+utiO+c3lL/KkVUg3nZLrB28A4iKC+9HGrRbYgVzDxNkhgUBxyVouFj8M O5NMR+FpZM6MPpT5N8lu4IgCfVZk19MlnmugONDoUR+p3hVScliJOt8bx96iHHiKbq1b boVVTxDM9nyJJfi6oxSFUySZZeYDsmT6C8oXZBBPIDWh3NssF/RCjh/7C0YAo8OTuUno 0rpdhY+IEK/406QdVqvIdhOX/TIbZOF+Ui16PDXOeBzpnKdA8/7PKqgNjtnFvex/ujNY FXCw== 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=3VUA0H1FqSwLKp/HJjCgFsX8ntjk+Qvs0JjKKwjJR0Q=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=v2H5vSjBcpIMQOc7nHXBrWA78hi7PlP4vBK6S08NfpXtsU3JVyQkleqzEciFg7ylF6 +OovZwDKRr1MfxUm4aFOMP2Ja4Vr2ojzVvvJtkDVe0Nw5sHTThpfU0ihnxFPj2UB1p0M HBNuUjlS4EwdvT2U3U/bgU81QyH3gbEzhpqjFGN5adcwHDIJLQXyWMzgwRzBzF3ez1Yi 2uDUSKdxHKRDgpvIoeEvhmiUmXyj53zj7R3/5PVCt9xL7Bm9a6lTZjQxU90tvf1ycymi yLQIkOkld2teeAI/kK3NvfzqGBPoA/dBmAnKJ0o8wAX26w90Kotl6sjdnI5fzk6vO9dt dnIA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L8Ilm2h4; 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=pass (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 a1e0cc1a2514c-7f9000e329asi2366698241.149.2024.05.15.08.10.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:10:38 -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=pass header.i=@linaro.org header.s=google header.b=L8Ilm2h4; 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=pass (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 1s7GFU-0003tw-3i; Wed, 15 May 2024 11:08:56 -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 1s7GFR-0003sm-1L for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:53 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFO-0002r6-NR for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:52 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4200ee78f35so32760365e9.1 for ; Wed, 15 May 2024 08:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785729; x=1716390529; 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=3VUA0H1FqSwLKp/HJjCgFsX8ntjk+Qvs0JjKKwjJR0Q=; b=L8Ilm2h49TQ6ZdSlbGTEWjoeBaJR32Ny+tQ+M2jpgbzXU5XLCSJtincGC2NdFRoCFk HRD7Vnx3BNoveIlRQP94sktI/JRV5hxCLHYWd185nYNfqmbRjbJlmuOfnkSkIZSfPUc4 MH9l+oz4UcLyhSAo7iIVjdUoLxJq+4vELbuS4gDXL3H5Il+X+TLOHH/D6N4gM65dIyzQ 2B87PxgSE1EoOLjUSgeldlrjVIvJQwkUiRHcp9qNIzfCbiQb66U7f7BxIxl88TkFxalt rTDEQn6VZLTkqHHgk8wgd2OiqCZld45LIhWKvgIt0oScmNfI78MIaa7Ahr3MV1WJFzdx v3yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785729; x=1716390529; 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=3VUA0H1FqSwLKp/HJjCgFsX8ntjk+Qvs0JjKKwjJR0Q=; b=DwaHWK8SR0cA3n5bWUT1Ng7S1HRA/gcZe1Kk1uQTFu0BGur5arXMMgDCfRm7wnPJLE LxUsmdwz5UznVoLAlFe/XlxgTf4ZQLHihpKdHuciPl8tU754K+sjQ2XHY+7BWpzqO5Pq iYasEmzppUGd/tj3Rd43BCnyUkq7x6QB5ErM4jL78AWbgXYD1Bnzgb5Xc6OSZpZxA3xQ m164TKbzkA9FFcWs3hmRmgMWGDrjQkTnk0aHn277Dq6SKXD21xZL/uj4tBTQT3iWivLT 3aqypYu/oMwAVzP8Rkw4OVIAMbEJh9TC/5TjP/OLxqKx38QVVdIoAIOypx+MRvSR+bPJ zVpg== X-Gm-Message-State: AOJu0YxWZzhFOhXAs3UPalvTKDk1u2uqGGteRu6Iy5/yMrWwJE4oeioP aFbCwOQeqNhXk0+maCZDmECyL6c0U5HWiEdTr848jnDGDSiOiWZ5JmN8dl4GZcOvhiWsqWNwWd7 NC50= X-Received: by 2002:a05:600c:4f93:b0:416:7b2c:df0f with SMTP id 5b1f17b1804b1-41fea931f13mr153183665e9.7.1715785729255; Wed, 15 May 2024 08:08:49 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 12/28] target/i386: Split out do_xsave_chk Date: Wed, 15 May 2024 17:08:21 +0200 Message-Id: <20240515150837.259747-13-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::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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 This path is not required by user-only, and can in fact be shared between xsave and xrstor. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 51 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 7796688514..6a319dadf2 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2675,16 +2675,6 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, X86Access ac; unsigned size; - /* The OS must have enabled XSAVE. */ - if (!(env->cr[4] & CR4_OSXSAVE_MASK)) { - raise_exception_ra(env, EXCP06_ILLOP, ra); - } - - /* The operand must be 64 byte aligned. */ - if (ptr & 63) { - raise_exception_ra(env, EXCP0D_GPF, ra); - } - /* Never save anything not enabled by XCR0. */ rfbm &= env->xcr0; opt &= rfbm; @@ -2721,15 +2711,35 @@ static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, access_stq(&ac, ptr + XO(header.xstate_bv), new_bv); } +static void do_xsave_chk(CPUX86State *env, target_ulong ptr, uintptr_t ra) +{ + /* The OS must have enabled XSAVE. */ + if (!(env->cr[4] & CR4_OSXSAVE_MASK)) { + raise_exception_ra(env, EXCP06_ILLOP, ra); + } + + /* The operand must be 64 byte aligned. */ + if (ptr & 63) { + raise_exception_ra(env, EXCP0D_GPF, ra); + } +} + void helper_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - do_xsave(env, ptr, rfbm, get_xinuse(env), -1, GETPC()); + uintptr_t ra = GETPC(); + + do_xsave_chk(env, ptr, ra); + do_xsave(env, ptr, rfbm, get_xinuse(env), -1, ra); } void helper_xsaveopt(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - uint64_t inuse = get_xinuse(env); - do_xsave(env, ptr, rfbm, inuse, inuse, GETPC()); + uintptr_t ra = GETPC(); + uint64_t inuse; + + do_xsave_chk(env, ptr, ra); + inuse = get_xinuse(env); + do_xsave(env, ptr, rfbm, inuse, inuse, ra); } static void do_xrstor_fpu(X86Access *ac, target_ulong ptr) @@ -2900,16 +2910,6 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr rfbm &= env->xcr0; - /* The OS must have enabled XSAVE. */ - if (!(env->cr[4] & CR4_OSXSAVE_MASK)) { - raise_exception_ra(env, EXCP06_ILLOP, ra); - } - - /* The operand must be 64 byte aligned. */ - if (ptr & 63) { - raise_exception_ra(env, EXCP0D_GPF, ra); - } - size = sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader); access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, ra); @@ -3004,7 +3004,10 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - do_xrstor(env, ptr, rfbm, GETPC()); + uintptr_t ra = GETPC(); + + do_xsave_chk(env, ptr, ra); + do_xrstor(env, ptr, rfbm, ra); } #if defined(CONFIG_USER_ONLY) From patchwork Wed May 15 15:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796963 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032704wra; Wed, 15 May 2024 08:10:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXxUOUdJG/CMWN2CuRyW3J5lP+8hJVKygjDjpi6PMlh1a/G8ShjhsRWjgiC2rSZ24L+FOtZ86NZ22zAipB1d2Co X-Google-Smtp-Source: AGHT+IGeoncMWStX5rygkz3rncKl7BtO2ZZYbW5WSCYAfOmByRU35YBxXA7MAan3X0f8IEnVM2VW X-Received: by 2002:a05:6102:4e:b0:47b:d70c:ca9d with SMTP id ada2fe7eead31-48077e5b4abmr14754352137.29.1715785819813; Wed, 15 May 2024 08:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785819; cv=none; d=google.com; s=arc-20160816; b=gycr/JST8DPAOPIqUNssqQsh5mWekdXwqM4iISk5AEYugHBVE2bZPETb00vw9w81Dn nblC7lxVsKULnyk7NpJubf4bKLhVegiOphwbnYHn76YANhTru10llxuSHcX5pOL61jyO I0KHcjcz4a2v4AuomHgJAHIZ8UzWZrwv+pjRNJ9uOVJdxBIsXZfbwGi3neiKzeAc1mMk 0Je77VedOo5TkiFG5wZqascTX05jbI1q3SCwq0OUXlfyvfCBu8NP+CMEEsf9mfnjGUXs EI3uRXezZ+131Cw6G0ic8cfN0kMA6ukLeyHSi/NiiWe61SUtp6MYiBWjKNGHrf2d+r6Z 6OgA== 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=FHnvCE4341fC3oXgYRXMWSd0dFv09lREaQY4UssVvek=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=T+3UIyNs+KDYCXes8fD7t/Uo+ZrUlh8A+cFW3xp2+Y9zTpSvWdEEEBSYA8KlQlcoKR EtV6Cef2Bd0w87GGhkzAFFPcPpBDdhsKlxX4PlPfK/bxyDJOGqMeOO/GBCcYoRGspd+3 CFEPbRtgfJPKTgHXX2lHnU01O7H5mZ7TfJHVJX6JSqGnkHog/N3n0T4FKaPI52o1rxtX NlagKMvRd/ALfZ9tm7vXxsIyyNWM3A0vDjjEnR6vTM0vGlDUJgZtfMJozi0EmxcXsnxh YJ2RAJWqBfQg4tEgWmXr5rekskG85s3OS93ZI+lSC6KqtM2Why/wCUdspx8vS0XrkQt4 DjOg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iwHhNd3m; 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-4806cc8b76esi2723710137.551.2024.05.15.08.10.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:10:19 -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=iwHhNd3m; 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 1s7GFU-0003un-NL; Wed, 15 May 2024 11:08:56 -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 1s7GFT-0003tj-IG for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:55 -0400 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFQ-0002sk-Gk for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:55 -0400 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2e564cad1f6so64578881fa.1 for ; Wed, 15 May 2024 08:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785730; x=1716390530; 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=FHnvCE4341fC3oXgYRXMWSd0dFv09lREaQY4UssVvek=; b=iwHhNd3m5H55qU+OscEesgNzaB213f05a1EWr+PmiVjr13jI1VP4uH8Xp4QMAS53Vx VXmllyGzg09dTZVHraOleZuSLQNU8n/uqyjf/KKsJUC2cBUhu8NLCVTWTZtZtIKaOPj3 eHmzMA3d83Ezmu71rVd6rqTawKfKwSNvC4KqLYq6YWpfJefBnY5arR2yyG1WO9wqqxb3 f8wOGHHHkPe1yPcOZOl3AvJD0TbK8kglaRujQF2A8Aut6b+APeA5rfGyLpwZNxBB8aPZ XiqsshbjECy2jyCDSvHTJUsoX/beqm9Chz8oX11tpwrz1sjUvGpMHrt9sjrb/3mJHsFx PW2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785730; x=1716390530; 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=FHnvCE4341fC3oXgYRXMWSd0dFv09lREaQY4UssVvek=; b=lN2W+oXRFFlmj17bj9deM21/a2vVsdylLNcj/kFymWG4vFp3+biVxYtl2NGN9ydhU+ ynFKw2QXUBxyVOdQCg9PJZytDl0F764lPFEL8mB1xJJlW+h5vYter/u/Td+PMEOFZyTC tL4u0CZoYuoaa+TltjOFBJsxwQWy6/5hHOsgNyg2axklz0UIGpumErLPcpf+uVTUwrfx fRj1P6mdHAXONY/RJvNdZSdkI+KApYL+QgACLloOwpqTtL6wn9xbbmiEcJMpZLeWHWxj AL+X21+VB8hhTuR5d4iYCdzbQMeURO0mVElwDLlhVMPylA/VGOQP/+Me3MwSHJ809tdU eICg== X-Gm-Message-State: AOJu0Yyuq5DnUc70gKBsaKyC3ZtnC8MPgXnzJcuumVBjj1lk1W0Mn9Y+ T0sS2SZT0n2dbO1gPXEoPCTmamXn6X3mSp+QIIy1M2QrZY3PUjhp1sQuCZpqhCM+wFmtZwoKgVc j/FM= X-Received: by 2002:a2e:602:0:b0:2e5:3ea9:8d26 with SMTP id 38308e7fff4ca-2e53ea98d95mr83109231fa.45.1715785729966; Wed, 15 May 2024 08:08:49 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 13/28] target/i386: Add rbfm argument to cpu_x86_{xsave, xrstor} Date: Wed, 15 May 2024 17:08:22 +0200 Message-Id: <20240515150837.259747-14-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::22f; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x22f.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 For now, continue to pass all 1's from signal.c. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/cpu.h | 4 ++-- linux-user/i386/signal.c | 4 ++-- target/i386/tcg/fpu_helper.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index ccccb62fc3..97014b14ce 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2232,8 +2232,8 @@ 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_fxsave(CPUX86State *s, target_ulong ptr); void cpu_x86_fxrstor(CPUX86State *s, target_ulong ptr); -void cpu_x86_xsave(CPUX86State *s, target_ulong ptr); -void cpu_x86_xrstor(CPUX86State *s, target_ulong ptr); +void cpu_x86_xsave(CPUX86State *s, target_ulong ptr, uint64_t rbfm); +void cpu_x86_xrstor(CPUX86State *s, target_ulong ptr, uint64_t rbfm); /* cpu.c */ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 990048f42a..824375d42a 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -268,7 +268,7 @@ static void xsave_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs /* Zero the header, XSAVE *adds* features to an existing save state. */ memset(fxsave->xfeatures, 0, 64); - cpu_x86_xsave(env, fxsave_addr); + cpu_x86_xsave(env, fxsave_addr, -1); __put_user(TARGET_FP_XSTATE_MAGIC1, &fxsave->sw_reserved.magic1); __put_user(extended_size, &fxsave->sw_reserved.extended_size); __put_user(env->xcr0, &fxsave->sw_reserved.xfeatures); @@ -569,7 +569,7 @@ static int xrstor_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs return 1; } if (tswapl(*(uint32_t *) &fxsave->xfeatures[xfeatures_size]) == TARGET_FP_XSTATE_MAGIC2) { - cpu_x86_xrstor(env, fxsave_addr); + cpu_x86_xrstor(env, fxsave_addr, -1); return 0; } } diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 6a319dadf2..a09d6aaf07 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3047,14 +3047,14 @@ void cpu_x86_fxrstor(CPUX86State *env, target_ulong ptr) do_fxrstor(&ac, ptr); } -void cpu_x86_xsave(CPUX86State *env, target_ulong ptr) +void cpu_x86_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - do_xsave(env, ptr, -1, get_xinuse(env), -1, 0); + do_xsave(env, ptr, rfbm, get_xinuse(env), -1, 0); } -void cpu_x86_xrstor(CPUX86State *env, target_ulong ptr) +void cpu_x86_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - do_xrstor(env, ptr, -1, 0); + do_xrstor(env, ptr, rfbm, 0); } #endif From patchwork Wed May 15 15:08:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796977 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034165wra; Wed, 15 May 2024 08:12:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW3DPPUISbtqqlU+ez/YPCumNjeVL3CQvDAxC6VVwPg88JrmFnekYKD9atNba88TEDODkxpFhrSQZmWkWOi0lE/ X-Google-Smtp-Source: AGHT+IGOLxxZ8xbLzCHS/bVDs7sOzesUXmfNLsFQJ5+7PfPpzsjMTW5kd80Ck2VsGaMfZeB9uYe4 X-Received: by 2002:a05:6870:ac21:b0:23d:697:e8fd with SMTP id 586e51a60fabf-24172f6b5b4mr18937146fac.40.1715785954400; Wed, 15 May 2024 08:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785954; cv=none; d=google.com; s=arc-20160816; b=zmDeWjXyriS6QhjAM3m+wpL331gpNn1s98vZ11uRssPPip3XUS4QFv2obdGPTXU6Wy CjrudKNtSuFWgKC9NhNYzf60r7PkRjXV76pLasWTsmpAYHQVOFDy4uw/v1R9pGpmctYm Za+UaXu5aouWih3pF8o3k4X60hV6QpXs+uODWP6CvqinZm6pWKPKOahrzaGaxvx3Gco9 JoS3Dg9hvpuc6z1Gbk/QzBIOlrZ4jw1ncnBB0r2g5djBxgZ+msct3iwo7UPhFFJfhDB3 TS37vh2L0LUAaR/kLWWlzJZSQpBipMpqw/GLjgI2oQCYoZeSU7podDSJHdlRrPxrIsgV piwQ== 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=fPObxy+AqeYTMv2Kbr9Ww6bj1NBgeP7IU5K30XX9RPI=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=k7XC5Olk5YpxSS46VDio7JVvOlsKt4rC0Bb4xh+z2Gn4JUFEpc23NgrKzahCVi1EeE s8+2DB41k+bEJMVdqqpEIV4IOfOc6MC9s5wvj1zr8lSPfCd2crGWggLqMrK5CqKK7BOn +mpiysMeBS2upynmuL2t2493/ewmSbYIaQHsT6MZs2b6+PFeQD29YYAFWhs2Qz/4Xzju bYVFHsKJmT8GD0jrgRZoR+L6z9eGw4E7/2KTu2aug21Mj2rsXMp0ro/HFmx5LYS2Pc8L w3qvJ4hI/Vz7bqHBVnc5UPUxNNg+8vJDPczom7tOlw3f+Rbz1h9ZyEywuQ00nR50PcXw vzEA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R6PsLwr5; 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 71dfb90a1353d-4df7c086c41si2304812e0c.224.2024.05.15.08.12.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:12:34 -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=R6PsLwr5; 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 1s7GFc-0003wC-C1; Wed, 15 May 2024 11:09:04 -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 1s7GFW-0003vO-5f for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:58 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFR-0002yN-7v for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:57 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-41dc9c83e57so45367405e9.0 for ; Wed, 15 May 2024 08:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785731; x=1716390531; 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=fPObxy+AqeYTMv2Kbr9Ww6bj1NBgeP7IU5K30XX9RPI=; b=R6PsLwr5Ju68k2JlZhp0rF6quFh5pemGmBiKLcbEUGbUeW0FxXc2ROv39KryPO6oyy nWhCXIepX2Xm80vuPUI/FpkxYpcgyAUwdotU6qy9DUV07WTyoez42NTADKz76gC9ABle GJViRtivKnlaN5UIRsZ16Gd2yeL/qCqPgvfZQbPKJd4iX2bbDHngg6JMkf1oNCFX5MT6 N2ZcMMiv8uXelYjyUubqZTKJOkY87QATtgnwEuHfxECg3kjUqLxwiuo8y2ualNI7F+CR 6OAUxoG721FiuHnsMZbWhCbf8AeE4m8noEdFyoP33Pg3vkSAK4f81E3AVOVA4ETJT3GJ fgTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785731; x=1716390531; 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=fPObxy+AqeYTMv2Kbr9Ww6bj1NBgeP7IU5K30XX9RPI=; b=cYlVG902/aLykIhi87MwVMtxvAUZy7PaoUgNfG0Kc0YediKWW/Iv/VWiAHq2wMrdPf sSwQzMX80Gu/cUOLU5XQ3VyMCbKWkQdn6z14YUQqD6UcA+j/Y59Jtwy03x1aUE7svQ6P /nHof6eeNa2iiCASnYl1d2T6khDkTrvk9tuvicjfAWFAg6K9rQUifpwsq1uz44FthM0w z3D5Z16+/ORKuwkuBsLFW6MdfRRqVJ9vaKq3Mob8L0n/yoiRsSjWmvTgazmAa4wKq+PM ohPL6tsziOXhRlKk6CwCBtwwDqrGZ+7bqdQhe2GkNwlLlHzPeLOJF+UVw7Ond8SQarcZ IUlg== X-Gm-Message-State: AOJu0Yx/l0vt4XKu0ALtA1Qfe0Fx73vMegagYQeMMrVOSupqYSrnsXCt YclH5JpzKDOBctZ7a08IuQ3OLdGomThRK6VCGxEC9k8WkD98K/9flqjFN8kfYf2l6SGQBDMtzfb HBbg= X-Received: by 2002:a05:600c:354a:b0:41b:f24a:b590 with SMTP id 5b1f17b1804b1-41fbc91f3e4mr173123515e9.3.1715785730819; Wed, 15 May 2024 08:08:50 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 14/28] target/i386: Add {hw, sw}_reserved to X86LegacyXSaveArea Date: Wed, 15 May 2024 17:08:23 +0200 Message-Id: <20240515150837.259747-15-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::330; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x330.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 This completes the 512 byte structure, allowing the union to be removed. Assert that the structure layout is as expected. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/cpu.h | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 97014b14ce..4b3bffeb9c 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1414,23 +1414,34 @@ typedef struct { */ #define UNASSIGNED_APIC_ID 0xFFFFFFFF -typedef union X86LegacyXSaveArea { - struct { - uint16_t fcw; - uint16_t fsw; - uint8_t ftw; - uint8_t reserved; - uint16_t fpop; - uint64_t fpip; - uint64_t fpdp; - uint32_t mxcsr; - uint32_t mxcsr_mask; - FPReg fpregs[8]; - uint8_t xmm_regs[16][16]; +typedef struct X86LegacyXSaveArea { + uint16_t fcw; + uint16_t fsw; + uint8_t ftw; + uint8_t reserved; + uint16_t fpop; + union { + struct { + uint64_t fpip; + uint64_t fpdp; + }; + struct { + uint32_t fip; + uint32_t fcs; + uint32_t foo; + uint32_t fos; + }; }; - uint8_t data[512]; + uint32_t mxcsr; + uint32_t mxcsr_mask; + FPReg fpregs[8]; + uint8_t xmm_regs[16][16]; + uint32_t hw_reserved[12]; + uint32_t sw_reserved[12]; } X86LegacyXSaveArea; +QEMU_BUILD_BUG_ON(sizeof(X86LegacyXSaveArea) != 512); + typedef struct X86XSaveHeader { uint64_t xstate_bv; uint64_t xcomp_bv; From patchwork Wed May 15 15:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796969 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033280wra; Wed, 15 May 2024 08:11:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXmPAc/N6yL0Xi/4b5nHg82gbqqy5H0F7jxDkbM7RW8+J4d6oUYQHly++Kd1rLPf6S9eJWYbmsASeK2patUatZN X-Google-Smtp-Source: AGHT+IH8anzZrIR0j2N4PNUPiuhYQaI7eXWPjcxBvzBuRTwKvzlNegwDIaf2PVA6f3uSXHkcvMQp X-Received: by 2002:a05:6122:2013:b0:4cb:56c5:5816 with SMTP id 71dfb90a1353d-4df88342e16mr14106011e0c.12.1715785875179; Wed, 15 May 2024 08:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785875; cv=none; d=google.com; s=arc-20160816; b=0JWmNvG5MLG3+w7FXprMqX1dDSKJl84or2RmHvq3ZuJvh1n94Aee2h9Rt/Je7sIyU/ D0BvROFI5HZvgLteQcMPTOeJ7wCCgbpNnaGrQStk/3uJodAzXl7Y9VBGJGcAI3NzJHBB uoAjQPrN7xX6I37VmMubmJPpXDX18GsLR6kUjxMYurNp8Up5WmHhgPKI/i7DEclO5SkH PE0z74R/HwtX7SdufgihW9IvgmSqhYFhpI6wLi7YcqMYa89PUOsmnaM/wnEgJc17d2u9 HySPW3+CE6AuHez5/CWm5YmhiBXy8Qn9x0zyzp9kk5wKBT+zwNZ5xulToduPfuVq2sFY cN9Q== 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=8E9ppc4CUToY/h7916Bi0wG7cWa/ImlZUPMW1khZFpk=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=dQb1PVKnLTilI4e1kpOS1tNlEjjPa1bePI98jRBOUCbiDg9vg30lPNfwpwOC0g98IJ ab9wTOstfLNSOHBqe/ugSHpwITDWIIQDTvdbBS1yAAKfmOwZZjTS1EzaS/jzFnr5zlZ5 07Eq/hdz0kJTaOF3zB9gcQgosbjpNMpat7UGF4UBkj1SwF4JIJs3A9Jk+FaaShcve7Fv pHk/PnQS1lscerpPD0fpk2OBk1rs/p43CVQQimvZ4valdnS2Y3Xgb6WIAMEIRlvbONmi SnyGElEuJK2Z40EMBhccZzE1ehkguB8VyDg/LoL1ff36YRRjop34hvSomvm+DSjjkE5q GqTg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jPRg41Ye; 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=pass (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 71dfb90a1353d-4df7bf80f72si2487009e0c.96.2024.05.15.08.11.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:15 -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=pass header.i=@linaro.org header.s=google header.b=jPRg41Ye; 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=pass (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 1s7GFW-0003vT-Ek; Wed, 15 May 2024 11:08:59 -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 1s7GFU-0003uu-Qy for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:56 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFQ-0002x3-Ug for qemu-devel@nongnu.org; Wed, 15 May 2024 11:08:56 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-420180b58c3so24013275e9.2 for ; Wed, 15 May 2024 08:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785731; x=1716390531; 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=8E9ppc4CUToY/h7916Bi0wG7cWa/ImlZUPMW1khZFpk=; b=jPRg41Ye0GTS8oRQNmoA9gjxBKVITCjyOIFnUejiK2Ll/k1PUchiPo7rqC8j5zj4/i 6pBgIb8Bnyl8Qe3pa/VMRA4N85RuCI/x2blFDbKKoZNbb5NM7a4Z9b2TiA3iuN5n7xK4 IJYM7/32a1Btk9jQkQbohyIHFASp5BupNlCUOzHzcw9tAtsBjUef53qqWHy9t21HpAMl fb5twZmxgeSJ+jw1mQAD1HhJIdRBHGXBbhmDBOb084ik6I6wWQbQfmL3Rxz9uKFK8b3G FkjpiZAYa31JELBwFZK8STvH/JGhftoVWSILMFxTOeoRUSP2N1lJCwO/gy8SUL7ddae7 eC1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785731; x=1716390531; 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=8E9ppc4CUToY/h7916Bi0wG7cWa/ImlZUPMW1khZFpk=; b=F1drADk93vIv2Ix/qNbrpTe4bgOKIM8YccXSRCnKY3He0UezVl0SQmsMcM3IlZSniT iirc6bn+Sh0g7IrtkmzLADPtCnzKLalHTlnAQBnsYFLPhrIh9oAzVMgfRgxGo6UbFp0Y xSxIFPX//if5YZTe5u+4USzSTX5EZi5vZvGn72Gyr1gKwI8ABv4ALkkdagz4Ot91DthS P5q8MFTIc/FMc1bDuLSDX0gkoKhU/MP97IcvZM4UPZMY5Dag4GvF89CI9ks2AfaSB0zh 7UQr4tyVI7vt3N+hlqmpsHvxRYS/Eyh8i/pAwQ5moOiNzWzKfS9Aq3h/XpOs65VmsUGX hwzQ== X-Gm-Message-State: AOJu0YweHjeH3xZzcJoe7x9mc3KyDq7pR+rtnHkK/42g3XGEuqemvz3g smjn8eYBoUT8jBeXyD6isAel+0kH8uRPq9a1y75XiWXCSWv50uxc1ck3rJvNH94R3oFA/jX5JdU YkOs= X-Received: by 2002:a05:600c:4f42:b0:419:f241:632f with SMTP id 5b1f17b1804b1-41feac49273mr132397645e9.31.1715785731570; Wed, 15 May 2024 08:08:51 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 15/28] linux-user/i386: Drop xfeatures_size from sigcontext arithmetic Date: Wed, 15 May 2024 17:08:24 +0200 Message-Id: <20240515150837.259747-16-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::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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 This is subtracting sizeof(target_fpstate_fxsave) in TARGET_FXSAVE_SIZE, then adding it again via &fxsave->xfeatures. Perform the same computation using xstate_size alone. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 824375d42a..89048ed069 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -253,7 +253,6 @@ static void xsave_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs __put_user(0, &fxsave->sw_reserved.magic1); } else { uint32_t xstate_size = xsave_area_size(env->xcr0, false); - uint32_t xfeatures_size = xstate_size - TARGET_FXSAVE_SIZE; /* * extended_size is the offset from fpstate_addr to right after the end @@ -273,7 +272,8 @@ static void xsave_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs __put_user(extended_size, &fxsave->sw_reserved.extended_size); __put_user(env->xcr0, &fxsave->sw_reserved.xfeatures); __put_user(xstate_size, &fxsave->sw_reserved.xstate_size); - __put_user(TARGET_FP_XSTATE_MAGIC2, (uint32_t *) &fxsave->xfeatures[xfeatures_size]); + __put_user(TARGET_FP_XSTATE_MAGIC2, + (uint32_t *)((void *)fxsave + xstate_size)); } } @@ -559,7 +559,6 @@ static int xrstor_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs if (env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) { uint32_t extended_size = tswapl(fxsave->sw_reserved.extended_size); uint32_t xstate_size = tswapl(fxsave->sw_reserved.xstate_size); - uint32_t xfeatures_size = xstate_size - TARGET_FXSAVE_SIZE; /* Linux checks MAGIC2 using xstate_size, not extended_size. */ if (tswapl(fxsave->sw_reserved.magic1) == TARGET_FP_XSTATE_MAGIC1 && @@ -568,7 +567,7 @@ static int xrstor_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs extended_size - TARGET_FPSTATE_FXSAVE_OFFSET)) { return 1; } - if (tswapl(*(uint32_t *) &fxsave->xfeatures[xfeatures_size]) == TARGET_FP_XSTATE_MAGIC2) { + if (tswapl(*(uint32_t *)((void *)fxsave + xstate_size)) == TARGET_FP_XSTATE_MAGIC2) { cpu_x86_xrstor(env, fxsave_addr, -1); return 0; } From patchwork Wed May 15 15:08:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796978 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034295wra; Wed, 15 May 2024 08:12:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV7JDSZmzJ7we2yv8j1qjtlU7IkLou16LYFAUWK9iwD29PGflqVLPoGWtu7E6WoraPtaKXWeREI5FtXqpPrHeHB X-Google-Smtp-Source: AGHT+IHmnHBO/TtJf9FQqQlF2Krntvr6SGy2l+jvJPeQFT5AXf/OiSe/myDWJRq/otZzKJMx1beG X-Received: by 2002:a05:6102:54ab:b0:47f:684:a3f with SMTP id ada2fe7eead31-48077e834b5mr17099694137.25.1715785972231; Wed, 15 May 2024 08:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785972; cv=none; d=google.com; s=arc-20160816; b=YVoiUBi9fy+4etI7Xomi1uTUPLxJk+ARfQrxYjcDwgc32SSib0jOIxwiaGhznOP3bK onav1B7QwFNUmSzD4YSUWT78ZUtwnftHZh90sEVpAmlTJI7RGsidC1yWB9tTGamsU4yT sNDwIDKPsd1Fn4yhZRXsy+WADpz6dxSERpKCeM4h8cWnTeMiGtsJL/N+a+Tjz9L2wk1c cRF83iy64ZGnObcyUg1Tud1ipKc5lb/DNS25A1FYAzNF9Cye3TkhcqIowYUoLNB0NA7u YpxVIheCCM5DLQ6p9f2jfs8ZBXPQHux9HC3z+ykRhS7ixPt8fytQcE98YOv4eZPI/x8a 3xJg== 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=cH8p7zFQoa8qKM/2WS7ZfbaGhkQJFlfpHgdlJuwcM/w=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=jW94CEjmwqxGH6uLMtqysSVzX6SRPeDxF3EFIRiz3Cba76aPoFBiiJv90pe3s5k37R 8qrlcj/ApuQn+rHA1CD8zvQMoyi04Sn9dDs8ZPdsrIDnKWA/8Ib2GWx++TthqOxTpvg2 gA6loJNeNIpEI5LT2Xy9QKA/0Vm3zkh5h2lvlBJ9jYwOowgtz8Wk3bGdTHN4kidQwsqD 95MFFr+zZrWDBwOwdVrCiQhb8Ac93pNMvcrSIqvnmzYtfYl+rLQOOLo1Ok1Gz3IHbjGA mUjnCyqs/LyBYVsHodaQUT+68KqIrfXbCafbkEA4WqMvo6P5Bj8LLf91Wjz+8BovfctS aeug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xPdo6OAl; 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=pass (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-4806ccc3dacsi2181904137.795.2024.05.15.08.12.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:12:52 -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=pass header.i=@linaro.org header.s=google header.b=xPdo6OAl; 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=pass (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 1s7GFl-00042O-G9; Wed, 15 May 2024 11:09:13 -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 1s7GFh-00040c-LM for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:09 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFR-0002zv-ON for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:09 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-420160f8f52so23039865e9.0 for ; Wed, 15 May 2024 08:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785732; x=1716390532; 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=cH8p7zFQoa8qKM/2WS7ZfbaGhkQJFlfpHgdlJuwcM/w=; b=xPdo6OAlo3KEO6xJFHjlu0nuhvZLkG121q6DtnSFmxRqLd1jPeuEx461Vb+y2Objuq Zgd/ZhwnbNMeOieiT9TQBjFY3/BA0Q36una3XMPOsMoYfbox6iLfwINjZWIF+4MnvKoh 9cqYZGq3SZW+zWz1s9rGgWogJcLInmN0YpIBYtWF8XpFUYMjucSQ5nj5NOdQTAqdhJKc eLl6bNbwfTJQfb+KFu/zeHT67Km/N4jYSyLZ/2WY97HAvpt0v4GGst7xITCWh9bqlzRt 7RI32VKEk7uZcKa/IQNNxYESpoln8c+ft0RX0G+ris2RigcsCEMzFqILbXSQLqOuvZAk BU2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785732; x=1716390532; 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=cH8p7zFQoa8qKM/2WS7ZfbaGhkQJFlfpHgdlJuwcM/w=; b=FjaVZkAMJJ174IfCvuCh9dfeYbP1lgcp+pYmWDFCfR9WbCeMqMbp6gAYvPrVspk9hT Bk2XyUbaZistYlUUNYysd6coJKXpr/EKXrl/s8t905qRTxDomhozWtPkSh1P5AGJ3oKI HDxP8IBmxQEu2PVrmsSBL8B5b/kXCtqfArE/zfPG93EsEsjSMjyrtjhY6ch96nt2jQmT YHsDCJApY8zk8Jq9liX/44o9Oio9t7UiQMkbhnN0GZSy4MpGhvUqZMVCmoES5ofrFpm4 eMqyoO1HiLiHL5AeDEgIWENGzMxTDljcCfCITXP2cp7Q+EsEK8JfaAmsEL3/QWCPjaMy QVMA== X-Gm-Message-State: AOJu0YyBa/QYHpY/dFbpKJ2QHET5JXUfaBppSWHAARst9PUs6dbSV7hj +KgD7qOAT4wGaovcl4Lzqv/fO6MKHqzp1NQzX5uA5QwKpGuvQVIdgzEPj9fLCPsuqowXlJzgs8d 8Gv4= X-Received: by 2002:a05:600c:35c2:b0:41c:2313:da92 with SMTP id 5b1f17b1804b1-41fea93afeemr134412515e9.4.1715785732320; Wed, 15 May 2024 08:08:52 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 16/28] linux-user/i386: Remove xfeatures from target_fpstate_fxsave Date: Wed, 15 May 2024 17:08:25 +0200 Message-Id: <20240515150837.259747-17-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::330; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x330.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, 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 This is easily computed by advancing past the structure. At the same time, replace the magic number "64". Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 89048ed069..f8064691c4 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -67,7 +67,6 @@ struct target_fpstate_fxsave { uint32_t xmm_space[64]; uint32_t hw_reserved[12]; struct target_fpx_sw_bytes sw_reserved; - uint8_t xfeatures[]; }; #define TARGET_FXSAVE_SIZE sizeof(struct target_fpstate_fxsave) QEMU_BUILD_BUG_ON(TARGET_FXSAVE_SIZE != 512); @@ -266,7 +265,7 @@ static void xsave_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs assert(!(fxsave_addr & 0x3f)); /* Zero the header, XSAVE *adds* features to an existing save state. */ - memset(fxsave->xfeatures, 0, 64); + memset(fxsave + 1, 0, sizeof(X86XSaveHeader)); cpu_x86_xsave(env, fxsave_addr, -1); __put_user(TARGET_FP_XSTATE_MAGIC1, &fxsave->sw_reserved.magic1); __put_user(extended_size, &fxsave->sw_reserved.extended_size); From patchwork Wed May 15 15:08:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796980 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034316wra; Wed, 15 May 2024 08:12:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXg2vTqMfO7OkADgtH32VpQNZ9uEk+zR72eEPOBe3gowRxZl0WNvE+pSvZoaoBxk2C1Eo7jpasa448plaxJrGgp X-Google-Smtp-Source: AGHT+IE6kfeAE/KUhfQcc6Lm9TGOUFYj3XnCIRzKT5LRC7Krb15QI+0B8Y4W4vPVlP7Wfxt5WOo+ X-Received: by 2002:a05:622a:11c8:b0:43b:758:6ca with SMTP id d75a77b69052e-43dfdad7b3amr157188461cf.33.1715785973433; Wed, 15 May 2024 08:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785973; cv=none; d=google.com; s=arc-20160816; b=Bw0dCbDUoJ93P8fhiycZlVDtNHYyqPk4mAFLXsfurGLiMYXmH/260qb26YjKFoTTBC wP/ICSZBHUThvbzRGZ8E3WUfOOafgbjfEV52KXKamBoTFMPp3RuNqp9fAF3JIppJfSv4 O20WSGwwRtZRWpE52QaaZ+vxOmzffVdtKjXC5j3CC5agJ8lSF+p/0ygVq88P+uWPrL1w T5MtH9qBBJilS+UuQA0frEuJx/Bmr1OdKWEKOEWQIYdYsFJg8MVr4ydDmpEXxzNmZz+E 7GQPDiLHT0fZQpsAufj1/rnGWukmJ0ZoAo94ci6L5KYIsdzOzalWV32ThBp4SRi99xJq pPYA== 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=xXRJWnawluUaMF/jqhQVfylOquOPm+Y6SErtNaXDicY=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=vCoObcj2PtJ0yf7LKPXUwEovWyO/UitMJHm2kfMBKTw08In84kOg+uk+c0K3/kiUTh NlSMjQ/6Mvs3v/JNJ+EIu7Sz4rCUUr3/aTxjeBqYR/C5UCGSdojZd6zHPIev731jiBIh Jr5vxWjYhJ0d1Q60CweT4bHUBusRkPLLGbM4y43BER2f4J0wBmh2nRy+4vofUf7wzenN 1Njz++NADseejWJZRhzDGclUyIo/ZAF6jLe6JO2tqomAzHF9lme8gqmLbyYJ81xqmkC6 cG27ouX9McJoWyY9cOppQYpGqcXG+TuAZkSPJwALjeMGC1OdHT/HIXpdzbsW7OOZok8x LQrQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n5jrImS0; 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=pass (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 d75a77b69052e-43df549efb7si143971451cf.35.2024.05.15.08.12.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:12:53 -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=pass header.i=@linaro.org header.s=google header.b=n5jrImS0; 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=pass (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 1s7GFd-0003xo-HB; Wed, 15 May 2024 11:09:05 -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 1s7GFY-0003vi-OQ for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:02 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFS-00030C-HO for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:00 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2e45c0a8360so72401041fa.3 for ; Wed, 15 May 2024 08:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785733; x=1716390533; 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=xXRJWnawluUaMF/jqhQVfylOquOPm+Y6SErtNaXDicY=; b=n5jrImS0fD6/VkWBUSIOkTg2eQL3GMA8XG1QHBIQRr+Vb36SlvyxZUwzmWfW8Vsg5E nB+tGaXNy4XNfZiVc9kxo/J33P0fQorh70ZkHlSRlaxPvuL+TKNTXpARdSsrR36AdcsA HV86nTA9fIcNU3rR9CC0Q+NYQIlToOPIgoorQYjMxuMe8YZIrd4Tzk86sqxA1PAU4hGP 8csELiv/fpygDhPHYNKFyjYeXvPh7YkO8HmAua8AXqIrpH7p92eKUYVyFcCalr8GiGvU p2rVTsxAAAotSCKblXgPmVv6FpV6nwdxK8GExBPe0ia+UqKyAjS1zyFckQk4YUELW4xh PvFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785733; x=1716390533; 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=xXRJWnawluUaMF/jqhQVfylOquOPm+Y6SErtNaXDicY=; b=P7wixdPLpvHqnTHuQ+hI+W4tlXMZxNUv5GbFHX6hhoxsNRLBA+jmNIiJo6pVfjxK94 /50Jf2C98aSRynw6zwBbx2bVvE4j8xslWpEUSG3weZT/wAcmHm1fznvDdVMhZXRlVDli stNN1B68l2UaVFQBVObobBJVvGglb1Ul5QTGlXXEbCIhLqp0lwfR3ZEyHd6BZZayDZtI zHV5LHGVzc/IC4gdPNfQBqGp9v8NQtfbCsE2NsTDxlwB6dCn/aTXUa/FrdnfhXQoD6US Ut73TS2vyeIb68QyUGA1LJE9GOdoysDQIJlSFlbxZjiEXeSiACzHv7TVFRusq6FwSWHb QiyQ== X-Gm-Message-State: AOJu0Yxn5loyeUaMciVDVBPikw2r/Z0LnrHsFslF8OXqiXlqUQbvr2SC 52mclZp2YrX6K6ObWVbFJL1+naSALPEEDPtZQSbu+7b8AyEvTt3+jC18uVr06PGPFz1Mv8tOCSn yPU0= X-Received: by 2002:a2e:7c02:0:b0:2e0:5f2c:e0c0 with SMTP id 38308e7fff4ca-2e5204b2edfmr103780521fa.37.1715785733068; Wed, 15 May 2024 08:08:53 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 17/28] linux-user/i386: Replace target_fpstate_fxsave with X86LegacyXSaveArea Date: Wed, 15 May 2024 17:08:26 +0200 Message-Id: <20240515150837.259747-18-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::232; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x232.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 Use the structure definition from target/i386/cpu.h. The only minor quirk is re-casting the sw_reserved area to the OS specific struct target_fpx_sw_bytes. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 71 +++++++++++++++------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index f8064691c4..5b1c570bff 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -34,16 +34,6 @@ struct target_fpreg { uint16_t exponent; }; -struct target_fpxreg { - uint16_t significand[4]; - uint16_t exponent; - uint16_t padding[3]; -}; - -struct target_xmmreg { - uint32_t element[4]; -}; - struct target_fpx_sw_bytes { uint32_t magic1; uint32_t extended_size; @@ -53,25 +43,6 @@ struct target_fpx_sw_bytes { }; QEMU_BUILD_BUG_ON(sizeof(struct target_fpx_sw_bytes) != 12*4); -struct target_fpstate_fxsave { - /* FXSAVE format */ - uint16_t cw; - uint16_t sw; - uint16_t twd; - uint16_t fop; - uint64_t rip; - uint64_t rdp; - uint32_t mxcsr; - uint32_t mxcsr_mask; - uint32_t st_space[32]; - uint32_t xmm_space[64]; - uint32_t hw_reserved[12]; - struct target_fpx_sw_bytes sw_reserved; -}; -#define TARGET_FXSAVE_SIZE sizeof(struct target_fpstate_fxsave) -QEMU_BUILD_BUG_ON(TARGET_FXSAVE_SIZE != 512); -QEMU_BUILD_BUG_ON(offsetof(struct target_fpstate_fxsave, sw_reserved) != 464); - struct target_fpstate_32 { /* Regular FPU environment */ uint32_t cw; @@ -84,7 +55,7 @@ struct target_fpstate_32 { struct target_fpreg st[8]; uint16_t status; uint16_t magic; /* 0xffff = regular FPU data only */ - struct target_fpstate_fxsave fxsave; + X86LegacyXSaveArea fxsave; }; /* @@ -97,7 +68,7 @@ QEMU_BUILD_BUG_ON(offsetof(struct target_fpstate_32, fxsave) & 15); # define target_fpstate target_fpstate_32 # define TARGET_FPSTATE_FXSAVE_OFFSET offsetof(struct target_fpstate_32, fxsave) #else -# define target_fpstate target_fpstate_fxsave +# define target_fpstate X86LegacyXSaveArea # define TARGET_FPSTATE_FXSAVE_OFFSET 0 #endif @@ -241,15 +212,17 @@ struct rt_sigframe { * Set up a signal frame. */ -static void xsave_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxsave, +static void xsave_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, abi_ulong fxsave_addr) { + struct target_fpx_sw_bytes *sw = (void *)&fxsave->sw_reserved; + if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) { /* fxsave_addr must be 16 byte aligned for fxsave */ assert(!(fxsave_addr & 0xf)); cpu_x86_fxsave(env, fxsave_addr); - __put_user(0, &fxsave->sw_reserved.magic1); + __put_user(0, &sw->magic1); } else { uint32_t xstate_size = xsave_area_size(env->xcr0, false); @@ -267,10 +240,10 @@ static void xsave_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxs /* Zero the header, XSAVE *adds* features to an existing save state. */ memset(fxsave + 1, 0, sizeof(X86XSaveHeader)); cpu_x86_xsave(env, fxsave_addr, -1); - __put_user(TARGET_FP_XSTATE_MAGIC1, &fxsave->sw_reserved.magic1); - __put_user(extended_size, &fxsave->sw_reserved.extended_size); - __put_user(env->xcr0, &fxsave->sw_reserved.xfeatures); - __put_user(xstate_size, &fxsave->sw_reserved.xstate_size); + __put_user(TARGET_FP_XSTATE_MAGIC1, &sw->magic1); + __put_user(extended_size, &sw->extended_size); + __put_user(env->xcr0, &sw->xfeatures); + __put_user(xstate_size, &sw->xstate_size); __put_user(TARGET_FP_XSTATE_MAGIC2, (uint32_t *)((void *)fxsave + xstate_size)); } @@ -384,9 +357,9 @@ get_sigframe(struct target_sigaction *ka, CPUX86State *env, size_t fxsave_offset } if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { - return (esp - (fxsave_offset + TARGET_FXSAVE_SIZE)) & -8ul; + return (esp - (fxsave_offset + sizeof(X86LegacyXSaveArea))) & -8ul; } else if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) { - return ((esp - TARGET_FXSAVE_SIZE) & -16ul) - fxsave_offset; + return ((esp - sizeof(X86LegacyXSaveArea)) & -16ul) - fxsave_offset; } else { size_t xstate_size = xsave_area_size(env->xcr0, false) + TARGET_FP_XSTATE_MAGIC2_SIZE; @@ -552,21 +525,29 @@ give_sigsegv: force_sigsegv(sig); } -static int xrstor_sigcontext(CPUX86State *env, struct target_fpstate_fxsave *fxsave, +static int xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, abi_ulong fxsave_addr) { + struct target_fpx_sw_bytes *sw = (void *)&fxsave->sw_reserved; + if (env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) { - uint32_t extended_size = tswapl(fxsave->sw_reserved.extended_size); - uint32_t xstate_size = tswapl(fxsave->sw_reserved.xstate_size); + uint32_t magic1 = tswapl(sw->magic1); + uint32_t extended_size = tswapl(sw->extended_size); + uint32_t xstate_size = tswapl(sw->xstate_size); + uint32_t minimum_size = (TARGET_FPSTATE_FXSAVE_OFFSET + + TARGET_FP_XSTATE_MAGIC2_SIZE + + xstate_size); + uint32_t magic2; /* Linux checks MAGIC2 using xstate_size, not extended_size. */ - if (tswapl(fxsave->sw_reserved.magic1) == TARGET_FP_XSTATE_MAGIC1 && - extended_size >= TARGET_FPSTATE_FXSAVE_OFFSET + xstate_size + TARGET_FP_XSTATE_MAGIC2_SIZE) { + if (magic1 == TARGET_FP_XSTATE_MAGIC1 + && extended_size >= minimum_size) { if (!access_ok(env_cpu(env), VERIFY_READ, fxsave_addr, extended_size - TARGET_FPSTATE_FXSAVE_OFFSET)) { return 1; } - if (tswapl(*(uint32_t *)((void *)fxsave + xstate_size)) == TARGET_FP_XSTATE_MAGIC2) { + magic2 = tswapl(*(uint32_t *)((void *)fxsave + xstate_size)); + if (magic2 == TARGET_FP_XSTATE_MAGIC2) { cpu_x86_xrstor(env, fxsave_addr, -1); return 0; } From patchwork Wed May 15 15:08:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796967 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033138wra; Wed, 15 May 2024 08:11:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHvdI1X+m+UKG8rEVJehudmXqyY9mYQkipaY+W63Tv751IW8ecMv8xlq2uf6IqqqmpWaSKFrDVptXa86kmzxgG X-Google-Smtp-Source: AGHT+IFXffJkpU2KCCmY6CksClXlJTQQ3n2sL5Eu+Q9GCCtMhd4ysnl+3yQSFOlVrhZ4t4aLc4Vm X-Received: by 2002:a05:6102:b15:b0:47b:d871:ccb2 with SMTP id ada2fe7eead31-48077dcc5c6mr18513162137.13.1715785862841; Wed, 15 May 2024 08:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785862; cv=none; d=google.com; s=arc-20160816; b=waxWFlXPFNMph/ju8v6HWJjzwXam1knquM9wlTtiHq/hPeh4OtALgPDOldK5wzGYVL QBkiU4ReDz5p94dpnNvD37giRWRLHxnKNxwsEW6twAYnK8ZznuuYW8Twx3aHuzPoMDh5 PnlIsTEfanZXKT2WiCjPAsMf1ks3rcg4k6efF5kxVfb97qf13zkmZbczb1Wu8hAV47S+ aU6ylTAQC3pquT7zVIAtefHg69aJl2gC+nZ3DukXczwz2HnOu85/axC8QvnZwHT8ztzZ DkVmSc5x9mAfTiMIzjUdaLOJtrYG0SpzYxaYXNPFFg4FZ1MEIQE0etuzWaN77jM5/bGN nbvw== 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=d+kCzCPFmRVWagKLDLCR1Cq5shqRDzyNhJ9IIrqSVUo=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=qAMjo5hQW1zTv9B6MnGQj0gN6E9i8P3vHa6gONXnfdHBpbt40/EfF45g3u9CALHd0T 3ynJAwCfnNdHoaHGeyDx4jh4It9ROeMK2bHDoSwNjz51veWbNrw9luD8+362XAAOCqYp 45DrQvGS6B6q7NszRaKAPaRXv8ZeHNxgq4ZzbrFXoK6CGhpHvPEz0C3ddc+YPZ83sYlS 7uhZYWxSVeDdI8YgytQNX2725xQqYA5+PvbYDma9SLeFaGcgdRlRxd34oV7XMIyLF6S7 WQL/wbk9FCdCFgFOTosa9zq33tk8FJVh8YADv9f2SCwQt/Qr7NgqrVn0PcukKx1WbE5T DhfQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yWTHJrvR; 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=pass (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-48478d712afsi252816137.323.2024.05.15.08.11.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:02 -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=pass header.i=@linaro.org header.s=google header.b=yWTHJrvR; 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=pass (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 1s7GFj-00040t-Br; Wed, 15 May 2024 11:09:11 -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 1s7GFb-0003wB-Lu for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFT-00030R-78 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:01 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42016c8daa7so22484795e9.2 for ; Wed, 15 May 2024 08:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785734; x=1716390534; 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=d+kCzCPFmRVWagKLDLCR1Cq5shqRDzyNhJ9IIrqSVUo=; b=yWTHJrvR4XCgjkZkGcBWNWV9OrlG309DhNPNtWAQu9dpZlnBYnUbt+oVf8CX6ygsSj d6mIcY8fSzhDbVDMfrnFfKJtZ0s9uoWFZqV7Oa/bAcSEZSI7v/LOiXhauAldZPQHj0r9 gVa7Mmak0cwA371FRbUtSO4suHzxygRC8hizZR0PzLV5C/Q5ud00xoKLg9XVoGxHfbzX nHSOPJHUYNpln44OUJ0CWCkcWQbSil0fp3RlY/mvxHnypUBUBOPlayYaGVWsdS9OV6iN /AUv+iCbWggGoG++JsiNTmWsPzijyCdCi20rjsEPOkPxkYkFU9nvwSaDtYux82es9zOx 4UwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785734; x=1716390534; 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=d+kCzCPFmRVWagKLDLCR1Cq5shqRDzyNhJ9IIrqSVUo=; b=wBVaENg5iKj31cEFm1yKmU7JjeKK1aTmZG9m/rWAaAvFuGWQAAuF96X7KLoJvtGjEK XnGgkLcyHKnXVettUvoYpWBlSJslKszpwkgC5UVj2pA9xR3kvDAZo73QWPaPmScBYn+0 //VeRI7XIeImO+7z3QG9C/f80NsskZLNiagOoIXrGBT4Li0Ddz9y/4sMnAR2rssHeKNs VkTQS4g6KVfdZrvBSS+Z/Xw512KP9Cnfh3MFbomPu2hVxHTVQIy+ilg68NL64sVPYQbE LZbJt4ZFeHiVfVwaZvQXiM1LaLUOkwO+B2Quy+9tco98qOX9LEXBj3NQXEcIk0n7Knr0 HCbg== X-Gm-Message-State: AOJu0YxAtwjlUbMauAHwYXcbIAKGE++4Yp/kWKpGep32LdDnNbjPsg4Y ewQv2z2GMRnUgT3sUL5HS2feJvso3sP7kj68obGG9lIBFyonW/uPKCfiWoFS8Pb5rJOD9Fi5DbJ XUw4= X-Received: by 2002:a05:600c:3c85:b0:419:d841:d318 with SMTP id 5b1f17b1804b1-41feac59e6dmr104160995e9.29.1715785733930; Wed, 15 May 2024 08:08:53 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 18/28] linux-user/i386: Split out struct target_fregs_state Date: Wed, 15 May 2024 17:08:27 +0200 Message-Id: <20240515150837.259747-19-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::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 43 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 5b1c570bff..3271ebd333 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -34,6 +34,23 @@ struct target_fpreg { uint16_t exponent; }; +/* Legacy x87 fpu state format for FSAVE/FRESTOR. */ +struct target_fregs_state { + uint32_t cwd; + uint32_t swd; + uint32_t twd; + uint32_t fip; + uint32_t fcs; + uint32_t foo; + uint32_t fos; + struct target_fpreg st[8]; + + /* Software status information [not touched by FSAVE]. */ + uint16_t status; + uint16_t magic; /* 0xffff: FPU data only, 0x0000: FXSR FPU data */ +}; +QEMU_BUILD_BUG_ON(sizeof(struct target_fregs_state) != 32 + 80); + struct target_fpx_sw_bytes { uint32_t magic1; uint32_t extended_size; @@ -44,29 +61,19 @@ struct target_fpx_sw_bytes { QEMU_BUILD_BUG_ON(sizeof(struct target_fpx_sw_bytes) != 12*4); struct target_fpstate_32 { - /* Regular FPU environment */ - uint32_t cw; - uint32_t sw; - uint32_t tag; - uint32_t ipoff; - uint32_t cssel; - uint32_t dataoff; - uint32_t datasel; - struct target_fpreg st[8]; - uint16_t status; - uint16_t magic; /* 0xffff = regular FPU data only */ - X86LegacyXSaveArea fxsave; + struct target_fregs_state fpstate; + X86LegacyXSaveArea fxstate; }; /* * For simplicity, setup_frame aligns struct target_fpstate_32 to * 16 bytes, so ensure that the FXSAVE area is also aligned. */ -QEMU_BUILD_BUG_ON(offsetof(struct target_fpstate_32, fxsave) & 15); +QEMU_BUILD_BUG_ON(offsetof(struct target_fpstate_32, fxstate) & 15); #ifndef TARGET_X86_64 # define target_fpstate target_fpstate_32 -# define TARGET_FPSTATE_FXSAVE_OFFSET offsetof(struct target_fpstate_32, fxsave) +# define TARGET_FPSTATE_FXSAVE_OFFSET offsetof(struct target_fpstate_32, fxstate) #else # define target_fpstate X86LegacyXSaveArea # define TARGET_FPSTATE_FXSAVE_OFFSET 0 @@ -279,15 +286,15 @@ static void setup_sigcontext(struct target_sigcontext *sc, __put_user(env->segs[R_SS].selector, (unsigned int *)&sc->ss); cpu_x86_fsave(env, fpstate_addr, 1); - fpstate->status = fpstate->sw; + fpstate->fpstate.status = fpstate->fpstate.swd; if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { magic = 0xffff; } else { - xsave_sigcontext(env, &fpstate->fxsave, + xsave_sigcontext(env, &fpstate->fxstate, fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); magic = 0; } - __put_user(magic, &fpstate->magic); + __put_user(magic, &fpstate->fpstate.magic); #else __put_user(env->regs[R_EDI], &sc->rdi); __put_user(env->regs[R_ESI], &sc->rsi); @@ -623,7 +630,7 @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) cpu_x86_frstor(env, fpstate_addr, 1); err = 0; } else { - err = xrstor_sigcontext(env, &fpstate->fxsave, + err = xrstor_sigcontext(env, &fpstate->fxstate, fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); } #else From patchwork Wed May 15 15:08:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796966 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032897wra; Wed, 15 May 2024 08:10:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV05GrCyCXCMaG2ztvQplxFlEcpIOEqKSMbcedbQb8Q12/JDwXBoCRse3JZ/Yf2rvf7pNDSFY8SrXzTk1rQPEVb X-Google-Smtp-Source: AGHT+IGRKRNclRxFQpY3BV9R1XfD0cu4ZUkpcOX2FsNKDNKJc3+mIUiG5BaBXtTW8fXvwcZSHNI6 X-Received: by 2002:a05:6122:4584:b0:4df:235b:8ba1 with SMTP id 71dfb90a1353d-4df882e90cemr14873423e0c.7.1715785838904; Wed, 15 May 2024 08:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785838; cv=none; d=google.com; s=arc-20160816; b=J5VWVf1sObtfZPh8W4Bo9YDR6fW/VMdeVFms1feU0GvA5NC2ZceIrfxypREv00d6um QaYcWdO3OslDtAIdSQmphOhyS4GM/WhPCrz1vHdVba5zNIG3N5A6zASnyCNlRG4lgYg8 KS4CFPWPIfOkymyD1cwLULsoSON6NFIijvIBRf5oa9cB8ePOwSa+/pGCGJ+xKVnvUoU9 A02HtVp+H1qQdk4vcmk1SETVfklzX6DcpLR7geCHlHildC2Nt06jJ9swXpPs/cnVWyeW QAMXeOqx/UG/9zpOysZnUM5xJbPMbxSGnohGE6ofH2iez5Y9hYlbEcjY6M6bo+wU0E4W iF/Q== 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=8IG0If/b6VQnjtJdCAv7RGvLxbc+5Pp5q/Lqtx4PykE=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=HvqOr+YCkMWx/UyXLJ78183RPimEbgwET29bVjVBqNroVwAiL6DrvstMJOyApPg75O nOVoQclfUh0trwC2mdOuQPSKLPmwtfoE9xKVXqPMsls9fX3fyLLuNJYmp/za/+a27+Wb Ua8mEhGdx0jwcZob0PSynQoFiyMiNf3kl132KOpx4UDBxdZLNdd41bYXHQX7MR04ixya GICzUtYL65AMjXMFO9WHAdLPlP4c+F+9/LVmf5wCX7wzSwL4h0U/YXmfGIiwFGIgoRtx /u1HrD1rvagHKGNyqnx49WmvOW6ZQcyMGkUzu+/tzm+OEky/phU5NJKVHHQTLfDSBXTf zrgg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oHax7iaY; 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=pass (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-4806cc6cbc7si2122929137.491.2024.05.15.08.10.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:10:38 -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=pass header.i=@linaro.org header.s=google header.b=oHax7iaY; 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=pass (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 1s7GFf-0003yv-RE; Wed, 15 May 2024 11:09:07 -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 1s7GFb-0003wF-Rm for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFU-000357-0x for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:01 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-41fd5dc03easo43231865e9.1 for ; Wed, 15 May 2024 08:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785734; x=1716390534; 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=8IG0If/b6VQnjtJdCAv7RGvLxbc+5Pp5q/Lqtx4PykE=; b=oHax7iaYoFpItOTnbTcfio3qEzv4x0NtN2GVjSiUAI4q1/Tyqizd+iZphHlDAOKZKz DmNK2exapw03SsNvJl7eN49EDU6WD9kVMK0vjWd2d00WiTpeim6CiTIb9JX4SzXhRoPm OcjHrEVK8Oitik+CAf/vitQ72iVU2hpNMOv4rseOHc2WxwQOgwt2w4PZcsEg9YePPgHk P3pnoH8WXcqGVVXUvC8dQvb/A8oDWduFC7gF+oGSWZ4DyRqp6pAS1VI0xacpwA0gvPWG E8CUKxHF1xqp0apdGYhrwTRXxR9APhHmL3c/TUnMBr9a6RaWL5i/Q5QVoa8asmGV/NrF jZ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785734; x=1716390534; 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=8IG0If/b6VQnjtJdCAv7RGvLxbc+5Pp5q/Lqtx4PykE=; b=Ynsy1DeQp5j75fQHCxt3v65wtADfOktRYZZgHUTRx8HnTD+VaGS3fGhqtDjU8QZyP+ lPlj05Euj/u9tbCJq7pQ0nlShl5Ot8fJ2xyl3SdavPc3zRUxFFLBUNqtBBaiaHKih1Q4 uyZSDFje/xBIt1BmldXABmVN/1gddZeDvnvR3A83YBuwQRw+JOwBBXomwTuTrxKx7+0d aZ62iVoBKySB3luYTGYtcgWAoqRjaq54IF8ZKv6+oXF0D1Xbzmh6KW7AocQV2iPlbf07 n/xhpKmMtG2O5rzZqoyu3Ln2HZ4fFxy8hWG2UaGOW3JPEQ+z0jQAuSLH8HGKvSXDZqjC ldmg== X-Gm-Message-State: AOJu0YxNAaLiGGtYO43DIQvSb3k/RgB3o+XCbpynY2j/RRKzRyGNvund jldClEzl+OupcshUX0bTx5vHW7GDgiQaphi+ZFIGvIfHrfg02dF9nhHJgvwoyMOlHHIGNhEn4Np Y8AM= X-Received: by 2002:a05:600c:138b:b0:419:f9ae:e50 with SMTP id 5b1f17b1804b1-41fead6ac32mr122146905e9.37.1715785734719; Wed, 15 May 2024 08:08:54 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 19/28] linux-user/i386: Fix -mregparm=3 for signal delivery Date: Wed, 15 May 2024 17:08:28 +0200 Message-Id: <20240515150837.259747-20-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::32e; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32e.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 Since v2.6.19, the kernel has supported -mregparm=3. Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 3271ebd333..6763b4bda8 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -405,8 +405,6 @@ void setup_frame(int sig, struct target_sigaction *ka, if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) goto give_sigsegv; - __put_user(sig, &frame->sig); - setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0], frame_addr + offsetof(struct sigframe, fpstate)); @@ -428,6 +426,13 @@ void setup_frame(int sig, struct target_sigaction *ka, env->regs[R_ESP] = frame_addr; env->eip = ka->_sa_handler; + /* Store argument for both -mregparm=3 and standard. */ + env->regs[R_EAX] = sig; + __put_user(sig, &frame->sig); + /* The kernel clears EDX and ECX even though there is only one arg. */ + env->regs[R_EDX] = 0; + env->regs[R_ECX] = 0; + cpu_x86_load_seg(env, R_DS, __USER_DS); cpu_x86_load_seg(env, R_ES, __USER_DS); cpu_x86_load_seg(env, R_SS, __USER_DS); @@ -449,9 +454,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUX86State *env) { abi_ulong frame_addr; -#ifndef TARGET_X86_64 - abi_ulong addr; -#endif struct rt_sigframe *frame; int i; @@ -461,14 +463,6 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) goto give_sigsegv; - /* These fields are only in rt_sigframe on 32 bit */ -#ifndef TARGET_X86_64 - __put_user(sig, &frame->sig); - addr = frame_addr + offsetof(struct rt_sigframe, info); - __put_user(addr, &frame->pinfo); - addr = frame_addr + offsetof(struct rt_sigframe, uc); - __put_user(addr, &frame->puc); -#endif if (ka->sa_flags & TARGET_SA_SIGINFO) { frame->info = *info; } @@ -508,9 +502,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->eip = ka->_sa_handler; #ifndef TARGET_X86_64 + /* Store arguments for both -mregparm=3 and standard. */ env->regs[R_EAX] = sig; + __put_user(sig, &frame->sig); env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, info); + __put_user(env->regs[R_EDX], &frame->pinfo); env->regs[R_ECX] = frame_addr + offsetof(struct rt_sigframe, uc); + __put_user(env->regs[R_ECX], &frame->puc); #else env->regs[R_EAX] = 0; env->regs[R_EDI] = sig; From patchwork Wed May 15 15:08:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796972 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033519wra; Wed, 15 May 2024 08:11:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVchnDXm0GqDlVBACRhDIr4wtPlvh8V1mr9aN8sZaE4pA+dFUydMdOmK7PuQOMhoYLFPLOEc5pitxB5Ist55OBO X-Google-Smtp-Source: AGHT+IGzsDg8AXTUz9ecZPLNhXv7yqaF2ynfjrfenEu/YDcbwbOQziGW1xXwUjujb1WAZ9rQ+PIL X-Received: by 2002:a05:6830:15:b0:6f0:4b5f:dc38 with SMTP id 46e09a7af769-6f0e929a4d4mr16582808a34.27.1715785893457; Wed, 15 May 2024 08:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785893; cv=none; d=google.com; s=arc-20160816; b=JWdbf6L047f7oqIh59KYQbbqh4mvQVNWfJLLIXbrn45rcH3szcoK0lxAZR/YeufFjr W938SttYwzQQz9Ix4x4dqt/IGcItEQNhE2Mo1cl/2ruYZAelfZnIk5rF62XFZ5MrmS9n LfJdLp/KnmwA/g/xtPYe3esqgTV1UTlCIx8mkusn0oo/GhuoEkgBQ4kWOPdIQ75L7qlN G7qkGFNQYNeVPNf/4ZKdUdDzMao3tcVYUqrE4pPT7TLhzgiG7qVJj+4WWUe46zl4qlOg ZnQKu8KFD/xmO4v+CxLxgxk6NLiep+kxSGzA+fpTgk7oXViQIVPeNmajMLB34ScQW6lV YoWA== 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=A/3mRVbjkwDF9eBMMUHlCcFHLaNSo0keoR5CYS7AGJ4=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=pi1GMALei8jZOKZ3JQ/pjpmHmoZXEoSF16PTlAocLJ5VxHmrbgTGUpKuX3AxHy7m+L UvsqcqoUQyuXNYhSHWykbK8DmobaHK0RzEzZTWNiu46sAkWOErJCQpnReVm0ikX0iDxO OaTslO6AN4eCdb8oFlgCzXhmqABMQTZMWqRn15BaaHXj+IT+2Hn6ADVUl8iXCVSO0uPr gy9p1+DXlU1fT/49NJNysOHB6h1NVD2m76NBCMIhZPokVTRvq6u0g8H8x5AWdc8zrWWx UIjaEIwIVK1oF14DMqWZoQDWfYbIw/aXAuznj4Okg+6LFSaHyOe0i5VLahpZRkyLH34t rWPQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QlGP/HPL"; 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=pass (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-481f335e201si1193047137.146.2024.05.15.08.11.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:33 -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=pass header.i=@linaro.org header.s=google header.b="QlGP/HPL"; 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=pass (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-0003yw-5V; 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 1s7GFb-0003wA-LP for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFU-00037z-NV for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:02 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-420180b5922so31881795e9.2 for ; Wed, 15 May 2024 08:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785735; x=1716390535; 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=A/3mRVbjkwDF9eBMMUHlCcFHLaNSo0keoR5CYS7AGJ4=; b=QlGP/HPL5kzNKbKAzEVzkeoA6QFr1XmDAvK0Zr47kZdqkCkipVdY84UMPJ2OT918tM 2mlCPBmWTK1wRpW5iP14BUB219uya7STLPLmynLQFASHzW0NkgIvfYu/TZwWcbnItOxX nvg/lll7XAo3LShWZboHR4PfvtOoYgodyGtZn0NsGrPU5Op8Q0IcrOjjAaj6CbOiZjE+ zfFGX4q4YgR0liHWYTee64B+JzPzgLQSv1IWnvnrZ11pqjHMiscaojFMDDbXqNfEf6a/ v0AAX6JZT/Tl0D0Ye8Z3Fllm6P/cAc8C7XF1hydqI2gG52ZSDhVnWM1OffJfQmA8c5lr uxkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785735; x=1716390535; 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=A/3mRVbjkwDF9eBMMUHlCcFHLaNSo0keoR5CYS7AGJ4=; b=ncZRcJ1biLu9ht3Q2scn0gJv2/aaUqPNShokyNQoFkm5Nau75xe5g8u/Z+K8oK5yJr Rj5xDiul8gkYSYJ1OC5TnNLnsjt0m48RTyAJq3nHSi0AAuL7FOxwOOMNbsoFuMQ5OTbP 8E3qVlOpaEmHgEu4kTllq01Xu5qOPgFu9HUvqa25fG8L9JWpMbzXtQMDG50N+rEvgc1o GJKVkIr64myr0KyHvemY1zyUDk9LBCpRggD0gm7NOpLVpk62NATDVf4bfL2tmKREBBOE Lps2jYahmxl+aPk49j4YIGogTSxcyNbxoUEiuQDNX7T1AeybHLfPW9if8Z5yncVY6b28 wJ3A== X-Gm-Message-State: AOJu0YyItTrjJfVXSjKG487Ihmf6j+odHgpxeH7dwXBLpkiDY282Zb0V PbygipkjgG9jelO0UUWix0+CP8mEGHRlOBPTykfFZR7rIcW4/ztzE72gZyj1sS/eaLZQDS7+u20 U0h0= X-Received: by 2002:a05:600c:35cb:b0:420:32f:3ddc with SMTP id 5b1f17b1804b1-420032f3f33mr135801965e9.24.1715785735441; Wed, 15 May 2024 08:08:55 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 20/28] linux-user/i386: Return boolean success from restore_sigcontext Date: Wed, 15 May 2024 17:08:29 +0200 Message-Id: <20240515150837.259747-21-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::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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 Invert the sense of the return value and use bool. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 6763b4bda8..9e6d883ea1 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -564,12 +564,12 @@ static int xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, return 0; } -static int -restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) +static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) { - int err = 1; abi_ulong fpstate_addr; unsigned int tmpflags; + struct target_fpstate *fpstate; + bool ok; #ifndef TARGET_X86_64 cpu_x86_load_seg(env, R_GS, tswap16(sc->gs)); @@ -617,29 +617,27 @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) // regs->orig_eax = -1; /* disable syscall checks */ fpstate_addr = tswapl(sc->fpstate); - if (fpstate_addr != 0) { - struct target_fpstate *fpstate; - if (!lock_user_struct(VERIFY_READ, fpstate, fpstate_addr, - sizeof(struct target_fpstate))) { - return err; - } -#ifndef TARGET_X86_64 - if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { - cpu_x86_frstor(env, fpstate_addr, 1); - err = 0; - } else { - err = xrstor_sigcontext(env, &fpstate->fxstate, - fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); - } -#else - err = xrstor_sigcontext(env, fpstate, fpstate_addr); -#endif - unlock_user_struct(fpstate, fpstate_addr, 0); - } else { - err = 0; + if (fpstate_addr == 0) { + return true; } + if (!lock_user_struct(VERIFY_READ, fpstate, fpstate_addr, + sizeof(struct target_fpstate))) { + return false; + } +#ifndef TARGET_X86_64 + if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { + cpu_x86_frstor(env, fpstate_addr, 1); + ok = true; + } else { + ok = !xrstor_sigcontext(env, &fpstate->fxstate, + fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); + } +#else + ok = !xrstor_sigcontext(env, fpstate, fpstate_addr); +#endif + unlock_user_struct(fpstate, fpstate_addr, 0); - return err; + return ok; } /* Note: there is no sigreturn on x86_64, there is only rt_sigreturn */ @@ -665,8 +663,9 @@ long do_sigreturn(CPUX86State *env) set_sigmask(&set); /* restore registers */ - if (restore_sigcontext(env, &frame->sc)) + if (!restore_sigcontext(env, &frame->sc)) { goto badframe; + } unlock_user_struct(frame, frame_addr, 0); return -QEMU_ESIGRETURN; @@ -690,7 +689,7 @@ long do_rt_sigreturn(CPUX86State *env) target_to_host_sigset(&set, &frame->uc.tuc_sigmask); set_sigmask(&set); - if (restore_sigcontext(env, &frame->uc.tuc_mcontext)) { + if (!restore_sigcontext(env, &frame->uc.tuc_mcontext)) { goto badframe; } From patchwork Wed May 15 15:08:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796964 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032836wra; Wed, 15 May 2024 08:10:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXWNvgxcLfr8OLDd3Bskx5kunUBMPkcPJhhoBdjRPuOpT8Dmv1tdRTh2atbK3NdIZzsIOIqyWn7F29ATonwfSW4 X-Google-Smtp-Source: AGHT+IEaCxIB23Ji8L9EigZzm5e3vfqmWL/LpBCHAg2ku73OhjyjICMsr41Ytqd1puXvbgkGX6v2 X-Received: by 2002:a05:6122:98f:b0:4da:ae51:b755 with SMTP id 71dfb90a1353d-4df8834ad8amr13225668e0c.3.1715785833152; Wed, 15 May 2024 08:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785833; cv=none; d=google.com; s=arc-20160816; b=Wgc6SIs5y5Psro7yOo9G9cBzfdB/5O98lXtBSFRouhpBld1lDZU948Y8oDXPYiphyg ggFVBX4JMKwiOxyfOA2PXQRpXA3mQZeyw3nlmN+E1fwc4b6OKRe6wTXr0PtZ+a5zyom8 XiiUF/khTDAVpQ3YXk9+rKp7YKO5y6JRb7NFfq3o1l6RvK6RhVpAk7PVW4/YgmfXB5pa vu7l/SgDagt1oKYR93Fli2fFpxHOXF6CYvDNeOHyRio17Fqp/HBl3SOBYbwP6LoH02Pp 0T/xSM9gfIpXlW2T5p85zJdVCiNPV0sgBd8UKIF80jpg9ZoS06+aTaR/bj3/CALaodMk zlJw== 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=gXRsFZySXvSqPrOv+ZAPgTOAgNl/fCJyejJjD81KENM=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=NpAw2KiO08onLyYc5uJtErHFGmc93Dkm0/b+8dtGxxpLt8zdW9iGg2SCTdrW9sZxGu dj2dwZzCFr2ifBjh2d/SyxZujCUfWU/6kRIMQl+MdoI0KJ6nK3qcYfKGgGY/wP+Qr14W NnBV+S1kltVVm2FLc/Iq/bEU5Pvv0/QAM6x5HQNimjDFE13S/Af6FEwwPxwCpvEaIYCn P0skphaW/1vj6Awwf+tcICHkAIjPBtFC7+9GZWQpAwfxdD3lAHi7dWTbH0/3L2uq6uKA V9RNjpAuqUBVFZowPVNugHcw5euloi74iVnnJQ5fUVV/8/q9bEN5VrfsIGErZD4ID9tD ldBQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vHZRRhiK; 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=pass (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 71dfb90a1353d-4df7c05c930si2500832e0c.138.2024.05.15.08.10.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:10:33 -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=pass header.i=@linaro.org header.s=google header.b=vHZRRhiK; 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=pass (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 1s7GFj-00040x-Vl; Wed, 15 May 2024 11:09:12 -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 1s7GFb-0003wG-SD for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFW-00038U-Uf for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:03 -0400 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2df848f9325so87351321fa.1 for ; Wed, 15 May 2024 08:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785736; x=1716390536; 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=gXRsFZySXvSqPrOv+ZAPgTOAgNl/fCJyejJjD81KENM=; b=vHZRRhiK5ZJPQVkd/qdRQTparGYylI6xjqRxT+SIGNYg1ZW92QRfSb9PLeT5QvETHw 9+NbBTrL4RjQP0iGx1VqIsgVL3naL/n9hwvZ4LJ/DFtJFmdX0jEB9SLpZNyb21mIug4z pPA623Tg7ykH/OZ9LRuJ2MEiz0f3+LmpxKwcaZ/GQA2SKztWByk3XhnJpwfpFfo3lotp TQzg/8gR8YLdnnB5baDjmSpfHF6dfAOhvbgq8wjIkCv2n/cIkgSFmoXC9nUhVQkdWWpy fY6Iuf6Y+PgccbWsYKjcFYriq6tGT4rMlWyOqN4OjnD7QLJIwKbHTaEcNSMVYsz02Jxo 4hLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785736; x=1716390536; 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=gXRsFZySXvSqPrOv+ZAPgTOAgNl/fCJyejJjD81KENM=; b=dOl+W+qwWA9eav95b2qbPoopZrWV+oPcEbyJxavc2s98P0CHh7Ayeh9EmxGkdcqGcw GJAh3eaiASpyOAh3pPEkTZjV8hP5MvbasvT7XnhisFBxHnaK0x6MauTPKzAlA8RLyJqD kv/auwv/dtbKHi0to6lxYjhdVTODwsKfwLcWch1WiQ2/06hbnsqixzqRHJgoRaCz7pt3 n3XXwq2kELwhhEwLaf781/CwROlmdsrXaIkitPq1Is2V9jekzPc3MG9doD/M6M5UozO1 jXHaUAp9z6pFm34pmlk8LPHlO4rKL6hhwHBOk/1X3JfutEZAFeYmIFBZ3uGaObZ2micZ kLKg== X-Gm-Message-State: AOJu0YzPJQmSxK/O8SZltU4wOxhpHMamcdh2byb6z85COnAvc6p8q3SX raEq1L3fkRC+siC9gqSLZDdwsPJeIAHjHTw4EAwl493LUfbGh7G3atbDSPtCg9jvPQ5goV6rI6A xAjA= X-Received: by 2002:a2e:7e05:0:b0:2dc:bf5c:9648 with SMTP id 38308e7fff4ca-2e51fd4b1f2mr115464991fa.19.1715785736240; Wed, 15 May 2024 08:08:56 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 21/28] linux-user/i386: Return boolean success from xrstor_sigcontext Date: Wed, 15 May 2024 17:08:30 +0200 Message-Id: <20240515150837.259747-22-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::234; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x234.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 Invert the sense of the return value and use bool. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 9e6d883ea1..03031ef9e5 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -530,8 +530,8 @@ give_sigsegv: force_sigsegv(sig); } -static int xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, - abi_ulong fxsave_addr) +static bool xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, + abi_ulong fxsave_addr) { struct target_fpx_sw_bytes *sw = (void *)&fxsave->sw_reserved; @@ -549,19 +549,19 @@ static int xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, && extended_size >= minimum_size) { if (!access_ok(env_cpu(env), VERIFY_READ, fxsave_addr, extended_size - TARGET_FPSTATE_FXSAVE_OFFSET)) { - return 1; + return false; } magic2 = tswapl(*(uint32_t *)((void *)fxsave + xstate_size)); if (magic2 == TARGET_FP_XSTATE_MAGIC2) { cpu_x86_xrstor(env, fxsave_addr, -1); - return 0; + return true; } } /* fall through to fxrstor */ } cpu_x86_fxrstor(env, fxsave_addr); - return 0; + return true; } static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) @@ -629,11 +629,11 @@ static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) cpu_x86_frstor(env, fpstate_addr, 1); ok = true; } else { - ok = !xrstor_sigcontext(env, &fpstate->fxstate, - fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); + ok = xrstor_sigcontext(env, &fpstate->fxstate, + fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); } #else - ok = !xrstor_sigcontext(env, fpstate, fpstate_addr); + ok = xrstor_sigcontext(env, fpstate, fpstate_addr); #endif unlock_user_struct(fpstate, fpstate_addr, 0); From patchwork Wed May 15 15:08:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796961 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3032347wra; Wed, 15 May 2024 08:09:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUQhIuRFyfef54hfx4/dBRCNFpkfz+wSfIUWWwP90mnx+anzZOBVLmCLbl1begT57f4GDaixClVuXzyCiVwruut X-Google-Smtp-Source: AGHT+IFJ2QRkXGp28g4fjPihJARDUd+ySSEsgRyaMzubtt2QhybBVPikLyQZAXd9hN4jIdN3PJJT X-Received: by 2002:a05:6122:31a1:b0:4d3:34f4:7e99 with SMTP id 71dfb90a1353d-4df8813d173mr13162223e0c.0.1715785789178; 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=GuMB/AzTAB9HMIXri1yR0WXWMK0iCeMYa1nu0uxeAShz9STsD3g2VBGNTh5IZkUqta 3dNWSYwJLgJXYJx7zwuCsMNhMoXpipv5ITHcoH6Ik5ndgF0zyv0NzwCtIEBpMBDSRYf9 MPi/4kKeEwf0j4VnQ5jsLQD/L5V8OHPKdrotJGg7PGRuYxeix5knhfiEVaL16EKJRi1y uknP8P3t9ZBnq0bucMTUBvMz68CpOF9q2Vcmps0izy0uwZWax/XefjGQleDRGWiXcCtm FrwklIo2nod6TkWkdXfH4URkm5wQ46Y/joGGo3KtcZo51uw02LHC+7IXMoVdgmgg8JiT kzKw== 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=NmdY83sMBqsJ6J92iPIEFflQV4nP5SinQ+Wwfv7WG8M=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=W3nY6SofHBx1QYwPC8utMkpr0QnTgk2NLZDigA8uIfunlCyZXRyu60fXSPWmc0ek/8 izGfdDKlQ16Nnup4qcbZYo3vDlujyWkTg8Ke0giyOWIlX0O2SnaHTH8VzDO9nUtOiLhz 5Yuji8U2BJ9aGtgq8KC6qx/4mu+hpDKLMRiHk4yHoLrgAASJGOlA+4ISGJl+INm1/3If zsnrGXTxp7ynXHTJzbFaddgLmRBmlNn9+iwUnUFNWMmpTxqWt/io4f+SgoygQpeCzgdv mpgTSuo6642mnupdirMZfbIbBiJ2HEoewjpE/eY+bk7tqVTRg2JJtFnSwSvtbp+vw4LQ Z7/g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hiY+Chkm; 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=pass (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 71dfb90a1353d-4df7bf86806si2167976e0c.68.2024.05.15.08.09.48 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=pass header.i=@linaro.org header.s=google header.b=hiY+Chkm; 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=pass (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 1s7GFk-00041c-OE; Wed, 15 May 2024 11:09:12 -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 1s7GFc-0003wb-Dt for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFW-0003AK-Q1 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:03 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-41ff5e3dc3bso39439465e9.1 for ; Wed, 15 May 2024 08:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785737; x=1716390537; 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=NmdY83sMBqsJ6J92iPIEFflQV4nP5SinQ+Wwfv7WG8M=; b=hiY+ChkmTWBauf0q8+o44uxZ01G1KpHmu/TwJDoYu2lBcFSCpET6cPb/sbM4pB3ZSB oY6gwz7SYTdJ5s/QXMljVSo3BCyte92+LidXxv+rkZl8qJYGi0MylrvN9uafHV5lXr+H XsBrpvWzCtuUQsj6mhWIQTtfmo6lJPsrq0yv244tDKlRDjqb1yzCM4VGCGQsVceXCIg2 HeKQNG0ZYLuUvXbzMH6K9z6FsVtuSb9os0lSzlnjsKtE4INWGIsNDe1vidqubpDXn/cp bXRpaeKOJJx36Bymt8dtcjM0REvaoFfNGdffyroGOio9+BYAiBrMiwzPnWC8f/HUNJaF 5WTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785737; x=1716390537; 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=NmdY83sMBqsJ6J92iPIEFflQV4nP5SinQ+Wwfv7WG8M=; b=gmh/mAgN89VSrdg9xo35p6FAZgXARhFQ5UDmovnlnSj/P4Tj7H42kY4LxqClIoL/Ac S2LT60GB9KtiPgd89yWWo9M4g3kz8l+WVkMrpy/2NGbpx2HTWo4hxZQ/FxI+qdt8GYsK /ahzNlOvOrKEALSseGM0myeTtekODyP35/eFJSrgaordbjo30VTQ/+Odc7uzDGuhxjY0 IBibuv/VPST+fI2LCNEmuewWx80X9khgy1f34FkhzoyKft5WnKJOe80Bdf6ykdFR16KD RsRefqu7HBZDCL/DdZ8lHH7/Aj6zKaRY/Kr0GgPTaWZxE22bvLoMlBXX+D6EQ8iMwbt8 wWFQ== X-Gm-Message-State: AOJu0YykbHh7HJLahjR+yeWGNylE/odGZ+MYYgXrmX9nWyzhoOvfQSu2 JS/gWkRNuvrlervPQ1zdGbeT6JIpbojaLA4BiEed/X38h7Ozl3U/TyzZX0a6F9ODmSd11spmA2X XnkI= X-Received: by 2002:a05:600c:468c:b0:420:1067:d698 with SMTP id 5b1f17b1804b1-4201067d80bmr88255775e9.23.1715785737104; Wed, 15 May 2024 08:08:57 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 22/28] linux-user/i386: Fix allocation and alignment of fp state Date: Wed, 15 May 2024 17:08:31 +0200 Message-Id: <20240515150837.259747-23-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::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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 For modern cpus, the kernel uses xsave to store all extra cpu state across the signal handler. For xsave/xrstor to work, the pointer must be 64 byte aligned. Moreover, the regular part of the signal frame must be 16 byte aligned. Attempt to mirror the kernel code as much as possible. Use enum FPStateKind instead of use_xsave() and use_fxsr(). Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1648 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 558 +++++++++++++++++++------------ tests/tcg/x86_64/test-1648.c | 33 ++ tests/tcg/x86_64/Makefile.target | 1 + 3 files changed, 377 insertions(+), 215 deletions(-) create mode 100644 tests/tcg/x86_64/test-1648.c diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 03031ef9e5..95dd01820d 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -65,20 +65,6 @@ struct target_fpstate_32 { X86LegacyXSaveArea fxstate; }; -/* - * For simplicity, setup_frame aligns struct target_fpstate_32 to - * 16 bytes, so ensure that the FXSAVE area is also aligned. - */ -QEMU_BUILD_BUG_ON(offsetof(struct target_fpstate_32, fxstate) & 15); - -#ifndef TARGET_X86_64 -# define target_fpstate target_fpstate_32 -# define TARGET_FPSTATE_FXSAVE_OFFSET offsetof(struct target_fpstate_32, fxstate) -#else -# define target_fpstate X86LegacyXSaveArea -# define TARGET_FPSTATE_FXSAVE_OFFSET 0 -#endif - struct target_sigcontext_32 { uint16_t gs, __gsh; uint16_t fs, __fsh; @@ -161,24 +147,16 @@ struct sigframe { int sig; struct target_sigcontext sc; /* - * The actual fpstate is placed after retcode[] below, to make - * room for the variable-sized xsave data. The older unused fpstate - * has to be kept to avoid changing the offset of extramask[], which + * The actual fpstate is placed after retcode[] below, to make room + * for the variable-sized xsave data. The older unused fpstate has + * to be kept to avoid changing the offset of extramask[], which * is part of the ABI. */ - struct target_fpstate fpstate_unused; + struct target_fpstate_32 fpstate_unused; abi_ulong extramask[TARGET_NSIG_WORDS-1]; char retcode[8]; - - /* - * This field will be 16-byte aligned in memory. Applying QEMU_ALIGNED - * to it ensures that the base of the frame has an appropriate alignment - * too. - */ - struct target_fpstate fpstate QEMU_ALIGNED(8); + /* fp state follows here */ }; -#define TARGET_SIGFRAME_FXSAVE_OFFSET ( \ - offsetof(struct sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET) struct rt_sigframe { abi_ulong pretcode; @@ -188,10 +166,8 @@ struct rt_sigframe { struct target_siginfo info; struct target_ucontext uc; char retcode[8]; - struct target_fpstate fpstate QEMU_ALIGNED(8); + /* fp state follows here */ }; -#define TARGET_RT_SIGFRAME_FXSAVE_OFFSET ( \ - offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET) /* * Verify that vdso-asmoffset.h constants match. @@ -209,66 +185,178 @@ struct rt_sigframe { abi_ulong pretcode; struct target_ucontext uc; struct target_siginfo info; - struct target_fpstate fpstate QEMU_ALIGNED(16); + /* fp state follows here */ }; -#define TARGET_RT_SIGFRAME_FXSAVE_OFFSET ( \ - offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET) #endif +typedef enum { +#ifndef TARGET_X86_64 + FPSTATE_FSAVE, +#endif + FPSTATE_FXSAVE, + FPSTATE_XSAVE +} FPStateKind; + +static FPStateKind get_fpstate_kind(CPUX86State *env) +{ + if (env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) { + return FPSTATE_XSAVE; + } +#ifdef TARGET_X86_64 + return FPSTATE_FXSAVE; +#else + if (env->features[FEAT_1_EDX] & CPUID_FXSR) { + return FPSTATE_FXSAVE; + } + return FPSTATE_FSAVE; +#endif +} + +static unsigned get_fpstate_size(CPUX86State *env, FPStateKind fpkind) +{ + /* + * Kernel: + * fpu__alloc_mathframe + * xstate_sigframe_size(current->thread.fpu.fpstate); + * size = fpstate->user_size + * use_xsave() ? size + FP_XSTATE_MAGIC2_SIZE : size + * where fpstate->user_size is computed at init in + * fpu__init_system_xstate_size_legacy and + * fpu__init_system_xstate. + * + * Here we have no place to pre-compute, so inline it all. + */ + switch (fpkind) { + case FPSTATE_XSAVE: + return (xsave_area_size(env->xcr0, false) + + TARGET_FP_XSTATE_MAGIC2_SIZE); + case FPSTATE_FXSAVE: + return sizeof(X86LegacyXSaveArea); +#ifndef TARGET_X86_64 + case FPSTATE_FSAVE: + return sizeof(struct target_fregs_state); +#endif + } + g_assert_not_reached(); +} + +static abi_ptr get_sigframe(struct target_sigaction *ka, CPUX86State *env, + unsigned frame_size, FPStateKind fpkind, + abi_ptr *fpstate, abi_ptr *fxstate, abi_ptr *fpend) +{ + abi_ptr sp; + unsigned math_size; + + /* Default to using normal stack */ + sp = get_sp_from_cpustate(env); +#ifdef TARGET_X86_64 + sp -= 128; /* this is the redzone */ +#endif + + /* This is the X/Open sanctioned signal stack switching. */ + if (ka->sa_flags & TARGET_SA_ONSTACK) { + sp = target_sigsp(sp, ka); + } else { +#ifndef TARGET_X86_64 + /* This is the legacy signal stack switching. */ + if ((env->segs[R_SS].selector & 0xffff) != __USER_DS + && !(ka->sa_flags & TARGET_SA_RESTORER) + && ka->sa_restorer) { + sp = ka->sa_restorer; + } +#endif + } + + math_size = get_fpstate_size(env, fpkind); + sp = ROUND_DOWN(sp - math_size, 64); + *fpend = sp + math_size; + *fxstate = sp; +#ifndef TARGET_X86_64 + if (fpkind != FPSTATE_FSAVE) { + sp -= sizeof(struct target_fregs_state); + } +#endif + *fpstate = sp; + + sp -= frame_size; + /* + * Align the stack pointer according to the ABI, i.e. so that on + * function entry ((sp + sizeof(return_addr)) & 15) == 0. + */ + sp += sizeof(target_ulong); + sp = ROUND_DOWN(sp, 16); + sp -= sizeof(target_ulong); + + return sp; +} + /* * Set up a signal frame. */ -static void xsave_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, - abi_ulong fxsave_addr) +static void fxsave_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxstate, + abi_ptr fxstate_addr) { - struct target_fpx_sw_bytes *sw = (void *)&fxsave->sw_reserved; + struct target_fpx_sw_bytes *sw = (void *)&fxstate->sw_reserved; - if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) { - /* fxsave_addr must be 16 byte aligned for fxsave */ - assert(!(fxsave_addr & 0xf)); - - cpu_x86_fxsave(env, fxsave_addr); - __put_user(0, &sw->magic1); - } else { - uint32_t xstate_size = xsave_area_size(env->xcr0, false); - - /* - * extended_size is the offset from fpstate_addr to right after the end - * of the extended save states. On 32-bit that includes the legacy - * FSAVE area. - */ - uint32_t extended_size = TARGET_FPSTATE_FXSAVE_OFFSET - + xstate_size + TARGET_FP_XSTATE_MAGIC2_SIZE; - - /* fxsave_addr must be 64 byte aligned for xsave */ - assert(!(fxsave_addr & 0x3f)); - - /* Zero the header, XSAVE *adds* features to an existing save state. */ - memset(fxsave + 1, 0, sizeof(X86XSaveHeader)); - cpu_x86_xsave(env, fxsave_addr, -1); - __put_user(TARGET_FP_XSTATE_MAGIC1, &sw->magic1); - __put_user(extended_size, &sw->extended_size); - __put_user(env->xcr0, &sw->xfeatures); - __put_user(xstate_size, &sw->xstate_size); - __put_user(TARGET_FP_XSTATE_MAGIC2, - (uint32_t *)((void *)fxsave + xstate_size)); - } + /* fxstate_addr must be 16 byte aligned for fxsave */ + assert(!(fxstate_addr & 0xf)); + cpu_x86_fxsave(env, fxstate_addr); + __put_user(0, &sw->magic1); } -static void setup_sigcontext(struct target_sigcontext *sc, - struct target_fpstate *fpstate, CPUX86State *env, abi_ulong mask, - abi_ulong fpstate_addr) +static void xsave_sigcontext(CPUX86State *env, + X86LegacyXSaveArea *fxstate, + abi_ptr fpstate_addr, + abi_ptr xstate_addr, + abi_ptr fpend_addr) +{ + struct target_fpx_sw_bytes *sw = (void *)&fxstate->sw_reserved; + /* + * extended_size is the offset from fpstate_addr to right after + * the end of the extended save states. On 32-bit that includes + * the legacy FSAVE area. + */ + uint32_t extended_size = fpend_addr - fpstate_addr; + /* Recover xstate_size by removing magic2. */ + uint32_t xstate_size = (fpend_addr - xstate_addr + - TARGET_FP_XSTATE_MAGIC2_SIZE); + /* magic2 goes just after xstate. */ + uint32_t *magic2 = (void *)fxstate + xstate_size; + + /* xstate_addr must be 64 byte aligned for xsave */ + assert(!(xstate_addr & 0x3f)); + + /* Zero the header, XSAVE *adds* features to an existing save state. */ + memset(fxstate + 1, 0, sizeof(X86XSaveHeader)); + cpu_x86_xsave(env, xstate_addr, -1); + + __put_user(TARGET_FP_XSTATE_MAGIC1, &sw->magic1); + __put_user(extended_size, &sw->extended_size); + __put_user(env->xcr0, &sw->xfeatures); + __put_user(xstate_size, &sw->xstate_size); + __put_user(TARGET_FP_XSTATE_MAGIC2, magic2); +} + +static void setup_sigcontext(CPUX86State *env, + struct target_sigcontext *sc, + abi_ulong mask, FPStateKind fpkind, + struct target_fregs_state *fpstate, + abi_ptr fpstate_addr, + X86LegacyXSaveArea *fxstate, + abi_ptr fxstate_addr, + abi_ptr fpend_addr) { CPUState *cs = env_cpu(env); + #ifndef TARGET_X86_64 uint16_t magic; /* already locked in setup_frame() */ - __put_user(env->segs[R_GS].selector, (unsigned int *)&sc->gs); - __put_user(env->segs[R_FS].selector, (unsigned int *)&sc->fs); - __put_user(env->segs[R_ES].selector, (unsigned int *)&sc->es); - __put_user(env->segs[R_DS].selector, (unsigned int *)&sc->ds); + __put_user(env->segs[R_GS].selector, (uint32_t *)&sc->gs); + __put_user(env->segs[R_FS].selector, (uint32_t *)&sc->fs); + __put_user(env->segs[R_ES].selector, (uint32_t *)&sc->es); + __put_user(env->segs[R_DS].selector, (uint32_t *)&sc->ds); __put_user(env->regs[R_EDI], &sc->edi); __put_user(env->regs[R_ESI], &sc->esi); __put_user(env->regs[R_EBP], &sc->ebp); @@ -280,21 +368,15 @@ static void setup_sigcontext(struct target_sigcontext *sc, __put_user(cs->exception_index, &sc->trapno); __put_user(env->error_code, &sc->err); __put_user(env->eip, &sc->eip); - __put_user(env->segs[R_CS].selector, (unsigned int *)&sc->cs); + __put_user(env->segs[R_CS].selector, (uint32_t *)&sc->cs); __put_user(env->eflags, &sc->eflags); __put_user(env->regs[R_ESP], &sc->esp_at_signal); - __put_user(env->segs[R_SS].selector, (unsigned int *)&sc->ss); + __put_user(env->segs[R_SS].selector, (uint32_t *)&sc->ss); cpu_x86_fsave(env, fpstate_addr, 1); - fpstate->fpstate.status = fpstate->fpstate.swd; - if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { - magic = 0xffff; - } else { - xsave_sigcontext(env, &fpstate->fxstate, - fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); - magic = 0; - } - __put_user(magic, &fpstate->fpstate.magic); + fpstate->status = fpstate->swd; + magic = (fpkind == FPSTATE_FSAVE ? 0 : 0xffff); + __put_user(magic, &fpstate->magic); #else __put_user(env->regs[R_EDI], &sc->rdi); __put_user(env->regs[R_ESI], &sc->rsi); @@ -323,57 +405,25 @@ static void setup_sigcontext(struct target_sigcontext *sc, __put_user((uint16_t)0, &sc->gs); __put_user((uint16_t)0, &sc->fs); __put_user(env->segs[R_SS].selector, &sc->ss); - - xsave_sigcontext(env, fpstate, fpstate_addr); #endif - __put_user(fpstate_addr, &sc->fpstate); + switch (fpkind) { + case FPSTATE_XSAVE: + xsave_sigcontext(env, fxstate, fpstate_addr, fxstate_addr, fpend_addr); + break; + case FPSTATE_FXSAVE: + fxsave_sigcontext(env, fxstate, fxstate_addr); + break; + default: + break; + } + __put_user(fpstate_addr, &sc->fpstate); /* non-iBCS2 extensions.. */ __put_user(mask, &sc->oldmask); __put_user(env->cr[2], &sc->cr2); } -/* - * Determine which stack to use.. - */ - -static inline abi_ulong -get_sigframe(struct target_sigaction *ka, CPUX86State *env, size_t fxsave_offset) -{ - unsigned long esp; - - /* Default to using normal stack */ - esp = get_sp_from_cpustate(env); -#ifdef TARGET_X86_64 - esp -= 128; /* this is the redzone */ -#endif - - /* This is the X/Open sanctioned signal stack switching. */ - if (ka->sa_flags & TARGET_SA_ONSTACK) { - esp = target_sigsp(esp, ka); - } else { -#ifndef TARGET_X86_64 - /* This is the legacy signal stack switching. */ - if ((env->segs[R_SS].selector & 0xffff) != __USER_DS && - !(ka->sa_flags & TARGET_SA_RESTORER) && - ka->sa_restorer) { - esp = (unsigned long) ka->sa_restorer; - } -#endif - } - - if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { - return (esp - (fxsave_offset + sizeof(X86LegacyXSaveArea))) & -8ul; - } else if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) { - return ((esp - sizeof(X86LegacyXSaveArea)) & -16ul) - fxsave_offset; - } else { - size_t xstate_size = - xsave_area_size(env->xcr0, false) + TARGET_FP_XSTATE_MAGIC2_SIZE; - return ((esp - xstate_size) & -64ul) - fxsave_offset; - } -} - #ifndef TARGET_X86_64 static void install_sigtramp(void *tramp) { @@ -395,20 +445,36 @@ static void install_rt_sigtramp(void *tramp) void setup_frame(int sig, struct target_sigaction *ka, target_sigset_t *set, CPUX86State *env) { - abi_ulong frame_addr; + abi_ptr frame_addr, fpstate_addr, fxstate_addr, fpend_addr; struct sigframe *frame; - int i; + struct target_fregs_state *fpstate; + X86LegacyXSaveArea *fxstate; + unsigned total_size; + FPStateKind fpkind; - frame_addr = get_sigframe(ka, env, TARGET_SIGFRAME_FXSAVE_OFFSET); + fpkind = get_fpstate_kind(env); + frame_addr = get_sigframe(ka, env, sizeof(struct sigframe), fpkind, + &fpstate_addr, &fxstate_addr, &fpend_addr); trace_user_setup_frame(env, frame_addr); - if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) - goto give_sigsegv; + total_size = fpend_addr - frame_addr; + frame = lock_user(VERIFY_WRITE, frame_addr, total_size, 0); + if (!frame) { + force_sigsegv(sig); + return; + } - setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0], - frame_addr + offsetof(struct sigframe, fpstate)); + fxstate = (void *)frame + (fxstate_addr - frame_addr); +#ifdef TARGET_X86_64 + fpstate = NULL; +#else + fpstate = (void *)frame + (fpstate_addr - frame_addr); +#endif - for (i = 1; i < TARGET_NSIG_WORDS; i++) { + setup_sigcontext(env, &frame->sc, set->sig[0], fpkind, + fpstate, fpstate_addr, fxstate, fxstate_addr, fpend_addr); + + for (int i = 1; i < TARGET_NSIG_WORDS; i++) { __put_user(set->sig[i], &frame->extramask[i - 1]); } @@ -421,6 +487,7 @@ void setup_frame(int sig, struct target_sigaction *ka, install_sigtramp(frame->retcode); __put_user(default_sigreturn, &frame->pretcode); } + unlock_user(frame, frame_addr, total_size); /* Set up registers for signal handler */ env->regs[R_ESP] = frame_addr; @@ -438,13 +505,6 @@ void setup_frame(int sig, struct target_sigaction *ka, cpu_x86_load_seg(env, R_SS, __USER_DS); cpu_x86_load_seg(env, R_CS, __USER_CS); env->eflags &= ~TF_MASK; - - unlock_user_struct(frame, frame_addr, 1); - - return; - -give_sigsegv: - force_sigsegv(sig); } #endif @@ -453,37 +513,51 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUX86State *env) { - abi_ulong frame_addr; + abi_ptr frame_addr, fpstate_addr, fxstate_addr, fpend_addr; struct rt_sigframe *frame; - int i; + X86LegacyXSaveArea *fxstate; + struct target_fregs_state *fpstate; + unsigned total_size; + FPStateKind fpkind; - frame_addr = get_sigframe(ka, env, TARGET_RT_SIGFRAME_FXSAVE_OFFSET); + fpkind = get_fpstate_kind(env); + frame_addr = get_sigframe(ka, env, sizeof(struct rt_sigframe), fpkind, + &fpstate_addr, &fxstate_addr, &fpend_addr); trace_user_setup_rt_frame(env, frame_addr); - if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) + total_size = fpend_addr - frame_addr; + frame = lock_user(VERIFY_WRITE, frame_addr, total_size, 0); + if (!frame) { goto give_sigsegv; + } if (ka->sa_flags & TARGET_SA_SIGINFO) { frame->info = *info; } /* Create the ucontext. */ - if (env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) { - __put_user(1, &frame->uc.tuc_flags); - } else { - __put_user(0, &frame->uc.tuc_flags); - } + __put_user(fpkind == FPSTATE_XSAVE, &frame->uc.tuc_flags); __put_user(0, &frame->uc.tuc_link); target_save_altstack(&frame->uc.tuc_stack, env); - setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, env, - set->sig[0], frame_addr + offsetof(struct rt_sigframe, fpstate)); - for (i = 0; i < TARGET_NSIG_WORDS; i++) { + fxstate = (void *)frame + (fxstate_addr - frame_addr); +#ifdef TARGET_X86_64 + fpstate = NULL; +#else + fpstate = (void *)frame + (fpstate_addr - frame_addr); +#endif + + setup_sigcontext(env, &frame->uc.tuc_mcontext, set->sig[0], fpkind, + fpstate, fpstate_addr, fxstate, fxstate_addr, fpend_addr); + + for (int i = 0; i < TARGET_NSIG_WORDS; i++) { __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } - /* Set up to return from userspace. If provided, use a stub - already in userspace. */ + /* + * Set up to return from userspace. If provided, use a stub + * already in userspace. + */ if (ka->sa_flags & TARGET_SA_RESTORER) { __put_user(ka->sa_restorer, &frame->pretcode); } else { @@ -515,60 +589,113 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->regs[R_ESI] = frame_addr + offsetof(struct rt_sigframe, info); env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, uc); #endif + unlock_user(frame, frame_addr, total_size); cpu_x86_load_seg(env, R_DS, __USER_DS); cpu_x86_load_seg(env, R_ES, __USER_DS); cpu_x86_load_seg(env, R_CS, __USER_CS); cpu_x86_load_seg(env, R_SS, __USER_DS); env->eflags &= ~TF_MASK; - - unlock_user_struct(frame, frame_addr, 1); - return; give_sigsegv: force_sigsegv(sig); } -static bool xrstor_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxsave, - abi_ulong fxsave_addr) +/* + * Restore a signal frame. + */ + +static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, + X86LegacyXSaveArea *fxstate, + abi_ptr fxstate_addr) { - struct target_fpx_sw_bytes *sw = (void *)&fxsave->sw_reserved; + struct target_fpx_sw_bytes *sw = (void *)&fxstate->sw_reserved; + uint32_t magic1, magic2; + uint32_t extended_size, xstate_size, min_size, max_size; - if (env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE) { - uint32_t magic1 = tswapl(sw->magic1); - uint32_t extended_size = tswapl(sw->extended_size); - uint32_t xstate_size = tswapl(sw->xstate_size); - uint32_t minimum_size = (TARGET_FPSTATE_FXSAVE_OFFSET - + TARGET_FP_XSTATE_MAGIC2_SIZE - + xstate_size); - uint32_t magic2; + switch (fpkind) { + case FPSTATE_XSAVE: + magic1 = tswap32(sw->magic1); + extended_size = tswap32(sw->extended_size); + xstate_size = tswap32(sw->xstate_size); + min_size = sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader); + max_size = xsave_area_size(env->xcr0, false); - /* Linux checks MAGIC2 using xstate_size, not extended_size. */ - if (magic1 == TARGET_FP_XSTATE_MAGIC1 - && extended_size >= minimum_size) { - if (!access_ok(env_cpu(env), VERIFY_READ, fxsave_addr, - extended_size - TARGET_FPSTATE_FXSAVE_OFFSET)) { - return false; - } - magic2 = tswapl(*(uint32_t *)((void *)fxsave + xstate_size)); - if (magic2 == TARGET_FP_XSTATE_MAGIC2) { - cpu_x86_xrstor(env, fxsave_addr, -1); - return true; - } + /* Check for the first magic field and other error scenarios. */ + if (magic1 != FP_XSTATE_MAGIC1 || + xstate_size < min_size || + xstate_size > max_size || + xstate_size > extended_size) { + break; } - /* fall through to fxrstor */ + if (!access_ok(env_cpu(env), VERIFY_READ, fxstate_addr, + xstate_size + TARGET_FP_XSTATE_MAGIC2_SIZE)) { + return false; + } + /* + * Check for the presence of second magic word at the end of memory + * layout. This detects the case where the user just copied the legacy + * fpstate layout with out copying the extended state information + * in the memory layout. + */ + if (get_user_u32(magic2, fxstate_addr + xstate_size)) { + return false; + } + if (magic2 != FP_XSTATE_MAGIC2) { + break; + } + cpu_x86_xrstor(env, fxstate_addr, -1); + return true; + + default: + break; } - cpu_x86_fxrstor(env, fxsave_addr); + cpu_x86_fxrstor(env, fxstate_addr); return true; } +#ifndef TARGET_X86_64 +static bool frstor_sigcontext(CPUX86State *env, FPStateKind fpkind, + struct target_fregs_state *fpstate, + abi_ptr fpstate_addr, + X86LegacyXSaveArea *fxstate, + abi_ptr fxstate_addr) +{ + switch (fpkind) { + case FPSTATE_XSAVE: + if (!xrstor_sigcontext(env, fpkind, fxstate, fxstate_addr)) { + return false; + } + break; + case FPSTATE_FXSAVE: + cpu_x86_fxrstor(env, fxstate_addr); + break; + case FPSTATE_FSAVE: + break; + default: + g_assert_not_reached(); + } + + /* + * Copy the legacy state because the FP portion of the FX frame has + * to be ignored for histerical raisins. The kernel folds the two + * states together and then performs a single load; here we perform + * the merge within ENV by loading XSTATE/FXSTATE first, then + * overriding with the FSTATE afterward. + */ + cpu_x86_frstor(env, fpstate_addr, 1); + return true; +} +#endif + static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) { - abi_ulong fpstate_addr; - unsigned int tmpflags; - struct target_fpstate *fpstate; + abi_ptr fpstate_addr; + unsigned tmpflags, math_size; + FPStateKind fpkind; + void *fpstate; bool ok; #ifndef TARGET_X86_64 @@ -614,29 +741,33 @@ static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) tmpflags = tswapl(sc->eflags); env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); - // regs->orig_eax = -1; /* disable syscall checks */ fpstate_addr = tswapl(sc->fpstate); if (fpstate_addr == 0) { return true; } - if (!lock_user_struct(VERIFY_READ, fpstate, fpstate_addr, - sizeof(struct target_fpstate))) { + + fpkind = get_fpstate_kind(env); + math_size = get_fpstate_size(env, fpkind); +#ifndef TARGET_X86_64 + if (fpkind != FPSTATE_FSAVE) { + math_size += sizeof(struct target_fregs_state); + } +#endif + fpstate = lock_user(VERIFY_READ, fpstate_addr, math_size, 1); + if (!fpstate) { return false; } -#ifndef TARGET_X86_64 - if (!(env->features[FEAT_1_EDX] & CPUID_FXSR)) { - cpu_x86_frstor(env, fpstate_addr, 1); - ok = true; - } else { - ok = xrstor_sigcontext(env, &fpstate->fxstate, - fpstate_addr + TARGET_FPSTATE_FXSAVE_OFFSET); - } -#else - ok = xrstor_sigcontext(env, fpstate, fpstate_addr); -#endif - unlock_user_struct(fpstate, fpstate_addr, 0); +#ifdef TARGET_X86_64 + ok = xrstor_sigcontext(env, fpkind, fpstate, fpstate_addr); +#else + ok = frstor_sigcontext(env, fpkind, fpstate, fpstate_addr, + fpstate + sizeof(struct target_fregs_state), + fpstate_addr + sizeof(struct target_fregs_state)); +#endif + + unlock_user(fpstate, fpstate_addr, 0); return ok; } @@ -648,30 +779,27 @@ long do_sigreturn(CPUX86State *env) abi_ulong frame_addr = env->regs[R_ESP] - 8; target_sigset_t target_set; sigset_t set; - int i; trace_user_do_sigreturn(env, frame_addr); - if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) - goto badframe; - /* set blocked signals */ - __get_user(target_set.sig[0], &frame->sc.oldmask); - for(i = 1; i < TARGET_NSIG_WORDS; i++) { - __get_user(target_set.sig[i], &frame->extramask[i - 1]); + if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) { + force_sig(TARGET_SIGSEGV); + return -QEMU_ESIGRETURN; } + /* Set blocked signals. */ + __get_user(target_set.sig[0], &frame->sc.oldmask); + for (int i = 1; i < TARGET_NSIG_WORDS; i++) { + __get_user(target_set.sig[i], &frame->extramask[i - 1]); + } target_to_host_sigset_internal(&set, &target_set); set_sigmask(&set); - /* restore registers */ + /* Restore registers */ if (!restore_sigcontext(env, &frame->sc)) { - goto badframe; + force_sig(TARGET_SIGSEGV); } - unlock_user_struct(frame, frame_addr, 0); - return -QEMU_ESIGRETURN; -badframe: unlock_user_struct(frame, frame_addr, 0); - force_sig(TARGET_SIGSEGV); return -QEMU_ESIGRETURN; } #endif diff --git a/tests/tcg/x86_64/test-1648.c b/tests/tcg/x86_64/test-1648.c new file mode 100644 index 0000000000..fd0644a8ce --- /dev/null +++ b/tests/tcg/x86_64/test-1648.c @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* See https://gitlab.com/qemu-project/qemu/-/issues/1648 */ + +#include + +__attribute__((noinline)) +void bar(void) +{ + /* Success! Continue through sigreturn. */ +} + +/* + * Because of the change of ABI between foo and bar, the compiler is + * required to save XMM6-XMM15. The compiler will use MOVAPS or MOVDQA, + * which will trap if the stack frame is not 16 byte aligned. + */ +__attribute__((noinline, ms_abi)) +void foo(void) +{ + bar(); +} + +void sighandler(int num) +{ + foo(); +} + +int main(void) +{ + signal(SIGUSR1, sighandler); + raise(SIGUSR1); + return 0; +} diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target index e64aab1b81..5fedf22117 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -13,6 +13,7 @@ X86_64_TESTS += vsyscall X86_64_TESTS += noexec X86_64_TESTS += cmpxchg X86_64_TESTS += adox +X86_64_TESTS += test-1648 TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=$(MULTIARCH_TESTS) From patchwork Wed May 15 15:08:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796974 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033601wra; Wed, 15 May 2024 08:11:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV0+FUkkvZU1fU9KmKjQttcG+mlyjo/Hb6uS+a6P3TbgdiFbn4QXQCrUPEQIZnEYuGAENitWMKJSo96K5RAlUUw X-Google-Smtp-Source: AGHT+IFZlJUZJJY3CLh05661G3LmDWjSiAcWwLtxmu63I3R0KcNaSKPdRIuFad9O6XlrfJ7FA6WF X-Received: by 2002:a05:6122:31a1:b0:4d3:34f4:7e99 with SMTP id 71dfb90a1353d-4df8813d173mr13176338e0c.0.1715785901702; Wed, 15 May 2024 08:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785901; cv=none; d=google.com; s=arc-20160816; b=jPaLPDURhhmLCiFR9woLhd3YjT1zw4GYxBIJgiwGtu1riv/dMx67Gi7JFpLVUgLtWB RZ2ZHI9WdtUwmjttlNem277dBPqU8erYRMvZp0plqUtj4M9jErJOVVPmqESObvSJZv4V nF1SJ73YDW8EoGTtq+uY2slLa6REDpXXFLO7n+/xt7VZEZD3+eDMPpJ4SFiXJYnCzhU7 nmqVcb5vfnTAAkLlE3XQexgB9YfsA0VcH4tGEERRRCI9kNuVTvc9NrhC960SnP1RET0+ GkLc88YlY4QBVtqNWLWRMfY8R3NE4ksUBAuy04sKhaMxUig2ztwvcj4wi25tNHB8Bp2m F5Ag== 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=suH2Sh1RTztpX0Ny0xBmvx/nzFkJoaQwrt5RKBi/xzU=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=dt+Z1TEEt8n7s5kFCoH1N/cusB+/2zf+fVt9ojMNSE3Hc0so/pLoeELPrnAfKg6o9I jtGrSh/MHUBeI1dYnSFDvkNLA53GL0gmtZjnQSNsCskFU+85AR3ZmaF+wsWkmnF90iop rdkFdlS4V9vBCRFb/VAvj/3034d/gRx4t5um4sW92efYWNvKcARxXi0tsvgXNj5nwzkv sVqSDa3lHk06Ya/jHuHE5tInkJrBQfks03xLC4OQGER1deyUNFoEjzBNDjHMc9NSuspO i4+zdEk5IV0VwRE/nH629GhfZalfaIWArkuJod7B94TXl4AVgqTGMQRCVyjuPM+swQ3O 4aOQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d4bOSwh0; 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=pass (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 71dfb90a1353d-4df7c0a9a59si2198326e0c.272.2024.05.15.08.11.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:41 -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=pass header.i=@linaro.org header.s=google header.b=d4bOSwh0; 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=pass (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-0003zU-Rv; 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 1s7GFb-0003wE-QO for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFX-0003Ag-FA for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:03 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2e6f51f9de4so16363941fa.3 for ; Wed, 15 May 2024 08:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785738; x=1716390538; 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=suH2Sh1RTztpX0Ny0xBmvx/nzFkJoaQwrt5RKBi/xzU=; b=d4bOSwh0EVj6QdASzJfxOJg981UcYUQwh+D4RO5C7VyaoMN92D9GK2cMYXD3aWT1Kh h/nASHw+Vl1T6lSq4JYfEQUjlqJWY23+boJZ+aMmn5lSrLwxTBp7D4hieFoMpUEdI5KQ cuyjxspn/cZVcX7tKoNungDckvRQbuIo56Rc1d/7DImy1Dy/PwcHA/ZDldGdii9QD0k3 XEcpv7Kg9PUao8ui7UIkEgwmYp4mc/fzao+nge2JbUam5XAm2PfmZFFhNbUmzDKwjc0z Q84Wv8rFxHisol1p7eqyT5v8UVDnPaY5NyJf6Cap+Zc5cSxNMEwbfZYA9zyPbAYd3YKJ cwzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785738; x=1716390538; 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=suH2Sh1RTztpX0Ny0xBmvx/nzFkJoaQwrt5RKBi/xzU=; b=L9zSXNZfarZllvcLibsRBNCMpNkq0xyLRkxYDfZqOGmkDj8NP6tXI5zp2nYONXBLA0 3Z09BFHk1fej+o0RSv7kt6zbZlCZ3R6S1YjxddLOHg6PShkBbHvUvpN3b9Y/OfLQmNRD Habfnz8dV4shtmPwOQR72YpvAlt8HnihwlGlVLoq9qQmpCjhTcm8VZfUO5riAkG+qdcZ 02mQFV6CToImJ+XXGm2g8rVPM80TSCmiPjfYZdY5J0dje74aYQ03suC+h/G1LiPRwmAB /ghdRbleVtT9ay+hpPbMVzSZUPEbntTU5AzdCY3WirANanTHC5KA7Ooz8VifngO1cZq+ eZFw== X-Gm-Message-State: AOJu0YxJM82NldTRLyxndbuyxtE7jEDM+JgxSs6kywHCWxcSt4Se5vPT vpBOHnL8YXjGNl1spdk6gHM/qphS918h081syn3qDkB9VlO6477w9E6gZ1uSAwgsLPmj5Kzn6cP xwyE= X-Received: by 2002:a2e:b002:0:b0:2db:a9c9:4c5e with SMTP id 38308e7fff4ca-2e51fd47edfmr160540711fa.21.1715785737804; Wed, 15 May 2024 08:08:57 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 23/28] target/i386: Honor xfeatures in xrstor_sigcontext Date: Wed, 15 May 2024 17:08:32 +0200 Message-Id: <20240515150837.259747-24-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::232; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x232.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 Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 95dd01820d..c2826a707d 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -613,6 +613,7 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, struct target_fpx_sw_bytes *sw = (void *)&fxstate->sw_reserved; uint32_t magic1, magic2; uint32_t extended_size, xstate_size, min_size, max_size; + uint64_t xfeatures; switch (fpkind) { case FPSTATE_XSAVE: @@ -629,10 +630,25 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, xstate_size > extended_size) { break; } + + /* + * Restore the features indicated in the frame, masked by + * those currently enabled. Re-check the frame size. + * ??? It is not clear where the kernel does this, but it + * is not in check_xstate_in_sigframe, and so (probably) + * does not fall back to fxrstor. + */ + xfeatures = tswap64(sw->xfeatures) & env->xcr0; + min_size = xsave_area_size(xfeatures, false); + if (xstate_size < min_size) { + return false; + } + if (!access_ok(env_cpu(env), VERIFY_READ, fxstate_addr, xstate_size + TARGET_FP_XSTATE_MAGIC2_SIZE)) { return false; } + /* * Check for the presence of second magic word at the end of memory * layout. This detects the case where the user just copied the legacy @@ -645,7 +661,8 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, if (magic2 != FP_XSTATE_MAGIC2) { break; } - cpu_x86_xrstor(env, fxstate_addr, -1); + + cpu_x86_xrstor(env, fxstate_addr, xfeatures); return true; default: From patchwork Wed May 15 15:08:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796981 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034334wra; Wed, 15 May 2024 08:12:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVVNHWAKMtuRxUGtb4s3i+MWQkh4keUEAOeChymgNtBD+27FFIbJqZGNUrTYRhSalBOpdEg4lsKgC6YBL0sSPB6 X-Google-Smtp-Source: AGHT+IGZpNKFnAlhdq42vbMFG0bQV9HrxfNvS2LYw/qFw+T8ZkKg4BtaHlMiZYCmV+yK0dl497EH X-Received: by 2002:a05:6102:c02:b0:47e:f1da:17b5 with SMTP id ada2fe7eead31-48077dce33fmr16974251137.5.1715785974844; Wed, 15 May 2024 08:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785974; cv=none; d=google.com; s=arc-20160816; b=Pv0CRLa5k/KFy2Ex1ypSlx2PNWVLKROyfRGBxzDdyErdn2clf9pguo/lAZ+1bjq0qS pX70F5oCtcb44TeT4CdzZ6yYpc0kh9qI3X8VIiHjoFXh6ZIE31/ItZuy1ae8hhClcQ1E ZCe+01M0ys66Sg1AJP2425MeC2HPMCPKlaRkuPWi5wajdpcssw5oKhXIMIovLkfoWz+r /EoKPgMYCjUjP5A5SfSekvWmInQCLzdakGHmtcJ8YJxnJmunXf887GI85IDN4i4xh7uM UKeGGeLAxrUy3b9DgGuNslqKhWQSHHmkFiiCXsABbyoNIkbfeP2PMsaNis39yhGNPd07 eWAQ== 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=/zyx2EtmnSzQ0QjFq1CHW7l9aXx9O2qNwb9GB2WJR34=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=Bj/N/pcnaV1OalbMp9cen+IsNT9COO3LbA2JGcpEwtdb/yQuFv0ulHeSfWM+17W8GS JOFCY0/cTagpoWRgQUqx0PnaQBQDNODdYeD9wiy+PiYCxE/Va3jYQ3dUumU8NcT8gVLY rVUAqAF0orm9rYbHUX0AoozDu0/RwtuXtgZKT+OjO9tRaQvV4fgIYGBbMTn+NJ+iHZOk jIuo4FWdanLvq/1Geh91KoNPyTweYJJe2pp/reF/WVLBh437SqzxlKWJXWas8LOYYFfw Gro1niRx0DfvCDUlrxc71UfbQWQf36o+8CMSMNKWAAQj4kraRbqS3VSugmQLtGX0eLXe GkRg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H0LpIS14; 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=pass (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-4806cb7c884si2709957137.100.2024.05.15.08.12.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:12:54 -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=pass header.i=@linaro.org header.s=google header.b=H0LpIS14; 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=pass (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 1s7GFi-00040s-2T; Wed, 15 May 2024 11:09:10 -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-0003xn-Bd for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:05 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFa-0003Bc-Oe for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:05 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42016c8db2aso23233075e9.0 for ; Wed, 15 May 2024 08:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785738; x=1716390538; 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=/zyx2EtmnSzQ0QjFq1CHW7l9aXx9O2qNwb9GB2WJR34=; b=H0LpIS14Sja7lCSoP6ox5qt+vlMc3cTUk+sRNb8aPwtoiEFXy2vFJ7Fo24S8iXbqec 7lgCK3w5uvc53U/o1cZCM3kZUMZ1WX1A9OyAdyygoVJoINSQB9+CuYoK37ejwtCEnFnj vngTxdp6beuFU9XXBbwSVzJq9js6AY7Fr7z9ijTnoRAiqAmygcsJkpKbthluyRRDDHsp 3x3V5ujkkyH5P8jHSJPrJ4i1OBWSXpbwaGZvgQCqjXmVKCdn6jjOxxAi+AcGO0A4/NoA NbqEEyorFBOIQZBZA10IlvxcE7bbvvbdWvQFn/fWRoOL3UkFl29CSA28VucEuhZQ5tqR 9XFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785738; x=1716390538; 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=/zyx2EtmnSzQ0QjFq1CHW7l9aXx9O2qNwb9GB2WJR34=; b=jnIszuGvREGQwlwFQCCjblNuFvyDn3zD8YWbYmoenVoDLTH5t6FAkXFkf4GCj8lD8o o+CxEUZk1/al6vTjIA4Yx1mGCmOepU7SQA2IKA5lQuL4BfMBpQe9GgKORz3A8nnTT1Kv xtDNuXvYDsfuQgFdNIl9r0JdcAYGKEQC8tAOsEgjlRJ1yMKaWwIWtJ+A12uRTJPqsvPr 9kjQtgjLNvduUBZeBbZ7Kmvz8yFyQTDmDKwYMkb8de1QQW1z8ERmhJz8ktowH2diJR73 qhe+nW7MItPTcdL35gTTWiM209KPDjaiatsM0qF0hzE4xwGmb3zG+i03eNiZf6kWgxuQ b1uw== X-Gm-Message-State: AOJu0YzrhPkoQT4TNH8bzwA0NHnHN8ZawtiMQawQgqiYNkdE1u2SdcMW JSu6B4dbH3Qcc9wBeNAYCXb0E6T6h2ije3NMoGJrbVdAqsSkhPn4N/aq6BrKdDK3DLLcpfKe7Cp BxVo= X-Received: by 2002:a05:600c:5605:b0:41c:7ac7:17f5 with SMTP id 5b1f17b1804b1-41feab42b76mr118210255e9.24.1715785738554; Wed, 15 May 2024 08:08:58 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 24/28] target/i386: Convert do_xsave to X86Access Date: Wed, 15 May 2024 17:08:33 +0200 Message-Id: <20240515150837.259747-25-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::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- linux-user/i386/signal.c | 2 +- target/i386/tcg/fpu_helper.c | 72 +++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index c2826a707d..2f93342ade 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -329,7 +329,7 @@ static void xsave_sigcontext(CPUX86State *env, /* Zero the header, XSAVE *adds* features to an existing save state. */ memset(fxstate + 1, 0, sizeof(X86XSaveHeader)); - cpu_x86_xsave(env, xstate_addr, -1); + cpu_x86_xsave(env, xstate_addr, env->xcr0); __put_user(TARGET_FP_XSTATE_MAGIC1, &sw->magic1); __put_user(extended_size, &sw->extended_size); diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index a09d6aaf07..f5748b72b8 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2668,47 +2668,38 @@ static uint64_t get_xinuse(CPUX86State *env) return inuse; } -static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, - uint64_t inuse, uint64_t opt, uintptr_t ra) +static void do_xsave_access(X86Access *ac, target_ulong ptr, uint64_t rfbm, + uint64_t inuse, uint64_t opt) { uint64_t old_bv, new_bv; - X86Access ac; - unsigned size; - - /* Never save anything not enabled by XCR0. */ - rfbm &= env->xcr0; - opt &= rfbm; - - size = xsave_area_size(opt, false); - access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, ra); if (opt & XSTATE_FP_MASK) { - do_xsave_fpu(&ac, ptr); + do_xsave_fpu(ac, ptr); } if (rfbm & XSTATE_SSE_MASK) { /* Note that saving MXCSR is not suppressed by XSAVEOPT. */ - do_xsave_mxcsr(&ac, ptr); + do_xsave_mxcsr(ac, ptr); } if (opt & XSTATE_SSE_MASK) { - do_xsave_sse(&ac, ptr); + do_xsave_sse(ac, ptr); } if (opt & XSTATE_YMM_MASK) { - do_xsave_ymmh(&ac, ptr + XO(avx_state)); + do_xsave_ymmh(ac, ptr + XO(avx_state)); } if (opt & XSTATE_BNDREGS_MASK) { - do_xsave_bndregs(&ac, ptr + XO(bndreg_state)); + do_xsave_bndregs(ac, ptr + XO(bndreg_state)); } if (opt & XSTATE_BNDCSR_MASK) { - do_xsave_bndcsr(&ac, ptr + XO(bndcsr_state)); + do_xsave_bndcsr(ac, ptr + XO(bndcsr_state)); } if (opt & XSTATE_PKRU_MASK) { - do_xsave_pkru(&ac, ptr + XO(pkru_state)); + do_xsave_pkru(ac, ptr + XO(pkru_state)); } /* Update the XSTATE_BV field. */ - old_bv = access_ldq(&ac, ptr + XO(header.xstate_bv)); + old_bv = access_ldq(ac, ptr + XO(header.xstate_bv)); new_bv = (old_bv & ~rfbm) | (inuse & rfbm); - access_stq(&ac, ptr + XO(header.xstate_bv), new_bv); + access_stq(ac, ptr + XO(header.xstate_bv), new_bv); } static void do_xsave_chk(CPUX86State *env, target_ulong ptr, uintptr_t ra) @@ -2724,22 +2715,32 @@ static void do_xsave_chk(CPUX86State *env, target_ulong ptr, uintptr_t ra) } } -void helper_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) +static void do_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm, + uint64_t inuse, uint64_t opt, uintptr_t ra) { - uintptr_t ra = GETPC(); + X86Access ac; + unsigned size; do_xsave_chk(env, ptr, ra); - do_xsave(env, ptr, rfbm, get_xinuse(env), -1, ra); + + /* Never save anything not enabled by XCR0. */ + rfbm &= env->xcr0; + opt &= rfbm; + size = xsave_area_size(opt, false); + + access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, ra); + do_xsave_access(&ac, ptr, rfbm, inuse, opt); +} + +void helper_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) +{ + do_xsave(env, ptr, rfbm, get_xinuse(env), rfbm, GETPC()); } void helper_xsaveopt(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - uintptr_t ra = GETPC(); - uint64_t inuse; - - do_xsave_chk(env, ptr, ra); - inuse = get_xinuse(env); - do_xsave(env, ptr, rfbm, inuse, inuse, ra); + uint64_t inuse = get_xinuse(env); + do_xsave(env, ptr, rfbm, inuse, inuse, GETPC()); } static void do_xrstor_fpu(X86Access *ac, target_ulong ptr) @@ -3049,7 +3050,18 @@ void cpu_x86_fxrstor(CPUX86State *env, target_ulong ptr) void cpu_x86_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - do_xsave(env, ptr, rfbm, get_xinuse(env), -1, 0); + X86Access ac; + unsigned size; + + /* + * Since this is only called from user-level signal handling, + * we should have done the job correctly there. + */ + assert((rfbm & ~env->xcr0) == 0); + size = xsave_area_size(rfbm, false); + + access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, 0); + do_xsave_access(&ac, ptr, rfbm, get_xinuse(env), rfbm); } void cpu_x86_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) From patchwork Wed May 15 15:08:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796983 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3034540wra; Wed, 15 May 2024 08:13:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUkh8wrF4EmQ4aKMkuNO2lsHBW2qqCqcr1J5bzrde5gIvDnP4/EVpAeP1VOCKAF+qsUZH8ptRoGomUYINsvjBwz X-Google-Smtp-Source: AGHT+IHLtMK7f5Sns+z3D2g0XZdnDgfXxnh46jbkg5UPmOtplBqIAmgkg6BMCfSQpYFNnrfj+gwU X-Received: by 2002:a05:6870:e92:b0:234:56f5:cf16 with SMTP id 586e51a60fabf-24172c2f216mr23302643fac.32.1715785995782; Wed, 15 May 2024 08:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785995; cv=none; d=google.com; s=arc-20160816; b=0wQM8Ffq/+wDZkquaA7MbDy+xkydMuMpsI/jStr/+164GYrJNVxpq9G2MmPH3Pw6L/ Owfxqjfmf+PSwUd+yiyH73KDcUwjmyNZceADWipOV+A70RYRwtL/gfc8bIW4SftBnOea pIqvQ3tG23xJIFB+EE+zCvpZQnX5oD1heX5BN2dbPMVZXtptQ6R/1Py+bSQAYLVrCIf6 IkBhVpdBpUi3q8jbEPtd2ihXOMWmNrHXrtmyY976oXthJdoVYpx2dtWmwsziFRnAd8VQ TJikhTu0qTA9gLKFMJ+eLES4jx3+7Su8cjZd4+g9DcPC2+FKs7Bcus2kSWvm1QMz+/9s GUUw== 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=StedKx2if52BenXHp9OmhhxzvGoDONYhwtdzrxe9+sA=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=WkMBCDWZKx0FXi+9t2SFSI5K8F7Wrw1kvoVtR3F6Oz9qNNCYTTFZ79k+9yHq+q9SwL Ic5aBuqkB8ssfMOFeoToPS4bQ2gvqrjtD9osN08yY2SSwErASZeTisys35fqJxTxfRGx 9AzI33S3U7styzQPJWU+5cwFOMo8kRFjBOPZcJUVpo/UK8MQZnd2ab4fQvP9aXJiYqvk RJWBCo218R5QYxV4inqY4dL0of1B/23J82zf7SwQRCzqKObsrFv7Ahu1pbjUsAvf/71E eW0qpb2VmjQb2MdXotFw2c+FOwhVCTs+JA8V4SGOm7umGtsN7w6TXCGN/mC53HzXnRl/ zk8Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M9HICQ+x; 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=pass (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-4806cc91063si2272919137.644.2024.05.15.08.13.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:13:15 -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=pass header.i=@linaro.org header.s=google header.b=M9HICQ+x; 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=pass (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 1s7GFh-00040C-9F; Wed, 15 May 2024 11:09:09 -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 1s7GFc-0003xA-PZ for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFY-0003EQ-LK for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:04 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-41fd5dc0480so43837435e9.1 for ; Wed, 15 May 2024 08:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785739; x=1716390539; 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=StedKx2if52BenXHp9OmhhxzvGoDONYhwtdzrxe9+sA=; b=M9HICQ+xGh/8PjGIt64BfriMvyi4GanZJQ4yLA1mudgvNSgvXshsLNs2Kj0fowdhao Vg/xd/L050ZMQqQTiyrTrtIjt1djG7EJg9bPetLQI2RrsndcvAqOKSQHky/P9VLFMmg/ ZdrWxu/Jfpze60reqh0mbyMCGdsIqNgvX1nUX4skr6QvyW3fYkCoZi6uzHcy2kTjsjDo 0qPOAba15qNNxiN/uYmOtPLiWar/5JFyRMaNQPbMSGjERJvbI4wE6L1YSbZu0JE+fHeX MX6vobxUnWoj38NafXNoOT9sQ3+dRPtKJrKXwtSCWiDhKlPhCtWyy6B1UnFw+qb8BmZ4 m5Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785739; x=1716390539; 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=StedKx2if52BenXHp9OmhhxzvGoDONYhwtdzrxe9+sA=; b=cDfNQpNHnJgAS8Qgy651E4d5HwCllV4TiKzuP1c/nlplIhUM44y7HomhFpUi7Ue/NN HTh8RK2stEU/pK4Zc9qKMc/BBwqxsDwBu4S0bAJW6ueIdznN3OgFtxjF4owEYjhjg3jN meSpFlV2ddBs2t5u3Gztu0N3em2+XZYyVMhsbBAqFMdvB+T2rXp97lnGxmwgOnB9CFZf RkBpxWD8f04lX9/+015zSbLORdhOKN+RCyrkhJaLwTLAXc8hIOODo3cSQXMFNu2asp04 N5Sb7jkVs28DhmlFEY/+sHTUELwyTIUHgR4BsKJ+vKE354JPY0jo+lcBLoXAkGJVaVas qHCw== X-Gm-Message-State: AOJu0YyqeY3tsRZ278aLkDmE2dm6ezcyqAAs14POu6ukKklQzisVKFHX q8dZZsncUMywhv9R7UfubD/Gk10yY9uS8+n3R1kkXXp2zblcGzIbnXTDAHrFgkpBGVL2EH1Xe1C iETI= X-Received: by 2002:a05:600c:46d3:b0:41b:6753:30be with SMTP id 5b1f17b1804b1-41fead6cf75mr138876155e9.38.1715785739379; Wed, 15 May 2024 08:08:59 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:08:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 25/28] target/i386: Convert do_xrstor to X86Access Date: Wed, 15 May 2024 17:08:34 +0200 Message-Id: <20240515150837.259747-26-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::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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 Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 106 +++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 42 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index f5748b72b8..1ac61c5d7d 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2903,51 +2903,38 @@ void helper_fxrstor(CPUX86State *env, target_ulong ptr) do_fxrstor(&ac, ptr); } -static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr_t ra) +static bool valid_xrstor_header(X86Access *ac, uint64_t *pxsbv, + target_ulong ptr) { uint64_t xstate_bv, xcomp_bv, reserve0; - X86Access ac; - unsigned size, size_ext; - rfbm &= env->xcr0; + xstate_bv = access_ldq(ac, ptr + XO(header.xstate_bv)); + xcomp_bv = access_ldq(ac, ptr + XO(header.xcomp_bv)); + reserve0 = access_ldq(ac, ptr + XO(header.reserve0)); + *pxsbv = xstate_bv; - size = sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader); - access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, ra); - - xstate_bv = access_ldq(&ac, ptr + XO(header.xstate_bv)); - - if ((int64_t)xstate_bv < 0) { - /* FIXME: Compact form. */ - raise_exception_ra(env, EXCP0D_GPF, ra); + /* + * XCOMP_BV bit 63 indicates compact form, which we do not support, + * and thus must raise #GP. That leaves us in standard form. + * In standard form, bytes 23:8 must be zero -- which is both + * XCOMP_BV and the following 64-bit field. + */ + if (xcomp_bv || reserve0) { + return false; } - /* Standard form. */ - /* The XSTATE_BV field must not set bits not present in XCR0. */ - if (xstate_bv & ~env->xcr0) { - raise_exception_ra(env, EXCP0D_GPF, ra); - } + return (xstate_bv & ~ac->env->xcr0) == 0; +} - /* The XCOMP_BV field must be zero. Note that, as of the April 2016 - revision, the description of the XSAVE Header (Vol 1, Sec 13.4.2) - describes only XCOMP_BV, but the description of the standard form - of XRSTOR (Vol 1, Sec 13.8.1) checks bytes 23:8 for zero, which - includes the next 64-bit field. */ - xcomp_bv = access_ldq(&ac, ptr + XO(header.xcomp_bv)); - reserve0 = access_ldq(&ac, ptr + XO(header.reserve0)); - if (xcomp_bv || reserve0) { - raise_exception_ra(env, EXCP0D_GPF, ra); - } - - size_ext = xsave_area_size(rfbm & xstate_bv, false); - if (size < size_ext) { - /* TODO: See if existing page probe has covered extra size. */ - access_prepare(&ac, env, ptr, size_ext, MMU_DATA_LOAD, ra); - } +static void do_xrstor(X86Access *ac, target_ulong ptr, + uint64_t rfbm, uint64_t xstate_bv) +{ + CPUX86State *env = ac->env; if (rfbm & XSTATE_FP_MASK) { if (xstate_bv & XSTATE_FP_MASK) { - do_xrstor_fpu(&ac, ptr); + do_xrstor_fpu(ac, ptr); } else { do_fninit(env); memset(env->fpregs, 0, sizeof(env->fpregs)); @@ -2956,23 +2943,23 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr if (rfbm & XSTATE_SSE_MASK) { /* Note that the standard form of XRSTOR loads MXCSR from memory whether or not the XSTATE_BV bit is set. */ - do_xrstor_mxcsr(&ac, ptr); + do_xrstor_mxcsr(ac, ptr); if (xstate_bv & XSTATE_SSE_MASK) { - do_xrstor_sse(&ac, ptr); + do_xrstor_sse(ac, ptr); } else { do_clear_sse(env); } } if (rfbm & XSTATE_YMM_MASK) { if (xstate_bv & XSTATE_YMM_MASK) { - do_xrstor_ymmh(&ac, ptr + XO(avx_state)); + do_xrstor_ymmh(ac, ptr + XO(avx_state)); } else { do_clear_ymmh(env); } } if (rfbm & XSTATE_BNDREGS_MASK) { if (xstate_bv & XSTATE_BNDREGS_MASK) { - do_xrstor_bndregs(&ac, ptr + XO(bndreg_state)); + do_xrstor_bndregs(ac, ptr + XO(bndreg_state)); env->hflags |= HF_MPX_IU_MASK; } else { memset(env->bnd_regs, 0, sizeof(env->bnd_regs)); @@ -2981,7 +2968,7 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr } if (rfbm & XSTATE_BNDCSR_MASK) { if (xstate_bv & XSTATE_BNDCSR_MASK) { - do_xrstor_bndcsr(&ac, ptr + XO(bndcsr_state)); + do_xrstor_bndcsr(ac, ptr + XO(bndcsr_state)); } else { memset(&env->bndcs_regs, 0, sizeof(env->bndcs_regs)); } @@ -2990,7 +2977,7 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr if (rfbm & XSTATE_PKRU_MASK) { uint64_t old_pkru = env->pkru; if (xstate_bv & XSTATE_PKRU_MASK) { - do_xrstor_pkru(&ac, ptr + XO(pkru_state)); + do_xrstor_pkru(ac, ptr + XO(pkru_state)); } else { env->pkru = 0; } @@ -3006,9 +2993,27 @@ static void do_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm, uintptr void helper_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { uintptr_t ra = GETPC(); + X86Access ac; + uint64_t xstate_bv; + unsigned size, size_ext; do_xsave_chk(env, ptr, ra); - do_xrstor(env, ptr, rfbm, ra); + + /* Begin with just the minimum size to validate the header. */ + size = sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader); + access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, ra); + if (!valid_xrstor_header(&ac, &xstate_bv, ptr)) { + raise_exception_ra(env, EXCP0D_GPF, ra); + } + + rfbm &= env->xcr0; + size_ext = xsave_area_size(rfbm & xstate_bv, false); + if (size < size_ext) { + /* TODO: See if existing page probe has covered extra size. */ + access_prepare(&ac, env, ptr, size_ext, MMU_DATA_LOAD, ra); + } + + do_xrstor(&ac, ptr, rfbm, xstate_bv); } #if defined(CONFIG_USER_ONLY) @@ -3066,7 +3071,24 @@ void cpu_x86_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) void cpu_x86_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) { - do_xrstor(env, ptr, rfbm, 0); + X86Access ac; + uint64_t xstate_bv; + unsigned size; + + /* + * Since this is only called from user-level signal handling, + * we should have done the job correctly there. + */ + assert((rfbm & ~env->xcr0) == 0); + size = xsave_area_size(rfbm, false); + access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, 0); + + if (!valid_xrstor_header(&ac, &xstate_bv, ptr)) { + /* TODO: Report failure to caller. */ + xstate_bv &= env->xcr0; + } + + do_xrstor(&ac, ptr, rfbm, xstate_bv); } #endif 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) From patchwork Wed May 15 15:08:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796975 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033686wra; Wed, 15 May 2024 08:11:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXnr+bnf+e8Aj8tGmHJFoEEUvtMPdtuzvL1r343q5JKjVE+jrTkpzpUETMNcsVDTZEXVt50SF3yq2XvgXDSf596 X-Google-Smtp-Source: AGHT+IEO0qJtQKQ5wm5P6NvB5fPDoVoZTem5SZReef2nTcrl3ic7X4KF+3GprLWiEOUpSYRrbE1M X-Received: by 2002:a05:6214:5502:b0:6a0:cc01:5c7b with SMTP id 6a1803df08f44-6a16815fe8amr176396756d6.24.1715785910325; Wed, 15 May 2024 08:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785910; cv=none; d=google.com; s=arc-20160816; b=QrW37NUvilUafZO/6P0Y+y8vV2BvkOz1XwF5IPFLrx0ShYcDhz4I0Xdxk3+3OasfXH a3qQg2x/hFxzoE4aTKlUThxwbVYjlaZTR0wR+PawU9wJOsqJ4LbmIMrXyG+1g5A8EiFh msJpbmuwj2G5Ep3MpS8B9mIFb6YKF6sOaqUZMkOoIZPeDwN5xdr/YWuN0KyG/JtKkjxV QljKsIAB6gVwLt/XMoR+OGqPerP89XepRD++MCZEEOcCByicEvy+J36NQl6HBO3+btv5 K9kyUPLHRiBwH8MoTv1zOf5LzwHcI5/QW1mfITHMNCAUp02Hz/N4zvsRM6erzcCTU1+2 Dqow== 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=Ah4RAfb74Ry/QSCvgzicI92Xf6jvMyFD3fqYCPKUsdU=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=0myyVrpJtiFpexx5STzxhvm1gEzrCqBL9dXDKgVyF/IPPR6d1/7nzyGqJ9sPw61C1X 6t0dykHQ+0ynUNtv7sMDyXDTgzm5LG3fSAnJPCFpRTInUtnPe3DJ+GQl9cIHm62HtjEW q7G37/ODFbrqktO07M6iEI/AsvlNVukf1XAbQiBYZtLG/onir4ycOlZk+/Af+A+F3k3a DqSeUEs006vpThSMRg2oa8nuM6v+yLfXP7uVkThKrZqLjhmn3OZGRFRA1CGOId/MezPB ysC8Ry35ady78QLl0ia4iS1V7863W+g1qEpNFYK7HyADoIGGN/nuAz4jxUOcwQ3fbL/D fUQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iQBgzp6k; 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 6a1803df08f44-6a15f2f6ba5si135742276d6.527.2024.05.15.08.11.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:50 -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=iQBgzp6k; 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 1s7GFj-00040v-P8; Wed, 15 May 2024 11:09:11 -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 1s7GFe-0003y5-1n for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:06 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFa-0003FH-VN for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:05 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42011507a54so25965105e9.0 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=1715785741; x=1716390541; 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=Ah4RAfb74Ry/QSCvgzicI92Xf6jvMyFD3fqYCPKUsdU=; b=iQBgzp6kEUFiPWy4dO+UHQO87wVow4hKxUgE2M4S5hsdDIlooCrMrXXQucixbuT7P+ 2dFBrm3WfpiILmNCxbokAfZXINkl65x7g6vjE/d/GlQeVNFGZ/o7tpA/WuxWBWvCRWj7 Ss2KqJQ+p4QaxC4gsBUYt/A+/qbu+VbM0mOShLCsnMfBolVk/VNScP6E2c8PxEUJSbF9 clMP270ULe1rAtFlUi9NI8oT/LwS9RPLVw1NNckJlICr8QMApwhbuXNAWZSuLuDySnFA /SVRoS9U+ehqme/QgHwDhIL1Zw8jvrtugZ5OtHiQAn4AiBUEo/2fT0fxIGSZcjj6y0qM OVDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785741; x=1716390541; 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=Ah4RAfb74Ry/QSCvgzicI92Xf6jvMyFD3fqYCPKUsdU=; b=gEC5QfHFGEF/yRGL9E3SVChChWrsi5rpZW81ApxQjYHI49103gXjvOC43xVqGQMtBY 8sALIR0Fb8+IfuMITAhacQqz2LDeC1ZFlwbU9+22FjZN8FFVie/UaY0E7l5nW/FO0rfu UWn06TAjZgRKkZaRaSi6SadTi1zMOq9xzg3y3+6ESEd6WrjnH7Oopwk0vvwy9jrt7wdJ 99/XDUzwucLsKBDUraKsa1JD6hMASS/ANFyhSpEReeN/HXUmufncdo5t8CfY2xyfde6i infLj0yjhKfp/2FazbBm6NE/v85WsrEnYpj5APWx6h55MpgZvbRF2ojws0CoiNXXXi+s SLBA== X-Gm-Message-State: AOJu0YwOzbm3m3OC2LM5Nat5sK+qGXS8EA1w3M2eTu8wyX/WuBTaY/yh Qd22lCb5CTmMLAAI6Zytfzl+1zTqu2MqzD9pYzfbC71X1u+DrZfSiUZb9SMUgzqexWfH0yeItgI GlBk= X-Received: by 2002:a05:600c:4754:b0:41f:ae5a:c72f with SMTP id 5b1f17b1804b1-41fbc91f419mr185164525e9.1.1715785740796; 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.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:09:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 27/28] target/i386: Pass host pointer and size to cpu_x86_{fxsave, fxrstor} Date: Wed, 15 May 2024 17:08:36 +0200 Message-Id: <20240515150837.259747-28-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::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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 | 4 ++-- linux-user/i386/signal.c | 13 +++++-------- target/i386/tcg/fpu_helper.c | 26 ++++++++++++++++---------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 2897faccb9..dbd91c064d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2243,8 +2243,8 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector, void cpu_x86_load_seg(CPUX86State *s, X86Seg seg_reg, int selector); 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_fxsave(CPUX86State *s, void *host, size_t len); +void cpu_x86_fxrstor(CPUX86State *s, void *host, size_t len); void cpu_x86_xsave(CPUX86State *s, target_ulong ptr, uint64_t rbfm); void cpu_x86_xrstor(CPUX86State *s, target_ulong ptr, uint64_t rbfm); diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 816e8ab2a9..1f5a3e9a0b 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -294,14 +294,11 @@ static abi_ptr get_sigframe(struct target_sigaction *ka, CPUX86State *env, * Set up a signal frame. */ -static void fxsave_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxstate, - abi_ptr fxstate_addr) +static void fxsave_sigcontext(CPUX86State *env, X86LegacyXSaveArea *fxstate) { struct target_fpx_sw_bytes *sw = (void *)&fxstate->sw_reserved; - /* fxstate_addr must be 16 byte aligned for fxsave */ - assert(!(fxstate_addr & 0xf)); - cpu_x86_fxsave(env, fxstate_addr); + cpu_x86_fxsave(env, fxstate, sizeof(*fxstate)); __put_user(0, &sw->magic1); } @@ -412,7 +409,7 @@ static void setup_sigcontext(CPUX86State *env, xsave_sigcontext(env, fxstate, fpstate_addr, fxstate_addr, fpend_addr); break; case FPSTATE_FXSAVE: - fxsave_sigcontext(env, fxstate, fxstate_addr); + fxsave_sigcontext(env, fxstate); break; default: break; @@ -669,7 +666,7 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, break; } - cpu_x86_fxrstor(env, fxstate_addr); + cpu_x86_fxrstor(env, fxstate, sizeof(*fxstate)); return true; } @@ -687,7 +684,7 @@ static bool frstor_sigcontext(CPUX86State *env, FPStateKind fpkind, } break; case FPSTATE_FXSAVE: - cpu_x86_fxrstor(env, fxstate_addr); + cpu_x86_fxrstor(env, fxstate, sizeof(*fxstate)); break; case FPSTATE_FSAVE: break; diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 05db16a152..0e5368951f 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3041,22 +3041,28 @@ void cpu_x86_frstor(CPUX86State *env, void *host, size_t len) do_frstor(&ac, 0, true); } -void cpu_x86_fxsave(CPUX86State *env, target_ulong ptr) +void cpu_x86_fxsave(CPUX86State *env, void *host, size_t len) { - X86Access ac; + X86Access ac = { + .haddr1 = host, + .size = sizeof(X86LegacyXSaveArea), + .env = env, + }; - access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), - MMU_DATA_STORE, 0); - do_fxsave(&ac, ptr); + assert(ac.size <= len); + do_fxsave(&ac, 0); } -void cpu_x86_fxrstor(CPUX86State *env, target_ulong ptr) +void cpu_x86_fxrstor(CPUX86State *env, void *host, size_t len) { - X86Access ac; + X86Access ac = { + .haddr1 = host, + .size = sizeof(X86LegacyXSaveArea), + .env = env, + }; - access_prepare(&ac, env, ptr, sizeof(X86LegacyXSaveArea), - MMU_DATA_LOAD, 0); - do_fxrstor(&ac, ptr); + assert(ac.size <= len); + do_fxrstor(&ac, 0); } void cpu_x86_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) From patchwork Wed May 15 15:08:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 796968 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp3033271wra; Wed, 15 May 2024 08:11:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVF3U3306An13NHJWkVyd3e3I+Ow+wSqci/o4/TU2z2SVUvrgAiBsMqYeCTag2rMpXjo0JttCyxp8X8J3CGw0nB X-Google-Smtp-Source: AGHT+IFhFKjbnbR5Gj+gcQ/xSznMnEgJB5KqoHo+WQdP7WrSEWzXydHsPZTaiy5z8Xxzu/TSbGim X-Received: by 2002:a05:6830:81:b0:6f0:6e00:1bca with SMTP id 46e09a7af769-6f0e9133d6amr18515424a34.11.1715785874595; Wed, 15 May 2024 08:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1715785874; cv=none; d=google.com; s=arc-20160816; b=F3nEyJc78Phdj4u3IPWln5Wo9Ggeqic+f6eJBYsqJTygMn+kDmHsDVztuUkL2t8KIf oxBhdzyLcy0aa+63xSUfTL+JivmQ3G1LRXMAPOnhon2KqxrNcOgMcrExl1q75Y+58Epv DKYLhjPgoFd2L7YHgpqKWHkvpGfkKK96wTB5OtTklRMvn9Rc8it/PjLmDDVBETb3rwja xFQlba88PXsS7rOE0MfaqcnO1heyBx0Br4A0Dgb4BU6fxCDMYXg9wJrUv+z+KX8EPvjo oJJrETyYsUnDNLbYdf13LoiCeydFTq7AnylGKGXHkoTBaIGNEFnDEBd8Hllhx39SQGjI mzMQ== 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=3+CU/PYG3Ilvn330jaFlX5AWHx4UTtAJ5ukJPjIH0Y8=; fh=X011yTyqhApvEaDulZV+xVgKKBTjUS9dtQWFbmf3LLM=; b=nL2i4Msm1IgwilKjI5aHdeUxVbVXW0XzxnCBbiKG+xSU9al/BD3fhkZolimLK4F3Fd v+sJMuL7HUsqfGz0ExpA+I22a111YXkVRcvE55Fwhfk+/OL5CTJGmv5zbh2e7eHijvuB cj9iy41s0UiPhlgsEX1WFqjGA5+CiG1RuqatPck6lKft9oKZQWsDKUH1GtSoCf7AwDUG 644+Y5pLEZARB9+o4B3BhBF0NVqyxL4KEa1QSchmlLsQ3ut/EzNmHn3bNdxOBv6rj9kH 3ihSWIMbFTeIDLmYNJZ3DvjIAifkn1oqkRod5OPhtUt245ZiM3mAIdIDY7Dsvyubg2qg LoJg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pkTPHOLf; 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-4806cc90a08si2730456137.594.2024.05.15.08.11.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 May 2024 08:11:14 -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=pkTPHOLf; 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-0003z2-Gx; 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 1s7GFe-0003yK-Dc for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:06 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7GFb-0003FQ-J3 for qemu-devel@nongnu.org; Wed, 15 May 2024 11:09:06 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2e3b1b6e9d1so84606281fa.2 for ; Wed, 15 May 2024 08:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715785741; x=1716390541; 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=3+CU/PYG3Ilvn330jaFlX5AWHx4UTtAJ5ukJPjIH0Y8=; b=pkTPHOLfKLB4MxKAivC5zdAlJOkgKjoaBKWrArp3kPEhSX/tgyq86+y51etz+oj+AW GbeHDWNef9f1Kbxvk+yOlPqXRIpfjM6VR6GLEcKQ856Z27LQ1+aI39B41uZTTY+RsGs+ +7XGEYdtY+yCBel0TiyEBjJsljvODzEamO8mwYQ7+EpKJ9oShtdK/H1RJI4WqpzQZyle GncAeInWwluTR86ADcr8YkceE7nDCZH83NalJ36uB03Vk47ZW1z3gdTUO5NftE0lJIOJ TZSYci/wMwsn+qJCE5pWs71yfdHX7Gkfm+cNEtTI3FJjnsI/Sy5P6PJXIVU4AcyyvEvL 8GYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715785741; x=1716390541; 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=3+CU/PYG3Ilvn330jaFlX5AWHx4UTtAJ5ukJPjIH0Y8=; b=ABWOlIjPPWqM1/FIH/Rzh8jqB0nzZOYP4h2/XTTxAJCa7uFWgTvGq/hTxJI55RnaJW ZvEvvnarzlhYWma9u4LNPASCjDh6hheWUu0LllC0VxSx7dG1L2tot2kXeW1BbhgAbCrO 47as9f6hh2MyFygVSz3lMpjTsNgM1nTjKQAnmFmLeexd+mplrkv8Dal8PSfpahfZaaMD YAbQCyvOxErnp16qZ9olwnOvLaBamEWwTQ4nSPkpz98W6cTF4Yo/u5hkG5igotM4tHXe 8FqIX5zdbtuIsoUWlrU8mO0P79+/VPa1JHQzHvyi+oWtY6ge/tcXhQfhWY4nCWL7GUza SYVA== X-Gm-Message-State: AOJu0Yy0O6HG2E/seSjIJpBcsmHF1v+C7OphdY0UqGrXPT8RNgUBtm87 eOxi79uArkZaxZkg2CWfoyHvLTueo3U5Y3C9qOJvTtASga5hgNzZK3tRKa23uBX8Rb901a4TzUV BCgY= X-Received: by 2002:a2e:602:0:b0:2e5:3ea9:8d26 with SMTP id 38308e7fff4ca-2e53ea98d95mr83114021fa.45.1715785741552; Wed, 15 May 2024 08:09:01 -0700 (PDT) Received: from stoup.. ([149.14.240.163]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013c5fa61sm132080825e9.40.2024.05.15.08.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 08:09:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, laurent@vivier.eu Subject: [PATCH v3 28/28] target/i386: Pass host pointer and size to cpu_x86_{xsave, xrstor} Date: Wed, 15 May 2024 17:08:37 +0200 Message-Id: <20240515150837.259747-29-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::232; envelope-from=richard.henderson@linaro.org; helo=mail-lj1-x232.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. In addition, return failure when the header contains invalid xstate_bv. The kernel handles this via exception handling within XSTATE_OP within xrstor_from_user_sigframe. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- target/i386/cpu.h | 4 ++-- linux-user/i386/signal.c | 20 ++++++++++++-------- target/i386/tcg/fpu_helper.c | 36 +++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index dbd91c064d..df75f4c2b1 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2245,8 +2245,8 @@ 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, void *host, size_t len); void cpu_x86_fxrstor(CPUX86State *s, void *host, size_t len); -void cpu_x86_xsave(CPUX86State *s, target_ulong ptr, uint64_t rbfm); -void cpu_x86_xrstor(CPUX86State *s, target_ulong ptr, uint64_t rbfm); +void cpu_x86_xsave(CPUX86State *s, void *host, size_t len, uint64_t rbfm); +bool cpu_x86_xrstor(CPUX86State *s, void *host, size_t len, uint64_t rbfm); /* cpu.c */ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 1f5a3e9a0b..16f6d17345 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -326,7 +326,7 @@ static void xsave_sigcontext(CPUX86State *env, /* Zero the header, XSAVE *adds* features to an existing save state. */ memset(fxstate + 1, 0, sizeof(X86XSaveHeader)); - cpu_x86_xsave(env, xstate_addr, env->xcr0); + cpu_x86_xsave(env, fxstate, fpend_addr - xstate_addr, env->xcr0); __put_user(TARGET_FP_XSTATE_MAGIC1, &sw->magic1); __put_user(extended_size, &sw->extended_size); @@ -611,6 +611,8 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, uint32_t magic1, magic2; uint32_t extended_size, xstate_size, min_size, max_size; uint64_t xfeatures; + void *xstate; + bool ok; switch (fpkind) { case FPSTATE_XSAVE: @@ -641,8 +643,10 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, return false; } - if (!access_ok(env_cpu(env), VERIFY_READ, fxstate_addr, - xstate_size + TARGET_FP_XSTATE_MAGIC2_SIZE)) { + /* Re-lock the entire xstate area, with the extensions and magic. */ + xstate = lock_user(VERIFY_READ, fxstate_addr, + xstate_size + TARGET_FP_XSTATE_MAGIC2_SIZE, 1); + if (!xstate) { return false; } @@ -652,15 +656,15 @@ static bool xrstor_sigcontext(CPUX86State *env, FPStateKind fpkind, * fpstate layout with out copying the extended state information * in the memory layout. */ - if (get_user_u32(magic2, fxstate_addr + xstate_size)) { - return false; - } + magic2 = tswap32(*(uint32_t *)(xstate + xstate_size)); if (magic2 != FP_XSTATE_MAGIC2) { + unlock_user(xstate, fxstate_addr, 0); break; } - cpu_x86_xrstor(env, fxstate_addr, xfeatures); - return true; + ok = cpu_x86_xrstor(env, xstate, xstate_size, xfeatures); + unlock_user(xstate, fxstate_addr, 0); + return ok; default: break; diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 0e5368951f..c17eaaa22b 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3065,42 +3065,44 @@ void cpu_x86_fxrstor(CPUX86State *env, void *host, size_t len) do_fxrstor(&ac, 0); } -void cpu_x86_xsave(CPUX86State *env, target_ulong ptr, uint64_t rfbm) +void cpu_x86_xsave(CPUX86State *env, void *host, size_t len, uint64_t rfbm) { - X86Access ac; - unsigned size; + X86Access ac = { + .haddr1 = host, + .env = env, + }; /* * Since this is only called from user-level signal handling, * we should have done the job correctly there. */ assert((rfbm & ~env->xcr0) == 0); - size = xsave_area_size(rfbm, false); - - access_prepare(&ac, env, ptr, size, MMU_DATA_STORE, 0); - do_xsave_access(&ac, ptr, rfbm, get_xinuse(env), rfbm); + ac.size = xsave_area_size(rfbm, false); + assert(ac.size <= len); + do_xsave_access(&ac, 0, rfbm, get_xinuse(env), rfbm); } -void cpu_x86_xrstor(CPUX86State *env, target_ulong ptr, uint64_t rfbm) +bool cpu_x86_xrstor(CPUX86State *env, void *host, size_t len, uint64_t rfbm) { - X86Access ac; + X86Access ac = { + .haddr1 = host, + .env = env, + }; uint64_t xstate_bv; - unsigned size; /* * Since this is only called from user-level signal handling, * we should have done the job correctly there. */ assert((rfbm & ~env->xcr0) == 0); - size = xsave_area_size(rfbm, false); - access_prepare(&ac, env, ptr, size, MMU_DATA_LOAD, 0); + ac.size = xsave_area_size(rfbm, false); + assert(ac.size <= len); - if (!valid_xrstor_header(&ac, &xstate_bv, ptr)) { - /* TODO: Report failure to caller. */ - xstate_bv &= env->xcr0; + if (!valid_xrstor_header(&ac, &xstate_bv, 0)) { + return false; } - - do_xrstor(&ac, ptr, rfbm, xstate_bv); + do_xrstor(&ac, 0, rfbm, xstate_bv); + return true; } #endif