From nobody Tue Nov 26 22:24:11 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=1704012674; cv=none; d=zohomail.com; s=zohoarc; b=S8lvRIwGYMEvtd8JoIECPay9H7yzViW1itOu5wPeYvz4+4+xw8h+pnioHyvDer9+hqCPciyhWWgVy45nvvQfxcuZnbbPolFnI43xcWpw6Lj4ybu0xy5WPdjxJAfDqjNwhhvxJzkTdKQiQnbwhDDwvw8yZRGmT6YVTQK5TbYQkFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704012674; 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=e1kMhOD0w1s7qjHiwnekeESNBiKPUesI43vYWlltEI8=; b=MKphbp3IW/37zSrdbrLw5afs0qIg+MROcd3QXY1vMvIF0OPhDJ9wSFBcxDvDYV2rWYthg0ipJp0ctN/O8U7TCo03I05EolVfW6nNnJIQ5GOy3TPhnQ+gDwTZ2EOy/kS0W7KyUkBaeTEyHPuwJcraWQ1hD/NCLQCUSFk/mOMGdPg= 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 1704012674460620.3221879343644; Sun, 31 Dec 2023 00:51:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJrRt-0004CI-GU; Sun, 31 Dec 2023 03:45:33 -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 1rJrRr-0004BM-6P for qemu-devel@nongnu.org; Sun, 31 Dec 2023 03:45:31 -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 1rJrRp-0000ib-Hq for qemu-devel@nongnu.org; Sun, 31 Dec 2023 03:45:30 -0500 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-685-Ra2HH6h1PqiQQ8rI6L-h1A-1; Sun, 31 Dec 2023 03:45:27 -0500 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2765a07d3eso86563666b.2 for ; Sun, 31 Dec 2023 00:45:26 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id d5-20020a50fe85000000b0054cb88a353dsm13186333edt.14.2023.12.31.00.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 00:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704012328; 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=e1kMhOD0w1s7qjHiwnekeESNBiKPUesI43vYWlltEI8=; b=YibOhIt8X1hDdNlTXMwvZMxyEIP6ETJwCNdWOSvwFnX9b2oi8OXjXSn6plHvlOykZs8qXV xmYoW37H4u7Ps49vNWPKxSYpylQW8ORQaay6X17eOylrkWGouD0heNxJRQ+cJKFejrujCX bghvdqVXHFCwmq3M22HR0jcHzhfUR/s= X-MC-Unique: Ra2HH6h1PqiQQ8rI6L-h1A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704012325; x=1704617125; 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=e1kMhOD0w1s7qjHiwnekeESNBiKPUesI43vYWlltEI8=; b=qbvvcw4QYJ6E9DmF62/QDDpmCmuv8+0cBuSwrk1WfoFVZ0txsJxYF4QJ74U/BKnj/N eV/KsMjgKU9ZvSIgMpHy3nJkGodahiUGb+ZHdFA+lDciEjkQDFN7dHofGbupYZ3YKolq kCn3NkLtsL/5Om1AdxyjMGqy1o5hfob8w/xv7fQ4iGZYO06xftE/bQG86hob0awlVGce je4q7MA+uSOYN7SD4bpG/5nYX+XrFQsKUcEvDT5X32tsmi3XWf0RxRbCjwaOg3cArKP4 BzP1XzgADJ+CkXTp2R2Wvbl2xayOk3OA259T2oD7a9kRKjuZrWS6W57qqR1eF/2DmiKA Avcg== X-Gm-Message-State: AOJu0YzjEWztWXQumo/P5QLAtpZKkig8BVVQ1Xs2jsOMIuX/QzhPH1cG PMtd+/9SU5aiERercMM/OU+G7phy+N32AtDa1q+Es/DCr0vQwhhJuGNbTdpOgabcDTh9Pmbg6sM Og3QYTX1vFGihQS9fpKQt2YyHs/9FG+7yrzVThECuuGet1yJ7vhMIdQbRfDeGGk8R3fHsAPrLfn kPVnCyLoA= X-Received: by 2002:a50:d4c1:0:b0:54d:740c:6bd9 with SMTP id e1-20020a50d4c1000000b0054d740c6bd9mr8820104edj.70.1704012325245; Sun, 31 Dec 2023 00:45:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQBxghtScOwif8HtEP6IcwyTvmW+X/TjwPGsPUWWnRQ3GkmizjRHc2wXYzHjAp6oRSPW5CkQ== X-Received: by 2002:a50:d4c1:0:b0:54d:740c:6bd9 with SMTP id e1-20020a50d4c1000000b0054d740c6bd9mr8820101edj.70.1704012325006; Sun, 31 Dec 2023 00:45:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PULL 08/46] target/i386: reimplement check for validity of LOCK prefix Date: Sun, 31 Dec 2023 09:44:24 +0100 Message-ID: <20231231084502.235366-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231084502.235366-1-pbonzini@redhat.com> References: <20231231084502.235366-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: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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: 1704012675116100001 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. Acked-by: Richard Henderson Signed-off-by: Paolo Bonzini --- 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