mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: linux-kernel@vger.kernel.org
Cc: Juergen Gross <jgross@suse.com>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH v2 18/21] objtool: Allow multiple pv_ops arrays
Date: Wed, 17 Sep 2025 16:52:17 +0200	[thread overview]
Message-ID: <20250917145220.31064-19-jgross@suse.com> (raw)
In-Reply-To: <20250917145220.31064-1-jgross@suse.com>

Having a single large pv_ops array has the main disadvantage of needing
all prototypes of the single array members in one header file. This is
adding up to the need to include lots of otherwise unrelated headers.

In order to allow multiple smaller pv_ops arrays dedicated to one
area of the kernel each, allow multiple arrays in objtool.

For better performance limit the possible names of the arrays to
start with "pv_ops".

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- new patch
---
 tools/objtool/arch/x86/decode.c       |  8 ++-
 tools/objtool/check.c                 | 74 +++++++++++++++++++++------
 tools/objtool/include/objtool/check.h |  2 +
 3 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 98c4713c1b09..4117a2c6f486 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -649,10 +649,14 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 			immr = find_reloc_by_dest(elf, (void *)sec, offset+3);
 			disp = find_reloc_by_dest(elf, (void *)sec, offset+7);
 
-			if (!immr || strcmp(immr->sym->name, "pv_ops"))
+			if (!immr || strncmp(immr->sym->name, "pv_ops", 6))
 				break;
 
-			idx = (reloc_addend(immr) + 8) / sizeof(void *);
+			idx = pv_ops_idx_off(immr->sym->name);
+			if (idx < 0)
+				break;
+
+			idx += (reloc_addend(immr) + 8) / sizeof(void *);
 
 			func = disp->sym;
 			if (disp->sym->type == STT_SECTION)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index e2736b462c90..ca6ad92618d8 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -542,21 +542,57 @@ static int decode_instructions(struct objtool_file *file)
 }
 
 /*
- * Read the pv_ops[] .data table to find the static initialized values.
+ * Known pv_ops*[] arrays.
  */
-static int add_pv_ops(struct objtool_file *file, const char *symname)
+static struct {
+	const char *name;
+	int idx_off;
+} pv_ops_tables[] = {
+	{ .name = "pv_ops", },
+	{ .name = NULL, .idx_off = -1 }
+};
+
+/*
+ * Get index offset for a pv_ops* array.
+ */
+int pv_ops_idx_off(const char *symname)
+{
+	int idx;
+
+	for (idx = 0; pv_ops_tables[idx].name; idx++) {
+		if (!strcmp(symname, pv_ops_tables[idx].name))
+			break;
+	}
+
+	return pv_ops_tables[idx].idx_off;
+}
+
+/*
+ * Read a pv_ops*[] .data table to find the static initialized values.
+ */
+static int add_pv_ops(struct objtool_file *file, int pv_ops_idx)
 {
 	struct symbol *sym, *func;
 	unsigned long off, end;
 	struct reloc *reloc;
-	int idx;
+	int idx, idx_off;
+	const char *symname;
 
+	symname = pv_ops_tables[pv_ops_idx].name;
 	sym = find_symbol_by_name(file->elf, symname);
-	if (!sym)
-		return 0;
+	if (!sym) {
+		ERROR("Unknown pv_ops array %s", symname);
+		return -1;
+	}
 
 	off = sym->offset;
 	end = off + sym->len;
+	idx_off = pv_ops_tables[pv_ops_idx].idx_off;
+	if (idx_off < 0) {
+		ERROR("pv_ops array %s has unknown index offset", symname);
+		return -1;
+	}
+
 	for (;;) {
 		reloc = find_reloc_by_dest_range(file->elf, sym->sec, off, end - off);
 		if (!reloc)
@@ -574,7 +610,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 + idx_off, func))
 			return -1;
 
 		off = reloc_offset(reloc) + 1;
@@ -590,11 +626,6 @@ 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",
-		NULL,
-	};
-	const char *pv_ops;
 	struct symbol *sym;
 	int idx, nr, ret;
 
@@ -603,11 +634,20 @@ static int init_pv_ops(struct objtool_file *file)
 
 	file->pv_ops = NULL;
 
-	sym = find_symbol_by_name(file->elf, "pv_ops");
-	if (!sym)
+	nr = 0;
+	for (idx = 0; pv_ops_tables[idx].name; idx++) {
+		sym = find_symbol_by_name(file->elf, pv_ops_tables[idx].name);
+		if (!sym) {
+			pv_ops_tables[idx].idx_off = -1;
+			continue;
+		}
+		pv_ops_tables[idx].idx_off = nr;
+		nr += sym->len / sizeof(unsigned long);
+	}
+
+	if (nr == 0)
 		return 0;
 
