mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: linux-kernel@vger.kernel.org, mingo@kernel.org,
	jpoimboe@kernel.org, peterz@infradead.org
Cc: alexandre.chartre@oracle.com
Subject: [PATCH v3 26/28] objtool: Get the destination name of a PV call
Date: Wed, 12 Nov 2025 17:03:13 +0100	[thread overview]
Message-ID: <20251112160315.2207947-27-alexandre.chartre@oracle.com> (raw)
In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com>

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@oracle.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


  parent reply	other threads:[~2025-11-12 16:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12 16:02 [PATCH v3 00/28] objtool: Function validation tracing Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 01/28] objtool: Move disassembly functions to a separated file Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 02/28] objtool: Create disassembly context Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 03/28] objtool: Disassemble code with libopcodes instead of running objdump Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 04/28] tool build: Remove annoying newline in build output Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 05/28] objtool: Print symbol during disassembly Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 06/28] objtool: Store instruction disassembly result Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 07/28] objtool: Disassemble instruction on warning or backtrace Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 08/28] objtool: Extract code to validate instruction from the validate branch loop Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 09/28] objtool: Record symbol name max length Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 10/28] objtool: Add option to trace function validation Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 11/28] objtool: Trace instruction state changes during " Alexandre Chartre
2025-11-12 16:02 ` [PATCH v3 12/28] objtool: Improve register reporting " Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 13/28] objtool: Identify the different types of alternatives Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 14/28] objtool: Improve tracing of alternative instructions Alexandre Chartre
2025-11-13  5:14   ` kernel test robot
2025-11-12 16:03 ` [PATCH v3 15/28] objtool: Do not validate IBT for .return_sites and .call_sites Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 16/28] objtool: Add the --disas=<function-pattern> action Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 17/28] objtool: Print headers for alternatives Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 18/28] objtool: Disassemble group alternatives Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 19/28] objtool: Print addresses with alternative instructions Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 20/28] objtool: Disassemble exception table alternatives Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 21/28] objtool: Disassemble jump " Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 22/28] objtool: Fix address references in alternatives Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 23/28] objtool: Provide access to feature and flags of group alternatives Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 24/28] objtool: Function to get the name of a CPU feature Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 25/28] objtool: Improve naming of group alternatives Alexandre Chartre
2025-11-13  5:15   ` kernel test robot
2025-11-12 16:03 ` Alexandre Chartre [this message]
2025-11-12 16:03 ` [PATCH v3 27/28] objtool: Improve the disassembly of the pv_ops call Alexandre Chartre
2025-11-12 16:03 ` [PATCH v3 28/28] objtool: Print single line for alternatives with one instruction Alexandre Chartre
2025-11-13  9:21 ` [PATCH v3 00/28] objtool: Function validation tracing Alexandre Chartre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251112160315.2207947-27-alexandre.chartre@oracle.com \
    --to=alexandre.chartre@oracle.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®