From patchwork Mon Oct 31 05:39:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 620202 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2605041pvb; Sun, 30 Oct 2022 22:42:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yzAilKji/DEjWiaA2dW8pgaVMH2lfWaCKWizw7KU2vwrATiaFgxM0AOhIHqK9vSLViZn/ X-Received: by 2002:a05:620a:191c:b0:6ed:88c5:e839 with SMTP id bj28-20020a05620a191c00b006ed88c5e839mr8007232qkb.627.1667194937227; Sun, 30 Oct 2022 22:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667194937; cv=none; d=google.com; s=arc-20160816; b=pfo8H+nTa1pq5WSEMdqPlSCa2Gt0y+9zlp3qR1bvwJvlG591UXITfJ2IE3qZ4Db/6N ZFHphqe7hWey28CeHELoyp47z3mtCZMmgJaF+p+nkLasxn/pAbl11tk8OI8lUxvLwVXV +PMWQ9uzrBKVaGdRmG5QAK6O5JBmL5SK4/zUvatgIh/TMv/GaUsvEaDl4mBf5r7KYgcb Y4+eaI1cB05PX1up1FWr/GyRncYVXqRdhvz+u/CKzFZ85rmyKppWsHp/HdqaI4h0Bfzu yvYL+MXRc3FcR4rot1GR2+HiDEvtXEesmCa25MOpagrAA1jc937mWcHszXk49S569VfX pOag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender: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=4EPNlPLvvaNZ49dHiEVCBrThmnHD1d1VYoHkcOJOcWA=; b=As/cj4J2M1jJvS6QXR5+tLQSxoqhMnbmD+kVu+rMmSL83WassXk5sO6VULJX9fbO3o j5IyBxFcRozogFL2Ao9GfNoHT5WE4zPz0hBRBGR7sF5wRMA0Rc/IV6cp5bis0uXjTC4a Zb8+qygNiEaYQdTVyAx8jK0qK94ywijbGiR67uXe38McO0KceE3hPR4rfWtIdkcA848X wJ02deMd6LmbpvlEwVdSKsNwyCwGrF9lMtmIE+xXjYwlLWh0l6Rfzc/xTt1CzW40O4Go yFDF+hwbnPkjB9XEw5MC10RQiRv8P/Ije6JU1WSSvduvgl+l51/kcHKK0lUtPWI025PJ 1ohQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lP1bUtld; 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 a8-20020a056214062800b004bbdf58cbd6si2300694qvx.475.2022.10.30.22.42.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 30 Oct 2022 22:42:17 -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=lP1bUtld; 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 1opNXO-0001hI-VX; Mon, 31 Oct 2022 01:40:42 -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 1opNXM-0001gE-Fp for qemu-devel@nongnu.org; Mon, 31 Oct 2022 01:40:40 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opNXK-00042A-Ty for qemu-devel@nongnu.org; Mon, 31 Oct 2022 01:40:40 -0400 Received: by mail-oi1-x22f.google.com with SMTP id l5so11883963oif.7 for ; Sun, 30 Oct 2022 22:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=4EPNlPLvvaNZ49dHiEVCBrThmnHD1d1VYoHkcOJOcWA=; b=lP1bUtldjz9AmUUgqlpQQ0W7J+0otT/lOdE6kXkCSj1rYI6eyb/kmT1KCYlDVDBUQy B/Z+Q6+d/8R38bPfOD9s8yGf6kgPWARk7NZmL1PGb0th5z4DOpA2gToSD94M0ztutX5l jvD021wWWLoClh5ni+X00Bj6pv9lbFDYG5bOY8x45bNgdEp836LdfVL1BzpZjhVHsqqL Qy65JGL2f0COnqWVu3xSOc94GtUMKnz54JvqKZPyV3OJlES2RqDUrsi4hYY0Js3TL5qa BDsmSSBaZIoHoIIFHV0wiibNmWjueE0QKyFjhZ8myr9+dKIQFlXizg2owOFNUOlfS3Ge T39A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4EPNlPLvvaNZ49dHiEVCBrThmnHD1d1VYoHkcOJOcWA=; b=hyja+TyxMt2wjh4mawW9tJjuTz2Xm1Jgl4/cp3J5znlVUHG1nxqbd5PJ4ld+dIVtmB WOtpwPLfrfjgB4rnPi7kDEHSUkRrALL1cva3dNRqZeMiSuOxjYfOd20pT0giuFr1/o13 vYOJgeGpIMtERcElFdGUh1CmpWtMd8tScTLgJYIIiE0vx9zyJDyxGAwMjf21S7nzG8D2 Fe+SWYh/M9+RUHe16emugooeTAeh//wMC7FqBouaQ11RL/TXSxFWFnwcC3dmSxX+x9hU CCB2bwWwL4IuvdddqO+aOb43hdivDDVU6KJQOAqjLixMz2aF52CueS5BLYDtlq34L13J 2RyA== X-Gm-Message-State: ACrzQf2oPqyPjFUlkJfhOPvVW3rfHWnNEtaC7yJ5QW1bpu11mEEmFUwn f9+6SCL8mXCwDfSb3yynK3DExoMhjay3gg== X-Received: by 2002:a05:6808:23c9:b0:359:b71b:459a with SMTP id bq9-20020a05680823c900b00359b71b459amr12135182oib.10.1667194837655; Sun, 30 Oct 2022 22:40:37 -0700 (PDT) Received: from stoup.. ([172.58.176.235]) by smtp.gmail.com with ESMTPSA id u8-20020a9d4d88000000b006618586b850sm2473857otk.46.2022.10.30.22.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 22:40:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 08/11] target/openrisc: Use cpu_unwind_state_data for mfspr Date: Mon, 31 Oct 2022 16:39:45 +1100 Message-Id: <20221031053948.3408-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221031053948.3408-1-richard.henderson@linaro.org> References: <20221031053948.3408-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22f.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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Since we do not plan to exit, use cpu_unwind_state_data and extract exactly the data requested. This is a bug fix, in that we no longer clobber dflag. Consider: l.j L2 // branch l.mfspr r1, ppc // delay L1: boom L2: l.lwa r3, (r4) Here, dflag would be set by cpu_restore_state (because that is the current state of the cpu), but but not cleared by tb_stop on exiting the TB (because DisasContext has recorded the current value as zero). The next TB begins at L2 with dflag incorrectly set. If the load has a tlb miss, then the exception will be delivered as per a delay slot: with DSX set in the status register and PC decremented (delay slots restart by re-executing the branch). This will cause the return from interrupt to go to L1, and boom! Signed-off-by: Richard Henderson --- target/openrisc/sys_helper.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index a3508e421d..dde2fa1623 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -199,6 +199,7 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd, target_ulong spr) { #ifndef CONFIG_USER_ONLY + uint64_t data[TARGET_INSN_START_WORDS]; MachineState *ms = MACHINE(qdev_get_machine()); OpenRISCCPU *cpu = env_archcpu(env); CPUState *cs = env_cpu(env); @@ -232,14 +233,20 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd, return env->evbar; case TO_SPR(0, 16): /* NPC (equals PC) */ - cpu_restore_state(cs, GETPC(), false); + if (cpu_unwind_state_data(cs, GETPC(), data)) { + return data[0]; + } return env->pc; case TO_SPR(0, 17): /* SR */ return cpu_get_sr(env); case TO_SPR(0, 18): /* PPC */ - cpu_restore_state(cs, GETPC(), false); + if (cpu_unwind_state_data(cs, GETPC(), data)) { + if (data[1] & 2) { + return data[0] - 4; + } + } return env->ppc; case TO_SPR(0, 32): /* EPCR */