From nobody Thu Nov 28 10:54:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694153399; cv=none; d=zohomail.com; s=zohoarc; b=CYa92Hs8SBchymoHoZdIeepelhFNURvXGRXISxFGnH916EeY/Lr8rP3jumLNzBYBdoxnkkefs7u6qBeBoUhq9FM/t1R+OM9bKfCqSRynHSxhJAoUQiRIoGTSBQER6q6TDOIwKNNn2PS6UuT/10q3B/DbTFXJ2yIyEoSIgQJNjkk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694153399; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=V2SYdMaTh5B2DYvWJCJ2xIYyu0izkkUvTM4RwQhhWt8=; b=MTis1TYH08XFj0l7szpMwGyTDvHqN8RIvG2uHYbu0e48NkNPe0sNAtYF0iXQbFuYw94/SZHk5bbAlcn0aVCK+dgZBHWzQ8OC4Tw2qhMwHrlpkK6ZNoLUCExoGiVdKXtTY8ZFeoKFItAYePSWTmzy+l4/8K6KROy1tk9+8Jz2q6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16941533999091018.5315789759957; Thu, 7 Sep 2023 23:09:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeUem-00016c-6b; Fri, 08 Sep 2023 02:07:52 -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 1qeUel-00010s-3r for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:07:51 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeUei-00086L-N3 for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:07:50 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1c1f8aaab9aso14776545ad.1 for ; Thu, 07 Sep 2023 23:07:48 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id q1-20020a170902dac100b001c3267ae31bsm715231plx.301.2023.09.07.23.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 23:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694153267; x=1694758067; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V2SYdMaTh5B2DYvWJCJ2xIYyu0izkkUvTM4RwQhhWt8=; b=sG0oBPKpeVV1CEdoq1RAQIs8XU+VqRfYzkY2q8Wv+c6oUerMzxGVlXwmb7xYowczl0 vP39mZswKcGNPbg6bTVJqwO1/UiGBUEMBvtrXYB4kaOQ0TPIVtsTiLBQwSWzH5yWqIyk +WPv6qASme3frh0KxnRzyxOPIVZK65tk0Wj8kcCZWiu4G/1ajVasItlhKAB9hl76pLmR a9pDHT3lgjzTKAR7GD6yMmfbcB6EJnLYuRqaeCVeoIIaCkKsQJ97AaFtbJNBP9cBg1qJ iIvxezniWvXQaMRSCP/huscgUsHaV/6GhTvBql2gAk2vleMHVe1t7Yo5Xr9r50VVBtVW 8DTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694153267; x=1694758067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V2SYdMaTh5B2DYvWJCJ2xIYyu0izkkUvTM4RwQhhWt8=; b=oNljDjuwJqjCQ6cvAeeVYLKspuLLgyMgzPjAjdrKIhlz4f8quOEOI83zX/qegFIKLR 6UQVFhAWXwbewaMihYZ3QIzkVgWYmepKXAWC2tXdHjh4dZciI9OWy/g8RaKJj0oXOHxf m7CTqog9X2uWHR2I+/v+UkKyoXsx3kBl5uLa7Ig16w7iJ9512GXPwGUsY6o7153H6yGS viSd6weQ/o/xqle3ppzSX1getEtgy68D63VoLhrOO7yVresxEwdd1psTiMbKzN96ix3Y zyU7m9QDPt8iLu9kY1kmHKuvoUjfvaNXydAeptnfzGwMlhaI3danVLtgowCHbycIwEyA oTyA== X-Gm-Message-State: AOJu0YzQkgh1WpNVo/rutEOmunIeqPVPmrZJGfoUCt2W7V+UR8Be/j/v p37k/pitpY9c8AKMGYO/vm4ojrWtbWOOa4Z8 X-Google-Smtp-Source: AGHT+IHj7l+i0mTgZINozOhRCYzryZLYvauDY5sDdVdEKCVKxVxZkmcuha/yRo0RJFqd3103AYlQ0Q== X-Received: by 2002:a17:902:f546:b0:1bb:7f71:df43 with SMTP id h6-20020a170902f54600b001bb7f71df43mr1796073plf.34.1694153267010; Thu, 07 Sep 2023 23:07:47 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Nikita Shubin , Alistair Francis Subject: [PULL 45/65] target/riscv: don't read CSR in riscv_csrrw_do64 Date: Fri, 8 Sep 2023 16:04:11 +1000 Message-ID: <20230908060431.1903919-46-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908060431.1903919-1-alistair.francis@wdc.com> References: <20230908060431.1903919-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=alistair23@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694153401073100009 Content-Type: text/plain; charset="utf-8" From: Nikita Shubin As per ISA: "For CSRRWI, if rd=3Dx0, then the instruction shall not read the CSR and shall not cause any of the side effects that might occur on a CSR read." trans_csrrwi() and trans_csrrw() call do_csrw() if rd=3Dx0, do_csrw() calls riscv_csrrw_do64(), via helper_csrw() passing NULL as *ret_value. Signed-off-by: Nikita Shubin Reviewed-by: Alistair Francis Message-ID: <20230808090914.17634-1-nikita.shubin@maquefel.me> Signed-off-by: Alistair Francis --- target/riscv/csr.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4a0f6a89be..e51815c448 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3917,21 +3917,27 @@ static RISCVException riscv_csrrw_do64(CPURISCVStat= e *env, int csrno, target_ulong write_mask) { RISCVException ret; - target_ulong old_value; + target_ulong old_value =3D 0; =20 /* execute combined read/write operation if it exists */ if (csr_ops[csrno].op) { return csr_ops[csrno].op(env, csrno, ret_value, new_value, write_m= ask); } =20 - /* if no accessor exists then return failure */ - if (!csr_ops[csrno].read) { - return RISCV_EXCP_ILLEGAL_INST; - } - /* read old value */ - ret =3D csr_ops[csrno].read(env, csrno, &old_value); - if (ret !=3D RISCV_EXCP_NONE) { - return ret; + /* + * ret_value =3D=3D NULL means that rd=3Dx0 and we're coming from help= er_csrw() + * and we can't throw side effects caused by CSR reads. + */ + if (ret_value) { + /* if no accessor exists then return failure */ + if (!csr_ops[csrno].read) { + return RISCV_EXCP_ILLEGAL_INST; + } + /* read old value */ + ret =3D csr_ops[csrno].read(env, csrno, &old_value); + if (ret !=3D RISCV_EXCP_NONE) { + return ret; + } } =20 /* write value if writable and write mask set, otherwise drop writes */ --=20 2.41.0