From: leif.lindholm@arm.com (Leif Lindholm)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/4] Add condition code checking to SWP emulation handler.
Date: Thu, 08 Dec 2011 17:32:06 +0000 [thread overview]
Message-ID: <20111208173204.7572.16929.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20111208173100.7572.9099.stgit@localhost6.localdomain6>
This patch fixes two separate issues with the SWP emulation handler:
1: Certain processors implementing ARMv7-A can (legally) take an
undef exception even when the condition code would have meant that
the instruction should not have been executed.
2: Opcodes with all flags set (condition code = 0xf) have been reused
in recent, and not-so-recent, versions of the ARM architecture to
implement unconditional extensions to the instruction set. The
existing code would still have processed any undefs triggered by
executing an opcode with such a value.
This patch uses the new generic ARM instruction set condition code
checks to implement proper handling of these situations.
Signed-off-by: Leif Lindholm <leif.lindholm@arm.com>
---
arch/arm/kernel/swp_emulate.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/arch/arm/kernel/swp_emulate.c b/arch/arm/kernel/swp_emulate.c
index 5f452f8..6a5210e 100644
--- a/arch/arm/kernel/swp_emulate.c
+++ b/arch/arm/kernel/swp_emulate.c
@@ -25,6 +25,7 @@
#include <linux/syscalls.h>
#include <linux/perf_event.h>
+#include <asm/opcodes.h>
#include <asm/traps.h>
#include <asm/uaccess.h>
@@ -185,6 +186,17 @@ static int swp_handler(struct pt_regs *regs, unsigned int instr)
perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->ARM_pc);
+ res = arm_check_condition(instr, regs->ARM_cpsr);
+ switch (res) {
+ case ARM_OPCODE_CONDTEST_FAIL:
+ /* Condition failed - return to next instruction */
+ regs->ARM_pc += 4;
+ return 0;
+ case ARM_OPCODE_CONDTEST_UNCOND:
+ /* If unconditional encoding - not a SWP, undef */
+ return -EFAULT;
+ }
+
if (current->pid != previous_pid) {
pr_debug("\"%s\" (%ld) uses deprecated SWP{B} instruction\n",
current->comm, (unsigned long)current->pid);
next prev parent reply other threads:[~2011-12-08 17:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-08 17:31 [PATCH 0/4] Add generic ARM ISA condition code check Leif Lindholm
2011-12-08 17:31 ` [PATCH 1/4] Add generic ARM instruction set condition code checks Leif Lindholm
2011-12-09 15:36 ` Will Deacon
2011-12-09 17:50 ` Leif Lindholm
2011-12-08 17:31 ` [PATCH 2/4] Use generic ARM instruction set condition code checks for nwfpe Leif Lindholm
2011-12-08 17:32 ` Leif Lindholm [this message]
2011-12-09 16:06 ` [PATCH 3/4] Add condition code checking to SWP emulation handler Will Deacon
2011-12-08 17:32 ` [PATCH 4/4] Use generic ARM instruction set condition code checks for kprobes Leif Lindholm
2011-12-09 15:54 ` Will Deacon
2011-12-09 16:17 ` Leif Lindholm
2011-12-09 16:40 ` Will Deacon
2011-12-09 17:48 ` Leif Lindholm
2011-12-09 18:05 ` Jon Medhurst (Tixy)
2011-12-09 18:26 ` Leif Lindholm
2011-12-09 18:26 ` Leif Lindholm
2011-12-09 15:27 ` [PATCH 0/4] Add generic ARM ISA condition code check Will Deacon
2011-12-09 15:29 ` Dave Martin
-- strict thread matches above, loose matches on Subject: below --
2011-12-09 18:54 [PATCH 0/4] Add generic ARM ISA condition code check v3 Leif Lindholm
2011-12-09 18:54 ` [PATCH 3/4] Add condition code checking to SWP emulation handler Leif Lindholm
2011-12-10 13:22 ` Will Deacon
2011-11-25 17:19 [PATCH 0/4] Add generic ARM ISA condition code checks Leif Lindholm
2011-11-25 17:19 ` [PATCH 3/4] Add condition code checking to SWP emulation handler Leif Lindholm
2011-11-30 17:01 ` Dave Martin
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=20111208173204.7572.16929.stgit@localhost6.localdomain6 \
--to=leif.lindholm@arm.com \
--cc=linux-arm-kernel@lists.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;
as well as URLs for NNTP newsgroup(s).