From nobody Tue Sep 16 12:26:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBD23C3DA7D for ; Tue, 3 Jan 2023 17:53:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238187AbjACRxk (ORCPT ); Tue, 3 Jan 2023 12:53:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238137AbjACRxa (ORCPT ); Tue, 3 Jan 2023 12:53:30 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ACA96478; Tue, 3 Jan 2023 09:53:29 -0800 (PST) Date: Tue, 03 Jan 2023 17:53:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672768408; h=from:from:sender:sender:reply-to: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=gDnLwWUNhGeNTjk5dBPlG54FpWRbQwmtLIh1GZI8edI=; b=ff54yNuVbe5la5TP/g6GEyikaMYYlDyZDOkYwUOnSUEUNfQWjGyM7gAGMoxhaNgFXHVBsr 82l11WfW1YYdKJYsYE40Y1verMUBs15Wa6PPBtpO1OLFOAjb8qf4z8GOUFGCSLxAZIVQkQ B7Bgwcd3Z30F5OeNTdPmy9oMWG++a7HEoPvUT+rcFX+Sk5CUxQ3zhLSF7rRPYX9rprcStg J1/DSja0PpPfmhmAuRbspdrwizkU9xEr6jrSj/0qOklqco59fCXJFnR+g1/r/l5KcchRma cJns8gB9WLCm61aGeqd3zAh9wOCnul6/bjYWgKSmcGDnZ9Qn2MtNZZHFxpWAlQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672768408; h=from:from:sender:sender:reply-to: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=gDnLwWUNhGeNTjk5dBPlG54FpWRbQwmtLIh1GZI8edI=; b=s/d4NfqvTJDoykzlfQrNJQbObkGNzB9ValgCU2jhTQzFYiABNCeALlwvdBelWjIjKjDZc0 9smxAT44lV6VvZBA== From: "tip-bot2 for Jason A. Donenfeld" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/insn: Avoid namespace clash by separating instruction decoder MMIO type from MMIO trace type Cc: "Jason A. Donenfeld" , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230101162910.710293-2-Jason@zx2c4.com> References: <20230101162910.710293-2-Jason@zx2c4.com> MIME-Version: 1.0 Message-ID: <167276840732.4906.11293412600459727136.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 72bb8f8cc088730c4d84117a6906f458c2fc64bb Gitweb: https://git.kernel.org/tip/72bb8f8cc088730c4d84117a6906f458c= 2fc64bb Author: Jason A. Donenfeld AuthorDate: Sun, 01 Jan 2023 17:29:04 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 03 Jan 2023 18:46:06 +01:00 x86/insn: Avoid namespace clash by separating instruction decoder MMIO type= from MMIO trace type Both and define various MMIO_ enum co= nstants, whose namespace overlaps. Rename the ones to have a INSN_ prefix, so that the heade= rs can be used from the same source file. Signed-off-by: Jason A. Donenfeld Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230101162910.710293-2-Jason@zx2c4.com --- arch/x86/coco/tdx/tdx.c | 26 +++++++++++++------------- arch/x86/include/asm/insn-eval.h | 18 +++++++++--------- arch/x86/kernel/sev.c | 18 +++++++++--------- arch/x86/lib/insn-eval.c | 20 ++++++++++---------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index cfd4c95..669d9e4 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -386,8 +386,8 @@ static int handle_mmio(struct pt_regs *regs, struct ve_= info *ve) { unsigned long *reg, val, vaddr; char buffer[MAX_INSN_SIZE]; + enum insn_mmio_type mmio; struct insn insn =3D {}; - enum mmio_type mmio; int size, extend_size; u8 extend_val =3D 0; =20 @@ -402,10 +402,10 @@ static int handle_mmio(struct pt_regs *regs, struct v= e_info *ve) return -EINVAL; =20 mmio =3D insn_decode_mmio(&insn, &size); - if (WARN_ON_ONCE(mmio =3D=3D MMIO_DECODE_FAILED)) + if (WARN_ON_ONCE(mmio =3D=3D INSN_MMIO_DECODE_FAILED)) return -EINVAL; =20 - if (mmio !=3D MMIO_WRITE_IMM && mmio !=3D MMIO_MOVS) { + if (mmio !=3D INSN_MMIO_WRITE_IMM && mmio !=3D INSN_MMIO_MOVS) { reg =3D insn_get_modrm_reg_ptr(&insn, regs); if (!reg) return -EINVAL; @@ -426,23 +426,23 @@ static int handle_mmio(struct pt_regs *regs, struct v= e_info *ve) =20 /* Handle writes first */ switch (mmio) { - case MMIO_WRITE: + case INSN_MMIO_WRITE: memcpy(&val, reg, size); if (!mmio_write(size, ve->gpa, val)) return -EIO; return insn.length; - case MMIO_WRITE_IMM: + case INSN_MMIO_WRITE_IMM: val =3D insn.immediate.value; if (!mmio_write(size, ve->gpa, val)) return -EIO; return insn.length; - case MMIO_READ: - case MMIO_READ_ZERO_EXTEND: - case MMIO_READ_SIGN_EXTEND: + case INSN_MMIO_READ: + case INSN_MMIO_READ_ZERO_EXTEND: + case INSN_MMIO_READ_SIGN_EXTEND: /* Reads are handled below */ break; - case MMIO_MOVS: - case MMIO_DECODE_FAILED: + case INSN_MMIO_MOVS: + case INSN_MMIO_DECODE_FAILED: /* * MMIO was accessed with an instruction that could not be * decoded or handled properly. It was likely not using io.h @@ -459,15 +459,15 @@ static int handle_mmio(struct pt_regs *regs, struct v= e_info *ve) return -EIO; =20 switch (mmio) { - case MMIO_READ: + case INSN_MMIO_READ: /* Zero-extend for 32-bit operation */ extend_size =3D size =3D=3D 4 ? sizeof(*reg) : 0; break; - case MMIO_READ_ZERO_EXTEND: + case INSN_MMIO_READ_ZERO_EXTEND: /* Zero extend based on operand size */ extend_size =3D insn.opnd_bytes; break; - case MMIO_READ_SIGN_EXTEND: + case INSN_MMIO_READ_SIGN_EXTEND: /* Sign extend based on operand size */ extend_size =3D insn.opnd_bytes; if (size =3D=3D 1 && val & BIT(7)) diff --git a/arch/x86/include/asm/insn-eval.h b/arch/x86/include/asm/insn-e= val.h index f07faa6..54368a4 100644 --- a/arch/x86/include/asm/insn-eval.h +++ b/arch/x86/include/asm/insn-eval.h @@ -32,16 +32,16 @@ int insn_fetch_from_user_inatomic(struct pt_regs *regs, bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs, unsigned char buf[MAX_INSN_SIZE], int buf_size); =20 -enum mmio_type { - MMIO_DECODE_FAILED, - MMIO_WRITE, - MMIO_WRITE_IMM, - MMIO_READ, - MMIO_READ_ZERO_EXTEND, - MMIO_READ_SIGN_EXTEND, - MMIO_MOVS, +enum insn_mmio_type { + INSN_MMIO_DECODE_FAILED, + INSN_MMIO_WRITE, + INSN_MMIO_WRITE_IMM, + INSN_MMIO_READ, + INSN_MMIO_READ_ZERO_EXTEND, + INSN_MMIO_READ_SIGN_EXTEND, + INSN_MMIO_MOVS, }; =20 -enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes); +enum insn_mmio_type insn_decode_mmio(struct insn *insn, int *bytes); =20 #endif /* _ASM_X86_INSN_EVAL_H */ diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index a428c62..679026a 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1536,32 +1536,32 @@ static enum es_result vc_handle_mmio_movs(struct es= _em_ctxt *ctxt, static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt = *ctxt) { struct insn *insn =3D &ctxt->insn; + enum insn_mmio_type mmio; unsigned int bytes =3D 0; - enum mmio_type mmio; enum es_result ret; u8 sign_byte; long *reg_data; =20 mmio =3D insn_decode_mmio(insn, &bytes); - if (mmio =3D=3D MMIO_DECODE_FAILED) + if (mmio =3D=3D INSN_MMIO_DECODE_FAILED) return ES_DECODE_FAILED; =20 - if (mmio !=3D MMIO_WRITE_IMM && mmio !=3D MMIO_MOVS) { + if (mmio !=3D INSN_MMIO_WRITE_IMM && mmio !=3D INSN_MMIO_MOVS) { reg_data =3D insn_get_modrm_reg_ptr(insn, ctxt->regs); if (!reg_data) return ES_DECODE_FAILED; } =20 switch (mmio) { - case MMIO_WRITE: + case INSN_MMIO_WRITE: memcpy(ghcb->shared_buffer, reg_data, bytes); ret =3D vc_do_mmio(ghcb, ctxt, bytes, false); break; - case MMIO_WRITE_IMM: + case INSN_MMIO_WRITE_IMM: memcpy(ghcb->shared_buffer, insn->immediate1.bytes, bytes); ret =3D vc_do_mmio(ghcb, ctxt, bytes, false); break; - case MMIO_READ: + case INSN_MMIO_READ: ret =3D vc_do_mmio(ghcb, ctxt, bytes, true); if (ret) break; @@ -1572,7 +1572,7 @@ static enum es_result vc_handle_mmio(struct ghcb *ghc= b, struct es_em_ctxt *ctxt) =20 memcpy(reg_data, ghcb->shared_buffer, bytes); break; - case MMIO_READ_ZERO_EXTEND: + case INSN_MMIO_READ_ZERO_EXTEND: ret =3D vc_do_mmio(ghcb, ctxt, bytes, true); if (ret) break; @@ -1581,7 +1581,7 @@ static enum es_result vc_handle_mmio(struct ghcb *ghc= b, struct es_em_ctxt *ctxt) memset(reg_data, 0, insn->opnd_bytes); memcpy(reg_data, ghcb->shared_buffer, bytes); break; - case MMIO_READ_SIGN_EXTEND: + case INSN_MMIO_READ_SIGN_EXTEND: ret =3D vc_do_mmio(ghcb, ctxt, bytes, true); if (ret) break; @@ -1600,7 +1600,7 @@ static enum es_result vc_handle_mmio(struct ghcb *ghc= b, struct es_em_ctxt *ctxt) memset(reg_data, sign_byte, insn->opnd_bytes); memcpy(reg_data, ghcb->shared_buffer, bytes); break; - case MMIO_MOVS: + case INSN_MMIO_MOVS: ret =3D vc_handle_mmio_movs(ctxt, bytes); break; default: diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index 21104c4..558a605 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -1595,16 +1595,16 @@ bool insn_decode_from_regs(struct insn *insn, struc= t pt_regs *regs, * Returns: * * Type of the instruction. Size of the memory operand is stored in - * @bytes. If decode failed, MMIO_DECODE_FAILED returned. + * @bytes. If decode failed, INSN_MMIO_DECODE_FAILED returned. */ -enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes) +enum insn_mmio_type insn_decode_mmio(struct insn *insn, int *bytes) { - enum mmio_type type =3D MMIO_DECODE_FAILED; + enum insn_mmio_type type =3D INSN_MMIO_DECODE_FAILED; =20 *bytes =3D 0; =20 if (insn_get_opcode(insn)) - return MMIO_DECODE_FAILED; + return INSN_MMIO_DECODE_FAILED; =20 switch (insn->opcode.bytes[0]) { case 0x88: /* MOV m8,r8 */ @@ -1613,7 +1613,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, in= t *bytes) case 0x89: /* MOV m16/m32/m64, r16/m32/m64 */ if (!*bytes) *bytes =3D insn->opnd_bytes; - type =3D MMIO_WRITE; + type =3D INSN_MMIO_WRITE; break; =20 case 0xc6: /* MOV m8, imm8 */ @@ -1622,7 +1622,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, in= t *bytes) case 0xc7: /* MOV m16/m32/m64, imm16/imm32/imm64 */ if (!*bytes) *bytes =3D insn->opnd_bytes; - type =3D MMIO_WRITE_IMM; + type =3D INSN_MMIO_WRITE_IMM; break; =20 case 0x8a: /* MOV r8, m8 */ @@ -1631,7 +1631,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, in= t *bytes) case 0x8b: /* MOV r16/r32/r64, m16/m32/m64 */ if (!*bytes) *bytes =3D insn->opnd_bytes; - type =3D MMIO_READ; + type =3D INSN_MMIO_READ; break; =20 case 0xa4: /* MOVS m8, m8 */ @@ -1640,7 +1640,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, in= t *bytes) case 0xa5: /* MOVS m16/m32/m64, m16/m32/m64 */ if (!*bytes) *bytes =3D insn->opnd_bytes; - type =3D MMIO_MOVS; + type =3D INSN_MMIO_MOVS; break; =20 case 0x0f: /* Two-byte instruction */ @@ -1651,7 +1651,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, in= t *bytes) case 0xb7: /* MOVZX r32/r64, m16 */ if (!*bytes) *bytes =3D 2; - type =3D MMIO_READ_ZERO_EXTEND; + type =3D INSN_MMIO_READ_ZERO_EXTEND; break; =20 case 0xbe: /* MOVSX r16/r32/r64, m8 */ @@ -1660,7 +1660,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, in= t *bytes) case 0xbf: /* MOVSX r32/r64, m16 */ if (!*bytes) *bytes =3D 2; - type =3D MMIO_READ_SIGN_EXTEND; + type =3D INSN_MMIO_READ_SIGN_EXTEND; break; } break;