Skip to contentSkip to conversation

x86/insn-eval: Remove unused regs arg some functions

PATCH In review Jiri Olsa 2 participants 7 messages Nov 17, 2025 – Nov 18, 2025

Subsystems (2)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

PATCH 1/5 x86/insn-eval: Remove unused regs arg some functions

hi,
regs argument is not used in several insn-eval functions, removing it.

I have some changes based on these functions and it feels wrong to pass NULL in regs argument. Also I don't want to send 5 extra patches with my other change, so sending this separately.

thanks,
jirka

---
Jiri Olsa (5):
x86/insn-eval: Remove regs arg from pt_regs_offset x86/insn-eval: Remove regs arg from get_reg_offset x86/insn-eval: Remove regs arg from insn_get_modrm_rm_off x86/insn-eval: Remove regs arg from insn_get_modrm_reg_off x86/insn-eval: Remove regs arg from get_reg_offset_16

 arch/x86/coco/sev/vc-handle.c    |  2 +-
 arch/x86/include/asm/insn-eval.h |  6 +++---
 arch/x86/kernel/cfi.c            |  2 +-
 arch/x86/kernel/umip.c           |  2 +-
 arch/x86/lib/insn-eval.c         | 35 +++++++++++++++--------------------
 arch/x86/mm/extable.c            |  2 +-
 6 files changed, 22 insertions(+), 27 deletions(-)
author
#1 lore raw

PATCH 1/5 x86/insn-eval: Remove regs arg from pt_regs_offset

It's not used, pt_regs_offset returns only offset to struct pt_regs, not the actual register values.

---
 arch/x86/include/asm/insn-eval.h | 2 +-
 arch/x86/lib/insn-eval.c         | 4 ++--
 arch/x86/mm/extable.c            | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/insn-eval.h +1 -1
index 4733e9064ee5..6b592040bda4 100644
@@ -15,7 +15,7 @@
 #define INSN_CODE_SEG_OPND_SZ(params) (params & 0xf)
 #define INSN_CODE_SEG_PARAMS(oper_sz, addr_sz) (oper_sz | (addr_sz << 4))
 
-int pt_regs_offset(struct pt_regs *regs, int regno);
+int pt_regs_offset(int regno);
 
 bool insn_has_rep_prefix(struct insn *insn);
 void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
arch/x86/lib/insn-eval.c +2 -2
index e03eeec55cfe..7b46eb717066 100644
@@ -437,7 +437,7 @@ static const int pt_regoff[] = {
 #endif
 };
 
