lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251112160315.2207947-27-alexandre.chartre@oracle.com>
Date: Wed, 12 Nov 2025 17:03:13 +0100
From: Alexandre Chartre <alexandre.chartre@...cle.com>
To: linux-kernel@...r.kernel.org, mingo@...nel.org, jpoimboe@...nel.org,
        peterz@...radead.org
Cc: alexandre.chartre@...cle.com
Subject: [PATCH v3 26/28] objtool: Get the destination name of a PV call

Add a function to get the destination name of a PV call. The destination
depends on the content of the pv_ops[] array which can dynamically change
at runtime.

However there are cases where we can speculate on the content of pv_ops[]
and provide the function name corresponding to the call. For example,
when an alternative depends on the X86_FEATURE_XENPV feature then we know
that the corresponding code will be using the Xen pv_ops[] values.

If we can't figure out the exact content of pv_ops[] then provide the
function name from the default pv_ops[] array.

Signed-off-by: Alexandre Chartre <alexandre.chartre@...cle.com>
---
 tools/objtool/arch/x86/decode.c         |  2 +-
 tools/objtool/check.c                   | 99 ++++++++++++++++++++++---
 tools/objtool/include/objtool/check.h   |  4 +
 tools/objtool/include/objtool/elf.h     |  7 ++
 tools/objtool/include/objtool/objtool.h |  6 +-
 tools/objtool/objtool.c                 | 27 ++++++-
 6 files changed, 129 insertions(+), 16 deletions(-)

diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index d651d8921ab47..9fef0d94517ca 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -685,7 +685,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 				return -1;
 			}
 
-			objtool_pv_add(file, idx, func);
+			objtool_pv_add(file, idx, func, PV_MODE_DEFAULT);
 		}
 
 		break;
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 1aad636a8d630..7978b3feb0cb2 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -538,7 +538,8 @@ static int decode_instructions(struct objtool_file *file)
 /*
  * Read the pv_ops[] .data table to find the static initialized values.
  */
-static int add_pv_ops(struct objtool_file *file, const char *symname)
+static int add_pv_ops(struct objtool_file *file, const char *symname,
+		      enum pv_mode pv_mode)
 {
 	struct symbol *sym, *func;
 	unsigned long off, end;
@@ -568,7 +569,7 @@ static int add_pv_ops(struct objtool_file *file, const char *symname)
 			return -1;
 		}
 
-		if (objtool_pv_add(file, idx, func))
+		if (objtool_pv_add(file, idx, func, pv_mode))
 			return -1;
 
 		off = reloc_offset(reloc) + 1;
@@ -584,24 +585,27 @@ static int add_pv_ops(struct objtool_file *file, const char *symname)
  */
 static int init_pv_ops(struct objtool_file *file)
 {
-	static const char *pv_ops_tables[] = {
-		"pv_ops",
-		"xen_cpu_ops",
-		"xen_irq_ops",
-		"xen_mmu_ops",
-		NULL,
+	static struct {
+		const char *name;
+		enum pv_mode mode;
+	} pv_ops_tables[] = {
+		{ "pv_ops",		PV_MODE_DEFAULT },
+		{ "xen_cpu_ops",	PV_MODE_XENPV },
+		{ "xen_irq_ops",	PV_MODE_XENPV },
+		{ "xen_mmu_ops",	PV_MODE_XENPV },
+		{ NULL },
 	};
 	const char *pv_ops;
 	struct symbol *sym;
 	int idx, nr, ret;
 
-	if (!opts.noinstr)
+	if (!opts.noinstr && !opts.disas)
 		return 0;
 
 	file->pv_ops = NULL;
 
 	sym = find_symbol_by_name(file->elf, "pv_ops");
-	if (!sym)
+	if (!sym || !sym->len)
 		return 0;
 
 	nr = sym->len / sizeof(unsigned long);
@@ -614,8 +618,8 @@ static int init_pv_ops(struct objtool_file *file)
 	for (idx = 0; idx < nr; idx++)
 		INIT_LIST_HEAD(&file->pv_ops[idx].targets);
 
-	for (idx = 0; (pv_ops = pv_ops_tables[idx]); idx++) {
-		ret = add_pv_ops(file, pv_ops);
+	for (idx = 0; (pv_ops = pv_ops_tables[idx].name); idx++) {
+		ret = add_pv_ops(file, pv_ops, pv_ops_tables[idx].mode);
 		if (ret)
 			return ret;
 	}
@@ -3379,6 +3383,77 @@ static bool pv_call_dest(struct objtool_file *file, struct instruction *insn)
 	return file->pv_ops[idx].clean;
 }
 
+/*
+ * Return the name of the destination of a PV call.
+ *
+ * The destination depends on the specified pv_mode. If an exact
+ * destination cannot be found then the name shows the position of
+ * the destination in the pv_ops[] array, and it is followed by
+ * the operation name for the default PV mode. For example:
+ * "pv_ops[61] ~ native_set_pte"
+ *
+ * The destination name can be followed by a '*' character if there
+ * is code that can override the pv_ops[] entry.
+ *
+ * The function returns NULL if there is no call and the operation
+ * is a NOP.
+ */
+const char *pv_call_dest_name(struct objtool_file *file,
+			      struct instruction *insn,
+			      enum pv_mode pv_mode)
+{
+	struct symbol *target_default = NULL;
+	struct symbol *target = NULL;
+	static char pvname[64];
+	const char *note = "";
+	struct reloc *reloc;
+	int idx;
+
+	reloc = insn_reloc(file, insn);
+	if (!reloc || strcmp(reloc->sym->name, "pv_ops"))
+		return NULL;
+
+	idx = (arch_dest_reloc_offset(reloc_addend(reloc)) / sizeof(void *));
+
+	if (file->pv_ops) {
+
+		target_default = file->pv_ops[idx].target_default;
+
+		switch (pv_mode) {
+
+		case PV_MODE_DEFAULT:
+			target = target_default;
+			break;
+
+		case PV_MODE_XENPV:
+			target = file->pv_ops[idx].target_xen;
+			break;
+
+		case PV_MODE_UNKNOWN:
+			break;
+		}
+
+		if (file->pv_ops[idx].target_override > 0)
+			note = " *";
+	}
+
+	if (target) {
+		if (!strcmp(target->name, "nop_func"))
+			return NULL;
+
+		snprintf(pvname, sizeof(pvname), "%s%s", target->name, note);
+
+	} else if (target_default) {
+		snprintf(pvname, sizeof(pvname), "pv_ops[%d] ~ %s%s",
+			 idx, target_default->name, note);
+	} else {
+		snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);
+	}
+
+	return pvname;
+}
+
+
 static inline bool noinstr_call_dest(struct objtool_file *file,
 				     struct instruction *insn,
 				     struct symbol *func)
diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/objtool/check.h
index c54dd0aae1f60..e352ed64f9edd 100644
--- a/tools/objtool/include/objtool/check.h
+++ b/tools/objtool/include/objtool/check.h
@@ -138,6 +138,10 @@ static inline struct symbol *insn_call_dest(struct instruction *insn)
 	return insn->_call_dest;
 }
 
