linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	"Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH 5/5] x86: Support reverse execution
Date: Wed,  1 Apr 2015 01:20:36 +0200	[thread overview]
Message-ID: <1427844036-1325-6-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1427844036-1325-1-git-send-email-fweisbec@gmail.com>

Support reverse execution for negative number of CPUs. We might be able
to implement that deeper with the function tracer.

No-Yet-Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 arch/x86/kernel/cpu/negative.c | 28 ++++++++++++++++++++++++++++
 arch/x86/kernel/head64.c       |  4 ++++
 2 files changed, 32 insertions(+)
 create mode 100644 arch/x86/kernel/cpu/negative.c

diff --git a/arch/x86/kernel/cpu/negative.c b/arch/x86/kernel/cpu/negative.c
new file mode 100644
index 0000000..3aff473
--- /dev/null
+++ b/arch/x86/kernel/cpu/negative.c
@@ -0,0 +1,28 @@
+/* Execute function in reverse for negative CPUs */
+
+#define _ASM_RET 0xc3
+#define FUNC_MAX_SIZE 4096
+static DEFINE_PER_CPU(char, reverse_func_buf[FUNC_MAX_SIZE]);
+
+void execute_reverse_function(void *func)
+{
+	char *opcode = (char *)func;
+	int i = 0, j = FUNC_MAX_SIZE - 1;
+	void (*reverse_func)(void);
+
+	/*
+	 * Reverse copy the function.
+	 * This assumes that every opcode is sizeof(char),
+	 * there might be a few situations where that won't work
+	 * but we'll fix them as soon as they get reported by users.
+	 */
+	while (1) {
+		reverse_func_buf[j--] = opcode[i];
+		if (opcode[i++] == _ASM_RET)
+			break;
+	}
+
+	reverse_func = &reverse_func_buf[FUNC_MAX_SIZE - 1];
+	reverse_func();
+}
+
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index c4f8d46..9ed2c88 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -197,5 +197,9 @@ void __init x86_64_start_reservations(char *real_mode_data)
 
 	reserve_ebda_region();
 
+#if CONFIG_NR_CPUS >= 0
 	start_kernel();
+#else
+	execute_reverse_function(start_kernel);
+#endif
 }
-- 
2.1.4


  parent reply	other threads:[~2015-03-31 23:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-31 23:20 [PATCH 0/5] Support negative number of CPUs Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 1/5] cpu: Infrastructure for negative cpu handling Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 2/5] smp: IPI handling for negative CPU Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 3/5] cpumask: Basic negative number of CPUs handling Frederic Weisbecker
2015-03-31 23:20 ` [PATCH 4/5] init: Support negative CPUs boot and halt code Frederic Weisbecker
2015-03-31 23:20 ` Frederic Weisbecker [this message]
2015-04-01  7:35 ` [PATCH 0/5] Support negative number of CPUs Paul E. McKenney
2015-04-01  9:37 ` Borislav Petkov

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=1427844036-1325-6-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).