From nobody Fri May 3 03:26:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522344550710270.9979505737832; Thu, 29 Mar 2018 10:29:10 -0700 (PDT) Received: from localhost ([::1]:42575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1bMK-0008TL-Ig for importer@patchew.org; Thu, 29 Mar 2018 13:29:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1bKw-0007lH-Co for qemu-devel@nongnu.org; Thu, 29 Mar 2018 13:27:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1bKs-0004JQ-GD for qemu-devel@nongnu.org; Thu, 29 Mar 2018 13:27:42 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:42826) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f1bKs-0004Ih-B3 for qemu-devel@nongnu.org; Thu, 29 Mar 2018 13:27:38 -0400 Received: by mail-pg0-x242.google.com with SMTP id f10so3488532pgs.9 for ; Thu, 29 Mar 2018 10:27:38 -0700 (PDT) Received: from monty.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id i186sm10378388pfg.53.2018.03.29.10.27.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Mar 2018 10:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PzJHNoaveAtdniybNUSO0zgkYJ4C0y41/UO+ZhKU7K4=; b=JZX2ExkFu69hw2WY2bvapumb8opo5Uwg7RhGPSiWCdafDKGEGL5nYIcCGLeOGjnYe2 lxYrlqq46YD7WDWHQEttN6Scx1g3Rtt7CzWZOYQ15puvlpgRe/jrq92aUlGK4xC+WXCV QL/UoI/kABSL7hsqFiRMaQgasX5vJMNPCqRHJ/nFOzbwLdpjGdlkn2mBstReUY8lr409 ZltcYZI3ynWJzJOEuT3lCyenQEc3xkmVArzFPApWuWfvty6qt/CLtNl3kll3p7poN35D us175bH+5QH+iiEDCPFM791m8nxcBRJnff5yE6zDHEC8q7iVQw53vJ+U4BnBk5fSVQ8p dYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PzJHNoaveAtdniybNUSO0zgkYJ4C0y41/UO+ZhKU7K4=; b=avm5tXfZdCkPz55gWjUFS32JFhZkOvXVpIVPXFeIHSH9eMSLSLMR29yMCHuaPGdR+h faSpJezOHPK1jTCB5XrHcpKIIWDYCLqA52J+PmtSfanFm4SLd28D3cr9l9xIuI2k9Aad NlFcRsX0fxSfRZAPRujFDJdmtr3I/3hgtGmFzP7HG9yzanUpV+9h7Wb0KFl7wWO62K9b pdxUFW1FwSUyhSFadmnC5EQBanx6PIqeUnI7t5zLMGxfjcp2vtzq6d9BF1XUsBgpG/TB G4qRUDcrmkFMQr3Qdl1HpkjmXZ/8r1SgX8xB8J+kk3CNa2BgJMYq3FBZ9etFVtCx5MTd tYbA== X-Gm-Message-State: AElRT7HtUxc5vywh2SD6Q0ILauwRG+pv/q44g2SwJiIZO8HcoEJ/WI6u nuZqntPUTbvitcYIxigrIH67CUYpgIk= X-Google-Smtp-Source: AIpwx48GDEGFZAD94BG3Moa2aoDm032zKzpnGBnpvYLajg9HVWvUBjcbkvySQfoD+7xA3bkpYY7OIQ== X-Received: by 10.99.117.26 with SMTP id q26mr6049153pgc.169.1522344457343; Thu, 29 Mar 2018 10:27:37 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Thu, 29 Mar 2018 10:26:57 -0700 Message-Id: <1522344417-60114-2-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1522344417-60114-1-git-send-email-mjc@sifive.com> References: <1522344417-60114-1-git-send-email-mjc@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PULL 1/1] RISC-V: Workaround for critical mstatus.FS bug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Michael Clark , patches@groups.riscv.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 This change is a workaround for a bug where mstatus.FS is not correctly reporting dirty after operations that modify floating point registers. This a critical bug or RISC-V in QEMU as it results in floating point register file corruption when running SMP Linux due to task migration and possibly uniprocessor Linux if more than one process is using the FPU. This workaround will return dirty if mstatus.FS is switched from off to initial or clean. According to the specification it is legal for an implementation to return only off, or dirty. Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Peter Maydell Cc: Alex Benn=C3=A9e Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Tested-by: Richard W.M. Jones Signed-off-by: Michael Clark Reviewed-by: Richard Henderson Reviewed-by and Signed-off-by so I made the PR for the conservative fix, --- target/riscv/op_helper.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index e34715d..7c6068b 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -144,8 +144,21 @@ void csr_write_helper(CPURISCVState *env, target_ulong= val_to_write, } =20 mstatus =3D (mstatus & ~mask) | (val_to_write & mask); - int dirty =3D (mstatus & MSTATUS_FS) =3D=3D MSTATUS_FS; - dirty |=3D (mstatus & MSTATUS_XS) =3D=3D MSTATUS_XS; + + /* Note: this is a workaround for an issue where mstatus.FS + does not report dirty after floating point operations + that modify floating point state. This workaround is + technically compliant with the RISC-V Privileged + specification as it is legal to return only off, or dirty. + at the expense of extra floating point save/restore. */ + + /* FP is always dirty or off */ + if (mstatus & MSTATUS_FS) { + mstatus |=3D MSTATUS_FS; + } + + int dirty =3D ((mstatus & MSTATUS_FS) =3D=3D MSTATUS_FS) | + ((mstatus & MSTATUS_XS) =3D=3D MSTATUS_XS); mstatus =3D set_field(mstatus, MSTATUS_SD, dirty); env->mstatus =3D mstatus; break; --=20 2.7.0