+const char *pv_call_dest_name(struct objtool_file *file,
+			      struct instruction *insn,
+			      enum pv_mode pv_mode);
+
 struct instruction *find_insn(struct objtool_file *file,
 			      struct section *sec, unsigned long offset);
 
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index df8434d3b7440..1d55f5da16932 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -46,6 +46,12 @@ struct section {
 	struct reloc *relocs;
 };
 
+enum pv_mode {
+	PV_MODE_UNKNOWN,
+	PV_MODE_DEFAULT,
+	PV_MODE_XENPV,
+};
+
 struct symbol {
 	struct list_head list;
 	struct rb_node node;
@@ -72,6 +78,7 @@ struct symbol {
 	u8 ignore	     : 1;
 	u8 nocfi             : 1;
 	struct list_head pv_target;
+	enum pv_mode pv_mode;
 	struct reloc *relocs;
 	struct section *group_sec;
 };
diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/include/objtool/objtool.h
index c0dc86a78ff65..cb25bf502f2b2 100644
--- a/tools/objtool/include/objtool/objtool.h
+++ b/tools/objtool/include/objtool/objtool.h
@@ -17,6 +17,9 @@
 struct pv_state {
 	bool clean;
 	struct list_head targets;
+	struct symbol *target_default;
+	struct symbol *target_xen;
+	int target_override;
 };
 
 struct objtool_file {
@@ -41,7 +44,8 @@ struct objtool_file {
 
 struct objtool_file *objtool_open_read(const char *_objname);
 
-int objtool_pv_add(struct objtool_file *file, int idx, struct symbol *func);
+int objtool_pv_add(struct objtool_file *file, int idx, struct symbol *func,
+		   enum pv_mode pv_mode);
 
 int check(struct objtool_file *file);
 int orc_dump(const char *objname);
diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c
index 5c8b974ad0f9d..95dfef07a530f 100644
--- a/tools/objtool/objtool.c
+++ b/tools/objtool/objtool.c
@@ -44,9 +44,10 @@ struct objtool_file *objtool_open_read(const char *filename)
 	return &file;
 }
 
-int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func)
+int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func,
+		   enum pv_mode pv_mode)
 {
-	if (!opts.noinstr)
+	if (!opts.noinstr && !opts.disas)
 		return 0;
 
 	if (!f->pv_ops) {
@@ -54,6 +55,28 @@ int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func)
 		return -1;
 	}
 
+	if (opts.disas) {
+		switch (pv_mode) {
+
+		case PV_MODE_DEFAULT:
+			if (f->pv_ops[idx].target_default)
+				f->pv_ops[idx].target_override++;
+			else
+				f->pv_ops[idx].target_default = func;
+			break;
+
+		case PV_MODE_XENPV:
+			f->pv_ops[idx].target_xen = func;
+			break;
+
+		default:
+			BUG();
+		}
+	}
+
+	if (!opts.noinstr)
+		return 0;
+
 	/*
 	 * These functions will be patched into native code,
 	 * see paravirt_patch().
-- 
2.43.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