Skip to content

Commit 72bb8f8

Browse files
zx2c4ingomolnar
authored andcommitted
x86/insn: Avoid namespace clash by separating instruction decoder MMIO type from MMIO trace type
Both <linux/mmiotrace.h> and <asm/insn-eval.h> define various MMIO_ enum constants, whose namespace overlaps. Rename the <asm/insn-eval.h> ones to have a INSN_ prefix, so that the headers can be used from the same source file. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20230101162910.710293-2-Jason@zx2c4.com
1 parent 55d2353 commit 72bb8f8

4 files changed

Lines changed: 41 additions & 41 deletions

File tree

arch/x86/coco/tdx/tdx.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
386386
{
387387
unsigned long *reg, val, vaddr;
388388
char buffer[MAX_INSN_SIZE];
389+
enum insn_mmio_type mmio;
389390
struct insn insn = {};
390-
enum mmio_type mmio;
391391
int size, extend_size;
392392
u8 extend_val = 0;
393393

@@ -402,10 +402,10 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
402402
return -EINVAL;
403403

404404
mmio = insn_decode_mmio(&insn, &size);
405-
if (WARN_ON_ONCE(mmio == MMIO_DECODE_FAILED))
405+
if (WARN_ON_ONCE(mmio == INSN_MMIO_DECODE_FAILED))
406406
return -EINVAL;
407407

408-
if (mmio != MMIO_WRITE_IMM && mmio != MMIO_MOVS) {
408+
if (mmio != INSN_MMIO_WRITE_IMM && mmio != INSN_MMIO_MOVS) {
409409
reg = insn_get_modrm_reg_ptr(&insn, regs);
410410
if (!reg)
411411
return -EINVAL;
@@ -426,23 +426,23 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
426426

427427
/* Handle writes first */
428428
switch (mmio) {
429-
case MMIO_WRITE:
429+
case INSN_MMIO_WRITE:
430430
memcpy(&val, reg, size);
431431
if (!mmio_write(size, ve->gpa, val))
432432
return -EIO;
433433
return insn.length;
434-
case MMIO_WRITE_IMM:
434+
case INSN_MMIO_WRITE_IMM:
435435
val = insn.immediate.value;
436436
if (!mmio_write(size, ve->gpa, val))
437437
return -EIO;
438438
return insn.length;
439-
case MMIO_READ:
440-
case MMIO_READ_ZERO_EXTEND:
441-
case MMIO_READ_SIGN_EXTEND:
439+
case INSN_MMIO_READ:
440+
case INSN_MMIO_READ_ZERO_EXTEND:
441+
case INSN_MMIO_READ_SIGN_EXTEND:
442442
/* Reads are handled below */
443443
break;
444-
case MMIO_MOVS:
445-
case MMIO_DECODE_FAILED:
444+
case INSN_MMIO_MOVS:
445+
case INSN_MMIO_DECODE_FAILED:
446446
/*
447447
* MMIO was accessed with an instruction that could not be
448448
* decoded or handled properly. It was likely not using io.h
@@ -459,15 +459,15 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
459459
return -EIO;
460460

461461
switch (mmio) {
462-
case MMIO_READ:
462+
case INSN_MMIO_READ:
463463
/* Zero-extend for 32-bit operation */
464464
extend_size = size == 4 ? sizeof(*reg) : 0;
465465
break;
466-
case MMIO_READ_ZERO_EXTEND:
466+
case INSN_MMIO_READ_ZERO_EXTEND:
467467
/* Zero extend based on operand size */
468468
extend_size = insn.opnd_bytes;
469469
break;
470-
case MMIO_READ_SIGN_EXTEND:
470+
case INSN_MMIO_READ_SIGN_EXTEND:
471471
/* Sign extend based on operand size */
472472
extend_size = insn.opnd_bytes;
473473
if (size == 1 && val & BIT(7))

arch/x86/include/asm/insn-eval.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ int insn_fetch_from_user_inatomic(struct pt_regs *regs,
3232
bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs,
3333
unsigned char buf[MAX_INSN_SIZE], int buf_size);
3434

35-
enum mmio_type {
36-
MMIO_DECODE_FAILED,
37-
MMIO_WRITE,
38-
MMIO_WRITE_IMM,
39-
MMIO_READ,
40-
MMIO_READ_ZERO_EXTEND,
41-
MMIO_READ_SIGN_EXTEND,
42-
MMIO_MOVS,
35+
enum insn_mmio_type {
36+
INSN_MMIO_DECODE_FAILED,
37+
INSN_MMIO_WRITE,
38+
INSN_MMIO_WRITE_IMM,
39+
INSN_MMIO_READ,
40+
INSN_MMIO_READ_ZERO_EXTEND,
41+
INSN_MMIO_READ_SIGN_EXTEND,
42+
INSN_MMIO_MOVS,
4343
};
4444

45-
enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes);
45+
enum insn_mmio_type insn_decode_mmio(struct insn *insn, int *bytes);
4646

4747
#endif /* _ASM_X86_INSN_EVAL_H */

arch/x86/kernel/sev.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,32 +1536,32 @@ static enum es_result vc_handle_mmio_movs(struct es_em_ctxt *ctxt,
15361536
static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
15371537
{
15381538
struct insn *insn = &ctxt->insn;
1539+
enum insn_mmio_type mmio;
15391540
unsigned int bytes = 0;
1540-
enum mmio_type mmio;
15411541
enum es_result ret;
15421542
u8 sign_byte;
15431543
long *reg_data;
15441544

15451545
mmio = insn_decode_mmio(insn, &bytes);
1546-
if (mmio == MMIO_DECODE_FAILED)
1546+
if (mmio == INSN_MMIO_DECODE_FAILED)
15471547
return ES_DECODE_FAILED;
15481548

1549-
if (mmio != MMIO_WRITE_IMM && mmio != MMIO_MOVS) {
1549+
if (mmio != INSN_MMIO_WRITE_IMM && mmio != INSN_MMIO_MOVS) {
15501550
reg_data = insn_get_modrm_reg_ptr(insn, ctxt->regs);
15511551
if (!reg_data)
15521552
return ES_DECODE_FAILED;
15531553
}
15541554

15551555
switch (mmio) {
1556-
case MMIO_WRITE:
1556+
case INSN_MMIO_WRITE:
15571557
memcpy(ghcb->shared_buffer, reg_data, bytes);
15581558
ret = vc_do_mmio(ghcb, ctxt, bytes, false);
15591559
break;
1560-
case MMIO_WRITE_IMM:
1560+
case INSN_MMIO_WRITE_IMM:
15611561
memcpy(ghcb->shared_buffer, insn->immediate1.bytes, bytes);
15621562
ret = vc_do_mmio(ghcb, ctxt, bytes, false);
15631563
break;
1564-
case MMIO_READ:
1564+
case INSN_MMIO_READ:
15651565
ret = vc_do_mmio(ghcb, ctxt, bytes, true);
15661566
if (ret)
15671567
break;
@@ -1572,7 +1572,7 @@ static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
15721572

15731573
memcpy(reg_data, ghcb->shared_buffer, bytes);
15741574
break;
1575-
case MMIO_READ_ZERO_EXTEND:
1575+
case INSN_MMIO_READ_ZERO_EXTEND:
15761576
ret = vc_do_mmio(ghcb, ctxt, bytes, true);
15771577
if (ret)
15781578
break;
@@ -1581,7 +1581,7 @@ static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
15811581
memset(reg_data, 0, insn->opnd_bytes);
15821582
memcpy(reg_data, ghcb->shared_buffer, bytes);
15831583
break;
1584-
case MMIO_READ_SIGN_EXTEND:
1584+
case INSN_MMIO_READ_SIGN_EXTEND:
15851585
ret = vc_do_mmio(ghcb, ctxt, bytes, true);
15861586
if (ret)
15871587
break;
@@ -1600,7 +1600,7 @@ static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
16001600
memset(reg_data, sign_byte, insn->opnd_bytes);
16011601
memcpy(reg_data, ghcb->shared_buffer, bytes);
16021602
break;
1603-
case MMIO_MOVS:
1603+
case INSN_MMIO_MOVS:
16041604
ret = vc_handle_mmio_movs(ctxt, bytes);
16051605
break;
16061606
default:

arch/x86/lib/insn-eval.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,16 +1595,16 @@ bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs,
15951595
* Returns:
15961596
*
15971597
* Type of the instruction. Size of the memory operand is stored in
1598-
* @bytes. If decode failed, MMIO_DECODE_FAILED returned.
1598+
* @bytes. If decode failed, INSN_MMIO_DECODE_FAILED returned.
15991599
*/
1600-
enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
1600+
enum insn_mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16011601
{
1602-
enum mmio_type type = MMIO_DECODE_FAILED;
1602+
enum insn_mmio_type type = INSN_MMIO_DECODE_FAILED;
16031603

16041604
*bytes = 0;
16051605

16061606
if (insn_get_opcode(insn))
1607-
return MMIO_DECODE_FAILED;
1607+
return INSN_MMIO_DECODE_FAILED;
16081608

16091609
switch (insn->opcode.bytes[0]) {
16101610
case 0x88: /* MOV m8,r8 */
@@ -1613,7 +1613,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16131613
case 0x89: /* MOV m16/m32/m64, r16/m32/m64 */
16141614
if (!*bytes)
16151615
*bytes = insn->opnd_bytes;
1616-
type = MMIO_WRITE;
1616+
type = INSN_MMIO_WRITE;
16171617
break;
16181618

16191619
case 0xc6: /* MOV m8, imm8 */
@@ -1622,7 +1622,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16221622
case 0xc7: /* MOV m16/m32/m64, imm16/imm32/imm64 */
16231623
if (!*bytes)
16241624
*bytes = insn->opnd_bytes;
1625-
type = MMIO_WRITE_IMM;
1625+
type = INSN_MMIO_WRITE_IMM;
16261626
break;
16271627

16281628
case 0x8a: /* MOV r8, m8 */
@@ -1631,7 +1631,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16311631
case 0x8b: /* MOV r16/r32/r64, m16/m32/m64 */
16321632
if (!*bytes)
16331633
*bytes = insn->opnd_bytes;
1634-
type = MMIO_READ;
1634+
type = INSN_MMIO_READ;
16351635
break;
16361636

16371637
case 0xa4: /* MOVS m8, m8 */
@@ -1640,7 +1640,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16401640
case 0xa5: /* MOVS m16/m32/m64, m16/m32/m64 */
16411641
if (!*bytes)
16421642
*bytes = insn->opnd_bytes;
1643-
type = MMIO_MOVS;
1643+
type = INSN_MMIO_MOVS;
16441644
break;
16451645

16461646
case 0x0f: /* Two-byte instruction */
@@ -1651,7 +1651,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16511651
case 0xb7: /* MOVZX r32/r64, m16 */
16521652
if (!*bytes)
16531653
*bytes = 2;
1654-
type = MMIO_READ_ZERO_EXTEND;
1654+
type = INSN_MMIO_READ_ZERO_EXTEND;
16551655
break;
16561656

16571657
case 0xbe: /* MOVSX r16/r32/r64, m8 */
@@ -1660,7 +1660,7 @@ enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes)
16601660
case 0xbf: /* MOVSX r32/r64, m16 */
16611661
if (!*bytes)
16621662
*bytes = 2;
1663-
type = MMIO_READ_SIGN_EXTEND;
1663+
type = INSN_MMIO_READ_SIGN_EXTEND;
16641664
break;
16651665
}
16661666
break;

0 commit comments

Comments
 (0)