From patchwork Thu Sep 1 06:51:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 601801 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp256356mae; Thu, 1 Sep 2022 00:14:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zhLNsMWb8XoiR6Pp3Wm8M/U4BLhT/V30zwOfCcEcDexl6rLT2Ulk/le2eeuPP7xklzM5Z X-Received: by 2002:ac8:4e49:0:b0:343:620e:fd53 with SMTP id e9-20020ac84e49000000b00343620efd53mr23267079qtw.71.1662016481507; Thu, 01 Sep 2022 00:14:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662016481; cv=none; d=google.com; s=arc-20160816; b=UbGlUOpQgW6cvqq5VneSEqqpw92m/VXYWKa9ZdgtH9g7tOqA/Nn7f45+su/t6DcLis l+6OW7XywpsuZvx75ipjpPx6peWBN+Q+fOHYA1FsZKfrgy3BR0Ogr0j3Lp13FxBkeoNu Gn9Zc7FFetX45QUY6kBiJvFVLQNqYKLlcTHgT75LrVVz85UGJxzhPOPGXPVrkXMDhHpc uGO7nPMcJxJuIZfqLfHUbuUXrs+xPIcw6NP35Y/JIQ1ul+7aEZW1hIb6W7e3jj9uNgZm vcAmeRpKhytjVrG79h2P1jdj9FOP60ViFgpJnytElXHZbJdfeNuut0PWUfZhvP42X8ED zRpA== 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=osXM6kebf211jyJTnRVlg1LBiYlRKdmijrWPSS9x4Wo=; b=fZeO0A4zNCTxEanY72wXnBA7RQ842WcBtA/cXb2Lm33MoDOM9o6Z4CkFxelJEjc5R3 zrR4vVH7p+EyMndJe438IIEwSlMPY39o+VXCoqhNITetd8XOwasKnbvAdPMPeqiTeVmP F52GhWbPSK2vRw/NTA2UHh4DcoMA+/V6LQ3DLZ+xEGRGqTJLj9OG2s5w6OuA5cyZukKD ksZtWAUMAh3pbWNRmBisWh1LObmZFvbCLJWcdPgEnjPnhZbGNvy9mzQjz/jjToEsbgt6 4bopYztqtuDadfGI/jFfSUXRrGa7cDpMuK9hl78f5tPu+edtKzpKGRHYLILlRi7vXvGk MfUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P5WP1BaH; 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 w20-20020a05620a0e9400b006b9c33a1e8dsi8110370qkm.752.2022.09.01.00.14.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Sep 2022 00:14:41 -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=P5WP1BaH; 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]:40718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTePR-0003sK-0i for patch@linaro.org; Thu, 01 Sep 2022 03:14:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTe4A-0005v5-4t for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:52:47 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:45914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTe47-0003G2-Vp for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:52:41 -0400 Received: by mail-wr1-x42e.google.com with SMTP id w5so4831641wrn.12 for ; Wed, 31 Aug 2022 23:52:39 -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=osXM6kebf211jyJTnRVlg1LBiYlRKdmijrWPSS9x4Wo=; b=P5WP1BaHPbW8kc19nsfqo7KRtUVJcL4r41BBgcQYOgpS3qiQbI6Afuo1dEeet9BZ+Y 6UcKS618BMMsrW+X3lbfsHUrc6ySwVr192gEOVoolgrvMPUVJqXk+k2A/8ysCEcXLbwg F+gCZjta/NtZrQZkywPHT2Nl3HR3zW0jtZejKyZUhEoNFNDce5J1/g+h4aNbK1Qsd4ee dhBtJAOy13pl3uzoa7bXuTsKX7HqpLIoJ7C0pE9fi/dS12NIL/D/uhZ5Wxfh1eHix4C0 0tj77MKCnN/00Wasm455yREtDF0fVljkyuvYjbpF9NnR9AT1q+fB8bNPGD8he1THYkKc lOOw== 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=osXM6kebf211jyJTnRVlg1LBiYlRKdmijrWPSS9x4Wo=; b=seiq2gHqU3GD4btkWoIqnlEQUUrndjD2Z/JdIMxj+Fw8jrcq2m5/24qk1/0QLfhO0R lvu4ql24Y8WhOP/o0pzOkRtkY1+RdUwLOr7LcdddIOmO4HJ7v8zpexXmAqpcF3ZFnM2t GlqG7meu4gvY7eYOiupHxNSaGvQcBYKYpI3TVBDhSvCNtTLrzjA0irv54SIT5wNJTyhj GCVrxlwkdqnxNmuUYB8Vo7zo4swrX3myka5XejBPUA+QJ0zv1Dtkouuj0FU8pK9kf9kE nKFmrDiFAxIUGs8XbCcSDMn1y66zkVLzFhAxWtwiwivhZBDwqeIk56LVMHiCgJGiwwqQ 7xwA== X-Gm-Message-State: ACgBeo2r0ET9gWKNagq2pIHtrI8/HvLHRLqar0YE9xD+KymxwKDk/2xL gNcImEDMIR+JDTCLwmS2MHmcy7raQl/+GaBb X-Received: by 2002:a5d:64c9:0:b0:226:dfa0:3fa7 with SMTP id f9-20020a5d64c9000000b00226dfa03fa7mr8469555wri.350.1662015159205; Wed, 31 Aug 2022 23:52:39 -0700 (PDT) Received: from stoup.. ([87.192.221.83]) by smtp.gmail.com with ESMTPSA id a6-20020a5d4d46000000b00226dedf1ab7sm8308153wru.76.2022.08.31.23.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 23:52:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Michael Rolnik , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 4/4] target/avr: Disable interrupts when env->skip set Date: Thu, 1 Sep 2022 07:51:54 +0100 Message-Id: <20220901065210.117081-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220901065210.117081-1-richard.henderson@linaro.org> References: <20220901065210.117081-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This bit is not saved across interrupts, so we must delay delivering the interrupt until the skip has been processed. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1118 Reviewed-by: Michael Rolnik Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/avr/helper.c | 9 +++++++++ target/avr/translate.c | 26 ++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/target/avr/helper.c b/target/avr/helper.c index 34f1cbffb2..156dde4e92 100644 --- a/target/avr/helper.c +++ b/target/avr/helper.c @@ -31,6 +31,15 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) AVRCPU *cpu = AVR_CPU(cs); CPUAVRState *env = &cpu->env; + /* + * We cannot separate a skip from the next instruction, + * as the skip would not be preserved across the interrupt. + * Separating the two insn normally only happens at page boundaries. + */ + if (env->skip) { + return false; + } + if (interrupt_request & CPU_INTERRUPT_RESET) { if (cpu_interrupts_enabled(env)) { cs->exception_index = EXCP_RESET; diff --git a/target/avr/translate.c b/target/avr/translate.c index dc9c3d6bcc..026753c963 100644 --- a/target/avr/translate.c +++ b/target/avr/translate.c @@ -2971,8 +2971,18 @@ static void avr_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) if (skip_label) { canonicalize_skip(ctx); gen_set_label(skip_label); - if (ctx->base.is_jmp == DISAS_NORETURN) { + + switch (ctx->base.is_jmp) { + case DISAS_NORETURN: ctx->base.is_jmp = DISAS_CHAIN; + break; + case DISAS_NEXT: + if (ctx->base.tb->flags & TB_FLAGS_SKIP) { + ctx->base.is_jmp = DISAS_TOO_MANY; + } + break; + default: + break; } } @@ -2989,6 +2999,11 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) { DisasContext *ctx = container_of(dcbase, DisasContext, base); bool nonconst_skip = canonicalize_skip(ctx); + /* + * Because we disable interrupts while env->skip is set, + * we must return to the main loop to re-evaluate afterward. + */ + bool force_exit = ctx->base.tb->flags & TB_FLAGS_SKIP; switch (ctx->base.is_jmp) { case DISAS_NORETURN: @@ -2997,7 +3012,7 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) case DISAS_NEXT: case DISAS_TOO_MANY: case DISAS_CHAIN: - if (!nonconst_skip) { + if (!nonconst_skip && !force_exit) { /* Note gen_goto_tb checks singlestep. */ gen_goto_tb(ctx, 1, ctx->npc); break; @@ -3005,8 +3020,11 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) tcg_gen_movi_tl(cpu_pc, ctx->npc); /* fall through */ case DISAS_LOOKUP: - tcg_gen_lookup_and_goto_ptr(); - break; + if (!force_exit) { + tcg_gen_lookup_and_goto_ptr(); + break; + } + /* fall through */ case DISAS_EXIT: tcg_gen_exit_tb(NULL, 0); break;