-	nr = sym->len / sizeof(unsigned long);
 	file->pv_ops = calloc(sizeof(struct pv_state), nr);
 	if (!file->pv_ops) {
 		ERROR_GLIBC("calloc");
@@ -617,8 +657,10 @@ 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_tables[idx].name; idx++) {
+		if (pv_ops_tables[idx].idx_off < 0)
+			continue;
+		ret = add_pv_ops(file, idx);
 		if (ret)
 			return ret;
 	}
diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/objtool/check.h
index 00fb745e7233..51f2396c5943 100644
--- a/tools/objtool/include/objtool/check.h
+++ b/tools/objtool/include/objtool/check.h
@@ -125,4 +125,6 @@ struct instruction *next_insn_same_sec(struct objtool_file *file, struct instruc
 	     insn && insn->sec == _sec;					\
 	     insn = next_insn_same_sec(file, insn))
 
+int pv_ops_idx_off(const char *symname);
+
 #endif /* _CHECK_H */
-- 
2.51.0


  parent reply	other threads:[~2025-09-17 14:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17 14:51 [PATCH v2 00/21] paravirt: cleanup and reorg Juergen Gross
2025-09-17 14:52 ` [PATCH v2 01/21] x86/paravirt: Remove not needed includes of paravirt.h Juergen Gross
2025-09-18  3:18   ` kernel test robot
2025-09-17 14:52 ` [PATCH v2 02/21] x86/paravirt: Remove some unneeded struct declarations Juergen Gross
2025-09-17 14:52 ` [PATCH v2 03/21] x86/paravirt: Remove PARAVIRT_DEBUG config option Juergen Gross
2025-09-17 14:52 ` [PATCH v2 04/21] x86/paravirt: Move thunk macros to paravirt_types.h Juergen Gross
2025-09-17 14:52 ` [PATCH v2 05/21] paravirt: Remove asm/paravirt_api_clock.h Juergen Gross
2025-09-17 14:52 ` [PATCH v2 06/21] sched: Move clock related paravirt code to kernel/sched Juergen Gross
2025-09-17 14:52 ` [PATCH v2 07/21] arm/paravirt: Use common code for paravirt_steal_clock() Juergen Gross
2025-09-17 14:52 ` [PATCH v2 08/21] arm64/paravirt: " Juergen Gross
2025-09-17 14:52 ` [PATCH v2 09/21] loongarch/paravirt: " Juergen Gross
2025-09-17 14:52 ` [PATCH v2 10/21] riscv/paravirt: " Juergen Gross
2025-09-24 17:08   ` Andrew Jones
2025-09-17 14:52 ` [PATCH v2 11/21] x86/paravirt: " Juergen Gross
2025-09-17 14:52 ` [PATCH v2 12/21] x86/paravirt: Move paravirt_sched_clock() related code into tsc.c Juergen Gross
2025-09-17 14:52 ` [PATCH v2 13/21] x86/paravirt: Introduce new paravirt-base.h header Juergen Gross
2025-09-17 14:52 ` [PATCH v2 14/21] x86/paravirt: Move pv_native_*() prototypes to paravirt.c Juergen Gross
2025-09-17 14:52 ` [PATCH v2 15/21] x86/xen: Drop xen_irq_ops Juergen Gross
2025-09-17 14:52 ` [PATCH v2 16/21] x86/xen: Drop xen_cpu_ops Juergen Gross
2025-09-17 14:52 ` [PATCH v2 17/21] x86/xen: Drop xen_mmu_ops Juergen Gross
2025-09-17 14:52 ` Juergen Gross [this message]
2025-09-17 14:52 ` [PATCH v2 19/21] x86/paravirt: Allow pv-calls outside paravirt.h Juergen Gross
2025-09-17 14:52 ` [PATCH v2 20/21] x86/paravirt: Specify pv_ops array in paravirt macros Juergen Gross
2025-09-17 14:52 ` [PATCH v2 21/21] x86/pvlocks: Move paravirt spinlock functions into own header Juergen Gross
2025-09-18  2:45   ` kernel test robot
2025-09-18  5:56     ` Juergen Gross
2025-09-18  5:38   ` kernel test robot
2026-02-20  4:10 ` [PATCH v2 00/21] paravirt: cleanup and reorg patchwork-bot+linux-riscv

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=20250917145220.31064-19-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.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®