-int pt_regs_offset(struct pt_regs *regs, int regno)
+int pt_regs_offset(int regno)
 {
 	if ((unsigned)regno < ARRAY_SIZE(pt_regoff))
 		return pt_regoff[regno];
@@ -527,7 +527,7 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs,
 	if (regno < 0)
 		return regno;
 
-	return pt_regs_offset(regs, regno);
+	return pt_regs_offset(regno);
 }
 
 /**
arch/x86/mm/extable.c +1 -1
index 2fdc1f1f5adb..b9a34de9181d 100644
@@ -15,7 +15,7 @@
 
 static inline unsigned long *pt_regs_nr(struct pt_regs *regs, int nr)
 {
-	int reg_offset = pt_regs_offset(regs, nr);
+	int reg_offset = pt_regs_offset(nr);
 	static unsigned long __dummy;
 
 	if (WARN_ON_ONCE(reg_offset < 0))
Signature · 1 line
2.51.1
author
#2 lore raw

PATCH 2/5 x86/insn-eval: Remove regs arg from get_reg_offset

In reply to Jiri Olsa

It's not used, get_reg_offset returns only offset to struct pt_regs, not the actual register values.

---
 arch/x86/lib/insn-eval.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
arch/x86/lib/insn-eval.c +7 -8
index 7b46eb717066..8b9c2b90d66e 100644
@@ -519,8 +519,7 @@ static int get_regno(struct insn *insn, enum reg_type type)
 	return regno;
 }
 
-static int get_reg_offset(struct insn *insn, struct pt_regs *regs,
-			  enum reg_type type)
+static int get_reg_offset(struct insn *insn, enum reg_type type)
 {
 	int regno = get_regno(insn, type);
 
@@ -861,7 +860,7 @@ int insn_get_code_seg_params(struct pt_regs *regs)
  */
 int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs)
 {
-	return get_reg_offset(insn, regs, REG_TYPE_RM);
+	return get_reg_offset(insn, REG_TYPE_RM);
 }
 
 /**
@@ -876,7 +875,7 @@ int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs)
  */
 int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs)
 {
-	return get_reg_offset(insn, regs, REG_TYPE_REG);
+	return get_reg_offset(insn, REG_TYPE_REG);
 }
 
 /**
@@ -982,7 +981,7 @@ static int get_eff_addr_reg(struct insn *insn, struct pt_regs *regs,
 	if (X86_MODRM_MOD(insn->modrm.value) != 3)
 		return -EINVAL;
 
-	*regoff = get_reg_offset(insn, regs, REG_TYPE_RM);
+	*regoff = get_reg_offset(insn, REG_TYPE_RM);
 	if (*regoff < 0)
 		return -EINVAL;
 
@@ -1035,7 +1034,7 @@ static int get_eff_addr_modrm(struct insn *insn, struct pt_regs *regs,
 	if (X86_MODRM_MOD(insn->modrm.value) > 2)
 		return -EINVAL;
 
-	*regoff = get_reg_offset(insn, regs, REG_TYPE_RM);
+	*regoff = get_reg_offset(insn, REG_TYPE_RM);
 
 	/*
 	 * -EDOM means that we must ignore the address_offset. In such a case,
@@ -1181,8 +1180,8 @@ static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs,
 	if (!insn->sib.nbytes)
 		return -EINVAL;
 
-	*base_offset = get_reg_offset(insn, regs, REG_TYPE_BASE);
-	indx_offset = get_reg_offset(insn, regs, REG_TYPE_INDEX);
+	*base_offset = get_reg_offset(insn, REG_TYPE_BASE);
+	indx_offset = get_reg_offset(insn, REG_TYPE_INDEX);
 
 	/*
 	 * Negative values in the base and index offset means an error when
Signature · 1 line
2.51.1
author
#3 lore raw

PATCH 3/5 x86/insn-eval: Remove regs arg from insn_get_modrm_rm_off

In reply to Jiri Olsa

It's not used, insn_get_modrm_rm_off returns only offset to struct pt_regs, not the actual register values.

---
 arch/x86/coco/sev/vc-handle.c    | 2 +-
 arch/x86/include/asm/insn-eval.h | 2 +-
 arch/x86/kernel/cfi.c            | 2 +-
 arch/x86/kernel/umip.c           | 2 +-
 arch/x86/lib/insn-eval.c         | 5 ++---
 5 files changed, 6 insertions(+), 7 deletions(-)
arch/x86/coco/sev/vc-handle.c +1 -1
index f08c7505ed82..fd81bbbd8af6 100644
@@ -467,7 +467,7 @@ static long *vc_insn_get_rm(struct es_em_ctxt *ctxt)
 	int offset;
 
 	reg_array = (long *)ctxt->regs;
-	offset    = insn_get_modrm_rm_off(&ctxt->insn, ctxt->regs);
+	offset    = insn_get_modrm_rm_off(&ctxt->insn);
 
 	if (offset < 0)
 		return NULL;
arch/x86/include/asm/insn-eval.h +1 -1
index 6b592040bda4..500654d9eaeb 100644
@@ -19,7 +19,7 @@ int pt_regs_offset(int regno);
 
 bool insn_has_rep_prefix(struct insn *insn);
 void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
-int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs);
+int insn_get_modrm_rm_off(struct insn *insn);
 int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
 unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs);
 unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
arch/x86/kernel/cfi.c +1 -1
index 638eb5c933e0..3cf944cbd7ef 100644
@@ -52,7 +52,7 @@ static bool decode_cfi_insn(struct pt_regs *regs, unsigned long *target,
 		return false;
 
 	/* Read the target address from the register. */
-	offset = insn_get_modrm_rm_off(&insn, regs);
+	offset = insn_get_modrm_rm_off(&insn);
 	if (offset < 0)
 		return false;
 
arch/x86/kernel/umip.c +1 -1
index d432f3824f0c..7aeb405237ac 100644
@@ -388,7 +388,7 @@ bool fixup_umip_exception(struct pt_regs *regs)
 	 * register.
 	 */
 	if (X86_MODRM_MOD(insn.modrm.value) == 3) {
-		reg_offset = insn_get_modrm_rm_off(&insn, regs);
+		reg_offset = insn_get_modrm_rm_off(&insn);
 
 		/*
 		 * Negative values are usually errors. In memory addressing,
arch/x86/lib/insn-eval.c +2 -3
index 8b9c2b90d66e..71f58d437253 100644
@@ -581,7 +581,7 @@ static int get_reg_offset_16(struct insn *insn, struct pt_regs *regs,
 
 	/* Operand is a register, use the generic function. */
 	if (X86_MODRM_MOD(insn->modrm.value) == 3) {
-		*offs1 = insn_get_modrm_rm_off(insn, regs);
+		*offs1 = insn_get_modrm_rm_off(insn);
 		*offs2 = -EDOM;
 		return 0;
 	}
@@ -849,7 +849,6 @@ int insn_get_code_seg_params(struct pt_regs *regs)
 /**
  * insn_get_modrm_rm_off() - Obtain register in r/m part of the ModRM byte
  * @insn:	Instruction containing the ModRM byte
- * @regs:	Register values as seen when entering kernel mode
  *
  * Returns:
  *
@@ -858,7 +857,7 @@ int insn_get_code_seg_params(struct pt_regs *regs)
  * cases, the returned value can be -EDOM to indicate that the particular value
  * of ModRM does not refer to a register and shall be ignored.
  */
-int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs)
+int insn_get_modrm_rm_off(struct insn *insn)
 {
 	return get_reg_offset(insn, REG_TYPE_RM);
 }
