From patchwork Wed Jan 15 06:17:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ShihPo Hung X-Patchwork-Id: 1223190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=Iy6Wlf8F; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47yHFZ2T3Lz9sPn for ; Wed, 15 Jan 2020 17:18:26 +1100 (AEDT) Received: from localhost ([::1]:49978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irc0W-00069q-4x for incoming@patchwork.ozlabs.org; Wed, 15 Jan 2020 01:18:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58904) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irbzx-00063z-03 for qemu-devel@nongnu.org; Wed, 15 Jan 2020 01:17:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irbzv-0003XG-SU for qemu-devel@nongnu.org; Wed, 15 Jan 2020 01:17:48 -0500 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:33049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irbzv-0003Wt-NV for qemu-devel@nongnu.org; Wed, 15 Jan 2020 01:17:47 -0500 Received: by mail-pj1-x1042.google.com with SMTP id u63so1700797pjb.0 for ; Tue, 14 Jan 2020 22:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=Jx3r2seKwSeUadPVhjH4OOR8DMwWWFpbD6d3Ui5d1O8=; b=Iy6Wlf8FywDmtcjxTWf0Q1wvPc/Miuzbi2uWt3BzSrgtQWcGESmCLvGAglCiN2qN98 9/ZWl02NeLoRXGURZ9ysiTXOyj/NYq4EuePi6qF4leEOtMi8rwErIrpz390+3WPhvoje bEoqdvJ2Xux1CBZrBw1DnQXFJ6OiZtWc29Krn8RyAPTUa6axQowYWqcLty+btNPap4ad cTyFdHkwRGcwIIzbDvSH/XXY/1U6P5OfLM40FOloJm3+PMDzVM4sxs4k1s86Qx2jIdGf oRMnykzfLQRdl16aFOnXe1s243fujiCPU6nkG4AlF/qIsNuLzzVLhUjCaFrpkh79xPnq jCTw== 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; bh=Jx3r2seKwSeUadPVhjH4OOR8DMwWWFpbD6d3Ui5d1O8=; b=JPOIi1/pUmGiNKxAbYZOVXENmtQn8JZfiEm5EukwzybMdiNufu7iVrlH29ByiouSHJ EBEADjuuGSDIKkE+cmhLptf/5JuzfW2t+G4vd3tu5X0+LFYB/R53DnrNWSyiHIiQupDd Y4imZzBzYpVuuAivMzN0HJfBM8ul4BpJB0PPutj5H2x/CVXSv86EhoqLazB6LyU0gPDd qBB+USMeUEfkVVXVwjJBJdB09h36rNDi95HY6Dkr+lYJtj7WruCVv7qVkAC1CDly1oKF HDtiLQQUh+N+v4yKRDdSDK5m3OFNXqV7r0I66MYdgTd76BTfiH+oNebk1Fje19Sk4/qV RW4A== X-Gm-Message-State: APjAAAWXbLU/EF6Uxl7cgdB4gxbKEPS18R+r3f/DCrFGi+LZhaXMSNil gyTg1IsBXOfMA9AOgHhnRWo2yw== X-Google-Smtp-Source: APXvYqzrCCLc5US08o/zjGzN1k1QnbEN+ADAX5uJfoWSEM5Y8AvoExONDVL82wqaP4iwY2Twitnmkw== X-Received: by 2002:a17:90a:d995:: with SMTP id d21mr34127974pjv.118.1579069066564; Tue, 14 Jan 2020 22:17:46 -0800 (PST) Received: from gamma04.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id w123sm20633601pfb.167.2020.01.14.22.17.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Jan 2020 22:17:45 -0800 (PST) From: shihpo.hung@sifive.com To: qemu-riscv@nongnu.org Subject: [PATCH v3 1/3] target/riscv: Fix tb->flags FS status Date: Tue, 14 Jan 2020 22:17:31 -0800 Message-Id: <1579069053-22190-1-git-send-email-shihpo.hung@sifive.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1042 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Karandikar , Bastian Koppelmann , Richard Henderson , qemu-devel@nongnu.org, Alistair Francis , Palmer Dabbelt , ShihPo Hung Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It was found that running libquantum on riscv-linux qemu produced an incorrect result. After investigation, FP registers are not saved during context switch due to incorrect mstatus.FS. In current implementation tb->flags merges all non-disabled state to dirty. This means the code in mark_fs_dirty in translate.c that handles initial and clean states is unreachable. This patch fixes it and is successfully tested with: libquantum Thanks to Richard for pointing out the actual bug. v3: remove the redundant condition v2: root cause FS problem Suggested-by: Richard Henderson Signed-off-by: ShihPo Hung Reviewed-by: Richard Henderson --- target/riscv/cpu.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e59343e..de0a8d8 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -293,10 +293,7 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, #ifdef CONFIG_USER_ONLY *flags = TB_FLAGS_MSTATUS_FS; #else - *flags = cpu_mmu_index(env, 0); - if (riscv_cpu_fp_enabled(env)) { - *flags |= TB_FLAGS_MSTATUS_FS; - } + *flags = cpu_mmu_index(env, 0) | (env->mstatus & MSTATUS_FS); #endif }