From nobody Tue Feb 10 23:54:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1660880484; cv=none; d=zohomail.com; s=zohoarc; b=nq3xFOGafj5dD1bJz9jniumYv6lkoWfCL1dpg54M+HB5sH2dL6g/vPqeO4gkTIK9T6ldv176vUTxL6/2T1q2Cs0PXqUiVTH3U3hegoTqoWQQ7VEOFCWGd9Zqoo+f8ImQVPlrH8G/4+n2tc5lhO/Axm5s7PUczy43f9A7uBczqAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660880484; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eG1O+v8L8NJE9bJ3ZvxBbx6/WL3iXYhAToDfN+kCmp0=; b=HJQ/tuQ78SMCNY09HDzUfN3iDhtGbJ7Uvi4Cwq0kOoyASm3JKJzwwCkkQ7qa98W1lMo8q+LqURoANVMtIklqqqd6hpkWB1sfXJgnSL4KXR5G9EqX0p09kDbVb6nKgggA8ior3rQWrqxassK4NHJ6SmvRuQfBretHaEo/06jvyUw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660880484186532.0298770775564; Thu, 18 Aug 2022 20:41:24 -0700 (PDT) Received: from localhost ([::1]:34460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOsst-0002Sw-0x for importer@patchew.org; Thu, 18 Aug 2022 23:41:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOseh-0002Ok-ID for qemu-devel@nongnu.org; Thu, 18 Aug 2022 23:26:43 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:39505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oOsef-0002k1-LV for qemu-devel@nongnu.org; Thu, 18 Aug 2022 23:26:43 -0400 Received: by mail-pg1-x52c.google.com with SMTP id q9so1839329pgq.6 for ; Thu, 18 Aug 2022 20:26:41 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:bbf3:9914:aa9c:3b4e]) by smtp.gmail.com with ESMTPSA id g184-20020a6252c1000000b00535d19c46d7sm2199904pfb.203.2022.08.18.20.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 20:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=eG1O+v8L8NJE9bJ3ZvxBbx6/WL3iXYhAToDfN+kCmp0=; b=vjHtIMwWNM8NKeTeKYqzlRL4PjUznKYu5wOaYlqIjR14ztgWVDOWLdABJ4S4DcVM63 Y/6g+Q8/qt16YJlZYwfMgyeuP8/KnjvHjhPGu0SYz/foRv+c/vJTt4d5WSSfTl/NxKYY Nk2q5oqaE0H8AL8sKwgSHA07dJ1V3WTG9pGE6ToVPAD8enR1Ii1f2Ls9j0mFj7I8Ynkj jqyzVHyhhuA+UwHyPz29wtPlwPQpaVSf+9hHRcXcoEH3Hy43mmvzY2va8iDdTrdiXfGm G0JpZfYTIHblmtinJaAX71GJWkUZ8ilOd3tPOldXzm5scpk/Wjg3nSrjo1UTPl0uD4ma FmYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=eG1O+v8L8NJE9bJ3ZvxBbx6/WL3iXYhAToDfN+kCmp0=; b=Nv2lXlqU55X1No2H17ueHHSAHeM2GBBmvAWy48K4kgahHY5LXrxwdfZSvkom7mXNUp 33e+KQ4KCsdeZFsPwV2LP+qUKamaxP7Hk4Gqe0tq7kXNbedmk3UC1JD/nBV7pZWVmxoc Wj+y9ZmAOSPHTBfRcawJ9TSJcIa9kmnZIlPxe5mU/fZc/rS6PK6TUHMc/LtX8mABO2WZ KxLDZ7qhZEOLrfDgGrfbLbFvfls83RorZGu9gq0VXbQuAXTMt/l32nkAzH/ZXd9/PT+h NIQ2rJ/4Itul9m9QXNOY4zHXMYwBeiX5fQxBCNYOcNyGvPsMMiTvUEoqZSCh1dCj/ELH 23mg== X-Gm-Message-State: ACgBeo3Y95xSdYEU56BRqfONOmAGBtQWbXDwJyWsan4wzeeB7NaKf7Q5 gjSXODClwjUrNeN/IUg0TINrQTj8rp3rEg== X-Google-Smtp-Source: AA6agR68NsfRFpb5xS0BHOO1HY6Uwqlcrg3tVT4COnmDNzLI/a7N9cOQWe/wCdDYUt/h1xTO2kSxMw== X-Received: by 2002:a05:6a00:2392:b0:52e:b4fb:848 with SMTP id f18-20020a056a00239200b0052eb4fb0848mr5954277pfc.8.1660879600910; Thu, 18 Aug 2022 20:26:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, iii@linux.ibm.com, dramforever@live.com, alistair.francis@wdc.com, alex.bennee@linaro.org Subject: [PATCH v6 21/21] target/riscv: Make translator stop before the end of a page Date: Thu, 18 Aug 2022 20:26:15 -0700 Message-Id: <20220819032615.884847-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819032615.884847-1-richard.henderson@linaro.org> References: <20220819032615.884847-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1660880484640100001 Content-Type: text/plain; charset="utf-8" Right now the translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1155 Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- target/riscv/translate.c | 17 +++++-- tests/tcg/riscv64/noexec.c | 79 +++++++++++++++++++++++++++++++ tests/tcg/riscv64/Makefile.target | 1 + 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/riscv64/noexec.c diff --git a/target/riscv/translate.c b/target/riscv/translate.c index a719aa6e63..f8af6daa70 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1154,12 +1154,21 @@ static void riscv_tr_translate_insn(DisasContextBas= e *dcbase, CPUState *cpu) } ctx->nftemp =3D 0; =20 + /* Only the first insn within a TB is allowed to cross a page boundary= . */ if (ctx->base.is_jmp =3D=3D DISAS_NEXT) { - target_ulong page_start; - - page_start =3D ctx->base.pc_first & TARGET_PAGE_MASK; - if (ctx->base.pc_next - page_start >=3D TARGET_PAGE_SIZE) { + if (!is_same_page(&ctx->base, ctx->base.pc_next)) { ctx->base.is_jmp =3D DISAS_TOO_MANY; + } else { + unsigned page_ofs =3D ctx->base.pc_next & ~TARGET_PAGE_MASK; + + if (page_ofs > TARGET_PAGE_SIZE - MAX_INSN_LEN) { + uint16_t next_insn =3D cpu_lduw_code(env, ctx->base.pc_nex= t); + int len =3D insn_len(next_insn); + + if (!is_same_page(&ctx->base, ctx->base.pc_next + len)) { + ctx->base.is_jmp =3D DISAS_TOO_MANY; + } + } } } } diff --git a/tests/tcg/riscv64/noexec.c b/tests/tcg/riscv64/noexec.c new file mode 100644 index 0000000000..86f64b28db --- /dev/null +++ b/tests/tcg/riscv64/noexec.c @@ -0,0 +1,79 @@ +#include "../multiarch/noexec.c.inc" + +static void *arch_mcontext_pc(const mcontext_t *ctx) +{ + return (void *)ctx->__gregs[REG_PC]; +} + +static int arch_mcontext_arg(const mcontext_t *ctx) +{ + return ctx->__gregs[REG_A0]; +} + +static void arch_flush(void *p, int len) +{ + __builtin___clear_cache(p, p + len); +} + +extern char noexec_1[]; +extern char noexec_2[]; +extern char noexec_end[]; + +asm(".option push\n" + ".option norvc\n" + "noexec_1:\n" + " li a0,1\n" /* a0 is 0 on entry, set 1. */ + "noexec_2:\n" + " li a0,2\n" /* a0 is 0/1; set 2. */ + " ret\n" + "noexec_end:\n" + ".option pop"); + +int main(void) +{ + struct noexec_test noexec_tests[] =3D { + { + .name =3D "fallthrough", + .test_code =3D noexec_1, + .test_len =3D noexec_end - noexec_1, + .page_ofs =3D noexec_1 - noexec_2, + .entry_ofs =3D noexec_1 - noexec_2, + .expected_si_ofs =3D 0, + .expected_pc_ofs =3D 0, + .expected_arg =3D 1, + }, + { + .name =3D "jump", + .test_code =3D noexec_1, + .test_len =3D noexec_end - noexec_1, + .page_ofs =3D noexec_1 - noexec_2, + .entry_ofs =3D 0, + .expected_si_ofs =3D 0, + .expected_pc_ofs =3D 0, + .expected_arg =3D 0, + }, + { + .name =3D "fallthrough [cross]", + .test_code =3D noexec_1, + .test_len =3D noexec_end - noexec_1, + .page_ofs =3D noexec_1 - noexec_2 - 2, + .entry_ofs =3D noexec_1 - noexec_2 - 2, + .expected_si_ofs =3D 0, + .expected_pc_ofs =3D -2, + .expected_arg =3D 1, + }, + { + .name =3D "jump [cross]", + .test_code =3D noexec_1, + .test_len =3D noexec_end - noexec_1, + .page_ofs =3D noexec_1 - noexec_2 - 2, + .entry_ofs =3D -2, + .expected_si_ofs =3D 0, + .expected_pc_ofs =3D -2, + .expected_arg =3D 0, + }, + }; + + return test_noexec(noexec_tests, + sizeof(noexec_tests) / sizeof(noexec_tests[0])); +} diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile= .target index d41bf6d60d..b5b89dfb0e 100644 --- a/tests/tcg/riscv64/Makefile.target +++ b/tests/tcg/riscv64/Makefile.target @@ -3,3 +3,4 @@ =20 VPATH +=3D $(SRC_PATH)/tests/tcg/riscv64 TESTS +=3D test-div +TESTS +=3D noexec --=20 2.34.1