Signature · 1 line
2.51.1
author
#4 lore raw

PATCH 4/5 x86/insn-eval: Remove regs arg from insn_get_modrm_reg_off

In reply to Jiri Olsa

It's not used, insn_get_modrm_reg_off returns only offset to struct pt_regs, not the actual register values.

---
 arch/x86/include/asm/insn-eval.h | 2 +-
 arch/x86/lib/insn-eval.c         | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/include/asm/insn-eval.h +1 -1
index 500654d9eaeb..63866ac12a08 100644
@@ -20,7 +20,7 @@ int pt_regs_offset(int regno);
 bool insn_has_rep_prefix(struct insn *insn);
 void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
 int insn_get_modrm_rm_off(struct insn *insn);
-int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
+int insn_get_modrm_reg_off(struct insn *insn);
 unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs);
 unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
 int insn_get_code_seg_params(struct pt_regs *regs);
arch/x86/lib/insn-eval.c +2 -3
index 71f58d437253..56563a5c4b42 100644
@@ -865,14 +865,13 @@ int insn_get_modrm_rm_off(struct insn *insn)
 /**
  * insn_get_modrm_reg_off() - Obtain register in reg part of the ModRM byte
  * @insn:	Instruction containing the ModRM byte
- * @regs:	Register values as seen when entering kernel mode
  *
  * Returns:
  *
  * The register indicated by the reg part of the ModRM byte. The
  * register is obtained as an offset from the base of pt_regs.
  */
-int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs)
+int insn_get_modrm_reg_off(struct insn *insn)
 {
 	return get_reg_offset(insn, REG_TYPE_REG);
 }
@@ -891,7 +890,7 @@ unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs)
 {
 	int offset;
 
-	offset = insn_get_modrm_reg_off(insn, regs);
+	offset = insn_get_modrm_reg_off(insn);
 	if (offset < 0)
 		return NULL;
 	return (void *)regs + offset;
Signature · 1 line
2.51.1
author
#5 lore raw

PATCH 5/5 x86/insn-eval: Remove regs arg from get_reg_offset_16

In reply to Jiri Olsa

It's not used, get_reg_offset_16 returns only offset to struct pt_regs, not the actual register values.

---
 arch/x86/lib/insn-eval.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/lib/insn-eval.c +2 -4
index 56563a5c4b42..4d8878092330 100644
@@ -532,7 +532,6 @@ static int get_reg_offset(struct insn *insn, enum reg_type type)
 /**
  * get_reg_offset_16() - Obtain offset of register indicated by instruction
  * @insn:	Instruction containing ModRM byte
- * @regs:	Register values as seen when entering kernel mode
  * @offs1:	Offset of the first operand register
  * @offs2:	Offset of the second operand register, if applicable
  *
@@ -546,8 +545,7 @@ static int get_reg_offset(struct insn *insn, enum reg_type type)
  *
  * 0 on success, -EINVAL on error.
  */
-static int get_reg_offset_16(struct insn *insn, struct pt_regs *regs,
-			     int *offs1, int *offs2)
+static int get_reg_offset_16(struct insn *insn, int *offs1, int *offs2)
 {
 	/*
 	 * 16-bit addressing can use one or two registers. Specifics of
@@ -1100,7 +1098,7 @@ static int get_eff_addr_modrm_16(struct insn *insn, struct pt_regs *regs,
 	if (X86_MODRM_MOD(insn->modrm.value) > 2)
 		return -EINVAL;
 
-	ret = get_reg_offset_16(insn, regs, &addr_offset1, &addr_offset2);
+	ret = get_reg_offset_16(insn, &addr_offset1, &addr_offset2);
 	if (ret < 0)
 		return -EINVAL;
 
Signature · 1 line
2.51.1
maintainer Acked-by on v1 1/5
#6 lore raw
In reply to Jiri Olsa
Quoted 19 lines · Jiri Olsa

hi,
regs argument is not used in several insn-eval functions, removing it.

I have some changes based on these functions and it feels wrong to pass NULL in regs argument. Also I don't want to send 5 extra patches with my other change, so sending this separately.

thanks,
jirka

---
Jiri Olsa (5):
x86/insn-eval: Remove regs arg from pt_regs_offset x86/insn-eval: Remove regs arg from get_reg_offset x86/insn-eval: Remove regs arg from insn_get_modrm_rm_off x86/insn-eval: Remove regs arg from insn_get_modrm_reg_off x86/insn-eval: Remove regs arg from get_reg_offset_16

Quoted 7 lines
 arch/x86/coco/sev/vc-handle.c    |  2 +-
 arch/x86/include/asm/insn-eval.h |  6 +++---
 arch/x86/kernel/cfi.c            |  2 +-
 arch/x86/kernel/umip.c           |  2 +-
 arch/x86/lib/insn-eval.c         | 35 +++++++++++++++--------------------
 arch/x86/mm/extable.c            |  2 +-
 6 files changed, 22 insertions(+), 27 deletions(-)