From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Nadav Amit <nadav.amit@gmail.com>,
Andy Lutomirski <luto@kernel.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Song Liu <songliubraving@fb.com>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH 2/3] x86/alternatives: Move tp_vec
Date: Mon, 26 Aug 2019 14:51:40 +0200 [thread overview]
Message-ID: <20190826125519.798115791@infradead.org> (raw)
In-Reply-To: <20190826125138.710718863@infradead.org>
In order to allow other users to make use of the tp_vec; move it near
the text_poke_bp_batch() code, instead of keeping it in the jump_label
code.
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/include/asm/text-patching.h | 4 ++++
arch/x86/kernel/alternative.c | 3 +++
arch/x86/kernel/jump_label.c | 25 ++++++++++++-------------
3 files changed, 19 insertions(+), 13 deletions(-)
--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -60,6 +60,10 @@ extern int after_bootmem;
extern __ro_after_init struct mm_struct *poking_mm;
extern __ro_after_init unsigned long poking_addr;
+#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_loc))
+extern struct text_poke_loc tp_vec[TP_VEC_MAX];
+extern int tp_vec_nr;
+
#ifndef CONFIG_UML_X86
static inline void int3_emulate_jmp(struct pt_regs *regs, unsigned long ip)
{
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -1017,6 +1017,9 @@ int poke_int3_handler(struct pt_regs *re
}
NOKPROBE_SYMBOL(poke_int3_handler);
+struct text_poke_loc tp_vec[TP_VEC_MAX];
+int tp_vec_nr;
+
/**
* text_poke_bp_batch() -- update instructions on live kernel on SMP
* @tp: vector of instructions to patch
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -100,15 +100,12 @@ void arch_jump_label_transform(struct ju
mutex_unlock(&text_mutex);
}
-#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_loc))
-static struct text_poke_loc tp_vec[TP_VEC_MAX];
-static int tp_vec_nr;
-
bool arch_jump_label_transform_queue(struct jump_entry *entry,
enum jump_label_type type)
{
struct text_poke_loc *tp;
void *entry_code;
+ bool ret = true;
if (system_state == SYSTEM_BOOTING) {
/*
@@ -118,12 +115,15 @@ bool arch_jump_label_transform_queue(str
return true;
}
+ mutex_lock(&text_mutex);
/*
* No more space in the vector, tell upper layer to apply
* the queue before continuing.
*/
- if (tp_vec_nr == TP_VEC_MAX)
- return false;
+ if (tp_vec_nr == TP_VEC_MAX) {
+ ret = false;
+ goto unlock;
+ }
tp = &tp_vec[tp_vec_nr];
@@ -151,20 +151,19 @@ bool arch_jump_label_transform_queue(str
text_poke_loc_init(tp, entry_code, NULL, JUMP_LABEL_NOP_SIZE, NULL);
tp_vec_nr++;
+unlock:
+ mutex_unlock(&text_mutex);
- return true;
+ return ret;
}
void arch_jump_label_transform_apply(void)
{
- if (!tp_vec_nr)
- return;
-
mutex_lock(&text_mutex);
- text_poke_bp_batch(tp_vec, tp_vec_nr);
- mutex_unlock(&text_mutex);
-
+ if (tp_vec_nr)
+ text_poke_bp_batch(tp_vec, tp_vec_nr);
tp_vec_nr = 0;
+ mutex_unlock(&text_mutex);
}
static enum {
next prev parent reply other threads:[~2019-08-26 12:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-26 12:51 [PATCH 0/3] Rewrite x86/ftrace to use text_poke() Peter Zijlstra
2019-08-26 12:51 ` [PATCH 1/3] x86/alternatives: Teach text_poke_bp() to emulate instructions Peter Zijlstra
2019-08-26 12:51 ` Peter Zijlstra [this message]
2019-08-26 14:36 ` [PATCH 2/3] x86/alternatives: Move tp_vec Peter Zijlstra
2019-08-26 12:51 ` [RFC][PATCH 3/3] x86/ftrace: Use text_poke() Peter Zijlstra
2019-08-26 15:13 ` Peter Zijlstra
2019-08-26 13:04 ` [PATCH 0/3] Rewrite x86/ftrace to use text_poke() Peter Zijlstra
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=20190826125519.798115791@infradead.org \
--to=peterz@infradead.org \
--cc=bristot@redhat.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=nadav.amit@gmail.com \
--cc=songliubraving@fb.com \
--cc=x86@kernel.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®