From patchwork Wed Apr 12 11:43:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672609 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287257wrx; Wed, 12 Apr 2023 04:44:23 -0700 (PDT) X-Google-Smtp-Source: AKy350ZfthqU0gTThiJ/8l8yJ31zARnVRMJbmEz/N4iLr63W+997U9JoYc3KyszBrshubARMwzZz X-Received: by 2002:a05:622a:210:b0:3e4:e58c:d322 with SMTP id b16-20020a05622a021000b003e4e58cd322mr22620017qtx.35.1681299863760; Wed, 12 Apr 2023 04:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299863; cv=none; d=google.com; s=arc-20160816; b=pacaJK0TQlmGagLo/lS39e+jbuRcWpDoGX1sGfQbaNKtRO4tIln0BDmxNQshquYGnw ElHQZgdZukFZMw3f/Lz1FQuLqAjWPzLR4uYcDmgQPieqobGARigsTNWc+3+TI1OE+KOU fPj4tRB3fGHXDJ5mvJAA+CP2A7Ws7W61T6EDSewT6PtPxdZMWyI5jJHu2PTRm2twl1kl 0XhRmc+9megydAC2vSe9lKNYgt4EhKxEL7nG+3tEXcIa95xz3KonKv78Euknavb+8ZKH 7iKD/05ijri0E3GD+KSOYzBZV2NnyQ2tf1qYBbj98OTZwIBRSnU1+IrDOW/YC645IZeQ cM9Q== 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:cc:to :from:dkim-signature; bh=es1PvJYw9d2r23P0DzMd3BW6TZP7rodwja8w1R+yBl8=; b=PsP5Ve8buIBFgNeaWWw5x4WvLEf2B7thB+a3J1L7ElpJcAWe6/j45nMAVfv6P1v74r AgrHQNcE5andhOuyJnLugsyIed6I1mlEquqWcKerp28pxKVQgI4pof/HPcR5zhiWJOK2 4c78VajNIm3tKpFezSq/1nWNxDl6DPmW3bP6qQ9gJ0W2jrnIiY7/HoCRMIbrhaAqA7Jb h32QZ1CSf3j5JKgGRSDXcVnLxjxw80Jm/nQyzvDzyUJKc1xDfc3c6WWdiZ5s/6DyOhFv 9yLFTVPgedtIAtLrE5QcrCVnITGiRer1oQ7MkW9um/GIYMFfv8eM0v7Tzhlc5d1cgHkL xtDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W552nbUc; 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 b14-20020a05622a020e00b003e4eb32a4ccsi10588762qtx.347.2023.04.12.04.44.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:23 -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=W552nbUc; 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 1pmYt6-0004j5-0P; Wed, 12 Apr 2023 07:43:44 -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 1pmYt3-0004f4-Il for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:41 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt0-0002NE-NI for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:41 -0400 Received: by mail-wr1-x432.google.com with SMTP id l18so10512595wrb.9 for ; Wed, 12 Apr 2023 04:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299816; x=1683891816; 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=es1PvJYw9d2r23P0DzMd3BW6TZP7rodwja8w1R+yBl8=; b=W552nbUcyiIpxvWAZBhvSMuF18TcXEgyQL7K0GjcOm5tUVwtOjJP9jx8+UD7pnkqVX RvaHOa1VaVCa4QEsXda6aukwBZPHDbK5s4e9Vw0d3hNcxkVsuTWlfKKfCTRsA4pOY6g/ SKlpwF4XSu+LwhnvRya87ovbxfPTazDwq5+UFahXPWxuAcfRRJi7ubBMCeljt2S9eMK/ qQSx2ZRta2/ihOQzlTpz3BKBdFeC8QdNZ0AKwu/Mhp/omO6tbS6tpfRtOEmJzd0E++5f glt9i40OyGJt3aLWh+j9sqjaakFF+Y41kZ2d4jpAjX0NKkfGF0fHcDqsDW1t3tIMNc23 xmRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299816; x=1683891816; 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=es1PvJYw9d2r23P0DzMd3BW6TZP7rodwja8w1R+yBl8=; b=Lr1Cqt8pXbUDmnb8whcVbFiNZrIjb4Xm4OhnFCVNWenMppj9QtaEwHJZZl0PgC1tu/ mP82EkBx+36XCkKBx/VV11NwNNhcMwhcZWoUGIWCjE9Z2/3/HSFIXNYE/o3iAOiCHzcD 67au2gFw016ve4R9bTYUkPqhY1EGXwi7Og3b9/pCeivaMCvouzmcckS7zvlrRqAtOsFA RzwQyJl3iubfKcUycx3pKBuEjiZzNDlApHJ+tIgDZorcIoNheAOeJL4gIVFkPAvWMZvC pYp/3fuOW/TV/TlcTZJYq22wI8RmdwjFYFLDx7MvJXBLBADUSpDNbjgkFh9J5BDZhGEc Wdaw== X-Gm-Message-State: AAQBX9cQJ42CiLjeNK67h9mwBGuhC1p8Q31rpsCwSIEvs4MmI/asqsvC 519go9XldEEBhfQlyIA7OXkdGKOVvh/89RHlsrG+/Nsm X-Received: by 2002:adf:fecb:0:b0:2e5:1ee3:df77 with SMTP id q11-20020adffecb000000b002e51ee3df77mr12169128wrs.46.1681299816220; Wed, 12 Apr 2023 04:43:36 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, LIU Zhiwei , Weiwei Li , Alistair Francis , Daniel Henrique Barboza Subject: [PATCH v7 01/25] target/riscv: Extract virt enabled state from tb flags Date: Wed, 12 Apr 2023 13:43:09 +0200 Message-Id: <20230412114333.118895-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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 From: LIU Zhiwei Virt enabled state is not a constant, so we should put it into tb flags. Thus we can use it like a constant condition at translation phase. Reported-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: LIU Zhiwei Reviewed-by: Weiwei Li Message-Id: <20230324143031.1093-2-zhiwei_liu@linux.alibaba.com> Reviewed-by: Alistair Francis Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-2-richard.henderson@linaro.org> --- target/riscv/cpu.h | 2 ++ target/riscv/cpu_helper.c | 1 + target/riscv/translate.c | 10 +--------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 86e08d10da..aa53d0e256 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -648,6 +648,8 @@ FIELD(TB_FLAGS, VTA, 24, 1) FIELD(TB_FLAGS, VMA, 25, 1) /* Native debug itrigger */ FIELD(TB_FLAGS, ITRIGGER, 26, 1) +/* Virtual mode enabled */ +FIELD(TB_FLAGS, VIRT_ENABLED, 27, 1) #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 433ea529b0..1d90977d46 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -104,6 +104,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_VS, get_field(env->mstatus_hs, MSTATUS_VS)); + flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, env->virt_enabled); } if (cpu->cfg.debug && !icount_enabled()) { flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); diff --git a/target/riscv/translate.c b/target/riscv/translate.c index d0094922b6..ebd00529ff 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1171,15 +1171,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->mstatus_fs = tb_flags & TB_FLAGS_MSTATUS_FS; ctx->mstatus_vs = tb_flags & TB_FLAGS_MSTATUS_VS; ctx->priv_ver = env->priv_ver; -#if !defined(CONFIG_USER_ONLY) - if (riscv_has_ext(env, RVH)) { - ctx->virt_enabled = env->virt_enabled; - } else { - ctx->virt_enabled = false; - } -#else - ctx->virt_enabled = false; -#endif + ctx->virt_enabled = FIELD_EX32(tb_flags, TB_FLAGS, VIRT_ENABLED); ctx->misa_ext = env->misa_ext; ctx->frm = -1; /* unknown rounding mode */ ctx->cfg_ptr = &(cpu->cfg); From patchwork Wed Apr 12 11:43:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672624 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288505wrx; Wed, 12 Apr 2023 04:47:35 -0700 (PDT) X-Google-Smtp-Source: AKy350bhPUwmlRJZ+K1Ye3FUhe4KWOWzHv5CgeKPxAK2c+Pi760RxJEwpCPsK/B65tL6FwVYUqPw X-Received: by 2002:a05:622a:a:b0:3e3:93ca:42c8 with SMTP id x10-20020a05622a000a00b003e393ca42c8mr29360842qtw.67.1681300055069; Wed, 12 Apr 2023 04:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300055; cv=none; d=google.com; s=arc-20160816; b=nh8gwhva6Cdgp+wEpfjE5bWQn2IozM2IqLMQjuYMaCUgp2k0M/o5PZQedYOVMNMfMW 8wN+UZyZ8B/xabCR45ugtn434XKaeixan7N3byVDEBN9/UTu9CEsGeqaSNRW2JaAUVkj T/Ht1OfeiDQCvNFOH/155Qs+VCPMiKow/nxKogg3zF02yShTQ6AL3X/kL4RWm+cIIW+B 3oZepxuQggSGFs5r+NKJcE5tTpRVFzQrKV5LovOSQJSNJLRxsUNLwYLX6k884Ih+/Wpq 5Lhzkzd1bC3azle6tXxSyNcq3TzeSeSpenzgXPSD04bYPQir3Z70vKZC89snRMwXLo70 hZmw== 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:cc:to :from:dkim-signature; bh=sZWSjtdLuqRfAHXhQ1Qn/4gxDZYp/Ml73FoJP/ry5BM=; b=lqejp7y6GnM3mbTsdvkrsuTUPWlKo8aJnsNOscj31taFG292WHBK7y+pNhGjKPLGOI dZRcUSuyoNm3Ye3R7FkpXswOP/5paHq8p18dKyoHGPLuZ5jNJwx4PLPKf2gS/Lb5hY77 jlfWNrSk7+yolxAPMdlHNnyT8vu+QLaJnBfh492EcS5Fe5WHAFVPTF6hjOmnz0Ed0Irl hHisM4eSTeEROJh/f59WigDFDGEW/G81/Z1kdQhIxLY0Xa1Mxp5+BiWj1aCFzJ7U81U2 SdkeLzG76O8jSNJrn9FjSWUlhZ+bj/O/HnnSjINf2hxfp1jRv6eR8S74ap4XQlZeKSXy biEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zpqh7kOk; 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 u17-20020a05620a431100b007456fa51212si10769805qko.250.2023.04.12.04.47.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:47:35 -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=zpqh7kOk; 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 1pmYtC-0004u9-Ud; Wed, 12 Apr 2023 07:43:50 -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 1pmYt6-0004k4-65 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:44 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt1-0002NQ-Db for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:42 -0400 Received: by mail-wr1-x430.google.com with SMTP id e7so493582wrc.12 for ; Wed, 12 Apr 2023 04:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299817; x=1683891817; 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=sZWSjtdLuqRfAHXhQ1Qn/4gxDZYp/Ml73FoJP/ry5BM=; b=zpqh7kOkoha8JhKb8g6iNhXDgtTC5gVB1VnvX3BxHnU+cYFLT6D2R1NFVydFAqm0yA eRGva3gmlWbKGZAPpDWsXHHKW4Gjw2p0PvqEEvwqgc1ND3q3IGkp0njS7U5Q1ClLZSy3 RiIVBc4JVY8wPe4h/YmX0VWygaRV9WTN3x8X1ISiJp54+rgNtN5SvlZ4qTNCMXyYarmq q6RcX0og6WA8/rDTOZA4C22iNXQIeZWWXnd/sfxE85VqwqpUX3vsufs8zea+IDSrey8g B6lwAKgtn31TkxxGoCjnA8KYd7eVHXQl1u1/91DbYh70K/2+Hk5kd+XUuPPeZYDw+o5v uz3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299817; x=1683891817; 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=sZWSjtdLuqRfAHXhQ1Qn/4gxDZYp/Ml73FoJP/ry5BM=; b=kemPkLAtFYYdrPIfCypguYCUbjyGUyNjzYUS0RXW6SNCSmqeVKt2Q1QLnu8H1r7Y2f tZ8XELf0iyNJypi0RjaM63VaXVbT/wZYSCG7KyDquwUKmK+7lz8KYFXHcS+eK0GVEhDI Yia6pyp1xD4jVsi1ZZ1HuFtY5+wcJlFNAlFRoMFEfuFOzO1XXqH7scOthzKNnPSy9/T/ /wvcBXy2juG/gpaJgWq8PBxOE1RzHLABLrnBB1QV7cifKdEZ0yiY/koyKlRDgpPAwKlL ih7URfFuFgRVpVUvW2bL88EIXncxi/A8sjLPeV88hl/LNT267DzepXfpRVNF7neu60UI zZvw== X-Gm-Message-State: AAQBX9dS2WIdpMV8y/jYbSYsavGMWSrFEAqLuWsPjzc1B9QxJ3jPb3AI 9MasH7YWEDyBlO21jimYucWbv7MNln/3tqUCngwJ7cO6 X-Received: by 2002:a5d:4564:0:b0:2ef:ba74:44c2 with SMTP id a4-20020a5d4564000000b002efba7444c2mr1748824wrc.2.1681299817039; Wed, 12 Apr 2023 04:43:37 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, LIU Zhiwei , Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 02/25] target/riscv: Add a general status enum for extensions Date: Wed, 12 Apr 2023 13:43:10 +0200 Message-Id: <20230412114333.118895-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x430.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=unavailable 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 From: LIU Zhiwei The pointer masking is the only extension that directly use status. The vector or float extension uses the status in an indirect way. Replace the pointer masking extension special status fields with the general status. Reviewed-by: Richard Henderson Signed-off-by: LIU Zhiwei Message-Id: <20230324143031.1093-3-zhiwei_liu@linux.alibaba.com> [rth: Add a typedef for the enum] Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-3-richard.henderson@linaro.org> --- target/riscv/cpu.h | 8 ++++++++ target/riscv/cpu_bits.h | 12 ++++-------- target/riscv/cpu.c | 2 +- target/riscv/csr.c | 14 +++++++------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index aa53d0e256..ba11279716 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -97,6 +97,14 @@ enum { TRANSLATE_G_STAGE_FAIL }; +/* Extension context status */ +typedef enum { + EXT_STATUS_DISABLED = 0, + EXT_STATUS_INITIAL, + EXT_STATUS_CLEAN, + EXT_STATUS_DIRTY, +} RISCVExtStatus; + #define MMU_USER_IDX 3 #define MAX_RISCV_PMPS (16) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index a16bfaf43f..fb63b8e125 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -9,6 +9,9 @@ (((uint64_t)(val) * ((mask) & ~((mask) << 1))) & \ (uint64_t)(mask))) +/* Extension context status mask */ +#define EXT_STATUS_MASK 0x3ULL + /* Floating point round mode */ #define FSR_RD_SHIFT 5 #define FSR_RD (0x7 << FSR_RD_SHIFT) @@ -735,13 +738,6 @@ typedef enum RISCVException { #define PM_ENABLE 0x00000001ULL #define PM_CURRENT 0x00000002ULL #define PM_INSN 0x00000004ULL -#define PM_XS_MASK 0x00000003ULL - -/* PointerMasking XS bits values */ -#define PM_EXT_DISABLE 0x00000000ULL -#define PM_EXT_INITIAL 0x00000001ULL -#define PM_EXT_CLEAN 0x00000002ULL -#define PM_EXT_DIRTY 0x00000003ULL /* Execution enviornment configuration bits */ #define MENVCFG_FIOM BIT(0) @@ -781,7 +777,7 @@ typedef enum RISCVException { #define S_OFFSET 5ULL #define M_OFFSET 8ULL -#define PM_XS_BITS (PM_XS_MASK << XS_OFFSET) +#define PM_XS_BITS (EXT_STATUS_MASK << XS_OFFSET) #define U_PM_ENABLE (PM_ENABLE << U_OFFSET) #define U_PM_CURRENT (PM_CURRENT << U_OFFSET) #define U_PM_INSN (PM_INSN << U_OFFSET) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index fab38859ec..32c04214a1 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -759,7 +759,7 @@ static void riscv_cpu_reset_hold(Object *obj) i++; } /* mmte is supposed to have pm.current hardwired to 1 */ - env->mmte |= (PM_EXT_INITIAL | MMTE_M_PM_CURRENT); + env->mmte |= (EXT_STATUS_INITIAL | MMTE_M_PM_CURRENT); #endif env->xl = riscv_cpu_mxl(env); riscv_cpu_update_mask(env); diff --git a/target/riscv/csr.c b/target/riscv/csr.c index f4d2dcfdc8..4268828dc4 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3534,7 +3534,7 @@ static RISCVException write_mmte(CPURISCVState *env, int csrno, /* hardwiring pm.instruction bit to 0, since it's not supported yet */ wpri_val &= ~(MMTE_M_PM_INSN | MMTE_S_PM_INSN | MMTE_U_PM_INSN); - env->mmte = wpri_val | PM_EXT_DIRTY; + env->mmte = wpri_val | EXT_STATUS_DIRTY; riscv_cpu_update_mask(env); /* Set XS and SD bits, since PM CSRs are dirty */ @@ -3614,7 +3614,7 @@ static RISCVException write_mpmmask(CPURISCVState *env, int csrno, if ((env->priv == PRV_M) && (env->mmte & M_PM_ENABLE)) { env->cur_pmmask = val; } - env->mmte |= PM_EXT_DIRTY; + env->mmte |= EXT_STATUS_DIRTY; /* Set XS and SD bits, since PM CSRs are dirty */ mstatus = env->mstatus | MSTATUS_XS; @@ -3642,7 +3642,7 @@ static RISCVException write_spmmask(CPURISCVState *env, int csrno, if ((env->priv == PRV_S) && (env->mmte & S_PM_ENABLE)) { env->cur_pmmask = val; } - env->mmte |= PM_EXT_DIRTY; + env->mmte |= EXT_STATUS_DIRTY; /* Set XS and SD bits, since PM CSRs are dirty */ mstatus = env->mstatus | MSTATUS_XS; @@ -3670,7 +3670,7 @@ static RISCVException write_upmmask(CPURISCVState *env, int csrno, if ((env->priv == PRV_U) && (env->mmte & U_PM_ENABLE)) { env->cur_pmmask = val; } - env->mmte |= PM_EXT_DIRTY; + env->mmte |= EXT_STATUS_DIRTY; /* Set XS and SD bits, since PM CSRs are dirty */ mstatus = env->mstatus | MSTATUS_XS; @@ -3694,7 +3694,7 @@ static RISCVException write_mpmbase(CPURISCVState *env, int csrno, if ((env->priv == PRV_M) && (env->mmte & M_PM_ENABLE)) { env->cur_pmbase = val; } - env->mmte |= PM_EXT_DIRTY; + env->mmte |= EXT_STATUS_DIRTY; /* Set XS and SD bits, since PM CSRs are dirty */ mstatus = env->mstatus | MSTATUS_XS; @@ -3722,7 +3722,7 @@ static RISCVException write_spmbase(CPURISCVState *env, int csrno, if ((env->priv == PRV_S) && (env->mmte & S_PM_ENABLE)) { env->cur_pmbase = val; } - env->mmte |= PM_EXT_DIRTY; + env->mmte |= EXT_STATUS_DIRTY; /* Set XS and SD bits, since PM CSRs are dirty */ mstatus = env->mstatus | MSTATUS_XS; @@ -3750,7 +3750,7 @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, if ((env->priv == PRV_U) && (env->mmte & U_PM_ENABLE)) { env->cur_pmbase = val; } - env->mmte |= PM_EXT_DIRTY; + env->mmte |= EXT_STATUS_DIRTY; /* Set XS and SD bits, since PM CSRs are dirty */ mstatus = env->mstatus | MSTATUS_XS; From patchwork Wed Apr 12 11:43:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672619 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288252wrx; Wed, 12 Apr 2023 04:46:55 -0700 (PDT) X-Google-Smtp-Source: AKy350Zu6ts0ELSGiZZhd0D+KI5G+LN3RaVTT1mOcQwA74cIMx9LLi4z92Hg363Mw1VUhNlTLGdk X-Received: by 2002:a05:6214:d81:b0:5ee:e4b2:d95b with SMTP id e1-20020a0562140d8100b005eee4b2d95bmr2889084qve.50.1681300014854; Wed, 12 Apr 2023 04:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300014; cv=none; d=google.com; s=arc-20160816; b=YVPJLFJmr+cchF5dKG4GxlT87D5tIJ2DUboCpYw/jgFMi6RxSTz97lCpmDQoWO97K9 sAj8o/9GBHBNrpzEPLUTwjVcclfD033/BD/9ngdiZTugocZnX5s/WyxGuelAIL3RlSIf bCr+pQp1e4uhcVuFEscB3ztgnJWPxLTJjXR5xadsnR02RzMbGpguunSaYYVRkusjiCWl 3Ki3fjVOxoaMtQybA9q184UzYb2DZyAamdzCVrPMbkw9B16/Xul2NhhGyl4hzIw/Rzhs gQfq5u0w0JKsTjfRJRuoJT7UcCv0FRRFx6nYek87Ph9Riz/nQSbUJeKs83xS3uNGn1ml rnlw== 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:cc:to :from:dkim-signature; bh=EKbGyzdb6cvD2agcBZ2QYZh6VK7dmyekZkQ2foWy+l8=; b=nWzOCJM6+/ml1KX/CWTr0vfpp4D8KfjYAI8IiRPzWAzym0zWTaa5pgLERAyJRKP3qw gUncQk7chbhapxPBEi9jydJCZdbXc7MpgAtP2sxe96TnPxoZ1Qzzs5oWKMY/NFIROEL/ PHSd20CFAbLWKASC6aDnfuN/grClsjt5vN+Y5E7LisjrDs0dWQgFnORBYkS/T0qRGGFz ctG/ZNt1F9sYA/iNIWqbvWQBDaNfWIFI0JZgScHcJOJqMrUEVqJDNNWpBaPtU/RsDTmq Zy9VcFH8cRhWLzBI1lzt/xLo6QiHVkYcoEU/5TTvP7E+gHNsh9p9xeh2AlomXUvDw5L1 X+Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ymQZcciH; 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 19-20020ac85753000000b003e4e46f881asi10470050qtx.611.2023.04.12.04.46.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:46:54 -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=ymQZcciH; 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 1pmYtC-0004sX-NB; Wed, 12 Apr 2023 07:43:50 -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 1pmYt6-0004k3-5p for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:44 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt3-0002Nb-9K for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:43 -0400 Received: by mail-wr1-x432.google.com with SMTP id i3so1256767wrc.4 for ; Wed, 12 Apr 2023 04:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299818; x=1683891818; 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=EKbGyzdb6cvD2agcBZ2QYZh6VK7dmyekZkQ2foWy+l8=; b=ymQZcciH+u37PRMsU3Wcipl5CA7nVULsKwNKHjqCc4JdXQCa5diPsXjgEjpyetRc70 5Ns6tXzLNv5DTk1Z1q16GeDS52HDPYTexFysvWoQc1UH73As2Qzf+aaNzSftlFoudo5p bZNMm8EboEdCQ77qtHH56M9kRexXcdYpLGeUtINOfM0TVgYHvZeqYNQCMoY5G+0fofFj UpJz3gw24eXem84/1sEm+ylQcVpgB2yoPM+kaIpIhffRQxtjRMKUBp5rWJQsvQLW3kUN gpougmr6s7BI1D+HmcJD/X46wRl9uP0PzLxlS5ncMXFCVIIOH8r8fxqdcOUBVDUClHJl qEdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299818; x=1683891818; 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=EKbGyzdb6cvD2agcBZ2QYZh6VK7dmyekZkQ2foWy+l8=; b=zFED0FUyP0AROIA/wPqfQ/pDcWeGJoXHUnQJI+WQkR8EdwJzSMq/OWfCtXLjgBIiTs bouUmBwYe/+C7HtwwQH2KzhsYTga3W7Mngcp1b+2m0t9bDqZknoxsGWwtFmrjXubRWQF uaH5IWuC6rRPX1g9R9xWk6i11rJfbLlF032TjMIdY3h8cRQQ0Bxmp0V7+GjaHNuQalnq yqGlW1P3cnPqIdsa6Cg6CY7sb9bMGCutX6Gf3QDgfQ17eqR2lx6MDC0T4voUnN59Lb6M UBGbOZDTuZYNf6zII4Pg/rGjvGJcDrIq+v/jyFxWYnwdlC/EOMVHPFlI/05fKDJEr70I DkPg== X-Gm-Message-State: AAQBX9fH8eVKu6sl1PLN9qXWRcFnfgVWhEsiLt9ZnFSUtgpritIlSkkv Rb9kvIbErJViBb74YMHzUwkfhk4+PjAiInnvCQ8gXxOF X-Received: by 2002:adf:ef4d:0:b0:2ef:e73d:605d with SMTP id c13-20020adfef4d000000b002efe73d605dmr1629175wrp.30.1681299817778; Wed, 12 Apr 2023 04:43:37 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, LIU Zhiwei , Weiwei Li , Alistair Francis , Daniel Henrique Barboza Subject: [PATCH v7 03/25] target/riscv: Encode the FS and VS on a normal way for tb flags Date: Wed, 12 Apr 2023 13:43:11 +0200 Message-Id: <20230412114333.118895-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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=unavailable 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 From: LIU Zhiwei Reuse the MSTATUS_FS and MSTATUS_VS for the tb flags positions is not a normal way. It will make it hard to change the tb flags layout. And even worse, if we want to keep tb flags for a same extension togather without a hole. Reviewed-by: Richard Henderson Signed-off-by: LIU Zhiwei Reviewed-by: Weiwei Li Message-Id: <20230324143031.1093-4-zhiwei_liu@linux.alibaba.com> [rth: Adjust trans_rvf.c.inc as well; use the typedef] Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-4-richard.henderson@linaro.org> --- target/riscv/cpu.h | 15 ++++++------ target/riscv/cpu_helper.c | 11 +++++---- target/riscv/translate.c | 32 +++++++++++-------------- target/riscv/insn_trans/trans_rvf.c.inc | 2 +- target/riscv/insn_trans/trans_rvv.c.inc | 8 +++---- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ba11279716..51d39687fe 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -631,18 +631,17 @@ void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); #define TB_FLAGS_PRIV_MMU_MASK 3 #define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2) -#define TB_FLAGS_MSTATUS_FS MSTATUS_FS -#define TB_FLAGS_MSTATUS_VS MSTATUS_VS #include "exec/cpu-all.h" FIELD(TB_FLAGS, MEM_IDX, 0, 3) -FIELD(TB_FLAGS, LMUL, 3, 3) -FIELD(TB_FLAGS, SEW, 6, 3) -/* Skip MSTATUS_VS (0x600) bits */ -FIELD(TB_FLAGS, VL_EQ_VLMAX, 11, 1) -FIELD(TB_FLAGS, VILL, 12, 1) -/* Skip MSTATUS_FS (0x6000) bits */ +FIELD(TB_FLAGS, FS, 3, 2) +/* Vector flags */ +FIELD(TB_FLAGS, VS, 5, 2) +FIELD(TB_FLAGS, LMUL, 7, 3) +FIELD(TB_FLAGS, SEW, 10, 3) +FIELD(TB_FLAGS, VL_EQ_VLMAX, 13, 1) +FIELD(TB_FLAGS, VILL, 14, 1) /* Is a Hypervisor instruction load/store allowed? */ FIELD(TB_FLAGS, HLSX, 15, 1) FIELD(TB_FLAGS, MSTATUS_HS_FS, 16, 2) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 1d90977d46..8412ef26ee 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -79,16 +79,17 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, } #ifdef CONFIG_USER_ONLY - flags |= TB_FLAGS_MSTATUS_FS; - flags |= TB_FLAGS_MSTATUS_VS; + flags = FIELD_DP32(flags, TB_FLAGS, FS, EXT_STATUS_DIRTY); + flags = FIELD_DP32(flags, TB_FLAGS, VS, EXT_STATUS_DIRTY); #else flags |= cpu_mmu_index(env, 0); if (riscv_cpu_fp_enabled(env)) { - flags |= env->mstatus & MSTATUS_FS; + flags = FIELD_DP32(flags, TB_FLAGS, FS, + get_field(env->mstatus, MSTATUS_FS)); } - if (riscv_cpu_vector_enabled(env)) { - flags |= env->mstatus & MSTATUS_VS; + flags = FIELD_DP32(flags, TB_FLAGS, VS, + get_field(env->mstatus, MSTATUS_VS)); } if (riscv_has_ext(env, RVH)) { diff --git a/target/riscv/translate.c b/target/riscv/translate.c index ebd00529ff..411e771e6f 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -64,10 +64,10 @@ typedef struct DisasContext { RISCVMXL xl; uint32_t misa_ext; uint32_t opcode; - uint32_t mstatus_fs; - uint32_t mstatus_vs; - uint32_t mstatus_hs_fs; - uint32_t mstatus_hs_vs; + RISCVExtStatus mstatus_fs; + RISCVExtStatus mstatus_vs; + RISCVExtStatus mstatus_hs_fs; + RISCVExtStatus mstatus_hs_vs; uint32_t mem_idx; /* * Remember the rounding mode encoded in the previous fp instruction, @@ -601,8 +601,6 @@ static TCGv get_address_indexed(DisasContext *ctx, int rs1, TCGv offs) #ifndef CONFIG_USER_ONLY /* - * The states of mstatus_fs are: - * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty * We will have already diagnosed disabled state, * and need to turn initial/clean into dirty. */ @@ -614,9 +612,9 @@ static void mark_fs_dirty(DisasContext *ctx) return; } - if (ctx->mstatus_fs != MSTATUS_FS) { + if (ctx->mstatus_fs != EXT_STATUS_DIRTY) { /* Remember the state change for the rest of the TB. */ - ctx->mstatus_fs = MSTATUS_FS; + ctx->mstatus_fs = EXT_STATUS_DIRTY; tmp = tcg_temp_new(); tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); @@ -624,9 +622,9 @@ static void mark_fs_dirty(DisasContext *ctx) tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); } - if (ctx->virt_enabled && ctx->mstatus_hs_fs != MSTATUS_FS) { + if (ctx->virt_enabled && ctx->mstatus_hs_fs != EXT_STATUS_DIRTY) { /* Remember the stage change for the rest of the TB. */ - ctx->mstatus_hs_fs = MSTATUS_FS; + ctx->mstatus_hs_fs = EXT_STATUS_DIRTY; tmp = tcg_temp_new(); tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); @@ -640,8 +638,6 @@ static inline void mark_fs_dirty(DisasContext *ctx) { } #ifndef CONFIG_USER_ONLY /* - * The states of mstatus_vs are: - * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty * We will have already diagnosed disabled state, * and need to turn initial/clean into dirty. */ @@ -649,9 +645,9 @@ static void mark_vs_dirty(DisasContext *ctx) { TCGv tmp; - if (ctx->mstatus_vs != MSTATUS_VS) { + if (ctx->mstatus_vs != EXT_STATUS_DIRTY) { /* Remember the state change for the rest of the TB. */ - ctx->mstatus_vs = MSTATUS_VS; + ctx->mstatus_vs = EXT_STATUS_DIRTY; tmp = tcg_temp_new(); tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); @@ -659,9 +655,9 @@ static void mark_vs_dirty(DisasContext *ctx) tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); } - if (ctx->virt_enabled && ctx->mstatus_hs_vs != MSTATUS_VS) { + if (ctx->virt_enabled && ctx->mstatus_hs_vs != EXT_STATUS_DIRTY) { /* Remember the stage change for the rest of the TB. */ - ctx->mstatus_hs_vs = MSTATUS_VS; + ctx->mstatus_hs_vs = EXT_STATUS_DIRTY; tmp = tcg_temp_new(); tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); @@ -1168,8 +1164,8 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->pc_succ_insn = ctx->base.pc_first; ctx->mem_idx = FIELD_EX32(tb_flags, TB_FLAGS, MEM_IDX); - ctx->mstatus_fs = tb_flags & TB_FLAGS_MSTATUS_FS; - ctx->mstatus_vs = tb_flags & TB_FLAGS_MSTATUS_VS; + ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS); + ctx->mstatus_vs = FIELD_EX32(tb_flags, TB_FLAGS, VS); ctx->priv_ver = env->priv_ver; ctx->virt_enabled = FIELD_EX32(tb_flags, TB_FLAGS, VIRT_ENABLED); ctx->misa_ext = env->misa_ext; diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc index 9e9fa2087a..b2de4fcf3f 100644 --- a/target/riscv/insn_trans/trans_rvf.c.inc +++ b/target/riscv/insn_trans/trans_rvf.c.inc @@ -19,7 +19,7 @@ */ #define REQUIRE_FPU do {\ - if (ctx->mstatus_fs == 0) \ + if (ctx->mstatus_fs == EXT_STATUS_DISABLED) \ if (!ctx->cfg_ptr->ext_zfinx) \ return false; \ } while (0) diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc index ca3c4c1a3d..ecbdf1b3d7 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -29,12 +29,12 @@ static inline bool is_overlapped(const int8_t astart, int8_t asize, static bool require_rvv(DisasContext *s) { - return s->mstatus_vs != 0; + return s->mstatus_vs != EXT_STATUS_DISABLED; } static bool require_rvf(DisasContext *s) { - if (s->mstatus_fs == 0) { + if (s->mstatus_fs == EXT_STATUS_DISABLED) { return false; } @@ -52,7 +52,7 @@ static bool require_rvf(DisasContext *s) static bool require_scale_rvf(DisasContext *s) { - if (s->mstatus_fs == 0) { + if (s->mstatus_fs == EXT_STATUS_DISABLED) { return false; } @@ -70,7 +70,7 @@ static bool require_scale_rvf(DisasContext *s) static bool require_scale_rvfmin(DisasContext *s) { - if (s->mstatus_fs == 0) { + if (s->mstatus_fs == EXT_STATUS_DISABLED) { return false; } From patchwork Wed Apr 12 11:43:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672610 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287284wrx; Wed, 12 Apr 2023 04:44:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bBl46D6/sKoquFEYVt7TsCtZyophrudP02rbkwZ8Cp4z2oCbb1iasCRdkDwLEVuMxUxG2t X-Received: by 2002:a05:622a:164d:b0:3c0:3b08:2d80 with SMTP id y13-20020a05622a164d00b003c03b082d80mr27779069qtj.63.1681299867342; Wed, 12 Apr 2023 04:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299867; cv=none; d=google.com; s=arc-20160816; b=XpU35JF8kT/AhiSYo149nHZmJ3LBVIyT/Yf4TMc5V6/dgZkTrv9ulIIbv0WJX8+8Wi 8D4jVCKYQyeFidj0GRwwoEWGfzkF1wIcy/q8xJeJjp3kigB1MJ6zicOGW9Q6r6LaSwBw WjPBA7OJ3S8IdS7RqJdvboKft0Oms6Dnf9RvWS8UiUtJjGm8J8dQnE5nkEU6uuQnNbht WzheL6VFKeTyg+omJrry37KiKtIEqtLIp3/ozM5hjNXOLOm4jKY/XhoMjrIlgAYxL7Hb 99YVcnArst62J0w/P1A8Gvyvi8zlCLQ6XBt0wKPhDJ7uw30QpqcCkY9oxJYin7O50T9o VIKQ== 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:cc:to :from:dkim-signature; bh=HVh+zRIWjFC/l6dDWYElki++Cx2rWrykEl8ZmED7Ed8=; b=Weds0DYtOfeUZsJJ7jlgHCSdDxGAAXMGAbcKVo6NjtoelR4PXnCXOTBts3O7RmExMc c67WOtfcgh9zcsmPY7Z7nUDqzMaUfdGnBoyoNHMn46PYtZB/Se4Rw/3m/W/mJhPMvLFm 9A6qNXUDL0V2dxRXOKC8XsTKsS6RETY6xVRP/jCfcSVQR787UXSuzksHGaSYXKkvhK8m V7pmDmOoMxkigjxyzhF+Wi9qh31DrPAMLdPlKb2JaSXvd8pl+rsCXYELNVP+VA/jdPyU g8Xjveeq+gtj3BJ6fOKbyc4wKCAFyujFxWa1c94dvRWDArclW4St55uTb5vxvsLgDQsD UGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YaXR6NLh; 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 x7-20020a376307000000b0074abf1b87f4si1122197qkb.307.2023.04.12.04.44.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:27 -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=YaXR6NLh; 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 1pmYtJ-0004wu-FV; Wed, 12 Apr 2023 07:43:57 -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 1pmYt8-0004ki-6v for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:47 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt3-0002Nq-Ay for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:44 -0400 Received: by mail-wr1-x431.google.com with SMTP id d9so10668174wrb.11 for ; Wed, 12 Apr 2023 04:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299819; x=1683891819; 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=HVh+zRIWjFC/l6dDWYElki++Cx2rWrykEl8ZmED7Ed8=; b=YaXR6NLhUnlhFhTFwv7nDOMCXYgU3nYRjTq9B1DYQ+cJqZbRxManFIGWPSkttA7HJS ZWdwnWOF3gEKuYsHzPVFLXpbOjmko6zdhCqr6VCE1dIkbPicPjUfrbYyq4aLfaRnWYWT Drbhg7KM7ev1mL0z1aBgNso9h6xOXNJyhEao0NsOUDV50yEspegRRBqZvui6AureN6FA QD+AopDjNIh5gCWPf2EdneCKVsj4NXK5YEWBIXziffAnDfT30HW/t8IJI1enOD2A33Ev SCWnjcTKUXlFOIly1hqpbAPp9b1xO9rcFTA3HYRJVfQOb4nO4Bsd2XiAF58bPtszw7v4 nBTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299819; x=1683891819; 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=HVh+zRIWjFC/l6dDWYElki++Cx2rWrykEl8ZmED7Ed8=; b=fF04NbfN4vpc8bMGsI/+9fCXtpdxW7Oouk0Ei27EnehqfJQLhh8oFUorlVoQpgqIQE B9xRtAbBJqTv3iJK9pZ5CBuAiVlJXlG3xQEGrXTZhg6fDSzJlghg0zgYJxLGqe4YA9lm 0MazShE0j48JACnrqkGEB2YQuc4e3bsdcIDGbmRk5qFPDwuc96h/1VoFumaIWMgNG5pt j1ZsnBkmosiaHBgN/Zmj92nYJ5Vz0brLIGOB0ntRrIbjXureuPjMPklTbwdWRmpttq13 Dq2PEgkBbIC0hRAlm5HqXFNPjLvdmH9msvC3UlU9WUXvxymlzqJBGPN4HKElfuYzLOLU +b4w== X-Gm-Message-State: AAQBX9fK+HUlPDKP8gV+54QvEH8BK5BXRmIc9/M7jYaNjNBt05fsi4n6 W2HEanCRJtRjV9mcM987ZJAEgm9etkrR+Vycn3n6bj6n X-Received: by 2002:a5d:61c8:0:b0:2f4:cf53:c961 with SMTP id q8-20020a5d61c8000000b002f4cf53c961mr878137wrv.54.1681299818713; Wed, 12 Apr 2023 04:43:38 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, LIU Zhiwei , Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 04/25] target/riscv: Remove mstatus_hs_{fs, vs} from tb_flags Date: Wed, 12 Apr 2023 13:43:12 +0200 Message-Id: <20230412114333.118895-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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=unavailable 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 Merge with mstatus_{fs,vs}. We might perform a redundant assignment to one or the other field, but it's a trivial and saves 4 bits from TB_FLAGS. Signed-off-by: Richard Henderson Reviewed-by: LIU Zhiwei Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-5-richard.henderson@linaro.org> --- target/riscv/cpu.h | 16 +++++++--------- target/riscv/cpu_helper.c | 33 ++++++++++++++++----------------- target/riscv/translate.c | 32 ++++++++++---------------------- 3 files changed, 33 insertions(+), 48 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 51d39687fe..ab64d5f92d 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -644,19 +644,17 @@ FIELD(TB_FLAGS, VL_EQ_VLMAX, 13, 1) FIELD(TB_FLAGS, VILL, 14, 1) /* Is a Hypervisor instruction load/store allowed? */ FIELD(TB_FLAGS, HLSX, 15, 1) -FIELD(TB_FLAGS, MSTATUS_HS_FS, 16, 2) -FIELD(TB_FLAGS, MSTATUS_HS_VS, 18, 2) /* The combination of MXL/SXL/UXL that applies to the current cpu mode. */ -FIELD(TB_FLAGS, XL, 20, 2) +FIELD(TB_FLAGS, XL, 16, 2) /* If PointerMasking should be applied */ -FIELD(TB_FLAGS, PM_MASK_ENABLED, 22, 1) -FIELD(TB_FLAGS, PM_BASE_ENABLED, 23, 1) -FIELD(TB_FLAGS, VTA, 24, 1) -FIELD(TB_FLAGS, VMA, 25, 1) +FIELD(TB_FLAGS, PM_MASK_ENABLED, 18, 1) +FIELD(TB_FLAGS, PM_BASE_ENABLED, 19, 1) +FIELD(TB_FLAGS, VTA, 20, 1) +FIELD(TB_FLAGS, VMA, 21, 1) /* Native debug itrigger */ -FIELD(TB_FLAGS, ITRIGGER, 26, 1) +FIELD(TB_FLAGS, ITRIGGER, 22, 1) /* Virtual mode enabled */ -FIELD(TB_FLAGS, VIRT_ENABLED, 27, 1) +FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 8412ef26ee..e3e620137b 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -45,7 +45,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, { CPUState *cs = env_cpu(env); RISCVCPU *cpu = RISCV_CPU(cs); - + RISCVExtStatus fs, vs; uint32_t flags = 0; *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; @@ -79,18 +79,12 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, } #ifdef CONFIG_USER_ONLY - flags = FIELD_DP32(flags, TB_FLAGS, FS, EXT_STATUS_DIRTY); - flags = FIELD_DP32(flags, TB_FLAGS, VS, EXT_STATUS_DIRTY); + fs = EXT_STATUS_DIRTY; + vs = EXT_STATUS_DIRTY; #else flags |= cpu_mmu_index(env, 0); - if (riscv_cpu_fp_enabled(env)) { - flags = FIELD_DP32(flags, TB_FLAGS, FS, - get_field(env->mstatus, MSTATUS_FS)); - } - if (riscv_cpu_vector_enabled(env)) { - flags = FIELD_DP32(flags, TB_FLAGS, VS, - get_field(env->mstatus, MSTATUS_VS)); - } + fs = get_field(env->mstatus, MSTATUS_FS); + vs = get_field(env->mstatus, MSTATUS_VS); if (riscv_has_ext(env, RVH)) { if (env->priv == PRV_M || @@ -100,18 +94,23 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1); } - flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS, - get_field(env->mstatus_hs, MSTATUS_FS)); - - flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_VS, - get_field(env->mstatus_hs, MSTATUS_VS)); - flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, env->virt_enabled); + if (env->virt_enabled) { + flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, 1); + /* + * Merge DISABLED and !DIRTY states using MIN. + * We will set both fields when dirtying. + */ + fs = MIN(fs, get_field(env->mstatus_hs, MSTATUS_FS)); + vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS)); + } } if (cpu->cfg.debug && !icount_enabled()) { flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); } #endif + flags = FIELD_DP32(flags, TB_FLAGS, FS, fs); + flags = FIELD_DP32(flags, TB_FLAGS, VS, vs); flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl); if (env->cur_pmmask < (env->xl == MXL_RV32 ? UINT32_MAX : UINT64_MAX)) { flags = FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1); diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 411e771e6f..3092c942ab 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -66,8 +66,6 @@ typedef struct DisasContext { uint32_t opcode; RISCVExtStatus mstatus_fs; RISCVExtStatus mstatus_vs; - RISCVExtStatus mstatus_hs_fs; - RISCVExtStatus mstatus_hs_vs; uint32_t mem_idx; /* * Remember the rounding mode encoded in the previous fp instruction, @@ -620,16 +618,12 @@ static void mark_fs_dirty(DisasContext *ctx) tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS); tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); - } - if (ctx->virt_enabled && ctx->mstatus_hs_fs != EXT_STATUS_DIRTY) { - /* Remember the stage change for the rest of the TB. */ - ctx->mstatus_hs_fs = EXT_STATUS_DIRTY; - - tmp = tcg_temp_new(); - tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS); - tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); + if (ctx->virt_enabled) { + tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS); + tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); + } } } #else @@ -653,16 +647,12 @@ static void mark_vs_dirty(DisasContext *ctx) tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); tcg_gen_ori_tl(tmp, tmp, MSTATUS_VS); tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); - } - if (ctx->virt_enabled && ctx->mstatus_hs_vs != EXT_STATUS_DIRTY) { - /* Remember the stage change for the rest of the TB. */ - ctx->mstatus_hs_vs = EXT_STATUS_DIRTY; - - tmp = tcg_temp_new(); - tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); - tcg_gen_ori_tl(tmp, tmp, MSTATUS_VS); - tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); + if (ctx->virt_enabled) { + tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); + tcg_gen_ori_tl(tmp, tmp, MSTATUS_VS); + tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); + } } } #else @@ -1171,8 +1161,6 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa_ext = env->misa_ext; ctx->frm = -1; /* unknown rounding mode */ ctx->cfg_ptr = &(cpu->cfg); - ctx->mstatus_hs_fs = FIELD_EX32(tb_flags, TB_FLAGS, MSTATUS_HS_FS); - ctx->mstatus_hs_vs = FIELD_EX32(tb_flags, TB_FLAGS, MSTATUS_HS_VS); ctx->hlsx = FIELD_EX32(tb_flags, TB_FLAGS, HLSX); ctx->vill = FIELD_EX32(tb_flags, TB_FLAGS, VILL); ctx->sew = FIELD_EX32(tb_flags, TB_FLAGS, SEW); From patchwork Wed Apr 12 11:43:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672614 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287481wrx; Wed, 12 Apr 2023 04:44:58 -0700 (PDT) X-Google-Smtp-Source: AKy350YSk90U05D4tNuoREHpxj0eiHsRZ3ed3KXITW47OZv0POhYpCClPH+a8x9folCy8zW8KQIB X-Received: by 2002:ac8:5b56:0:b0:3e6:459c:1312 with SMTP id n22-20020ac85b56000000b003e6459c1312mr24977452qtw.11.1681299897869; Wed, 12 Apr 2023 04:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299897; cv=none; d=google.com; s=arc-20160816; b=tytBIH8eQgvgKpbQ8T9j+9xpM9xsm4nwcqGnJ9rA7BRpKPHjlS0zqF4Lem4/LlXmV8 37u0zjfL0OolBl/PJe0NFQb3P5r0BC9qvTloebVr3G6ZGFEczwfYLGJTv1l15OfSRyLU OlbfE35ygZZUkVD/kbj223Ep3SKHuJ6Hz82X3pjJQoGgld7OT2kM4Pp+Ah9pMPzxaS6W NQMc25JS6HayyM22IewCEXdKaMkDK95TAB3S+2rvfLGk4B9whgJVS0roFiJ4rfSn5df+ cX7i1HM+oVkYaatR89fqTye+u4X3wUH+QEpnZTXrf7giapIbPfkhN0md7UTRcqIhFRat queQ== 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:cc:to :from:dkim-signature; bh=MWsW7ULWn4A1fSKqhQgD2QQ0V+0wVuw8Sc2XWLbfpiw=; b=VNAQqEKWw8jpajj/sbzbtOxBp5MZFPexnGZ54tM1he32GPw8T0lCMetiXSWpHhqTY4 8U1T0pWfTe03M/BTS6RyuZOrKkPneUk/xHd/qouadYkcgpdz2mBRtZkU/nwx7SFwvJJd Swjn+NNQ7yJSnCUiARb75QM5lmmAll/mRNPhHTGLexsim+DWjjTncTIfIF8QPEi/LJuO YXIRMja/+NsoA+KlWRymDkm9Au4YPY2I+7+0i6X4o2375Omf0ostCFMigHcieiBDQCnc VnSCHOnaioKccZfp0kl6MKrNY88/R71bZQLaIPP8JEfpSr7TuIpZdRmvgZckAmmBTWM0 7OPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EaGiVx4G; 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 h16-20020a05622a171000b003b9ec33eabesi10235074qtk.463.2023.04.12.04.44.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:57 -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=EaGiVx4G; 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 1pmYtJ-0004wx-G2; Wed, 12 Apr 2023 07:43:57 -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 1pmYt6-0004k7-I5 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:45 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt3-0002OA-Ah for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:44 -0400 Received: by mail-wr1-x431.google.com with SMTP id j1so14578095wrb.0 for ; Wed, 12 Apr 2023 04:43:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299819; x=1683891819; 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=MWsW7ULWn4A1fSKqhQgD2QQ0V+0wVuw8Sc2XWLbfpiw=; b=EaGiVx4GjyyxgSsuNjJfa17MmsOKGI61kKrBoCOg/r7MFkgDWealhajr5GU/1r361p lsBlJ5LSdh3Gu5YaDhGX7so8r8b9mlAxU2z/lzBqBtR1NHidKH6xFCGckErGpkdUcVrA dvbyvUFKT8U1UZvWjpg6QR2ZM+hbwCSUHDutG6KZXJrNmTYYxdbA0kQZrP14dZa5xRa/ 1qWkSHXfWU1w0kk7UUgZbd+BMuX6VLaz59aMnOZYoOdsqItr3NP7jhgCWsl6ES7tVoUW gqvmBUfMDIovJUDfbEFsWvh9IBS6s6PnnAKWlz5FMSdxhawBC1UdQOBtJdnd34iW1jQT EpCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299819; x=1683891819; 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=MWsW7ULWn4A1fSKqhQgD2QQ0V+0wVuw8Sc2XWLbfpiw=; b=K2eNtzgudVG7RPQnpg6nrKmFgJV61DcbDiHacL+lIZOoPujBLx8lM+L+xQ0J8YIzI+ m2Al/T/oyKTtd8d4BYy93aqBiZ3fSPssxGohU3Z1ATZZqAa9KPixP2lc6U9DKuj5OLoR hSK6L11dMESm/iVyOQVwxWzELEwuD9zt6y8ajYNnl6E+Eyx8reQTtifVZtVSJkjWmI9h YVSXuuHtmq5RDjN5zr+B0nF1O4GgjnixgeplHa9N7GcUgTBI5qX5ZWKBPVnOkamZdYae Omc8xr4jjC1AcPgI/KmGFXwKUMWIAgeA/CgsnEiy+8VExCUtBiziNpFOhLTnIxZzFrWp NGiQ== X-Gm-Message-State: AAQBX9fXeVLbjV3AI6/9JDAlv3Y8byRSLaGBvqchyFy9/NToxGrRiWcR QrtFO8aL1d6IkSXjYV+zOZzkJMM8nDzKAszRXBD246W1 X-Received: by 2002:adf:f1ca:0:b0:2f4:eb13:4091 with SMTP id z10-20020adff1ca000000b002f4eb134091mr758520wro.45.1681299819677; Wed, 12 Apr 2023 04:43:39 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, LIU Zhiwei , Weiwei Li , Alistair Francis , Daniel Henrique Barboza Subject: [PATCH v7 05/25] target/riscv: Add a tb flags field for vstart Date: Wed, 12 Apr 2023 13:43:13 +0200 Message-Id: <20230412114333.118895-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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 From: LIU Zhiwei Once we mistook the vstart directly from the env->vstart. As env->vstart is not a constant, we should record it in the tb flags if we want to use it in translation. Reported-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: LIU Zhiwei Reviewed-by: Weiwei Li Message-Id: <20230324143031.1093-5-zhiwei_liu@linux.alibaba.com> Reviewed-by: Alistair Francis Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-6-richard.henderson@linaro.org> --- target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 1 + target/riscv/translate.c | 4 ++-- target/riscv/insn_trans/trans_rvv.c.inc | 14 +++++++------- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ab64d5f92d..786ad047ee 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -655,6 +655,7 @@ FIELD(TB_FLAGS, VMA, 21, 1) FIELD(TB_FLAGS, ITRIGGER, 22, 1) /* Virtual mode enabled */ FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) +FIELD(TB_FLAGS, VSTART_EQ_ZERO, 24, 1) #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e3e620137b..7579e83c3d 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -74,6 +74,7 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, FIELD_EX64(env->vtype, VTYPE, VTA)); flags = FIELD_DP32(flags, TB_FLAGS, VMA, FIELD_EX64(env->vtype, VTYPE, VMA)); + flags = FIELD_DP32(flags, TB_FLAGS, VSTART_EQ_ZERO, env->vstart == 0); } else { flags = FIELD_DP32(flags, TB_FLAGS, VILL, 1); } diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 3092c942ab..3ab8a9999e 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -99,7 +99,7 @@ typedef struct DisasContext { uint8_t vta; uint8_t vma; bool cfg_vta_all_1s; - target_ulong vstart; + bool vstart_eq_zero; bool vl_eq_vlmax; CPUState *cs; TCGv zero; @@ -1168,7 +1168,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->vta = FIELD_EX32(tb_flags, TB_FLAGS, VTA) && cpu->cfg.rvv_ta_all_1s; ctx->vma = FIELD_EX32(tb_flags, TB_FLAGS, VMA) && cpu->cfg.rvv_ma_all_1s; ctx->cfg_vta_all_1s = cpu->cfg.rvv_ta_all_1s; - ctx->vstart = env->vstart; + ctx->vstart_eq_zero = FIELD_EX32(tb_flags, TB_FLAGS, VSTART_EQ_ZERO); ctx->vl_eq_vlmax = FIELD_EX32(tb_flags, TB_FLAGS, VL_EQ_VLMAX); ctx->misa_mxl_max = env->misa_mxl_max; ctx->xl = FIELD_EX32(tb_flags, TB_FLAGS, XL); diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc index ecbdf1b3d7..6c07eebc52 100644 --- a/target/riscv/insn_trans/trans_rvv.c.inc +++ b/target/riscv/insn_trans/trans_rvv.c.inc @@ -547,7 +547,7 @@ static bool vext_check_sds(DisasContext *s, int vd, int vs1, int vs2, int vm) */ static bool vext_check_reduction(DisasContext *s, int vs2) { - return require_align(vs2, s->lmul) && (s->vstart == 0); + return require_align(vs2, s->lmul) && s->vstart_eq_zero; } /* @@ -3083,7 +3083,7 @@ static bool trans_vcpop_m(DisasContext *s, arg_rmr *a) { if (require_rvv(s) && vext_check_isa_ill(s) && - s->vstart == 0) { + s->vstart_eq_zero) { TCGv_ptr src2, mask; TCGv dst; TCGv_i32 desc; @@ -3112,7 +3112,7 @@ static bool trans_vfirst_m(DisasContext *s, arg_rmr *a) { if (require_rvv(s) && vext_check_isa_ill(s) && - s->vstart == 0) { + s->vstart_eq_zero) { TCGv_ptr src2, mask; TCGv dst; TCGv_i32 desc; @@ -3148,7 +3148,7 @@ static bool trans_##NAME(DisasContext *s, arg_rmr *a) \ vext_check_isa_ill(s) && \ require_vm(a->vm, a->rd) && \ (a->rd != a->rs2) && \ - (s->vstart == 0)) { \ + s->vstart_eq_zero) { \ uint32_t data = 0; \ gen_helper_gvec_3_ptr *fn = gen_helper_##NAME; \ TCGLabel *over = gen_new_label(); \ @@ -3189,7 +3189,7 @@ static bool trans_viota_m(DisasContext *s, arg_viota_m *a) !is_overlapped(a->rd, 1 << MAX(s->lmul, 0), a->rs2, 1) && require_vm(a->vm, a->rd) && require_align(a->rd, s->lmul) && - (s->vstart == 0)) { + s->vstart_eq_zero) { uint32_t data = 0; TCGLabel *over = gen_new_label(); tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_vl, 0, over); @@ -3638,7 +3638,7 @@ static bool vcompress_vm_check(DisasContext *s, arg_r *a) require_align(a->rs2, s->lmul) && (a->rd != a->rs2) && !is_overlapped(a->rd, 1 << MAX(s->lmul, 0), a->rs1, 1) && - (s->vstart == 0); + s->vstart_eq_zero; } static bool trans_vcompress_vm(DisasContext *s, arg_r *a) @@ -3677,7 +3677,7 @@ static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ QEMU_IS_ALIGNED(a->rd, LEN) && \ QEMU_IS_ALIGNED(a->rs2, LEN)) { \ uint32_t maxsz = (s->cfg_ptr->vlen >> 3) * LEN; \ - if (s->vstart == 0) { \ + if (s->vstart_eq_zero) { \ /* EEW = 8 */ \ tcg_gen_gvec_mov(MO_8, vreg_ofs(s, a->rd), \ vreg_ofs(s, a->rs2), maxsz, maxsz); \ From patchwork Wed Apr 12 11:43:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672630 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp290222wrx; Wed, 12 Apr 2023 04:52:07 -0700 (PDT) X-Google-Smtp-Source: AKy350amRNHL4CceameRszGf0R85Ce2o9hhh1AGvQNkEW//XAZ8pdYbqE5S9uFcm2ilLiNq+l+CV X-Received: by 2002:a05:6214:d6f:b0:5a5:b269:bfd7 with SMTP id 15-20020a0562140d6f00b005a5b269bfd7mr3993260qvs.8.1681300326873; Wed, 12 Apr 2023 04:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300326; cv=none; d=google.com; s=arc-20160816; b=lb/22CV6Qx9DYsF5IYQNN8tLgqcl5E03X9UmoAvS3qnfLKI4+9qwAGIxhurvS3Fg8C rvNwsvWLedIu4YL3vwguYV/PtcL/2VWw8n0ij//l1/D0F1AYtoBGxJJhoqyF8S/5Tfhc +sblsR7gmJlbliH/56ytl8/pykLYkAn0aADF2vyb6tdDIF/ghEgdQ5eYFyvVJMPou80C ygYEMdPfFXpq8HD6KYvrbf9aFsjrUB6ADOCvRQg7JOi0Muniod0QCXQrDGj2KQN5vtE6 HA2LCwo0EC5Nq0KGIBhKDXbJ8vyxhw3adu/VyC6V2qqLPG/6cTqjyWaB4je/hhNrRL6Y wndw== 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:cc:to :from:dkim-signature; bh=AmmNXj22HP7KMuzDURhipUP2NYBo1bwlMxGUrM5ujg4=; b=Pro+PLKYohoCmv5IrvqYzxzni/k2+kivV1GEW9UqGVkj8g63XvIMp36M8SBjXA9xGJ xKHz3ReONLQWcRRRZ0uyXHKIwVEjJyS+nW+A7LUtjVDijM4OQR1mCawxJMC23wpZU0eZ hZl1W2udjDjhrqT3afqytQdipDNBnu+0PvnAUgZ7SUFsqyXNK4nJJvuht4ehdfCExKK+ JcX7PUIdjCBR/t/TaWdF3zAf9dXSOkOFhzb0fhhLZ34opUu1fexyjKpI/k8MYpuMv35u DkREUlu28r5OFFDUvz9a+pNmFC8NqIp3CJFmvezAjI+h/hXJ3Hxs/Vm4nTeYrBHTtdR8 cPIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JYxktg14; 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 iv10-20020ad45cea000000b005e8f062f213si4319047qvb.483.2023.04.12.04.52.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:52:06 -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=JYxktg14; 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 1pmYtd-0005lH-SX; Wed, 12 Apr 2023 07:44:17 -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 1pmYt8-0004kh-4u for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:47 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt4-0002OM-1w for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:44 -0400 Received: by mail-wr1-x430.google.com with SMTP id s12so2104068wrb.1 for ; Wed, 12 Apr 2023 04:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299820; x=1683891820; 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=AmmNXj22HP7KMuzDURhipUP2NYBo1bwlMxGUrM5ujg4=; b=JYxktg14OyscHvAJSlWTTTMGJoWJab/Pv42K4KJzZYMTdfQHZkBqhiam+/nHG9/1Kb zqQmsGBvCIDo26AQY/2H7ehJIC286cEdZEzxp6ULD5UQsAwBMN5DcU7hICY0BTs4F7vX 4HRgFBAVE5/RMEeb9fr5S7Sk969lHxW/zoJHhO5FujSBBSq9XpZzwHz/zK/iDZAaV42p EGkVpJEyjHxKLarB7wVe94Ys6/l8zO4E5tQCfMgR7pqmRXSdsdwpBaEYOG6OTbIG+ru2 aWDHROFHbbv7cah2aXMDF8qcW1JJNb+YFyZGrUR055NUxnih7sygK7e4qdis75wDFlHg kNSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299820; x=1683891820; 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=AmmNXj22HP7KMuzDURhipUP2NYBo1bwlMxGUrM5ujg4=; b=2iCu3WXVzg9ikqGVWiuEvL8j8T1qs20PV9HLH4GHBi7zz1Ml24bvaXwaUKwYbSsrsw F35HkdRr6zM2xSoffAyKIcAhyS4GFVm1ZNoeKyN90erSpCPbyz6tpncsuKeivcU9rXp2 K85W0FFwA5+GaMFgg6UBqFyfATuhe+/hLU9ACgUJL9H46a1doQmtWEU/s4jcO8AWXgKS CSxnlqFtoUptCC2THS4PSRUiELru7btrgB5V8LMusSN41lmlxMy9DalHdvb7wAW+Vj/r W3t8TiJ3dOS9pUsm1q2WnCc/UEAGlOrqVdRUAa/CMrzsVof4rae06HaIYVONASoMJmt7 TDXg== X-Gm-Message-State: AAQBX9d0bUNumfy31lK5UJIKsLmSz/fmgT9CkaHvaD/hSlJ7I4h7M0SE fG5V6jkTggpAZcNNyTOtN4KOjREZ/fRQxdF2qXYQzvm5 X-Received: by 2002:adf:db47:0:b0:2f2:4db4:1f5b with SMTP id f7-20020adfdb47000000b002f24db41f5bmr4751710wrj.29.1681299820519; Wed, 12 Apr 2023 04:43:40 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Fei Wu , LIU Zhiwei , Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 06/25] target/riscv: Separate priv from mmu_idx Date: Wed, 12 Apr 2023 13:43:14 +0200 Message-Id: <20230412114333.118895-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x430.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=unavailable 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 From: Fei Wu Currently it's assumed the 2 low bits of mmu_idx map to privilege mode, this assumption won't last as we are about to add more mmu_idx. Here an individual priv field is added into TB_FLAGS. Reviewed-by: Richard Henderson Signed-off-by: Fei Wu Message-Id: <20230324054154.414846-2-fei2.wu@intel.com> Reviewed-by: LIU Zhiwei Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-7-richard.henderson@linaro.org> --- target/riscv/cpu.h | 2 +- target/riscv/cpu_helper.c | 4 +++- target/riscv/translate.c | 2 ++ target/riscv/insn_trans/trans_privileged.c.inc | 2 +- target/riscv/insn_trans/trans_xthead.c.inc | 14 +------------- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 786ad047ee..9b971ee1b0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -629,7 +629,6 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *env, target_ulong riscv_cpu_get_fflags(CPURISCVState *env); void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); -#define TB_FLAGS_PRIV_MMU_MASK 3 #define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2) #include "exec/cpu-all.h" @@ -656,6 +655,7 @@ FIELD(TB_FLAGS, ITRIGGER, 22, 1) /* Virtual mode enabled */ FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) FIELD(TB_FLAGS, VSTART_EQ_ZERO, 24, 1) +FIELD(TB_FLAGS, PRIV, 25, 2) #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 7579e83c3d..36d6e422d7 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -83,6 +83,8 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, fs = EXT_STATUS_DIRTY; vs = EXT_STATUS_DIRTY; #else + flags = FIELD_DP32(flags, TB_FLAGS, PRIV, env->priv); + flags |= cpu_mmu_index(env, 0); fs = get_field(env->mstatus, MSTATUS_FS); vs = get_field(env->mstatus, MSTATUS_VS); @@ -751,7 +753,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, */ MemTxResult res; MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; - int mode = mmu_idx & TB_FLAGS_PRIV_MMU_MASK; + int mode = env->priv; bool use_background = false; hwaddr ppn; int napot_bits = 0; diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 3ab8a9999e..6d59348f0c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -67,6 +67,7 @@ typedef struct DisasContext { RISCVExtStatus mstatus_fs; RISCVExtStatus mstatus_vs; uint32_t mem_idx; + uint32_t priv; /* * Remember the rounding mode encoded in the previous fp instruction, * which we have already installed into env->fp_status. Or -1 for @@ -1153,6 +1154,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) uint32_t tb_flags = ctx->base.tb->flags; ctx->pc_succ_insn = ctx->base.pc_first; + ctx->priv = FIELD_EX32(tb_flags, TB_FLAGS, PRIV); ctx->mem_idx = FIELD_EX32(tb_flags, TB_FLAGS, MEM_IDX); ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS); ctx->mstatus_vs = FIELD_EX32(tb_flags, TB_FLAGS, VS); diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc index e3bee971c6..7c2837194c 100644 --- a/target/riscv/insn_trans/trans_privileged.c.inc +++ b/target/riscv/insn_trans/trans_privileged.c.inc @@ -52,7 +52,7 @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) * that no exception will be raised when fetching them. */ - if (semihosting_enabled(ctx->mem_idx < PRV_S) && + if (semihosting_enabled(ctx->priv == PRV_U) && (pre_addr & TARGET_PAGE_MASK) == (post_addr & TARGET_PAGE_MASK)) { pre = opcode_at(&ctx->base, pre_addr); ebreak = opcode_at(&ctx->base, ebreak_addr); diff --git a/target/riscv/insn_trans/trans_xthead.c.inc b/target/riscv/insn_trans/trans_xthead.c.inc index df504c3f2c..3e13b1d74d 100644 --- a/target/riscv/insn_trans/trans_xthead.c.inc +++ b/target/riscv/insn_trans/trans_xthead.c.inc @@ -263,25 +263,13 @@ static bool trans_th_tst(DisasContext *ctx, arg_th_tst *a) /* XTheadCmo */ -static inline int priv_level(DisasContext *ctx) -{ -#ifdef CONFIG_USER_ONLY - return PRV_U; -#else - /* Priv level is part of mem_idx. */ - return ctx->mem_idx & TB_FLAGS_PRIV_MMU_MASK; -#endif -} - /* Test if priv level is M, S, or U (cannot fail). */ #define REQUIRE_PRIV_MSU(ctx) /* Test if priv level is M or S. */ #define REQUIRE_PRIV_MS(ctx) \ do { \ - int priv = priv_level(ctx); \ - if (!(priv == PRV_M || \ - priv == PRV_S)) { \ + if (ctx->priv == PRV_U) { \ return false; \ } \ } while (0) From patchwork Wed Apr 12 11:43:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672623 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288487wrx; Wed, 12 Apr 2023 04:47:32 -0700 (PDT) X-Google-Smtp-Source: AKy350aS2cCrT8e0HOScPYJ23Thcy6PDwm34xrxXNvTMos1cX87kOQAHceDojbW/TMKahP864vmI X-Received: by 2002:a05:622a:14e:b0:3e3:9275:17ad with SMTP id v14-20020a05622a014e00b003e3927517admr3580200qtw.12.1681300052026; Wed, 12 Apr 2023 04:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300052; cv=none; d=google.com; s=arc-20160816; b=IXyFxcZMObfgq/s56ohc4F/FmLfCp7h/fgLR/afZAlaUzVkJf0IwdW5xuhO6wGxR34 FsLSf8SunPDeB1usZIwLurwwcDo0AmM/vCmTzYd8BsN7w5U/T4kaFTjCPiA7U/r50EBN +IPqUMqSAg39540B6HK6X7QAc4aLEIOT5kd93mcC/4MLxHadkkLBsFE1btgqMC99sh87 HN6gxPBAIZ0LxrIX6U0quarXB4LZtlBvBq7L6newveqPUaNaknURfjhLCTc299DC+mhc +jU+BrC3xwcqhtUBFHCtAqlI1J6yfC0csowCBfm6TVhkqTiXPDBDwlLQevJGcK60BuiL l0+Q== 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:cc:to :from:dkim-signature; bh=vFpmN4l+aiQZzHkMQF0Is1Gbr8TTg8AJfI2hz+TEgNU=; b=Kjqfdcc0caX2gciAIcjUnnu/AORr8L9qztDSphB+GFq1UUYTFRXWcA8DsL0pony+Z/ 6yZFZ3ZQ9MNqkGCin9X13tefBXaku7oo02gI46oGDTxifFqiLDDOpWtHK5hz+fpc9T99 xPJE6sekUujS2B+7FePyY0vDLJpNO2nNtGh4n/JAEhFOC9ft7yiWrRA/gYwAtDIIaCKC WmqdUEYHGWR1TINVEiIaPJ2f4RjMtxEd/9G/5nNPJUpUtxs1FmEk5sc5HAyDxGEwlnS8 ZcjtnFLDj5Pav8k8t9FvoFBLkqcPulV/IGXiPNlHPUgN+d+cT5sFA/hCPBfYYH6gorYx qWFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nubkifGA; 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 bl16-20020a05620a1a9000b0074a88515827si8139103qkb.755.2023.04.12.04.47.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:47:32 -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=nubkifGA; 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 1pmYtd-0005m8-Vs; Wed, 12 Apr 2023 07:44:18 -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 1pmYt8-0004l5-DZ for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:47 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt4-0002NE-1m for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:45 -0400 Received: by mail-wr1-x432.google.com with SMTP id l18so10512845wrb.9 for ; Wed, 12 Apr 2023 04:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299821; x=1683891821; 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=vFpmN4l+aiQZzHkMQF0Is1Gbr8TTg8AJfI2hz+TEgNU=; b=nubkifGATpQrBCVy4n7E0dP6pAc1PkiFqkKd3VkYpkLWWgA+z6/AHXD6SsbJB9QUxd 0Od0dfFs161Qb7JD776X970PESx5q24GgMNOZTlVNSSGnoQPm334rfc1Hy/dHrmsn09V flmFoJ6Ztu4yqFM0wwe2JXdvgWLEEG92aj+3anO/UjpqIO3Q0K8POx/UZM0X9/kIrEc4 f6Od1BxtJgiCC0yKN8PA/td1VNllIFEOve8KI39zWjkdHHg25XOYj6VTub8559IXCIB1 uKnG3YaK3AsAq0sGOTQrwDCY2NLkE3kQl4Zgn1lQQ5bQoW8Klx8pSq26bRKd5OC1Xm+A 5rGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299821; x=1683891821; 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=vFpmN4l+aiQZzHkMQF0Is1Gbr8TTg8AJfI2hz+TEgNU=; b=tu78DYeATl0JJIwHDVMt9ayDDie0zz/0oIPTrKT+Zs5ve/2aoO3lWAHu0YaV/KxScv eOuM7hG/9cEbuL0DY1fbA6uaR67DOZ79QmjAxcoRoNkN2zxVWLM0i1aKNKRzEJ6wPdcG GhR7Y+Te5/JoLZ5h5dzk4ce9QNQ29qdk2wzEOIsxOvdd1q2cvW6XEI0TrCkTCSN37FnI cpzfgpBrL6iKeAM8RaElmpk8lOTCMK5fxOXdnz3Vixd2EHspdUCJmVXpQzeykLwz7xSh w1hl1hl//l+/BD/uiKO6etAtNnS2He1LShD9VL+i4ETeGxmxbKdyRrWbWph2d0zzyYuc YeKg== X-Gm-Message-State: AAQBX9c0rDSmTPhyjLPUshKuKIRZs4Y8uaSEmu+bczwo0UAF5/45qekG s733nFpvYaql+brcMuK+OIuyRVtydxBZTeMnu85g2JRc X-Received: by 2002:adf:dfcc:0:b0:2ef:af46:1278 with SMTP id q12-20020adfdfcc000000b002efaf461278mr11347284wrn.10.1681299821156; Wed, 12 Apr 2023 04:43:41 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Fei Wu , LIU Zhiwei , Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 07/25] target/riscv: Reduce overhead of MSTATUS_SUM change Date: Wed, 12 Apr 2023 13:43:15 +0200 Message-Id: <20230412114333.118895-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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 From: Fei Wu Kernel needs to access user mode memory e.g. during syscalls, the window is usually opened up for a very limited time through MSTATUS.SUM, the overhead is too much if tlb_flush() gets called for every SUM change. This patch creates a separate MMU index for S+SUM, so that it's not necessary to flush tlb anymore when SUM changes. This is similar to how ARM handles Privileged Access Never (PAN). Result of 'pipe 10' from unixbench boosts from 223656 to 1705006. Many other syscalls benefit a lot from this too. Reviewed-by: Richard Henderson Signed-off-by: Fei Wu Message-Id: <20230324054154.414846-3-fei2.wu@intel.com> Reviewed-by: LIU Zhiwei Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-8-richard.henderson@linaro.org> --- target/riscv/cpu.h | 2 -- target/riscv/internals.h | 14 ++++++++++++++ target/riscv/cpu_helper.c | 17 +++++++++++++++-- target/riscv/csr.c | 3 +-- target/riscv/op_helper.c | 5 +++-- target/riscv/insn_trans/trans_rvh.c.inc | 4 ++-- 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 9b971ee1b0..6239c99f4c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -629,8 +629,6 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *env, target_ulong riscv_cpu_get_fflags(CPURISCVState *env); void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong); -#define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2) - #include "exec/cpu-all.h" FIELD(TB_FLAGS, MEM_IDX, 0, 3) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 5620fbffb6..b55152a7dc 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -21,6 +21,20 @@ #include "hw/registerfields.h" +/* + * The current MMU Modes are: + * - U 0b000 + * - S 0b001 + * - S+SUM 0b010 + * - M 0b011 + * - HLV/HLVX/HSV adds 0b100 + */ +#define MMUIdx_U 0 +#define MMUIdx_S 1 +#define MMUIdx_S_SUM 2 +#define MMUIdx_M 3 +#define MMU_HYP_ACCESS_BIT (1 << 2) + /* share data between vector helpers and decode code */ FIELD(VDATA, VM, 0, 1) FIELD(VDATA, LMUL, 1, 3) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 36d6e422d7..174a77706b 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -21,6 +21,7 @@ #include "qemu/log.h" #include "qemu/main-loop.h" #include "cpu.h" +#include "internals.h" #include "pmu.h" #include "exec/exec-all.h" #include "instmap.h" @@ -36,7 +37,19 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) #ifdef CONFIG_USER_ONLY return 0; #else - return env->priv; + if (ifetch) { + return env->priv; + } + + /* All priv -> mmu_idx mapping are here */ + int mode = env->priv; + if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) { + mode = get_field(env->mstatus, MSTATUS_MPP); + } + if (mode == PRV_S && get_field(env->mstatus, MSTATUS_SUM)) { + return MMUIdx_S_SUM; + } + return mode; #endif } @@ -588,7 +601,7 @@ void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable) bool riscv_cpu_two_stage_lookup(int mmu_idx) { - return mmu_idx & TB_FLAGS_PRIV_HYP_ACCESS_MASK; + return mmu_idx & MMU_HYP_ACCESS_BIT; } int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4268828dc4..124be448dc 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1270,8 +1270,7 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, val = legalize_mpp(env, get_field(mstatus, MSTATUS_MPP), val); /* flush tlb on mstatus fields that affect VM */ - if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV | - MSTATUS_MPRV | MSTATUS_SUM)) { + if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPV)) { tlb_flush(env_cpu(env)); } mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index bd21c6eeef..00bdf77f32 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "cpu.h" +#include "internals.h" #include "qemu/main-loop.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" @@ -428,14 +429,14 @@ void helper_hyp_gvma_tlb_flush(CPURISCVState *env) target_ulong helper_hyp_hlvx_hu(CPURISCVState *env, target_ulong address) { - int mmu_idx = cpu_mmu_index(env, true) | TB_FLAGS_PRIV_HYP_ACCESS_MASK; + int mmu_idx = cpu_mmu_index(env, true) | MMU_HYP_ACCESS_BIT; return cpu_lduw_mmuidx_ra(env, address, mmu_idx, GETPC()); } target_ulong helper_hyp_hlvx_wu(CPURISCVState *env, target_ulong address) { - int mmu_idx = cpu_mmu_index(env, true) | TB_FLAGS_PRIV_HYP_ACCESS_MASK; + int mmu_idx = cpu_mmu_index(env, true) | MMU_HYP_ACCESS_BIT; return cpu_ldl_mmuidx_ra(env, address, mmu_idx, GETPC()); } diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc index 4b730cd492..ae98b45e5e 100644 --- a/target/riscv/insn_trans/trans_rvh.c.inc +++ b/target/riscv/insn_trans/trans_rvh.c.inc @@ -42,7 +42,7 @@ static bool do_hlv(DisasContext *ctx, arg_r2 *a, MemOp mop) if (check_access(ctx)) { TCGv dest = dest_gpr(ctx, a->rd); TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); - int mem_idx = ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK; + int mem_idx = ctx->mem_idx | MMU_HYP_ACCESS_BIT; tcg_gen_qemu_ld_tl(dest, addr, mem_idx, mop); gen_set_gpr(ctx, a->rd, dest); } @@ -89,7 +89,7 @@ static bool do_hsv(DisasContext *ctx, arg_r2_s *a, MemOp mop) if (check_access(ctx)) { TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); - int mem_idx = ctx->mem_idx | TB_FLAGS_PRIV_HYP_ACCESS_MASK; + int mem_idx = ctx->mem_idx | MMU_HYP_ACCESS_BIT; tcg_gen_qemu_st_tl(data, addr, mem_idx, mop); } return true; From patchwork Wed Apr 12 11:43:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672627 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288897wrx; Wed, 12 Apr 2023 04:48:36 -0700 (PDT) X-Google-Smtp-Source: AKy350ZibbvL6vr6fQewikU9SOG9sEmKU7BdDK3H1MqWm0NizUUE+HOK76Ntbu3OC2oZWHnE0lTw X-Received: by 2002:ac8:5a03:0:b0:3e0:4e3d:6f5c with SMTP id n3-20020ac85a03000000b003e04e3d6f5cmr9238768qta.49.1681300116232; Wed, 12 Apr 2023 04:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300116; cv=none; d=google.com; s=arc-20160816; b=El/J6KxG4k2x4dUQ7qUWwVV0QJS9OfZmd3zEbpl0x/ndY20qDHqI9vDVXYS0ah3817 CkQ0XqcBcJDoNYtWZiYJGFtSJ4z/VdcFCzHAtJI+D+KozvwFLV05jV7hf4m3rz+YSXoY Omnk+bKVZ3ehvImzZD+mXnVBR9qNDKavB9l+6aG4RVrwH6S3E0/BL6UNS9SF3bP3JP6+ rrzkj3kP55ozLrOMopkdx6UHCrDot6WpqDh0y9C8a+ynOJ//J2QNT/Vhrjy/lyBA8Qsa ovgXwkAX3mjKO+5C1URCPMR0jvK/z+Apju+Oq3tWldGc3gfgqEc42g/LZrYvLGCfDAAg AaNA== 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:cc:to :from:dkim-signature; bh=nYIzXxaKlE7pVBf36j8eV1KDqBsqyyZsO57pOhE6S3s=; b=lxuM5j9T+nVyfyJLJZw04JyZBzoWPJxTD4Sll20ppvv+5oNM7SwtJJTECLBXXQtHWz mpHywWInxs1DBg8b+4uWDe2C+lv8Z1zzJTfJb6U/5Ibs974QIGIryP8pA2w3d/zcruCz tU/zIz7MvJ5M1rt/XBiMF3/a6LvgjR35AeF/gQSP+EQhjy/QV5A4buhDYz2lsTd1OzeS TMR8BRg1j6HaeKGl2/J1MHlYiqi9wQYqJTnEl1rG6iQfPSl8xEHBk1EMLKIRaBMtnD/D 3K3eze1Qj1ugcn3AMxUM/IdJlNbn54dEaQoMRVx76sAH91hS8Ui0z7ON40J6vyDZFYWu kMvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ONqpGGeP; 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 t22-20020a05622a149600b003e655315a35si10304725qtx.621.2023.04.12.04.48.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:48:36 -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=ONqpGGeP; 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 1pmYtc-0005f5-Us; Wed, 12 Apr 2023 07:44:16 -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 1pmYt9-0004m7-Cr for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:47 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt5-0002PF-UT for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:46 -0400 Received: by mail-wr1-x434.google.com with SMTP id q29so10426688wrc.3 for ; Wed, 12 Apr 2023 04:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299822; x=1683891822; 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=nYIzXxaKlE7pVBf36j8eV1KDqBsqyyZsO57pOhE6S3s=; b=ONqpGGePtrPAOKWUp+MMlXKvAAooORMK36G0DfY8L2Lp+ZSrKpcsQ2pvjEmclVEubR IaIlilj7qIVZ9slBvCt+e8nwPhQ1RM15ChtOwtvsPEqjypRxJoSdjHV2E26sY/se4Jp1 okiN+cCb7Be6FCD5MJlhnSNh6L5CUE4NsDSyL02NFqjsOsit8q/MPNwFE0+ieVuZri6l A/JkYWgMyOyTTJa0/NvxCOVCNyQli0blYlcYhoQ7WrqAdJ+umHlBIfr8w68HV5wagZpM Wh7knq6ENbQtJsuHrsUx/8gr8rhyz4/nO70sRIfeG1Uv4SIZkjZS3S+BzflAHi4V/N8u uyQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299822; x=1683891822; 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=nYIzXxaKlE7pVBf36j8eV1KDqBsqyyZsO57pOhE6S3s=; b=v+ZMsafqRMFT+6Hjz7YS3v8VdmkcQjezh5DvPUE2BXXKXEWxfH0RFs890gk3cFm/W0 ih6Acb9VsTY9+IcYvwg2zKAN4tNhHnJx+gOGBeAxuhjpQ6+i3NubqUwAbw9HYOe+cHCo wMOD/iLTFAQxk1Tu1qbEJTjaHeddyvqXp7nukXdXPqE3whfpuzzTCSGo12JhVTuUM3J1 uybR+2fJH3vWE0llKh/dI9KHM3q5ADNeQD6ZVxiUvlw+ij93c2QxrxK9DKgGu2XAmbXb B2bM23N8NgpQHzTQEgdjFhlslvujkljCg3+LBZC1/YbPa0JVD+sqm4WkrMxrNhVeAIxj ti8A== X-Gm-Message-State: AAQBX9flG3uSiR5r//uq1LftKm5UMLSiB8GZYjRvzpge1YnQVY1Nv+pG 78sdpMAmqgjT111HhLhRPozukcj7acR2nkWM6Ouk+xBO X-Received: by 2002:adf:fa02:0:b0:2f2:7adf:3c67 with SMTP id m2-20020adffa02000000b002f27adf3c67mr3858978wrr.61.1681299822045; Wed, 12 Apr 2023 04:43:42 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 08/25] accel/tcg: Add cpu_ld*_code_mmu Date: Wed, 12 Apr 2023 13:43:16 +0200 Message-Id: <20230412114333.118895-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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=unavailable 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 At least RISC-V has the need to be able to perform a read using execute permissions, outside of translation. Add helpers to facilitate this. Signed-off-by: Richard Henderson Acked-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-9-richard.henderson@linaro.org> --- include/exec/cpu_ldst.h | 9 +++++++ accel/tcg/cputlb.c | 48 ++++++++++++++++++++++++++++++++++ accel/tcg/user-exec.c | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 09b55cc0ee..c141f0394f 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -445,6 +445,15 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx, # define cpu_stq_mmu cpu_stq_le_mmu #endif +uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); +uint16_t cpu_ldw_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); +uint32_t cpu_ldl_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); +uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); + uint32_t cpu_ldub_code(CPUArchState *env, abi_ptr addr); uint32_t cpu_lduw_code(CPUArchState *env, abi_ptr addr); uint32_t cpu_ldl_code(CPUArchState *env, abi_ptr addr); diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index e984a98dc4..e62c8f3c3f 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2768,3 +2768,51 @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr addr) MemOpIdx oi = make_memop_idx(MO_TEUQ, cpu_mmu_index(env, true)); return full_ldq_code(env, addr, oi, 0); } + +uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + return full_ldub_code(env, addr, oi, retaddr); +} + +uint16_t cpu_ldw_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + MemOp mop = get_memop(oi); + int idx = get_mmuidx(oi); + uint16_t ret; + + ret = full_lduw_code(env, addr, make_memop_idx(MO_TEUW, idx), retaddr); + if ((mop & MO_BSWAP) != MO_TE) { + ret = bswap16(ret); + } + return ret; +} + +uint32_t cpu_ldl_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + MemOp mop = get_memop(oi); + int idx = get_mmuidx(oi); + uint32_t ret; + + ret = full_ldl_code(env, addr, make_memop_idx(MO_TEUL, idx), retaddr); + if ((mop & MO_BSWAP) != MO_TE) { + ret = bswap32(ret); + } + return ret; +} + +uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + MemOp mop = get_memop(oi); + int idx = get_mmuidx(oi); + uint64_t ret; + + ret = full_ldq_code(env, addr, make_memop_idx(MO_TEUQ, idx), retaddr); + if ((mop & MO_BSWAP) != MO_TE) { + ret = bswap64(ret); + } + return ret; +} diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index a7e0c3e2f4..fc597a010d 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1219,6 +1219,64 @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr ptr) return ret; } +uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint8_t ret; + + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_INST_FETCH); + ret = ldub_p(haddr); + clear_helper_retaddr(); + return ret; +} + +uint16_t cpu_ldw_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint16_t ret; + + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_INST_FETCH); + ret = lduw_p(haddr); + clear_helper_retaddr(); + if (get_memop(oi) & MO_BSWAP) { + ret = bswap16(ret); + } + return ret; +} + +uint32_t cpu_ldl_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint32_t ret; + + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_INST_FETCH); + ret = ldl_p(haddr); + clear_helper_retaddr(); + if (get_memop(oi) & MO_BSWAP) { + ret = bswap32(ret); + } + return ret; +} + +uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint64_t ret; + + validate_memop(oi, MO_BEUQ); + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_DATA_LOAD); + ret = ldq_p(haddr); + clear_helper_retaddr(); + if (get_memop(oi) & MO_BSWAP) { + ret = bswap64(ret); + } + return ret; +} + #include "ldst_common.c.inc" /* From patchwork Wed Apr 12 11:43:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672626 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288859wrx; Wed, 12 Apr 2023 04:48:31 -0700 (PDT) X-Google-Smtp-Source: AKy350b6d6Rg7v36KbBlpxcRyUC0safg+ZHDl4eag4cVuVLhhfCJYv3z19t2o0gsRaZ+jbBLJEdn X-Received: by 2002:a05:6214:260d:b0:5b4:ccc0:4f60 with SMTP id gu13-20020a056214260d00b005b4ccc04f60mr31325621qvb.37.1681300111003; Wed, 12 Apr 2023 04:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300110; cv=none; d=google.com; s=arc-20160816; b=kk/Ov+c217LsCYgp6C+jlYPCh3R8/rgWBjGS0o6tLBdZwnp1fOcjvI2R+eaPcPM2zs KoAbHRFWVNgPUPxwOQEnyIRmvGk7fDqeAmsVIpGmi8Ho2jS/0jyBvUzCLhyEmILAXNY5 +lAWXbEEDn42QF/XQEkXHlKf+j7pxIlCXD/ziUZkiIMIVXsSTt72TooUTDd8aJcJjUQx 01qfn6wZNzD5UKMZ5K6fefUSAGuWQgNXwnSlDZXZnbGp4N24NnnBjUli3KnQ+rmFhqKY 4ZzvFhuO7teHl7jMK9ZSji6x6EmBSh18vhPEL3+Hw66OARLEEQwdUHQGfTh1/bYIMOpm nLxg== 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:cc:to :from:dkim-signature; bh=jf2N922f7MxhHGZfTcgNdzsCq9UU22b0tOdlcxX9fy8=; b=b7PseRCgO+1NoYlO5So4KdlKg/ekl3NWhokT2uKdLKwCT/tiMaI5bbrRfO1PRWr4PV u238YF2y62QzYqjpUcfuanJrgZpaMRkXIB5pddWfWz3x4P0q81F0nN8ITBcODflQ1ek2 dHXsxHgahL6kngRfZlGt5xOVK6sDSHDQytTzTHUoa1N24mHxrNBKaLGqQmxciptDqNNA +e1KsvEfe3Kv6WAY3qR8MBIsUHiG7ogUkv25sFYyRqhgYClL/qhfYrijyxJMfAGMuD3p qukfN72h+j3vBqxVU3pZMO8I/U+fVALzORVoPnnzDP/j8TSj1GQVgD4DcFapNo/ceq9L Yv8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="v/jWYxdJ"; 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 i184-20020a3786c1000000b00747d1d07939si10297671qkd.655.2023.04.12.04.48.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:48:30 -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="v/jWYxdJ"; 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 1pmYtf-0005yk-Hd; Wed, 12 Apr 2023 07:44:19 -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 1pmYt9-0004ml-PL for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:47 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt7-0002PS-T9 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:47 -0400 Received: by mail-wr1-x42b.google.com with SMTP id g5so13963139wrb.5 for ; Wed, 12 Apr 2023 04:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299823; x=1683891823; 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=jf2N922f7MxhHGZfTcgNdzsCq9UU22b0tOdlcxX9fy8=; b=v/jWYxdJsgTuWFPt6wHpyVXn2fUj/zYPVBvMTgmj+8NBdxqnxOIr6zyx31dKLv5sb1 Sfie28Z3vW3trfGGnL5kSPdiUVVO0joqiR7ai//b4jKF19uxA9okt4+bE2EHzQaCMn0x APUQMJmhYKtWRT+nyCENCV+Uu85AydKyV98g5lkYq/bC83I2iPAFsGkhFFEE3SP2Q6eV o1lkCwKEPPHNT0/j+jblNG6qAu53yve3LL6hpW/fs1KH8pQ1K9XoPeuUP7jku/Vt7lEL WkRnCVFnDgwIQBaEyaNazdcfYly/h8jTN64LsmhvAV4QJ4+rWdTxMUjEAZEWUstQmoJa vU6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299823; x=1683891823; 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=jf2N922f7MxhHGZfTcgNdzsCq9UU22b0tOdlcxX9fy8=; b=PE7dsA15B32lB08sZsX45GAmtJ/+r72rrHicNk3JyRjlSpzTAbndotqQ7ZUiZrsMWx 2Oyo2KBzn+38aj9cmtx4pRiRBI+eQ1kAK7y5LKhffqpfUQ8cvwvPPWVFskaCC6gcjQHq NgvyvSMkB4Z6Z2YYQVMZUqF/dSnSMswQCE5qZ5miYRhC0QW31cQluTTZGfalCIZ9+EXY iaUTwAglwPL6hageHV10NwKmknvf7DZACif+TcHT/MEtEraka7DsRCUTeojETyl1x7bK f2wKXMmBEKH1Zcw/PTk+OjXDDp6U7pmhfUBa1coZtyecAV/lh6aAcII88oiO85/MZKm7 nOBA== X-Gm-Message-State: AAQBX9fefW6P8eNCalruf+WycQFnAcFHDde0ST1ZVPf1aVSMTYk53vOg 8slb+zbrYW719vr1uCcGtil0gXmywGP0BjD3JPeSr8sh X-Received: by 2002:a5d:4e8b:0:b0:2f5:20b:e944 with SMTP id e11-20020a5d4e8b000000b002f5020be944mr586206wru.29.1681299823058; Wed, 12 Apr 2023 04:43:43 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 09/25] target/riscv: Use cpu_ld*_code_mmu for HLVX Date: Wed, 12 Apr 2023 13:43:17 +0200 Message-Id: <20230412114333.118895-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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=unavailable 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 Use the new functions to properly check execute permission for the read rather than read permission. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-10-richard.henderson@linaro.org> --- target/riscv/op_helper.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 00bdf77f32..4a0bb5b11a 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -427,18 +427,27 @@ void helper_hyp_gvma_tlb_flush(CPURISCVState *env) helper_hyp_tlb_flush(env); } +/* + * TODO: These implementations are not quite correct. They perform the + * access using execute permission just fine, but the final PMP check + * is supposed to have read permission as well. Without replicating + * a fair fraction of cputlb.c, fixing this requires adding new mmu_idx + * which would imply that exact check in tlb_fill. + */ target_ulong helper_hyp_hlvx_hu(CPURISCVState *env, target_ulong address) { int mmu_idx = cpu_mmu_index(env, true) | MMU_HYP_ACCESS_BIT; + MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx); - return cpu_lduw_mmuidx_ra(env, address, mmu_idx, GETPC()); + return cpu_ldw_code_mmu(env, address, oi, GETPC()); } target_ulong helper_hyp_hlvx_wu(CPURISCVState *env, target_ulong address) { int mmu_idx = cpu_mmu_index(env, true) | MMU_HYP_ACCESS_BIT; + MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx); - return cpu_ldl_mmuidx_ra(env, address, mmu_idx, GETPC()); + return cpu_ldl_code_mmu(env, address, oi, GETPC()); } #endif /* !CONFIG_USER_ONLY */ From patchwork Wed Apr 12 11:43:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672632 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp290599wrx; Wed, 12 Apr 2023 04:53:07 -0700 (PDT) X-Google-Smtp-Source: AKy350aBivQQbO8jvkj0xkz6ulEORq+ekQ9xkVh3Q3eXIpX48N6QPL/PtDohkb8y+zHvbP1G/vwS X-Received: by 2002:a05:622a:553:b0:3ac:fba0:cde with SMTP id m19-20020a05622a055300b003acfba00cdemr26879172qtx.22.1681300387640; Wed, 12 Apr 2023 04:53:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300387; cv=none; d=google.com; s=arc-20160816; b=MJNRd1oNMS+Ro/Jbkfz92DuQvvJFDzCha7GyMaUceR870obl3exbruZNcYtlf3LXmo sOwWivGgt5FfVQh1LgQsUkrrbODyo/Pk1XdYPWYJRaP/FDsIiwrXzZNeUdUfAJ1m+jZK bywj+u7LqznYVkfxp5fyqmhTetikuZzUjYpYwvNC+O6dtlDi3oWot2hHwA4r/hS9OPJx XIOYLWdSs6a8oneW2pW06AQ7vS/gQFGBeAaupRqBgPGTxQaxCuAvDEfRkxNeXxyxs++P AETANjeYWnUh7vykIOoaebQG+zEpNqap4AJulXdoR7Hbu2Ku7aBER1r93hPzq54dFLbY P/oA== 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:cc:to :from:dkim-signature; bh=vKKuPzhzhJX3Aqm998ZahUXy3w/Jj2uJkgEst/LLnAU=; b=B8xmsXYPI+/SJCDTeZisjSHJLGFNdcD0zeelqWqmsjbusk+iJotKIDMoZRyiPO4Hfq JjasNzlM3rfhPTDDnb4XiP7FW9XE45DuMKqXYJCJ71ucxQCm4lCixW6n4VNiuhenWq3G aKuQ9OcgBWGcSj2DGzVdIR0gEpENRXCDODs55oCCyIv5p8POMgLxpTTNPw9vaxz3NUre LZ33WPUAutoV68B6bzx4iHy9OS4ZEjux37t5J0QbzKGZHuDoNqQGeqlsfGhnlShpjbR9 wKzBdV5XmBOH4nq8z84ugsx7jFSt+XImZIwEy20A5jEk3S0cjOcjndIHb4zDBM/HzLDL b/eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y01HkMiP; 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 e7-20020ac84e47000000b003e4ec4b5d7esi10553568qtw.30.2023.04.12.04.53.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:53:07 -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=y01HkMiP; 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 1pmYtX-0005Gc-7s; Wed, 12 Apr 2023 07:44:11 -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 1pmYtA-0004qi-OL for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:48 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt7-0002Q8-TH for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:48 -0400 Received: by mail-wr1-x42a.google.com with SMTP id l18so10512985wrb.9 for ; Wed, 12 Apr 2023 04:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299824; x=1683891824; 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=vKKuPzhzhJX3Aqm998ZahUXy3w/Jj2uJkgEst/LLnAU=; b=y01HkMiPV386N+ceVyAi1jdaV/cGlLe+C7Fb3zULUh+oUx5D1UCMuFdIQ+NXw7lRpd wdF8Q4xzRh912tgaoZwVGEQueHmE/+Dw3uLglTPonhIZUHFLeuUmb8/EYf2RBaBIS/Sm DOPKcXCVxkIi8BbOGFt4PzDnAQF2ok9lk6D55HrLEx947IkUy2B5opxUFJhQR/YKeBtY e9OsvjH4VkHKheXY/yFWOOK+mYHR5vetVaw5kkIzMM3yKBcI2uOmL6qWNf9NBVLPZiTi JI5FCNkWTYsXCjSDC6+eZFmVo+6HrjxrpeSr94ooQMEvCuHHQArIu3ofdBNP4VZpd4Rd K/wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299824; x=1683891824; 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=vKKuPzhzhJX3Aqm998ZahUXy3w/Jj2uJkgEst/LLnAU=; b=pDaGvlx+qeS3akYKuBNmKuYsjN6dAtl/OBhJb/icu8OhfUaouD2uf9PlbZBP9ZrRNs XKoqGXrygo6NPsO0JEMTiXYUqxWCJo7TJSkXYpTXB/XsCrX8sPwQ8GGExWkqR9g37AfW IWndhk7m6+AAtQBNTRgCpBjpq0Ft7CneZKaEZodV5Rr4OnqwvzKDfxYZVZHJt4/Mx7Re wyyyKEs00mjLBbu1/HydpwN/KVi1gBzeBtlBZrDUIMgepgNe8a1yMHW5aRSuzQJIXrpV 6d5bHsnwIwDnAy//Kb7igT3R+0qBGnf9VO5PxVd33hEMB5ta8zvp/5FgqX5SRdMj6m9F Wclg== X-Gm-Message-State: AAQBX9e95eWsGsO16rvHnWn0e+us1248CG6nCiDDgIk0nv/v3RmUS1e7 cb7xpYeEm5xgj0to9qKVKDj5UJzz/CgqNXsvW7Q0x1cQ X-Received: by 2002:adf:ce05:0:b0:2e5:1da2:2a06 with SMTP id p5-20020adfce05000000b002e51da22a06mr4513646wrn.5.1681299824055; Wed, 12 Apr 2023 04:43:44 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 10/25] target/riscv: Handle HLV, HSV via helpers Date: Wed, 12 Apr 2023 13:43:18 +0200 Message-Id: <20230412114333.118895-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42a.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 Implement these instructions via helpers, in expectation of determining the mmu_idx to use at runtime. This allows the permission check to also be moved out of line, which allows HLSX to be removed from TB_FLAGS. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-11-richard.henderson@linaro.org> --- target/riscv/cpu.h | 6 +- target/riscv/helper.h | 12 ++- target/riscv/cpu_helper.c | 26 ++--- target/riscv/op_helper.c | 99 +++++++++++++++-- target/riscv/translate.c | 2 - target/riscv/insn_trans/trans_rvh.c.inc | 137 ++++++++++-------------- 6 files changed, 169 insertions(+), 113 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6239c99f4c..35cf2e2691 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -639,8 +639,7 @@ FIELD(TB_FLAGS, LMUL, 7, 3) FIELD(TB_FLAGS, SEW, 10, 3) FIELD(TB_FLAGS, VL_EQ_VLMAX, 13, 1) FIELD(TB_FLAGS, VILL, 14, 1) -/* Is a Hypervisor instruction load/store allowed? */ -FIELD(TB_FLAGS, HLSX, 15, 1) +FIELD(TB_FLAGS, VSTART_EQ_ZERO, 15, 1) /* The combination of MXL/SXL/UXL that applies to the current cpu mode. */ FIELD(TB_FLAGS, XL, 16, 2) /* If PointerMasking should be applied */ @@ -652,8 +651,7 @@ FIELD(TB_FLAGS, VMA, 21, 1) FIELD(TB_FLAGS, ITRIGGER, 22, 1) /* Virtual mode enabled */ FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1) -FIELD(TB_FLAGS, VSTART_EQ_ZERO, 24, 1) -FIELD(TB_FLAGS, PRIV, 25, 2) +FIELD(TB_FLAGS, PRIV, 24, 2) #ifdef TARGET_RISCV32 #define riscv_cpu_mxl(env) ((void)(env), MXL_RV32) diff --git a/target/riscv/helper.h b/target/riscv/helper.h index 1880e95c50..98e97810fd 100644 --- a/target/riscv/helper.h +++ b/target/riscv/helper.h @@ -123,8 +123,16 @@ DEF_HELPER_1(itrigger_match, void, env) #ifndef CONFIG_USER_ONLY DEF_HELPER_1(hyp_tlb_flush, void, env) DEF_HELPER_1(hyp_gvma_tlb_flush, void, env) -DEF_HELPER_2(hyp_hlvx_hu, tl, env, tl) -DEF_HELPER_2(hyp_hlvx_wu, tl, env, tl) +DEF_HELPER_FLAGS_2(hyp_hlv_bu, TCG_CALL_NO_WG, tl, env, tl) +DEF_HELPER_FLAGS_2(hyp_hlv_hu, TCG_CALL_NO_WG, tl, env, tl) +DEF_HELPER_FLAGS_2(hyp_hlv_wu, TCG_CALL_NO_WG, tl, env, tl) +DEF_HELPER_FLAGS_2(hyp_hlv_d, TCG_CALL_NO_WG, tl, env, tl) +DEF_HELPER_FLAGS_2(hyp_hlvx_hu, TCG_CALL_NO_WG, tl, env, tl) +DEF_HELPER_FLAGS_2(hyp_hlvx_wu, TCG_CALL_NO_WG, tl, env, tl) +DEF_HELPER_FLAGS_3(hyp_hsv_b, TCG_CALL_NO_WG, void, env, tl, tl) +DEF_HELPER_FLAGS_3(hyp_hsv_h, TCG_CALL_NO_WG, void, env, tl, tl) +DEF_HELPER_FLAGS_3(hyp_hsv_w, TCG_CALL_NO_WG, void, env, tl, tl) +DEF_HELPER_FLAGS_3(hyp_hsv_d, TCG_CALL_NO_WG, void, env, tl, tl) #endif /* Vector functions */ diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 174a77706b..abf275d2c6 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -102,24 +102,16 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, fs = get_field(env->mstatus, MSTATUS_FS); vs = get_field(env->mstatus, MSTATUS_VS); - if (riscv_has_ext(env, RVH)) { - if (env->priv == PRV_M || - (env->priv == PRV_S && !env->virt_enabled) || - (env->priv == PRV_U && !env->virt_enabled && - get_field(env->hstatus, HSTATUS_HU))) { - flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1); - } - - if (env->virt_enabled) { - flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, 1); - /* - * Merge DISABLED and !DIRTY states using MIN. - * We will set both fields when dirtying. - */ - fs = MIN(fs, get_field(env->mstatus_hs, MSTATUS_FS)); - vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS)); - } + if (env->virt_enabled) { + flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, 1); + /* + * Merge DISABLED and !DIRTY states using MIN. + * We will set both fields when dirtying. + */ + fs = MIN(fs, get_field(env->mstatus_hs, MSTATUS_FS)); + vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS)); } + if (cpu->cfg.debug && !icount_enabled()) { flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); } diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 4a0bb5b11a..663382785e 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -427,6 +427,91 @@ void helper_hyp_gvma_tlb_flush(CPURISCVState *env) helper_hyp_tlb_flush(env); } +static int check_access_hlsv(CPURISCVState *env, bool x, uintptr_t ra) +{ + if (env->priv == PRV_M) { + /* always allowed */ + } else if (env->virt_enabled) { + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, ra); + } else if (env->priv == PRV_U && !get_field(env->hstatus, HSTATUS_HU)) { + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); + } + + return cpu_mmu_index(env, x) | MMU_HYP_ACCESS_BIT; +} + +target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx); + + return cpu_ldb_mmu(env, addr, oi, ra); +} + +target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx); + + return cpu_ldw_mmu(env, addr, oi, ra); +} + +target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx); + + return cpu_ldl_mmu(env, addr, oi, ra); +} + +target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_TEUQ, mmu_idx); + + return cpu_ldq_mmu(env, addr, oi, ra); +} + +void helper_hyp_hsv_b(CPURISCVState *env, target_ulong addr, target_ulong val) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_UB, mmu_idx); + + cpu_stb_mmu(env, addr, val, oi, ra); +} + +void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong val) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx); + + cpu_stw_mmu(env, addr, val, oi, ra); +} + +void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong val) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx); + + cpu_stl_mmu(env, addr, val, oi, ra); +} + +void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong val) +{ + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, false, ra); + MemOpIdx oi = make_memop_idx(MO_TEUQ, mmu_idx); + + cpu_stq_mmu(env, addr, val, oi, ra); +} + /* * TODO: These implementations are not quite correct. They perform the * access using execute permission just fine, but the final PMP check @@ -434,20 +519,22 @@ void helper_hyp_gvma_tlb_flush(CPURISCVState *env) * a fair fraction of cputlb.c, fixing this requires adding new mmu_idx * which would imply that exact check in tlb_fill. */ -target_ulong helper_hyp_hlvx_hu(CPURISCVState *env, target_ulong address) +target_ulong helper_hyp_hlvx_hu(CPURISCVState *env, target_ulong addr) { - int mmu_idx = cpu_mmu_index(env, true) | MMU_HYP_ACCESS_BIT; + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, true, ra); MemOpIdx oi = make_memop_idx(MO_TEUW, mmu_idx); - return cpu_ldw_code_mmu(env, address, oi, GETPC()); + return cpu_ldw_code_mmu(env, addr, oi, GETPC()); } -target_ulong helper_hyp_hlvx_wu(CPURISCVState *env, target_ulong address) +target_ulong helper_hyp_hlvx_wu(CPURISCVState *env, target_ulong addr) { - int mmu_idx = cpu_mmu_index(env, true) | MMU_HYP_ACCESS_BIT; + uintptr_t ra = GETPC(); + int mmu_idx = check_access_hlsv(env, true, ra); MemOpIdx oi = make_memop_idx(MO_TEUL, mmu_idx); - return cpu_ldl_code_mmu(env, address, oi, GETPC()); + return cpu_ldl_code_mmu(env, addr, oi, ra); } #endif /* !CONFIG_USER_ONLY */ diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 6d59348f0c..928da0d3f0 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -80,7 +80,6 @@ typedef struct DisasContext { bool virt_inst_excp; bool virt_enabled; const RISCVCPUConfig *cfg_ptr; - bool hlsx; /* vector extension */ bool vill; /* @@ -1163,7 +1162,6 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa_ext = env->misa_ext; ctx->frm = -1; /* unknown rounding mode */ ctx->cfg_ptr = &(cpu->cfg); - ctx->hlsx = FIELD_EX32(tb_flags, TB_FLAGS, HLSX); ctx->vill = FIELD_EX32(tb_flags, TB_FLAGS, VILL); ctx->sew = FIELD_EX32(tb_flags, TB_FLAGS, SEW); ctx->lmul = sextract32(FIELD_EX32(tb_flags, TB_FLAGS, LMUL), 0, 3); diff --git a/target/riscv/insn_trans/trans_rvh.c.inc b/target/riscv/insn_trans/trans_rvh.c.inc index ae98b45e5e..3e9322130f 100644 --- a/target/riscv/insn_trans/trans_rvh.c.inc +++ b/target/riscv/insn_trans/trans_rvh.c.inc @@ -16,158 +16,131 @@ * this program. If not, see . */ -#ifndef CONFIG_USER_ONLY -static bool check_access(DisasContext *ctx) -{ - if (!ctx->hlsx) { - tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, - offsetof(CPURISCVState, bins)); - if (ctx->virt_enabled) { - generate_exception(ctx, RISCV_EXCP_VIRT_INSTRUCTION_FAULT); - } else { - generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST); - } - return false; - } - return true; -} -#endif - -static bool do_hlv(DisasContext *ctx, arg_r2 *a, MemOp mop) -{ #ifdef CONFIG_USER_ONLY - return false; +#define do_hlv(ctx, a, func) false +#define do_hsv(ctx, a, func) false #else - decode_save_opc(ctx); - if (check_access(ctx)) { - TCGv dest = dest_gpr(ctx, a->rd); - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); - int mem_idx = ctx->mem_idx | MMU_HYP_ACCESS_BIT; - tcg_gen_qemu_ld_tl(dest, addr, mem_idx, mop); - gen_set_gpr(ctx, a->rd, dest); - } - return true; -#endif +static void gen_helper_hyp_hlv_b(TCGv r, TCGv_env e, TCGv a) +{ + gen_helper_hyp_hlv_bu(r, e, a); + tcg_gen_ext8s_tl(r, r); } +static void gen_helper_hyp_hlv_h(TCGv r, TCGv_env e, TCGv a) +{ + gen_helper_hyp_hlv_hu(r, e, a); + tcg_gen_ext16s_tl(r, r); +} + +static void gen_helper_hyp_hlv_w(TCGv r, TCGv_env e, TCGv a) +{ + gen_helper_hyp_hlv_wu(r, e, a); + tcg_gen_ext32s_tl(r, r); +} + +static bool do_hlv(DisasContext *ctx, arg_r2 *a, + void (*func)(TCGv, TCGv_env, TCGv)) +{ + TCGv dest = dest_gpr(ctx, a->rd); + TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); + + decode_save_opc(ctx); + func(dest, cpu_env, addr); + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool do_hsv(DisasContext *ctx, arg_r2_s *a, + void (*func)(TCGv_env, TCGv, TCGv)) +{ + TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); + TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); + + decode_save_opc(ctx); + func(cpu_env, addr, data); + return true; +} +#endif /* CONFIG_USER_ONLY */ + static bool trans_hlv_b(DisasContext *ctx, arg_hlv_b *a) { REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_SB); + return do_hlv(ctx, a, gen_helper_hyp_hlv_b); } static bool trans_hlv_h(DisasContext *ctx, arg_hlv_h *a) { REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_TESW); + return do_hlv(ctx, a, gen_helper_hyp_hlv_h); } static bool trans_hlv_w(DisasContext *ctx, arg_hlv_w *a) { REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_TESL); + return do_hlv(ctx, a, gen_helper_hyp_hlv_w); } static bool trans_hlv_bu(DisasContext *ctx, arg_hlv_bu *a) { REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_UB); + return do_hlv(ctx, a, gen_helper_hyp_hlv_bu); } static bool trans_hlv_hu(DisasContext *ctx, arg_hlv_hu *a) { REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_TEUW); -} - -static bool do_hsv(DisasContext *ctx, arg_r2_s *a, MemOp mop) -{ -#ifdef CONFIG_USER_ONLY - return false; -#else - decode_save_opc(ctx); - if (check_access(ctx)) { - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); - TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); - int mem_idx = ctx->mem_idx | MMU_HYP_ACCESS_BIT; - tcg_gen_qemu_st_tl(data, addr, mem_idx, mop); - } - return true; -#endif + return do_hlv(ctx, a, gen_helper_hyp_hlv_hu); } static bool trans_hsv_b(DisasContext *ctx, arg_hsv_b *a) { REQUIRE_EXT(ctx, RVH); - return do_hsv(ctx, a, MO_SB); + return do_hsv(ctx, a, gen_helper_hyp_hsv_b); } static bool trans_hsv_h(DisasContext *ctx, arg_hsv_h *a) { REQUIRE_EXT(ctx, RVH); - return do_hsv(ctx, a, MO_TESW); + return do_hsv(ctx, a, gen_helper_hyp_hsv_h); } static bool trans_hsv_w(DisasContext *ctx, arg_hsv_w *a) { REQUIRE_EXT(ctx, RVH); - return do_hsv(ctx, a, MO_TESL); + return do_hsv(ctx, a, gen_helper_hyp_hsv_w); } static bool trans_hlv_wu(DisasContext *ctx, arg_hlv_wu *a) { REQUIRE_64BIT(ctx); REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_TEUL); + return do_hlv(ctx, a, gen_helper_hyp_hlv_wu); } static bool trans_hlv_d(DisasContext *ctx, arg_hlv_d *a) { REQUIRE_64BIT(ctx); REQUIRE_EXT(ctx, RVH); - return do_hlv(ctx, a, MO_TEUQ); + return do_hlv(ctx, a, gen_helper_hyp_hlv_d); } static bool trans_hsv_d(DisasContext *ctx, arg_hsv_d *a) { REQUIRE_64BIT(ctx); REQUIRE_EXT(ctx, RVH); - return do_hsv(ctx, a, MO_TEUQ); + return do_hsv(ctx, a, gen_helper_hyp_hsv_d); } -#ifndef CONFIG_USER_ONLY -static bool do_hlvx(DisasContext *ctx, arg_r2 *a, - void (*func)(TCGv, TCGv_env, TCGv)) -{ - decode_save_opc(ctx); - if (check_access(ctx)) { - TCGv dest = dest_gpr(ctx, a->rd); - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); - func(dest, cpu_env, addr); - gen_set_gpr(ctx, a->rd, dest); - } - return true; -} -#endif - static bool trans_hlvx_hu(DisasContext *ctx, arg_hlvx_hu *a) { REQUIRE_EXT(ctx, RVH); -#ifndef CONFIG_USER_ONLY - return do_hlvx(ctx, a, gen_helper_hyp_hlvx_hu); -#else - return false; -#endif + return do_hlv(ctx, a, gen_helper_hyp_hlvx_hu); } static bool trans_hlvx_wu(DisasContext *ctx, arg_hlvx_wu *a) { REQUIRE_EXT(ctx, RVH); -#ifndef CONFIG_USER_ONLY - return do_hlvx(ctx, a, gen_helper_hyp_hlvx_wu); -#else - return false; -#endif + return do_hlv(ctx, a, gen_helper_hyp_hlvx_wu); } static bool trans_hfence_gvma(DisasContext *ctx, arg_sfence_vma *a) From patchwork Wed Apr 12 11:43:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672617 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288187wrx; Wed, 12 Apr 2023 04:46:45 -0700 (PDT) X-Google-Smtp-Source: AKy350bGGw6UF4hSkdCCwC8gexBFo1x9iJdrAjFmmtawp0OR1u/efrO49JUPPrYPHKRefinLtvCW X-Received: by 2002:a05:622a:ca:b0:3bf:d8b6:4ca1 with SMTP id p10-20020a05622a00ca00b003bfd8b64ca1mr29474846qtw.28.1681300005197; Wed, 12 Apr 2023 04:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300005; cv=none; d=google.com; s=arc-20160816; b=pCeYBW6JhEzPne43DY0ichoxBSYVE4ePn85jmLSRlJpDsrO0VL5W+1FWvcPTlY3voK VKrNqa7bOuuKuNqja9HyxG9SvCK0PMpxW80zVQfxwm876o1P6aw9niSnXFRsavVjCnSd lDDwqXxINgcXImxGaFjZR2mHi3hlTEQx4oG9+YTgayXCQHsk39utkwAVKkfny4cR39CY M1t9+Lj2P/x7iBF8EkRU76t76zlL5V99B70dk8E5rtQLc7koJoOcvLIktNTXjCUc8ic4 pbBLGcSdKOIOk3IT7jRjMSZqIWGd8Sn5685jJPwqHk3yP39VSc7WxONX2IR/EKL7ib1i Psfw== 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:cc:to :from:dkim-signature; bh=d5xHxmaEOgXeHn2A8bHUUouqfxAhC2pmFZSPjP/T4RA=; b=Id2BaZ3zeSqOxLSzbZs0Adnt8whVeB5phyG3V8V6ao2GmvIq0WizdmOqb7gZUBbOXX If93accXDyXfr4a8ndoLUtLrYecXWkYEkvOxfigOzj+NsbHld4vCvVjeW0fxQ0ujR3Xb hPKvm+QYbuM2QEuL+GEEH59d0KshZ2YrinbV8n1MFlk8iexySv1I9ABTIlPewhTYDIvg 8Tf1pz+ML+1DNhlyf+09ZqrNc9y5kFmgmI4mM6bMTl4c74Gkonl2xJHjCMHUG7F/8Hx9 85AeP1hABGP+m9Vu+YqoPOsatNb5vXCEwh0NsDN/K1Zmw5IY/09zl7UfS9qgsBKUrKc5 Ps2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iUFz6FMN; 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 e22-20020a05622a111600b003bd00fdf974si10818829qty.9.2023.04.12.04.46.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:46:45 -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=iUFz6FMN; 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 1pmYte-0005nN-4E; Wed, 12 Apr 2023 07:44:18 -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 1pmYtB-0004rG-2j for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:49 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt9-0002QF-6w for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:48 -0400 Received: by mail-wr1-x436.google.com with SMTP id j11so14219544wrd.2 for ; Wed, 12 Apr 2023 04:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299825; x=1683891825; 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=d5xHxmaEOgXeHn2A8bHUUouqfxAhC2pmFZSPjP/T4RA=; b=iUFz6FMNJKOwmKWjet0a5BDbOC5RP1/hvbzKia/CJNC51T0WUDnyNUtoW2yCKYdG8O m9+SPinDpvdG9KU4qwEsJXozVJJF3CB2pLxyf52CXZfL6P6v0TELHRmsAb6YdGi8LIxY EMi2CzNH8ZtBzDKlvukANZENiWe1qZ3OosWsTwKBlU3R+I7gkPs/kgP394NMeCHNluCQ JTuW+gLChrF134ow9A0WVK33F0rlXQYMyDXJ7VuBLjaF1d8y2YHUmGK8M+3w5OzikwW8 5bms+kTZrBUl2Q5joojdDXJs1Q0C0k+KF9UavbY1sC/MhaoYAD6PGOsOqrNibK8kymKF 0M5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299825; x=1683891825; 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=d5xHxmaEOgXeHn2A8bHUUouqfxAhC2pmFZSPjP/T4RA=; b=I7D04VYVkLZruxBPAWDi2/nuHlX8XaUKQA8Yzds7wDTLd3MzuFV+13zNVSJSyc8j4Y +FsEOvre+u54apjpK5c8dO1SyT0Jj4Q8ODRt7Y4Va5ypZKxkrXTMuZBIUwJr9tCiPtTH GU/o1P8X5TEb6IrdTn6EaqVrWlveXqSm2uXrqQfJimOg4cGbGON2SFoIe/uAlmAKKTqD MKDy+cN3C7hFpLUqpNwpPGSHPS/mO2JZ4CMxF0Sv4ozB5tI1a2b7IoieCbSxso3U4GO5 /FnFg7W3ii95fopEaSrn0PU0S36Np1w6x8h/wISWtqokLNt/bYOFjE9YchRsPUw7dLe7 G7/Q== X-Gm-Message-State: AAQBX9e7p0lGYAOA4Bq4t354Bspuv8EWRVk2txw2Yp9/d0R9m1vUw+ml sI2ClekNR5oCY+KKcjMPdcwhXhCcJOAtaut0qOy7VdNV X-Received: by 2002:adf:e34c:0:b0:2e5:a86c:fe74 with SMTP id n12-20020adfe34c000000b002e5a86cfe74mr8403377wrj.51.1681299824828; Wed, 12 Apr 2023 04:43:44 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 11/25] target/riscv: Rename MMU_HYP_ACCESS_BIT to MMU_2STAGE_BIT Date: Wed, 12 Apr 2023 13:43:19 +0200 Message-Id: <20230412114333.118895-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x436.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=unavailable 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 We will enable more uses of this bit in the future. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-12-richard.henderson@linaro.org> --- target/riscv/internals.h | 6 ++++-- target/riscv/cpu_helper.c | 2 +- target/riscv/op_helper.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index b55152a7dc..7b63c0f1b6 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -27,13 +27,15 @@ * - S 0b001 * - S+SUM 0b010 * - M 0b011 - * - HLV/HLVX/HSV adds 0b100 + * - U+2STAGE 0b100 + * - S+2STAGE 0b101 + * - S+SUM+2STAGE 0b110 */ #define MMUIdx_U 0 #define MMUIdx_S 1 #define MMUIdx_S_SUM 2 #define MMUIdx_M 3 -#define MMU_HYP_ACCESS_BIT (1 << 2) +#define MMU_2STAGE_BIT (1 << 2) /* share data between vector helpers and decode code */ FIELD(VDATA, VM, 0, 1) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index abf275d2c6..291a1acbf7 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -593,7 +593,7 @@ void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable) bool riscv_cpu_two_stage_lookup(int mmu_idx) { - return mmu_idx & MMU_HYP_ACCESS_BIT; + return mmu_idx & MMU_2STAGE_BIT; } int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts) diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 663382785e..a5de3daee7 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -437,7 +437,7 @@ static int check_access_hlsv(CPURISCVState *env, bool x, uintptr_t ra) riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); } - return cpu_mmu_index(env, x) | MMU_HYP_ACCESS_BIT; + return cpu_mmu_index(env, x) | MMU_2STAGE_BIT; } target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr) From patchwork Wed Apr 12 11:43:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672608 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287239wrx; Wed, 12 Apr 2023 04:44:18 -0700 (PDT) X-Google-Smtp-Source: AKy350brUcWhI/42fFuCSarDYx0aIBndWlvsCHxpCg6lRybdItzBDbR2yDmIo4wMknh4TbH05PFx X-Received: by 2002:ac8:5888:0:b0:3e6:4b7b:253 with SMTP id t8-20020ac85888000000b003e64b7b0253mr31279654qta.7.1681299858555; Wed, 12 Apr 2023 04:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299858; cv=none; d=google.com; s=arc-20160816; b=bhso8wdeAROw8MUMRgkV3gihtpV8bF6mY6Yc36U+5lLQbUvQ+vHZGLIddzim0EIs4A 3xzIVpZVeiBYfO4/38X3h4YAY6DXCFfEqlqYp0606shyxkxnXV/UgXoJU/UvBm6l4Xq6 3q/5FxLSMfOY7FaJhCehw8kwb1hP5cgpLWqt3/zXKymShciwNPCc6ve67SevZaV8P0FB 6Gq3l7DrrN+h1+Byi+ooCYYQR/4yLxd8oLmUNmGtAI2G2lGAui9Oc7DLhPZEYQcNmBPy cMpwseHcco/y7QsyUUCJHAjefr22QflTKsqcBQpetYazM86I0sO4EG3OhGj0TvTKHXl/ iaWg== 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:cc:to :from:dkim-signature; bh=3Lv2amYuxnL/rjHsnpYSrIfjZprlyKOd0sUgv/cdui0=; b=cW5YYZaQeR5jqLGggvdgnyFjy74A4z8LAb7F1dn1KeB05Oi5yfAl//dlDMq1a6PFBk P56GKKMxL1QM2O6LIo5yH5Jed5Hkl98ri4xpvmC22kv+BKuL/DZd2drxE0PTCiRk+fH5 wGlPhZOoxiVkN/iA85P32xYiXvx+myNftxlYzZKaf3utRq9p/UR3RJh17pFwoCieF8IZ yIDPTMuOBkU2yVJAQuzP5v8bwQEGYBMhOZSFTtrlrgzMCHLMoCeK5YHjB4jeGdKJzJob EHpDnlTqOkaZBZZZtk4Xcd2h/WubjtX2bTG9YKiNHTfhnxONl/WLMotzcQ77MZiyWpp9 hxzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dxAvSN0Z; 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 w8-20020ac857c8000000b003ba35fdb9b4si10574581qta.280.2023.04.12.04.44.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:18 -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=dxAvSN0Z; 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 1pmYtQ-0004z2-JA; Wed, 12 Apr 2023 07:44:08 -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 1pmYtB-0004s0-PI for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:50 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYt9-0002NQ-72 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:49 -0400 Received: by mail-wr1-x430.google.com with SMTP id e7so493967wrc.12 for ; Wed, 12 Apr 2023 04:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299825; x=1683891825; 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=3Lv2amYuxnL/rjHsnpYSrIfjZprlyKOd0sUgv/cdui0=; b=dxAvSN0Za8XtSpewBHotI+liYkI3R0XrGZHy6SfbuCEyIm+MtuFxfbEFSzIPpEJAdS fisDH/mrWbVKN0sPmo21Uj+sNykOQQEIsaJt+/3JqfN2mDEIEuU4OFGaTGnoamkefCxj 6WvLu1enXEJvVTVFvl2YD2p/u3jHl8RZ3xLOpWUJV9cDapiclgm5Kbd2hZZq2H3byg0D NR4ED99Azidh5iIcL8mFWah1sux7Vc6gsJmIA088+/ENagtw3NOl8gVMpmskUuHdAbWo SH7ASFGp4zmfIeGVXUTgOm2eKloNo0G7Qgz2JmRFvO7pmRQvLFgXywDDVRC4bd4iZ39T 7pdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299825; x=1683891825; 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=3Lv2amYuxnL/rjHsnpYSrIfjZprlyKOd0sUgv/cdui0=; b=RgOIzyYG29A7j0MCo8oS4+tKhGIFau/ufaLKzIgP+1udCrjInxq9yW6QvsuPZJHT2K blq0Af2DkLe9dGYCU0PnRNj2Hcnv1D0MwX4qKVcXj51akNhDEKmg11DpczqqJJXjq1Na n87UUnuB7GLjQml2noGrHW9zu5nWJQgMCSDsgP3jUL4OnE7qmzYLPYuqTnrcNvyJQAnD R1o4xNfDkDyyeeMZvdnZ7CuEA4zKKGK2kOjaW3x63xDSKwYJkM/OiESD4FACKi1YsVgY amDhMA3hMh0SjdTcZV4pDapp++bWKSIX0wjsV+HNqLDEQ+9NsxOb3Vr3Csc2w6EF7wVy S8gw== X-Gm-Message-State: AAQBX9cim2VgDqP24IWEVInasWRTrSh3UVxu7mWsgsnhAZx5IAEllVG6 IwpvJDxvZ/C3hYCUcCUW93WZVOIpEouOIdlDWPylwLnV X-Received: by 2002:adf:f2c5:0:b0:2d1:70cc:66e0 with SMTP id d5-20020adff2c5000000b002d170cc66e0mr1541381wrp.44.1681299825582; Wed, 12 Apr 2023 04:43:45 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 12/25] target/riscv: Introduce mmuidx_sum Date: Wed, 12 Apr 2023 13:43:20 +0200 Message-Id: <20230412114333.118895-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x430.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=unavailable 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 In get_physical_address, we should use the setting passed via mmu_idx rather than checking env->mstatus directly. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-13-richard.henderson@linaro.org> --- target/riscv/internals.h | 5 +++++ target/riscv/cpu_helper.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 7b63c0f1b6..0b61f337dd 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -37,6 +37,11 @@ #define MMUIdx_M 3 #define MMU_2STAGE_BIT (1 << 2) +static inline bool mmuidx_sum(int mmu_idx) +{ + return (mmu_idx & 3) == MMUIdx_S_SUM; +} + /* share data between vector helpers and decode code */ FIELD(VDATA, VM, 0, 1) FIELD(VDATA, LMUL, 1, 3) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 291a1acbf7..29ee9b1b42 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -842,7 +842,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, widened = 2; } /* status.SUM will be ignored if execute on background */ - sum = get_field(env->mstatus, MSTATUS_SUM) || use_background || is_debug; + sum = mmuidx_sum(mmu_idx) || use_background || is_debug; switch (vm) { case VM_1_10_SV32: levels = 2; ptidxbits = 10; ptesize = 4; break; From patchwork Wed Apr 12 11:43:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672615 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287482wrx; Wed, 12 Apr 2023 04:44:58 -0700 (PDT) X-Google-Smtp-Source: AKy350aKFcfDgJLECnzXutqicalLITUAkYYn95QY+cs7PHK8pIa66sg4ClbwbmyDK/aQCw9pRycQ X-Received: by 2002:ad4:5aed:0:b0:5ed:ca29:22f0 with SMTP id c13-20020ad45aed000000b005edca2922f0mr10278077qvh.17.1681299897850; Wed, 12 Apr 2023 04:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299897; cv=none; d=google.com; s=arc-20160816; b=HKfYyc2BDdJIEYNargR5DpGkK+F3+YCdD9/9g8L92wvAEMsz8qGlyEul2jpC+udJ29 YURL61wW/54CIKrz7XNGYEovy/cbWuPISROwQweRcQmaKIyVYTpIYjwonDX3WIN1f0lF ocRSHgBbl7gnqwWd7hND5Y+YsrKZfNJ95Bbeh7gvJ55SX7hVSmjl0UA884EY6QViHQ9g e5LwmVC10HJHE4tnRV73a1RxNNXLCDVBMlygZDV/k2wPC/cb6Bf11/X7I6259WWIKbME YcMSaluepX7VDF4CZ68YGCMTGMtH6u95E2K85famRUSoSCDB7dCJW1BCoabxknUA7uDu rG0w== 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:cc:to :from:dkim-signature; bh=ctqzVVZjJ45Im/ugL7sow9fNEblGak+zrzESoiQbQPE=; b=nsJiZqCiKCp7jN3UcfUPIyllAjK+F/IbBPwhrMY4vJu/AcmknoWjM3KDcVdk4cKzM/ bMbeeV1Qxh7sdBYfKdsQBBwvihB28vUJUGDPoIz4nqZO+6liAllcJk/QXHj66nl8yheI fOKYaEnxxvtkYXCuZurpm7NEoWHcE9p4r34Ba3RiO/j8qobRXyXXJ+4UXwe1LuvX02Zg xJ0He7W5Lym7miv7oFgYmO6A0G29sfIlBiFLmoQOrc1HXY5o+kbVJp0u4jxjdjED/67H Mj9Ad1/G5JWhMRfyrcNli/PxzPCtSdFRM0QDjCEU0sueq5XcDcloVGgYc55w3jSLISMD NlZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xUJ/UTUS"; 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 j187-20020a37b9c4000000b0071a7a156eebsi9951599qkf.240.2023.04.12.04.44.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:57 -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="xUJ/UTUS"; 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 1pmYtb-0005VB-Kj; Wed, 12 Apr 2023 07:44:15 -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 1pmYtC-0004sW-6x for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:50 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtA-0002RC-Fq for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:49 -0400 Received: by mail-wr1-x434.google.com with SMTP id g5so13963307wrb.5 for ; Wed, 12 Apr 2023 04:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299826; x=1683891826; 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=ctqzVVZjJ45Im/ugL7sow9fNEblGak+zrzESoiQbQPE=; b=xUJ/UTUS1t2FeTQIcLLY7FY8FvnT0PrL2a2JNjJB4DJztR2lK/dqGE+j+aoTJ16ncB dMfavDP08SUjeKTCxh6HejLswjK8pdHCg1RQ3LDkNPoKcYNk5W8Q9VOliTQ7DqxzTZYB jOVkSZQcAjNV4Vpxg/cbEPQyhrW2SYWX7nzzBmlDSLkLMB5xjxAdilOswW8EIIiKLxpw +iXDtReQ/AC2WUAnJXpXM0hkuL0hScHyMVySKO3qxeh8hYNNGvUIOR4I3ssNU9vI5qJB tRGtM6Cw3gpfC7ZM/Ikl4PbIL7d41fPJr9Uvns5cqKNRXpaeFzvvP68KZnP76kntXzSH r8AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299826; x=1683891826; 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=ctqzVVZjJ45Im/ugL7sow9fNEblGak+zrzESoiQbQPE=; b=5xVj83psEJYfgJJqtn1QAU7ZIAYKo5XAcVWCx9HXr0E7QmQ0LqXBNtRmXn4Ox6E/kQ 9LkgS9cxovPFfxihL7rk5PGYyswAgeWv8pD0NaxGvyHjFBss9CYFWdpOh5P6kVW/KJLe 2D6xms1av1Am9P+eXhHzYQcR1VE9c8x7pSL42B4wpjGQMcc2543G3nsGxoG8DhHg8Jse 1Vn1yC0qDZZqkIsCm2fXQbnQJLJp0ADZQs7+/62upeK5thUvzCFmIaMNfGytMsZ1GdxK y2fYyU43Rsez5DVSUrMuZJGzqnngfwN1INFeROSKJfcjibhH2BlAKi8ftSkO/HoJk8Iy Pqew== X-Gm-Message-State: AAQBX9fNwce1Ed6+4iSDHv4JTX0wOrpL4uElm+lYx4e6GcGzQTn/OcQq LMePvHXLSP6fjKRR/sVsjVUUptzo02pB5emxWWjP9hqA X-Received: by 2002:a5d:4b4c:0:b0:2f2:af44:60e7 with SMTP id w12-20020a5d4b4c000000b002f2af4460e7mr1598229wrs.68.1681299826504; Wed, 12 Apr 2023 04:43:46 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 13/25] target/riscv: Introduce mmuidx_priv Date: Wed, 12 Apr 2023 13:43:21 +0200 Message-Id: <20230412114333.118895-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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 Use the priv level encoded into the mmu_idx, rather than starting from env->priv. We have already checked MPRV+MPP in riscv_cpu_mmu_index -- no need to repeat that. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-14-richard.henderson@linaro.org> --- target/riscv/internals.h | 9 +++++++++ target/riscv/cpu_helper.c | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 0b61f337dd..4aa1cb409f 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -37,6 +37,15 @@ #define MMUIdx_M 3 #define MMU_2STAGE_BIT (1 << 2) +static inline int mmuidx_priv(int mmu_idx) +{ + int ret = mmu_idx & 3; + if (ret == MMUIdx_S_SUM) { + ret = PRV_S; + } + return ret; +} + static inline bool mmuidx_sum(int mmu_idx) { return (mmu_idx & 3) == MMUIdx_S_SUM; diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 29ee9b1b42..57bb19c76e 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -758,7 +758,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, */ MemTxResult res; MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; - int mode = env->priv; + int mode = mmuidx_priv(mmu_idx); bool use_background = false; hwaddr ppn; int napot_bits = 0; @@ -781,10 +781,6 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, */ if (riscv_cpu_two_stage_lookup(mmu_idx)) { mode = get_field(env->hstatus, HSTATUS_SPVP); - } else if (mode == PRV_M && access_type != MMU_INST_FETCH) { - if (get_field(env->mstatus, MSTATUS_MPRV)) { - mode = get_field(env->mstatus, MSTATUS_MPP); - } } if (first_stage == false) { From patchwork Wed Apr 12 11:43:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672611 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287288wrx; Wed, 12 Apr 2023 04:44:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YB8nIE3RMgunwqzBISwYnZTqvZXR8A583ys+Zn6FJRq8fhQwUtUlKXqC+q+4x+BGWRatAf X-Received: by 2002:ad4:5c6a:0:b0:5c7:d03c:f2b2 with SMTP id i10-20020ad45c6a000000b005c7d03cf2b2mr28470524qvh.28.1681299867651; Wed, 12 Apr 2023 04:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299867; cv=none; d=google.com; s=arc-20160816; b=myvzVzuSrsVHEt/Mw32Q6dNWN6SkmhDnCuF3w1OMH8qdeQrMZC9b+ITtqXLv47fTsm Hg4oCW3vTnhyaMXpycF6lGf5AQtB7x12YTFX8nyKsI7CCnaNF+vLTOLfUP9HFp2azbZB mJ9h+SdwsPZbOyfXM+9uMCwySeAF6lcI4zOmTxAlKETsCPqJXZMSInmnPIN13GSdZLhr rw7hvWVY2W3CiPq0aF0XlEfVzBRx2G2mYkBvtuqUUHxWE2qRiL6yY5ziXTlpmBNjPB3e lyuT0qL/oXp7Uh8N/NaRJkWg3yK6NBBB+4IOoHK64hzrkQDIrtCOdq5/ZNc7K8m/zSTY ld7g== 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:cc:to :from:dkim-signature; bh=a4Zsigsmxtifc1mTfNj4Cc3gPaSn9A3+wFQ54BAyMXU=; b=yZOpksacQqpkZbBFdhLlH/RF5ZUJIAy5SzaTPjOlpeIerf62XY8gH/RITgOxIxS0I1 H58f9tCC1ErY7IiN8vKwbZ29C3bKBmKpM0NW0t++FixceEyn99oTs2489jlH6fpCeFcf u5TkmcFM7zr5TQyUfaCsMLZBIf+SJHnD8hnLAX2J+eyhrmoJnrWHoiKfGTpvtqlEBzdO WFCt0CINaG2bTO2UgNEI78vEN2kcMTtVU0/6iHEO5HLx4p4m8yujsgtZV25F3dfI/yq3 wGJJ241tmeZoFMf5yETQL5OcK6KpomSTlxJV05plErXBH7xWbauKD4feU9+LJ0WE6Tjx vIKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U4A9LEu4; 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 ey10-20020a0562140b6a00b005e5bbd9f522si10667171qvb.259.2023.04.12.04.44.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:27 -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=U4A9LEu4; 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 1pmYtc-0005cR-Na; Wed, 12 Apr 2023 07:44:16 -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 1pmYtD-0004v0-3V for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:51 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtB-0002Rd-0g for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:50 -0400 Received: by mail-wr1-x431.google.com with SMTP id v6so10561142wrv.8 for ; Wed, 12 Apr 2023 04:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299827; x=1683891827; 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=a4Zsigsmxtifc1mTfNj4Cc3gPaSn9A3+wFQ54BAyMXU=; b=U4A9LEu4gse6uImkH9lAKhvjWvKPgcFYdtbvkjFBqOpydp4ZzGnI/GufNqLCK53CvA zJPP1FIH36U63Liy1dzWhD1yEcEOoc1nzOzhMWyoON97TWmmE/guenzIv+n5nysIRiIh +VQPhTv0lF711vRdCbPCkNnzo3vf3LPOLhTNjW+ht+y/g9T3eRvnNrfUbH9Af2bKBgmi hDmmkg6otQl5s9FPPNBXQ7hX9Fqv/v5eo1x9PxCWhrZ/3K8WHg47sfuH6RrEs+Jomhx6 jv8tJDzW9YDtKEV26QebxKyz9yz7QmCw086D6pjsn8SrPsZsMksEA3P6B6ppTihPji1h tlEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299827; x=1683891827; 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=a4Zsigsmxtifc1mTfNj4Cc3gPaSn9A3+wFQ54BAyMXU=; b=6sVPR+C/5Q+ABx2dgLkcPBJxpI27O+fARccWQUZQfxtidEpvzYlWpRBr8r2fmSQ30+ xtxoKXqR0GWCOnEe9b80dpNVTMBw7bv21sIl0kU+5SVrXk9WkJg6JdMS3Y6lJwzR9438 jWgsg05jRotfMdrZV7YGYZCuk4LZsjX48lT7GR6veCgte6YGwlaoUsxe65Ug6yhIzmt7 TV7TLxFosM7rM1hatoOXTowJgEoU+a5N8OA0LMBGUW0tCAun/zTdzPgzTddaYrz9iKpu aiZUoxg3nYn3AfLqsy7irU08Yxuu6yrgHSZA4kIiMLnA4KvwwgMdHaY2pB6yUC3vQ4SY GO7Q== X-Gm-Message-State: AAQBX9eRVNrkPu6+uQL1PBmnURdwJcx6vNRsdhZoMoLM3euRYT6ho+rr oYauyszg/R+HH3BMm6GtnkJqVGJLKr5UlpAjezQqa10N X-Received: by 2002:adf:f1cc:0:b0:2f0:23bf:da7d with SMTP id z12-20020adff1cc000000b002f023bfda7dmr8837713wro.29.1681299827355; Wed, 12 Apr 2023 04:43:47 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 14/25] target/riscv: Introduce mmuidx_2stage Date: Wed, 12 Apr 2023 13:43:22 +0200 Message-Id: <20230412114333.118895-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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=unavailable 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 Move and rename riscv_cpu_two_stage_lookup, to match the other mmuidx_* functions. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-15-richard.henderson@linaro.org> --- target/riscv/cpu.h | 1 - target/riscv/internals.h | 5 +++++ target/riscv/cpu_helper.c | 20 ++++++-------------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 35cf2e2691..d1f888a790 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -581,7 +581,6 @@ target_ulong riscv_cpu_get_geilen(CPURISCVState *env); void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen); bool riscv_cpu_vector_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); -bool riscv_cpu_two_stage_lookup(int mmu_idx); int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch); G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 4aa1cb409f..b5f823c7ec 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -51,6 +51,11 @@ static inline bool mmuidx_sum(int mmu_idx) return (mmu_idx & 3) == MMUIdx_S_SUM; } +static inline bool mmuidx_2stage(int mmu_idx) +{ + return mmu_idx & MMU_2STAGE_BIT; +} + /* share data between vector helpers and decode code */ FIELD(VDATA, VM, 0, 1) FIELD(VDATA, LMUL, 1, 3) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 57bb19c76e..9dfd1d739b 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -591,11 +591,6 @@ void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable) } } -bool riscv_cpu_two_stage_lookup(int mmu_idx) -{ - return mmu_idx & MMU_2STAGE_BIT; -} - int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts) { CPURISCVState *env = &cpu->env; @@ -779,7 +774,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, * MPRV does not affect the virtual-machine load/store * instructions, HLV, HLVX, and HSV. */ - if (riscv_cpu_two_stage_lookup(mmu_idx)) { + if (mmuidx_2stage(mmu_idx)) { mode = get_field(env->hstatus, HSTATUS_SPVP); } @@ -1175,8 +1170,7 @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, } env->badaddr = addr; - env->two_stage_lookup = env->virt_enabled || - riscv_cpu_two_stage_lookup(mmu_idx); + env->two_stage_lookup = env->virt_enabled || mmuidx_2stage(mmu_idx); env->two_stage_indirect_lookup = false; cpu_loop_exit_restore(cs, retaddr); } @@ -1201,8 +1195,7 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, g_assert_not_reached(); } env->badaddr = addr; - env->two_stage_lookup = env->virt_enabled || - riscv_cpu_two_stage_lookup(mmu_idx); + env->two_stage_lookup = env->virt_enabled || mmuidx_2stage(mmu_idx); env->two_stage_indirect_lookup = false; cpu_loop_exit_restore(cs, retaddr); } @@ -1256,7 +1249,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, * MPRV does not affect the virtual-machine load/store * instructions, HLV, HLVX, and HSV. */ - if (riscv_cpu_two_stage_lookup(mmu_idx)) { + if (mmuidx_2stage(mmu_idx)) { mode = get_field(env->hstatus, HSTATUS_SPVP); } else if (mode == PRV_M && access_type != MMU_INST_FETCH && get_field(env->mstatus, MSTATUS_MPRV)) { @@ -1268,7 +1261,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, pmu_tlb_fill_incr_ctr(cpu, access_type); if (env->virt_enabled || - ((riscv_cpu_two_stage_lookup(mmu_idx) || two_stage_lookup) && + ((mmuidx_2stage(mmu_idx) || two_stage_lookup) && access_type != MMU_INST_FETCH)) { /* Two stage lookup */ ret = get_physical_address(env, &pa, &prot, address, @@ -1366,8 +1359,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, } else { raise_mmu_exception(env, address, access_type, pmp_violation, first_stage_error, - env->virt_enabled || - riscv_cpu_two_stage_lookup(mmu_idx), + env->virt_enabled || mmuidx_2stage(mmu_idx), two_stage_indirect_error); cpu_loop_exit_restore(cs, retaddr); } From patchwork Wed Apr 12 11:43:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672631 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp290595wrx; Wed, 12 Apr 2023 04:53:07 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/imJYxQDj5epxXAXxq7bYfITirj9x4CVchdHv3tKTxPukuTuXuk7xht4zLbHzYttl3Eam X-Received: by 2002:a05:622a:1a01:b0:3e3:9621:bd2f with SMTP id f1-20020a05622a1a0100b003e39621bd2fmr2794472qtb.53.1681300387375; Wed, 12 Apr 2023 04:53:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300387; cv=none; d=google.com; s=arc-20160816; b=JDeFNlAPTjA3owsbVMa8o4ffD898vyc/8GEF4UkzPXezFpLabCzynfM+wsuX002rDq iAsjVh5T7QyDd4ig9DirTtnuGoMgtpEHh+5VcYbFARDfSey0gXgrsn2p4ixlz29ZBrLt Ugnxhz3QSzsDg5PfhmxDiarzlHUtnq4A5MCgj5/i33yGlSav/7FfUa7rVbJuDYwhntdD edR6vtBH1Y4SCd95QtaVXshu33blzVQdQ21HwjwnJ4kq/y1UtRoYjx7b+3m3ts2ZDhZn Nve0Su3W1Ae817la90/q3VIb9y1VP/Wk6spZHvDU35ZwARSNS1gREUPlKcoG6XUlZ6Xi QSOQ== 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:cc:to :from:dkim-signature; bh=1b/kBvvVthJX/VbKnXsWeX6FiZxYMKF2JWi4jeCwEjI=; b=qyoVrLsTn2ZFbR3+o6BR2PlIE5yphiU7yOzQC2BrofJYY6AKrSse4B+msulv6eUhUH gi08X9u7hWmOYkJCwZJjBE77t1LK9v7WpgGQ0qlFnryjrOcpF60ZrpiV1jWjvo6v2jIJ PNYYd6o5JYdXAcPiYv/8TlGU3sokea+d3juqCZcqIEuOQbWMQx110mofYootK7uBidaP sdvE/H5HvqZRnH2zLC7fTKvBEPO/S3OlTGVFSNhnResSiBCIetInrx3Jq0GiTHnp+2QN Jc7Fg42wrlC17z+Pe37dzNdeui4g/5yyUdOAwQSfqDjGxEUSK32ws2crsl+LAbXECW3Z vfog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jfp6IJ9b; 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 q26-20020a05620a025a00b007487f4016easi10545433qkn.5.2023.04.12.04.53.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:53:07 -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=jfp6IJ9b; 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 1pmYtf-00060T-K6; Wed, 12 Apr 2023 07:44:19 -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 1pmYtD-0004vg-Ee for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:53 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtB-0002OA-4S for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:51 -0400 Received: by mail-wr1-x431.google.com with SMTP id j1so14578506wrb.0 for ; Wed, 12 Apr 2023 04:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299828; x=1683891828; 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=1b/kBvvVthJX/VbKnXsWeX6FiZxYMKF2JWi4jeCwEjI=; b=jfp6IJ9b6SfvDChBPWboAtWgpFxpKJNIvu7lhf0kVA7Eu8IQo2XlTqKRpz0rt/paXg 4w6PfgYIt946339LuxW6JFkQxE/OaKO2mhL+B8VSXySbn7HywzBJpf90AU7vxSXfnkTV h+hNIxtWLpTcDL5tZLvJZm8e5039skLZYRe1Q49lDVzEXgmapyE3dJh6IuCpU/bswRHr HJmr7Y7mi5rHCefuGETh0/fLqzwYFcvR0atM7FqWAZ8WPNAWKSjEorGFD1tI8jLsmh/d pFlizOwI5NWUBKjoF/hLYZLnoAB8LGxECo+fRmMOfs+ttNQguj1yignVOd0pawzOa3h4 jm1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299828; x=1683891828; 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=1b/kBvvVthJX/VbKnXsWeX6FiZxYMKF2JWi4jeCwEjI=; b=Z2+xApHnFaZdfMrfjrZN2ipWh4MlNOcJec8oLTaMW21/tZPKUb3OWoTPL0rWjJxh9I 4mlYI3Ex9o7W+ZR/hZ2wvgi4YOismWp3GiZl7term8f/45v9MNBnUUIuK7Ry+UMcCjI0 JOyrLVpmsVZFWOmt/2+HK3m0kBmBX2DX8OK3JdwOucBW7uPzsC4P+cfPlvPMLsKZP+hh 1TRSo8X3K3NFzZ0cyCqA+BkzZfOd19ascAFSC6/QX2s6N9SDA7Ig3rIyXj2SuISAXYWG JqM20klOOnkpNWJ25OW/QoYtZq4VH92jHBjgZG5xxFInZDiX3iUSp4/bp54/qHNSTalQ duAA== X-Gm-Message-State: AAQBX9fEUQCd9ZHF3w/pPoB4EqUZjC0iO0IdHSCLyyqCvf35bJW0uVuN Sr21feyk0uqPSfoUBQo9lWR7ygmxvMnHMpZNcSKae+NP X-Received: by 2002:a5d:540e:0:b0:2f0:27cc:1e7 with SMTP id g14-20020a5d540e000000b002f027cc01e7mr4409096wrv.9.1681299828407; Wed, 12 Apr 2023 04:43:48 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 15/25] target/riscv: Move hstatus.spvp check to check_access_hlsv Date: Wed, 12 Apr 2023 13:43:23 +0200 Message-Id: <20230412114333.118895-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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 The current cpu_mmu_index value is really irrelevant to the HLV/HSV lookup. Provide the correct priv level directly. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-16-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 10 +--------- target/riscv/op_helper.c | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 9dfd1d739b..ccba3c45e7 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -770,14 +770,6 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, use_background = true; } - /* - * MPRV does not affect the virtual-machine load/store - * instructions, HLV, HLVX, and HSV. - */ - if (mmuidx_2stage(mmu_idx)) { - mode = get_field(env->hstatus, HSTATUS_SPVP); - } - if (first_stage == false) { /* * We are in stage 2 translation, this is similar to stage 1. @@ -1250,7 +1242,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, * instructions, HLV, HLVX, and HSV. */ if (mmuidx_2stage(mmu_idx)) { - mode = get_field(env->hstatus, HSTATUS_SPVP); + ; } else if (mode == PRV_M && access_type != MMU_INST_FETCH && get_field(env->mstatus, MSTATUS_MPRV)) { mode = get_field(env->mstatus, MSTATUS_MPP); diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index a5de3daee7..49c19d971d 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -437,7 +437,7 @@ static int check_access_hlsv(CPURISCVState *env, bool x, uintptr_t ra) riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); } - return cpu_mmu_index(env, x) | MMU_2STAGE_BIT; + return get_field(env->hstatus, HSTATUS_SPVP) | MMU_2STAGE_BIT; } target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr) From patchwork Wed Apr 12 11:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672621 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288480wrx; Wed, 12 Apr 2023 04:47:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YVAchZPl6GoU+O8SPZcySuwHgmqVOPa7wLlm04HpOBjVf+aQ5lJtCDdpEyXM+JFK6DsEwp X-Received: by 2002:a05:622a:1a97:b0:3d5:ff70:88f2 with SMTP id s23-20020a05622a1a9700b003d5ff7088f2mr3211192qtc.17.1681300051231; Wed, 12 Apr 2023 04:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300051; cv=none; d=google.com; s=arc-20160816; b=Rz0u+SjEqnYcKs4fFkgSjeX9OG218YjvD6bgwrRC3jnSJbz46IQDJf/OCm8CMPx+yD MrgfQE2xSNgngK3Wzb2geyE017F4DULZlkjkcDI1Jh4hzOTfVb1+EN4F16k9XRDqKU6N UL7QSG+13B7bx9vxNnVN0zFLDBQFmX6P+bVLbzcq+tE8AabCLWtOVBAbgVy0BnQSWuci R7EvgLrGfWzzq5xiDrtzXewaW9rynjZHGJKthEdB1tJ4luyb4uCTaF+HfAunjlysEbzo t8wwaNndlyLZyz/ScGgMhrAQnzNb+dGVgN058Ksk6l+fPsz9nuC6TIzEmNPHTUTahvhm C9Mw== 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:cc:to :from:dkim-signature; bh=fc7ZqB0501n3cQfOjNTftlZU8unqltEwwtjDsL6xclU=; b=f8LrajOB6fG7PxfeimRM9tZ/g7L28pai8wX1E+X76dbxa9UN3TwgCgb7AqvSqBheCD fCxP6UK2EEkbOMJN6crO6Rbu3PsefLVNgIWDa5z8vk6/YEvR/394ZQo9Bh98IvHtevK9 OYAtryPl5yIYBN1Lgrd9R9cugyVDZpYQASXm29nVKV32J+RzhTCZ4mn+ErWtzRUi3KCr FV1dfP050oqxRMoWj6AU1xVCFSqmquNU7E6jwgfVOJFffegbSx2EENJ5xBqiP/38PJ+A x0u0WM82of80mHOvIIONQBPrr805yhjNm28NdZx1CqXtVB7GOKxuuYXCSLDk3uC6dNLO T6hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CnCsJy3y; 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 i14-20020ac85c0e000000b003e4e8bec38fsi9956344qti.394.2023.04.12.04.47.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:47:31 -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=CnCsJy3y; 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 1pmYti-0006Lz-2N; Wed, 12 Apr 2023 07:44:22 -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 1pmYtD-0004vj-U0 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:53 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtC-0002Or-3O for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:51 -0400 Received: by mail-wr1-x429.google.com with SMTP id e7so494153wrc.12 for ; Wed, 12 Apr 2023 04:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299829; x=1683891829; 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=fc7ZqB0501n3cQfOjNTftlZU8unqltEwwtjDsL6xclU=; b=CnCsJy3yNooYT9AkA2kepFNlR146UK7RsPYjW4Rz720wOJJQHAcHjpBfjtz/3IbP0y Bq5IE097CecxHpxRMiYhyJVHcIz2dzaMfhaCqFg+1XFQXqBD8D6F6OHjGjaNPvLQ7eEN 07WEHo5Wq3e0lrsbQm+A4ysa/17C+klJX2TD7qksLzpn0uM4ustSpSMJV6QwZbeklX4U 7mQhrHl42vugLPgh1YHMDedXSJ/t105dHT+qpnhsYwRGB+9vgPQ665tCQWNFiEGgsa9S UtEA5PznDPPFOmM3xUq8oyKEQQ+wJBJ6PnIjvt775k6r4DayWg1Z/gXLjt9jwFIMwETY Gwww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299829; x=1683891829; 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=fc7ZqB0501n3cQfOjNTftlZU8unqltEwwtjDsL6xclU=; b=SRTfyM3Gjh4Ixu5mjUmrbON/NPFfCKPqHn6ab79ebldAlEAH34BlQ8mg4v0P7mjg5I MgBfln7RdXfOa6b8cCE+Yj8oUWK5oBCqXr+MAGY4GItaO1siR1KCWtM6+e2fiWC5LKfF IlNtxTNIoimJ1RJdD+qAOUzl6nGhJ4IMy55dQZ1HWLVRUNAi6lrjfCD9wKHxTddDThPH Uj2CVp6M6jydvMdicM1d3jBa4a9H3W8n7kISC+AcH8U9rog8EU6Xfdy1eOr53Tqe0/D2 aMA0i871LOnSTkVR0ujL0clIYTVZDARzAefhhulq8MtzhJrJrLl2hkqH2kzYZWQHDG5l +iRA== X-Gm-Message-State: AAQBX9cH6uKcYi9eAGsrqYwVAL+F5ir4pXPyN2/rtekdInBgGszoLXJX GePnq8VXO/hLSyuticfwAZInoJEx6w8d7YBWQVpTzT17 X-Received: by 2002:a5d:50c1:0:b0:2ef:b5a0:35e8 with SMTP id f1-20020a5d50c1000000b002efb5a035e8mr10364496wrt.20.1681299829356; Wed, 12 Apr 2023 04:43:49 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 16/25] target/riscv: Set MMU_2STAGE_BIT in riscv_cpu_mmu_index Date: Wed, 12 Apr 2023 13:43:24 +0200 Message-Id: <20230412114333.118895-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x429.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 Incorporate the virt_enabled and MPV checks into the cpu_mmu_index function, so we don't have to keep doing it within tlb_fill and subroutines. This also elides a flush on changes to MPV. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-17-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 49 ++++++++++++++------------------------- target/riscv/csr.c | 6 +---- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index ccba3c45e7..baa4b3a1d2 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -37,19 +37,21 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) #ifdef CONFIG_USER_ONLY return 0; #else - if (ifetch) { - return env->priv; - } + bool virt = env->virt_enabled; + int mode = env->priv; /* All priv -> mmu_idx mapping are here */ - int mode = env->priv; - if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) { - mode = get_field(env->mstatus, MSTATUS_MPP); + if (!ifetch) { + if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) { + mode = get_field(env->mstatus, MSTATUS_MPP); + virt = get_field(env->mstatus, MSTATUS_MPV); + } + if (mode == PRV_S && get_field(env->mstatus, MSTATUS_SUM)) { + mode = MMUIdx_S_SUM; + } } - if (mode == PRV_S && get_field(env->mstatus, MSTATUS_SUM)) { - return MMUIdx_S_SUM; - } - return mode; + + return mode | (virt ? MMU_2STAGE_BIT : 0); #endif } @@ -1162,7 +1164,7 @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, } env->badaddr = addr; - env->two_stage_lookup = env->virt_enabled || mmuidx_2stage(mmu_idx); + env->two_stage_lookup = mmuidx_2stage(mmu_idx); env->two_stage_indirect_lookup = false; cpu_loop_exit_restore(cs, retaddr); } @@ -1187,7 +1189,7 @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, g_assert_not_reached(); } env->badaddr = addr; - env->two_stage_lookup = env->virt_enabled || mmuidx_2stage(mmu_idx); + env->two_stage_lookup = mmuidx_2stage(mmu_idx); env->two_stage_indirect_lookup = false; cpu_loop_exit_restore(cs, retaddr); } @@ -1225,7 +1227,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, int prot, prot2, prot_pmp; bool pmp_violation = false; bool first_stage_error = true; - bool two_stage_lookup = false; + bool two_stage_lookup = mmuidx_2stage(mmu_idx); bool two_stage_indirect_error = false; int ret = TRANSLATE_FAIL; int mode = mmu_idx; @@ -1237,24 +1239,8 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n", __func__, address, access_type, mmu_idx); - /* - * MPRV does not affect the virtual-machine load/store - * instructions, HLV, HLVX, and HSV. - */ - if (mmuidx_2stage(mmu_idx)) { - ; - } else if (mode == PRV_M && access_type != MMU_INST_FETCH && - get_field(env->mstatus, MSTATUS_MPRV)) { - mode = get_field(env->mstatus, MSTATUS_MPP); - if (riscv_has_ext(env, RVH) && get_field(env->mstatus, MSTATUS_MPV)) { - two_stage_lookup = true; - } - } - pmu_tlb_fill_incr_ctr(cpu, access_type); - if (env->virt_enabled || - ((mmuidx_2stage(mmu_idx) || two_stage_lookup) && - access_type != MMU_INST_FETCH)) { + if (two_stage_lookup) { /* Two stage lookup */ ret = get_physical_address(env, &pa, &prot, address, &env->guest_phys_fault_addr, access_type, @@ -1350,8 +1336,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, return false; } else { raise_mmu_exception(env, address, access_type, pmp_violation, - first_stage_error, - env->virt_enabled || mmuidx_2stage(mmu_idx), + first_stage_error, two_stage_lookup, two_stage_indirect_error); cpu_loop_exit_restore(cs, retaddr); } diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 124be448dc..211acad5ae 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1270,7 +1270,7 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, val = legalize_mpp(env, get_field(mstatus, MSTATUS_MPP), val); /* flush tlb on mstatus fields that affect VM */ - if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPV)) { + if ((val ^ mstatus) & MSTATUS_MXR) { tlb_flush(env_cpu(env)); } mask = MSTATUS_SIE | MSTATUS_SPIE | MSTATUS_MIE | MSTATUS_MPIE | @@ -1318,10 +1318,6 @@ static RISCVException write_mstatush(CPURISCVState *env, int csrno, uint64_t valh = (uint64_t)val << 32; uint64_t mask = MSTATUS_MPV | MSTATUS_GVA; - if ((valh ^ env->mstatus) & (MSTATUS_MPV)) { - tlb_flush(env_cpu(env)); - } - env->mstatus = (env->mstatus & ~mask) | (valh & mask); return RISCV_EXCP_NONE; From patchwork Wed Apr 12 11:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672625 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288855wrx; Wed, 12 Apr 2023 04:48:30 -0700 (PDT) X-Google-Smtp-Source: AKy350ZBMDeaGPQO41pAOpbJ24xOmzLW3rum0D7H+Gne0U89hKeYLhvNSUTJox+uvqTGCU3PvzFW X-Received: by 2002:a05:6214:d6f:b0:5a5:b269:bfd7 with SMTP id 15-20020a0562140d6f00b005a5b269bfd7mr3977549qvs.8.1681300109969; Wed, 12 Apr 2023 04:48:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300109; cv=none; d=google.com; s=arc-20160816; b=UncHu4XSX5tziH9tYmNfzOBmEZz5kvO+5ujaIMN5jnms7bTvuavT1MMeEwA9uyAzbv 46+Hq3sPyxYYPeHBhlWTiWU0kQYDoOoV4ENEzu9viZJmHI92df6imC4oThSo8h01jif2 SvvJRSET272vMH5PuZHOKXXIF3OKeWjfyW9x0L3+iizgEf0lA3Z+/l8whOyQLgbxq38v sfPTGivLhELuQNrdxhmB5E8W8ElUvAnrdRoI0ob+NRmRB0ISjZBbxyaP8rTqDDBFf6M/ ggLneSpsypyBBKfdjPgGsf2g309QE+EdZB/6Z2O2MlPeUc8WloKw6KZmqvECQ2+eQewe OVYA== 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:cc:to :from:dkim-signature; bh=PGKLd4EHm+dCotYmJKaBamFgwpM99B3AQVGNyZFQsdk=; b=Uq0m1vSiQUD6zniJjJLetTodcpsYgDgBfpDcqtQpL2yqWdCaE49/zflXgZy0j2fUdr AuUTogtSd8RFulznSpOyWc2sfo/b+KBWYA+egqhcyeJ5FD+J+YCiUB4Od70qXcMyQUtf 8XAx/y09XfLwyBVtVxUNlENd65szG22UGEibqJYs6odO4gyDxvN4+O4JmeTewv25Qi5r WN+KgYRbGaXlK18IpyvP9yQLBM+yYFSjobB+w+kGl6Yop1R/yuqISULdaA2pop/6w9Lx mqa2PgpAIyYlR/JKfkOSE8B2n+zRT18wi1Ggh0GIQOVcFbBVGK45EX/4qbppIGg5QIEk H93w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QTF9njU3; 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 jn8-20020ad45de8000000b005a477ecd028si4275941qvb.448.2023.04.12.04.48.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:48:29 -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=QTF9njU3; 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 1pmYti-0006R4-UQ; Wed, 12 Apr 2023 07:44:22 -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 1pmYtG-0004wz-Uz for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtF-0002T7-2h for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:54 -0400 Received: by mail-wm1-x333.google.com with SMTP id he11-20020a05600c540b00b003ef6d684102so4195836wmb.3 for ; Wed, 12 Apr 2023 04:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299830; x=1683891830; 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=PGKLd4EHm+dCotYmJKaBamFgwpM99B3AQVGNyZFQsdk=; b=QTF9njU393ydPl4QfHDvoJ8NgV5kD34YNrIFg9uMEPMwLND7vtcYS1ztBKBHoV8Rra yr18xSt41U3ZmIq5oWfRiC6kgvNmaxGveqmJ+JDJrrKNqoCN4vcBRUaCQ3PSVbO1p4l2 NLQBQeuPoJp01bzqcWfOlnJQqwM1bt43+Qk42yYYL4UkajtwzERtGKHZmERoLTHtoN5r ywdXXTVsdTteYGSaA9X7n6bsqpR9NoWBctkWth0t9kNIU5hN1YF99IwWL3RDgkWcGKwp u308NZDgO2Er+38tZPz6GxTLDovol7HMi04ZpM6WQM2CM/NSkQN5gY+h1UxsyCpnmRvA q0eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299830; x=1683891830; 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=PGKLd4EHm+dCotYmJKaBamFgwpM99B3AQVGNyZFQsdk=; b=wZukGK6tbiNJlUAfWefBPaIwszVQ7eNMCG/fcci64w2yajoeMaiypT5n8+PbR9ll+B QZUgZuYmJq9SvEuF1PmOHkPsIbRSY9ArfQqjSvYHccPt9ePIdFygef0OUHXQ6akSUP1W UFsaSfO8QqDWMSCxP68D1zA22Y15aZj7lvgTA2CjQF0zvRnEnp1x7y0dRuWO/1q4lD0S GhrEAKghpf+Zy2Vayn3pSNML1PHUSnSc2YlmGE+eYcaPiDz0MGrZCCQJh+dpNF4Lyk0x Ypw7yUDvPzIs+P/KYDMSkTpJBS/V8S93th9ttkT/HNqp8ujkNuWRkjlZ20cO5XeSX9IF CntQ== X-Gm-Message-State: AAQBX9eq+olE18ioks43rygDbmzQDHkd2FCLSW+YcFoaQ9nLT90vvRSO toMcUxeVVXSNCn0v4D4xOGqhM2PThqecv/NotmuwdLNZ X-Received: by 2002:a05:600c:ad2:b0:3f0:7ddf:d8e4 with SMTP id c18-20020a05600c0ad200b003f07ddfd8e4mr1602192wmr.17.1681299830573; Wed, 12 Apr 2023 04:43:50 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 17/25] target/riscv: Check SUM in the correct register Date: Wed, 12 Apr 2023 13:43:25 +0200 Message-Id: <20230412114333.118895-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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 Table 9.5 "Effect of MPRV..." specifies that MPV=1 uses VS-level vsstatus.SUM instead of HS-level sstatus.SUM. For HLV/HSV instructions, the HS-level register does not apply, but the VS-level register presumably does, though this is not mentioned explicitly in the manual. However, it matches the behavior for MPV. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-18-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 12 ++++++++---- target/riscv/op_helper.c | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index baa4b3a1d2..38bd83f66d 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -42,11 +42,16 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) /* All priv -> mmu_idx mapping are here */ if (!ifetch) { - if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) { + uint64_t status = env->mstatus; + + if (mode == PRV_M && get_field(status, MSTATUS_MPRV)) { mode = get_field(env->mstatus, MSTATUS_MPP); virt = get_field(env->mstatus, MSTATUS_MPV); + if (virt) { + status = env->vsstatus; + } } - if (mode == PRV_S && get_field(env->mstatus, MSTATUS_SUM)) { + if (mode == PRV_S && get_field(status, MSTATUS_SUM)) { mode = MMUIdx_S_SUM; } } @@ -826,8 +831,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, } widened = 2; } - /* status.SUM will be ignored if execute on background */ - sum = mmuidx_sum(mmu_idx) || use_background || is_debug; + sum = mmuidx_sum(mmu_idx) || is_debug; switch (vm) { case VM_1_10_SV32: levels = 2; ptidxbits = 10; ptesize = 4; break; diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c index 49c19d971d..66a9065a5d 100644 --- a/target/riscv/op_helper.c +++ b/target/riscv/op_helper.c @@ -437,7 +437,11 @@ static int check_access_hlsv(CPURISCVState *env, bool x, uintptr_t ra) riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, ra); } - return get_field(env->hstatus, HSTATUS_SPVP) | MMU_2STAGE_BIT; + int mode = get_field(env->hstatus, HSTATUS_SPVP); + if (!x && mode == PRV_S && get_field(env->vsstatus, MSTATUS_SUM)) { + mode = MMUIdx_S_SUM; + } + return mode | MMU_2STAGE_BIT; } target_ulong helper_hyp_hlv_bu(CPURISCVState *env, target_ulong addr) From patchwork Wed Apr 12 11:43:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672629 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp289660wrx; Wed, 12 Apr 2023 04:50:36 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/TyM/BKd/bDveujSqV9FzgWIzgxwbv7+9Ss80Io0zuajVwhOyK7hiHpXEaYqUu9LTONf4 X-Received: by 2002:a05:6214:29ec:b0:5e8:42d0:d74c with SMTP id jv12-20020a05621429ec00b005e842d0d74cmr21084252qvb.37.1681300236731; Wed, 12 Apr 2023 04:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300236; cv=none; d=google.com; s=arc-20160816; b=wBtVKQeNO8uEv26RsTjHm6mRNsXKirUDpqBrGM+mjTPFuZLKZgElb3Q/YauMVCGBDm nY9aPkNl+Yld9R4Zngc+xfN9nZZfdx/rljAEzUw9yEhcOc8pq4QcRxdKC6SYVTLz5C6r 432xAIzrvbmFbaBuEadQQM5YCOigcTzCBzkvnQuVPpfFBTcrMjLZ5emXm+o7SWZSU2EQ yd5K5d9/ukQpHTdmwq+ss6wF+Qe/88Wg3LJtQUgiBouPW11H4HARvyhTn0z9rz1Yq2/L KD9k4jvyQvV3tMroyDKlzjw03tDFkB3BPPZYE+EVck8z7QonGQFM0Z9JScvQdr/hVwK4 cJpQ== 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:cc:to :from:dkim-signature; bh=VRysGopMuvQKVUYQZTztZp4OETaqkIX63XPVMpwePPA=; b=Om4AIC02J3DjyTQiwQTT15k6kHiedh8R29Y1/yZLAgqS/4NaZyBMYzGp7QbrMIovow JJuTkk2rq8a2F2WeO38vMz2yCQbGCrLjSmlRkKkcPLphspGdjafBX8yfNxO+LfVmotQI oOi1CTdaCkisfpUgVqfjn+2+pnxQbF0LmL8Z2TkjcuKwjAi3jxnZw0s4jZ9JoVPPsaZa PcS5cLrMAWEFUKufzAnjvuXrx/B4p2aBJwtuG7CVsQ01mgZG9XsR5UCo3IUzMHGzaOMn 5qHDXP8xyweC8JdszLSs9/m7rykeH2tlX77PskqLLCrk3SKNtJqrw2Psk5JeEEC3ZubD RjZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QJ3F18qO; 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 t12-20020ac8588c000000b003e4ea3f6018si1418985qta.139.2023.04.12.04.50.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:50:36 -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=QJ3F18qO; 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 1pmYti-0006Nh-Ae; Wed, 12 Apr 2023 07:44:22 -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 1pmYtI-0004xE-70 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtF-0002TT-41 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:55 -0400 Received: by mail-wm1-x330.google.com with SMTP id m8so20047771wmq.5 for ; Wed, 12 Apr 2023 04:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299831; x=1683891831; 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=VRysGopMuvQKVUYQZTztZp4OETaqkIX63XPVMpwePPA=; b=QJ3F18qOPbwQNDoW+wchI3it8GRc+GussBXF1STfJmsi5SLrFqNbwQaYrs+ylqzIO7 Qjhm3SIpvEuKhxgjP8BMI9HDxx+7veVSXfVAbtotqsMD/cU9dBo59Wkor/6+Fncn2BfY sVJCX5SEHZ6ImZFisg47wFz5z8Cr5cConbTB47l5zbqoVTpXx5a3j20gNs2aIFKxUduP F6AzjFKIvFwNXjuVolFS3LeJCXW8aZJZuGlH4wMJQ+OOIsKb8sTUqinobAGVizt0s6uP uRGn/cIt899oNqIvDLBJFvwt67k63LpZ5nqXhWTx83EXyDc9YshEgI5FR/vM6dqLdkhh qUiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299831; x=1683891831; 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=VRysGopMuvQKVUYQZTztZp4OETaqkIX63XPVMpwePPA=; b=0LB4TwPDj2ACanb/Awd0QgsCRvaq/CVUYDIw6mMqvpl2NhmKCz+qxdvuJfnV5wgjkf kCgTqNpXj9PQ/sbH07EQE0lsaz8xa5sehB/cUjH6UapMVf4C1bz1Zkrb+X5Ng1bdW0QN ZTG+Ta3ZP8gW8ZDE055qhnYTKdS/kVqwUq+g4VBqxAHozsbUerbjmq/nOm9/U5sjx+6A R0zD10SzqmAQcL9JgotsKJYj3gUvvUbJIz6nBbARrV33lWxt2Ni5PyHOpZiqk14P+J2F +2s9X644Srmoe14YHisQMSQMcHtLsgpkkkZZep27cs0kPFlVZzZrUxzarEFOSUDfX4on d6Sw== X-Gm-Message-State: AAQBX9e9HdQuU1huUnhpcNmyGFUd35hoCpC3Zf+B7GBcOlC2sUaHLfEI hf7accqJqbfSmfhB0E4uhKQI69Jst58TRoxaQ+wBIOTc X-Received: by 2002:a1c:7917:0:b0:3f0:9f28:fb6c with SMTP id l23-20020a1c7917000000b003f09f28fb6cmr1061289wme.12.1681299831380; Wed, 12 Apr 2023 04:43:51 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 18/25] target/riscv: Hoist second stage mode change to callers Date: Wed, 12 Apr 2023 13:43:26 +0200 Message-Id: <20230412114333.118895-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x330.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 Move the check from the top of get_physical_address to the two callers, where passing mmu_idx makes no sense. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-19-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 38bd83f66d..5753e4e612 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -777,14 +777,6 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, use_background = true; } - if (first_stage == false) { - /* - * We are in stage 2 translation, this is similar to stage 1. - * Stage 2 is always taken as U-mode - */ - mode = PRV_U; - } - if (mode == PRV_M || !riscv_cpu_cfg(env)->mmu) { *physical = addr; *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; @@ -890,7 +882,7 @@ restart: /* Do the second stage translation on the base PTE address. */ int vbase_ret = get_physical_address(env, &vbase, &vbase_prot, base, NULL, MMU_DATA_LOAD, - mmu_idx, false, true, + MMUIdx_U, false, true, is_debug); if (vbase_ret != TRANSLATE_SUCCESS) { @@ -1271,7 +1263,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, im_address = pa; ret = get_physical_address(env, &pa, &prot2, im_address, NULL, - access_type, mmu_idx, false, true, + access_type, MMUIdx_U, false, true, false); qemu_log_mask(CPU_LOG_MMU, From patchwork Wed Apr 12 11:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672628 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp289658wrx; Wed, 12 Apr 2023 04:50:36 -0700 (PDT) X-Google-Smtp-Source: AKy350YXjD0UPBTGGQeA246rmDiKOMVkq4bn+UOGys7zwpMmcNnzlio2EMzatmdCQ/vGAA2SBii8 X-Received: by 2002:ac8:5cc5:0:b0:3e6:3661:7b29 with SMTP id s5-20020ac85cc5000000b003e636617b29mr24887676qta.21.1681300236459; Wed, 12 Apr 2023 04:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300236; cv=none; d=google.com; s=arc-20160816; b=DH4DGrAoOqtvaZsmlmCOMyTKmEK39RZ6fd2tTX7atbtHGDWn/vgVszdgA7TJH7i2xd AgezKcp8VXDjyfBe5jtmfCEAQpZ/MVi8XL99W+MPa4lBe+IYrwDEt1G26Z7bUBWlLpLU UAdRL2f5iY0N78OTKlQEl2R5mhO5XZrnJA6rStdDyN6UTJ4OY89dNi6eznqfAKKQ1Y3s J/psWfzkqkXMgEKDcdnlZ00EpCtmnfPnznQqnldYc/KMoiZlprshQFSIDaInkH+558Fz /KVEQBdkxAZ1hVq063ZWt3oxtI8OvcD6V5zzlbG6450EXcVrgB0BNPkhTqmacKGb9Sk8 4wJw== 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:cc:to :from:dkim-signature; bh=4dyXCtchSD+HKn11xxL6vJfEveqvcGr2NQzNKSenNrQ=; b=mg49nHWfZSaJHofy3DyhQINpAODnV9pG7lYFnqeMAPBrL42h48a0ujLDPL/TjG5hT9 2g6wGLLynty+EiunemvHAkFm6ZDdIz12oe0gbbzjtTz+K+E1hbFrqU0Qwibkt/nUtfIP Y0StBxfaVqbPIwblb2OI/zDH15Nq1Pxj00OfL/g9xl+4TLU2M/gOD1F4QYdIGSu1EFXM aURPNxhxzM9McSEdyGXucuKV2unO9qTnN7PCTAmNhGqUpJG2zE9Ja9H+OXFypYI2sEyI HR6gDoz8OA0KfC3s3peHqKNPyzX/QNeeD2r12onWojDEYGXujMLTvI3vBIYjvZUTJkYG L1hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BKIDOmBS; 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 k12-20020a05620a414c00b0074a44b9391dsi10991581qko.678.2023.04.12.04.50.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:50:36 -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=BKIDOmBS; 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 1pmYtf-0005xa-A0; Wed, 12 Apr 2023 07:44:19 -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 1pmYtG-0004wy-V6 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtF-0002Rd-3j for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:54 -0400 Received: by mail-wr1-x431.google.com with SMTP id v6so10561386wrv.8 for ; Wed, 12 Apr 2023 04:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299832; x=1683891832; 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=4dyXCtchSD+HKn11xxL6vJfEveqvcGr2NQzNKSenNrQ=; b=BKIDOmBSyPRnXY7Vdzj9fSl2kqvbzlnJEMpcXPAvRXqM8mjU6jcsGgHhKLfj7WaOen 19yCWM6+e9R6QpUNCH6gf+g7yOA/jHBywUDfReRRihufm53f11lU0+uqxfjEaLfbpCpo if1D869VpRXNqfm+vBPSjmdGtZb8uj4QCWjRNpBKlwmzn2UWFF9FWMMDWqscxpxAeXXp MYDSMl2508/6OMKFSes0NHL/1QcgQp9Yrm73FIHiBsncLssgJtSdJUrejYFqHybQyXC2 P4idbz5EH7vx7mSpct2onVk55GqflZuA+avYDu9b5vgBki9txWF5KcMV+ZaW6NzTSnUp ifDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299832; x=1683891832; 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=4dyXCtchSD+HKn11xxL6vJfEveqvcGr2NQzNKSenNrQ=; b=DVXda2iKIEMQs7vMhWRLU3vQs0CD6oboIl8vv0ZR8fmeQy+J+JK/44PTIpPf2NliEc M5aqlfJ9OXUVHE8yt0spWMYLCk1/DdyNve62dXIesSe6GlDorKTDC0eKQRiHwNWr4rcc LdvNx5OkhDIn4Ak9MLR0BHyvXZsNFhLGtaJyQTSufEAa+6+71RV5C570l1BYdAZNem0F v2ACG++tdm+PPer/XVP2HQ7wtuZ4splXtbWKtAP5R8zHdITvRkzDJb2teyRlgek3boaM 94KAaDdXXLGw13TqjVLy4vUpSM5t6nZM7d3Tdt/+DCuSMNx31RvGNMI6e94uCqDDJiKZ TlSQ== X-Gm-Message-State: AAQBX9dqWyOFMqEmIIO+wGRVoxJwBbIaDhnOOmh1nprRT1QGJeJZqw4V Ha7UA0/ARZI7a34tCxirtDvGj+eZseFC8AunkRteQa0A X-Received: by 2002:a05:6000:1003:b0:2f2:d852:c3f8 with SMTP id a3-20020a056000100300b002f2d852c3f8mr4209725wrx.39.1681299832312; Wed, 12 Apr 2023 04:43:52 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 19/25] target/riscv: Hoist pbmte and hade out of the level loop Date: Wed, 12 Apr 2023 13:43:27 +0200 Message-Id: <20230412114333.118895-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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 These values are constant for every level of pte lookup. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-20-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 5753e4e612..7c9f89d4d3 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -856,6 +856,14 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, return TRANSLATE_FAIL; } + bool pbmte = env->menvcfg & MENVCFG_PBMTE; + bool hade = env->menvcfg & MENVCFG_HADE; + + if (first_stage && two_stage && env->virt_enabled) { + pbmte = pbmte && (env->henvcfg & HENVCFG_PBMTE); + hade = hade && (env->henvcfg & HENVCFG_HADE); + } + int ptshift = (levels - 1) * ptidxbits; int i; @@ -916,14 +924,6 @@ restart: return TRANSLATE_FAIL; } - bool pbmte = env->menvcfg & MENVCFG_PBMTE; - bool hade = env->menvcfg & MENVCFG_HADE; - - if (first_stage && two_stage && env->virt_enabled) { - pbmte = pbmte && (env->henvcfg & HENVCFG_PBMTE); - hade = hade && (env->henvcfg & HENVCFG_HADE); - } - if (riscv_cpu_sxl(env) == MXL_RV32) { ppn = pte >> PTE_PPN_SHIFT; } else if (pbmte || riscv_cpu_cfg(env)->ext_svnapot) { From patchwork Wed Apr 12 11:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672618 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288192wrx; Wed, 12 Apr 2023 04:46:45 -0700 (PDT) X-Google-Smtp-Source: AKy350YvEFvP+bIPRDM1gYo9LFJHKMfxOINPrfAU2vTXb9p5j9fvbkzaR6UNv41S2ORUjFfcxvrV X-Received: by 2002:a05:6214:4018:b0:5ad:45f2:4307 with SMTP id kd24-20020a056214401800b005ad45f24307mr3225994qvb.11.1681300005564; Wed, 12 Apr 2023 04:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300005; cv=none; d=google.com; s=arc-20160816; b=WHcSi0sEcVZim5OUIQbH0f/zbroQyzQQzRJEkxVe8pTjAtf7ji+8Gn5O9dHPtrIClF YMz/9LBbP9Bs1PD3asbYY+9JFn/mapITDBUazx2GzWRj+o9cK+Xari47sH1EjUXpRfSs 1YGLlZ8E6sh3OAT/IW7UcinhoQKJOndOxtt5Grdf7orlIyuZpLRSm1w4K+bsu7Tiao+P 3IpO+uXaoh+BnS039DTAbl5TDNipHmVp+bI4xf9ULOexjigEjrfu0qpHVdljIV2mBfvz F1IF/d0KP+A1yhlwEOFGD/IxJXvPCzHKv45kFCZsVmVLiN/59+FFtrrPujlICFg96CoT xRYA== 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:cc:to :from:dkim-signature; bh=4wya4UWrfM6HlFM9BlBmRDPTvoeLhiO0tJTDNDDUjUY=; b=vvbVn7E1YZLGJDqWWryGvwx1CuSHvygNF1jwF93wNFcrauXtviS8JQNjWv6s3w07/h KhG+vUJnd7R4zXSFkX8sFgrW1R1uSXIzLhzp1XyJHaR95ZXWX6zoAvD82zutwqK6MlgE 3z2THJDPQGKVxNViwsLN2zee8KzEaEDZemq1cDhU4HGCtMi3aD0f+1LOU01EU0SV4o7V knuDovzzLdZ9jA24RBg846orLm1YM6K5eLLTJLMz/Du+hDsed99LkLTSv+EkoI2Xegp1 rHoK/v3f+mSUeBAjqMy+ercr4F5D0ufiVmVsjh8wem4YJtmlBVWDb+//DSQBMqEGphgX 9eKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iW8EY7N3; 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 bk29-20020a05620a1a1d00b00746864b273csi11102541qkb.627.2023.04.12.04.46.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:46:45 -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=iW8EY7N3; 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 1pmYth-0006Fv-5p; Wed, 12 Apr 2023 07:44:21 -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 1pmYtI-0004xZ-Py for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtG-0002UB-On for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:56 -0400 Received: by mail-wr1-x431.google.com with SMTP id v6so10561422wrv.8 for ; Wed, 12 Apr 2023 04:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299833; x=1683891833; 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=4wya4UWrfM6HlFM9BlBmRDPTvoeLhiO0tJTDNDDUjUY=; b=iW8EY7N3pHi4bOxiGnuzivpg4mm4O1zwdElQMn393nM1ciyctixacvZmaBO0XdTcz0 Ti4EG3ndAmPaQvOVOzM8ErLqm+7bsPef519uwcuXqRiWHfBdkcsW+M8/pfbOHfqYfUwj byZ9GUa9yt4ftR2KANRmnJWVrDObQpvOoLjns4qdZGsugll0yPCcKz/TvY6EoPUOL+RL LS+dxiVjqmWLxCpEQ6DbUwdd0aB6WuloZO8Nxd5f9V3Lh9obBArPHWlzcskKUn+ys4gG xbIq0KsgGOjgr/5znjgDfEydQEWliK4pFZCpZG+sE+lMt2d7mfhYIWivHM8bu0Jy4C/O sb9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299833; x=1683891833; 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=4wya4UWrfM6HlFM9BlBmRDPTvoeLhiO0tJTDNDDUjUY=; b=fCJnoaELFu9ujmWpD3YOeFhUgOT2geJJPsd8QHaXBnQnpbZMJFaZX/A26U7fkjWKFm N3LW5W9Y0P8S0zwVnyxBH/L3uPyCI5GX/KPzXrlkdUdt4WfUTu91j8OBZ/UX70ePKFRj n3wlhKXFSTf3STOviuf+ukfwa7Ln5Bkz+EQWbGTxWy9XYLVv9AwDJrZoWqomKNn0rRy8 VX0B/aSCmR9y1JaS/0b2O12OksRO4HOLnET1AyPvEWGFgHAatbX8fmsP11j4Gs9y8dFU ocLke9JpqYfvMmPLZOska9M6C0Gkb5fUtg5U9NwMxmiYjO14T0MiploG3XzT+g20nQzj 3Qng== X-Gm-Message-State: AAQBX9fxRquzTv6tI1ETD/6weXKSqJeX/ZtNFeerHIPW1o+W3HmYK81P CWmI5yCqVsxEUYmR3v84ssPNYkFXwaLj3PkaijTiRLFh X-Received: by 2002:adf:f20b:0:b0:2d1:e517:4992 with SMTP id p11-20020adff20b000000b002d1e5174992mr4008816wro.69.1681299833415; Wed, 12 Apr 2023 04:43:53 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 20/25] target/riscv: Move leaf pte processing out of level loop Date: Wed, 12 Apr 2023 13:43:28 +0200 Message-Id: <20230412114333.118895-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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=unavailable 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 Move the code that never loops outside of the loop. Unchain the if-return-else statements. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-21-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 238 ++++++++++++++++++++------------------ 1 file changed, 125 insertions(+), 113 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 7c9f89d4d3..c2d083f029 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -865,6 +865,8 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, } int ptshift = (levels - 1) * ptidxbits; + target_ulong pte; + hwaddr pte_addr; int i; #if !TCG_OVERSIZED_GUEST @@ -881,7 +883,6 @@ restart: } /* check that physical address of PTE is legal */ - hwaddr pte_addr; if (two_stage && first_stage) { int vbase_prot; @@ -913,7 +914,6 @@ restart: return TRANSLATE_PMP_FAIL; } - target_ulong pte; if (riscv_cpu_mxl(env) == MXL_RV32) { pte = address_space_ldl(cs->as, pte_addr, attrs, &res); } else { @@ -938,128 +938,140 @@ restart: if (!(pte & PTE_V)) { /* Invalid PTE */ return TRANSLATE_FAIL; - } else if (!pbmte && (pte & PTE_PBMT)) { + } + if (pte & (PTE_R | PTE_W | PTE_X)) { + goto leaf; + } + + /* Inner PTE, continue walking */ + if (pte & (PTE_D | PTE_A | PTE_U | PTE_ATTR)) { return TRANSLATE_FAIL; - } else if (!(pte & (PTE_R | PTE_W | PTE_X))) { - /* Inner PTE, continue walking */ - if (pte & (PTE_D | PTE_A | PTE_U | PTE_ATTR)) { - return TRANSLATE_FAIL; - } - base = ppn << PGSHIFT; - } else if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) { - /* Reserved leaf PTE flags: PTE_W */ - return TRANSLATE_FAIL; - } else if ((pte & (PTE_R | PTE_W | PTE_X)) == (PTE_W | PTE_X)) { - /* Reserved leaf PTE flags: PTE_W + PTE_X */ - return TRANSLATE_FAIL; - } else if ((pte & PTE_U) && ((mode != PRV_U) && - (!sum || access_type == MMU_INST_FETCH))) { - /* User PTE flags when not U mode and mstatus.SUM is not set, - or the access type is an instruction fetch */ - return TRANSLATE_FAIL; - } else if (!(pte & PTE_U) && (mode != PRV_S)) { - /* Supervisor PTE flags when not S mode */ - return TRANSLATE_FAIL; - } else if (ppn & ((1ULL << ptshift) - 1)) { - /* Misaligned PPN */ - return TRANSLATE_FAIL; - } else if (access_type == MMU_DATA_LOAD && !((pte & PTE_R) || - ((pte & PTE_X) && mxr))) { - /* Read access check failed */ - return TRANSLATE_FAIL; - } else if (access_type == MMU_DATA_STORE && !(pte & PTE_W)) { - /* Write access check failed */ - return TRANSLATE_FAIL; - } else if (access_type == MMU_INST_FETCH && !(pte & PTE_X)) { - /* Fetch access check failed */ - return TRANSLATE_FAIL; - } else { - /* if necessary, set accessed and dirty bits. */ - target_ulong updated_pte = pte | PTE_A | + } + base = ppn << PGSHIFT; + } + + /* No leaf pte at any translation level. */ + return TRANSLATE_FAIL; + + leaf: + if (ppn & ((1ULL << ptshift) - 1)) { + /* Misaligned PPN */ + return TRANSLATE_FAIL; + } + if (!pbmte && (pte & PTE_PBMT)) { + /* Reserved without Svpbmt. */ + return TRANSLATE_FAIL; + } + if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) { + /* Reserved leaf PTE flags: PTE_W */ + return TRANSLATE_FAIL; + } + if ((pte & (PTE_R | PTE_W | PTE_X)) == (PTE_W | PTE_X)) { + /* Reserved leaf PTE flags: PTE_W + PTE_X */ + return TRANSLATE_FAIL; + } + if ((pte & PTE_U) && + ((mode != PRV_U) && (!sum || access_type == MMU_INST_FETCH))) { + /* + * User PTE flags when not U mode and mstatus.SUM is not set, + * or the access type is an instruction fetch. + */ + return TRANSLATE_FAIL; + } + if (!(pte & PTE_U) && (mode != PRV_S)) { + /* Supervisor PTE flags when not S mode */ + return TRANSLATE_FAIL; + } + if (access_type == MMU_DATA_LOAD && + !((pte & PTE_R) || ((pte & PTE_X) && mxr))) { + /* Read access check failed */ + return TRANSLATE_FAIL; + } + if (access_type == MMU_DATA_STORE && !(pte & PTE_W)) { + /* Write access check failed */ + return TRANSLATE_FAIL; + } + if (access_type == MMU_INST_FETCH && !(pte & PTE_X)) { + /* Fetch access check failed */ + return TRANSLATE_FAIL; + } + + /* If necessary, set accessed and dirty bits. */ + target_ulong updated_pte = pte | PTE_A | (access_type == MMU_DATA_STORE ? PTE_D : 0); - /* Page table updates need to be atomic with MTTCG enabled */ - if (updated_pte != pte) { - if (!hade) { - return TRANSLATE_FAIL; - } + /* Page table updates need to be atomic with MTTCG enabled */ + if (updated_pte != pte) { + if (!hade) { + return TRANSLATE_FAIL; + } - /* - * - if accessed or dirty bits need updating, and the PTE is - * in RAM, then we do so atomically with a compare and swap. - * - if the PTE is in IO space or ROM, then it can't be updated - * and we return TRANSLATE_FAIL. - * - if the PTE changed by the time we went to update it, then - * it is no longer valid and we must re-walk the page table. - */ - MemoryRegion *mr; - hwaddr l = sizeof(target_ulong), addr1; - mr = address_space_translate(cs->as, pte_addr, &addr1, &l, - false, MEMTXATTRS_UNSPECIFIED); - if (memory_region_is_ram(mr)) { - target_ulong *pte_pa = - qemu_map_ram_ptr(mr->ram_block, addr1); + /* + * - if accessed or dirty bits need updating, and the PTE is + * in RAM, then we do so atomically with a compare and swap. + * - if the PTE is in IO space or ROM, then it can't be updated + * and we return TRANSLATE_FAIL. + * - if the PTE changed by the time we went to update it, then + * it is no longer valid and we must re-walk the page table. + */ + MemoryRegion *mr; + hwaddr l = sizeof(target_ulong), addr1; + mr = address_space_translate(cs->as, pte_addr, &addr1, &l, + false, MEMTXATTRS_UNSPECIFIED); + if (memory_region_is_ram(mr)) { + target_ulong *pte_pa = qemu_map_ram_ptr(mr->ram_block, addr1); #if TCG_OVERSIZED_GUEST - /* - * MTTCG is not enabled on oversized TCG guests so - * page table updates do not need to be atomic - */ - *pte_pa = pte = updated_pte; + /* + * MTTCG is not enabled on oversized TCG guests so + * page table updates do not need to be atomic + */ + *pte_pa = pte = updated_pte; #else - target_ulong old_pte = - qatomic_cmpxchg(pte_pa, pte, updated_pte); - if (old_pte != pte) { - goto restart; - } else { - pte = updated_pte; - } + target_ulong old_pte = qatomic_cmpxchg(pte_pa, pte, updated_pte); + if (old_pte != pte) { + goto restart; + } + pte = updated_pte; #endif - } else { - /* - * misconfigured PTE in ROM (AD bits are not preset) or - * PTE is in IO space and can't be updated atomically - */ - return TRANSLATE_FAIL; - } - } - + } else { /* - * for superpage mappings, make a fake leaf PTE for the TLB's - * benefit. + * Misconfigured PTE in ROM (AD bits are not preset) or + * PTE is in IO space and can't be updated atomically. */ - target_ulong vpn = addr >> PGSHIFT; - - if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { - napot_bits = ctzl(ppn) + 1; - if ((i != (levels - 1)) || (napot_bits != 4)) { - return TRANSLATE_FAIL; - } - } - - napot_mask = (1 << napot_bits) - 1; - *physical = (((ppn & ~napot_mask) | (vpn & napot_mask) | - (vpn & (((target_ulong)1 << ptshift) - 1)) - ) << PGSHIFT) | (addr & ~TARGET_PAGE_MASK); - - /* set permissions on the TLB entry */ - if ((pte & PTE_R) || ((pte & PTE_X) && mxr)) { - *prot |= PAGE_READ; - } - if (pte & PTE_X) { - *prot |= PAGE_EXEC; - } - /* - * add write permission on stores or if the page is already dirty, - * so that we TLB miss on later writes to update the dirty bit - */ - if ((pte & PTE_W) && - (access_type == MMU_DATA_STORE || (pte & PTE_D))) { - *prot |= PAGE_WRITE; - } - return TRANSLATE_SUCCESS; + return TRANSLATE_FAIL; } } - return TRANSLATE_FAIL; + + /* For superpage mappings, make a fake leaf PTE for the TLB's benefit. */ + target_ulong vpn = addr >> PGSHIFT; + + if (riscv_cpu_cfg(env)->ext_svnapot && (pte & PTE_N)) { + napot_bits = ctzl(ppn) + 1; + if ((i != (levels - 1)) || (napot_bits != 4)) { + return TRANSLATE_FAIL; + } + } + + napot_mask = (1 << napot_bits) - 1; + *physical = (((ppn & ~napot_mask) | (vpn & napot_mask) | + (vpn & (((target_ulong)1 << ptshift) - 1)) + ) << PGSHIFT) | (addr & ~TARGET_PAGE_MASK); + + /* set permissions on the TLB entry */ + if ((pte & PTE_R) || ((pte & PTE_X) && mxr)) { + *prot |= PAGE_READ; + } + if (pte & PTE_X) { + *prot |= PAGE_EXEC; + } + /* + * Add write permission on stores or if the page is already dirty, + * so that we TLB miss on later writes to update the dirty bit. + */ + if ((pte & PTE_W) && (access_type == MMU_DATA_STORE || (pte & PTE_D))) { + *prot |= PAGE_WRITE; + } + return TRANSLATE_SUCCESS; } static void raise_mmu_exception(CPURISCVState *env, target_ulong address, From patchwork Wed Apr 12 11:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672633 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp290647wrx; Wed, 12 Apr 2023 04:53:14 -0700 (PDT) X-Google-Smtp-Source: AKy350at8SGJmvFKcz4jcs3XIHC7YtSxAdmvr4g7mElqEP4g6f61/YfcU3ZRBOkU8DDD2ca1uasO X-Received: by 2002:a05:622a:1181:b0:3e8:b1da:7f14 with SMTP id m1-20020a05622a118100b003e8b1da7f14mr1452474qtk.19.1681300394304; Wed, 12 Apr 2023 04:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300394; cv=none; d=google.com; s=arc-20160816; b=EoWqdIQu3tyWWruGSxleRUhrAZrfFMkt/IcybTDbyZ2DW2nm4EIFKGiBSWcAg7/pkq A6kf+3F4ria7EnZu7BJhCWKyJdzk3T5AbBrgIrBgzzqHtQ0QqHIEDBMxRjJ9IubiNeRi W1QQ8I77GmTs2eCzLPmwOX3HrliXe7ggwJDC4/vk1NUB7IppbcYaa6f3i4+m6zhRWwdf HXQBktK1Pce83iSX1ulfogRC+sakepHPlc4q45rIam8ST5CYdNuqI6/wqyJqBqyaxB1U r6XDXAvJ507V52wt6e6wW7b5yxmzo8iuGurFbWLMNPFL5hH3CfmXtcOmwNsUztJlT5xE F3oA== 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:cc:to :from:dkim-signature; bh=YAXm4ASIFttpyWJKyvCjhM0MOstGOXoJQiE+ToyL5+M=; b=p6DNs5OEfGW0NWDssZCdYBp092cKdoqtskHiXfDmHz84qSUn+u9sDObrUs+0raKDSb 7L441qpu/hFQmbIkrprjAR2F1Xfg+O5K/X0p6HJvDz2OZV7Nt2FdPpkMM/UDorZ9sS47 WfNNeap5/5KxTeDpyZrBIlCLHqfQXNA9FU3GaJZMCfrs0qwlldMXD+9i7YQNmdb+1Mp5 A8XKEGFnRIxQiEdjS3TSfSVvMEZEJXreDnVaA76Q3I7hXV7wrY1uwXeUPEyTdKGmgdUx 00ucPbrar3OgmuGLVS3F114RCD6gW7czwM1E6Codiu1hq/73uvtUgKkHm+on03Jnh/D/ 4tuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JQEcA83I; 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 k16-20020a05622a03d000b003e6368b4ba6si10396090qtx.102.2023.04.12.04.53.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:53:14 -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=JQEcA83I; 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 1pmYtl-0006bV-0Q; Wed, 12 Apr 2023 07:44:25 -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 1pmYtJ-0004xb-9U for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtH-0002Nb-0g for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: by mail-wr1-x432.google.com with SMTP id i3so1257587wrc.4 for ; Wed, 12 Apr 2023 04:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299834; x=1683891834; 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=YAXm4ASIFttpyWJKyvCjhM0MOstGOXoJQiE+ToyL5+M=; b=JQEcA83IUV8RsbqU9Jt1Ab2eJb90z0Dew09aJl+CBYZxLWseO/BOfWLdsJRDAZIifJ Y2gqzORdm82xcIfN3QvNmWNnfhUNVnSqVq5FCDqDxZr4dm5sntl4uH7QlI4Cypo7OuIl ftNBdg4dm1/FRBRkETXEWeAf6X2gKfr0mMaoHBtPahd9zu34B34uuikcBDMwZHZ/z4Ad eyfbFcLurDAdOJba8aKW9XEoSPcUzoLy2I2x4Xwcz3kTZnxDPvt+U/Gb1AjyCzQHONEh QejIVWnUoF1/w14eUNAvcS/wv6nNtiM1VUq+bSyocHDPUDg8nsQuC7fB9RSCxkOcS7sE EHGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299834; x=1683891834; 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=YAXm4ASIFttpyWJKyvCjhM0MOstGOXoJQiE+ToyL5+M=; b=Cte3Jhwq+k11P+ZFDVzD/6PDkVIm5j0qtG+P5aa9iQqmCFhs7P90bfsBt96bwaSBjC XuMvzbo7agdIQjjUO5Gpx9CRxQnEzm+HbWn/bvC8EDtCNawwotFp0R4uhfBnuGImAB1u 3CLRKXuXOi5Jk18Vg2GgXAvB7rE4/kctpeZIsBTtL0aKjeBdnHYmFGnFMJ5TSidMJtaO z+1P7xOt2P0XrDdPQxvOWKYwSfAIP1GyFgsdxt/0dH+x/5OJDMLoPF2uStqGSgAESRDv O7p7n7fET2KQvYLwXhTy6W3staRr/d43nV2a//o/EeuG/iQD0ug7KTwHZNLYTIQWbnWm m6Mg== X-Gm-Message-State: AAQBX9d0dTmrTPFzNJ1twBrUBzTvP6B2krkgdlmaa9NPugIkD9j2R+PD eJGOKUfsFulONEWZ8G2RVSOtzacd9pDhvim5G8TPlxaK X-Received: by 2002:a5d:6dd0:0:b0:2cf:9889:8428 with SMTP id d16-20020a5d6dd0000000b002cf98898428mr4319572wrz.35.1681299834123; Wed, 12 Apr 2023 04:43:54 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 21/25] target/riscv: Suppress pte update with is_debug Date: Wed, 12 Apr 2023 13:43:29 +0200 Message-Id: <20230412114333.118895-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x432.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 The debugger should not modify PTE_A or PTE_D. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-22-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c2d083f029..6dc3fdf594 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1001,7 +1001,7 @@ restart: (access_type == MMU_DATA_STORE ? PTE_D : 0); /* Page table updates need to be atomic with MTTCG enabled */ - if (updated_pte != pte) { + if (updated_pte != pte && !is_debug) { if (!hade) { return TRANSLATE_FAIL; } From patchwork Wed Apr 12 11:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672612 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287389wrx; Wed, 12 Apr 2023 04:44:43 -0700 (PDT) X-Google-Smtp-Source: AKy350YEh5KO6RwuVIM8BDUCqKKD8C6t0vz+ADknYRR+P6CZx6x8ewQc2CYKsyRlYLLbU5yO3Ous X-Received: by 2002:a05:6214:23c8:b0:5e9:752:766b with SMTP id hr8-20020a05621423c800b005e90752766bmr25506971qvb.47.1681299883013; Wed, 12 Apr 2023 04:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299882; cv=none; d=google.com; s=arc-20160816; b=iA8/0yTUz2f1aeUoFULrP/pVXCE5/ezADp9arG5lvddp0+GPilUHvBGYXa7crEvWM8 JBeHKuCgn7FUxzI3ww8vgcw2Px0AfABBqWj4Qf9Z2CMJogFcpA5ITdUm3NjNwmi4X3iF Z8ZDaS8zDqGWAx7B/hRJdJsrRzRhPZ9oAbwpB3RPFSB5Ffe/bq36cOqcah6tZq1wGvI2 cDmpnQm7zdI3H/bQI+nxK8n8eROg3xXLYKur8dl8XVbLB655sENuhGqQC34Ef37nJv5g c/9XoWwdym2xyh4jCKjPwaMWpOHEStNooJpoY/OZ826rLl6JNnUiCGBzv4JQuw649Km5 T3gw== 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:cc:to :from:dkim-signature; bh=Zn52Ufb7DRbVaQ81Qm+6XQB/991khVVrBH6/wkfCyPw=; b=Zd9ojrR6WZJukFnSIxzSozqD8/QXZRreITQuk0RRthOpAfUP1EMfqJu4D0ho+/91KE onZWQ4PNG/quUkRhYH1LPQbAXdkDswuNW5FGM0GN+uwMrs+HmQyLRdq6zDAP2kZ1aZvI nQz6kiqWc99Nz0RvUbY5S4b3AqAevRVRQLcNN2RPpi3AAb5MpL27fjXRk4xAebXzGNSk WJ9PlMx8kE5UpRq3oOMoA789SRMoIwo8/mLZhh/dWX1fC3KrVHatgoHWeqrc7YCHOjs5 w/NUdAe/WszUWd8wZirlbkFqPEmPtT1mfvSed+74ix22bFZdXtQUO5IJTlq1s3+nABXl 3VWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tct9DIzA; 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 jo16-20020a056214501000b005ddc55f5c48si10703718qvb.171.2023.04.12.04.44.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:42 -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=tct9DIzA; 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 1pmYtk-0006aU-Rw; Wed, 12 Apr 2023 07:44:24 -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 1pmYtJ-0004z4-UD for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:59 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtI-0002NQ-Ai for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:57 -0400 Received: by mail-wr1-x430.google.com with SMTP id e7so494456wrc.12 for ; Wed, 12 Apr 2023 04:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299835; x=1683891835; 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=Zn52Ufb7DRbVaQ81Qm+6XQB/991khVVrBH6/wkfCyPw=; b=tct9DIzAzD/uENt4eA2Cqn0Fmd8KmINwv3jrPeu7YUoQLVUOVMPtzAs11P6KlHoEBq psbFabdJIBPWD8DQTUYlUO5bBp6p39SwcTmPc665VJgPvKHUuOW+CqMdp8GkU0XJ9oPj 7ul9MXh2162cSexD4qFLsIoMAFyFaVC4ZBRwsAz1P016MjhKtLo95qBEvRVU3AP3CaKX nDJFB10/mTbU4jfLUWHkqxm0ZIcYbCSBiVXXCFptlpFk2L9542vlDyh/zh6bnFMuTR1J P0A7IWrKn80LU++ix5yPdWrYQtInz+oRSBp+3hDDaFa8/fwnedql3nDOcE9P+A5Y7Ev9 z38w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299835; x=1683891835; 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=Zn52Ufb7DRbVaQ81Qm+6XQB/991khVVrBH6/wkfCyPw=; b=q7CKL8ehhIdCmhydA2w6AKL9fYmpFTf1feAKCCMMb4AMg4OXbNBDHOdUESbj/0LvNC 5YOrMI+1CGrsFFKiZDjm4NGwerASDW2PVmWGm+DKUk6xIiFpxwB9QDK+lCi6qvODDsga zN0T9naOk/MGajOlWGUuzAe6NthLGn9YvuzjRN4CYGB/YQp7tjl7xoZ6zaC9EcEm1/+G mAgv4MNwxXq90Gbv4ts0+Lz4wMjKrkJDL1x4//6c1feivt06ceiqLAGpiXoCy2nHFgok 3IlJO0L7iyZCQ2kdP19dC5FrRebk+IdYuI+1BrsCg5mvlkBI/LMKZb7YGa517q3ynZ/y 3HvQ== X-Gm-Message-State: AAQBX9cKOWZXwGl19s3OtpJZa6vsIdjq0HaxMWCP8dKn8JEho0cn/5bH XBhy9r7ryweJXRCDtfYlvU4++/PXw3kq3WIZEU+q+pJC X-Received: by 2002:a5d:4902:0:b0:2c7:d575:e8a4 with SMTP id x2-20020a5d4902000000b002c7d575e8a4mr9580924wrq.65.1681299835563; Wed, 12 Apr 2023 04:43:55 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 22/25] target/riscv: Don't modify SUM with is_debug Date: Wed, 12 Apr 2023 13:43:30 +0200 Message-Id: <20230412114333.118895-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x430.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 If we want to give the debugger a greater view of memory than the cpu, we should simply disable the access check entirely, not simply for this one corner case. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-23-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 6dc3fdf594..9a2b944990 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -823,7 +823,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, } widened = 2; } - sum = mmuidx_sum(mmu_idx) || is_debug; + sum = mmuidx_sum(mmu_idx); switch (vm) { case VM_1_10_SV32: levels = 2; ptidxbits = 10; ptesize = 4; break; From patchwork Wed Apr 12 11:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672620 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288267wrx; Wed, 12 Apr 2023 04:46:56 -0700 (PDT) X-Google-Smtp-Source: AKy350b5COM5boBEuCZ4QKdSLAMSf37NJ1YhOoXnaTApweV2MTYsrZK03NRYWlL0rQCfHtZKpdPw X-Received: by 2002:a05:6214:21a6:b0:5df:47e2:8df5 with SMTP id t6-20020a05621421a600b005df47e28df5mr26478674qvc.31.1681300016327; Wed, 12 Apr 2023 04:46:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300016; cv=none; d=google.com; s=arc-20160816; b=JvwGE+lQiuiB5wjW37Nj7yrzQKFeztRpiFgkiylCVksoKP4uC60I5mE9as+Dqy8X3U V/C5VrvBjNBTwYhCEVRS2bBMZWOb1vEi6BcnkqUjvfpy0+g7aruoP/oJNteccO03yZdm N/PFB74YSsCplKwm+Z30C+k/7IEGJqbEf/ZRMnLUBhd9HjEryCrJY3xHeNuhxkAw+peV UPPsEzTRjQrOygGTAMqljBDVM4s4wpg+EFFm1mlkm35Spbk7SZf9/wuKvF3un2tlBppl R50ogRwrbl5i+t5dIg2CqrufKshnvNwml8E2BjIe65R0URH0k4Sff1g5nlyVJfdVMWMy lSBw== 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:cc:to :from:dkim-signature; bh=ia5N2/U/AO+3qNL0VIGZiWVWDwXAJ3RRrVuamnKN6gs=; b=SG2dkV9EIzvBvR3vRQNx253Jsiz3jKUaL3k2Xf78BzVYCjIlNnZobixT2y5mDu/03/ dMvjISBnZm0Fslv54VYQ5rrFE2qzjE2pU1HG78TPWnKBRxGo91j7O7md37JQxMknATHi zcer2qQ9Zxwql9eLZyde1TXtAkIihRR/jq7pfanGhw3ZfFeNuEGB2b3QYWf45jDh/cvK IxzRRtaBqRt4yUJZbm7J3cBKvQDTDdnSk6TjT75g/48CoCH7q3ZffPeSjpwkS+0nMTf4 CVYY0PI9V2UF1vIVOS4tXo4pcSim18U7YPR11pMAj3Jt5pRtG3W/w0b9l8cGn3qBEWW6 6gUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XGws3Mzs; 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 r13-20020a056214212d00b005e764dd08easi9708590qvc.296.2023.04.12.04.46.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:46:56 -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=XGws3Mzs; 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 1pmYtj-0006W3-RW; Wed, 12 Apr 2023 07:44:23 -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 1pmYtK-0004zG-Ma for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:59 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtI-0002Rd-Ra for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:58 -0400 Received: by mail-wr1-x431.google.com with SMTP id v6so10561548wrv.8 for ; Wed, 12 Apr 2023 04:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299836; x=1683891836; 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=ia5N2/U/AO+3qNL0VIGZiWVWDwXAJ3RRrVuamnKN6gs=; b=XGws3MzszdtAXrTZpOBPFyrF/g1amQqNqyEbNRxDOwD7oWlsBcdQXtlhco9Smf5EN1 bgexxb79eii3srT78wW9PzidwBAw1lOsClDuJZ7iKOAyA0DoEjdVkqUN075p7SFEROad 10fpImO4APwZkyYjpvzdLq3uTCyK3xvI/YAjbWqKv76rPt2ga6AklUamSoGmSs6PO5D8 CcjwWnCuXkrSjZFZT/wt/bf2GgrpPW0LEqeu/mG7QU+TASaZGeyv35DkKXcBPhWNvDW7 OCltDL0t6a5tEpcv0Vlppj6g0VC5u9KNGjHBBKUdCYP39AM1KwlWtnzu++iNdfuxvUpa pASQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299836; x=1683891836; 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=ia5N2/U/AO+3qNL0VIGZiWVWDwXAJ3RRrVuamnKN6gs=; b=SThgzfW24WBeZBQiv2Q4KCol369Rs6bDVtnuZzR76pejFxjSd/dz5ZxEfsw9GDQ0Le UAaoemI3jVoQV3FKw2PK/SUVIPjC4RNfTaTDgyOrkiy4AFEQ75eP4lcY+iYPHQv49PPR +1RbZ80sgagSihAMZ6E2UsjY1ntMyeCuyrVSOC915Gf43F63qv767UsPm2XfiRl7pXQJ mgnoGhyAe983xaDgeMFftxr44CxRhgjsjVzZ606aMJA9JuO9AtcwWV6PKN3Lc0WerfEw CjQ/lpkypzF1J5Fo3AnrWK9Nd1mMf2hxuslsEQMOIuA7ympr5BN1rif1uQ+vtR0afrJ6 P1FA== X-Gm-Message-State: AAQBX9eNe8dbfYhHXWVBq8AoFpdr0oDl/vmQdQ82T8kX9Ixx8+OG1r5T OWc9UQCFkRLF4MbpEiOGPVnmiNoSsxXneQvPP064BXc+ X-Received: by 2002:adf:f545:0:b0:2f2:542a:6f50 with SMTP id j5-20020adff545000000b002f2542a6f50mr4488081wrp.56.1681299836216; Wed, 12 Apr 2023 04:43:56 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 23/25] target/riscv: Merge checks for reserved pte flags Date: Wed, 12 Apr 2023 13:43:31 +0200 Message-Id: <20230412114333.118895-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x431.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 Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-24-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 9a2b944990..c7c384bae3 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -962,14 +962,14 @@ restart: /* Reserved without Svpbmt. */ return TRANSLATE_FAIL; } - if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) { - /* Reserved leaf PTE flags: PTE_W */ - return TRANSLATE_FAIL; - } - if ((pte & (PTE_R | PTE_W | PTE_X)) == (PTE_W | PTE_X)) { - /* Reserved leaf PTE flags: PTE_W + PTE_X */ + + /* Check for reserved combinations of RWX flags. */ + switch (pte & (PTE_R | PTE_W | PTE_X)) { + case PTE_W: + case PTE_W | PTE_X: return TRANSLATE_FAIL; } + if ((pte & PTE_U) && ((mode != PRV_U) && (!sum || access_type == MMU_INST_FETCH))) { /* From patchwork Wed Apr 12 11:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672622 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp288486wrx; Wed, 12 Apr 2023 04:47:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bCTJCfjd+/4jyYORZG2pSG5Rgazvgtqw5GK9Upv1KOOcivq/ofRPQiSsuOiLEzQ2A9hDoa X-Received: by 2002:a05:6214:224a:b0:5c2:a8b0:d71a with SMTP id c10-20020a056214224a00b005c2a8b0d71amr24065392qvc.43.1681300051971; Wed, 12 Apr 2023 04:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681300051; cv=none; d=google.com; s=arc-20160816; b=nWd6PyY+piCpxhLgU+wHzCbW6KAUoXDacd+gVrbRHTwxZepR7MPjtHF+f/7FImo4kI QS+UweuL7HmW0D4GGqYqS2TudaGYPBgIKsRJmvSvI1+3HFMfaWYu2YVpws9DQ+UiZ2Px 7K9zmuRu7t9keGX24jONoJXZ1NLccpheIghulpTtmYZFfs1E1eytvH47F1YgfhVM7OSm WT9jiEpCkbZQnM8Xjxd371ydXfmoIwsCcRlz/2P0UXxjv2RIEAh6sSNxMmf6yWbrZRn3 zSUry9zFo6g5KlHw+Yk2dErE9hxhI4ARExp3HbgfRhSQGbZjmpXwPELsMNZj9fApSnxK ag5A== 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:cc:to :from:dkim-signature; bh=M8HoEQ5oqUBzgSiPkg41KaPcHxMWLCXEpmxQRlUQgmQ=; b=xJxzdHd+unqm5FDHyMQMUS8LZfdohNNmM2WGDwk2zVbkY3bevEmSWO34myk8H758vT Vvq7RWaxgTA5spOJ6+CFqtOxt44if+ZnJKMhhohWFtyCOTQ2b/a4fzq6LzE4kFIX+mRX 0LEQ1euAlmEp5aQNaezJv3iZgA6AEURt8xWo1/NXAVmt1ZWQnH2APfWuuVfbZyxuMbDf 16G5vhSK6xa/CqO2ez9g9v9V6nkUBPlJEcBkSteogA/2AvkcsU3ZAIo72VE6UZrHdFS+ dTwzrh6tnKxlwMWWqnA240t4Na6+vinMFhIiQ/jCTOLxBNQlOI9eRb9AbgAy0/PxR48H dDlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nJzOtn/+"; 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 i188-20020a37b8c5000000b00746bb25f27esi10241256qkf.104.2023.04.12.04.47.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:47:31 -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="nJzOtn/+"; 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 1pmYtm-0006mO-MT; Wed, 12 Apr 2023 07:44:26 -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 1pmYtM-000530-55 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:44:03 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtK-0002NF-9r for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:43:59 -0400 Received: by mail-wr1-x436.google.com with SMTP id s2so7310659wra.7 for ; Wed, 12 Apr 2023 04:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299837; x=1683891837; 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=M8HoEQ5oqUBzgSiPkg41KaPcHxMWLCXEpmxQRlUQgmQ=; b=nJzOtn/+ToFW+ybfxz8jOABM1E3vPQ8vyaeAoTbeRgrWMCEhinWPmUJNMK+tdZbeWZ Wq2WD8dWA/QCd1r/dsSZtbKlj8b4WBBZIdaHmm+Q0C1+Ud+nwzuzjj315NCyhoWOXAtl QUFi6Rs/Rt6pB56atBvvG76E9LWLbRSvz4tL6ZG9rJOf4hdWaIvoiNbM5MrDRmwAYsDj DUhygJWmP3MPUkOYyA0FgAHGw1g6OMH/QYrlYlzRzB2pScY7IpdSN/X2ZR0NWbs4AHXp rJhRx+4b00O118umgVvsMOWmY25p/CLB2CD7JuYOX/saT4o5O9T+ozvKN/9zDpAXyaDv WqCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299837; x=1683891837; 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=M8HoEQ5oqUBzgSiPkg41KaPcHxMWLCXEpmxQRlUQgmQ=; b=KQgORmg/S2ZxPvV2/QWYR8CvKIbnj92WVXrIQV4c4NVY5aObvIHu0VfCKB4EeKtH+1 3pE4eLmH2ezS9AlyVxY/Bi4js5ZYdsXSyWVTwbfoQY7/QFGCPsm8JkdWOaI88LqWEwS2 616/fMitHWhMxGnioM06IWZuM7RHbLaoXS2O5PAnxNI4MHmjbRz9WE2hKYsz8Q9K/pkU TQviAONKo5DLmm07CBlD685kgvwQrdJi+4fWNGMlPt5RZIRwRNphPxoo80WLFJpdSLFW 1WU8ucnCtgc9FfApYQld5vqH5/J0GHovzRbGV4Eco29MIpgxxc68uiKL20SsRhTpbMAW 67vw== X-Gm-Message-State: AAQBX9eq+Lda1Le0JAkkVtLWqHGeff95c1UN89RzpP+FDLczoLODUomP cb2xnBq8Fs/w4f24jC0aFuHKGljZV/Kx0ZKoaoQoQ29v X-Received: by 2002:adf:e441:0:b0:2e4:bfa0:8c30 with SMTP id t1-20020adfe441000000b002e4bfa08c30mr4769296wrm.47.1681299837424; Wed, 12 Apr 2023 04:43:57 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 24/25] target/riscv: Reorg access check in get_physical_address Date: Wed, 12 Apr 2023 13:43:32 +0200 Message-Id: <20230412114333.118895-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x436.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 We were effectively computing the protection bits twice, once while performing access checks and once while returning the valid bits to the caller. Reorg so we do this once. Move the computation of mxr close to its single use. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-25-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 69 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index c7c384bae3..7849e18554 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -747,7 +747,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot, * @is_debug: Is this access from a debugger or the monitor? */ static int get_physical_address(CPURISCVState *env, hwaddr *physical, - int *prot, vaddr addr, + int *ret_prot, vaddr addr, target_ulong *fault_pte_addr, int access_type, int mmu_idx, bool first_stage, bool two_stage, @@ -779,20 +779,14 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, if (mode == PRV_M || !riscv_cpu_cfg(env)->mmu) { *physical = addr; - *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; + *ret_prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TRANSLATE_SUCCESS; } - *prot = 0; + *ret_prot = 0; hwaddr base; - int levels, ptidxbits, ptesize, vm, sum, mxr, widened; - - if (first_stage == true) { - mxr = get_field(env->mstatus, MSTATUS_MXR); - } else { - mxr = get_field(env->vsstatus, MSTATUS_MXR); - } + int levels, ptidxbits, ptesize, vm, sum, widened; if (first_stage == true) { if (use_background) { @@ -835,7 +829,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, levels = 5; ptidxbits = 9; ptesize = 8; break; case VM_1_10_MBARE: *physical = addr; - *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; + *ret_prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TRANSLATE_SUCCESS; default: g_assert_not_reached(); @@ -970,6 +964,27 @@ restart: return TRANSLATE_FAIL; } + int prot = 0; + if (pte & PTE_R) { + prot |= PAGE_READ; + } + if (pte & PTE_W) { + prot |= PAGE_WRITE; + } + if (pte & PTE_X) { + bool mxr; + + if (first_stage == true) { + mxr = get_field(env->mstatus, MSTATUS_MXR); + } else { + mxr = get_field(env->vsstatus, MSTATUS_MXR); + } + if (mxr) { + prot |= PAGE_READ; + } + prot |= PAGE_EXEC; + } + if ((pte & PTE_U) && ((mode != PRV_U) && (!sum || access_type == MMU_INST_FETCH))) { /* @@ -982,17 +997,9 @@ restart: /* Supervisor PTE flags when not S mode */ return TRANSLATE_FAIL; } - if (access_type == MMU_DATA_LOAD && - !((pte & PTE_R) || ((pte & PTE_X) && mxr))) { - /* Read access check failed */ - return TRANSLATE_FAIL; - } - if (access_type == MMU_DATA_STORE && !(pte & PTE_W)) { - /* Write access check failed */ - return TRANSLATE_FAIL; - } - if (access_type == MMU_INST_FETCH && !(pte & PTE_X)) { - /* Fetch access check failed */ + + if (!((prot >> access_type) & 1)) { + /* Access check failed */ return TRANSLATE_FAIL; } @@ -1057,20 +1064,16 @@ restart: (vpn & (((target_ulong)1 << ptshift) - 1)) ) << PGSHIFT) | (addr & ~TARGET_PAGE_MASK); - /* set permissions on the TLB entry */ - if ((pte & PTE_R) || ((pte & PTE_X) && mxr)) { - *prot |= PAGE_READ; - } - if (pte & PTE_X) { - *prot |= PAGE_EXEC; - } /* - * Add write permission on stores or if the page is already dirty, - * so that we TLB miss on later writes to update the dirty bit. + * Remove write permission unless this is a store, or the page is + * already dirty, so that we TLB miss on later writes to update + * the dirty bit. */ - if ((pte & PTE_W) && (access_type == MMU_DATA_STORE || (pte & PTE_D))) { - *prot |= PAGE_WRITE; + if (access_type != MMU_DATA_STORE && !(pte & PTE_D)) { + prot &= ~PAGE_WRITE; } + *ret_prot = prot; + return TRANSLATE_SUCCESS; } From patchwork Wed Apr 12 11:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672613 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp287423wrx; Wed, 12 Apr 2023 04:44:48 -0700 (PDT) X-Google-Smtp-Source: AKy350ZL0L1uZG+ZxKvlbpmy6yaIGU7nSxROYT3/6Rmq5YJdH1BF10ai1pPlODtSnXSaK0loqLZA X-Received: by 2002:a05:622a:51:b0:3e6:9e18:73ee with SMTP id y17-20020a05622a005100b003e69e1873eemr19279439qtw.15.1681299888328; Wed, 12 Apr 2023 04:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681299888; cv=none; d=google.com; s=arc-20160816; b=OpZ0TgfFFvKC2ubKaMFz+ouMfndCL6e4kWCt3zYNC+KrlbImtU2od9pmk6GpIA3XRs ZoSa2ZHFP6iV0fqu4oPF2EN+89w3UlKFbh1Xy0isTO8KzM89eMTTNwvaDW+9lyVmQ82q HHr7qqUDV4A0NNOW6tM2hloin/OMD9lQgnlb9/Jcl1LqTEBKUEbPEc3/u2R31N4aCvww UpVLi6eXiVxD2AP0iTcc7A4Jo5SoN+O4JHX2gk81CV6gpYdnV9UQd/TUFfQmcQT4ztjW 3NRQ7RPs/9JtuCgqDYSUoa9dIkTvgSQ18+9arDiDSUl/R8SiQCnbfit/9yF7BBMbqTII 585g== 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:cc:to :from:dkim-signature; bh=NoQh8yWVm3hAFzwy/qPB+auaAmUwei9hlZGr86CydxQ=; b=BC8HY+6ciHhcNqV8V8OyfF6K6WXdM4NftSP19bf+JjIlzz8J7DhVi9mdMZJioO4Na3 lydTzNs/jdkFkyqX5q+S7V/4UiBz3vaR4jdnNjPxuE2c2o/4dRYFNWXMjDlprnnWpM0j VSDX0iUmV6glFrQuRojX1WESO/HkK342c/Qk58wZN+lL10Oihzuv4gMWf1GE/JtiHyjQ OGD0q2M1thl0vukWrUFqtuNJRSulO1ISHGcJJ8vg3HY0pbhofQN2T5P+lB2GIxUX6nYI s7ZxQqU6oxBOborYAlfhqJwUx5C3E5fwYEp1M1v0vvVQCGiWuDcMze6pRSrDrxAteBUj Gj8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kt3E4SgZ; 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 10-20020a05620a048a00b00748490a3731si10326209qkr.38.2023.04.12.04.44.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Apr 2023 04:44:48 -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=kt3E4SgZ; 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 1pmYto-0006xj-8H; Wed, 12 Apr 2023 07:44:28 -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 1pmYtO-00056K-AC for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:44:03 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmYtL-0002PS-40 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 07:44:00 -0400 Received: by mail-wr1-x42b.google.com with SMTP id g5so13963917wrb.5 for ; Wed, 12 Apr 2023 04:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681299838; x=1683891838; 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=NoQh8yWVm3hAFzwy/qPB+auaAmUwei9hlZGr86CydxQ=; b=kt3E4SgZNmIZI+gaYwAzRQ8G1J/IB70YWIOS6Xe7xnUxDG8lkGx6VhPkGFaptJG5E/ YMme7EOKqeHOcWMJcKUT5hKe+aV/G/D+jKiDd3d+T+Su9jAIMjej7Cv8PC8umikoDGPz 36E+Pcjnmf9dvuwJ8ulyJSvzDcEs/8H+BiDEeP0gZjtzb6+iVVwnzS7xUwcFpdIVBTR9 lUA80wGv0sotcNnp05C3mgHI9Ec90WVUNi2jkbwsXNhXq1btYsjpqr80CDKkFOFK1haU C5pNjswMDesfg/FvNOced0WwXcjsFiQiyxtzCmVdC1JOHQ/CBj/DfRcY2hIL9k8MPf0j UVfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681299838; x=1683891838; 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=NoQh8yWVm3hAFzwy/qPB+auaAmUwei9hlZGr86CydxQ=; b=jVzC4oLT0j9LIpbZCa5a5e+HDiakXpBUxP1PzuedFWPIRn5/utcVdayrJ2+CetppZN S8H6bPZqCs022gT9kxDXFR3oh28j20WvG7+lISYS6ivsqRxcsNi9rLpuZDISN2VrG1FL 7VUoOjXXn3d+Xynq/4SoTdSP0HvzIZGBmu2RPJrKozVy8XcNA/VlYDgfMd1AK1FHe1DH 2p47536lDDb4oGjie5Rb0C2Fibzk/9ulrKaToYMkdSR/ZwWa1HLwP6gIRt6b09W9UaOx Mqg1b7JpWY8c30ga82h1ROxPZljZ/HdHUfFslybsKYP4UnqM9Z1iejZinbj23B/5QlMp hSjg== X-Gm-Message-State: AAQBX9d+kDlexAlsXS8hLKdhugegVHMTYkl9Dhp3FELAZxH06+tDvuml 52t+Rtl7CpOfd5Wwp1KX7+/OPACARY870SPmqsSqRw1p X-Received: by 2002:a5d:4846:0:b0:2ef:ba74:663 with SMTP id n6-20020a5d4846000000b002efba740663mr10594545wrs.27.1681299838379; Wed, 12 Apr 2023 04:43:58 -0700 (PDT) Received: from stoup.hotel.gast (ip-037-024-010-236.um08.pools.vodafone-ip.de. [37.24.10.236]) by smtp.gmail.com with ESMTPSA id k9-20020a5d4289000000b002d21379bcabsm16980826wrq.110.2023.04.12.04.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 04:43:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, qemu-riscv@nongnu.org, Alistair Francis , Weiwei Li , Daniel Henrique Barboza Subject: [PATCH v7 25/25] target/riscv: Reorg sum check in get_physical_address Date: Wed, 12 Apr 2023 13:43:33 +0200 Message-Id: <20230412114333.118895-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230412114333.118895-1-richard.henderson@linaro.org> References: <20230412114333.118895-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 Implement this by adjusting prot, which reduces the set of checks required. This prevents exec to be set for U pages in MMUIdx_S_SUM. While it had been technically incorrect, it did not manifest as a bug, because we will never attempt to execute from MMUIdx_S_SUM. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Weiwei Li Tested-by: Daniel Henrique Barboza Message-Id: <20230325105429.1142530-26-richard.henderson@linaro.org> --- target/riscv/cpu_helper.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 7849e18554..32a65f8007 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -786,7 +786,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, *ret_prot = 0; hwaddr base; - int levels, ptidxbits, ptesize, vm, sum, widened; + int levels, ptidxbits, ptesize, vm, widened; if (first_stage == true) { if (use_background) { @@ -817,7 +817,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, } widened = 2; } - sum = mmuidx_sum(mmu_idx); + switch (vm) { case VM_1_10_SV32: levels = 2; ptidxbits = 10; ptesize = 4; break; @@ -985,15 +985,15 @@ restart: prot |= PAGE_EXEC; } - if ((pte & PTE_U) && - ((mode != PRV_U) && (!sum || access_type == MMU_INST_FETCH))) { - /* - * User PTE flags when not U mode and mstatus.SUM is not set, - * or the access type is an instruction fetch. - */ - return TRANSLATE_FAIL; - } - if (!(pte & PTE_U) && (mode != PRV_S)) { + if (pte & PTE_U) { + if (mode != PRV_U) { + if (!mmuidx_sum(mmu_idx)) { + return TRANSLATE_FAIL; + } + /* SUM allows only read+write, not execute. */ + prot &= PAGE_READ | PAGE_WRITE; + } + } else if (mode != PRV_S) { /* Supervisor PTE flags when not S mode */ return TRANSLATE_FAIL; }