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: