From nobody Mon Nov 25 04:55:26 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=1717485583; cv=none; d=zohomail.com; s=zohoarc; b=VxFjv/7GL4t48Kymi63YAV4hcCkMeMa6GYYx1tyqqAvLht2ph6foaZ+LJpKHU+1YdNjSUy9ykutYmw1mBkkTD6yxFDj40mqOEsI64Smv+tUn1l1U66kjhv99407JHBCMMbzDIv92WVqsGpe9LOO6/XhRmc+WpmNvLpv8u57+VFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485583; 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=kSWUo4sCXjrNOR0yu+FmZCYBkQr0GiAN238dsmBJ6yo=; b=K+BnyEM8WQcCMIt8jGLhuE1VvXfNCVchqS8ekA2tBKGEJ7GI0Lu/AUqyhbIcloim1XZ9DJ2VfPhw7cLZTJLZ5Aeig60ORg4smW/ilUhbdtqevQt2ZIV2GlTuQ88DbPw3VbLqMpN6pvAc+UvTo8yvFfLg8FRbxQKSsuWRWtDHDqg= 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 1717485583207684.658652637204; Tue, 4 Jun 2024 00:19:43 -0700 (PDT) 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 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 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a68f2d64342so15791466b.1 for ; Tue, 04 Jun 2024 00:18:42 -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) 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= X-MC-Unique: QlqoyUdePouWqsE8TZtvMQ-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485583661100005 Content-Type: text/plain; charset="utf-8" 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) } } =20 +static int exception_is_fault(int intno) +{ + switch (intno) { + /* + * #DB can be both fault- and trap-like, but it never sets RF=3D1 + * 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, in= t intno, int is_int, int type, dpl, selector, ss_dpl, cpl; int has_error_code, new_stack, shift; uint32_t e1, e2, offset, ss =3D 0, esp, ss_e1 =3D 0, ss_e2 =3D 0; - uint32_t old_eip, sp_mask; + uint32_t old_eip, sp_mask, eflags; int vm86 =3D env->eflags & VM_MASK; + bool set_rf; =20 has_error_code =3D 0; if (!is_int && !is_hw) { @@ -614,8 +633,10 @@ static void do_interrupt_protected(CPUX86State *env, i= nt intno, int is_int, } if (is_int) { old_eip =3D next_eip; + set_rf =3D false; } else { old_eip =3D env->eip; + set_rf =3D exception_is_fault(intno); } =20 dt =3D &env->idt; @@ -748,6 +769,15 @@ static void do_interrupt_protected(CPUX86State *env, i= nt intno, int is_int, } push_size <<=3D shift; #endif + eflags =3D cpu_compute_eflags(env); + /* + * AMD states that code breakpoint #DBs clear RF=3D0, Intel leaves it + * as is. AMD behavior could be implemented in check_hw_breakpoints(). + */ + if (set_rf) { + eflags |=3D RF_MASK; + } + if (shift =3D=3D 1) { if (new_stack) { if (vm86) { @@ -759,7 +789,7 @@ static void do_interrupt_protected(CPUX86State *env, in= t 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, in= t 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; =20 has_error_code =3D 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 =3D next_eip; + set_rf =3D false; } else { old_eip =3D env->eip; + set_rf =3D exception_is_fault(intno); } =20 dt =3D &env->idt; @@ -950,9 +983,15 @@ static void do_interrupt64(CPUX86State *env, int intno= , int is_int, } esp &=3D ~0xfLL; /* align stack */ =20 + /* See do_interrupt_protected. */ + eflags =3D cpu_compute_eflags(env); + if (set_rf) { + eflags |=3D 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(DisasContextB= ase *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 =3D !dc->jmp_opt && !(cflags & CF_USE_ICOUNT); =20 --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485694; cv=none; d=zohomail.com; s=zohoarc; b=bPAxNFWU/yg8ub7JCJwUywsI5CkYqR4GXVNnagiWqNYgyEq3aBTzKZhZE8rUPTxJOjWzhOhWpPutHI4cPzJ2eXgg6Q+zxvWemGbZTW2L+M/TTqnuSxXEZnfhXbSzTmS7pBOufMzyq1Kd/8p6rtfbB6+RGGcVJ2FdtJOXcTLYSf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485694; 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=U/nNXKv5w7XsoKaYFhzY0rSXugZeBuJcWZqnC83Ujh0=; b=jRhuGpYjkiVPZR8DRPKtNEO3pgaKLY0f6gHTXAd/MaHFzT3APjz2CTQ0fyJAP1Figu1yxhdddWxzxBWMZoLwVdni+JbRCcmvpg2O6JcNp+J3si2IcsVWP4mfht6+2Oos7/OjeAwt7vjBGFTq+PUY60rlQ3ufOBnf4xFmc6VAbgg= 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 1717485694088646.842225155216; Tue, 4 Jun 2024 00:21:34 -0700 (PDT) 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 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 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57a52be5f2aso831590a12.3 for ; Tue, 04 Jun 2024 00:18:46 -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) 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= X-MC-Unique: qqppHs-CNLiIai-j2BHHBg-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485695861100003 Content-Type: text/plain; charset="utf-8" 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, in= t) 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) =20 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); =20 /* bpt_helper.c */ +void do_end_instruction(CPUX86State *env); + +/* sysemu/bpt_helper.c */ bool check_hw_breakpoints(CPUX86State *env, bool force_dr6_update); =20 #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 &=3D ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before= */ + env->eflags &=3D ~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, i= nt exception_index, raise_interrupt2(env, exception_index, 0, 0, 0, retaddr); } =20 +G_NORETURN void helper_icebp(CPUX86State *env) +{ + CPUState *cs =3D 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 =3D EXCP01_DB; + env->error_code =3D 0; + env->exception_is_int =3D 0; + env->exception_next_eip =3D 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) } } =20 +static void gen_update_eip_next(DisasContext *s) +{ + assert(s->pc_save !=3D -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 =3D s->pc; +} + static void gen_update_eip_cur(DisasContext *s) { assert(s->pc_save !=3D -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 *en= v, X86DecodedInsn *decode) =20 static void gen_INT1(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { - gen_exception(s, EXCP01_DB); + gen_update_cc_op(s); + gen_update_eip_next(s); + gen_helper_icebp(tcg_env); + s->base.is_jmp =3D DISAS_NORETURN; } =20 static void gen_INT3(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485564; cv=none; d=zohomail.com; s=zohoarc; b=du+dV9sH6+e1NkjHrd4zQzXqtXRa5SOitK9bdO/JFU5A5nBptDQxjkzAQKh1QVJffv6+S0O+Oi7vVornYfHqgyHF2k7HDZr5vAUKRTL22rOjRNCRyyHEjuLuNC7Ba/AGLJFj5VDQBPnNA8PgIxOSh5NGcmx1GyYrsjG0jZ3M0IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485564; 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=3+poIGky4GSqhFlE6pkBG1pa6bXFWkqUUf8ylZXVgw0=; b=hr3hiNMFR4/TyBv+oF0yDj6GnFha32FJir1N66wo3TboJdOqu/6GNvd2CzaJSlvnQ6RVUionCdJOid57HXiVZglHvJB3qEsUtLyT+9ER2f4/GmgHeMB94vquO3j9qe3GP1xxEGpiq7LlAPbM5s0Hs7nwAUkd/v5t2Abqa7fTA3w= 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 1717485564417899.0394465340104; Tue, 4 Jun 2024 00:19:24 -0700 (PDT) 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 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 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a24dac048so2179637a12.0 for ; Tue, 04 Jun 2024 00:18:49 -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) 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= X-MC-Unique: ze5qarTvPYCinkPjVbE8hQ-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485565425100006 Content-Type: text/plain; charset="utf-8" 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 a= ddr) tlb_flush_page(env_cpu(env), addr); } =20 -static G_NORETURN -void do_hlt(CPUX86State *env) +G_NORETURN void helper_hlt(CPUX86State *env) { CPUState *cs =3D env_cpu(env); =20 @@ -527,14 +526,6 @@ void do_hlt(CPUX86State *env) cpu_loop_exit(cs); } =20 -G_NORETURN void helper_hlt(CPUX86State *env, int next_eip_addend) -{ - cpu_svm_check_intercept_param(env, SVM_EXIT_HLT, 0, GETPC()); - env->eip +=3D next_eip_addend; - - do_hlt(env); -} - void helper_monitor(CPUX86State *env, target_ulong ptr) { if ((uint32_t)env->regs[R_ECX] !=3D 0) { @@ -558,6 +549,6 @@ G_NORETURN void helper_mwait(CPUX86State *env, int next= _eip_addend) if (cs->cpu_index !=3D 0 || CPU_NEXT(cs) !=3D 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] =3D { [0xE7] =3D X86_OP_ENTRYrr(OUT, 0,v, I_unsigned,b), /* AX/EAX */ =20 [0xF1] =3D X86_OP_ENTRY0(INT1, svm(ICEBP)), - [0xF4] =3D X86_OP_ENTRY0(HLT, chk(cpl0)), + [0xF4] =3D X86_OP_ENTRY0(HLT, chk(cpl0) svm(HLT)), [0xF5] =3D X86_OP_ENTRY0(CMC), [0xF6] =3D X86_OP_GROUP1(group3, E,b), [0xF7] =3D X86_OP_GROUP1(group3, E,v), @@ -2539,7 +2539,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) =20 /* * 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 =3D DISAS_NORETURN; #endif } --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485566; cv=none; d=zohomail.com; s=zohoarc; b=exqRKR88IsVuZVflzyoKeqCrWjVuFfQyh3e+W6J69fytipB7VF2lzGXquw6pEGgJACDdFodvO2OJ/47auCT9PWI0VwadctVQoYO4Uid9QLPZFqHsWtVRs4sW9vzXDLUriBf0wMBwoF9KKvJqQEcprTwSWEYYtBpVuFpOM51+2w8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485566; 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=PdoHVj3MnM6xNHR6wiFxITGd/pg/M7TRVW28uhWoqSA=; b=J7jA28AvS4fGZgXQkQxnkRylOX9X343mDO9auU3+sfgPDvwxodK2IYNvUNw5ECoh7uFs3mW6B6X0mDziznTyjEYDKYKi4QadX+AzCaCRLfFzClDQgRTjWlesUk5Q+9Ejb2ZUJTXDC9F4lviG230iBM8Wqasei7DQwh0KMQE07M4= 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 1717485566048198.96125434541364; Tue, 4 Jun 2024 00:19:26 -0700 (PDT) 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 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 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a33a589b3so1410062a12.0 for ; Tue, 04 Jun 2024 00:18:52 -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) 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= X-MC-Unique: R5rhD1EjPJ-uXDIGk3u0bg-1 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) 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 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: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485567338100018 Content-Type: text/plain; charset="utf-8" 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, in= t) 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]; =20 /* misc_helper.c */ void cpu_load_eflags(CPUX86State *env, int eflags, int update_mask); -G_NORETURN void do_pause(CPUX86State *env); =20 /* 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); } =20 -G_NORETURN void do_pause(CPUX86State *env) +G_NORETURN void helper_pause(CPUX86State *env) { CPUState *cs =3D env_cpu(env); =20 @@ -97,14 +97,6 @@ G_NORETURN void do_pause(CPUX86State *env) cpu_loop_exit(cs); } =20 -G_NORETURN void helper_pause(CPUX86State *env, int next_eip_addend) -{ - cpu_svm_check_intercept_param(env, SVM_EXIT_PAUSE, 0, GETPC()); - env->eip +=3D next_eip_addend; - - do_pause(env); -} - uint64_t helper_rdpkru(CPUX86State *env, uint32_t ecx) { if ((env->cr[4] & CR4_PKE_MASK) =3D=3D 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) =20 /* XXX: not complete but not completely erroneous */ if (cs->cpu_index !=3D 0 || CPU_NEXT(cs) !=3D 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, CPUX86St= ate *env, X86OpEntry *entry, } } =20 +static void decode_90(DisasContext *s, CPUX86State *env, X86OpEntry *entry= , uint8_t *b) +{ + static X86OpEntry pause =3D X86_OP_ENTRY0(PAUSE, svm(PAUSE)); + static X86OpEntry nop =3D X86_OP_ENTRY0(NOP); + static X86OpEntry xchg_ax =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v); + + if (REX_B(s)) { + *entry =3D xchg_ax; + } else { + *entry =3D (s->prefix & PREFIX_REPZ) ? pause : nop; + } +} + static const X86OpEntry opcodes_root[256] =3D { [0x00] =3D X86_OP_ENTRY2(ADD, E,b, G,b, lock), [0x01] =3D X86_OP_ENTRY2(ADD, E,v, G,v, lock), @@ -1441,7 +1454,7 @@ static const X86OpEntry opcodes_root[256] =3D { [0x86] =3D X86_OP_ENTRY2(XCHG, E,b, G,b, xchg), [0x87] =3D X86_OP_ENTRY2(XCHG, E,v, G,v, xchg), =20 - [0x90] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x90] =3D X86_OP_GROUP0(90), [0x91] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), [0x92] =3D X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), [0x93] =3D 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); } =20 +static void gen_PAUSE(DisasContext *s, CPUX86State *env, X86DecodedInsn *d= ecode) +{ + gen_update_cc_op(s); + gen_update_eip_next(s); + gen_helper_pause(tcg_env); + s->base.is_jmp =3D DISAS_NORETURN; +} + static void gen_PCMPESTRI(DisasContext *s, CPUX86State *env, X86DecodedIns= n *decode) { TCGv_i32 imm =3D tcg_constant8u_i32(decode->immediate); @@ -4014,18 +4022,6 @@ static void gen_WAIT(DisasContext *s, CPUX86State *e= nv, X86DecodedInsn *decode) =20 static void gen_XCHG(DisasContext *s, CPUX86State *env, X86DecodedInsn *de= code) { - if (decode->b =3D=3D 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 =3D DISAS_NORETURN; - } - /* No writeback. */ - decode->op[0].unit =3D 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); --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485581; cv=none; d=zohomail.com; s=zohoarc; b=c7PH+EfDBugMdinchXvi/PLC39MwXg4by69SWxuT8eU7lYKNdYdXrLO12DjAaBigqvF8c01RNKqC+iTgnikLtkVYmNCJdXxXxhu4u+xVUQCQlnSv2jqMW4dcTMOM7qqSKC//VFM6hter4fCKJgT1wobQbrWtd2BmQE2C2eXllSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485581; 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=Omj7V/9neG3Skvv8V7gZhHDNOP50DtvEDEa1OSvAS0I=; b=bF0Hhq3ZCpg/HzwXnC8W2aW8ZOO5pJrL6dtWap2zPzWXUEQFHsGMaBb2hkhGe9C8chcWWtXRNsWKeDOVEZzpNSYIgXQqxpabkrpkDjDw2mzkC3/IcP1bV4yQaybIONSDWBJJAmdQbONf6jhiYYpZErrJnmu3DR0/ud2ipEbCnHo= 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 1717485581036362.5234641058821; Tue, 4 Jun 2024 00:19:41 -0700 (PDT) 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 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 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-57a49b8a27eso280391a12.0 for ; Tue, 04 Jun 2024 00:18:55 -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) 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= X-MC-Unique: JkrlGbTJOJ2yd_9XeoYcOQ-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485581366100001 Content-Type: text/plain; charset="utf-8" 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/b= pt_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) } } =20 + if (env->dr[7] & DR7_GD) { + env->dr[7] &=3D ~DR7_GD; + env->dr[6] |=3D DR6_BD; + raise_exception_ra(env, EXCP01_DB, GETPC()); + } + return env->dr[reg]; } =20 @@ -251,6 +257,12 @@ void helper_set_dr(CPUX86State *env, int reg, target_u= long t0) } } =20 + if (env->dr[7] & DR7_GD) { + env->dr[7] &=3D ~DR7_GD; + env->dr[6] |=3D 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) !=3D DR7_TYPE_IO_RW) { --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485592; cv=none; d=zohomail.com; s=zohoarc; b=n+EaKeSXEL/y64m8+m7H8vkYqZck2gaNpolFAf53UBbmCCGqgzgh4I8qtRmrLwbYnuNDImRnAj5refKe+PMsFpG52meZVBvBKWVEbAuvEko+Bs+/sGpVcDnAvTHR1Rx1wLES2QR8p/Ezhm5k4NXeuL57vZg6t/AgkLcT9Hq4Qzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485592; 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=aHLLmdM1T47s1VBxMQynaNLfQGaY0mg7XaNcdIi3/jE=; b=Q1sp7uWwWjlhagocRSM40iUk3kFMdOrJXP4y0vKclos2eLChwuXBTC0Na1WQPfonJ+VSs0ILPW/q7beYcIQRYIEeFl3atqxYvVwHIDcvPpESkzMj8rOjC07Dxn8nAxGMM6hKZYsXZYDQHAJP66z5nOi8FhCGCAd7kXLtEbaLyMs= 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 1717485592958112.60690979049957; Tue, 4 Jun 2024 00:19:52 -0700 (PDT) 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 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 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a68e0faf1f6so91954566b.3 for ; Tue, 04 Jun 2024 00:18:57 -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) 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= X-MC-Unique: JmLhD4cwN9aHzLJtN2dPKw-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485593419100003 Content-Type: text/plain; charset="utf-8" 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/s= vm_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; =20 if (aflag =3D=3D 2) { addr =3D env->regs[R_EAX]; @@ -361,20 +363,22 @@ void helper_vmrun(CPUX86State *env, int aflag, int ne= xt_eip_addend) env->vm_vmcb + offsetof(struct vmcb, save.= rsp)); env->regs[R_EAX] =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.= rax)); - env->dr[7] =3D x86_ldq_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, save.dr7)); - env->dr[6] =3D x86_ldq_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, save.dr6)); + + new_dr7 =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save= .dr7)); + new_dr6 =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save= .dr6)); =20 #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 =20 + cpu_x86_update_dr7(env, new_dr7); + env->dr[6] =3D 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) =20 env->dr[6] =3D x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb, save.dr6)); - env->dr[7] =3D 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); =20 /* 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. */ =20 - /* Disables all breakpoints in the host DR7 register. */ - /* Checks the reloaded host state for consistency. */ =20 /* If the host's rIP reloaded by #VMEXIT is outside the limit of the --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485591; cv=none; d=zohomail.com; s=zohoarc; b=nUBMWiAxjK8iHssn1dvel2HZaB2kV+yGCqs2vYt0XA99YiNFZDaV8jqfzMa3wyxMFNY/PtDZBimaWQVlO49Xi+W0JWmo2dmTFfDDTGLqm5ynMnDAyGvM5fNqIaaCw3YCD2YyuRI727YBsLKY7lreA1ZiTCVK6skbah2MYT8XjIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485591; 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=jd1l2qesW2ZIZOnZQq5rLZIMm8vL0i3PnwLlc9wF0HE=; b=dqF1pQl/nGXjaY5W6EEFzGCXwr5roS2UUvt8tqDAA15nXJt9FGDegCAMhRrp3yKpxbLXJGjFFxDNw5bXQqTbS6pPXLsexCdj0TqMChj7wBGddVjXUm03eqROH4yBgs5ZEIVuiUykTh5iBXW+dnLO7rk9z0PoEYZaLVWK3ULsXfg= 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 1717485591570224.66580962425314; Tue, 4 Jun 2024 00:19:51 -0700 (PDT) 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 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 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-57a4d24a479so625961a12.2 for ; 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-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) 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= X-MC-Unique: qKODYWeuMCy_Ew_yBHChpQ-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485593437100004 Content-Type: text/plain; charset="utf-8" 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/s= vm_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 nex= t_eip_addend) control.intercept_except= ions )); =20 + env->hflags &=3D ~HF_INHIBIT_IRQ_MASK; + if (x86_ldl_phys(cs, env->vm_vmcb + + offsetof(struct vmcb, control.int_state)) & + SVM_INTERRUPT_SHADOW_MASK) { + env->hflags |=3D HF_INHIBIT_IRQ_MASK; + } + nested_ctl =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.nested_c= tl)); asid =3D x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, @@ -815,8 +822,12 @@ void do_vmexit(CPUX86State *env) env->hflags &=3D ~HF_GUEST_MASK; env->intercept =3D 0; env->intercept_exceptions =3D 0; + + /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ cs->interrupt_request &=3D ~CPU_INTERRUPT_VIRQ; env->int_ctl =3D 0; + + /* Clears the TSC_OFFSET inside the processor. */ env->tsc_offset =3D 0; =20 env->gdt.base =3D x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vm= cb, @@ -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 vm= cb, save.efer))); + + /* Completion of the VMRUN instruction clears the host EFLAGS.RF bit. = */ env->eflags =3D 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)); =20 svm_load_seg_cache(env, MMU_PHYS_IDX, env->vm_hsave + offsetof(struct vmcb, save.es), R_E= S); @@ -888,19 +910,17 @@ void do_vmexit(CPUX86State *env) =20 env->hflags2 &=3D ~HF2_GIF_MASK; env->hflags2 &=3D ~HF2_VGIF_MASK; - /* FIXME: Resets the current ASID register to zero (host ASID). */ =20 - /* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ =20 - /* Clears the TSC_OFFSET inside the processor. */ + /* FIXME: Checks the reloaded host state for consistency. */ =20 - /* 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) !=3D 0) { + env->dr[6] |=3D 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 st= ate. + * 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); --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485671; cv=none; d=zohomail.com; s=zohoarc; b=NnTiQ6HN3W6cusaxPYUSNuTu9yy139xwzZPfv0zs7zL8uMyLjzcVVAvGiCgm51lG+EybAk4IMZW5sNsHIjrbYnbCscheONdeQFajuKhIebYcWN8e2kYhQFetCYgdRvmdBUtlZkdG5NVJrhYk7O7y52rdr4axR2qdqoz/uBAZBic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485671; 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=7QRT7KodLZb3R6daWVQofmOuNLtzn1249htY3GzAkRw=; b=DERHE+zQRbsCgorN8rAVyxIbCb2DOyuRjj5xLZgzTaxIId8pG+OCizftnMpTe6wZsvHSErYdY1ixVfiaOQQ18g5AglCHZpc2Pgp5uEi1RgnqghA0zi0eXpQ3aUpbFJkNKec2+tJ9kktUCu2CizgVQ8H7tIoiTniqWtEKPFOEAZk= 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 1717485670997805.5652926278849; Tue, 4 Jun 2024 00:21:10 -0700 (PDT) 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 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 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5785176c796so2529924a12.3 for ; Tue, 04 Jun 2024 00:19:03 -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) 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= X-MC-Unique: O9t0rNKEPI2U-nDgKXyVGg-1 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) 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 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: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485671799100006 Content-Type: text/plain; charset="utf-8" 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 =3D env_cpu(env); =20 + /* 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 =3D EXCP_INTERRUPT; cpu_loop_exit(cs); --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485675; cv=none; d=zohomail.com; s=zohoarc; b=Um6PQcHTz/Gc8XsSlLCgff5IGUPSgzICGBRvixN06INpDIdBT4CnaFdDCtnNSclLQp5lV1gxASlr7aoCI3/3PHjPLNy7bxwLGm2W6BeldXRHY+cdsZ3JLxAAyEC8WWP2ShpDO75nfHi8DO82a0Mmag6QazC6zA3tCUPeD5JreO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485675; 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=JE1l3mnnViu2bSu14FqFVuNS+di8GAj9jPlWPGLObPQ=; b=HB8laNsyB1aMc48WhvrLc/6fCEXREHv4rpmH7xza0hE/2xB2BqFRqa5lSKLwG46+pmGkJ8X2j0IQMfSoGaqoP6Tpejp9ovzNgd/tH0UTwMRRB5cp+wQBn+9D+nLCfhMlg7uC6rQLVoErl3mWvWFcXyKszktsOS1NJHIcY7K3wQU= 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 1717485675601331.95008178822513; Tue, 4 Jun 2024 00:21:15 -0700 (PDT) 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 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 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a6905050583so98639466b.0 for ; Tue, 04 Jun 2024 00:19:07 -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) 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= X-MC-Unique: 4pccu4QMO96Lu7Bxg9Zc6w-1 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) 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 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: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485675762100001 Content-Type: text/plain; charset="utf-8" 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 =3D env_cpu(env); =20 - env->hflags &=3D ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before= */ + do_end_instruction(env); cs->halted =3D 1; cs->exception_index =3D EXCP_HLT; cpu_loop_exit(cs); diff --git a/target/i386/tcg/sysemu/seg_helper.c b/target/i386/tcg/sysemu/s= eg_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) =20 bool x86_cpu_exec_halt(CPUState *cpu) { - if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { - X86CPU *x86_cpu =3D X86_CPU(cpu); + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; =20 + 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] |=3D DR6_BS; + do_interrupt_all(x86_cpu, EXCP01_DB, 0, 0, env->eip, 0); + } + return true; } =20 bool x86_need_replay_interrupt(int interrupt_request) --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485670; cv=none; d=zohomail.com; s=zohoarc; b=GH0hiKjXkryL+XOpQ4VLLZ+BOqpgPWZ1HAY98Pqf8R4q2pL/GlNNo0W2pUe+XQY4n02BvinWTCiWSwiBdibFCO5KiXnpsHXUBPflSCcT/1VoU8tHyBFUVIz49usLNaqKZ75+bU7MldoO6YS5mFl0k57Uwx+AWVkL9V9re2Ri4xY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485670; 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=rCpaT2bnUFA6x8rHRoclpeCn7PmIy3X6pqFoqtygESw=; b=hT42NIekNl7KTjDpDU34UG1umRuQkSmLdjj15klyF8b4qb3OvoE0YIGOyhQ0jkR0Re95tLa6FtcV6Z7274l8aeNL3cfMmzMuDGofvN657kjJr2c8o1PHtMSRVMmYNkVIVgXYz3RcKKbBhIfvv3s8sAhJ2G1ccGJ6O/JnOqTGDo4= 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 1717485670325341.95661301065854; Tue, 4 Jun 2024 00:21:10 -0700 (PDT) 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 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 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a68ce1ac733so131341166b.3 for ; Tue, 04 Jun 2024 00:19:10 -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) 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= X-MC-Unique: PTHoBow0Ot-vOrveUVg6iw-1 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) 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 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.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485671796100005 Content-Type: text/plain; charset="utf-8" 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/b= pt_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 =3D 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); --=20 2.45.1 From nobody Mon Nov 25 04:55:26 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=1717485566; cv=none; d=zohomail.com; s=zohoarc; b=HDMSh6yBS8gpC0zp73OWaPHPLQu+5Y4gE6gNizy723O0TyIdcScQ5W9vMJuUOMtC/RozeRNhh/dwpseh+FVOqa56vkLu4uzimWHuXkvXfDHEmt5uxnPfESdjPdC5nwdzUzl4K28uO2rQKPRBp/Usva9AUWyLQzl1XYLwyassVYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717485566; 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=hmcO4ui07BBe0FjQAMjYfYJsiVn0613DcSvAYmLll7I=; b=K1vyQy4KObToL0/cnGKVPkmlrdeAJ4e0H9evu6kEif1sBWsmj8hGnFhVL77YN+2lKso1sq0EPvxWqA8fKhOAI0y3yGFR9jJ7YxT4mjyxVmlwKeuicf1b2p4qVtXSzuw9Tea27RhNYd5zWIizHLmydRJ2SeDV8J1nflW14BZi9Ek= 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 1717485566332527.4519443135808; Tue, 4 Jun 2024 00:19:26 -0700 (PDT) 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 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 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-57a280de2d2so959023a12.2 for ; Tue, 04 Jun 2024 00:19:12 -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) 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= X-MC-Unique: FNWUItZzN92CUqg5shIWUw-1 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) 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 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: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1717485567314100017 Content-Type: text/plain; charset="utf-8" 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) =20 switch (dc->base.is_jmp) { case DISAS_NORETURN: + /* + * Most instructions should not use DISAS_NORETURN, as that suppre= sses + * 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 v= mexit, + * 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); --=20 2.45.1