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; }