Skip to content

Commit d5ec187

Browse files
kirylhansendc
authored andcommitted
x86/insn-eval: Introduce insn_get_modrm_reg_ptr()
The helper returns a pointer to the register indicated by ModRM byte. It's going to replace vc_insn_get_reg() in the SEV MMIO implementation. TDX MMIO implementation will also use it. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Reviewed-by: Tony Luck <[email protected]> Tested-by: Joerg Roedel <[email protected]> Acked-by: Tom Lendacky <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 23ef731 commit d5ec187

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bool insn_has_rep_prefix(struct insn *insn);
1919
void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
2020
int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs);
2121
int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
22+
unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs);
2223
unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
2324
int insn_get_code_seg_params(struct pt_regs *regs);
2425
int insn_get_effective_ip(struct pt_regs *regs, unsigned long *ip);

arch/x86/lib/insn-eval.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,26 @@ int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs)
848848
return get_reg_offset(insn, regs, REG_TYPE_REG);
849849
}
850850

851+
/**
852+
* insn_get_modrm_reg_ptr() - Obtain register pointer based on ModRM byte
853+
* @insn: Instruction containing the ModRM byte
854+
* @regs: Register values as seen when entering kernel mode
855+
*
856+
* Returns:
857+
*
858+
* The register indicated by the reg part of the ModRM byte.
859+
* The register is obtained as a pointer within pt_regs.
860+
*/
861+
unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs)
862+
{
863+
int offset;
864+
865+
offset = insn_get_modrm_reg_off(insn, regs);
866+
if (offset < 0)
867+
return NULL;
868+
return (void *)regs + offset;
869+
}
870+
851871
/**
852872
* get_seg_base_limit() - obtain base address and limit of a segment
853873
* @insn: Instruction. Must be valid.

0 commit comments

Comments
 (0)