From patchwork Tue Jun 4 07:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3135AC27C53 for ; Tue, 4 Jun 2024 07:19:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORU-00033j-Tx; Tue, 04 Jun 2024 03:18:48 -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 1sEORS-0002zc-WB for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORQ-0005ai-Ox for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485524; 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=kSWUo4sCXjrNOR0yu+FmZCYBkQr0GiAN238dsmBJ6yo=; b=PKISnDKgsXsTfFJ4sgDNGFt9X/FukJ4ILSk7nzYhR/3JEY5bQn3rxFF+Im5dwzW/p0amv8 hq654eDgpIsVtR+SdQC/2FHBZCWoC82XEVO3Zl7TI+wCLU9YzdFunclBCnFY51vexodOa6 Da1P60w7E5JS1erfP04/xC3a39Lp/3k= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-QlqoyUdePouWqsE8TZtvMQ-1; Tue, 04 Jun 2024 03:18:43 -0400 X-MC-Unique: QlqoyUdePouWqsE8TZtvMQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a68f2d64342so15791466b.1 for ; Tue, 04 Jun 2024 00:18:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485520; x=1718090320; 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=kSWUo4sCXjrNOR0yu+FmZCYBkQr0GiAN238dsmBJ6yo=; b=EoNSKnvwAKm1ZuR/JC94XStrepcEKs2U2XhOmbyjzZjmSljs52veknUD/iN3kgBnTJ 13qV86859rGPjddjuCiAI50JmqalVWwSL6abBx26dKItJsb3Wxr9ANnEebQqabWo04r0 kzf/9yL+w9P8leReKNNdq4hmDMra2hvB5o128UI6AvhrNWSaSXpTQI+Er9Bhw6zRn+BR OiCmi3/BfJxctjEAxv8vaHgXOzWh6SZyC82UdSvrtOAdUNzocgxsINa2zP35orhh5KuB Hs9XEY2+jyr2r7JVoSRrYqgeYmN2JsoMqMD8rNr7wvkzt79i6WbTVEyCRtKaXgxQA9Ux 6VTA== X-Gm-Message-State: AOJu0Yzwz9KqEMCX+chvaeyoMCPJj/MWral5KsKePMttKPZLubO2Gu0H V9wiIMNSRLwacxo6OjC5cWxqiedB3FD42uhInX0ST0owq4BEUhyAT9ofmu242FyeaRvcdwz9R9Q +EcrzCk1ewcrI+JE1a+jWAfNiSG2lZCdP+2s+eoYgU+/mAW/wU4iBpuap9tU9YGdpm3gU1M1qXL uO2m1RMrnn60un8uU2K87tr3sbSxNQXDGj+2wG X-Received: by 2002:a17:906:ae8f:b0:a63:4ed6:beac with SMTP id a640c23a62f3a-a681fe4d9a1mr722276766b.8.1717485520597; Tue, 04 Jun 2024 00:18:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp5zJ6aPDe1MZBE4mtzCzWtAok5a9J4jipTW0LaLYuKzVRBhQwqJH3Oq0/B7U+NRHTP6sOVA== X-Received: by 2002:a17:906:ae8f:b0:a63:4ed6:beac with SMTP id a640c23a62f3a-a681fe4d9a1mr722275066b.8.1717485520124; Tue, 04 Jun 2024 00:18:40 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68f4191cfdsm332559566b.137.2024.06.04.00.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 01/11] target/i386: fix pushed value of EFLAGS.RF Date: Tue, 4 Jun 2024 09:18:23 +0200 Message-ID: <20240604071833.962574-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When preparing an exception stack frame for a fault exception, the value pushed for RF is 1. Take that into account. The same should be true of interrupts for repeated string instructions, but the situation there is complicated. Signed-off-by: Paolo Bonzini Acked-by: Richard Henderson --- target/i386/tcg/seg_helper.c | 49 ++++++++++++++++++++++++++++++++---- target/i386/tcg/translate.c | 8 ++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c index 0301459004e..715db1f2326 100644 --- a/target/i386/tcg/seg_helper.c +++ b/target/i386/tcg/seg_helper.c @@ -526,6 +526,24 @@ static inline unsigned int get_sp_mask(unsigned int e2) } } +static int exception_is_fault(int intno) +{ + switch (intno) { + /* + * #DB can be both fault- and trap-like, but it never sets RF=1 + * in the RFLAGS value pushed on the stack. + */ + case EXCP01_DB: + case EXCP03_INT3: + case EXCP04_INTO: + case EXCP08_DBLE: + case EXCP12_MCHK: + return 0; + } + /* Everything else including reserved exception is a fault. */ + return 1; +} + int exception_has_error_code(int intno) { switch (intno) { @@ -605,8 +623,9 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, int type, dpl, selector, ss_dpl, cpl; int has_error_code, new_stack, shift; uint32_t e1, e2, offset, ss = 0, esp, ss_e1 = 0, ss_e2 = 0; - uint32_t old_eip, sp_mask; + uint32_t old_eip, sp_mask, eflags; int vm86 = env->eflags & VM_MASK; + bool set_rf; has_error_code = 0; if (!is_int && !is_hw) { @@ -614,8 +633,10 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, } if (is_int) { old_eip = next_eip; + set_rf = false; } else { old_eip = env->eip; + set_rf = exception_is_fault(intno); } dt = &env->idt; @@ -748,6 +769,15 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, } push_size <<= shift; #endif + eflags = cpu_compute_eflags(env); + /* + * AMD states that code breakpoint #DBs clear RF=0, Intel leaves it + * as is. AMD behavior could be implemented in check_hw_breakpoints(). + */ + if (set_rf) { + eflags |= RF_MASK; + } + if (shift == 1) { if (new_stack) { if (vm86) { @@ -759,7 +789,7 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, PUSHL(ssp, esp, sp_mask, env->segs[R_SS].selector); PUSHL(ssp, esp, sp_mask, env->regs[R_ESP]); } - PUSHL(ssp, esp, sp_mask, cpu_compute_eflags(env)); + PUSHL(ssp, esp, sp_mask, eflags); PUSHL(ssp, esp, sp_mask, env->segs[R_CS].selector); PUSHL(ssp, esp, sp_mask, old_eip); if (has_error_code) { @@ -776,7 +806,7 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, PUSHW(ssp, esp, sp_mask, env->segs[R_SS].selector); PUSHW(ssp, esp, sp_mask, env->regs[R_ESP]); } - PUSHW(ssp, esp, sp_mask, cpu_compute_eflags(env)); + PUSHW(ssp, esp, sp_mask, eflags); PUSHW(ssp, esp, sp_mask, env->segs[R_CS].selector); PUSHW(ssp, esp, sp_mask, old_eip); if (has_error_code) { @@ -868,8 +898,9 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int, target_ulong ptr; int type, dpl, selector, cpl, ist; int has_error_code, new_stack; - uint32_t e1, e2, e3, ss; + uint32_t e1, e2, e3, ss, eflags; target_ulong old_eip, esp, offset; + bool set_rf; has_error_code = 0; if (!is_int && !is_hw) { @@ -877,8 +908,10 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int, } if (is_int) { old_eip = next_eip; + set_rf = false; } else { old_eip = env->eip; + set_rf = exception_is_fault(intno); } dt = &env->idt; @@ -950,9 +983,15 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int, } esp &= ~0xfLL; /* align stack */ + /* See do_interrupt_protected. */ + eflags = cpu_compute_eflags(env); + if (set_rf) { + eflags |= RF_MASK; + } + PUSHQ(esp, env->segs[R_SS].selector); PUSHQ(esp, env->regs[R_ESP]); - PUSHQ(esp, cpu_compute_eflags(env)); + PUSHQ(esp, eflags); PUSHQ(esp, env->segs[R_CS].selector); PUSHQ(esp, old_eip); if (has_error_code) { diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 0486ab69112..d438f8f76f7 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -4630,6 +4630,14 @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) * If jmp_opt, we want to handle each string instruction individually. * For icount also disable repz optimization so that each iteration * is accounted separately. + * + * FIXME: this is messy; it makes REP string instructions a lot less + * efficient than they should be and it gets in the way of correct + * handling of RF (interrupts or traps arriving after any iteration + * of a repeated string instruction but the last should set RF to 1). + * Perhaps it would be more efficient if REP string instructions were + * always at the beginning of the TB, or even their own TB? That + * would even allow accounting up to 64k iterations at once for icount. */ dc->repz_opt = !dc->jmp_opt && !(cflags & CF_USE_ICOUNT); From patchwork Tue Jun 4 07:18:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BFD0C27C53 for ; Tue, 4 Jun 2024 07:20:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORZ-00038x-8v; Tue, 04 Jun 2024 03:18:53 -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 1sEORX-000368-Fr for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORV-0005bO-RL for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485529; 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=U/nNXKv5w7XsoKaYFhzY0rSXugZeBuJcWZqnC83Ujh0=; b=ISxBcOyuKeOZ5q6Ij4Mh6hRMsHkJQ7PeCJXOkPNlPfPwkoNGPS/RntHk24lPIg8cFvJVHB yIDUC/nURzL7zmIATWAfTIPxsIRUCNZGr0SY2YVTxvQ1Jr4YIpUHew+OfnhRwrP8pGagFs Hl9CKiRXBR5jPpzILZVWlKh8yZyQweE= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-qqppHs-CNLiIai-j2BHHBg-1; Tue, 04 Jun 2024 03:18:46 -0400 X-MC-Unique: qqppHs-CNLiIai-j2BHHBg-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57a52be5f2aso831590a12.3 for ; Tue, 04 Jun 2024 00:18:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485524; x=1718090324; 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=U/nNXKv5w7XsoKaYFhzY0rSXugZeBuJcWZqnC83Ujh0=; b=WJfUijtoyiqTG9/lj/CX8k069OjqhRnT/0O4iSziZ1miXzTxQcihiQQ05Zy9n+Ca8o A30GGmJBYsGJfCEV3N4hARZZYU1whbGS2Xyc0nvtq4+mFQN3oYLFESjVDfnn3mpJDuvw /gVzC3aVZDjtV64Lzd5A2PMqX0hI1zkdxLgeDRW3eHEWJeHV7l4rWfXDYeLVLyoDxSf0 CG8iK8kPddtbAMmeVA6nDXU8iBjhtVth4nfI9VelzYKMVcQjq1LTvkQl9mUQA6CA6xuO WIBySmmz8nUBuGbnhbGmB3mc99cRNpZuQijZeGb+LLIWbl0o9sRx8/QdWkxHsYoioJF8 QoMQ== X-Gm-Message-State: AOJu0Yy7P01M/TLRTjpCC7a901BhaxB6GJWcZ3WM4MFqHgqSL5hMKwms fqrVoaCuB9fudhqqY9Z1F31jJcwEVUxvdwximuYo9iX2C/6xdw8xV0WNoGAL2EjL+k2J8gJ1DYc 003AnJAAx8oTblh4B+gP5XMVoIT3RUZDyQbrQSX185hzlKJ4D18xpxUj+zS1iEdsfwZjbZk9ZTI r84WO81iaC+RK6ximUFtLY/kadnkhhgPz7j/Hl X-Received: by 2002:a17:906:6d06:b0:a68:b0f2:1d95 with SMTP id a640c23a62f3a-a68b0f21f73mr514339566b.71.1717485524171; Tue, 04 Jun 2024 00:18:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwfIzW2qIHF45NYhJjYVhuvBsePfnB39ghXQq3gsX5UUvBAEf+++bMCa3NFAFq5n+AMi1O+A== X-Received: by 2002:a17:906:6d06:b0:a68:b0f2:1d95 with SMTP id a640c23a62f3a-a68b0f21f73mr514338366b.71.1717485523566; Tue, 04 Jun 2024 00:18:43 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68ce1e4462sm398245566b.197.2024.06.04.00.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 02/11] target/i386: fix implementation of ICEBP Date: Tue, 4 Jun 2024 09:18:24 +0200 Message-ID: <20240604071833.962574-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ICEBP generates a trap-like exception, while gen_exception() produces a fault. Resurrect gen_update_eip_next() to implement the desired semantics. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/helper.h | 1 + target/i386/tcg/helper-tcg.h | 3 +++ target/i386/tcg/bpt_helper.c | 6 ++++++ target/i386/tcg/excp_helper.c | 20 ++++++++++++++++++++ target/i386/tcg/translate.c | 13 +++++++++++++ target/i386/tcg/emit.c.inc | 5 ++++- 6 files changed, 47 insertions(+), 1 deletion(-) diff --git a/target/i386/helper.h b/target/i386/helper.h index a52a1bf0f21..8f291a5f66f 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -56,6 +56,7 @@ DEF_HELPER_2(sysret, void, env, int) DEF_HELPER_FLAGS_2(pause, TCG_CALL_NO_WG, noreturn, env, int) DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int) DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_1(icebp, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_3(boundw, void, env, tl, int) DEF_HELPER_3(boundl, void, env, tl, int) diff --git a/target/i386/tcg/helper-tcg.h b/target/i386/tcg/helper-tcg.h index effc2c1c984..6a5505e7b4c 100644 --- a/target/i386/tcg/helper-tcg.h +++ b/target/i386/tcg/helper-tcg.h @@ -112,6 +112,9 @@ int exception_has_error_code(int intno); void do_smm_enter(X86CPU *cpu); /* bpt_helper.c */ +void do_end_instruction(CPUX86State *env); + +/* sysemu/bpt_helper.c */ bool check_hw_breakpoints(CPUX86State *env, bool force_dr6_update); #endif /* I386_HELPER_TCG_H */ diff --git a/target/i386/tcg/bpt_helper.c b/target/i386/tcg/bpt_helper.c index bc34ac27fea..9695b9dd041 100644 --- a/target/i386/tcg/bpt_helper.c +++ b/target/i386/tcg/bpt_helper.c @@ -37,3 +37,9 @@ void helper_rechecking_single_step(CPUX86State *env) helper_single_step(env); } } + +void do_end_instruction(CPUX86State *env) +{ + env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */ + env->eflags &= ~HF_RF_MASK; +} diff --git a/target/i386/tcg/excp_helper.c b/target/i386/tcg/excp_helper.c index 65e37ae2a0c..72387aac24f 100644 --- a/target/i386/tcg/excp_helper.c +++ b/target/i386/tcg/excp_helper.c @@ -140,6 +140,26 @@ G_NORETURN void raise_exception_ra(CPUX86State *env, int exception_index, raise_interrupt2(env, exception_index, 0, 0, 0, retaddr); } +G_NORETURN void helper_icebp(CPUX86State *env) +{ + CPUState *cs = env_cpu(env); + + do_end_instruction(env); + + /* + * INT1 aka ICEBP generates a trap-like #DB, but it is pretty special. + * + * "Although the ICEBP instruction dispatches through IDT vector 1, + * that event is not interceptable by means of the #DB exception + * intercept". Instead there is a separate fault-like ICEBP intercept. + */ + cs->exception_index = EXCP01_DB; + env->error_code = 0; + env->exception_is_int = 0; + env->exception_next_eip = env->eip; + cpu_loop_exit(cs); +} + G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr, MMUAccessType access_type, uintptr_t retaddr) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index d438f8f76f7..77ed9c1db47 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -549,6 +549,19 @@ static inline void gen_op_st_rm_T0_A0(DisasContext *s, int idx, int d) } } +static void gen_update_eip_next(DisasContext *s) +{ + assert(s->pc_save != -1); + if (tb_cflags(s->base.tb) & CF_PCREL) { + tcg_gen_addi_tl(cpu_eip, cpu_eip, s->pc - s->pc_save); + } else if (CODE64(s)) { + tcg_gen_movi_tl(cpu_eip, s->pc); + } else { + tcg_gen_movi_tl(cpu_eip, (uint32_t)(s->pc - s->cs_base)); + } + s->pc_save = s->pc; +} + static void gen_update_eip_cur(DisasContext *s) { assert(s->pc_save != -1); diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index e990141454b..36127d99943 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1858,7 +1858,10 @@ static void gen_INT(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) static void gen_INT1(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { - gen_exception(s, EXCP01_DB); + gen_update_cc_op(s); + gen_update_eip_next(s); + gen_helper_icebp(tcg_env); + s->base.is_jmp = DISAS_NORETURN; } static void gen_INT3(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) From patchwork Tue Jun 4 07:18:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5CB34C25B7E for ; Tue, 4 Jun 2024 07:19:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORc-0003Bb-UP; Tue, 04 Jun 2024 03:18:56 -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 1sEORc-0003BI-7o for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORa-0005cX-LG for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485533; 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=3+poIGky4GSqhFlE6pkBG1pa6bXFWkqUUf8ylZXVgw0=; b=W20a+jufyofXBt+KDIkybKd/tsazj1Xlck8JMzJpo3jN2Eot6qBgfK+0mxhmBPabqzEd6+ 9oOe6C/sOg/teXeNl1A1b9LqpcYsjynb22lshNTQ7ovu/iTXWrC+GjAKwuup/nxpMiRFkD QjJLb1UoX40zDbL9MTlGPFRUWjPclJQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-ze5qarTvPYCinkPjVbE8hQ-1; Tue, 04 Jun 2024 03:18:49 -0400 X-MC-Unique: ze5qarTvPYCinkPjVbE8hQ-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a24dac048so2179637a12.0 for ; Tue, 04 Jun 2024 00:18:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485527; x=1718090327; 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=3+poIGky4GSqhFlE6pkBG1pa6bXFWkqUUf8ylZXVgw0=; b=GciWqtLOkx9d2NFvXYZUfVdIwt2obuihHFa2BQ9GbcSQ0o/67Gf/N0rxRs1n0/xHsR PRhdnMvAb5cnNoBTbyeYxU3/97Q2tc5vSbNRxIxhBcRL64HCGoIz13cFaBhxd2nNQyaE tkyLkk2ZjQAumfoc9/vgRXx7EhH9H4oXWua7uEV+G7eGVOpgTMzDz6frHTx6FY+GI2gA uCMlnmR5+vvpFn2EdPmG5C1JeMd8GRzpVoTJh5MWprTRn9Tuv6ZZm3bqdvGFSor7llrT 7uuaZ+8i3eoU6biqOV9jXddWrlGEuHQuIxqiY09/Wng36ps67/9je1PhsXXe63IKiqng FylQ== X-Gm-Message-State: AOJu0YwXc2gh4+7E+Mgxiu6wrT0BKWRbEUljS6PmBrvPiFwt2/JB4rtY BzAOsn/XAjEd7ZWtjmcX6FUMYXtXAQxMmwkf4mE80OHgW1Ci8xwWZ5uySp8yoA2lTXBUaInf0ZO 8cE4W0+XK78F8tMATRlJ7qclNgtRt8kNiNaqQv7BaGjW6gBI+R6KWKO869jgf86uO9ssAVSQ5Ct tQ8/pjYCIxkHrk1shDOYDTlkxxfn2drstEPYci X-Received: by 2002:a50:ba89:0:b0:57a:321f:cc4f with SMTP id 4fb4d7f45d1cf-57a3f55eb7emr7394309a12.19.1717485527376; Tue, 04 Jun 2024 00:18:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDlyGHizdRw6inPRoPSe2Ub88yvUi1oKW9DNURVkz2VD/rdI026ySJVII7f+mRWqCng5ft2w== X-Received: by 2002:a50:ba89:0:b0:57a:321f:cc4f with SMTP id 4fb4d7f45d1cf-57a3f55eb7emr7394293a12.19.1717485526957; Tue, 04 Jun 2024 00:18:46 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a790f1c95sm1565969a12.50.2024.06.04.00.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 03/11] target/i386: cleanup HLT helpers Date: Tue, 4 Jun 2024 09:18:25 +0200 Message-ID: <20240604071833.962574-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use decode.c's support for intercepts, doing the check in TCG-generated code rather than the helper. This is cleaner because it allows removing the eip_addend argument to helper_hlt(). Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/helper.h | 2 +- target/i386/tcg/sysemu/misc_helper.c | 13 ++----------- target/i386/tcg/decode-new.c.inc | 4 ++-- target/i386/tcg/emit.c.inc | 4 ++-- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/target/i386/helper.h b/target/i386/helper.h index 8f291a5f66f..c244dbb4812 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -90,7 +90,7 @@ DEF_HELPER_2(vmsave, void, env, int) DEF_HELPER_1(stgi, void, env) DEF_HELPER_1(clgi, void, env) DEF_HELPER_FLAGS_2(flush_page, TCG_CALL_NO_RWG, void, env, tl) -DEF_HELPER_FLAGS_2(hlt, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_1(hlt, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_FLAGS_2(monitor, TCG_CALL_NO_WG, void, env, tl) DEF_HELPER_FLAGS_2(mwait, TCG_CALL_NO_WG, noreturn, env, int) DEF_HELPER_1(rdmsr, void, env) diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/misc_helper.c index edb7c3d8940..e41c88346cb 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -516,8 +516,7 @@ void helper_flush_page(CPUX86State *env, target_ulong addr) tlb_flush_page(env_cpu(env), addr); } -static G_NORETURN -void do_hlt(CPUX86State *env) +G_NORETURN void helper_hlt(CPUX86State *env) { CPUState *cs = env_cpu(env); @@ -527,14 +526,6 @@ void do_hlt(CPUX86State *env) cpu_loop_exit(cs); } -G_NORETURN void helper_hlt(CPUX86State *env, int next_eip_addend) -{ - cpu_svm_check_intercept_param(env, SVM_EXIT_HLT, 0, GETPC()); - env->eip += next_eip_addend; - - do_hlt(env); -} - void helper_monitor(CPUX86State *env, target_ulong ptr) { if ((uint32_t)env->regs[R_ECX] != 0) { @@ -558,6 +549,6 @@ G_NORETURN void helper_mwait(CPUX86State *env, int next_eip_addend) if (cs->cpu_index != 0 || CPU_NEXT(cs) != NULL) { do_pause(env); } else { - do_hlt(env); + helper_hlt(env); } } diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.c.inc index 0ff0866e8f3..376d2bdabe1 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -1496,7 +1496,7 @@ static const X86OpEntry opcodes_root[256] = { [0xE7] = X86_OP_ENTRYrr(OUT, 0,v, I_unsigned,b), /* AX/EAX */ [0xF1] = X86_OP_ENTRY0(INT1, svm(ICEBP)), - [0xF4] = X86_OP_ENTRY0(HLT, chk(cpl0)), + [0xF4] = X86_OP_ENTRY0(HLT, chk(cpl0) svm(HLT)), [0xF5] = X86_OP_ENTRY0(CMC), [0xF6] = X86_OP_GROUP1(group3, E,b), [0xF7] = X86_OP_GROUP1(group3, E,v), @@ -2539,7 +2539,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) /* * Checks that result in #GP or VMEXIT come second. Intercepts are - * generally checked after non-memory exceptions (i.e. before all + * generally checked after non-memory exceptions (i.e. after all * exceptions if there is no memory operand). Exceptions are * vm86 checks (INTn, IRET, PUSHF/POPF), RSM and XSETBV (!). * diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 36127d99943..2e94e8ec56f 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1638,8 +1638,8 @@ static void gen_HLT(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { #ifdef CONFIG_SYSTEM_ONLY gen_update_cc_op(s); - gen_update_eip_cur(s); - gen_helper_hlt(tcg_env, cur_insn_len_i32(s)); + gen_update_eip_next(s); + gen_helper_hlt(tcg_env); s->base.is_jmp = DISAS_NORETURN; #endif } From patchwork Tue Jun 4 07:18:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4CEDC27C52 for ; Tue, 4 Jun 2024 07:19:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORh-0003Ec-Kc; Tue, 04 Jun 2024 03:19:01 -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 1sEORg-0003Ch-6C for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:00 -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 1sEORe-0005dN-Do for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485537; 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=PdoHVj3MnM6xNHR6wiFxITGd/pg/M7TRVW28uhWoqSA=; b=A6xG8l5nK2COHr3g9reR6EfiVjLaYywt1ZUU9r7Gi2/uTZ6IusInwhGb9dsn2DBl58HffU Zd/zCaVqtSqB8axdHu6j0LWiu1GrlF92fH9Dh+rfXFHRM6XvkyluOzyUxHvwtzCO5tLM1k eL7QTIb9xaBtqUaIFqO4O4Zmwq7byHI= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-77-R5rhD1EjPJ-uXDIGk3u0bg-1; Tue, 04 Jun 2024 03:18:52 -0400 X-MC-Unique: R5rhD1EjPJ-uXDIGk3u0bg-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a33a589b3so1410062a12.0 for ; Tue, 04 Jun 2024 00:18:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485531; x=1718090331; 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=PdoHVj3MnM6xNHR6wiFxITGd/pg/M7TRVW28uhWoqSA=; b=pVmdev/mh3SESkkcp91eGHlYUg8yhWlLC3k7yOzP6U8OQqjzWMSgmJyn+RSk6NiI1t NUFHCATAhyY1zn3PGvkZsv/x60HvzLqQTI/Zl6sYZxe+0bx1HVuVhOuUQA169rJIB1FG JuoqBeYPqH4sT5CUEz8FuBLaX8lnsFAI75cWC+6sp6XoXnF3XYhnAkMVxexA0Fw/MmB5 alEuhfSqaUvhlTOOrr4KSKkodVvvP5HQDHA8XghotkxlkNNsL0RJ/DYKRmg/FS+ghiUN geKZj7ExhTA6JJs5KKaG9wV1Fb0P9v4RUJRcxjY+CCIPgWiUKDMv2lo/tMli8Sr5MNRG itCQ== X-Gm-Message-State: AOJu0Yx16qOADA232C9MKD4MG8827yPZuveRxKQbkAz3laHH6DjTG7fw 8US3VErCoHBUblntAl1SKwQ61jsSdD+xx4Azd1LaGfGms43MH0ot3BBP/75slO5I5gyk+DGBJRO 2kiyGXvWiq72fILNw7ZGM31UafCderfbnWz23LcTOSC6Np6LoQeo3QgmDKpmduAFaSE9vTeAvdx /ufD3ZsV5Xpw9PdRH140IJqGoGPFzx3yDQQKQb X-Received: by 2002:a17:906:3488:b0:a69:24f:23e7 with SMTP id a640c23a62f3a-a69024f243dmr351152866b.19.1717485530705; Tue, 04 Jun 2024 00:18:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQO0U2Meo9rcZ2moPnucu22v3XH/OB4DJUwrQep5TLlkvYphj1TyHZDUcQps26eCEEn8DF9A== X-Received: by 2002:a17:906:3488:b0:a69:24f:23e7 with SMTP id a640c23a62f3a-a69024f243dmr351150866b.19.1717485530236; Tue, 04 Jun 2024 00:18:50 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68e7dc0f95sm368091766b.108.2024.06.04.00.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 04/11] target/i386: cleanup PAUSE helpers Date: Tue, 4 Jun 2024 09:18:26 +0200 Message-ID: <20240604071833.962574-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use decode.c's support for intercepts, doing the check in TCG-generated code rather than the helper. This is cleaner because it allows removing the eip_addend argument to helper_pause(), even though it adds a bit of bloat for opcode 0x90's new decoding function. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/helper.h | 2 +- target/i386/tcg/helper-tcg.h | 1 - target/i386/tcg/misc_helper.c | 10 +--------- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/decode-new.c.inc | 15 ++++++++++++++- target/i386/tcg/emit.c.inc | 20 ++++++++------------ 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/target/i386/helper.h b/target/i386/helper.h index c244dbb4812..2f46cffabd8 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -53,7 +53,7 @@ DEF_HELPER_1(sysenter, void, env) DEF_HELPER_2(sysexit, void, env, int) DEF_HELPER_2(syscall, void, env, int) DEF_HELPER_2(sysret, void, env, int) -DEF_HELPER_FLAGS_2(pause, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_1(pause, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int) DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int) DEF_HELPER_FLAGS_1(icebp, TCG_CALL_NO_WG, noreturn, env) diff --git a/target/i386/tcg/helper-tcg.h b/target/i386/tcg/helper-tcg.h index 6a5505e7b4c..43180b58314 100644 --- a/target/i386/tcg/helper-tcg.h +++ b/target/i386/tcg/helper-tcg.h @@ -91,7 +91,6 @@ extern const uint8_t parity_table[256]; /* misc_helper.c */ void cpu_load_eflags(CPUX86State *env, int eflags, int update_mask); -G_NORETURN void do_pause(CPUX86State *env); /* sysemu/svm_helper.c */ #ifndef CONFIG_USER_ONLY diff --git a/target/i386/tcg/misc_helper.c b/target/i386/tcg/misc_helper.c index b0f0f7b893b..8316d42ffcd 100644 --- a/target/i386/tcg/misc_helper.c +++ b/target/i386/tcg/misc_helper.c @@ -88,7 +88,7 @@ G_NORETURN void helper_rdpmc(CPUX86State *env) raise_exception_err(env, EXCP06_ILLOP, 0); } -G_NORETURN void do_pause(CPUX86State *env) +G_NORETURN void helper_pause(CPUX86State *env) { CPUState *cs = env_cpu(env); @@ -97,14 +97,6 @@ G_NORETURN void do_pause(CPUX86State *env) cpu_loop_exit(cs); } -G_NORETURN void helper_pause(CPUX86State *env, int next_eip_addend) -{ - cpu_svm_check_intercept_param(env, SVM_EXIT_PAUSE, 0, GETPC()); - env->eip += next_eip_addend; - - do_pause(env); -} - uint64_t helper_rdpkru(CPUX86State *env, uint32_t ecx) { if ((env->cr[4] & CR4_PKE_MASK) == 0) { diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/misc_helper.c index e41c88346cb..093cc2d0f90 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -547,7 +547,7 @@ G_NORETURN void helper_mwait(CPUX86State *env, int next_eip_addend) /* XXX: not complete but not completely erroneous */ if (cs->cpu_index != 0 || CPU_NEXT(cs) != NULL) { - do_pause(env); + helper_pause(env); } else { helper_hlt(env); } diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.c.inc index 376d2bdabe1..c2d8da8d14e 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -1359,6 +1359,19 @@ static void decode_group11(DisasContext *s, CPUX86State *env, X86OpEntry *entry, } } +static void decode_90(DisasContext *s, CPUX86State *env, X86OpEntry *entry, uint8_t *b) +{ + static X86OpEntry pause = X86_OP_ENTRY0(PAUSE, svm(PAUSE)); + static X86OpEntry nop = X86_OP_ENTRY0(NOP); + static X86OpEntry xchg_ax = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v); + + if (REX_B(s)) { + *entry = xchg_ax; + } else { + *entry = (s->prefix & PREFIX_REPZ) ? pause : nop; + } +} + static const X86OpEntry opcodes_root[256] = { [0x00] = X86_OP_ENTRY2(ADD, E,b, G,b, lock), [0x01] = X86_OP_ENTRY2(ADD, E,v, G,v, lock), @@ -1441,7 +1454,7 @@ static const X86OpEntry opcodes_root[256] = { [0x86] = X86_OP_ENTRY2(XCHG, E,b, G,b, xchg), [0x87] = X86_OP_ENTRY2(XCHG, E,v, G,v, xchg), - [0x90] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x90] = X86_OP_GROUP0(90), [0x91] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), [0x92] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), [0x93] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 2e94e8ec56f..f90f3d3c589 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -2350,6 +2350,14 @@ static void gen_PANDN(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) decode->op[1].offset, vec_len, vec_len); } +static void gen_PAUSE(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) +{ + gen_update_cc_op(s); + gen_update_eip_next(s); + gen_helper_pause(tcg_env); + s->base.is_jmp = DISAS_NORETURN; +} + static void gen_PCMPESTRI(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { TCGv_i32 imm = tcg_constant8u_i32(decode->immediate); @@ -4014,18 +4022,6 @@ static void gen_WAIT(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) static void gen_XCHG(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { - if (decode->b == 0x90 && !REX_B(s)) { - if (s->prefix & PREFIX_REPZ) { - gen_update_cc_op(s); - gen_update_eip_cur(s); - gen_helper_pause(tcg_env, cur_insn_len_i32(s)); - s->base.is_jmp = DISAS_NORETURN; - } - /* No writeback. */ - decode->op[0].unit = X86_OP_SKIP; - return; - } - if (s->prefix & PREFIX_LOCK) { tcg_gen_atomic_xchg_tl(s->T0, s->A0, s->T1, s->mem_index, decode->op[0].ot | MO_LE); From patchwork Tue Jun 4 07:18:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8DE8C25B7E for ; Tue, 4 Jun 2024 07:19:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORg-0003Cd-1H; Tue, 04 Jun 2024 03:19:00 -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 1sEORe-0003CC-Nx for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORd-0005dG-8D for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:18:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485536; 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=Omj7V/9neG3Skvv8V7gZhHDNOP50DtvEDEa1OSvAS0I=; b=A0mjk/L1SvU4vLUkmMoQz6nlPNSiOt0W2xQ1rP9NEotSJJQs21EJihrk/Nf+iyOmvzcd1g p65+dBr0MjrNFSFpSetzIsYrfV1n8unjmPP/UR7yDd8IHvLZNUBY7e25JjlnXhhztRPbgV 1jk6OUkWfJw/CqOhMMuOfNymjguZNDc= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-JkrlGbTJOJ2yd_9XeoYcOQ-1; Tue, 04 Jun 2024 03:18:55 -0400 X-MC-Unique: JkrlGbTJOJ2yd_9XeoYcOQ-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-57a49b8a27eso280391a12.0 for ; Tue, 04 Jun 2024 00:18:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485533; x=1718090333; 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=Omj7V/9neG3Skvv8V7gZhHDNOP50DtvEDEa1OSvAS0I=; b=wCw5DjyC6l6rz/1xc4yjaSnFRZvIxef7obpgjOZQnIYZtuvqlBGH3X+IxKa3TooGhq 7J+VyZ1/bXVUmXnKQXnJwiDlSr+7JcbGVylXW1JTDbYWLvJSr+eO/dd5dtMKgZ/Qcj9p y3Ie27X6PsxtNPJ3IfzcJFExKKY1O0cO3UGRw9iv96cbjsAoVXT1Jsddpq6AbgW0+AR9 Yo8+V8anvyA4vRcBUhmGmPaMTrvKizUsS0MaF++sR6Q78suIYtNPzr1XHqKa9cIBcmy6 qYlGNgapoZPL7/hbk2MNyg3DHUzA4RhwPQZc4Uk1ls3Z2NMYrQR1J8u1xQY99irO+qC6 gIdg== X-Gm-Message-State: AOJu0Yy3G2v8TKbExa4IqMt279CJdimCjrKOweFp/uKwe3+Y5vtnLVdC TQ3ZY52V/6ozrV+yaP+NzXTY8JXrNdYGO10xOxz5y4f9Vzd80nYPJfCfan8hZRlwuV9bZdOb0KU SEB6rej6X1o0ezdmIf4G1A2wUKL8hiGhtbs/dxKxgztMjuxl09ZUJQeF9i5oSSD0pEhSy6PWIlx UzS3T3uIoNJTA2+/2wRG+7gnq8I/3aZt3NMMKm X-Received: by 2002:a50:f61a:0:b0:57a:21ac:cffb with SMTP id 4fb4d7f45d1cf-57a363c0b25mr6727881a12.6.1717485533094; Tue, 04 Jun 2024 00:18:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCezG3hGaTMkTnK57x1SObQ44iKILGwexCJljPWHBvebFJP7okSozYhSVbwBCwbI5SKYGCOA== X-Received: by 2002:a50:f61a:0:b0:57a:21ac:cffb with SMTP id 4fb4d7f45d1cf-57a363c0b25mr6727865a12.6.1717485532602; Tue, 04 Jun 2024 00:18:52 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a31c6d301sm6731711a12.76.2024.06.04.00.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 05/11] target/i386: implement DR7.GD Date: Tue, 4 Jun 2024 09:18:27 +0200 Message-ID: <20240604071833.962574-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DR7.GD triggers a #DB exception on any access to debug registers. The GD bit is cleared so that the #DB handler itself can access the debug registers. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/sysemu/bpt_helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/i386/tcg/sysemu/bpt_helper.c b/target/i386/tcg/sysemu/bpt_helper.c index 4d96a48a3ca..c1d5fce250c 100644 --- a/target/i386/tcg/sysemu/bpt_helper.c +++ b/target/i386/tcg/sysemu/bpt_helper.c @@ -238,6 +238,12 @@ target_ulong helper_get_dr(CPUX86State *env, int reg) } } + if (env->dr[7] & DR7_GD) { + env->dr[7] &= ~DR7_GD; + env->dr[6] |= DR6_BD; + raise_exception_ra(env, EXCP01_DB, GETPC()); + } + return env->dr[reg]; } @@ -251,6 +257,12 @@ void helper_set_dr(CPUX86State *env, int reg, target_ulong t0) } } + if (env->dr[7] & DR7_GD) { + env->dr[7] &= ~DR7_GD; + env->dr[6] |= DR6_BD; + raise_exception_ra(env, EXCP01_DB, GETPC()); + } + if (reg < 4) { if (hw_breakpoint_enabled(env->dr[7], reg) && hw_breakpoint_type(env->dr[7], reg) != DR7_TYPE_IO_RW) { From patchwork Tue Jun 4 07:18:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C341EC25B7E for ; Tue, 4 Jun 2024 07:19:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORk-0003GG-Hp; Tue, 04 Jun 2024 03:19:04 -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 1sEORj-0003Fu-93 for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORh-0005dt-Kq for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485541; 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=aHLLmdM1T47s1VBxMQynaNLfQGaY0mg7XaNcdIi3/jE=; b=efhTdAymb0TMMJdPeZtGRQRnPIdBGScx3IHZcNQVsKb2WFVuHM0Xhfi/EduHp52ySEYotD Ud/GzcmqpBhfmIRYdIr/Pe2ObePXikCIz6XghyPeVWme5toRgQl5wu9o8XIfYRJCZUIDss VQqW0+bFAWMoo2edMatNX3x4FprrGG4= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-JmLhD4cwN9aHzLJtN2dPKw-1; Tue, 04 Jun 2024 03:18:58 -0400 X-MC-Unique: JmLhD4cwN9aHzLJtN2dPKw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a68e0faf1f6so91954566b.3 for ; Tue, 04 Jun 2024 00:18:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485536; x=1718090336; 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=aHLLmdM1T47s1VBxMQynaNLfQGaY0mg7XaNcdIi3/jE=; b=GidKJJWEnP32gxLclhF9ClCy1+lbDNGdE1zU+UHU6kz4VJfHEAsFySFT3OqaDlowQw qofOvh6zf2Wo1FGmzXaIytJO+DXMgrC44CyHonc5YUm/cWwv3alPlffnRPBrugRvfAZj cHs9cutqi7ENOtWVkCo5Y7yu1J4My72+nrNty/mAeQyEIKoNIq0tj3B8hqJrm0kWN1MM SeErNbAYETOJDgN+dOVyP7L+MJNuMQRgOYwbLiwfd0SUjNAArrDm6A9fNDVwUXXz2j5b VfaP6Fje3bKyeuSsJXrJhm9L5eutHopaYHoo3+hqvgnLyXhY5jD+/rweVe3K0VA17s+7 oWPA== X-Gm-Message-State: AOJu0Yxk3S4hO5n5AFa27r2iJl7cJq0XO5+sPQGsMkWS7skoZOM68oLU DT2sYy4hB4OFuWH2/Nw5U9eGu+wuYrEJjYvOhNlMKdA9VOtd4MTeU0+C+2ae1yOxfd6EZkoYQJi mkSzYuRuE5OF92GKPl0L7gxpMcOFDb4Jl4ACYCXDUtB+LJ+q3oYbJuS9gDxnA21HzvdxIi/2iBC 2v/NAowW24Azv3XCDFwmfNkk6zTG2ZsbImptyq X-Received: by 2002:a17:906:1314:b0:a68:f02d:755e with SMTP id a640c23a62f3a-a68f02d75ffmr367376266b.33.1717485536209; Tue, 04 Jun 2024 00:18:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEiDKlwyMKl0NsNRRK1YIeDVRXuTckOHGSViOkixZOCxkXtftRfzpQTqPq38EA02n+X/FiQ3A== X-Received: by 2002:a17:906:1314:b0:a68:f02d:755e with SMTP id a640c23a62f3a-a68f02d75ffmr367374766b.33.1717485535681; Tue, 04 Jun 2024 00:18:55 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68c7892dd5sm415290966b.43.2024.06.04.00.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 06/11] target/i386: disable/enable breakpoints on vmentry/vmexit Date: Tue, 4 Jun 2024 09:18:28 +0200 Message-ID: <20240604071833.962574-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org If the required DR7 (either from the VMCB or from the host save area) disables a breakpoint that was enabled prior to vmentry or vmexit, it is left enabled and will trigger EXCP_DEBUG. This causes a spurious #DB on the next crossing of the breakpoint. To disable it, vmentry/vmexit must use cpu_x86_update_dr7 to load DR7. Because cpu_x86_update_dr7 takes a 32-bit argument, check reserved bits prior to calling cpu_x86_update_dr7, and do the same for DR6 as well for consistency. This scenario is tested by the "host_rflags" test in kvm-unit-tests. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/sysemu/svm_helper.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/svm_helper.c index 5d6de2294fa..922d8964f8e 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -163,6 +163,8 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) uint64_t new_cr0; uint64_t new_cr3; uint64_t new_cr4; + uint64_t new_dr6; + uint64_t new_dr7; if (aflag == 2) { addr = env->regs[R_EAX]; @@ -361,20 +363,22 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) env->vm_vmcb + offsetof(struct vmcb, save.rsp)); env->regs[R_EAX] = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.rax)); - env->dr[7] = x86_ldq_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, save.dr7)); - env->dr[6] = x86_ldq_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, save.dr6)); + + new_dr7 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.dr7)); + new_dr6 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.dr6)); #ifdef TARGET_X86_64 - if (env->dr[6] & DR_RESERVED_MASK) { + if (new_dr7 & DR_RESERVED_MASK) { cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); } - if (env->dr[7] & DR_RESERVED_MASK) { + if (new_dr6 & DR_RESERVED_MASK) { cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); } #endif + cpu_x86_update_dr7(env, new_dr7); + env->dr[6] = new_dr6; + if (is_efer_invalid_state(env)) { cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); } @@ -864,8 +868,11 @@ void do_vmexit(CPUX86State *env) env->dr[6] = x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, save.dr6)); - env->dr[7] = x86_ldq_phys(cs, - env->vm_hsave + offsetof(struct vmcb, save.dr7)); + + /* Disables all breakpoints in the host DR7 register. */ + cpu_x86_update_dr7(env, + x86_ldq_phys(cs, + env->vm_hsave + offsetof(struct vmcb, save.dr7)) & ~0xff); /* other setups */ x86_stl_phys(cs, @@ -891,8 +898,6 @@ void do_vmexit(CPUX86State *env) from the page table indicated the host's CR3. If the PDPEs contain illegal state, the processor causes a shutdown. */ - /* Disables all breakpoints in the host DR7 register. */ - /* Checks the reloaded host state for consistency. */ /* If the host's rIP reloaded by #VMEXIT is outside the limit of the From patchwork Tue Jun 4 07:18:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CCC2C27C52 for ; Tue, 4 Jun 2024 07:19:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORp-0003JG-UV; Tue, 04 Jun 2024 03:19:10 -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 1sEORo-0003Ii-54 for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORm-0005e8-Ec for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485545; 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=jd1l2qesW2ZIZOnZQq5rLZIMm8vL0i3PnwLlc9wF0HE=; b=aZGB/hjyP+6ZeapqcoLTRbLarwWO9j9lF9j4QIsHeC+pNNc4vxCLgli/VNr3JxKoGKePNo Y+Cr/cd7xLRaXo74ptJidhTYWV7TYKxzkntV169PlEizcTRnKH3uk0DZz1HTHcFw8mWwlJ F/F+ApIXUT+c8XERQV34Kg3OIlYbHY0= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-qKODYWeuMCy_Ew_yBHChpQ-1; Tue, 04 Jun 2024 03:19:01 -0400 X-MC-Unique: qKODYWeuMCy_Ew_yBHChpQ-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a4d24a479so625961a12.2 for ; Tue, 04 Jun 2024 00:19:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485539; x=1718090339; 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=jd1l2qesW2ZIZOnZQq5rLZIMm8vL0i3PnwLlc9wF0HE=; b=Wl0fiimJ7ObZW9rZ1zCZsxRWQZC6LFGSOZWX/2lUCaMmmwHgTLNsQ2KaRIy8wDodRj Nfsxbyv5akaI/qBfRVSUYc1ord5wL+iC0bDSGVZZQQO5o/aCSyF5liMOAwDKqZgLN1aW VHLz+U8yTbm/Zb1fgkLe8tJqUtUz9/wjOQkQTAP69Ctka+1im9HHkFCS3JtmWeLukLjd FrzwiDaiuzM3m3ib5IxmQcXEWjHjav8210ZtVksdZvFFgjaZZlzfUk/hv6hEPJRTr3HK UepM6ZtmEHlkzd2RgHSVqnJRB9Geu/IIcJkSvKEnSNfUVilq84o8R9EtMbZU8c1OucX6 SjbA== X-Gm-Message-State: AOJu0YxPdBoWBjqYZviLdqS+Geomzp8tEdY/s3wSswdii9JOs9LJH3Ey RnOl7pPJSrmHtRxiY6aCKi9MuVfV3akaitYqhhgt4wfPWO0/290frJGvFD5ZsQGc9Ajqt2neeWc DAXXoQ9Fos0p95OTcor7aHATof4npnjYvzHduLfegUuJJOdOlz0S/g/Gw8fY7riraI9OcADgXOd yGoj7YGUaUJMIqM11XEwr+NUSrpwYZwKYpfoWv X-Received: by 2002:a50:9b19:0:b0:56e:238e:372c with SMTP id 4fb4d7f45d1cf-57a3653a3d7mr6317057a12.26.1717485539453; Tue, 04 Jun 2024 00:18:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEO0u2buUys//GDCQkPASoTC85cdAxlXiBbEDw9TLP/QXn/YYBULWdqRoYv2d33dS4yPgCfKw== X-Received: by 2002:a50:9b19:0:b0:56e:238e:372c with SMTP id 4fb4d7f45d1cf-57a3653a3d7mr6317043a12.26.1717485538985; Tue, 04 Jun 2024 00:18:58 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a81f1dbd9sm633269a12.93.2024.06.04.00.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:18:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 07/11] target/i386: fix INHIBIT_IRQ/TF/RF handling for VMRUN Date: Tue, 4 Jun 2024 09:18:29 +0200 Message-ID: <20240604071833.962574-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From vm entry to exit, VMRUN is handled as a single instruction. It uses DISAS_NORETURN in order to avoid processing TF or RF before the first instruction executes in the guest. However, the corresponding handling is missing in vmexit. Add it, and at the same time reorganize the comments with quotes from the manual about the tasks performed by a #VMEXIT. Another gen_eob() task that is missing in VMRUN is preparing the HF_INHIBIT_IRQ flag for the next instruction, in this case by loading it from the VMCB control state. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/sysemu/svm_helper.c | 46 +++++++++++++++++++++-------- target/i386/tcg/translate.c | 5 ++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/svm_helper.c index 922d8964f8e..9db8ad62a01 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -254,6 +254,13 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) control.intercept_exceptions )); + env->hflags &= ~HF_INHIBIT_IRQ_MASK; + if (x86_ldl_phys(cs, env->vm_vmcb + + offsetof(struct vmcb, control.int_state)) & + SVM_INTERRUPT_SHADOW_MASK) { + env->hflags |= HF_INHIBIT_IRQ_MASK; + } + nested_ctl = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.nested_ctl)); asid = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, @@ -815,8 +822,12 @@ void do_vmexit(CPUX86State *env) env->hflags &= ~HF_GUEST_MASK; env->intercept = 0; env->intercept_exceptions = 0; + + /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ cs->interrupt_request &= ~CPU_INTERRUPT_VIRQ; env->int_ctl = 0; + + /* Clears the TSC_OFFSET inside the processor. */ env->tsc_offset = 0; env->gdt.base = x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, @@ -836,6 +847,15 @@ void do_vmexit(CPUX86State *env) cpu_x86_update_cr4(env, x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, save.cr4))); + + /* + * Resets the current ASID register to zero (host ASID; TLB flush). + * + * If the host is in PAE mode, the processor reloads the host's PDPEs + * from the page table indicated the host's CR3. FIXME: If the PDPEs + * contain illegal state, the processor causes a shutdown (QEMU does + * not implement PDPTRs). + */ cpu_x86_update_cr3(env, x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, save.cr3))); @@ -843,12 +863,14 @@ void do_vmexit(CPUX86State *env) set properly */ cpu_load_efer(env, x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, save.efer))); + + /* Completion of the VMRUN instruction clears the host EFLAGS.RF bit. */ env->eflags = 0; cpu_load_eflags(env, x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, save.rflags)), ~(CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C | DF_MASK | - VM_MASK)); + RF_MASK | VM_MASK)); svm_load_seg_cache(env, MMU_PHYS_IDX, env->vm_hsave + offsetof(struct vmcb, save.es), R_ES); @@ -888,19 +910,17 @@ void do_vmexit(CPUX86State *env) env->hflags2 &= ~HF2_GIF_MASK; env->hflags2 &= ~HF2_VGIF_MASK; - /* FIXME: Resets the current ASID register to zero (host ASID). */ - /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ - /* Clears the TSC_OFFSET inside the processor. */ + /* FIXME: Checks the reloaded host state for consistency. */ - /* If the host is in PAE mode, the processor reloads the host's PDPEs - from the page table indicated the host's CR3. If the PDPEs contain - illegal state, the processor causes a shutdown. */ - - /* Checks the reloaded host state for consistency. */ - - /* If the host's rIP reloaded by #VMEXIT is outside the limit of the - host's code segment or non-canonical (in the case of long mode), a - #GP fault is delivered inside the host. */ + /* + * EFLAGS.TF causes a #DB trap after the VMRUN completes on the host + * side (i.e., after the #VMEXIT from the guest). Since we're running + * in the main loop, call do_interrupt_all directly. + */ + if ((env->eflags & TF_MASK) != 0) { + env->dr[6] |= DR6_BS; + do_interrupt_all(X86_CPU(cs), EXCP01_DB, 0, 0, env->eip, 0); + } } diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 77ed9c1db47..a9c6424c7df 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -3745,6 +3745,11 @@ static void disas_insn_old(DisasContext *s, CPUState *cpu, int b) } gen_update_cc_op(s); gen_update_eip_cur(s); + /* + * Reloads INHIBIT_IRQ mask as well as TF and RF with guest state. + * The usual gen_eob() handling is performed on vmexit after + * host state is reloaded. + */ gen_helper_vmrun(tcg_env, tcg_constant_i32(s->aflag - 1), cur_insn_len_i32(s)); tcg_gen_exit_tb(NULL, 0); From patchwork Tue Jun 4 07:18:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8782DC25B7E for ; Tue, 4 Jun 2024 07:21:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORx-0003Tz-7y; Tue, 04 Jun 2024 03:19: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 1sEORs-0003Jn-AL for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:12 -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 1sEORq-0005ed-Tf for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485550; 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=7QRT7KodLZb3R6daWVQofmOuNLtzn1249htY3GzAkRw=; b=CMYvL3kH736vf2LqhENjLcck/BvwaFLixNiBOd3o26AWEKtMVlCnF4pBS48eMkokpEaltp YtXaiHtFyXqVD9xHDF8hihiCUIZOCu5ab25hWvdi7oBbZxghBy86zaQSuuSoDm0aG9WqnK lMfIaaP3HhJLp/thrNNZi96O5hTVa6o= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-367-O9t0rNKEPI2U-nDgKXyVGg-1; Tue, 04 Jun 2024 03:19:03 -0400 X-MC-Unique: O9t0rNKEPI2U-nDgKXyVGg-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5785176c796so2529924a12.3 for ; Tue, 04 Jun 2024 00:19:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485541; x=1718090341; 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=7QRT7KodLZb3R6daWVQofmOuNLtzn1249htY3GzAkRw=; b=DcVYmMUDds0viAnRdk7ILq6qhtDn0CSZUi18cGgcIf5RwFP1Nk0S6VJurNDZ1puYzj iLIWq5mkvUNFYmHOxuqREqcGPz2Uz/eJr+0OsSa+aoqbVqfXNYeA9VhRiCHfoLwYwPfk Xm+3QHG7dcw5/Od+l4gumaJZJiS28aBHqnbkRitHn6HOwCwUvlRFBrJwbpYRC0yBI2F4 2RnY6T7MiELs6t6jj0qj9fqz+WVjwGA38Jmfut24XgM6fB1bG+xpmH1BxNAwUPkdhIGy lADYrpqVfuK9NSm8b9VNQZccO4JWLDyDw0rImlKLBytFXRjgZGDM5KgSni0n/DnK1Jxu CNzg== X-Gm-Message-State: AOJu0YwblkOMbkvNRGr0+UVMhBxrQRP6SHqbYu8bvlX2CODR8VHBdMMW yMH23fdRX8DbxyP9Wbs2AR2m9uTsmZzh+WWptVzatq3upiqiOSMg2kkNw1yMofaMf9PzVqPQxts zT3nEVRlHgdAVyivAhxlAwuBv5QFpKwKW5hJ6DODziq72Xs6Pbbxqjv7K4nDFl+S1th4Bbs/+Go Gbalvp6xw2zWCCEuGd9iUDNSYahTjINXvhFvp9 X-Received: by 2002:a50:bac4:0:b0:57a:4af2:fcf5 with SMTP id 4fb4d7f45d1cf-57a4af301e7mr5552127a12.2.1717485541844; Tue, 04 Jun 2024 00:19:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhle3APIdal4Bk/OucXEarJ/czXHdsdM6YxIQkHqBU3g2Eie1cm8u0xHfzyTcpyo9qYd2Whw== X-Received: by 2002:a50:bac4:0:b0:57a:4af2:fcf5 with SMTP id 4fb4d7f45d1cf-57a4af301e7mr5552115a12.2.1717485541494; Tue, 04 Jun 2024 00:19:01 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a31c9c0b8sm6920580a12.86.2024.06.04.00.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:19:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 08/11] target/i386: fix INHIBIT_IRQ/TF/RF handling for PAUSE Date: Tue, 4 Jun 2024 09:18:30 +0200 Message-ID: <20240604071833.962574-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org PAUSE uses DISAS_NORETURN because the corresponding helper calls cpu_loop_exit(). However, while HLT clear HF_INHIBIT_IRQ_MASK to correctly handle "STI; HLT", the same is missing from PAUSE. And also gen_eob() clears HF_RF_MASK and synthesizes a #DB exception if single-step is active; none of this is done by HLT and PAUSE. Start fixing PAUSE, HLT will follow. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/misc_helper.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/tcg/misc_helper.c b/target/i386/tcg/misc_helper.c index 8316d42ffcd..ed4cda8001e 100644 --- a/target/i386/tcg/misc_helper.c +++ b/target/i386/tcg/misc_helper.c @@ -92,6 +92,10 @@ G_NORETURN void helper_pause(CPUX86State *env) { CPUState *cs = env_cpu(env); + /* Do gen_eob() tasks before going back to the main loop. */ + do_end_instruction(env); + helper_rechecking_single_step(env); + /* Just let another CPU run. */ cs->exception_index = EXCP_INTERRUPT; cpu_loop_exit(cs); From patchwork Tue Jun 4 07:18:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE5BBC27C52 for ; Tue, 4 Jun 2024 07:20:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORu-0003Nn-2T; Tue, 04 Jun 2024 03:19:14 -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 1sEORs-0003Jv-Hl for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:12 -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 1sEORq-0005ea-Lh for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485549; 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=JE1l3mnnViu2bSu14FqFVuNS+di8GAj9jPlWPGLObPQ=; b=Dx9CgANCQrw0FWlcDdPVHm3+zjno0Feq6tKAHzMqVEvFFR2cGcAPGNV8ZT7/P2x0VJn5Q9 ka9jb47eHbbRy/zvT0LPeMOp1XTvJ8lElWXswdG03nRPSxxnQ/jQAePyv7E5QhX8ORgkwm ExyriNwBESsXwHtwHQwySg7kvTLSEi4= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-473-4pccu4QMO96Lu7Bxg9Zc6w-1; Tue, 04 Jun 2024 03:19:07 -0400 X-MC-Unique: 4pccu4QMO96Lu7Bxg9Zc6w-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a6905050583so98639466b.0 for ; Tue, 04 Jun 2024 00:19:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485545; x=1718090345; 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=JE1l3mnnViu2bSu14FqFVuNS+di8GAj9jPlWPGLObPQ=; b=jDvhN5Vkbqxa++MX8vyZ/hIn5ns9wHEybG8sfC3V14R+D4Ei/kNJfWfHpPggZ7CG3O Q7Iy1bLMLd8GaNBlN78LHmUjBPBWNUx4jXtfoRKsx39favC5gHJ0JSbkvIzMsBe5DQsl EuAubcAYTYKqWLNSbHlXqMt9Sg5yD4hsLmtXd2jo9AgksBlqw3k0+CFgn67ZkEuXb2ht GRRJci+Qx71PUKeJ2bbkrfKFEoHqZi5OQN4kPpyQQFJf5xGSaobFRRQQCX4RyNNiX1C7 ylU4NmCCy1sO6obI7qkJG2xmeaZXBqpAMD8ikIctKggyGwOLYGgx5MU3PgGVLhYvRp4S JO8g== X-Gm-Message-State: AOJu0Yw1g0mS7LhJ2lUHA2tX3nDzmcRfaWrSfl5WPruQESVMILsF63jU oMi4Y8eYu/yl5O9rDTjv/RFgNY2HfX4lVxOKcLcnhC+60PPeUBuBlpCsi3MyNkk0AAHkdqbSip0 ATlNrh4/y6Tc3pQ2KebCXdpSxadrLmfBoj2kT2vIGjKxcWRnO3bX2kCK054l37akJK6YYP7JfuK 90ywz81jl6MdSplm6jp3cvaLIh+7RIXs2ZY8zt X-Received: by 2002:a17:907:86ab:b0:a68:e6a5:b3ea with SMTP id a640c23a62f3a-a68e6a5b62emr482088466b.5.1717485545486; Tue, 04 Jun 2024 00:19:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENzK6nQS1tseB7U+OjQCdrGXaLXdU4IzYUBYvuiHaq08HZ1dNBP2xLwrAvziQzb4BvIRSaag== X-Received: by 2002:a17:907:86ab:b0:a68:e6a5:b3ea with SMTP id a640c23a62f3a-a68e6a5b62emr482086566b.5.1717485545075; Tue, 04 Jun 2024 00:19:05 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68f10450besm342684566b.35.2024.06.04.00.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:19:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 09/11] target/i386: fix TF/RF handling for HLT Date: Tue, 4 Jun 2024 09:18:31 +0200 Message-ID: <20240604071833.962574-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org HLT uses DISAS_NORETURN because the corresponding helper calls cpu_loop_exit(). However, while gen_eob() clears HF_RF_MASK and synthesizes a #DB exception if single-step is active, none of this is done by HLT. Note that the single-step trap is generated after the halt is finished. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/seg_helper.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/misc_helper.c index 093cc2d0f90..7fa0c5a06de 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -520,7 +520,7 @@ G_NORETURN void helper_hlt(CPUX86State *env) { CPUState *cs = env_cpu(env); - env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */ + do_end_instruction(env); cs->halted = 1; cs->exception_index = EXCP_HLT; cpu_loop_exit(cs); diff --git a/target/i386/tcg/sysemu/seg_helper.c b/target/i386/tcg/sysemu/seg_helper.c index 9ba94deb3aa..05174a79e73 100644 --- a/target/i386/tcg/sysemu/seg_helper.c +++ b/target/i386/tcg/sysemu/seg_helper.c @@ -130,15 +130,26 @@ void x86_cpu_do_interrupt(CPUState *cs) bool x86_cpu_exec_halt(CPUState *cpu) { - if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { - X86CPU *x86_cpu = X86_CPU(cpu); + X86CPU *x86_cpu = X86_CPU(cpu); + CPUX86State *env = &x86_cpu->env; + if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { bql_lock(); apic_poll_irq(x86_cpu->apic_state); cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL); bql_unlock(); } - return cpu_has_work(cpu); + + if (!cpu_has_work(cpu)) { + return false; + } + + /* Complete HLT instruction. */ + if (env->eflags & TF_MASK) { + env->dr[6] |= DR6_BS; + do_interrupt_all(x86_cpu, EXCP01_DB, 0, 0, env->eip, 0); + } + return true; } bool x86_need_replay_interrupt(int interrupt_request) From patchwork Tue Jun 4 07:18:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0EE47C25B7E for ; Tue, 4 Jun 2024 07:21:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORx-0003UC-CG; Tue, 04 Jun 2024 03:19: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 1sEORw-0003SA-32 for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEORu-0005f7-DU for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485553; 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=rCpaT2bnUFA6x8rHRoclpeCn7PmIy3X6pqFoqtygESw=; b=Del/ih8iKfEPiq9DfG6xRow8KN2FUaJTdY3VFyQ/YBaniQPZY/1YBfQqTDPKUkJgwXtkIR CEnfNzwWjE8d/gqG9hGA5gcaHkA5QSAJ7DwoAOguU+mcBdZnIueJ5CocBr1gEb4ES1GYDg O2OcBpV+vTFwGMm6+7SUfrVGkPOawKI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-PTHoBow0Ot-vOrveUVg6iw-1; Tue, 04 Jun 2024 03:19:10 -0400 X-MC-Unique: PTHoBow0Ot-vOrveUVg6iw-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a68ce1ac733so131341166b.3 for ; Tue, 04 Jun 2024 00:19:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485548; x=1718090348; 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=rCpaT2bnUFA6x8rHRoclpeCn7PmIy3X6pqFoqtygESw=; b=rjrG40Mo9xtdhVzkjgRoQOTPjKC0zNVSEfRrvAGjxpip8/dcFvxUKALZ/NYp25G1bg spE2dQjXGOK75rvn3J0fE0W2dF42PqMqYKWUpOyWql4ux4n/vmwcdBo9/Vq1frvi9ANT OrIQGorzh+sE2ugwhiPq0fQ9jgHbT2OJjJbZaobbQ9GSjHNEsHJV2jUPjYJhAJaQpYtu s8esD73409VsphxbJyUg/DUVuE1LE3ucTwAMPZ6FeY0FsalMmzHIk5iXBY5P7b2n3IWv /T06vgdkWwVZc+mh3GbeaAcpB7sXXerCK/9iYqkge+tJd6R4pDH6sYsQ86nV45anCXNU C0YA== X-Gm-Message-State: AOJu0YwUbX1DzpsbhHUF4J6jb2Mxx03pdFvT+E5JQusUxQJjiyObvNIt sREW0f41YcJQdprnMiz/0flSUbuiU8zfn94rUb9lQEBTZxhbXBaQzuEp/QupaiUWD1SFeFegxVm WR3aPkfG5qX1iS+oT7XGvq+xUmlX6Z/ReoIR1aBzNEo1RD1tT//bZI01YpodlFJIJEDGdGic69N 9fi3DFszzUmF2HUup2fcwyN9pEzRPxdLdEwEkt X-Received: by 2002:a17:906:fcb5:b0:a68:bd86:bc7c with SMTP id a640c23a62f3a-a68bd86c3b9mr478160566b.14.1717485548596; Tue, 04 Jun 2024 00:19:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVZEq2jBNSX29dg7vxQjGg9fkdmXnO5CcO2BShBZ9Q0fIGKQVQuQNa70xvmHDXWBbIrAhKjg== X-Received: by 2002:a17:906:fcb5:b0:a68:bd86:bc7c with SMTP id a640c23a62f3a-a68bd86c3b9mr478159266b.14.1717485548208; Tue, 04 Jun 2024 00:19:08 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a690f020b9bsm246164066b.140.2024.06.04.00.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:19:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 10/11] target/i386: document incorrect semantics of watchpoint following MOV/POP SS Date: Tue, 4 Jun 2024 09:18:32 +0200 Message-ID: <20240604071833.962574-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini Acked-by: Richard Henderson --- target/i386/tcg/sysemu/bpt_helper.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/tcg/sysemu/bpt_helper.c b/target/i386/tcg/sysemu/bpt_helper.c index c1d5fce250c..b29acf41c38 100644 --- a/target/i386/tcg/sysemu/bpt_helper.c +++ b/target/i386/tcg/sysemu/bpt_helper.c @@ -215,6 +215,12 @@ void breakpoint_handler(CPUState *cs) if (cs->watchpoint_hit->flags & BP_CPU) { cs->watchpoint_hit = NULL; if (check_hw_breakpoints(env, false)) { + /* + * FIXME: #DB should be delayed by one instruction if + * INHIBIT_IRQ is set (STI cannot trigger a watchpoint). + * The delayed #DB should also fuse with one generated + * by ICEBP (aka INT1). + */ raise_exception(env, EXCP01_DB); } else { cpu_loop_exit_noexc(cs); From patchwork Tue Jun 4 07:18:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13684811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32DA9C27C54 for ; Tue, 4 Jun 2024 07:19:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEORy-0003Uw-TN; Tue, 04 Jun 2024 03:19: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 1sEORx-0003UF-Dt for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:17 -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 1sEORv-0005fD-4S for qemu-devel@nongnu.org; Tue, 04 Jun 2024 03:19:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717485554; 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=hmcO4ui07BBe0FjQAMjYfYJsiVn0613DcSvAYmLll7I=; b=MRakWEHPV3LNTeajKE6B4eiSGxZL9NB8o3+N4mC6g8GIU4WcigshvyXe4PhU8WSpyPe0Oa BER9AYZwZqERvFXbwpsaV/bVWqrF7ZEksaEIJZ2EhCmSi0wabslYux8GkYDcB2fynJdaJ4 MFfkTs/1PtkZlaHx/gsWRMKjyogFNdA= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-FNWUItZzN92CUqg5shIWUw-1; Tue, 04 Jun 2024 03:19:12 -0400 X-MC-Unique: FNWUItZzN92CUqg5shIWUw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57a280de2d2so959023a12.2 for ; Tue, 04 Jun 2024 00:19:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485551; x=1718090351; 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=hmcO4ui07BBe0FjQAMjYfYJsiVn0613DcSvAYmLll7I=; b=PeuWuRlgZSae7oHxMugPjJe0RQIBTQ9TcqSnU5DnDY9hvYibVJGLl4rxS3xQbswXoH HVO2k41kiJ1/GLYmTnsQQBNV534LbFUJHVSLnSEbJ+Ge2qGefV1aHgifzYCaIzUl5D4P UdOXX4T8TGZpbye7gq7uG6DM7Gr3sySeEvgarh7zA1xxdwSd8vn6/mMc/0pB30U1OIzU 3YeVlEljRDdiBcgtCKYzzMQLgRqwcFfJLEQFNjPPGx4/0DI0AiM/TJD1UHiwE/LQ84Mm AzpXhUtP/p/+6z+BN/emzqC0LPUhipiprSp9RYJF0HRc32wGjl7jVowJKBP04AZ7wlSu MbDA== X-Gm-Message-State: AOJu0YxiMRBzBGHRgX7mziTiLp2p814XIxHBVPB9RPfTSrQE33PraqUI /5BTB6HEDOpZFH3oWPoAaTR5+MF+nVhkgQXVkWKKSetUiEZPhfczdGsBQVrWgCtvZ6WNXWW3WsJ jogQaIG2GWyiaDKfpBYJ8W3oJcb2m+OUbZr5girob62+3CHEBoileBIXOgJY699p2zaYosvW01M JVKUVbZpHBw36sziTV4CRmHeCYUYpPCCFW6Lmd X-Received: by 2002:a50:a455:0:b0:578:649c:f7f0 with SMTP id 4fb4d7f45d1cf-57a361ad344mr9758312a12.0.1717485550915; Tue, 04 Jun 2024 00:19:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYb4sk77q6MLomxoIGFTwZAm3Y2EODdLD3YlFoe+WcxlIYFBaiI27cGyOsjYacJpJCkuql7A== X-Received: by 2002:a50:a455:0:b0:578:649c:f7f0 with SMTP id 4fb4d7f45d1cf-57a361ad344mr9758296a12.0.1717485550556; Tue, 04 Jun 2024 00:19:10 -0700 (PDT) Received: from avogadro.local ([151.81.115.112]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a31bb841fsm6900380a12.34.2024.06.04.00.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:19:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 11/11] target/i386: document use of DISAS_NORETURN Date: Tue, 4 Jun 2024 09:18:33 +0200 Message-ID: <20240604071833.962574-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604071833.962574-1-pbonzini@redhat.com> References: <20240604071833.962574-1-pbonzini@redhat.com> MIME-Version: 1.0 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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.001, RCVD_IN_MSPIKE_WL=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DISAS_NORETURN suppresses the work normally done by gen_eob(), and therefore must be used in special cases only. Document them. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index a9c6424c7df..2b6f67be40b 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -4761,6 +4761,17 @@ static void i386_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) switch (dc->base.is_jmp) { case DISAS_NORETURN: + /* + * Most instructions should not use DISAS_NORETURN, as that suppresses + * the handling of hflags normally done by gen_eob(). We can + * get here: + * - for exception and interrupts + * - for jump optimization (which is disabled by INHIBIT_IRQ/RF/TF) + * - for VMRUN because RF/TF handling for the host is done after vmexit, + * and INHIBIT_IRQ is loaded from the VMCB + * - for HLT/PAUSE/MWAIT to exit the main loop with specific EXCP_* values; + * the helpers handle themselves the tasks normally done by gen_eob(). + */ break; case DISAS_TOO_MANY: gen_update_cc_op(dc);