From patchwork Tue Apr 9 05:02: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: 787188 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57887wrs; Mon, 8 Apr 2024 22:07:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVANY1F797PiWOGUD5dwV/r+n5Hz7ghEvhIymwPAFPYbEuoJgVmhQm8R6hMOm93jhhfhCrZ92Mkz6iacOrkkN52 X-Google-Smtp-Source: AGHT+IEy5I5GUsEVJqGGekAomWXzesfndQSvDFlQiKZ2844y/qEYqmfmKhd6oBe1ZHPUN8ypKL6A X-Received: by 2002:a05:622a:490:b0:431:818d:fac7 with SMTP id p16-20020a05622a049000b00431818dfac7mr10951378qtx.35.1712639222985; Mon, 08 Apr 2024 22:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639222; cv=none; d=google.com; s=arc-20160816; b=R2qQ3fMbQ4wgoR1T6IMVwkkryhTzjlrSe7SBgPyPRP5pzYofvggmaO7+OjXUuPYcGn AcEblI6GP/u1TCI9bR5ha7NqIHbGN2aueclpDC0nOFq4xN2Jg66sUWFTZM89Y0hCExjz YSAejI5tAQGuombxYPH5Ke82tJ6JeVwCuMNMKG0K6n+r4tjkwCoInLLQkx094Mr2JzS9 L0KqZy7s+3xcdITexjv94ao1vKXbLIFkxozf2mcitOZvJF5mwr96TlyRt0U4IAyphFjY +JZoKxHkhoa404GK892aPYIyAT9Um0ln4VL33S4PpM4c4tCy7ijmxp+N8XbVNJIAAjTQ dRWA== 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:to:from :dkim-signature; bh=deMS08IZ066zxxT6J5vjnKajDpbmm9n8+soIwY3Yceg=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=lWRh/K4jPodYpKIAlhVi0Hg1QzDPL7BudFdcp0ojl8M4gezB+CfgCvzhA4sdTiG4tn tyg2nrwLxaNUGI7ZsrXMBNJrOzZNRk6DgoBmW0gesm8A9HhdynqIu9zkoTTom6ZmrfyD O0f0OcJbn8dV/0aLf8o1xZtHpcn6+3cvhYgblwNyk93kb5ARhCT6r7VBXaOKZMw8rbtc W9/3bK5WMxmgh37iYMsM1NvLlZ9V48VVPXYuLoyLYZ1eH3en9ptqcRySd1i/1LCnaGve W5+N/VIYZ08F8rs1638W6qdkgsj7bMsy33MvzwpWIH+9CPccSs+dYaLF9VucLHzbyNc2 1j8w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gBRzSrz/"; 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 z10-20020a05622a028a00b004346ff4454csi6903998qtw.640.2024.04.08.22.07.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:07: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="gBRzSrz/"; 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 1ru3dZ-000364-Hw; Tue, 09 Apr 2024 01:03: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 1ru3dV-00035A-SO for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:10 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dU-0005C7-2M for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:09 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6eced6fd98aso4607126b3a.0 for ; Mon, 08 Apr 2024 22:03:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638986; x=1713243786; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=deMS08IZ066zxxT6J5vjnKajDpbmm9n8+soIwY3Yceg=; b=gBRzSrz/DD6bx2iyueT1CxiXKV1jclO3Is+m3/K3Rp1AgDxHj5PuwZmEQMRieDiEVK mdrTC7TfQvarCIWnWOgxHSjZKmCtV+xYF25gusVtxTW4jas6QbiQYoQ+9KjIwIMIXhep yMZieGAIkYrvUC6x36CZJA7P5B+P+dAWjv49KhYVcuE2fmQUv9pT8Uv3PhsVE4XUnfzD Z86r1B6SJ8p/1EZhyijSdDv9ZywQUjIfT6446FZh2TMe216z199wyR0wfLfazCIDa6QA kBZol09OB8KiPkrANjdSrZpV/ZdMasIxOhwF3kaLZav5IrNOxl8gqRR0xOTbp2pj+t/p Wkdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638986; x=1713243786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=deMS08IZ066zxxT6J5vjnKajDpbmm9n8+soIwY3Yceg=; b=qlJGMXmoBpTMogxt6eBtmRBopcBj9lkmLo5BuS+IEAAt30K9Rp4lrCcUUh3wqAFOku HiqEWpDe4W5j8ooILwMKWEWSgs2BI7RBNMJSucv+dZK3GkgCZxvj86fub+6QEzyZtcwO rGke5ggikoMnD3tRRWbhlyMpKGqSGCZQUSQ9cLmdLRRsi4boXBXgyEqXB7JnXe2CqbqQ D0DCXPeCjhHBCDSX7q/qPUJluYssPZ1sYuFbcOlzPSrbjf8BEE2NCrY8kA5wOa48qAkc ZjpVXmPZ7lOhLSoIlMQID/VPWCHlgAgwAsBOXvBYdn0QARW2bn1cA/yAdoOyteJnHDcE iPYQ== X-Gm-Message-State: AOJu0YwkvBu2RFLFf/nxmZIiRWGMoIDaUZuFncbRBrtF5nscaDsJYTEm 7LIPhJFDFBlbIOIb4YkMtdWugMXbCEMBVCO9Mzo6x/A0Qrj9z+BaHPWQuF0932Z8U1/jwKs1TuA v X-Received: by 2002:a05:6a00:c85:b0:6ea:e009:1ae6 with SMTP id a5-20020a056a000c8500b006eae0091ae6mr14465230pfv.25.1712638986261; Mon, 08 Apr 2024 22:03:06 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/28] target/i386: Add tcg/access.[ch] Date: Mon, 8 Apr 2024 19:02:35 -1000 Message-Id: <20240409050302.1523277-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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. Signed-off-by: Richard Henderson --- target/i386/tcg/access.h | 40 +++++++++ target/i386/tcg/access.c | 160 ++++++++++++++++++++++++++++++++++++ target/i386/tcg/meson.build | 1 + 3 files changed, 201 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..8b70f3244b --- /dev/null +++ b/target/i386/tcg/access.c @@ -0,0 +1,160 @@ +/* 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 { + ret->haddr2 = haddr2; + } + } +} + +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; + } + assert(offset <= ac->size - len); + if (likely(offset >= ac->size1)) { + return ac->haddr2; + } + 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 Tue Apr 9 05:02: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: 787184 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57721wrs; Mon, 8 Apr 2024 22:06:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW2bvRh0hpVcfrxH1A2opLHGWYDOGeQXfG2jfenRg6OzWaRm8ahZa4gmKWgWiOSw0XqVUxmlKhUnwAq6dVotAR6 X-Google-Smtp-Source: AGHT+IGhz3u2BJ6SPv6VpuXgrxFizFmtb6N3ZO+ha/jmmOH8NsB2CAs5xG4BRj8OOiqyM4I86d5C X-Received: by 2002:ad4:558b:0:b0:699:28cd:b48d with SMTP id f11-20020ad4558b000000b0069928cdb48dmr2524040qvx.8.1712639191375; Mon, 08 Apr 2024 22:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639191; cv=none; d=google.com; s=arc-20160816; b=LsV0LzzgTE20qoqmJKl8aTuKLZPrWV11Hh8VvSjdOwQ7hnFEQLDCcs+UfB2Kp4I1ze STXJRMAO9aeUaH2YYzXG7qgn0gI7OefGfo4G/lllegGQsq7KvgrFgrgdOz5St2BnhMkA nZClDhfHhx8w3svnN1VCHj1NP5SW9EDHXX55/+ukSZlZNE+D9gRy4oX7Jt8FGEH6LJ3j JfbWjTg+gCgO/7hJj+8Df7EpIBSgH9xKEZ1m2JbDt0SjSZ7SbN76V0w/WMrEUxYHFZJ/ YA65sBsJBnvZdGmw0dqx8mNx3XvMLQLJBhR4rKN4e+yRQ4/O6DwYXqPZ+X34Y5KsTFCW lg4Q== 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:to:from :dkim-signature; bh=V5J2w56+6+p4hbOrq3RzfNRUe5UKleBy/qCHeJy8gMU=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=F2XIm7rqckLC4Fl+zr1rJRgtmqM6u0QVOqTMUgUE8q+X85jekfpw3hr28ZLSvv8pNv 7JHTvIbI7egGg5W5gJcfjGsQ9T5hH0TD14y9vwynogfm8BmcYua1tIPF5GsOxCbT3KCX DcEnAWNs7b1agJbyvKQMAL5MzFhWapxLHUEJk/Vi3JiS0E/9ydBiAe4csTmqFnaYjw9h 3XnGVcVimPcfqko40LFYstsn5GMzWE+qXLPbNC+/w/cGo1qjXOXa7zg1cDr9UZsLDSND C+AImwM/AFCeJ2HTRzPcM7wwz0NehP3cgs2WI3ceFaaSesVdgPonVUrIjDL/yRClsfbK MAWg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="RaBtI/FB"; 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 q12-20020a0ce9cc000000b0069945d8f21fsi8401530qvo.77.2024.04.08.22.06.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06:31 -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="RaBtI/FB"; 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 1ru3dZ-00036i-M8; Tue, 09 Apr 2024 01:03: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 1ru3dX-00035K-0q for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:11 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dU-0005CS-N2 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:10 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6ecf8ebff50so3128118b3a.1 for ; Mon, 08 Apr 2024 22:03:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638987; x=1713243787; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=V5J2w56+6+p4hbOrq3RzfNRUe5UKleBy/qCHeJy8gMU=; b=RaBtI/FBxW9PWiHZWgPI8DDbhhSQodAwd77oCxYSYIHCDpNReBqINwbJN/2KD9d/SI ywoeqO/vrfZxdK6IJK7bfPy6tcL8dvdvjjRb0F6NfI/xyo6lOA6aZDsFDsAo8NQbeV+T 4C4BsZTo9KARcAwzXfthqptyZy/eDGQtzfPUtHQI+bsEsOwG1FSUa3BS1bPZw/WxevB6 Hke3iA4CkWqFkbuZJi+6ubrrebRfupmQZmpWUxs7zJ3Jf4/LiA2MUQe5mM//6yzV2K6Z vwukMWqEJEQwYixcT4FzxfFKX1nx65LdhBZERi4TUJsAF+iMc/VpnA1sAmFHVnRwmhzI tK9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638987; x=1713243787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V5J2w56+6+p4hbOrq3RzfNRUe5UKleBy/qCHeJy8gMU=; b=R+6mC6vvo6ubOI6hId9JSfjWyQ3RghVoKU6Z7C4mMLlRH1kTytZxghK5LhNAxxHoaW yo+va8/OcLVdx4lHSvRBXQbM6VYGaQTEiLmCU70v75894XkG6oNl6wibY5SOEPa2uI1s RCRiIlEaFxv7tqpWMeLHchWm40iQukVlUjxoX8w/VEAOLLIPKyalA5tpa6fpLcL/4EhI 9H4TYN+yMZ9FTYFeWOP9vdd3ND+qqjinXxn8wVqJCwFTJLoDTHyAAEsA63blwW8iZ34a LQX51KhnBCAuw9cn2v90vpTS4pBtjwZJm6aPHJPyZShYGhszXTj5S5qR5FZaS4AJACvX BBpQ== X-Gm-Message-State: AOJu0YwgXNoHIvzLqmzoEbfrmWx/Ug3FfHTSDSyuI7jCcRgb2GY5l5Sn oLlcdYSJQaaXHvB51SrZN9JzQPof/6Hk7hITVU/IT0nQ/1SFegfDmoZKC/6o8HZA3je+ko0mAGp 3 X-Received: by 2002:a05:6a00:929b:b0:6ec:d3a6:801 with SMTP id jw27-20020a056a00929b00b006ecd3a60801mr2622378pfb.11.1712638987345; Mon, 08 Apr 2024 22:03:07 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/28] target/i386: Convert do_fldt, do_fstt to X86Access Date: Mon, 8 Apr 2024 19:02:36 -1000 Message-Id: <20240409050302.1523277-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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 4b965a5d6c..878fad9795 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -26,6 +26,7 @@ #include "fpu/softfloat.h" #include "fpu/softfloat-macros.h" #include "helper-tcg.h" +#include "access.h" /* float macros */ #define FT0 (env->ft0) @@ -83,23 +84,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 */ @@ -381,16 +381,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) @@ -2459,15 +2465,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, GETPC()); + for (i = 0; i < 8; i++) { tmp = ST(i); - do_fstt(env, tmp, ptr, retaddr); + do_fstt(&ac, ptr, tmp); ptr += 10; } @@ -2482,14 +2491,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; } @@ -2506,6 +2518,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; @@ -2524,9 +2537,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, GETPC()); + for (i = 0; i < 8; i++) { floatx80 tmp = ST(i); - do_fstt(env, tmp, addr, ra); + do_fstt(&ac, addr, tmp); addr += 16; } } @@ -2699,6 +2714,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); @@ -2711,8 +2727,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, GETPC()); + 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 Tue Apr 9 05:02: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: 787172 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57347wrs; Mon, 8 Apr 2024 22:05:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWda7KKVIdi2j9a2tdRiSRJ228+9eFE7f2/1+VAUsDbz05QWhhKBkI+WWQUgIfR0hkZ1FFQDcEbGxwSB+EeMZxH X-Google-Smtp-Source: AGHT+IGOIKRim6nuliTL14HyxP7DxDMZxLMgo+Rms15gyBXpx10Ro4lYVEj9ctHdNDKuXJR+gBzh X-Received: by 2002:a05:620a:b4d:b0:78d:40df:9a58 with SMTP id x13-20020a05620a0b4d00b0078d40df9a58mr10065487qkg.50.1712639115887; Mon, 08 Apr 2024 22:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639115; cv=none; d=google.com; s=arc-20160816; b=nUaehVYBNiYScXmbstwrc1/R1z7IwlDan4xAtOdBQyRmqX5DrQraqcDGi/89C5MhNv zfMmcRkEueX4Cum9+42V6HfAf7VFjLitJWK3MX3juIPKmIgyZRrfLGo0ljH19Ve5y1c6 8xYc7Qezt7JWxQ6tYB2d7RnJeStUOp0Juvhm4Brn8MKm204Mub6MMVHhTCyTSBccloPj aKDeTM7lydeAU8LLdyWVLaqzWdk6825uyOe6DsPWUr97vZ8bjUSrxnWz/5yZt+1igCMd UUAlKqYoyIHREskILBh7P4ZdVx85xcAdWo2Rb2+V2/HpOMdopMyEwwzFb/8JZla3pFVs hcnQ== 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:to:from :dkim-signature; bh=hw+ackY6dyXP/DNnptVLPX26mJCPUv8gsFb56I8Q9dg=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=brLRghbnX7Dn5Pa6j22hvpK5Eijxdg1WRk3CTSdXuf2/m3gJ/oVbhww/mgpSNvbLKp pug3GdaBBEmiw3FxzKL2lNIYfKKdlO6Dv3bWgwusCITjlQ+EGh7O7fVu2yoOAiRCCZRS pUCDzqG1yOboOu+/fDzV3PXBg5//FGT3OvzsW8Xi3D3LNueGOdTiNkH+moxqUBkXQAQ7 VmFkOwrofSMedC135Drue8WB0IcaPaT9nVpRlahLIpi1WlraDsF4iUnNtTtBcykBqjDp 3V4dVZsieZVhLkM4b4eXS2QF+eif+y3vuxZd1fcwnqz4EvQ9cZgA6o7ef+XWjEFe+2AI MHaA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kTCMswH+; 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 29-20020a05620a041d00b0078d635ac8e3si4527314qkp.189.2024.04.08.22.05.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05: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=fail header.i=@linaro.org header.s=google header.b=kTCMswH+; 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 1ru3da-00036t-Aa; Tue, 09 Apr 2024 01:03:14 -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 1ru3dX-00035o-Qf for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:11 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dW-0005Cj-1q for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:11 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ecee1f325bso4670950b3a.2 for ; Mon, 08 Apr 2024 22:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638989; x=1713243789; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hw+ackY6dyXP/DNnptVLPX26mJCPUv8gsFb56I8Q9dg=; b=kTCMswH+fGSysYiTUJ2HrRXet8dlj1sJUNWegGB9xSDgG9rqTV6U1iRckdb946cL3C REBnn+yD6boz4YlhhJlIP8Ox0BcF2AiWS48D2p7OM37dzaVa3Eg1Sx4WY6OJaK+0MmP1 qr0zH5xVB7nEGqoiSQ2O+aHlYee4p7zJPHF4jQZc5oP4JcjsX/DZtwppmiLvMwDnDJFb Fhpen0fs6NdR5CWFkhtOzGmdWF1FWzg7+A+LVu1QOH06/Al3PrhzidjSqhOFO3Fj13aL wKbRi5vNQ1ETdQWZEBZnX3yB1JI05dw20ZkYWKCv9QMOoNXME+kd5KklWppdF2ZISwiV hNfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638989; x=1713243789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hw+ackY6dyXP/DNnptVLPX26mJCPUv8gsFb56I8Q9dg=; b=VRecvfOAqqqOJO0Snqkz2K8Y/6fzzGEFnKK2f0Hp0DwLnddu5Y0TYxEByCsKzH/77K 0JgpbZtnvBazSBhbEJx74bG5SRa0dyi0qjESZaDfFygDbhImY4Dsf0sM6+NYcKgnqyXA DLINUBu6ZWjH+gGPVh6C74Axm6eIvAX/nrBnkJpkWW+ruRQipJdbkzevdkQgctaVyV3x wKEvUtNJALJzV/wpEBKlyW139BY4Ef/fTlAhyC52FUPPNe4wttD3z72ZNVBEpbJHriHX HrCE36J4fdlKRzGOTduMaFy6sGKA6wXMV5rAvt8w3sLxGvnxtljOvRXG2BCWbMS1hFtv dQMg== X-Gm-Message-State: AOJu0Yy5AT60DXujQ5D8G/4lFbq1DcXtsbNAKyjr/yWmiAfwV5fCU52X 7xSro1xMTRw4Kb1amMarNSxXuuWsxWplErWu9jS6GFCD4gFYDGj5lO35UDsVvCb/ae0decyBybz 4 X-Received: by 2002:a05:6a00:1250:b0:6ea:8b0c:584 with SMTP id u16-20020a056a00125000b006ea8b0c0584mr12316148pfi.9.1712638988740; Mon, 08 Apr 2024 22:03:08 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/28] target/i386: Convert helper_{fbld, fbst}_ST0 to X86Access Date: Mon, 8 Apr 2024 19:02:37 -1000 Message-Id: <20240409050302.1523277-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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 | 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 878fad9795..ad8b536cb5 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -772,18 +772,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); @@ -797,7 +800,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); @@ -805,20 +810,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) { @@ -827,10 +832,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 Tue Apr 9 05:02:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787177 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57464wrs; Mon, 8 Apr 2024 22:05:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV8DKFuVcg0s3jpNjixs2hIXHSAMy5mzH+8pnwQhN4BWRf13HiOpAhtfWK5KNBCpa5YU86G/w81VhiW2U6Oewtw X-Google-Smtp-Source: AGHT+IHbxA9UBTMTasArL7ngQ4au06eNVz3ksOqkwbeZtYW1tuKmYl85UFJH71OBvQfqDH2G7cL7 X-Received: by 2002:a05:622a:553:b0:430:e9fb:2c37 with SMTP id m19-20020a05622a055300b00430e9fb2c37mr9875029qtx.46.1712639137633; Mon, 08 Apr 2024 22:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639137; cv=none; d=google.com; s=arc-20160816; b=SVFXWX9Lyd3SQcvvwAoV5XqSy3diAxa44vrC5AxPiEeN2ay3BQnq4MP6MrUcx+YUxp WJlGxleFAyfwhJWEpdnbWVxnLUNmNe5ty2X8H5nMEYFR4pfxwq8sMWhtOLUWqkKoKVgG rNM78rz7kkGcYKd58UtU4Jy0k0MvaXXqy5IizgwtK77iKFVu9oh+zJm+seTjh6oK+94h aj+E8V+5BIh3cbxBySUGWqXuHIAMtsZAICVojTg4ZOvZNeVnb2QE7TKSAPGO3QWDd/qS FC8Am+GigkfZBHlRDZQOGNvZFf6y3nhErjJQLrEo5qaDPpByMEY3XfvWkJwFN01PWh7F p9MQ== 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:to:from :dkim-signature; bh=d7e1o1kdWD6RW81p7hz4Hv5E+EYx9lw2VzyOZjbmFo0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=edaPDDuDlZ6f+W/6B/wA3HuAPYPZfj5sfjWQKPhe6CAsQLsVJ3tz6H5GBl7vPdnXHp zA+rBzy5QigUQCU+U3x6UPPuFHLlolQ/hPZ07mBea7Bl6+sSc9vCbkKe9KH3fsq+tPHa yAoha1fxuSgIZubjlJXEnv3PA2eucbd5YSqV0G1JuKXbr3fapoPQOud0xcf/fRgCHr6Q 7GsBLZ5fuVvPoKS+BbO3ay/PnBysodOE+qYqQL0A7jd7g9RJgZFc+OMhTn5TfDJBzc52 ASaAZ1OEfc4b9SAVpV1qPP6u+FdWNGq9ho1vssFPthpAbR96NWfcwkr9HLvU62Qe6gKj cS6A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oHGYgXcd; 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 n22-20020a05622a11d600b00434e5fa8c9csi152557qtk.319.2024.04.08.22.05.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:37 -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=oHGYgXcd; 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 1ru3db-000373-6B; Tue, 09 Apr 2024 01:03:15 -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 1ru3dZ-00036j-RR for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:13 -0400 Received: from mail-ot1-x32e.google.com ([2607:f8b0: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 1ru3dX-0005DZ-51 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:13 -0400 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6ea0c8237d2so1422575a34.0 for ; Mon, 08 Apr 2024 22:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638990; x=1713243790; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=d7e1o1kdWD6RW81p7hz4Hv5E+EYx9lw2VzyOZjbmFo0=; b=oHGYgXcdhOG2DZhcprKKyMqE5PiXAMs35/aOf8Qr9SIamFGgjPkKBW1cO3KJ+DoREr VJBrYvS8/cd7Nz3MIqFZrqjQ6QU82BVIt30Re3hHg/wHJOfOxtmlK2TjOTXCnnEY9j+6 /jxSYy9jt88jueOjA5DBAAo28OHK4kX39Vs8lMLOHiCt2jZVvPQbJPDv1axA5g66UTrX 6OyyuHHmcuLMNS9XH4+VkuvGHA99OYG76SYK4OQ3O9dIsLfV37CqYy67HT3vG7i2K+Ko LiOobdJ9B7joYKnYp7Khs3OsAVVTUXGVXOZ7DPl9z2jn0bXuPcSaJqszK0UFJuFkoM9J m2Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638990; x=1713243790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d7e1o1kdWD6RW81p7hz4Hv5E+EYx9lw2VzyOZjbmFo0=; b=AnMQqtQYM2f2wNvK/Du0W7immxXhHnZDtN/jU5AmLwViFiu0D7MU4HR6f35UYpfVEQ m7ivSlfIrtDRLgrjK9DowsfuXJ0sEFhsREEE8zbp0hojOGDFk3yYsHm/3f1OMoi6PxmK tTYoBxoGgKPmvqms6qEjdQcDfxiCTmJP8UgnO746BXoejkaambcQrTJ/v0NZ+R+kTjP6 m6pQH2VHpqkKETGm5N2NAV6sUqxGuUutDejt2AAWz1JgX9bSrWGqEgaVoqmX2z6EevOu ENxMRLt/QvT6aXE7BMXssnFwEgCSdPpRF8hMlIHYbuq/7/2wKOVZruaw4LwAaeWCI4dn PCWg== X-Gm-Message-State: AOJu0Yxw6+ri3JRU06qEUJKp/2iyLjijJ6lwDmzbCzTsxhO8rQNfNnwU 3IwaAQrApXmzG6UxRAwPAXWXhKGxYtZYvKYS+YcaeWNNNpUevtMGjVA4SYQIXyn0pdYttdSaNv+ Z X-Received: by 2002:a05:6808:1412:b0:3c5:d6d5:b1c7 with SMTP id w18-20020a056808141200b003c5d6d5b1c7mr13284261oiv.25.1712638989847; Mon, 08 Apr 2024 22:03:09 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/28] target/i386: Convert do_fldenv to X86Access Date: Mon, 8 Apr 2024 19:02:38 -1000 Message-Id: <20240409050302.1523277-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::32e; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-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 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 ad8b536cb5..28ae8100f6 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2441,20 +2441,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); @@ -2464,7 +2459,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, @@ -2498,12 +2496,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 Tue Apr 9 05:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787180 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57502wrs; Mon, 8 Apr 2024 22:05:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXIyXJU/uAPInSEIHqe8MG1FXgWfy9Qpt5nP4TGappo/Zn5KE67R2wP/VxEZ8n58s4J4GB/puVz5ssht21fQJJI X-Google-Smtp-Source: AGHT+IHjWXViZJo0IHKDoCFBVE3yMX55pyS8V3YY9Rr64oVOkza+IjCoW0hEAIdTSAbXJ/7Rmugs X-Received: by 2002:a05:6808:1396:b0:3c3:cd86:b834 with SMTP id c22-20020a056808139600b003c3cd86b834mr12401491oiw.42.1712639150939; Mon, 08 Apr 2024 22:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639150; cv=none; d=google.com; s=arc-20160816; b=KpRUXUHp7zhGenLQeDoRsPpJJvDnS4Bm3JLp/kRq9SyXO8SS5ijsuraPBsMJpEPug1 Jy/tOoJeUUaKZNTwZbLDXLBXR9bl2wlVzXZAdszh0Q0byArD41LVNAYYyq6G85WnrQXb IVcYNgzvSyUdjZkpByf6cLFOa5KfAExTYPPWnfNFxUroY5eXNRCvlY19YAw2PFUi9020 dWpjnuFocF0mV3Hv9NJYblvKm+n5AHUoKNz6RADAwWfj8REm2jb2GiyiWUT/0HxoQpvq 0E3IA5+ex70+o4lPyut9bEvk/sCK29M00TP9icUb+L61zdLMPPevjEMw29Nexh/JvsWy Nflw== 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:to:from :dkim-signature; bh=hfT+4T/tbtQh8YAz/UBeFKLC0zLop+UH8ip/+XkWEh8=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=YFeP+WuRgD4NZy/tl40lcDBbmrj09ekTg/Tznij7OtiGYrrBhg02jOXKzQ+C5C2ccD kV2mI97caNqhPgItS219tCTF1lJWoeIGXdM5FgjptVy6+yBh5beXpbSIq1X7v8wUbl5+ zb3I1tWV+V8Eaz5XvC5ckxD3scJ8XIArZrmb2npWN1j6YC5cBDuCOFUsRtjYHgDFnYBD 1r1slNHXyeGUxPx1sbmmqV5aTXFKmyvt/e+sUc0xpU/v7VMgSxh6ABnTUYizif9UoQ16 XQc12YaRBWoKo1QHdMhJX7xZS0JsCbIhixAvtWOsleAoWezX9A3X6C5ALwZvfLUZb769 iI8g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R7ftRM1a; 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 k18-20020a05620a0b9200b00789ea463f58si9168955qkh.191.2024.04.08.22.05.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05: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=R7ftRM1a; 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 1ru3db-00037K-U6; Tue, 09 Apr 2024 01:03:15 -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 1ru3da-00036u-Cb for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:14 -0400 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dY-0005E4-Ji for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:14 -0400 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5a4f608432bso3887834eaf.2 for ; Mon, 08 Apr 2024 22:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638991; x=1713243791; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hfT+4T/tbtQh8YAz/UBeFKLC0zLop+UH8ip/+XkWEh8=; b=R7ftRM1aDw/21xoTbXxfQjwyr6mTTKsvLVI+xU5p8wktv3S0Diu4Bjo6bvIsCGwOgF sy/u/rAeYf/qtSFMPquPf8BWQO3mtR5uIJrK/Mq+J9Ih2N4W1Q4Gzil5wSe6b9Ki1ZPR Qn0PjkvVuYYUz3WoBXdsakfsW2L64twX9s2JrHZE+R0yQAsO6lytSVkKYGcBPvVhRGN0 MasdlTSQ8Wcruyw7k7mTzSbnXYagi3zQTEUE2DaJqWcA6QbhWADat0HVkx8sKBEKeHv7 touAMIktUb8QKozERCqM6/mlsHEFdh6tMzlMSTSOHtBWjoijJMbJ2Jx8aAuFCiPY9TXb SMwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638991; x=1713243791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hfT+4T/tbtQh8YAz/UBeFKLC0zLop+UH8ip/+XkWEh8=; b=OMG3MvQ16jOrD8MTqkK67J4iTTAnzGKy4XvVcpPEYueACUPJk1jh/R4d0TMc734kfA HUtDUAkZ52YPjY+U0CXPe2xtNPBWWnKSnjbjRtBOnNMpUwZ8H3eDw3xjlOjNixS+cM4M g9AXtzSyw51qhQuS72JDW6MuCmYOIYf34zzciHfFmZug0sj0FV3AbSdDTVPPiXfHAQ81 P+f6Qrrz1enf0lwbFvIpKALVM8K9M0KRPKMfZGMslS0A7D4V6fC2CYX8/U5FRY068oM/ qLdPH4QJgHjNgGIZXaxUCR55UPYSGFgGOqmyDGHB8nq+AkG/1WUOHBtFifvGL/g/myKP 6G/g== X-Gm-Message-State: AOJu0YyYqNXz2TFC4kXtbmz4rdTEm1QWu4aD1s5h+5Xo/ouY/+5ZCvpt c/gQqx16Oe66sKqHvATduinSoLysA/BWIv7H/1PDPncDVOQsk64sLGqRyJ6QFaE35yUWzlzIzZY R X-Received: by 2002:a05:6870:a927:b0:22e:e46f:57e3 with SMTP id eq39-20020a056870a92700b0022ee46f57e3mr10882383oab.35.1712638991273; Mon, 08 Apr 2024 22:03:11 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/28] target/i386: Convert do_fstenv to X86Access Date: Mon, 8 Apr 2024 19:02:39 -1000 Message-Id: <20240409050302.1523277-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c29; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc29.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 | 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 28ae8100f6..25074af0ce 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2372,9 +2372,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; @@ -2401,28 +2401,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) @@ -2470,12 +2473,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, GETPC()); - ptr += (target_ulong)14 << data32; - access_prepare(&ac, env, ptr, 80, MMU_DATA_STORE, GETPC()); + do_fstenv(&ac, ptr, data32); + ptr += envsize; for (i = 0; i < 8; i++) { tmp = ST(i); From patchwork Tue Apr 9 05:02:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787168 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57231wrs; Mon, 8 Apr 2024 22:04:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX3fRfTYylUzO18N7U9zOQAU1KRuiDFClnjBu7BfOUZ1Pjse0XFob/zhJBQXZFKUllFB3dMh1jNWujL+Gdidiqp X-Google-Smtp-Source: AGHT+IGz+YD5Dom88TeSWshBRM9Qw+uAa+LS8CtbCRndKUmpwN42LUuZHD8oeRSynRqM8tmWundV X-Received: by 2002:a05:6214:ccf:b0:699:1b4e:86dd with SMTP id 15-20020a0562140ccf00b006991b4e86ddmr14369300qvx.46.1712639091228; Mon, 08 Apr 2024 22:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639091; cv=none; d=google.com; s=arc-20160816; b=t9rwl62y72YNoRgJ57wzeQFGJzqz1dOT6LmFu0CnwH8+N7D3ngIY7NtX2lHRl7so/l 8xaspj8vd6dzNkF3fiXUWd77bdTCwJwDVXiXydLIFxox42YDfel4xjSfheYcl7sLsu6H iYoFhobVPrgvZG0smG4hCqXbe17HhKpCxaUI0Teah+YHYL53/dyhTaAkwz33WJZ0kCGB RCdFSpXK6F/QCKLcQw5wlDGj8HSPSkDVtaVDouGg8JZGOz/8zUoxcaE5Ua2Yqx5mFaZW TY6jRlRHJm7/+FF7rw18pSG7Bsj1ymEcNiWpGz4vnbeY1BcyoFygkkjjRzVW6mK1kKLf ueyQ== 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:to:from :dkim-signature; bh=eh7OtO5x8MRpHpQMvxE89QnFoiPmlYi26LFAKoMr5Dg=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=NyoXkf22ZCKqtX654G1PqnLgbpuWtaODRo09DiczE1ntIJw2eVFClvjTJhPdGFJp7Q fShaMe2XVQtFMGCAp4Ww9K8zs9o1Gw/SF/rxleSsec0T5hZv9DCDqiF5cNcT+i2oy4Ib FJwRE0FB0mvfRPNqKRKfm9FTBNdF1uvXKlPhkqCfjVAIB8pMYCenPqTrOXtVtqWDxwG1 mEOKC2I3dlIb+E6iuEs+3ql+rBhbRTkQKeiVfG3w6/SL3eRYWhc7Q2sgLbQQGIOvFDTo 7ULLw01MZANezosVLH3xzWYfHzuD1z7PdDdrVal7D9U67CZlt3RIWCt2e1/d0zboVqEi p9zA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wzjEoodv; 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 v14-20020a0cf90e000000b0069943127002si8853664qvn.318.2024.04.08.22.04.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:04:51 -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=wzjEoodv; 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 1ru3dd-00037r-QU; Tue, 09 Apr 2024 01:03:17 -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 1ru3dc-00037M-B5 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:16 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3da-0005EP-KG for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:16 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ecf3943040so3483635b3a.0 for ; Mon, 08 Apr 2024 22:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638993; x=1713243793; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eh7OtO5x8MRpHpQMvxE89QnFoiPmlYi26LFAKoMr5Dg=; b=wzjEoodvMruifXDvp6NWS6chqrAXoBp0rCntuLQtEg2TAcjb2Rsk4j7ALS9yquPucR 53oWQ00OZ4HF3nV7RCd6J+ZXN8hG+2RedrHvOZsqi8Tv2ajvkGLXEKPqAFuov/1kA1ND d2wbwgEOaKaY0wwk0B3JquWWtKpBUSgmy32RfQIOzz8hTYTFj+eFLcjE6k/R2rYCzYKO U0jUVqyqoAPFAGv9n8Jp/KtgHPerqk102fM4/1WhhggnNZiHCnZ2r9y0Mj81unKQN6qQ MwLdGp1E5Y1XS8bX+Z09Nt17N5l/f+tva/TaeYawv22+EOAiyQrTsSfrpXOGr64RX5L8 RY6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638993; x=1713243793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eh7OtO5x8MRpHpQMvxE89QnFoiPmlYi26LFAKoMr5Dg=; b=tMNZFjozwGhinS1edV/JySNWBDDNPDdnobIVPlntA0F8q1WJxrOUDo3mCk7ykOtBZN PvFrXP03K1p2ENtSq4u68hWDvVq9Vs4w04Ktn4UcPcnx0RLa22psosprEiiYITu0XJ+0 uMNvNyIwUQDFuqY+YyLx4fast9tcNPqgykbpO+mVV+PVsitDnTtj69qovxoxq7elhK5Y /ORvqONkHMci3OH4KbyauztElEFw1r0n6FewDWjSH7MPTedMcXMYXCQsiyIX2f6Bbh88 H7bsiEOs8cSHdTcFh7s1SzRSqU32ChmNkFeD7i2r0LFRoWNk19H1kJmtIH1LexAnoKcj YuDQ== X-Gm-Message-State: AOJu0YxZA/gT1K193Z0B4DAlIhMb7R/WAd2UzFwLFS/YQtb9O4MZ365r wdp9uhsISGkWAmCEwG+I706zWrL4mTRZCoqcBV9BSw1nM1Xp63guGaOGSj8W1X/BJtA6YERmsLQ P X-Received: by 2002:a05:6a20:431c:b0:1a7:a6f3:1822 with SMTP id h28-20020a056a20431c00b001a7a6f31822mr1107931pzk.12.1712638992770; Mon, 08 Apr 2024 22:03:12 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/28] target/i386: Convert do_fsave, do_frstor to X86Access Date: Mon, 8 Apr 2024 19:02:40 -1000 Message-Id: <20240409050302.1523277-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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 | 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 25074af0ce..e6fa161aa0 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2468,21 +2468,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, GETPC()); + 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; } @@ -2491,23 +2486,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; } @@ -2515,7 +2509,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) @@ -2971,12 +2969,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 Tue Apr 9 05:02:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787182 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57651wrs; Mon, 8 Apr 2024 22:06:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWFszP5pDILqsZZ7Dd/AnKtxc3cBrvsjFnKeMK6n1rVpExb9myM8mKAxCK7qh9dP2QtB21R4NBnmE91YWIIGTmK X-Google-Smtp-Source: AGHT+IH338bPRnQMo5d2q5ZZ0WBVJHOfKrFhdFGCyE9om3QA9eMNlUdFbLpRjs6oPiDYdAZ+pWGs X-Received: by 2002:a05:6902:f81:b0:dcb:aa26:50f9 with SMTP id ft1-20020a0569020f8100b00dcbaa2650f9mr10245664ybb.46.1712639181183; Mon, 08 Apr 2024 22:06:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639181; cv=none; d=google.com; s=arc-20160816; b=NXbx30XQkuHs7iqpVSDyRagGENdqJcMIhivJz2V8UBlHKLHAYEruospJv14JWPrbuh 86NM7wcNyc2wH7fWh7H24mJw3au5D4kHo6XCK0VPz2F2vKQaAaLmTemrJQ7AB9Q+3ZFp VXkxAd60UypigsVTVJwX5JYSCcMTTFIBqGyKPkw2p9n7Cmt0ej/gJSxkuCjGhMxNE27Y fWL1S+e+QrrF17yy6xTRLJGMIORgjY79XH9v8vhQ3Y1M8kScSHAQbceBzIOmofMiKtXl XXqPXdwq9eAqpBFbBorQ2FR6QXlcITniJVchPar+dbhzkvAD6bAzwUkGo3GWN9Oxvdfo UV0A== 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:to:from :dkim-signature; bh=kKpDLagrZYAiIJ964rsnwQrd7WyWBxSid17PdqzgjX0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=HOh2KLd83UD+xsPQw7JSvuUvnxbxvBPO4RWbQFtNmKPjPCWXz2GKa5F9ZacfiGTdkv oQ6mE7nPFbZAh6qBDztx/KAbYf24iIKodSJDWLFzeRJHQ/hYr2/4342JtxaHZ87oZfBr JUuLtAv9JvqiKSYgt09kq3o9Q6seX0eKc206mjLAIhxS1IDIgmlH9O5THUS89c7T1lXN zwknra12Y8pXdiJ47JiHtD61BLQdpZ6KQkS3XblowbtQTIZVy8DaqSlRepkFf2cpjiS/ z+j33DD3yIpWvaR8bPe16gU2BzjhaWEm1u30Yqkw8DQDO7K+eNkHz1CrHjYbh6Y/PyWR 1E/w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tkpTZW2n; 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 c17-20020ac87dd1000000b00434cbc576a9si1357785qte.307.2024.04.08.22.06.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06:21 -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=tkpTZW2n; 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 1ru3df-00038a-Df; Tue, 09 Apr 2024 01:03:19 -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 1ru3dd-00037u-RY for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:17 -0400 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dc-0005El-06 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:17 -0400 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-229a90b7aa9so2326353fac.1 for ; Mon, 08 Apr 2024 22:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638994; x=1713243794; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kKpDLagrZYAiIJ964rsnwQrd7WyWBxSid17PdqzgjX0=; b=tkpTZW2nPICETU9UfFP2cTlfekW5vFsULFYfpFaHzrkchYlHUMzGZEE5v0x1bk2OzY 0656o1tIZ1PPP9PB4rMlXgbjufykdRG9ys38IKYuZ5n9EXRnP9VdwFz9gF7TcYOdHhiD Y7jIq5htreMAat13hBlNxTdpccwhAajYBGq6SKBwg2TPORHwIg7GN9ZNklEUc3R3JZUN VYOGkfTJITr0XbJ6fOaODYvkLwdqftpGrqbwabmuv7f/pPV5ZhxAeif9PO+rEpFKlkZN njlw7nVVVw7DeYcW4GY8tZlzHZ3rpXQTceXCvdAAozTR4ovwk46gPsoPXfrf3DkFN5x+ +3AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638994; x=1713243794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kKpDLagrZYAiIJ964rsnwQrd7WyWBxSid17PdqzgjX0=; b=KKKqeSO4I1rb8iKZUPs/K4Z5aMZRl3mh6dpgXlt2GgW8lv1DPn0snguWvYtH6lQ2RU IPhdio1LCXRmpS5k/J4bG13sFLLtLZusE4iPbK0i1MfHPpDfKQtWO1oHN/81UmIg/LwY Zo/AZFjCY/Rwy/ORrXNgzbVRapbysrs7JXwOlmHWY5MO3KGEslVtBoYl9W3sxIotDGAk NOj17OF8eO5ApQytPhdgCSTwdVgDIgVZaPJ95/BbY2sS7lI3gulN02nzSXmbJiU5qDo6 oaGZM3UE7glUYcrzpEIr7yis9rb3z7k8RuKPsY+BpN+rIZX0Ufr1iU+FPhxpKzLaFIq+ no2w== X-Gm-Message-State: AOJu0YyoaJyQsvs7TmukmzMrkYthRfkQR7nRFeDF/Mdy8oGUEbGgfzrB MWhM/y6e5Cnkh0zGqfQtjUcyFP+bBuqisqzMNtPkDkW5OL4UQvFTmpGwan+iVy/RSKKnAqF9Fsx 9 X-Received: by 2002:a05:6870:82a1:b0:22e:bc50:3492 with SMTP id q33-20020a05687082a100b0022ebc503492mr10175727oae.47.1712638994360; Mon, 08 Apr 2024 22:03:14 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/28] target/i386: Convert do_xsave_{fpu, mxcr, sse} to X86Access Date: Mon, 8 Apr 2024 19:02:41 -1000 Message-Id: <20240409050302.1523277-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::33; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x33.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 | 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 e6fa161aa0..643e017bef 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2518,11 +2518,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; @@ -2530,35 +2530,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, GETPC()); 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; @@ -2570,8 +2572,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; } } @@ -2618,20 +2620,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); } } } @@ -2659,6 +2665,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)) { @@ -2674,15 +2681,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 Tue Apr 9 05:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787176 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57450wrs; Mon, 8 Apr 2024 22:05:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWSaNYv0yztWhknmZtX3DxdmiGZhYG6WaAJelyUw/kdkiX8SIZm9xgVVOei71hVLEZNEYgrfAOVmWNtcUOukqr4 X-Google-Smtp-Source: AGHT+IG+dBYxDkE4JrAxsc5bmSZ2aOdUFlFekMb+IDk1WlVaeo++UA/JhiaZy8KnsfLB7C7sY2bn X-Received: by 2002:a05:620a:17a6:b0:78d:6fe6:a308 with SMTP id ay38-20020a05620a17a600b0078d6fe6a308mr1155926qkb.0.1712639136259; Mon, 08 Apr 2024 22:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639136; cv=none; d=google.com; s=arc-20160816; b=EyyxuNO8T/CMuIOCjxgVGTOCg9sDh90AjvV/glaT8uom4cAHg8TuFPXoVPRAgLF16J QvMExNEwI+xXgXERBbv/4O/yX84Wpxoa/RIj56tXtzWUviBn621VZTWM9tz6FscJlS4I oAbn9fYZRLRXSuYrhBEKr7NzZdrejp7GW10B7iX/Tv6Kf6367RABD9fis+Whi6GFXibF 7xf3pqAXuygGQ1jbTuMgm8CIsn3Ry0u33wlauCsx0sdlDhzm92yaCdICEkPdTmVhTWWd +HDAGb7PCdPfnEQaJEoPoL13HJviv/yKJxwIAcDKle9pieW0E8DtLGXKXXiaz//+cUbw /N7Q== 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:to:from :dkim-signature; bh=JofZgc4oYeIfJmBDMO4CGM8MdcaFZQ0RyhmTRyn19x0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=cX9qEXrGTp/5r6seUetRyekwrfDLO4ByiPr8bDlD2jaLNkvGCGvo1iqPcp+Jizt18G oMMQstB2LvSEEa9z6ET4OGqWCKXQ4M+4o6YfipRp/XspqL2pYzQ8qMGPMWftXWLreB/E oJNvxHjRowhZa44ywRb2hDa2whrkRl5VUJ5XsuTr+FX6sPC+k9NmIuE/r25Md1t4JIYy YvKJSy7zy4kMNc9mNcgjW36/0olGUcwjChpPyWcWVYbQtrPTDP7LEUe62riJvFCU5uwI VSciG+YuUTabKsKEz1sCLGgdNIm5fH6TJUv7KeBwvh7WgNmmz6tSpEYgN3zUPnLvL8hu A47Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uO78aQI1; 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 xr1-20020a05620a5cc100b0078be188f652si9339752qkn.359.2024.04.08.22.05.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:36 -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=uO78aQI1; 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 1ru3df-00038b-HE; Tue, 09 Apr 2024 01:03:19 -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 1ru3de-00038D-Pn for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:18 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dd-0005FG-1l for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:18 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ecf8ebff50so3128155b3a.1 for ; Mon, 08 Apr 2024 22:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638995; x=1713243795; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JofZgc4oYeIfJmBDMO4CGM8MdcaFZQ0RyhmTRyn19x0=; b=uO78aQI1M0bbTkv7VY23Ig5pVnQywFJf9kYein/UoY4hmYk/cm7LodRrBqw50b/Cxx CdH+F2xtI1HnsckxwolPNxwk3PrbD3F6Y66OgsEciNRKlwOd3eOVyH/zbGQtFUBcOCiR /0Nq0upBmVPshW41s/gWdCgPPIISmmMiihnltyh/RiA+FsXJGX0sX1LVGvMQBbGIHbKk MhTye/GzKoaZJh6XYYv67zWV2ZUp9fCvWbgIsMyhGhvAU96XfdT/v340kmmVTD3g+j+o 1AkGK0KgzAel6N9yylgiwIfoDyj0VO1YlCDpXI2vPE1P2mls4ZoXGUs3oGnVeYmfyoPq YdcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638995; x=1713243795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JofZgc4oYeIfJmBDMO4CGM8MdcaFZQ0RyhmTRyn19x0=; b=ortx8wqvY/7JpnU83pnd4lczUQwp0H9zLPbxHnIAu95Ctl+GHYF4SLdKL2Iq4VR8mT LVylMZdwiMmrRfU4jFrAgWWf0T0CAFv1IQAB+HVMf7YGt17S+iZM/SFXlbXuhVYILcFF FMwHLATKQZs7nKJ5ZJ25qMaiFuB5qr+Oj/KCM4yh5J2zu6o6uXwsF1Di6Y9xCRhB34Ku 84KL8SEvaUZ+ZdYjYhl9aP4Y+XGbTnrSBmedSeMDQP5gv1fTnnsa3PnGjGAW9goZXcsU NBKJgeHe8htPXdmGSfSSqUGgIilQNrQct/MmyDaoiEEB9VYNAu1VyK9d4N/z8MqADtD/ E3Kg== X-Gm-Message-State: AOJu0YzyPsK39N5ltIRModqeZE9SfVZow54KYESGDhGTjfgIS3fK5qYh mfkWErtoO9x2YvZzDvQq5qYITWlfjHBtQxZjhjd3hqPaeCefAGnep+31lI/DgFGI/+EfYO2D+MJ 9 X-Received: by 2002:a05:6a00:4fd2:b0:6ed:4b2d:a764 with SMTP id le18-20020a056a004fd200b006ed4b2da764mr2489755pfb.11.1712638995469; Mon, 08 Apr 2024 22:03:15 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/28] target/i386: Convert do_xrstor_{fpu, mxcr, sse} to X86Access Date: Mon, 8 Apr 2024 19:02:42 -1000 Message-Id: <20240409050302.1523277-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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 | 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 643e017bef..59f73ad075 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2724,39 +2724,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, GETPC()); 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; @@ -2768,8 +2770,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; } } @@ -2849,20 +2851,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); } } } @@ -2875,6 +2881,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; @@ -2913,9 +2920,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)); @@ -2924,9 +2934,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 Tue Apr 9 05:02:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787166 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57034wrs; Mon, 8 Apr 2024 22:04:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWAg+6GRLRydPjC+TzuLSV4UBV3pwhpzXsLBWwyAqcxDk7I7P4axPkDuBu5r8RmmZD3UMU53QimBXMAswK9U77H X-Google-Smtp-Source: AGHT+IEvVioajCtKeIitbzNLD3QYXIuXqZNkURc/2bdYQkucRFhzaWApexyUQZ+Mpjqu+9bekd5E X-Received: by 2002:a05:6214:e48:b0:69b:1e64:413d with SMTP id o8-20020a0562140e4800b0069b1e64413dmr4554133qvc.52.1712639044611; Mon, 08 Apr 2024 22:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639044; cv=none; d=google.com; s=arc-20160816; b=tCGL8GSsKTy+no6ktdeOPTC51mSKlzbEruziMHpRr68wlfV+W1BLiaz0z/BK9QeVVO MPG6G7Zd2jRB+YCU1HdnknT4c8K27UiyWe5/FJ5fCGS0ORynGIknjDrPznObELjepe2a abQT8WnabLyC/9kmKfc/5egrIllevfdfvJujYuR4sHXQLOkeImKk4ngAeRSbMlEtj3J5 P4DIp4EQgYNPCIGwQmOZfgJlzIFufn9+SSMQ68Ke5i1u2ims86MENdzziqXQ7gLsIyi1 lIoV32UVX3nSzs1EICqDDoa126X3OvridOzJzDVeHJRi3BngpO2he6uJ7O+PvjMDH7pD ARQw== 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:to:from :dkim-signature; bh=Lp1ipweNADN/6K9dE0kz0Ja73YaJ/vSstA3RIvGr8kM=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=F8JAvtm6Po0MyDPOXI7CANuI0SCKOtJw5bcgnPr+0YULOgziAHmHmA450r9HQsU/cd q6hCby8glwrsDY3Z78iW0Zr/iigta1Qg/1MTjCAim9Hkczljk1EKAKPm5keNOjTrPoem lbsNk4F+2wcJIKezTdd/HlQVa+xBAuMafYFjncs4RVifaMiNXYmN3leRdzlOLMfYu0rm RezfbpQuhH6yy64M+lqK2dPw9Da86JTUpAnPxDUI6if9dMPpzO8y+xrC+du5dz1cdtgl S4311YQgi54mc4KFoBHpAnFrNomB6G2ev4Xt7dkl0FiSnOCLTA80jvC52zF+f9xytEBw MOCg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bGVWqD60; 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 ev2-20020a0562140a8200b006992215faa0si9276556qvb.484.2024.04.08.22.04.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:04:04 -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=bGVWqD60; 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 1ru3dh-00039C-4w; Tue, 09 Apr 2024 01:03:21 -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 1ru3df-00038f-OP for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:19 -0400 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3de-0005FX-0v for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:19 -0400 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-22fa18566adso121512fac.0 for ; Mon, 08 Apr 2024 22:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638996; x=1713243796; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Lp1ipweNADN/6K9dE0kz0Ja73YaJ/vSstA3RIvGr8kM=; b=bGVWqD60NjJM/0SL2FCs5WeHp9OQhyuHbwyG+WkNwqlu/g3ydJBOx/IMFMgY7vcRYk NNWmyWTqxm7Bp/C4CQmZ5rkhICt+5ukRoH4vNCcjGK69PbjL5sHhU9swEPyQNvhLnZOE xMruL8Xy84zWJxEqsdpP/4CqsnbpiFm+PVLtXxc4qISXvXOXAsdXT2MaF3YXw5+uobuq PxarYji448fn3sMbHKDGzVEjepVD1lGfZKSDEaIR8U/qTII1L7NLyTmOK/uOBS1NZtCB k6vvBx+TqJBBBxgq8yaubnfk+xp9Naet/aCI9dXsd0eyVeDbWVLRynKVNO4q1ROm9pfu 3etg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638996; x=1713243796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lp1ipweNADN/6K9dE0kz0Ja73YaJ/vSstA3RIvGr8kM=; b=Y+gLNH1FY64rNZ1VWVj0mtEYwAJIIgRNLPzmtlkEP9V8pfZogZKve+TIHyJOv91tOJ QdXPVMTgsE80jd6gUsTS6yelFkA11/J8aDQBgpkBOGqwSZ8iIZLzxamuWDXWO93nz57k z91JT5rtUGFgAekQlFpJDduV0odnnnYn4xRKfwzswG6aaWMj9KtO4kOMNNUpH9h7+5CJ cvgwx/L/flg2CBBHAoZdVqHhm7G2Vv/PZDHWbbW6dShS+ZRnek+1TdkEPux40ITBQLC8 bpKU/EkSp5tGHLtKN0kJ28sZ97kpHe8UTDZ6cRrk25dmWzW6niHVIE5Z1V6g26RDoBUD 8QAA== X-Gm-Message-State: AOJu0YwDUTFbLO93OSmNjqxg74foIauetUmkJ6+2stfglX21jCpjxybW atTXQnyXVtK/xYixiUUOLXl0heXE3Cs3hzs6OfA/pKaarH9VkP5H8fPSBXhbnKs664MKJgh7Cci e X-Received: by 2002:a05:6870:15c4:b0:22a:107c:4dd6 with SMTP id k4-20020a05687015c400b0022a107c4dd6mr11849811oad.40.1712638996599; Mon, 08 Apr 2024 22:03:16 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/28] tagret/i386: Convert do_fxsave, do_fxrstor to X86Access Date: Mon, 8 Apr 2024 19:02:43 -1000 Message-Id: <20240409050302.1523277-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::33; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x33.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 Move the alignment fault from do_* to helper_*, as it need not apply to usage from within user-only signal handling. 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 59f73ad075..23e22e4521 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2618,8 +2618,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 */ @@ -2629,22 +2646,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) @@ -2849,8 +2851,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 */ @@ -2860,22 +2879,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) @@ -3007,12 +3011,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 Tue Apr 9 05:02:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787171 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57308wrs; Mon, 8 Apr 2024 22:05:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUDkKT+tPRL0KA3apyCKJyrYTNzcXNATiwJxfedoFJp/P9tqR0AwGJLrtTov0eykn4+Nua4qeCWx8ZQng7jvVJp X-Google-Smtp-Source: AGHT+IGxpO8VArKPoph4qAKivivaSr1680FCbQet1qJr9umRZ+ek5LOeAERX0YgUlarDaY7F1oEl X-Received: by 2002:a05:6214:21ca:b0:69b:246b:4bff with SMTP id d10-20020a05621421ca00b0069b246b4bffmr3478100qvh.33.1712639106853; Mon, 08 Apr 2024 22:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639106; cv=none; d=google.com; s=arc-20160816; b=nznLAfYITwdcm/RrO/rWEjIv2h+rfi9IOGcxZ01gV+r7OMbTiVkXTsXwHI9f3WKjPJ QpNRPzsP+DoF7cvqydwDg4M3zjrq4eQMXCxam3x7QSsyowv1+ZMYVfVp6jtnlh8DBUv+ OISbhJ20WUySeuOzduMJaannZFmdAPP6c+uOOCx9X627rwB94I6EMcX3tZEXYp2zEBjC Dcrmcs4ifOsNVJe6iAeL1kJxPoKbK/F6OpukEEpMXOjai0sHs3nmwdyPxIbOkqcTCUv0 JgcajnlnQM5iG4T570N2zfjE11RMACKoa4NKqxDnZvpFtLoQKR3yit8VEEZMJXrfGKcW Gmhg== 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:to:from :dkim-signature; bh=xn1vjagAhAGFyndA/SHEdLBYzd75+zPjvoYCTonqVpQ=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=lNRhG9c6MccedRmj6iYs4Fws/1dE+9/lugxXc/oOptk5Vspa9sYsSpsxN6rzmPRJCX KKP4PKmteLat/rWJoQ/AGBK6MtkYoQs2OOdgDisfQZCHW7Vg940iJ0VNtiDr2Jz6x3oS 54cGCxjrb5n8SmpjQAGzhlHkSkFCL/KjMtpLHPoEt7tgeXQAONObUBNQAzJUZCq3Ui92 WNJKoH3CaBfHak4dqpGv18At3Ni/GwdnAnXCeoz9W45PE62GtyHNX63efUnmrKHlbTRk z8PaQgkpSCrdGd0qLAePFqmiUfDys1Z1MxIrmxDGhk7MCLh8ZB1ScIUzRWY9HG3JEm7+ +lnA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CXZHEw0N; 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 y11-20020ad457cb000000b0069b290fb61dsi792912qvx.83.2024.04.08.22.05.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:06 -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=CXZHEw0N; 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 1ru3di-00039V-5z; Tue, 09 Apr 2024 01:03:22 -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 1ru3dg-000390-OE for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:20 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0: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 1ru3df-0005G9-1w for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:20 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3c3aeef1385so2893280b6e.3 for ; Mon, 08 Apr 2024 22:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638998; x=1713243798; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xn1vjagAhAGFyndA/SHEdLBYzd75+zPjvoYCTonqVpQ=; b=CXZHEw0NlNDWcym+UekgroJbNKZ0YsAXtQ8f2+fF0RyqeHygnhaQ90joTyaH8NlN+o JLxh1LpNMm7iEHihesL6vYfNEhGGfqUhFKqtokusKbw7/xTfFYBi3kpLjcGEa74LDvLe bbTsnsbO54tsWMPlpKTiEbI5tjFzHR/gIl7X6pGXKkuSstotLLpO0t2TkkdQqP84689P Fzvr7F2MzChO3ps2Uqdc+qbX73zLtd3Q/oT2lxghKYMITI1+FgueHLWxfjwLUep461qf x5aJoU4TTn7h6paba4/lWEQjmCJXfLXQxt2eVEeu80LInW83hoh7bwcrs4Hf1VEoajts MaqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638998; x=1713243798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xn1vjagAhAGFyndA/SHEdLBYzd75+zPjvoYCTonqVpQ=; b=gFGlXC2C8nSePTfKr5LuFRXP5DWIq0LDn0e3U0Zxv5j9ZyLzR4eGV29ljBtvE2gcen hSdu0ZNvHZevNafk4/9QWOEuglFRYLr2WffKM2TIIfxffayzkV+OWXTDYSMkAhRGMepK nYEllYGPeKSmqEz/mWXlSpxUZKryflxIz+oBVVtJk3tkXhMLXA5H3ldgeDKDNe1I8mSC uqDf+s+kNOKiaw7KQSNpGlHLMENNTD2B/eySShEAjVaRWnzqGKj6bn9eHxGoa1qsSPUt QR/XU8c6iSUXINAWe5/82oKiNHsywuMnmbI9a9X4P+3hC2k3Bm3ITyQ/EWp9ZsR8SJ8I ++fg== X-Gm-Message-State: AOJu0Ywv2+95mcll5Qa1xIpbSV4EHMLoox2TdE6TK7slVzHQ57vz0p1q vNPU5y8q+czqPo30lafadgZ7g4F5FAmVR02/Mn2FzS/k2O6/j2oNRlDxRm+XSDtSI6hXdyWezf4 x X-Received: by 2002:a05:6808:190e:b0:3c5:d512:22b5 with SMTP id bf14-20020a056808190e00b003c5d51222b5mr12711153oib.14.1712638997981; Mon, 08 Apr 2024 22:03:17 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/28] target/i386: Convert do_xsave_* to X86Access Date: Mon, 8 Apr 2024 19:02:44 -1000 Message-Id: <20240409050302.1523277-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-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 The body of do_xsave is now fully converted. 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 23e22e4521..82a041f4bf 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2578,8 +2578,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) { @@ -2589,33 +2590,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) @@ -2668,6 +2672,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)) { @@ -2683,8 +2688,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); @@ -2697,22 +2702,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 Tue Apr 9 05:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787165 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57024wrs; Mon, 8 Apr 2024 22:04:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWSepGI8SLv/HXivpCvuOPF9cd3eVEuNc3OmJH/q/iygcWUfhBDtNxwLil7FF1sErz8lNb4a0gGQGNff+5DXHSt X-Google-Smtp-Source: AGHT+IGf6tn2PusNwsB1wuky/lL0iBd2Bgp1aVj6qxVl3KwLuoFyE1mUkON8oa7oEVihgjsPtXSY X-Received: by 2002:a05:620a:c91:b0:78d:3649:2594 with SMTP id q17-20020a05620a0c9100b0078d36492594mr2202438qki.22.1712639043333; Mon, 08 Apr 2024 22:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639043; cv=none; d=google.com; s=arc-20160816; b=SJzjvSUgaGP4fg8yYhulYeOpxGkesZcBRXaHt8SjDRhk87iz55B1cgsd2qHEzFPIM5 ZK+X8mxxkH13eByctz2HnozGshn9Twly9Ofas3uIwcPUeGz0SzpYjRZF9Z+O1yfZPyw3 xumlYCbu+lZFBw1pnDuiIoZ2qHD9ryMxl1Nre0CKp+bnqxsnktWrbkSLREraQzQ+UubF 7A2MPSC5bJPbnbc7lXvQ5dZlsF+GiKhm1NR7ytbCz2ai6ucYVUSugXZv+JTBf1jwuk9+ 32GpTNowhPXz5TaUYW9AlHZmiYmWSznJccLZkpgQLLPktDnDKcCGSnPohoMok2Zo99fw i92g== 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:to:from :dkim-signature; bh=eNES/6ErEss0F0rb0ZQ2Omi0ZiA4KOev3GgtB2/SY/g=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=dTh9NkrbV6Mp6hj2vyks6mVcIDyE4wmZrn62rx12nc38wQt/XbHCiExbJT7eVUBjNf Llxtym1d/ZD2w5N+Z5GWbZLXSY5pDf9BqCAinuRLZkt4JwX37Hm/louKfGTfSTRQyGdt tuHOihx6/TTINd5Y4+5P+8pWGiYQGlJ/xRM7wcimTy1yV/fjEHfdU5UWtkWkD/eqn1od CcmHJ4w1rh1Vo5cg/nz94JB9v3K0wmyH17WKXfZGB9l7JmzvPAbIN6iifU/LuPQ+r9iN K8UefbETn/oXsrmx5s6WhgsXIPQwmSMUfoQa5TTx18oltaakOS5UhVyZJqxD+A+Lo/ME eYlg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tXfcdMOd; 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 w18-20020a05620a095200b0078d66561eecsi3578595qkw.33.2024.04.08.22.04.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:04:03 -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=tXfcdMOd; 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 1ru3dj-00039x-UQ; Tue, 09 Apr 2024 01:03:23 -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 1ru3di-00039W-75 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:22 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dg-0005Gh-BX for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:21 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ecf8ebff50so3128190b3a.1 for ; Mon, 08 Apr 2024 22:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712638999; x=1713243799; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eNES/6ErEss0F0rb0ZQ2Omi0ZiA4KOev3GgtB2/SY/g=; b=tXfcdMOdaZpLq2gep0SOTC0F6qeAm8bLPfoaiESQyo9/dpTBuK9rygzVRij6aXbHC3 2PsV4vrRsy6/dONL0hMeP6TlXqwPKfVtN5z/lbMiqyp1lGTff5WDjOrKEGB9r8yNdS40 lenNhx+7l8E9b7l25d/qE+W0Wqb+LtC11ElMSGKvmYP4EGOSxEryojXRYIgvMpcKUQr7 h0gL2O60bi1jWAM5lXbcs5C5ezGxAW6Q9+iXrWD8bZ5W9eifu14szZk3PhmLPJBAwA7v RAcEnvY8er0mI+vOKEUJNdn8j4iAMOfdNAO/HTT3WaeO0hUI/Ib5gZOze/tmVviKFzx6 qq6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712638999; x=1713243799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eNES/6ErEss0F0rb0ZQ2Omi0ZiA4KOev3GgtB2/SY/g=; b=OjY49t7L1d1We6+u2pFACcN7qb+kMNfcDKRvI6NFo4ke6Ww3pYWtAIYsuyeaLglB7g nK+XiXuTctXF6ZAAUoJMWyl5hnSmVf+5OGudRnajsXUpOZtxE3B7j+vzQM2NDemaqz+P g/7fGIE7xzCVsG9pVZJ62yeodq/2Ude2zzi/Wn0S54oOB5j073ukRyVKW0U8+xSJhsiS nvB6qxAuRYKX38c6nOpQG9HUglm+pqlDEBr0OztZrEPUvPDWcBfDFeu6ymGof8t3ipJY 97duVWCvflEWJ+1i3sKIbKi89Mh3CBU5OzAyIYhTLObvolGCIQf+dYPfh3Ycs8+eBBVG /4uw== X-Gm-Message-State: AOJu0YwHdHeA+sudoEMIUdwwWp0+ooEKbB1C8uxPEqa3kGwUB1ediezl 4Y/dcBQEQSXTxYt323OY2j/A817y+AieGuuJbPsOi2ey95JPfalfhCAVv+YhymZthzHPPvcixuU i X-Received: by 2002:a05:6a00:4b13:b0:6e6:fb9a:fb45 with SMTP id kq19-20020a056a004b1300b006e6fb9afb45mr2160227pfb.1.1712638999119; Mon, 08 Apr 2024 22:03:19 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/28] target/i386: Convert do_xrstor_* to X86Access Date: Mon, 8 Apr 2024 19:02:45 -1000 Message-Id: <20240409050302.1523277-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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_xrstor is now fully converted. 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 82a041f4bf..883002dc22 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2799,8 +2799,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) { @@ -2810,8 +2811,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); } } @@ -2831,29 +2832,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) @@ -2891,6 +2895,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; @@ -2904,7 +2909,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. */ @@ -2923,14 +2931,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) { @@ -2952,14 +2963,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)); @@ -2968,7 +2979,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)); } @@ -2977,7 +2988,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 Tue Apr 9 05:02:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787183 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57680wrs; Mon, 8 Apr 2024 22:06:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUd+OiNWSf9plHIHQS6SjpWhM3UIorBJ+1fe6ekZfRulGDr+FA5A7UAx48DTZDeBCv5ked3YFXdOOY4vWQfszoH X-Google-Smtp-Source: AGHT+IFmut5TuU0qTep2/5qgFV26rDVuAbOa7sN7D5vUOf6gwk/kBNiCj279pFDE5uTknO/s3Ge+ X-Received: by 2002:a37:e20d:0:b0:78d:627e:1aaf with SMTP id g13-20020a37e20d000000b0078d627e1aafmr2532597qki.31.1712639184437; Mon, 08 Apr 2024 22:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639184; cv=none; d=google.com; s=arc-20160816; b=JZGWYqruqGt7BBGg7xu3cQu05m7m5j/PdNeUKN/XRq2URfR3wu/Fnaz9DmECiwwQyE asb9V4RyhojTIvZWfc1dUU3gCL/lBS1TRXM4FvjdV3EkRwUt/jaZHUMYJspaJKKXdTS6 RH9IntG1oEm13OFZL7eM2KWl16IuhtoP1cg4Wa5++PspO92CextWFI/YqMCFtPigTo/i ZMaCSfh7O0ZtTyq0MitNSugTdoIdyjX0EE/vU+8r1KVC4xJFmNJ5Fzt0lPjHOyLk1ua+ X7b60fouCsSqiMkfk7cbZh7cSDK09r/NGe+3zExKtl0FPytmTbKMjgg1PC8BRy/nauNS SYZA== 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:to:from :dkim-signature; bh=n9BYI6TKWEdafNRUeJOtLO8qVCbGTQ3duCoyIptUdsw=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=JkNeBmMbBchVrzRFzYVI0J3QBoUGnSu5Cxwt2i2wmZ2jKveqezshaYNPc6WRbS2CAU 47uGhUqtjPlwzQg9mXRlHsMeEF7swPZ+xFDxo2zTzyhCGaoDpdDBRJcdKpnoFvd0S9Sm l6YQB/o+WV2JzTU20xxXPDP3K1UDsQuUiOTkzFmmSksw8o0Zvaufig+FIKpFi29FCAam a+eq2VKKlRzylb2uso365EAlFeInraVGWQF+l9d3H2AysrLubhaZ0npd4ofXgPqyAJ2Q pkvA93TTxa9Xz4H2/rri95VFrUvzBbapKRvyaDIoflU8+WkcWXLhJVY9lnujxIhW1EOj m8og==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XRfAPaDy; 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 s15-20020a05620a030f00b0078d64240769si4199046qkm.420.2024.04.08.22.06.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06:24 -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=XRfAPaDy; 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 1ru3dl-0003Ad-NL; Tue, 09 Apr 2024 01:03:25 -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 1ru3dj-00039t-J4 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:23 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dh-0005H9-WD for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:23 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6ecfeefe94cso2519148b3a.0 for ; Mon, 08 Apr 2024 22:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639000; x=1713243800; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=n9BYI6TKWEdafNRUeJOtLO8qVCbGTQ3duCoyIptUdsw=; b=XRfAPaDyPLPUtLWx22HTpVkFvyaX36EqRJHHVIRtaF9GKxvcyog96WM4JC0PI7bNjL AO1IgsspI96Bj1ze3ayi3TAdYY9qst50GDgF51cAFDVyR4XbRftS/HDZ55bBlyHw9vtl 6iIVly597Bvcc4ZVrUHyvZf74oWsNipymM/lUtUJZ/QhrPEcuQgJe8MLHa/7xqkRgoMk SJPKH6s60SW449EQlXjr37Rk3RQVT+0p5+XYeiDW9Q9Rl3FrTzn/yLshV5RP3xiRrigk 8YBCwnMQoB/HzFQCpZX++BgemmMvPuGH82iHmaDhCy5gaCO5JhQy2ABXXA2XGldimTSg n72A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639000; x=1713243800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n9BYI6TKWEdafNRUeJOtLO8qVCbGTQ3duCoyIptUdsw=; b=TNc5cJ9dXF9kxl7i3waiq3sJUJbZ3TrjrQ3vQpxeFrPKdkaUfQ0Nv2ORG1xAL+33e/ jEVR1QZ/zymNuRkfSVhRq6+awJp4oanMnJHKtXsJuxbv+v/4lu2GoCaL56K9sHFUYtUg d1rJ3ThCn1hjgqIF2/aSVGJM3DBG9heZjXVMmd9GHtm22APqDnnqvV2tbeujV2VjLX2C gxz1cnobp1fVpUPJjL2viZiWHhlsSU+fTY0eg1RleNiU1fEr90IM85abtSMLlUwhNNEC WKaPEHw/8A4+PPyFNW+BlVcq3srZ6viV2AkO0uY3X8WU1oEbYrxX47PAmraDzbdluvAL Noqw== X-Gm-Message-State: AOJu0YzP3YOcaVCu2YVuzv3zLt6HS5BgnrC2rzXEKKmEQ7x7duhfQt6p HNVsnBXv4LiQ7HS0gP4tvgXVHeBCcgBnT5Ngh0PVyzIYwqK61BG0sZQ8F4M7yt5DKJG5X+s9s5h n X-Received: by 2002:a05:6a00:4684:b0:6ed:e1c:1038 with SMTP id de4-20020a056a00468400b006ed0e1c1038mr1688454pfb.7.1712639000500; Mon, 08 Apr 2024 22:03:20 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 12/28] target/i386: Split out do_xsave_chk Date: Mon, 8 Apr 2024 19:02:46 -1000 Message-Id: <20240409050302.1523277-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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. 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 883002dc22..11c60152de 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2674,16 +2674,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; @@ -2720,15 +2710,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) @@ -2899,16 +2909,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); @@ -3003,7 +3003,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 Tue Apr 9 05:02:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787185 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57739wrs; Mon, 8 Apr 2024 22:06:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV+Vksd7NH7FLKTxKetb+CPuFa2n+1FV08TlADMI6It3BRReNJeyovAHMH4TgrVN9XPLgkrNfJ0b/+F5u+s1Od1 X-Google-Smtp-Source: AGHT+IH+B3gowr3jKZRxXpFcRbGQTY7wqxHBdAsows7xC/QOVk6HdIpOd9m/LZVsbC2jUivwq4G8 X-Received: by 2002:a05:6214:2387:b0:699:2443:bcea with SMTP id fw7-20020a056214238700b006992443bceamr9140171qvb.22.1712639195671; Mon, 08 Apr 2024 22:06:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639195; cv=none; d=google.com; s=arc-20160816; b=iWv6bApCm69nf+YSrVjmunxM3Xg8D86HWqFUIz2lV8F7+hLG1LTiItIye6z5irwlYx 7Ma1BSVhjhrWEppXLvXdWlgy/nt2oqudWlgYqgR10o1AfsdDW3au//cf2+fYqSqW3aly gmv4xffFlUzsBvAc9VJwfy2hmhCgOLS2OaVidKR7AreVH4akqF0JnL54mHyXCZeSQP1k hvK+OQ6sQuOOVuVLxbMe7oPtBV3PoEBd8Q1G4Ss9+AIYNvY3j4RSN0VPbjb9Vkyv163u vz3cgGTxEbKQEs6f6x/RjtbGx5rmj+XmouoBtfKntfhGDutGmgcOyVQqt7vCkSLCWSNn 6Q+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:to:from :dkim-signature; bh=ty9Kcl8q8mjC0qYnkE9obh2ntk7k/Zh+tnhaLzpayq8=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=VR3fIM0yYX5X3SZNKKEYVokYYTO466Aab0rji5XO4/NhjsxSMxp/NJqu3h04WlwJwc ov3uXb0joY5WHnmwwG1gKP9EhPo+43OiXmRHw4BCjIGVr5WVFWdtx93KJCn/h4Ko5X+9 hBjvt3kYoxzGDvRTzabUK2eV64NF/xQTwxnt75miaEIuaeSl48NZEXPu/iSDz5dTLep1 /MvO3S+vVBgFtI7rRfdNMcnRhGHFUjJP89O6UQ10ix6IbNZ47AAHGZbHzEPP18QBqhEt Y575LYweJIU7scNZtc0gR+stfLSkjiPQ7LdGMrBSdUT6C0J48Xry3R6gJisWQI8CTUwd H88A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Fo5sIzc0; 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 p5-20020a05621415c500b00696b0e4b287si9413954qvz.477.2024.04.08.22.06.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06:35 -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=Fo5sIzc0; 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 1ru3dn-0003BF-Ge; Tue, 09 Apr 2024 01:03:27 -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 1ru3dl-0003AJ-EI for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:25 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3di-0005Hi-SK for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:24 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3c38eced701so3051323b6e.1 for ; Mon, 08 Apr 2024 22:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639002; x=1713243802; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ty9Kcl8q8mjC0qYnkE9obh2ntk7k/Zh+tnhaLzpayq8=; b=Fo5sIzc0m1hhRYeo/htBiT9QnnlUxgrENlSwQjmQdNFBdt1pdVXyj8ZHKep8RZU4OB NyudmFqHM6cMZcJz4oBLnUC02/VYsdmdw0P5ioEqN8mnG2no1I9VoanYtEG0aRoBqoIQ JrgkGxuMgRa77b5PbF1TNccfT7sNSlAUKOhrh2t7a5V4xluHewuOeQ97L9DmN9U+YpyK VQJKOXBmvedtMVrVlqVx1VZ4QQuEE9YP9BbQVlQEsRV44rbwpJNAES/Ia0ghJfB0ynJ+ OI6afWgKjMv7uG/v5hcTiIhO+6FJy+WVBVvEIW8glJRuwGQf+vrXXk2EF4AvSYmiskGQ Sz6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639002; x=1713243802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ty9Kcl8q8mjC0qYnkE9obh2ntk7k/Zh+tnhaLzpayq8=; b=jQODh7N36XhAsUJqbZRRWk46tumd8ca2JaNDxerCjafhZzLfakC7G0HuoUqVKgXTy5 eVMFHT01iAvA329IX18WxG6vXHMzRetCeIJK33EmImEZhynER0w/+/F4o7ak8aL2zBPM 08WpL39bNRB0D/V+ho0mtlyEKwEgrkAjxHhyC3hXGt3aSokbYS5dsMd1RMUFPeeWzXQ2 b9cFQcD2dTAuuy2mzhUpxlgp1uCqhFSY6cw/A7D/40lkXWPWLurnqdOi+bJqzT8LXNE3 LP5WD8aDiiD5g9EsPm/AOv0d/5+kM4rujQveqAl3JbqXdG/WYhV2aX3ETtAV43zRxI4o cpGw== X-Gm-Message-State: AOJu0YxfNaqVrtjACd7OCwtqC4lwDLwYFRzMDbAepV7aj+dERMnNbpEd IVPwnjO6/J6V4N1w2Tx+WW2drfQngj/VfwAXyDKnnqS7OPeRWYmtYPpW0wwXZAvsZPA94GTAdo0 E X-Received: by 2002:a05:6808:13c6:b0:3c3:c17b:9e0 with SMTP id d6-20020a05680813c600b003c3c17b09e0mr14005822oiw.49.1712639001814; Mon, 08 Apr 2024 22:03:21 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/28] target/i386: Add rbfm argument to cpu_x86_{xsave, xrstor} Date: Mon, 8 Apr 2024 19:02:47 -1000 Message-Id: <20240409050302.1523277-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22b.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. 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 6b05738079..5860acb0c3 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2223,8 +2223,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 cfe70fc5cf..68659fa1db 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -267,7 +267,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); @@ -568,7 +568,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 11c60152de..dbc1e5d8dd 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3046,14 +3046,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 Tue Apr 9 05:02:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787164 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57026wrs; Mon, 8 Apr 2024 22:04:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX3tQplB4j4fODL768iUNs/v0TXFSP1s5y3NtYfY4KH2XAELrCehbfZ7VCdzJTIzn1qrVTsXTch0m9E/0xSelO9 X-Google-Smtp-Source: AGHT+IG88QqF25aG/6r3lh57ZxNdBieShnFdbJ7iRGQpc6SHNXfC4BZiD798/QlSmjqGweGpTLZp X-Received: by 2002:a05:620a:372a:b0:78d:696d:6b9b with SMTP id de42-20020a05620a372a00b0078d696d6b9bmr4187210qkb.29.1712639043325; Mon, 08 Apr 2024 22:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639043; cv=none; d=google.com; s=arc-20160816; b=vpVwJorVdAYaOv74j/YIwDlea8I3qP0ERDnv/RzL24dRTDkc8lH7v0pwRp6dlVjWzU KhnwLpnVCweN7UZ1AsxBLAJ7vq522JAqO4IexRUx1vVo71B8sw9tM7JO9POm0oGyyj26 Ol9G4MOqr7+p4Q2VboszMiP7+8wV6f0MasDuXvS0o8OJQg7s8Tlv59dmt1y9MXWpB8L5 MYV006Zkd84b+0SEjGGAZtVQk/3TdsPO7mE7d0HD6Wdn8MQEvGpxfiDS8sjDL51pgCo/ q/5UVS6GKz4WYxBngeDq1pqqA+wD0iRm1u2Pvc4JKrZ6Z0WDUBz2f8ulgO0lV3vkp3SA knEA== 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:to:from :dkim-signature; bh=QdlWMWgnGp4nnm6wecPBCmGBGP6RpnH+ptC3EDh4jQk=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=Jsr6XB/nf80GdArti7TBgpAU2DTD+jkTGzjj5LUb+wQhoy4ZWVxLg0/pxOrxDdn0U/ fnbRRdPReMiJGzvaqvst7xndIrHsxIPgnWONOtAKOJJUuVko0u952P/qoh4sAGT9MSzt 8wTKpkzaD9gmexklhi1EFOU2MAe0rTqtP+s2AAozHSSu6hf91j9peguOZyePL3zKtiTU YbE5sVXAGoE+PnwXCz2lx2YEMLTguK+XkYjcOZnL6YUB687XX+/kj7swuhgNSX8nAWBi 2hTLjQrLX6m/secjkJsKs+JHGrgbG1QdSoQY10wXCGnqoZY2y/48PgruKa7AsRZMA5xe ciNA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Ol7HKID2; 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 v21-20020a05620a123500b0078d60855e5dsi5629676qkj.709.2024.04.08.22.04.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:04:03 -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=Ol7HKID2; 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 1ru3dp-0003CB-Mq; Tue, 09 Apr 2024 01:03:29 -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 1ru3dm-0003Ah-EN for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:26 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dk-0005Ia-RT for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:26 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ed0938cd1dso3148137b3a.2 for ; Mon, 08 Apr 2024 22:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639003; x=1713243803; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QdlWMWgnGp4nnm6wecPBCmGBGP6RpnH+ptC3EDh4jQk=; b=Ol7HKID2WkaGoMSBXbMMflP/AN2JZhIYhPFU1Gu3ZSCbgDdR5fuT0aPMKoKxHeBV0y g2OyLYKkyi078ttj30SqFHqoUV2sC35jZAN+PVGJELvdPnpJCqfEkf/tqXFMjpwFUfWQ Vxsg0F93dSRlLU66UVxooINTyPsLysdgzWYD9nDcMiIDsJcPzFaaTxGTGPtxkqsk9D6E vz9x6d2V7Oh9Q/pt5SV+cRTpMGTAJ1ChkcPN5JtwO9kw1Js3s2iaBV+1YkH03IDeKbiJ tW6IF+LQ1pvV6Xke1mo9kbPzvpnpL+6tdxZoMJQ1EOzEjI391xR0/wSrsZtpl7V+MAi5 25fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639003; x=1713243803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QdlWMWgnGp4nnm6wecPBCmGBGP6RpnH+ptC3EDh4jQk=; b=DgvnUsXMM2QYbI4E2LayDNiS11X+gZXDp8WfacfKx5zmmeuQxzLIvkRhF5lEHyBKIw ACvnvtmb5P8JoNWWeZMCRDJIezlDZ+yZAPHhOXd/So4hOQgSjs4vT2RNi2xu9cNoFtRG ukYNrO+rAGopWc/nDjpMVhdbIsHc3jTrCPv47DASYfWSu47aDAUj+Td4712f3xqZ+lo1 Dht17hwVvfvZU5Hba3IjXFlYKlNbRIT9CT0YfZKDwxNkJqFhs02BDlUD9GM8opNH9pG4 D4jJT1llIzqOh01prmNSMTpgqOB/wq/izd0Gks2MN8opEO7h/ql+Vpi4taem//kEYUXo j9Zw== X-Gm-Message-State: AOJu0YxRupx6eCTGuftRGLCjT4Smbw4zXoiFJE/oHb+T8cfHBXnJIkSl l+0x9OfgHOHccTfyNJpmrDepR1GU8fpYwEQ0WukxOpRJ6IV2+aD1vnw4Zmmxf3THymnobunlshS 5 X-Received: by 2002:a05:6a00:3d44:b0:6ea:bf1c:9dfd with SMTP id lp4-20020a056a003d4400b006eabf1c9dfdmr14465987pfb.27.1712639003022; Mon, 08 Apr 2024 22:03:23 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/28] target/i386: Add {hw, sw}_reserved to X86LegacyXSaveArea Date: Mon, 8 Apr 2024 19:02:48 -1000 Message-Id: <20240409050302.1523277-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.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. 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 5860acb0c3..5f9c420084 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1419,23 +1419,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 Tue Apr 9 05:02:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787174 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57404wrs; Mon, 8 Apr 2024 22:05:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXE6W49BPPttUYaOByMo/k2w/eeY3qqjiqPuqAtWc+cd7lgRgihw6I4ptwO9z2Fagi8pkBi4gVKLSCDjQF1R16s X-Google-Smtp-Source: AGHT+IEdus4QyYGvohQ6nR3FN1rLV+Plzz07xEFP0UNbzhcZZLSsMCV2DRFjACtR9wL06Vprg42C X-Received: by 2002:a05:620a:12f8:b0:78d:68d6:c1e9 with SMTP id f24-20020a05620a12f800b0078d68d6c1e9mr3163133qkl.47.1712639127656; Mon, 08 Apr 2024 22:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639127; cv=none; d=google.com; s=arc-20160816; b=Z7KFIV3uBQS5Ve11r5MKfwpCYisBgBCjlKiT6TJd0DuRChDKUKwKmzUUDVRUED4ljv P/dVORD1ULvC1xJyR6WrdNFnc4ByhnFf1mLu02QNh2dIHUJzSlrS6yZuhDo3ZjgGpEO4 Tzd9EDuvBj/ERUtVxtzc7Ll5GdTWtnh9gZ4Lli/m8SAfrNjM9wF0jG/cEe78uKUVMSK6 hfYhTLkv/LWKi0CqEHioHKeGub16YIbFwYn92UKKlKnnoU+QsNaQ4TshjbK4tmoUjIIH kKtMEvs/PWYn8Q5k6KnCqwBxThghpuwfI1nnE67ZiWet4H0s9/JOTi2Ob+zFV/WKa11T L6Qw== 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:to:from :dkim-signature; bh=6eUFt2PWahbI/Q/BaP9MYWhwnfohtu4MmJvBHxZyZEg=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=RcCbmj2n+bppaSgATeyoIpPJ9XV1P0xXhyVAu8kNqPOKkRA8Wid1OaWbBuFv7SJQIn NWBHTt72cFX3+mu3N1Ov2kfZENnaksop6AdjixX+toLjOv/EEq8GdwQ7pO+1UUYZp+AA vErTHieg7nPNBNRXbpUqkxXGsftpkjev8/LrIDnGdhJ2dj7Ra/dTGIsSK80G0HwDW5QU oz50w/xPK3QTmt0HP1UGwda/FJw6z22/93X+27ijKPhs5tfxOCKlnDzIO1YGgi4QeotX X6ZtO48rQems2uH/7yFQ6wINxzPcBs8CFHhD0zr4fc4E6RX+v5E54cUCNqn8HIR+NfzT ss7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rsZ02lZZ; 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 a15-20020a05620a16cf00b0078d666019c2si3525091qkn.555.2024.04.08.22.05.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:27 -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=rsZ02lZZ; 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 1ru3do-0003BK-1G; Tue, 09 Apr 2024 01:03:28 -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 1ru3dn-0003BA-9y for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:27 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dl-0005J1-Nc for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:27 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ed20fb620fso1747930b3a.2 for ; Mon, 08 Apr 2024 22:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639004; x=1713243804; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6eUFt2PWahbI/Q/BaP9MYWhwnfohtu4MmJvBHxZyZEg=; b=rsZ02lZZmNmC6hZQ53L05GcpCHmXoK5xrN2CrOPrhqR0DCKdnhUsg0SVGFGrRaxe/m JUF8Kh5PUd6yYZ4WgVRgFFYGocPMevD0Dqc5/m8zlWIdE78OcOVTuZ6QdzSEydE0jTS2 n0sX/cgSVoJjC97k4Cq1BdAoOxCmZ5zGRy5H+GDXuXjlTV8HKW40kYyg/JGNfCik+9Fa wh8mcbpJwLdDbqkTXskuY069t9B77W69zh3RJI6E97rLt0aU6Ez/sfHHVaQgY9LAfAER 3I6RworKQ3zCUyJGVgkqrXnUqivgqVvhD/OmiQ0XMT3u9SCN/tlWNIk38ACS85e6/emP SU3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639004; x=1713243804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6eUFt2PWahbI/Q/BaP9MYWhwnfohtu4MmJvBHxZyZEg=; b=XsyB7ph31jfMWugUuqTkAWkX+MXjNP2oG+sLDMZgmEgCsksyDVmXZU2wWgB7EdAWD1 Y0yU13sEu/0rTj/1CsHyMpyP493enPNnT63WULC6fVOQQU9c51gQuxTz9yp41IltWIK/ Xe2ko41AYL9BX5rg3nmxfCNQQH8H1OcNY2d29vGOBuS91NKmcZHoiEPn1XgGPDLZKpcW oEVocs7lj+ySP+JDnLgWHuDM4sqh0bp4b30LgJkkXnQI9swIGKzswQgL3La6RI5wOZov klHWdTjm8oLgKDJUOtP2FhPDXmWsiLY2LSAx+xfgD9n1/wuY5TpFoj2pXkUAvo9S34Fk 8dBA== X-Gm-Message-State: AOJu0YxOGzgkxZWYYUyCtUPPXSHvmoOEYdI1SfPmRXZ5uKCMmXwoPrlo TTjq1oX518WY6rmqwU+hoQ/FxSn44uaD4wqq0wLYaFi2rGxaaEHpvQJRkIJ2FkMOhifTFLkLN6G A X-Received: by 2002:a05:6a00:c86:b0:6ea:b9a1:63d7 with SMTP id a6-20020a056a000c8600b006eab9a163d7mr12510999pfv.10.1712639004231; Mon, 08 Apr 2024 22:03:24 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 15/28] linux-user/i386: Drop xfeatures_size from sigcontext arithmetic Date: Mon, 8 Apr 2024 19:02:49 -1000 Message-Id: <20240409050302.1523277-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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. 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 68659fa1db..547c7cc685 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -252,7 +252,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 @@ -272,7 +271,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)); } } @@ -558,7 +558,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 && @@ -567,7 +566,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 Tue Apr 9 05:02:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787179 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57483wrs; Mon, 8 Apr 2024 22:05:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVWhvjBez5qGC+EzjCkElQgwrmvdc9ZrF0DQcucGxRgPjT7UW1lFqy25x6tzMbL7925dmE1mKpe8hNmNGu3Aaei X-Google-Smtp-Source: AGHT+IGIT5DjvtjWU5qHJi32sArRixdsoHGjv1ONYLZHlm+WwjGbi10sSeDViuoGbz02tU3DqmUJ X-Received: by 2002:a05:620a:3708:b0:78a:f3:34eb with SMTP id de8-20020a05620a370800b0078a00f334ebmr12566050qkb.23.1712639145739; Mon, 08 Apr 2024 22:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639145; cv=none; d=google.com; s=arc-20160816; b=bLsNIdGmFyOAyTEitEHLmBvLeQTmOyLcC0RTFERuLH4WFil4G/74DRoXNdY8qS9f+R IlnuTinJeNBhdYi2ynEdzNj49f7CGNRbXWKkig14WBPqc0N31BLKiv+tfx+siHBbeh6K HvRkNhajAL82SCQoitDLXAHGR5Bso4MQWKA7dpUWE/UkP3fqoZn09I9fJQGmdGfIVRgR NClM2ma0clpNZj752lw+2Z9tf/rxEHhkM/xig4moHnjhCjWvIPwpwneyqxmhHZkDgEZo uc3PSQ0oh9R33nJHcLYrB7g7sHhbKZ6MwNgFArkxzuGibEv1eZefb811B0V9HR75UXQf vOHg== 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:to:from :dkim-signature; bh=N8gp+LNEKmu7cGCLf0zC8bqAS5Tm3qcAiz5MWMTkDck=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=NIsScmgacWyNUfHSHiRfjgvUQKaskZ2L7pImfdHPIR+JFHSf88zvzuk0lpEgGb+oGt OzcDc80H78PhXxH65UAEPWp53HwsagxAglRv4TRITWAu+AcUUvJpqHGlX3WthnsGdEhe HJO33o32lPShTzp0GWC1GzdaixHuSHunXBaF8Tg4mZgMYsHgtelW4UTY9xgvI6VlkD3m 3edBeh1+47+ksmNPznNfzhBWSy723/LnMSBsyzBGbUT7rhorHvLXrfqLEmSl0QYVtZ74 StYXVJH60eHHrpkaGbqCAd2bSpC3d3uEnhrPEUV0mpRw1TQidIPx7VXldjiXcWNdKLod 6htQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZojU6IOE; 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 wk15-20020a05620a578f00b0078d6349faf2si4417186qkn.338.2024.04.08.22.05.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:45 -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=ZojU6IOE; 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 1ru3dq-0003CM-AE; Tue, 09 Apr 2024 01:03:30 -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 1ru3do-0003BL-F4 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:28 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dm-0005JL-SH for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:28 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6ecc9f0bdaaso3638709b3a.1 for ; Mon, 08 Apr 2024 22:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639005; x=1713243805; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=N8gp+LNEKmu7cGCLf0zC8bqAS5Tm3qcAiz5MWMTkDck=; b=ZojU6IOETqP78QiVsHkLT+VKs4ymZ1qa+QnpG7DHKTJABpC0r/McU+d0uG3Y0jEmJ3 Pq9PbO/iNpKnb4DQIeHA+zFUKYRhr470BCWZ/lfl+xY2YY02s0dRVxgk0ALJ7wHUizyC ZmR5NAPyzmLNK2v1xlBG1tp/6QgfeB4zHlaLeUEJsUtg9/3e7NwWr3CE3VqAW4dYEJmg 7O36i4Rau6Hc2NvTBTsTt/xQV6IsXV2no1AW89i6LCMmk9HqUJTvYAOKBGc5WAKY+ol7 mpVKdY9XyYGqZAMTC79AdK16xyNk1ByHXUC8NEUyTLQ9CLNHO4f4QY5DNzTn+HgBYeKH FXsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639005; x=1713243805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N8gp+LNEKmu7cGCLf0zC8bqAS5Tm3qcAiz5MWMTkDck=; b=kbTAgvMgdzfXrZEuCWfLaqWCd9Knq+zJpV4SuD5UqHf2NlejU9WkxqB+JSDw9MG1mM 7MV08dkSv/j6dQqHHUXasbWMj8JE+IJ3rkJVjAlmt1l1Ks75j5cr5zVtkdnSpb1mHODl YWLcpsWbpRFg3FPMuXnDAuSUcGQELeaMPqHZwlSS/JfDqW7/iJTa1LidhJUcV71rSlzx 3az34ErFbvPdfhoLr/YqLJMUcCVi5luXS6R5Z34x0qU8e43k8UVSibDSHaxU8/gQyFV+ hBl2N8LXI077oc3377mwLdhck0ZAmBcGhtOCC3vdh1ztXuyp7qMXivi5uQIw+BWd76yB 5C/Q== X-Gm-Message-State: AOJu0YyvNOh7DCFpnMj46FAYnmaV6CuYqc1jlqxx/3nuoIU8mqVyOYsh CRNDzXeyM0HtGKrinV7PNSXecOeuNOLrvFbalin+et3bTUW8F5MABZToKfS4MAK46oAdp7gwLSR K X-Received: by 2002:a05:6a00:c8b:b0:6ea:e2ed:497d with SMTP id a11-20020a056a000c8b00b006eae2ed497dmr10312574pfv.19.1712639005339; Mon, 08 Apr 2024 22:03:25 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 16/28] linux-user/i386: Remove xfeatures from target_fpstate_fxsave Date: Mon, 8 Apr 2024 19:02:50 -1000 Message-Id: <20240409050302.1523277-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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 easily computed by advancing past the structure. At the same time, replace the magic number "64". 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 547c7cc685..a4748b743d 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -66,7 +66,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); @@ -265,7 +264,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 Tue Apr 9 05:02:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787189 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57908wrs; Mon, 8 Apr 2024 22:07:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUgjkzN/pqENrMokPutZ0UtQ6FtWT++qmwldZgf2f9L+SvWhqCsMKexj4JbWaFIipVEMI6D8QWBcG/f6yG8ihNH X-Google-Smtp-Source: AGHT+IEi74DmUFWfOBOThePlLgRuRWhJrvhZTOb+nlMsrR++5qqFwg2pY6x09uhr8Vi7DLrtC+IA X-Received: by 2002:a05:6214:1243:b0:699:2e62:4115 with SMTP id r3-20020a056214124300b006992e624115mr12518549qvv.23.1712639225540; Mon, 08 Apr 2024 22:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639225; cv=none; d=google.com; s=arc-20160816; b=eAN3lH51EXtSBdNDEvgf4nOPCK4efAeiqAGBfZ0qjw9B8PoUjs1rpVOx0+M+T5bqC/ GGThtKhGH2IDGEqFPYRiFTxxDyKBbHOnmUy1ck9oik7kXDgbvLSSTyHhK5tTxLsfeBGL X577h7KZ1viIBvFsQtTd09BXcQWcR0xEJHYz93mhokYZO0cq6kgud+pKkOCKRkvr1H98 9Klpo32bCfS4jaD0/f+zROYyr3LsbpS8gz2Fi+OJqk5AftLmYu5XKQLQBaXxY+pEkLjG ssTrrNhPiJxPVANZnHvK7+pZq03Re1JOYKpYZjDdGoU8A/XDCzpCTTbQ5Yf9/C7YM/Fj USLA== 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:to:from :dkim-signature; bh=sAutoO51T8yiouPWosWlBYNCYdh90GN9jDKu8ChGAKw=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=Z/WbTWDOpEUPyQSsFgYeqiDDgI0W9e9PjFXVUXLJJ/9GdShYVcAKtOl7S2VxL3jmP0 2bpu9h7UX4ATZCNpmswXyHf+mHPIRPOMn1Ag7xLwksx5JSaO7A23ZdBZf1U+tXcY19PE z6GVLVJtSB4M9qUNpfMxswkR39gxcRnIVRAWdiuKJHlMxpoCrk2vrTaLjG6/GlNIRRV9 KFSKf/D2mKAMm5ezascFeAVatYTAL0Myu/zBmDs3YcKVdPxfSyAvzwITq4nQJgZ9eEri c2WAIxaUdQgh7wdkt1T7kabKNa5ZuenA3eY0iBxGL4Fze5a76MWMeB4RtiKINSZgVtRE a/qA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ulDFlVIZ; 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 b17-20020ad45191000000b0069b1dd3261csi3119984qvp.91.2024.04.08.22.07.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:07:05 -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=ulDFlVIZ; 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 1ru3dr-0003CW-3O; Tue, 09 Apr 2024 01:03:31 -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 1ru3dp-0003CD-S7 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:29 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dn-0005Jf-Vd for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:29 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6ead4093f85so4257062b3a.3 for ; Mon, 08 Apr 2024 22:03:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639006; x=1713243806; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sAutoO51T8yiouPWosWlBYNCYdh90GN9jDKu8ChGAKw=; b=ulDFlVIZ77FV+0lanQXRDy9fpzQC4QcXNhKnNt0MTC3FxlZcoKz0dX+FdReUIwZtF6 rXeGZJiuKP0VWMQcXrVChcan4DK4gutPoQH62t7W4P4c+b35Uof7fds4mcMIw4bxYBl7 RilMKU+4uo7YxczC1jwF9nzxFcIJwCR3gryeBWtjLVrqLRp+2DH1+SDue2OOKJIdFjjo G4E74Ljize9OMrM/0wW2YYHjg4QR2fT68fCCGhQ7ukkbBElQw7T9grOawgkZllJovEPs T6jZqxmMgPXy/yGku8J1kBrMXgQ7FPszlQpgWa/vxz4UgPMPlTMasznRL1+FyxtNjpAK XAww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639006; x=1713243806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sAutoO51T8yiouPWosWlBYNCYdh90GN9jDKu8ChGAKw=; b=Vw1dirOUdvZ57Xmmth/3GJ6m3/Dlq2srZ5ZAyiq6Mdhc+VpzlFolMz1x4P1NmvmnVG gTdhBhhngPjLIy8RlcBl4d9TcxwVhvVZW9WWrHGAwzrK5MC1CXfz2yjWBlTsZ22TLE0y 88JE35apqb1+5SeRf+giiuY6lhAvcp61trI6MukPN/WIegTmLAprcPVmqZFN1qGydJGs BCl3/4j3mSzHgP8HakiobEi5jP9lHz3tTNCGCOU2yryo4pXaTAJFmKGu0efbP6C2GNr9 OYiDeGo0kPuuViAj+KTxnWEhTXnEMnsI/XDO0sI63pz8JH6d5n+t9DCcKh4vfKs0BxaM TXXA== X-Gm-Message-State: AOJu0YznabxMBbA4KBa3/4KfmLFpDjz5FlEuzpQlsqkZo+GjEbVgbmrk W3QCUMomWWUb7t2fF4R3OXS1oxMIhey+UDQ/dAV1Im4H4vWK86YNcau5KHKvmblF71aakrYIJg9 Y X-Received: by 2002:a05:6a00:2191:b0:6ed:5f66:602 with SMTP id h17-20020a056a00219100b006ed5f660602mr2923950pfi.9.1712639006439; Mon, 08 Apr 2024 22:03:26 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/28] linux-user/i386: Replace target_fpstate_fxsave with X86LegacyXSaveArea Date: Mon, 8 Apr 2024 19:02:51 -1000 Message-Id: <20240409050302.1523277-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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. 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 a4748b743d..ed98b4d073 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -33,16 +33,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; @@ -52,25 +42,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; @@ -83,7 +54,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; }; /* @@ -96,7 +67,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 @@ -240,15 +211,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); @@ -266,10 +239,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)); } @@ -383,9 +356,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; @@ -551,21 +524,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 Tue Apr 9 05:02:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787191 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57950wrs; Mon, 8 Apr 2024 22:07:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVfnOF58YVMrpKBRNXcIJ0+z9T7P6boP2DUxsh8ZOTlnB6nx/6ouZjg0xJRcopDo+pQmaAQRo2+gltksiDKsQHl X-Google-Smtp-Source: AGHT+IEmKDpbpBjgfj4BenGWlwg5E7H3Il/ZQb494u3JU/e5h5MFBFi+feNeeihKycWyEzwcCuwl X-Received: by 2002:a25:d001:0:b0:de0:d7dc:8dcf with SMTP id h1-20020a25d001000000b00de0d7dc8dcfmr7462089ybg.56.1712639233739; Mon, 08 Apr 2024 22:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639233; cv=none; d=google.com; s=arc-20160816; b=Poyft2OoKRi0oC8DLnjDdLrEQzOg7ypq6ii67m1yjAIyKkNbqRxfZ5fawfsLOCWGJf AOQe9eL4j0TDlILtVLDDH87nddS7Rje0KxctOPRZliDSTAPuMxskuW/0PSmSlaEFrace E6sMEmBX8VNdIRIdkAqHslAaQNoEqwspunv+CeyIdcem4N+qWZP3g/QyC4096D5KLnWr ZIa2fywiVFiTewWFDiGEdEV1vGsKHSdC4cv2oFoifST3B+LhkGIYntF5Aw5ugd9R/lWq D3QZ4lgKGVfDOQgxEM9TPsysytnEWPTF41ZPc+IsI7nWZFJorIifiZKx6QcvKBAZhfzC a+Aw== 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:to:from :dkim-signature; bh=lfYCgXuXxRvNB6GamBg7nUp4jaKTlVTiooGSAkryLH8=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=pPvkkUrF8H0Oa7XtLedvZ7hSdkX2s/5qe2D1TBawPcGLGWXpGFE9ZZnEEIeEKzjTkI CW+l1T4RL6EaIdGzgATwNqRrqclrVQ+iWF/CcjPXYMIPgJn3eH9s6BagzqMO61LgZfQq irpAq2BqcDKVcZaBLCE8eg5TDj02bPI5IZfa+RnAhNHF8u8van+V0A/4tcxtIaJF9da9 Z5TbeXVuD+bcKUPHSts1XEP+yzqBmAgbwQlerYaqtp6dyzxb2BF4RTl9ITO4vbweoIUg 6GbA6BzNOYH3H/BmxsH4s5OWVCQvi1WulKyYICdlxORbq6LsPy/ndt2AK+YODUHmefmh 76Jw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lqnqz0Ue; 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 m6-20020a05622a118600b0043466716c89si8553522qtk.581.2024.04.08.22.07.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:07:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lqnqz0Ue; 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 1ru3dr-0003CX-Kr; Tue, 09 Apr 2024 01:03:31 -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 1ru3dq-0003CN-EE for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:30 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0: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 1ru3do-0005KD-O9 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:30 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3c5efef980cso303318b6e.2 for ; Mon, 08 Apr 2024 22:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639007; x=1713243807; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=lfYCgXuXxRvNB6GamBg7nUp4jaKTlVTiooGSAkryLH8=; b=lqnqz0UeH9XnkiLJWsRywouGizM1Ym/QZ7H+plEk6CsH0WiUNyE+g7gWpBAwJ6fuDY Uzd7Z+FS4VBvlfAlYV28btvDulNRl3ELaFsirkMI1+b2Y35xCYSzLgFwV72b66rKsniR xGlR/TLjzH/Gq6Q2l8cuJo3JrvOyrE9rflLU9wP38pOPDgwblt87/3bMxrB7hsKgEWlP T0qxG2m1zzEfMVzr8LD3TI+67mypJNs63Z8D/kouzveeJCDKhendENjpjTbRkKytiXmO 1B4b0QFiQ01AHrFUoqFuZ+ZfMmmbGe1+IiEa870884kaQ2JaIabf/RYxFZ0fc2gnfyNE LbYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639007; x=1713243807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lfYCgXuXxRvNB6GamBg7nUp4jaKTlVTiooGSAkryLH8=; b=fzlCmujbWB9gOsGCKmzSbOzC8zJzdHtvGT4OMbuhyQzG+FbUf0HehYHFtqQT6bQF9h v/9PPmKOKKTSWrv1VHIWjw+yK7qqxxci2Hqo/UbRGcVUrRrGJ9dNYMJwxTFQg6wK7ezp z0Ddwy4RKU8ZRkv7s+jIysZ0raSugFweImxbRKJu1gOIk2f53gyDNRLCwEqqJIriur5m X487ZVzTynq4Dp3XARW35WsVQt45BPXG8dCajrHgMIXy88HFCmfCUDdH7sfWji0huVNn eR1MtIQHCFwLYs+N5IJA/4yvOsaJ//+hjY7kRp02jMi/8Vc0p1+zWpRMraTmo8042J2K 0B0w== X-Gm-Message-State: AOJu0YxdfQeJI2HCxu7JjH2/eAobi7fToVln4Dimb90LjjDD3f6TmvVy cu40SW+61MUWFdoYWbsK82vZegH85rDyZHBSYe+lofF42irc9VdFbvTyZy/oVGir6bHsMiIIHdE L X-Received: by 2002:aca:110d:0:b0:3c6:3bc:a686 with SMTP id 13-20020aca110d000000b003c603bca686mr24979oir.17.1712639007568; Mon, 08 Apr 2024 22:03:27 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 18/28] linux-user/i386: Split out struct target_fregs_state Date: Mon, 8 Apr 2024 19:02:52 -1000 Message-Id: <20240409050302.1523277-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-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 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 ed98b4d073..559b63c25b 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -33,6 +33,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; @@ -43,29 +60,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 @@ -278,15 +285,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); @@ -622,7 +629,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 Tue Apr 9 05:02:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787192 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57970wrs; Mon, 8 Apr 2024 22:07:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWkujFRY36rBsdulODYSP7cPwOI+BerMp/wGeWdQdt12y3CUtsqjc1fAwmV6OWCnq5mgcIQkgRiGfhGEUWNb3sK X-Google-Smtp-Source: AGHT+IFUwL20orADl+1Uc6JCC2mcHCw6QMcY8OCTlkHSRPB2EtV6pncKt5oKhiZOqfGu/cjbS+JN X-Received: by 2002:a1f:eecb:0:b0:4d4:1340:df12 with SMTP id m194-20020a1feecb000000b004d41340df12mr7135480vkh.0.1712639236840; Mon, 08 Apr 2024 22:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639236; cv=none; d=google.com; s=arc-20160816; b=BZVe6rO5ZNPL89XC9kOXh4XpqWgw71N1CCWncpk//atpBRY6BIkHVyKOE9+owc/tzr 3cq8tGzFygsN+vqof6l7QMWU9/Dra5JA0z4dx7oBeptEwszohUoHMeyoEjfERaL22KST Nd8MU0GjKJ4CifILO+eJfxLARaPSzpMcRRVlpRqPcYaqbjbfHhcA5q7sXPfhQfPgUi1B FMZuBwzhhHUupTGu7dI8H82k3pFzuvZovO7Zqfzn18m2kot2va3HUuhDevmEprDqPHJx kfFx+hgv/lbVo4j06EtGD7QJqcsq+3srxohMhCUfdkjUDhurEbejgXu0mnEqgqDoOkMT SvLw== 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:to:from :dkim-signature; bh=Lwz2AVaZ4jMxsAZ0LmeafrPRZnLD2nezi1yCURh51Zs=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=O+8O/hdMtpNVsRIBgNCDRexGFNtbSTcXvJgHYftSSJePLBgKoSc1ztPJRJOAz3jNiT 6aM0IFMVf/Jg54SZO9ZjEpinJrlBHrnfgh+LSO5NYApHnfbpJ5F/xn0lm31Dz2oOODUw 3u4ZxX6xhzq3NlCokz3qA5/NaueNyC5P+w/13C53GxAT/TtgmGopIH05X+KQk5V7Ri56 TLCrs/bKzr5BYx50brZ8UnYjl1Sh3nNPWFVjcptwjEH+JbUPlEHYj0fpyNn1ursURw5u NPFmzY5PbiUQfpoxFDaPUHkbJ7/+7oqk7UBNV3XLP31Agld3Re83Acz75pysXnkZI/mj pArQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZZXtMsrM; 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 z2-20020ad44142000000b006992c2d0c66si9644993qvp.458.2024.04.08.22.07.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:07:16 -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=ZZXtMsrM; 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 1ru3dv-0003E9-Py; Tue, 09 Apr 2024 01:03:35 -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 1ru3du-0003DR-Cv for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:34 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dp-0005Kh-Q1 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:34 -0400 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3c60019eecaso73182b6e.0 for ; Mon, 08 Apr 2024 22:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639008; x=1713243808; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Lwz2AVaZ4jMxsAZ0LmeafrPRZnLD2nezi1yCURh51Zs=; b=ZZXtMsrMIMFCRBfcRuYB3Pzyi+O6Fu35oYPgbCQ0oHPfUYAif/kVHhgWYIKaSwgsqv jciv1xGynDGzRAsdM95rrQj7ieGqD7gZQfHHyPv0evcYR6MSAltbcHDvYPhq+xFbydUx Z1nbfE3pBYvJuXGD1HasbSIPITMhCnLT55XTBnMoJEmCdq/QH9de7/Zb7wpUuLdcX9aC h679+VRqYYJgRlm+gIuT497S4+mmZ2btO7g30Z3OPgSfhIemvDl/dOICPyTI86hBmQrs wZ7gJCd1nmthS9D53T3LIEipJYYs7xoPm5g3wEHN54l5DFkUeyplZmw2tadz+SziS6GK 53FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639008; x=1713243808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lwz2AVaZ4jMxsAZ0LmeafrPRZnLD2nezi1yCURh51Zs=; b=LzUcc+0irV0fhmsTyNlb1mxmrpUv/xg6PQr3uVXV4s+QduDoUBVU8P3X3rWFsYQ1Ky DoxejkFagDQCSbVT0SiNVkbIYqrmEoPXIrArMr30CThqcjCORyWbHMWaUgnQGIPPK1FY Z2AUNeRJVWc3LvFZ/Dk0EdJYmoWgTK/cq+Y4d32ptGkI8OoLHhRfsnUCLu82KI1v/8a8 voIWsJZitu5smwzeJgOoCv48z32cwKM1OSzRuiJrum+n6fddV8DlNTTthKerOKifAI+A rpOHoag2kXghXkCWIqKNgi9/kjSGI74+TsZ5f1GTv+PMTM7/0v9u1p6RbhzSgNdYiRKL SAgg== X-Gm-Message-State: AOJu0YwvcoAryWElWVIlkhuIc6iyJwh5Jh3G0cb+ujBGUfvqvAyF8Lzh hi19RfZJo2XJ76QkuBZW7ycadJ7uyz6Y4s+DuG8zAcf6QVepL08lWyuvBNn8rl+5AbhioURY1Z7 y X-Received: by 2002:aca:2313:0:b0:3c5:e553:475a with SMTP id e19-20020aca2313000000b003c5e553475amr7552060oie.45.1712639008712; Mon, 08 Apr 2024 22:03:28 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 19/28] linux-user/i386: Fix -mregparm=3 for signal delivery Date: Mon, 8 Apr 2024 19:02:53 -1000 Message-Id: <20240409050302.1523277-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22d.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 | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 559b63c25b..f8cc0cff07 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -427,6 +427,11 @@ void setup_frame(int sig, struct target_sigaction *ka, env->regs[R_ESP] = frame_addr; env->eip = ka->_sa_handler; + /* Make -mregparm=3 work */ + env->regs[R_EAX] = sig; + 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); @@ -448,9 +453,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; @@ -460,14 +462,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; } @@ -507,9 +501,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 Tue Apr 9 05:02:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787186 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57816wrs; Mon, 8 Apr 2024 22:06:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWWekKVIjhgKzQZCmYk6sZP0uEoOd8StwdToiZCiIrgBFfiAaJtL8ApMUUCEBWPJ2378es5ZiKMcTSt47nM9nmx X-Google-Smtp-Source: AGHT+IFykNwOCRzRdTUHfYqC4Noj0QtuAAJyhGT9/60aQAkWxR2SLR9okHSuW19Fr/1h7AkGs7fK X-Received: by 2002:a05:620a:13f9:b0:78d:6a00:c49e with SMTP id h25-20020a05620a13f900b0078d6a00c49emr3094700qkl.16.1712639208556; Mon, 08 Apr 2024 22:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639208; cv=none; d=google.com; s=arc-20160816; b=boQAZc0aaa/KYta2N1faVFROfY77URFGxZomEuOSl6N4kjtAA2jJ+A85QJ6jgmFKNk qwihQ6yTI1TCoAZZPA7uFJ5GGLbkSho8RbWsqYXBzYyiPTEDEPHnx/b2xIuzzYtvZCDo yRWis9t7Q3JMb/HvKTn6bODCmX29dsozXZ+RzDLvWwUoxldVR0fr5Hy90lQTeZy66A7T Nhz579EeChbvSTOYzzd/r6rZmS60rtAGVV6PPtWAFOQnWH+gFoQ+VYLYJI6/qH/LMUGC XF3NUIHlawHXKNDuN3qpPr8x/WV9kGWRfHnxEaXD4pkuVFCjE/mg514NNvUSqCF3T7L5 fdtQ== 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:to:from :dkim-signature; bh=ywDEWaMPHCkZHNZHZvDhBEB+D4W5S61RGKLaVoHCr7o=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=gGDZenfMbMNHT7JEDSspkcZV9z7aJofvvUvBeSW3C781HnKuW2jLp58eQUN/Bz0u8R 4ucemmoXci5rRn4QsY3EwMF6zctnayQaKjBOdBNMCSgGt1rYsaf/C3UW51k5nWyoCG0v A8GrJvmlDWLXuJ0VJqXBQPqNNH2uV+oy8jOyOCcp6/cuCW+nXi5+PJrIQ8ejuj7dDLOg 7k40xKvO5kubUQmC0sFH4GPRZt93IpkdbvaQb+0POuOTzDRRVlmyy1P2k2zRn+mtaWS1 605HdA2nbQXAzwWPa28cmqVbaAaSi7jF/B5LnbWbc6/JYVt3oIosNAJtCxa9k0g1N7hz gfdQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CF2bkEmh; 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 e18-20020a05620a209200b0078d5d4df212si6084508qka.396.2024.04.08.22.06.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06:48 -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=CF2bkEmh; 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 1ru3du-0003DK-7E; Tue, 09 Apr 2024 01:03:34 -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 1ru3ds-0003D8-Lm for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:32 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dr-0005LT-2c for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:32 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ed04c91c46so3408112b3a.0 for ; Mon, 08 Apr 2024 22:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639010; x=1713243810; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ywDEWaMPHCkZHNZHZvDhBEB+D4W5S61RGKLaVoHCr7o=; b=CF2bkEmh2up95Lwedu0z6rIg10INFCUnGDgZL3GsGZWRYwjkgpHbfrgDKoCfih+RWX 9PCNICrWKyrWp0hH34ENm0rjQmSJWU6TrEOg9lmlQXP2E2Wj2BH5+V9U4+r4v5ViEWp9 3GsBhO9/g1Ac9d0MgsSVE5dC27Or33Ep5ikHBlq/22/Ij8uRz268CtISFIzG0nEgIA/J 0GtNmk91oOEloPjiaCPdKQaNB/VcM0z6BlCRhVzzJzPFFniu+ajuUECkCLrjEiLW1Ef4 f3wvh2cbzm/S3/Alnn+zR85XFO0P0FHqtVuRPvNjgT9JU5nCy3ckDetA3VbDjQHGC/bt XZhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639010; x=1713243810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ywDEWaMPHCkZHNZHZvDhBEB+D4W5S61RGKLaVoHCr7o=; b=MkffxL8TLAny2bxAGFG1dy1dhTj3PVmUSt9TX9m7uB7H5ZAfzhN+ywk+0iBGteX1GB bc5GXp2y2bSnuE9u2rd2VhcGouqIkgUrALKM9xA0S+xmX1FJcp+eAC9qb011T5Q2LO/P Igo/gde08inzNyV0c5vicLMqM6PIiSOhzmgBRuR/3tcgJra1k6SMemmftUW8M0DI02JS yftsGE0Ob+/N8BzSeW+ncjwV4lHbFYAB8ep51g3wvNaOqlU/TKz1eQikCw08Nd/u/pYE KTkNcijUimSw4388zeW/s2cMPTZyYZxhsXRpfuqNdyIc9E1l4vZc+cAFDaHvc7DILHGR vDMg== X-Gm-Message-State: AOJu0YzR3csnmsZJY7tsDZVzHXoxdybo7xI2DxsBbs1SjslZRtZRX2Jh x1lE+E647jZJV83kSghkqyegD47qvFOwRi/6k+2fzZUcGeCTk1GIzRcd/OghLI1/PBk5IsrVuJ3 c X-Received: by 2002:a05:6a00:852:b0:6ec:f28b:659f with SMTP id q18-20020a056a00085200b006ecf28b659fmr14320620pfk.3.1712639009803; Mon, 08 Apr 2024 22:03:29 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 20/28] linux-user/i386: Return boolean success from restore_sigcontext Date: Mon, 8 Apr 2024 19:02:54 -1000 Message-Id: <20240409050302.1523277-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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. 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 f8cc0cff07..1571ff8553 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -563,12 +563,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)); @@ -616,29 +616,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 */ @@ -664,8 +662,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; @@ -689,7 +688,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 Tue Apr 9 05:02:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787190 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57945wrs; Mon, 8 Apr 2024 22:07:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWKmA7vSjt5w+Q+Q2NbfsJZCvm3N94E2lyA5gcRAmXuIS08DwSp/hHB8iZJXvItZn4B1WxY4rruPA+iyt3F6OOZ X-Google-Smtp-Source: AGHT+IHjouiqANQUWbq/npVAOCf0v3N4cOy/w/Lt109mcI6uEM6qTZtSTo02M03dSKH0SpdiFIYi X-Received: by 2002:a25:6648:0:b0:dc2:232d:7fde with SMTP id z8-20020a256648000000b00dc2232d7fdemr9681709ybm.13.1712639233036; Mon, 08 Apr 2024 22:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639233; cv=none; d=google.com; s=arc-20160816; b=cWmSqYOEMRRD0fMoh4TSEWBWW09PKh3r1cBBashuQQdyo/7xtKdevHp/VKmj6OnN28 PT8mgPYZ1/NoInKwO8XOCG7+OylGzcOxiGOLZZecJq2GwAGcxNjO+SHAjXnNM7aUHcGx qzMeEaTdPwjPMb3yWE+d5QPHGccs5hk76JLKqvY+nxDjgVLhLYUe07ixG2mbwm2i8ij0 sfcIYp4TQlDCg7Ea2ImSuWzEyjS6SGk908Y8uSB/tkejBuHIbkNiU18XWCmUPamHHkyg p5EQygrOiqjIsTtDg6lRNeLCNEkTJ0/INOLkz+kft14kCi+uXSF5tqR/zQtHe4gEBbeB to/w== 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:to:from :dkim-signature; bh=HlBd919hOWRpacVU0kzMPBm6pP4Z5Z1zQwF3gBDERhU=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=qthOz3B6fzPYXxT8rzavCK1KGNzFktChj5MA50YxWvtPSDBkNNY9A05CXzHf0CZLKw x+SHg88Uu9LEo1TkDfOpq1DqwmTjpsNlylYjuSmm9DWSUuy5fhEborE1x0GA13r/NQyc +Xayni9E0/jXdD1YzXO1QKZMJAjFmNrVS9w51LGfIi2jbSzMZKxWnYtPImCZBukoJKDh EsJWZ6Epae2JDifs24FkvssC9N3uWeJ487t2zQGrQa3Xkx0iqiCXLD10LawXAY9F0aVQ 8AIxzhy4VLyKrXLdi23mbNszGRes5YuTL7BjcOCKqtYRwtqjhG70SX31P2qQt4320bf0 gBLA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IaOGd88u; 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 h9-20020ac85849000000b00434e572c598si178383qth.455.2024.04.08.22.07.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:07:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IaOGd88u; 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 1ru3dv-0003Dq-4M; Tue, 09 Apr 2024 01:03:35 -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 1ru3du-0003DJ-3k for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:34 -0400 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3ds-0005M8-8b for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:33 -0400 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-22f01274622so1543947fac.1 for ; Mon, 08 Apr 2024 22:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639011; x=1713243811; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HlBd919hOWRpacVU0kzMPBm6pP4Z5Z1zQwF3gBDERhU=; b=IaOGd88uwSlx2AXSmDSochmWr+CSxz7bTPXoeShfh4H8VooUz2uRzF+h4F86Pqs3E7 B2YI4h3XN72Jxr9fI0QuXi/GEX0I5UCD7ZhJC/MwSMYWImbcvWkn26O/T2Qyj+CWhp6n HJPm5TeyDBy1IQ40umBhLdrN6wi5oSIGyt5+kbHqQzFz5OneViO41qYPpZIcKGOpSh5s w41AaQitDXx1G3qlfAwqhrkaXC88Nb5+1ZOMzmJ+76npyZ3b3NZCxyVVat5yjNQpMn9d o3xKV7mdSfEnAlzz4ib1+mCqiOTQBF/OljWm7wiQk2fs2p0vq+khbF4f+cdKS0Kvqodz oEuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639011; x=1713243811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HlBd919hOWRpacVU0kzMPBm6pP4Z5Z1zQwF3gBDERhU=; b=qdsFslyv5TjIXy4uuIG0XQcE4F+2HgBm4JZGZ9v8LUp+Tfs7P96cUVf7HQKNYuzKGs DM334Ewl7JbpMyoXRCmY0TrGd6ijkU3ozSHn7aOOSL6a77x+9cMtaOg0HzacVgZNmr8F QiOoAKJ86QjrUPSU5jhCcY6c1M8BHE9fIkwp0XsB+5NUesINCmCJHnjt+B8ygODLI4Md OIvRqGgxfY+towvmGWjqNxqu9iyeoQ0L12EQDMUhfILUwwu8OqRSvK7GwhvRBJ0JebPX c6tS1/dFnIkNf8iJHyUiR3dd7CY3QOZSJovsdeV3rIEyswCvLTN9CoBp3Q41qVsGWxGr A8JQ== X-Gm-Message-State: AOJu0YxwPhi+97YXTK2CHrCqL+xvpzxWkv9ddfXAYFJ4aX6EYdmJhxoN /NOkcNEcv9/0ZYzulNE6AbVmqDhHuT2AUJEWTICA/1mvR088LmE16agQSkLEFi2Wn5TubRiBODi k X-Received: by 2002:a05:6871:88a:b0:22e:dfbc:4d90 with SMTP id r10-20020a056871088a00b0022edfbc4d90mr11912206oaq.5.1712639011107; Mon, 08 Apr 2024 22:03:31 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 21/28] linux-user/i386: Return boolean success from xrstor_sigcontext Date: Mon, 8 Apr 2024 19:02:55 -1000 Message-Id: <20240409050302.1523277-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::35; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x35.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. 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 1571ff8553..d600a4355b 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -529,8 +529,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; @@ -548,19 +548,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) @@ -628,11 +628,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 Tue Apr 9 05:02:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787175 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57413wrs; Mon, 8 Apr 2024 22:05:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW0Io+UpRjpCvzAvge29VYRcBw3q+6tERYZpcoh2965SaDRLS7yE/AA5Yrz9oSURCsB7kLTg35AldbuF3YxEnTf X-Google-Smtp-Source: AGHT+IGJrx3IT9TSTdvM7+ADhl/za3TKOolT4Q3DexfhgsvX9GeXxlnNbXWn11beONKHTw/HO/im X-Received: by 2002:a05:6214:2b0e:b0:69b:2d2c:6988 with SMTP id jx14-20020a0562142b0e00b0069b2d2c6988mr512702qvb.0.1712639128678; Mon, 08 Apr 2024 22:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639128; cv=none; d=google.com; s=arc-20160816; b=MiX1PfEi7cjQfEJOY/ifgCKe0o1oJQdoZ4fZqcNyEFIGdlvBIh2YMBDKDmNiehKVAZ 312VMtIzKKhavZK4ksr3bBRX0JBZadimNrZnS9G98psfpacg7pGD7tdXsuL8QDsgZ4eq KfbBtVTipKEqJqluvj2p3bca2NIwl7UOA33CAXDJLaeLccoEsmQ5yGFV23gWgUFiba4+ RaNOCaxuu7Vc5jzVxAFMaGM2rs5L28MK8tLPMI88K73p4HZwD0meldo997OwwHuC9rx/ BhfYK8oEUp7NUJitcsQICigUYuSwtY3nowjGQLKHmnNCF84LkCc4Ks2YSNQ4TMY0mztL PYJw== 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:to:from :dkim-signature; bh=YLb7ERyLC7sFP5FMjxKR/yL/hAQ2RTg/kn98cl9LZag=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=P3Fd3cTTkmBeIDkV5/5551gUfJLSfgmhxfKsRsbnYV18YX3cAqBQ1HcssHa02ZfzK3 mlPxK5cTmNr+JHs+b3UHR1bg5mDD1iErYX4yM9IhYqL8mixxTQEvXeAtxw/kDUNR0xpF Eskw5S97vFMTx5r3HVycBVCejgVNhtiQ35bTZGekdFEWwEVISTGznRLK+gKHcFT8yg82 AqmdWAa6NveoxmEDGJ5ha0vjr6ktr0DxYTXzO4Q09YZjCV8Y6cl/Yv5/lZWjFRmJ2M9m vEriXNygl+dc7O41wesSfsCzVIJDwXgwDCm3rmJ6PwPY+t5IrAYe+NsLk/j7jfDVvXp8 1Vxg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OgpvBOpx; 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 f17-20020a056214165100b00699408491a8si9241826qvw.136.2024.04.08.22.05.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:28 -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=OgpvBOpx; 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 1ru3dy-0003F8-Lt; Tue, 09 Apr 2024 01:03:38 -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 1ru3dx-0003Ec-A5 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:37 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3du-0005Mf-1k for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:37 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e703e0e5deso4501059b3a.3 for ; Mon, 08 Apr 2024 22:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639012; x=1713243812; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=YLb7ERyLC7sFP5FMjxKR/yL/hAQ2RTg/kn98cl9LZag=; b=OgpvBOpxT7nVJNmXbC7mpGIaHAh/ehVCGC33yhBCLnUSxZu3aT7a3z/uqEZVnPiiNF h9Xtho22DXchzkkT12V+7mQXtqNvajo+7j53tw5C+/i6G54NHndyblKrovBY0X8URa8b WMOZZXDphqF78vBtpSUcSrCPqREkz4Xb5hzvkYdWjxDziQsx8/xVP+VV1oQaiGpo3/+a bgG932rtfNu4vAfhq6pkAiDlaX50eul6Ex1D3FIhHVsXnkrTQIEbsjgZHjsZRnXKG/bU Aa9+PbRao24wu6MsM9O6ADqbFcBqcafQ/t53oixesiucjbhYmlklQtdqnmZzGihkAppp c1Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639012; x=1713243812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YLb7ERyLC7sFP5FMjxKR/yL/hAQ2RTg/kn98cl9LZag=; b=l4IuxtJHnzck51KXf2GDSe5l6nTFprrqnmgF2mdBRRGZLMj23ovuKn+A/XhWvg8iEu qOmKsCmP57JcwmJbaczacb0ybpKVMVAHynKp+uNqJxJHsIaoZEFqzRPhhMl3YzQ070q8 Gyfzkz8h5SWkv9TKyuYV1Y9ieYewdQ42RS2SIcb/fnQw1/ftNoNSjtH8xHbslM2jGdfW L32fS5dMQN3JZSC6+MifXda8Cm9gwlcp7Kgz51+q8w9e8/dDs8gaAnI2X3rq1STnSaki yjI2I8ytDBlkOuEGJ9D0RRth2PzUWXdvNbWnGL+amr2d+VI/6c6CQ22C5MIe43z08kHo TnEw== X-Gm-Message-State: AOJu0YwlyoeGHS9tvZaZRhrY3To0kJYgmbymbxxgUj2pAWhq7AmjqG5F ajGqZenZeGM9V89liREbik6bK3QJlvcicPf5ul5VnG4S16ihSYGHw+oOtoFrgCPFH146qxpdEfK r X-Received: by 2002:a05:6a00:939b:b0:6ed:21b1:e230 with SMTP id ka27-20020a056a00939b00b006ed21b1e230mr6099515pfb.19.1712639012450; Mon, 08 Apr 2024 22:03:32 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 22/28] linux-user/i386: Fix allocation and alignment of fp state Date: Mon, 8 Apr 2024 19:02:56 -1000 Message-Id: <20240409050302.1523277-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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 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 d600a4355b..d015fe520a 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -64,20 +64,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; @@ -160,24 +146,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; @@ -187,10 +165,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. @@ -208,66 +184,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); @@ -279,21 +367,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); @@ -322,57 +404,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) { @@ -394,22 +444,38 @@ 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; + } __put_user(sig, &frame->sig); - 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]); } @@ -422,6 +488,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; @@ -437,13 +504,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 @@ -452,37 +512,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 { @@ -514,60 +588,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 @@ -613,29 +740,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; } @@ -647,30 +778,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 Tue Apr 9 05:02:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787181 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57644wrs; Mon, 8 Apr 2024 22:06:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUqPcV5mdtrPts0p5crmLxlY6mUwI8x5Em8hEPkEb4wDTTISu/vMVwKA3XjZGRQFCn982GuENyNpU9qGsHiI4bs X-Google-Smtp-Source: AGHT+IE3S+16HqgPPzLOcyeUHK+yyvl7pW14/GBkcc2DTKvIGZj4aOAMQwdbAw9lYwCbB+yuv24N X-Received: by 2002:a05:6214:2525:b0:69b:213e:a6d1 with SMTP id gg5-20020a056214252500b0069b213ea6d1mr3196717qvb.21.1712639179511; Mon, 08 Apr 2024 22:06:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639179; cv=none; d=google.com; s=arc-20160816; b=qV/MgucvGrHFFf0CukWKiY9eUJCH5bi49tAWThIvwAeEo1R9YgpFgWE4wlgzn4NEOQ fuvyeTXhV63pkQZtnZC5U9mOA15XC216m9YA4yYTljAOGLvWAE8bUwqnXtaSuYYaSAT/ 8sUElYeGbL19Utb2TesTomS96oGak+BUhs6QNc1mOcRrez3cJ+8pBy8TFurfD6alnxmc hZOAMKyj9tXd/rNH21502azHJX2LdiM8Sh7quaNbYZC3VC+cFfNmyivY/d9wKPI+t+io ciRy5HjWKQhE4ZlypZU0sGDQxSf58dcI0iFm5K9/B/HY+BXWtljx6Wzps6njdatc7MlZ CStw== 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:to:from :dkim-signature; bh=zQJasuYfr/HR9syiI0F0T/STtVHqGadJh9IMsrqhsDI=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=QABMjimZ1z+Pb3s+fc1EGR9rQg8ZGel0plhSrDzQAPqyHB0BUY5TcrEDKvRLXufccq xgwCKvUPLBPgJkOE+/z+7zW7SZbJOQk5Qbp4GIGt4MdDwMJyKXEO+UvXaILbf3HDZICo qBELj4t//LT8IWQWOlEhGUsiWa4mlZcEYLLIBizm7of6Y0nXRji7G7igGSQ8J1Ns2qx2 CjLNzXC5i0lJMBhmfe4LLxlK71OmuxroY6YDG0p6wUL0O/bu3SgX3Msi7ilAdFotGYvN pF52lEAtKUkMrIXOw+DeUmtrLzLMlw9cTCvcHqdEml1CVeF9R8aR0f401zwBhPQyeyLV yO/g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YKdF3UI/"; 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 b19-20020a0cf053000000b0069919a57f2fsi9651744qvl.110.2024.04.08.22.06.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:06: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="YKdF3UI/"; 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 1ru3dx-0003Ek-MP; Tue, 09 Apr 2024 01:03:37 -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 1ru3dw-0003EP-K6 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:36 -0400 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dv-0005NZ-2v for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:36 -0400 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5aa3af24775so1068085eaf.0 for ; Mon, 08 Apr 2024 22:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639014; x=1713243814; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zQJasuYfr/HR9syiI0F0T/STtVHqGadJh9IMsrqhsDI=; b=YKdF3UI/MEvOTVvCXN+VHDR6YMs3bLADwxFH1WL5wVVaypER7gR2eZV7L9eJLyTVD3 LvUSy9IXLLSyCV33TQMe+fyG9+7iZDRPyyiexa/HzctE+N7OWkZoLzj78ebbDVtns/mY DKUZKVz0HWuvIDPDnxvomryQqbRwQ5qFxqfMxmbVoV4nRJuhyoBtlxZO1/1DANbx4aqC Vpjm9vc9brmw6gXJ7vRQloJJKex7oa/4dRPsIFZLh0i/xXDsCVPJbE9yNrVXrTACW2iH CyBSyf+0YUqrTDrkQBz7oQVkTTWIbNOgthWwAjsnQM4cQjYPt+QGS6zwdRbn9zTaOdUJ y0Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639014; x=1713243814; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zQJasuYfr/HR9syiI0F0T/STtVHqGadJh9IMsrqhsDI=; b=smYSDeULV0LHmSNqZjw05CTORim/XCyXSZ4RQIA7PbcPAe5IpTy7E47Hpgh6+yl6rB HxmbpgKVHcVw3SLFBbdVZ5MIx+nxIdg5LQkAIOJAbR0dZPUyHVnnK4/uexwIY//+DgxC +kfvZWEoWEOuUo/P8EmxSIer07v42m/fj1/h1Q1Kxx53gpaIe6uVS1EXqjRZn/RP3Saf hEua1U8SUuispE2bo2h2q5VpLihigk1ks0T908cR5VPr3dQAvlsIUfli4WEi5Gi0UTvO 2+1BoTw6u2Tytl1n6GR98L1kL1skfksN/00mBNPgbuQyzg1i6FZDFa2pxIxGSDBZkQ3k x7yQ== X-Gm-Message-State: AOJu0YxsMkEOsfXa9cYk9i0wEHkj+Sc2e4V+Gt2CHwPw+IW5gX83klvl xtt0txWALLpH09t0qBIOxwSCabzt8BLZHGZRPWh10mKzxQlj6A6IsYPuxkFftH41BC7IBvhHtTk E X-Received: by 2002:a05:6870:5ba0:b0:22e:c6b2:84aa with SMTP id em32-20020a0568705ba000b0022ec6b284aamr11776863oab.27.1712639014014; Mon, 08 Apr 2024 22:03:34 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 23/28] target/i386: Honor xfeatures in xrstor_sigcontext Date: Mon, 8 Apr 2024 19:02:57 -1000 Message-Id: <20240409050302.1523277-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c32; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc32.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 d015fe520a..fd09c973d4 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -612,6 +612,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: @@ -628,10 +629,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 @@ -644,7 +660,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 Tue Apr 9 05:02:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787178 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57468wrs; Mon, 8 Apr 2024 22:05:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUf2NhPFH+6umCreLNEgrnCcfVyETrN3YQ5UtCSfwKwlEX8R+wxqrPgTtS3SbheU+sdPtfiEYCIShtrY8pFZ2jU X-Google-Smtp-Source: AGHT+IGnrNWj6oP3IT6bhG6Noc16uQg0spFKLPvkKtZ6M0AhdSXseI1jY0M5NHyu9xUY4ldIpotV X-Received: by 2002:ac8:7ee8:0:b0:434:7c49:a94e with SMTP id r8-20020ac87ee8000000b004347c49a94emr6619866qtc.27.1712639139583; Mon, 08 Apr 2024 22:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639139; cv=none; d=google.com; s=arc-20160816; b=MZTrt38SjzTzHv0IW4R2S/xV9FZzqnbttbskok7X3kv0o/GKvN2PdQvuEQGQvr3TXe sX9mpWTPhUek6/q134WbBR27x5sUz/O5ssaPnGD8aJryc6XxVbzhOY294+WUWlPkVGDU 5dZfcJkUEzrHYrvL0zG1HnxGytnew4BgqlRyoS26TfQarf7+nKjIKo9q4TgwzZjA5IFn 91DpKrkHwuEiK9LGp88aYkpYAnt2+IQbUL9UntwtaKLqdIj7i7C/JnpVwUFO/jGipEqd YsBy/lxlnQhcSYKtW5RSjF06FQ1+/X+O98NaypGpSmJj2O6QR9WtjBlH40OlijGKYvqh 42JA== 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:to:from :dkim-signature; bh=WQH+lbdw0Skr3IWU6+iU1d7e+abJeDKYaSWCKRgQQbA=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=awj1UZDrP7qP+dqm0j04jiXIrUL+HhiFgOC/LkyEXp/vIGaXBAIEyutlo2xG8ou/Jr 0tzhdu2j/nl8dghfC+K/Lz/xh8q5WlWxKiBttlkb3LYpKHf69JjSieRxhSmFCQLQOdyv 9JR6u03ZWhKYQ3T0tP+gQaCrBaRe1E20HbR0f6HMb69Xxcl7Evt74LQXGlTg21vrmrrP oKxxdlYPQxcFLOTTG+DmqFHsvVwIMLRsAlTJpd9v5NkKBi8kdzkH2byRYeo5NWhcUAW6 cdUs2mQGLCmkKlK0/XwnThmjjpMWF25yyGyHPxga+VwLbpk0QDQg3+cwX2tDtn4UY84T w1/A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wy7fmNxb; 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 e12-20020ac85dcc000000b004313889961dsi9567806qtx.557.2024.04.08.22.05.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:39 -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=Wy7fmNxb; 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 1ru3dz-0003FN-AM; Tue, 09 Apr 2024 01:03:39 -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 1ru3dy-0003F0-8L for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:38 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dw-0005Nv-IM for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:38 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6ecec796323so4832519b3a.3 for ; Mon, 08 Apr 2024 22:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639015; x=1713243815; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=WQH+lbdw0Skr3IWU6+iU1d7e+abJeDKYaSWCKRgQQbA=; b=Wy7fmNxbYjEouulHNYoG0lertne92TWzsczIaeve0TpNbQXmEHXdsnuTugT3bBWcaH ACXJObwI53vpOH6E3Bkrhu4k9NzN7VudMq6dUA9ukdtYnwPUyT7dnOlh0uMKHx3GFKe9 o0uGe/Jnrs06TsKMItR8Re+wgbk84UU6adIDIT7ig5dhaq5Dj5fgihUFrVgNMIJyHkXs rUbc/7jL6hUXKyVAL23orBXe1xhxIlzWANHKV+SCe2bDSAtLAV+xQe9n89FtxX67du2P IyQ/wqJ/BjiWu320vHzdKTxW9PQWj50fDhlaKz+coX/dXKy3/DbG/EeJLVyXljaQI6cm wD9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639015; x=1713243815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WQH+lbdw0Skr3IWU6+iU1d7e+abJeDKYaSWCKRgQQbA=; b=bGulfWPGaCQxyhVmPv9eHj8psAOULfmoJH9wS34/67ih0n5Um9/+Zh25pSAN3IqUNP PmfKqTPNvn+yasmZNei2IIC4gJSh2H8OotjmFfbMILgJMH1t22QB6MlTGLJ76MOIgh0q TeZcDd+dX++hQ7CmOOFuoTum0zoKQr+3WXPvp2+SR1Ujiv3enTZraVzgDKs6cQC04zbr p1FhiUOhi6hbsjQIAP0sjDxegjV/OeYujmGknR7dHoidXPVcte2I1EyWNySTXk0me8gY cpzY5FvETg+TOpXwepk9o8rUfE9lhWIIu3sVm6gKIaj4xaszSxlAzTEhRVNy7m8sCuGS tRvg== X-Gm-Message-State: AOJu0YzzwzrQrqJ+NhpFC1i37OM0pYv9OYynMPzU+FAcQwUmaY7jGGn0 ZnyDzW09inQkvp69Q83g5PAU9kEA7SsmyLtXak8n8S7Eb4+FRN1DCaP7JPK9dK4Tbn42T6jKHyr h X-Received: by 2002:a05:6a20:3241:b0:1a7:807:ca2 with SMTP id hm1-20020a056a20324100b001a708070ca2mr11029045pzc.29.1712639015114; Mon, 08 Apr 2024 22:03:35 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 24/28] target/i386: Convert do_xsave to X86Access Date: Mon, 8 Apr 2024 19:02:58 -1000 Message-Id: <20240409050302.1523277-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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 | 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 fd09c973d4..ba17d27219 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -328,7 +328,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 dbc1e5d8dd..d4dd09dc95 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2667,47 +2667,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) @@ -2723,22 +2714,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) @@ -3048,7 +3049,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 Tue Apr 9 05:02:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787173 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57391wrs; Mon, 8 Apr 2024 22:05:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVyZivHPpWv16w6SyBxUfQ84RxVijesom0in7pQz8KaTSabR6OVtb0XE7ZXLDKH7ZGo7urhdXq2shy5Vway25YO X-Google-Smtp-Source: AGHT+IF9pfsqG3PG0R4btwFc8RouO6/KUDs1kVAChHZWxF3vpVrd2Ao+ANmxMTYyIuzitRLSlfJq X-Received: by 2002:a05:622a:15d2:b0:432:e451:9dee with SMTP id d18-20020a05622a15d200b00432e4519deemr12863889qty.52.1712639124002; Mon, 08 Apr 2024 22:05:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639123; cv=none; d=google.com; s=arc-20160816; b=iX7+JiWFAHIwMJRvbPpWaSrSScTlZGc7XZx6MjmPvh3wjNZVwZD6LVTPdays0aBGsU +3YMnkk6IjQ72BPEpi/P4gDm3idsr1GgbNNvWUSUd+sS+QslgrJytTc12Y8sd7wVgbNh Y792nDNCWlUsUO5nz0Hhea1UlaJs9zhNyWOVrOLfgQCyTanr2pqk3r/vp5bZ7ms2/69g RqtnuM5B+5y4+OlisKH9daXVp7fR0EmsSGblmqizDVGcgIOyONxfQIlHvfRJH5jT4Mtb pSFfwbg+KEvSD+QLJe0Q5VNZEtOkH3CgyQn7wDsriXyVMWRWer/CegXjTMvF32TxtpoH fXPg== 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:to:from :dkim-signature; bh=4uWY1NxVcrV95bV5MVGH7iWV55UiyAePqOvtwTyZGwY=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=kyix/QteX1k1zfi23c8kxFZBdM0BQSpixNSfeoFSAGXZUe6ZqTAfTh2LeDaPr7LT/7 9hgI4PAoujfaUO6MYnwpWF7rO90o4QwzyNyIN+MNhoRHshGr6gYAt6InGu+qCmybdYbF oKB130ciPD2tQY29EVLyAjnmkr2DnjQ7gZLoqBi7RYB4mvmEb9E4A7RBMTaC/HgzswIR eovt9Z7x6bu1LMKEHxklFW/Pwh09WK06gIbKSqinyID1jKyVGWltMkuiLrAalQMsXWoT pdT/UTaIvp0MduNsoRd+b7PtmyVaXE2wjnTqUtet8yWa4mVqyQdVUF66chsD7Xkg/+bY tkbQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bmHw5Uap; 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 a12-20020ac85b8c000000b004349685b1dbsi4185316qta.421.2024.04.08.22.05.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05: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=bmHw5Uap; 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 1ru3e0-0003Fo-Bq; Tue, 09 Apr 2024 01:03:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ru3dz-0003FP-D3 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:39 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dx-0005O7-FL for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:39 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ed20fb620fso1748011b3a.2 for ; Mon, 08 Apr 2024 22:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639016; x=1713243816; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4uWY1NxVcrV95bV5MVGH7iWV55UiyAePqOvtwTyZGwY=; b=bmHw5UapAfnfdkg6Vb8NHbpHvm75YWcYqCiDKa2fPrj57mcXYDEqysyPLtrBcBNHgS p9SQw5Nv5g4Kr3ZBXe1J+gotSOtzJi72IIGX+w2jEOSJo9xWUNNJBMJjId7BWw6c79Ze L1MMHv0XZFxx73tLY3W6MwxuKpa0r2TkD8DHgzPthlC0VcLt7CBxLT19dtu8qw5y9wFS 6LDJ5M2UrSlXGLcBSaPz8sdHsUcR+MW26Y8VpzIUxpeuKJMw9TiZ0XoF0XDrmR9CIvFq z2yWVLzoO341hWnPsh59qt3Ps0hx01pgQR4nG41+QTFDMFjpbqTZzo8zQ91b00WtOfBi Q25Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639016; x=1713243816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4uWY1NxVcrV95bV5MVGH7iWV55UiyAePqOvtwTyZGwY=; b=kne85MlQJGA2Pyd1ypOojhPidNPIyYGTcCMbpL5v1PB1CL9H4cwn59WfixAL1fpnEj 9I/ZZnQT6h52ZNAMpWAckpqsauQHv8sCRsAIsbAsz2A/7RK4wFqMKAm1SPWy4xaUYBC2 6irGVAc5wTHFb3KhcN034V/8OhUye29nan+0oU3BveuKo4UUECpOKqiHpSNn402IG5kI jauQfpySVVkzlp6KvzaXIKEufaRSWN5ynWrRUPEf7K0mxXJ1b9kby0F+ZgEoq3ucbW68 cO94rvM9TqEtJLoYCneY+4aa9a7C2LQQAaZ6T3qdCHy9r1unKoLLdkcdgm+c6nnE6jN0 BVdA== X-Gm-Message-State: AOJu0Yxug0nQdtavZ/2dt/or1K4WNGN1aks4vb04O+SIryo6ZgKilaH1 rjkLdWsY5MpNI4Mwl/ZiBhjbgtmKV1dyq/2TotaFjGM1Pm5LZFiiflTFE+ZHfECatl8DoXQmgbp T X-Received: by 2002:a05:6a00:1888:b0:6ea:baf6:5720 with SMTP id x8-20020a056a00188800b006eabaf65720mr11160918pfh.3.1712639016224; Mon, 08 Apr 2024 22:03:36 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 25/28] target/i386: Convert do_xrstor to X86Access Date: Mon, 8 Apr 2024 19:02:59 -1000 Message-Id: <20240409050302.1523277-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.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 | 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 d4dd09dc95..909da05f91 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -2902,51 +2902,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)); @@ -2955,23 +2942,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)); @@ -2980,7 +2967,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)); } @@ -2989,7 +2976,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; } @@ -3005,9 +2992,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) @@ -3065,7 +3070,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 Tue Apr 9 05:03:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787170 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57296wrs; Mon, 8 Apr 2024 22:05:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU0568526znE3pifSoa+b3xlxNz5ChpkB8O3Bmqj67FP1hJ6peAdqYLht6/CNa5Rkx/C8CEvmusL0eIn6uE57ux X-Google-Smtp-Source: AGHT+IFHZRnkoL0dCu31EjiAYAeJWaB7MyRutq7UKqm7cOUCzYc1/BYHsi6dUBtwArcoYK1Y8yT9 X-Received: by 2002:a05:6214:2686:b0:69b:2523:fcd3 with SMTP id gm6-20020a056214268600b0069b2523fcd3mr2546978qvb.60.1712639105049; Mon, 08 Apr 2024 22:05:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639105; cv=none; d=google.com; s=arc-20160816; b=JFAcNTQ+FqIW29jni5F0J8J73LuDV7QmXRwA7w3ITEkDIt6Z2jN3QtahOKVpQ+6dB/ bLDuRewngO6DNxv+imZsDU1CN5V9W1PjUw9REOaNFwI117yjzvyhMpyL8A/JitZrcBuv dRnJBC0x31k9cxNSgc5EmHcoNGWbnH6srYpQZuUt17nN4ZhLM0EJBPRTSp0mlCi4qjZj 0W3rR79B6/RFJlEm0FpFfW7cPJMtf5ZjMOSPguPAbcMsd0kzO7V5gSo8hCL0yRKgfi3U AhlE2ZLUnXw9TRy7XP/ouW8bDzimYsu/f/MhAuve4462+erKTIl2ubH8WS6LetZ5plkG U6Fw== 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:to:from :dkim-signature; bh=Anvecy/e2tvOY5sGb/v0c6reXmQKZCwnsUl0b7ikqas=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=rtdyP4vhfkNMH/m84Ohj9KoSONnXNn8MG4L4q2XQq6DWFIhhNZyXVvThNk2UXKMbzX 5+3V7mTKxFzw7dTzLuCjsf94BJJZPSLq7Ngl3zeZBq4gzb1VS4GbkHHLkxV/3kWKEcyt t+5QDHeVQPlngeCxL8wcLFbmloajWFvnYPSHmUNlwgm/NrPWF8yE5Hsf7D53EgI7QtQ3 XpCen2ctTUZRTtblnGFR0IrfXjoGJ3+jVzDHCOEg24I07KoZyDj6cqGAnat4Nk1uIEI8 wE2hBT/Yv702/37zhLVtARM0yOhdYyhyxLtkKYrEd7VWfGKPEhB6tuz6jvkbwiuStLYw NSHw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vcfgRo3H; 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 f5-20020a05621400c500b00699324c28a8si5884865qvs.414.2024.04.08.22.05.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:05:05 -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=vcfgRo3H; 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 1ru3e1-0003GJ-Sk; Tue, 09 Apr 2024 01:03:41 -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 1ru3e0-0003Fp-Lr for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:40 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3dz-0005Ol-25 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:40 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ed01c63657so3079746b3a.2 for ; Mon, 08 Apr 2024 22:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639018; x=1713243818; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Anvecy/e2tvOY5sGb/v0c6reXmQKZCwnsUl0b7ikqas=; b=vcfgRo3HZQkGgHrMSJhS0d35utihgTktNzFr1Jfpu33El1iOFGITZS8WYVYJ/7EggS 8MwqYGPdbf4C27xfUjVn90OG/GcY2+KkFFo4l4CWRalv9DAvLetNPbDDC0hNNHKLv6uk er+HmZZwjS6N1Vhg3KNk4mnhozZDUca44IBFeI1g7cPTRjv1Dtf6JY0kLn60XttErzU3 OojLzinK8yXl7AERfvm+0bwOUQDKRD9Q6U2hWL/IzW/ytrrS5s4CTcDa/2umKBKuA4KC ce0wZD4T26hxmgXDMDbEMTRWvxMBOkBE4v1/bUL/pDm7AshtQOidVsNRdbSFp9pZG9aI BFGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639018; x=1713243818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Anvecy/e2tvOY5sGb/v0c6reXmQKZCwnsUl0b7ikqas=; b=mfEy4gWUoKOTIyC2cw8jWUSa9559fIKKnji0hWHY//4k5OJcwqVvtrdMPI8uCcCFeM V+8sD+ORknu62kFUigmQ45XF2H36dTmh4W7Hf1Njm4B4flqm7pBoF8NB7zcSUgMMmnm/ HwHKWo235vsM9zzJ86RhR3GB+iOWgAyMHwDa6q9wQ106suK8QmrpdINxZTsHlF7ILHnG JqR87Zt+4Fv7QjgF9UYFN6hkBTG0OBo33f89dtNZCZMOss7fXQAdRpP8whDSJxUQnddE iJvX37wjDaHIEx9sWLvEIWqLey0go5STIFCGyVFAR63JfJNSExxRfYtbdP7yy/F3iC6P jaqw== X-Gm-Message-State: AOJu0YzoqbAiNOITZznW7r6OyKUYOrUVe/qLV1nAsvO5nJxTJghbAAY7 jfAYdIUcrVtpVEBpyhAPww+N1S1Au86VnP2q08jsN8ByhhyigMy1HjiOdcLtZn1GgV9DUCGUNON J X-Received: by 2002:a05:6a00:2285:b0:6ed:9493:bc6d with SMTP id f5-20020a056a00228500b006ed9493bc6dmr43465pfe.12.1712639017667; Mon, 08 Apr 2024 22:03:37 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 26/28] target/i386: Pass host pointer and size to cpu_x86_{fsave, frstor} Date: Mon, 8 Apr 2024 19:03:00 -1000 Message-Id: <20240409050302.1523277-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.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. 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 5f9c420084..8eb97fdd7a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2227,11 +2227,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 ba17d27219..7178440d67 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -372,7 +372,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); @@ -701,7 +701,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 909da05f91..0a91757690 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3016,22 +3016,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 Tue Apr 9 05:03:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787187 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57867wrs; Mon, 8 Apr 2024 22:07:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVnukABu4KPJBeNncKCgb3FOaDQse1KGZsAOF9uha6BPrhIZrNGhGcKyFr8laCR3JYMc04jc/3mKPGEXU+2P45+ X-Google-Smtp-Source: AGHT+IG/AresZZqlmDk0JvX0pfrPxvf1jkZe4AXIPLXGz8+5TjDcxSYzEdHWGFwveEYWCKLOkzor X-Received: by 2002:a05:622a:6:b0:434:9135:4386 with SMTP id x6-20020a05622a000600b0043491354386mr5604371qtw.48.1712639220591; Mon, 08 Apr 2024 22:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639220; cv=none; d=google.com; s=arc-20160816; b=ILSMhLJiY86NwzP0QU5cIPMzpAC9JBj8wNNLalwruQJF7GYxbU3m4tOGyhfKYLUkZh XrrnXd4DIcm22R7RigBEQQrmvwdQo3czCqhW6tWol14kfeSCzRAwwnl38aQqc2b9JbgD 0uMo09d8uFGy0rCE5WLXVFcYBY/EtvYdOsRMYzaTQvJxGRjgepbEhZ07MiXoGpEMKlUr x3ppTUBLCgR+uRZQLB8tUPVjuf8Uz5C5RAVoy6k1c/92iUkGN+bp6i+TCFEoXvE3vKdJ 9gR/Cn1GjXkoWeRHGG29wyBbBfsmKN2TwtT7aAFnDbFO8+W3eY2k7twPe4OsTJbJ0+Xl K4cw== 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:to:from :dkim-signature; bh=i+D5XYE0Hfp+YN9LtsSBmGwI6H0rpmZNTNUQOtDcToo=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=kZS9xeiKh68wHHrneZUpneoAJ1Z66JMVM7rEqlU27Bm2gaRoUxsUitysqRfMj7B4Wn VSpv4z5j/ze1aOjaAUn+S2iwH86i4Zq4NIph7Ch2BjP8oLEJ/iqLetGrLMDoK/j61Dxx lO3oXKxy4Wez3sHrkQCL/ERARNxqJzv1MWo8nTKYwYCMutH2OBqfVVmHEi50NG7VL7H1 0pPWwVNLQcKtrt9niDg1DEfJf2tgJ0kxqktFcbYNTDO471VFePizPowh5gFLGiKTobfx HM/3j8zcp6gvZyF1NxEukbXYWsc6G2CVcRIJdEULYwNm1lZDVJxFX0u352etvWZYZQtd GMMg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CdL4K8S7; 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 y11-20020a05622a120b00b00432e0c41ee8si9590819qtx.280.2024.04.08.22.07.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:07: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=fail header.i=@linaro.org header.s=google header.b=CdL4K8S7; 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 1ru3e4-0003Gp-00; Tue, 09 Apr 2024 01:03:44 -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 1ru3e2-0003GN-9c for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:42 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3e0-0005PO-JY for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:42 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5d4d15ec7c5so4163695a12.1 for ; Mon, 08 Apr 2024 22:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639019; x=1713243819; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=i+D5XYE0Hfp+YN9LtsSBmGwI6H0rpmZNTNUQOtDcToo=; b=CdL4K8S7qB8v+vrvnhQfsVfXUgOvKzQWH/wo0qHHWJFR1ivm8iGKf3AtkfW86ogK4s WGz2BSZZKcZrCe2Gs6/x4n4Mt8XG3uO8Bwh+zKE2Puy9qEpG/Cyqgce6X1tpmDj5WJVY 8KUEm4uEm+i5wPsMTgyFtu4n2zg08PFmokcaKUS8KGEIYQBQ+yRraGNhodPXxWXSo+Hs 3ksOV3e5mPYL/5+l6ilcH+r40dulAErbYgiGqd1BvxJTRG11y5d85Sdu6wqUZxSZXo4y 1A+ym9N7cXQJzT3+tYIhveGLYiPIU+OmEwYthC779ODmbzSzM285LNvXD3R/7S9TMnl+ XaXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639019; x=1713243819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i+D5XYE0Hfp+YN9LtsSBmGwI6H0rpmZNTNUQOtDcToo=; b=qlZxifQRdXV4RCGNBJIeb1nH7m93VNoWDXSfrgI0wV+nq34ay/GvQcDQtXriN2iJAg jdZ1EEIuGk1ClvhHO4eeygQUNaw09usNLr3ZwHGm9QIxti7Jx73KVXfPle3dYyyOJaFf tOOZ4Oqu27/Iw77nzj8PqHxtDaQb1mdJWzeqU02sYihmXD+oIPHN64vw51bjwp4tnKy9 cNcsmkjKqsKkY6C7frqx/D4KE7iFSKkTZkRn6uf5FY6yBdwu5zUYUf5irWmtePZV2J3/ mHL5NF0TBtN5vxGzj4Y3vTdZb9RuiYYRjYPQRbEP+Efc6orc05RHKKVzAsFtwuQd+E1U Qy6Q== X-Gm-Message-State: AOJu0Yz3khecEXFht7A/WLZuZeOtfoDnSBad/lHhJ2feYi+gAIh1R2i3 Aq1WO1xVyW03kjOO+EU0Yn1+TCG+1A3uiAsqrvk8H44V9TqM+1GdmrygEKrTom2Qszh/AdgmbyJ 4 X-Received: by 2002:a05:6a20:e614:b0:1a3:50b7:7b5b with SMTP id my20-20020a056a20e61400b001a350b77b5bmr13865608pzb.60.1712639019156; Mon, 08 Apr 2024 22:03:39 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 27/28] target/i386: Pass host pointer and size to cpu_x86_{fxsave, fxrstor} Date: Mon, 8 Apr 2024 19:03:01 -1000 Message-Id: <20240409050302.1523277-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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. 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 8eb97fdd7a..35a8bf831f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2234,8 +2234,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 7178440d67..b823dee17f 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -293,14 +293,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); } @@ -411,7 +408,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; @@ -668,7 +665,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; } @@ -686,7 +683,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 0a91757690..1c2121c559 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3040,22 +3040,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 Tue Apr 9 05:03:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 787169 Delivered-To: patch@linaro.org Received: by 2002:adf:fdd2:0:b0:346:15ad:a2a with SMTP id i18csp57239wrs; Mon, 8 Apr 2024 22:04:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUmg3rAn7Wo27PZs6a8X7X9JPknDuEHw/VRdK6nbmDr5wCzjAmwVmmhrnKgXtKVk/70rGkinYEmJ3KItr//ZZe1 X-Google-Smtp-Source: AGHT+IFMRan+nyXk8mtaCVkS0BbWgk2E3JKwzkU+G/4eFriEYlE0t8xPPXcNKetQ4Z34iTPTah/X X-Received: by 2002:a05:620a:578a:b0:78d:6bdb:8bd0 with SMTP id wk10-20020a05620a578a00b0078d6bdb8bd0mr1921940qkn.51.1712639093429; Mon, 08 Apr 2024 22:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712639093; cv=none; d=google.com; s=arc-20160816; b=PNQgLZ7n0Dzne57f04nWxbs9FE3jbbaQrjM+MGBYJ/JStqGtto5L4xilof1D9Amkfb ZPUBl5UaooeRe1UROkeopOlvG+4pkUGJ3KBGybySJQY+aQ5Rvv8MtyudmNiB0NmLb+sr Q4MXQrXGZ3o7UK8+VjaB2Iw9VKsVc8Xkl7iqmeq5NHnfPmB6z+gqQdd2SXSHozS/vVBp Daa5kUIOuPHtG3Fw133uyO4uXUyalUrEHHoK+w58Q+vsQUJsiB66nkmuFZchDl0MrXvt FaYWw+AnwGLsXtZycJOy+QfEWrG5ixu3aiv2CcAOHS/ScwQ7jDO1AcAHiWWleYjEjh1K jfJg== 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:to:from :dkim-signature; bh=GoHB33Bfj8uNurFePxqw98pp2Ot/UcwhxjflbY0n1tE=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=v9rGXHTXQp7N1dAfq1X3ItPysjhV9yyE1p7e4cvkN4Upu1PVsMShHLIIy3IohIyABZ 07zdc/xXS69AyLeJawt5PWS5xXnKA7xcnw8ZkCjmp9Rmjsm6pU+Jff4W4wERrafqzlZU c4m9Lo75+GebS6d371ZYTPSfpr2rf6DEU7HmMXULdm0ZpUe177TBoh2OzMXJcimu7Nhk 6KEgmD7UtCkyGYCtaOy6N17xHPHxOylvqnrozcAdyyb04Y4oiYhvBSS6D/dMXq8CVI1j rEjl+MjeqQh/ksB6cG5uKd+jY5KgIq5crhjDTD/jPRMWXFmtWjp5AXc3cWyeppmx3B5S DkyQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rg5UeMKe; 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 j8-20020a05620a410800b0078d6b330249si1889675qko.762.2024.04.08.22.04.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Apr 2024 22:04: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=fail header.i=@linaro.org header.s=google header.b=rg5UeMKe; 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 1ru3e6-0003KW-F2; Tue, 09 Apr 2024 01:03: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 1ru3e3-0003Gh-2o for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:43 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ru3e1-0005Pm-C3 for qemu-devel@nongnu.org; Tue, 09 Apr 2024 01:03:42 -0400 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3c60019eecaso73220b6e.0 for ; Mon, 08 Apr 2024 22:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712639020; x=1713243820; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GoHB33Bfj8uNurFePxqw98pp2Ot/UcwhxjflbY0n1tE=; b=rg5UeMKelVb+VYFki35FKnJSejyhrfAiOavh4hV5rzfgqDD8jETMYleaaQyAw3mJVi BoIa+4XeVNsVRTWz/rxrZEbxeNFrXiX48wdsJcWURfDo1gTskmX1G/knaP+9om9NWhjd iTuhz10YX0BUt/ak9oOybl8Fa2MODjQvRbWVSlF9pZ7ziwaUVq8j8dPVM7LpByiMq/2j m890oiqgoXVwM9+nDJnBXruAdObgsFRCNnoJdmlWKWcfy30ASWP62EKgSVARVIB9Ekcq okAD3WViSFlVWU4MPl2SEp0tlIdlIgh3pgjW4IA8KOwYTOoKTXeIvumOexCnQyK/4/CG vexg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712639020; x=1713243820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GoHB33Bfj8uNurFePxqw98pp2Ot/UcwhxjflbY0n1tE=; b=P/UWIoavd8axhSxePNUuxULnezWfxUg8gwm5ezAXLMyHDzBKEtc1NKdQIYV2CkCtms jiJbJFrPQbb456/wGjcfpCa4lz/ioXIY7cPt8Gi9N5TTJBP4zj2UjAIT+MlJKqfqf0fD d4RwtVQMUM7/GxKgBYw2Wrm9n2fGvEZeFsgbu9JgIBhPSrZhJNFXEkcGOGS1zWcZHs+M 2UdUTz0bHFRqL9Q/hl40yVsm5g0kk1b0SnZ946ZSqQMCBp8UHfVw6yS35TI9tv1ftRUW is3r8BJGqGGRZxcues8zaa+haTtzeP8QLcr5PBySPJb5i58uITOwLXaPy+5iBq4Z9t5r BeJg== X-Gm-Message-State: AOJu0Yz6AaBkMjYuAUJRnDSyHzfJnXJ1t+XdPHF7KMc54rgNRBYZtfdz w/WXnRYiPJstGz3s68axfb62eXie/+m+iUpc9GhFHKym9ushi9zkGk2u/HvLg5+ugutcxIioo2i v X-Received: by 2002:a05:6808:f02:b0:3c4:f52c:64d with SMTP id m2-20020a0568080f0200b003c4f52c064dmr12254553oiw.59.1712639020266; Mon, 08 Apr 2024 22:03:40 -0700 (PDT) Received: from stoup.. (098-147-007-212.res.spectrum.com. [98.147.7.212]) by smtp.gmail.com with ESMTPSA id z26-20020aa785da000000b006e64ddfa71asm7654894pfn.170.2024.04.08.22.03.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 22:03:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 28/28] target/i386: Pass host pointer and size to cpu_x86_{xsave, xrstor} Date: Mon, 8 Apr 2024 19:03:02 -1000 Message-Id: <20240409050302.1523277-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240409050302.1523277-1-richard.henderson@linaro.org> References: <20240409050302.1523277-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x230.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. 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 35a8bf831f..21d905d669 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2236,8 +2236,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 b823dee17f..d8803e7df3 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -325,7 +325,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); @@ -610,6 +610,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: @@ -640,8 +642,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; } @@ -651,15 +655,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 1c2121c559..4ec0f3786f 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -3064,42 +3064,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