From nobody Mon Nov 25 13:30:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1714981983; cv=none; d=zohomail.com; s=zohoarc; b=MchvL9y234mRyvhlwEd6VJJdlVzBXleE7uiHWWltTswlF+OfLqh1bwf6Q4/1BaTEgLNV4YSrxzRnasBq5vkehMRYhFO0qbMSABzRrxdxFMxixrjWvQICgp0/wrSpX66BGtJEFh0avm7OCj9PWA/h3P2prBl+irgN3pztm6JJvro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1714981983; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tkBKFh1uHjc74jYCPGWrYjt/t0FCbUHfDC8rQ9UiTvU=; b=I2wRBsT4vUtCXp/+tMA5PT2gObguqTQ47Vrnnd28bdSBC292S3LI1dQF3VyTnw7bvz0KCROIKPjnt57a5n88xylYaRev3sOBuK3fk/MGjLYM3bS4EoyaEi2MOpLWFIWxiHJBxAHQvGjiepsuq07OUpMt8Uh09wUDmTyt+EYWJdU= 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 1714981983867611.2997661144468; Mon, 6 May 2024 00:53:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3t91-0005rd-T9; Mon, 06 May 2024 03:52: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 1s3t8Y-0005il-JI for qemu-devel@nongnu.org; Mon, 06 May 2024 03:51:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3t8I-0001UC-Dh for qemu-devel@nongnu.org; Mon, 06 May 2024 03:51:35 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-Q2X3w0YfP6-0mpOcdwpIIQ-1; Mon, 06 May 2024 03:51:32 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a599dbd2b6aso89396066b.2 for ; Mon, 06 May 2024 00:51:32 -0700 (PDT) Received: from avogadro.local ([151.95.155.52]) by smtp.gmail.com with ESMTPSA id wk18-20020a170907055200b00a59df1df5c3sm118393ejb.47.2024.05.06.00.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 00:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714981893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tkBKFh1uHjc74jYCPGWrYjt/t0FCbUHfDC8rQ9UiTvU=; b=b58Mr0OTGcte+kEf1vKkUT0lO3n0mr2uVs+CyBwSCiTWNNYVQlD/6iJKrffs7uH7r6n9Sw g1/SCd2FT/uGBOb/z4jcWYfLUoD3Gz4BgsO562UUQwBbhy3Ox7ZcFskRXLxB3AwiVs7ge7 VIqBGp2bjJHQqacDxzqfPhrqqt32vyU= X-MC-Unique: Q2X3w0YfP6-0mpOcdwpIIQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714981890; x=1715586690; 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=tkBKFh1uHjc74jYCPGWrYjt/t0FCbUHfDC8rQ9UiTvU=; b=KbZKc3aD7gatMlW17qLlwrFEOHoV+/wm3kVKpN42xZYmgsNctsBo00OxJ80wXaN2md V74lx7nXgIwSlEl2afaDSVHHY5F5zrcaDzyYytOtZmhraTDmROZCbxY+H0kXEiHOoJDe kl/7QSvorWyiDwofAuUQg7pBY1szpQrH89bVJAoHH/M9j+AVReyZAC5MKNn1buad5Y57 1NGFEcdE3FAPl8NBoRKEJlcJR0CBJGaq1ExPMEL7KajRMJZvqfNQ98yXYYRL4QY6IfSf yrgGJQU7r0li6lxqLLquwvu/Qe070bHszB0MyEv0RZAfJsAkQCjmm3HohbJoGN/PKXjH peOw== X-Gm-Message-State: AOJu0Yx43zOboUZM38cVY4oB/E3PchGlDBjpGP2g4YqLSZVc+xoq6JCG Uxj9xLHStugF3J9OwR10IElZvp5Q2jsG+sRoEGv16/NHe29XqqYvXNexnrYArEcIyv/AaXNn5Vq 2NwmyJ5NMHdyRGWu5fw/HSycpTxotkGOtwGUFog2JDhMNQH/w6unaYD1xBivzusXIw79nexWL/6 coPlUdtcLrWbZ9QObmiikgwvOvChSMGs1S2HIj X-Received: by 2002:a17:907:9724:b0:a59:b359:3e14 with SMTP id jg36-20020a170907972400b00a59b3593e14mr3133828ejc.10.1714981890197; Mon, 06 May 2024 00:51:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5ZHa5Mfy3hpTH89lkjF861B+hFQWwvqYjvqgkZjswi1MTMI5pb2F7nwTfoCx0J17I1AJLJw== X-Received: by 2002:a17:907:9724:b0:a59:b359:3e14 with SMTP id jg36-20020a170907972400b00a59b3593e14mr3133816ejc.10.1714981889655; Mon, 06 May 2024 00:51:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ruihan Li , Richard Henderson Subject: [PULL 01/46] target/i386: Give IRQs a chance when resetting HF_INHIBIT_IRQ_MASK Date: Mon, 6 May 2024 09:50:40 +0200 Message-ID: <20240506075125.8238-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240506075125.8238-1-pbonzini@redhat.com> References: <20240506075125.8238-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.431, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1714981986817100013 Content-Type: text/plain; charset="utf-8" From: Ruihan Li When emulated with QEMU, interrupts will never come in the following loop. However, if the NOP instruction is uncommented, interrupts will fire as normal. loop: cli call do_sti jmp loop do_sti: sti # nop ret This behavior is different from that of a real processor. For example, if KVM is enabled, interrupts will always fire regardless of whether the NOP instruction is commented or not. Also, the Intel Software Developer Manual states that after the STI instruction is executed, the interrupt inhibit should end as soon as the next instruction (e.g., the RET instruction if the NOP instruction is commented) is executed. This problem is caused because the previous code may choose not to end the TB even if the HF_INHIBIT_IRQ_MASK has just been reset (e.g., in the case where the STI instruction is immediately followed by the RET instruction), so that IRQs may not have a change to trigger. This commit fixes the problem by always terminating the current TB to give IRQs a chance to trigger when HF_INHIBIT_IRQ_MASK is reset. Reviewed-by: Richard Henderson Signed-off-by: Ruihan Li Message-ID: <20240415064518.4951-4-lrh2000@pku.edu.cn> Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index c05d9e52259..051ffb5e1fd 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2798,13 +2798,17 @@ static void gen_bnd_jmp(DisasContext *s) static void do_gen_eob_worker(DisasContext *s, bool inhibit, bool recheck_tf, bool jr) { + bool inhibit_reset; + gen_update_cc_op(s); =20 /* If several instructions disable interrupts, only the first does it.= */ - if (inhibit && !(s->flags & HF_INHIBIT_IRQ_MASK)) { - gen_set_hflag(s, HF_INHIBIT_IRQ_MASK); - } else { + inhibit_reset =3D false; + if (s->flags & HF_INHIBIT_IRQ_MASK) { gen_reset_hflag(s, HF_INHIBIT_IRQ_MASK); + inhibit_reset =3D true; + } else if (inhibit) { + gen_set_hflag(s, HF_INHIBIT_IRQ_MASK); } =20 if (s->base.tb->flags & HF_RF_MASK) { @@ -2815,7 +2819,9 @@ do_gen_eob_worker(DisasContext *s, bool inhibit, bool= recheck_tf, bool jr) tcg_gen_exit_tb(NULL, 0); } else if (s->flags & HF_TF_MASK) { gen_helper_single_step(tcg_env); - } else if (jr) { + } else if (jr && + /* give irqs a chance to happen */ + !inhibit_reset) { tcg_gen_lookup_and_goto_ptr(); } else { tcg_gen_exit_tb(NULL, 0); --=20 2.44.0