From nobody Wed Nov 27 00:37:06 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=1703269047; cv=none; d=zohomail.com; s=zohoarc; b=fNZ6b5ZDE9Hi96Xl+wBa6D9fU+4YoxnTKqgdRtzf7sD2/3o0gIoWzDscQr4RpnU6IGarP36ybUSxFA3eX8s4sDG2d2eSp0R712Ozn9HdTpEkUlRglF4+k0Y2UGXPPkrXXIEgOxCgdUxtDAYzKVQZdo/sBz+B4l6ZlTtVAqa7Ez4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703269047; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=Yq5Jlqtm77xROj7+26dNFssPKgrW3rlMl3GvEYgyhmE=; b=bTtZUEw2Pln/ec4sLvBMddSgZs69kTE/lrs8lpLga8S5+vgdnIvF4RxlVkb8AS2LPLQiS7PTKxd9+jsCxaSQmtqFqljfokL1KXsYziaAbPCfAVh7q5RfU0Ro4pAabPDZ/Yb65ZwCNDTv3d8yVRYv8XGI5xwVAaWC6DjGf2toJGc= 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 1703269047172971.3071016473681; Fri, 22 Dec 2023 10:17:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGk4r-00018L-Rt; Fri, 22 Dec 2023 13:16:53 -0500 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 1rGk4T-0000yn-Ob for qemu-devel@nongnu.org; Fri, 22 Dec 2023 13:16:33 -0500 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 1rGk4P-0006BZ-1J for qemu-devel@nongnu.org; Fri, 22 Dec 2023 13:16:27 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-Cosvj1m-O7SaerLdNnmsVQ-1; Fri, 22 Dec 2023 13:16:21 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40d39bbe215so14527345e9.1 for ; Fri, 22 Dec 2023 10:16:21 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id bg6-20020a05600c3c8600b00405c7591b09sm7778206wmb.35.2023.12.22.10.16.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 10:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703268983; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Yq5Jlqtm77xROj7+26dNFssPKgrW3rlMl3GvEYgyhmE=; b=ECfsuINCrRRt68YMwyqkN7bTGYCU2n3a+TkH05s2e5OfWcidgh/dLl6PVwhfip2xkz5d+i lRw9TiXOzwEiUy/D1enYlEFI2xQuLRG8vNb9o/faUUgHqwjuApQvM12qcckdk+ayfNR3GP K7zLvYouNiCdHzQGgjY+R3H21rL+ldk= X-MC-Unique: Cosvj1m-O7SaerLdNnmsVQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703268980; x=1703873780; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yq5Jlqtm77xROj7+26dNFssPKgrW3rlMl3GvEYgyhmE=; b=ew/5z+NanuKOOCtSzjvDHLNgz60xYktVjHBfGAvdgPZtFNQruuOuD0yjRn6IxpIXKq x+B6aZnTA+xieWjwSwH0R3ge3pRTpdm1S/+wBFu3Sv/9eXcqSvNQVSl/MqhXGw74kYk/ RX9hDsmN4qQZ/EYgw+z2zh+7tGntmCtzPqAOOLGanDcDN9CN0uIiHZlSipQWRME3XqfZ R3axcx3sG/KPkJ9XvEpL/+iy5a4ydYYoCDv79h6Q5hUzvmL7N57zCJhErS+nUajvog+r SV1KA7J6xRARQKqEnz3kJ18Sj0Rx1pQ1FdtfSpGNiRStAU17q3TcwEy1Hx6E2pOvBJ14 HEAQ== X-Gm-Message-State: AOJu0YyzvMe+b4l7BXnWgiRooNcH3Bh0ock+jxJh5sb8W0ykGPhYyHld py1s05j0ncxNtNWL3s4V4PLWQtxDdH6dRmvkgzDD8m3dO6ajKZiiB2RZ4K3SD80oxfcQeuVS0xx CzoCO1sz3gfPqI/pGdAIcoNMVLaDRP8yjaD80Oaquuc9TnofFn156xiu3WyjykAsFrFgyo5zG1c ROuPDiWag= X-Received: by 2002:a05:600c:4e92:b0:40b:5e21:ec15 with SMTP id f18-20020a05600c4e9200b0040b5e21ec15mr901315wmq.71.1703268980251; Fri, 22 Dec 2023 10:16:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IH35FGyRCSLkdlwW9FUOLjlsgJ2QMioBg7cLC/EUKB0W3dzumz+LAi0nDAvLoYao0pFKcYExw== X-Received: by 2002:a05:600c:4e92:b0:40b:5e21:ec15 with SMTP id f18-20020a05600c4e9200b0040b5e21ec15mr901311wmq.71.1703268979910; Fri, 22 Dec 2023 10:16:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 07/22] target/i386: reimplement check for validity of LOCK prefix Date: Fri, 22 Dec 2023 19:15:48 +0100 Message-ID: <20231222181603.174137-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231222181603.174137-1-pbonzini@redhat.com> References: <20231222181603.174137-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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: 1703269048481100002 Content-Type: text/plain; charset="utf-8" The previous check erroneously allowed CMP to be modified with LOCK. Instead, tag explicitly the instructions that do support LOCK. Signed-off-by: Paolo Bonzini Acked-by: Richard Henderson --- target/i386/tcg/decode-new.c.inc | 17 ++++++++++------- target/i386/tcg/decode-new.h | 3 +++ target/i386/tcg/emit.c.inc | 5 ----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.= c.inc index 232c6a45c96..5eb2e9d0224 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -151,6 +151,7 @@ =20 #define cpuid(feat) .cpuid =3D X86_FEAT_##feat, #define xchg .special =3D X86_SPECIAL_Locked, +#define lock .special =3D X86_SPECIAL_HasLock, #define mmx .special =3D X86_SPECIAL_MMX, #define zext0 .special =3D X86_SPECIAL_ZExtOp0, #define zext2 .special =3D X86_SPECIAL_ZExtOp2, @@ -1103,10 +1104,6 @@ static int decode_modrm(DisasContext *s, CPUX86State= *env, X86DecodedInsn *decod { int modrm =3D get_modrm(s, env); if ((modrm >> 6) =3D=3D 3) { - if (s->prefix & PREFIX_LOCK) { - decode->e.gen =3D gen_illegal; - return 0xff; - } op->n =3D (modrm & 7); if (type !=3D X86_TYPE_Q && type !=3D X86_TYPE_N) { op->n |=3D REX_B(s); @@ -1881,6 +1878,9 @@ static void disas_insn_new(DisasContext *s, CPUState = *cpu, int b) if (decode.op[0].has_ea) { s->prefix |=3D PREFIX_LOCK; } + decode.e.special =3D X86_SPECIAL_HasLock; + /* fallthrough */ + case X86_SPECIAL_HasLock: break; =20 case X86_SPECIAL_ZExtOp0: @@ -1909,6 +1909,12 @@ static void disas_insn_new(DisasContext *s, CPUState= *cpu, int b) break; } =20 + if (s->prefix & PREFIX_LOCK) { + if (decode.e.special !=3D X86_SPECIAL_HasLock || !decode.op[0].has= _ea) { + goto illegal_op; + } + } + if (!validate_vex(s, &decode)) { return; } @@ -1952,9 +1958,6 @@ static void disas_insn_new(DisasContext *s, CPUState = *cpu, int b) gen_load_ea(s, &decode.mem, decode.e.vex_class =3D=3D 12); } if (s->prefix & PREFIX_LOCK) { - if (decode.op[0].unit !=3D X86_OP_INT || !decode.op[0].has_ea) { - goto illegal_op; - } gen_load(s, &decode, 2, s->T1); decode.e.gen(s, env, &decode); } else { diff --git a/target/i386/tcg/decode-new.h b/target/i386/tcg/decode-new.h index e6c904a3192..611bfddd957 100644 --- a/target/i386/tcg/decode-new.h +++ b/target/i386/tcg/decode-new.h @@ -158,6 +158,9 @@ typedef enum X86InsnCheck { typedef enum X86InsnSpecial { X86_SPECIAL_None, =20 + /* Accepts LOCK prefix; LOCKed operations do not load or writeback ope= rand 0 */ + X86_SPECIAL_HasLock, + /* Always locked if it has a memory operand (XCHG) */ X86_SPECIAL_Locked, =20 diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index d444d83e534..98c4c9569ef 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -55,11 +55,6 @@ static void gen_NM_exception(DisasContext *s) gen_exception(s, EXCP07_PREX); } =20 -static void gen_illegal(DisasContext *s, CPUX86State *env, X86DecodedInsn = *decode) -{ - gen_illegal_opcode(s); -} - static void gen_load_ea(DisasContext *s, AddressParts *mem, bool is_vsib) { TCGv ea =3D gen_lea_modrm_1(s, *mem, is_vsib); --=20 2.43.0