Dave Martin | 8 Aug 2012 14:23
Favicon

[PATCH v2 REPOST 0/4] ARM: opcodes: Facilitate custom opcode injection

I stopped pushing this series because it was not clear whether it would
be immediately useful.

Since it looks again like this series might be useful to some people
(KVM and Xen guys in particular), it seems worth reposting.  I've
rebased it and done some simple build testing.  It looks like it is
still working OK for ARM and Thumb in LE and BE8 configurations. 

Changes since v2:

 * Rebased againt v3.6-rc1 for repost.  No other changes.

Changes since v1:

 * This update contains minor typo fixes and extra clarification
   in the commit messages.  There are no functional changes.

Thanks to Nico for his review.

Original cover letter:

Since my "uniform assembler" series had some problems and did not
meet with widespread agreement, this can't be used as a basis for a
mechanism to safely inject custom instruction opcodes (which was my
immediate reason for writing those patchse).

This series follows a more conventional approach to achieve the
goal for safe opcode injection across all kernel endianness and
instruction set configurations.

(Continue reading)

Dave Martin | 8 Aug 2012 14:23
Favicon

[PATCH v2 REPOST 3/4] ARM: opcodes: Add helpers for emitting custom opcodes

This patch adds some __inst_() macros for injecting custom opcodes
in assembler (both inline and in .S files).  They should make it
easier and cleaner to get things right in little-/big-
endian/ARM/Thumb-2 kernels without a lot of #ifdefs.

This pure-preprocessor approach is preferred over the alternative
method of wedging extra assembler directives into the assembler
input using top-level asm() blocks, since there is no way to
guarantee that the compiler won't reorder those with respect to
each other or with respect to non-toplevel asm() blocks, unless
-fno-toplevel-reorder is passed (which is in itself somewhat
undesirable because it defeats some potential optimisations).

Currently <asm/unified.h> _does_ silently rely on the compiler not
reordering at the top level, but it seems better to avoid adding
extra code which depends on this if the same result can be achieved
in another way.

Signed-off-by: Dave Martin <dave.martin <at> linaro.org>
Acked-by: Nicolas Pitre <nico <at> linaro.org>
---
 arch/arm/include/asm/opcodes.h |   69 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h
index f57e417..f7937e1 100644
--- a/arch/arm/include/asm/opcodes.h
+++ b/arch/arm/include/asm/opcodes.h
 <at>  <at>  -156,4 +156,73  <at>  <at>  extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
 	| ___asm_opcode_identity32(___asm_opcode_identity16(second))	    \
(Continue reading)

Dave Martin | 8 Aug 2012 14:23
Favicon

[PATCH v2 REPOST 2/4] ARM: opcodes: Make opcode byteswapping macros assembly-compatible

Most of the existing macros don't work with assembler, due to the
use of type casts and C functions from <linux/swab.h>.

This patch abstracts out those operations and provides simple
explicit versions for use in assembly code.

__opcode_is_thumb32() and __opcode_is_thumb16() are also converted
to do bitmask-based testing to avoid confusion if these are used in
assembly code (the assembler typically treats all arithmetic values
as signed).

These changes avoid the need for the compiler to pre-evaluate
constant expressions used to generate opcodes.  By ensuring that
the forms of these expressions can be evaluated directly by the
assembler, we can just stringify the expressions directly into the
asm during the preprocessing pass.  The alternative approach
(passing the evaluated expression via an inline asm "i" constraint)
gets painful because the contents of the asm and the constraints
must be kept in sync.  This makes the resulting macros awkward to
use.

Retaining the C forms of the macros allows more efficient code to
be generated when opcodes are generated programmatically at run-
time, but there is no way to embed run-time-generated opcodes in
asm() blocks.

Signed-off-by: Dave Martin <dave.martin <at> linaro.org>
Acked-by: Nicolas Pitre <nico <at> linaro.org>
---
 arch/arm/include/asm/opcodes.h |   97 +++++++++++++++++++++++++++++++++------
(Continue reading)

Dave Martin | 8 Aug 2012 14:23
Favicon

[PATCH v2 REPOST 1/4] ARM: opcodes: Don't define the thumb32 byteswapping macros for BE32

The existing __mem_to_opcode_thumb32() is incorrect for BE32
platforms.  However, these don't support Thumb-2 kernels, so this
option is not so relevant for those platforms anyway.

This operation is complicated by the lack of unaligned memory
access support prior to ARMv6.

Rather than provide a "working" macro which will probably won't get
used (or worse, will get misused), this patch removes the macro for
BE32 kernels.  People manipulating Thumb opcodes prior to ARMv6
should almost certainly be splitting these operations into
halfwords anyway, using __opcode_thumb32_{first,second,compose}()
and the 16-bit opcode transformations.

Signed-off-by: Dave Martin <dave.martin <at> linaro.org>
Acked-by: Nicolas Pitre <nico <at> linaro.org>
---
 arch/arm/include/asm/opcodes.h |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h
index 19c48de..6bf54f9 100644
--- a/arch/arm/include/asm/opcodes.h
+++ b/arch/arm/include/asm/opcodes.h
 <at>  <at>  -49,18 +49,31  <at>  <at>  extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
 #include <linux/swab.h>

 #ifdef CONFIG_CPU_ENDIAN_BE8
+
 #define __opcode_to_mem_arm(x) swab32(x)
(Continue reading)

Dave Martin | 8 Aug 2012 14:23
Favicon

[PATCH v2 REPOST 4/4] ARM: opcodes: Opcode definitions for the Virtualization Extensions

For now, this patch just adds a definition for the HVC instruction.
More can be added here later, as needed.

Now that we have a real example of how to use the opcode injection
macros properly, this patch also adds a cross-reference from the
explanation in opcodes.h (since without an example, figuring out
how to use the macros is not that easy).

Signed-off-by: Dave Martin <dave.martin <at> linaro.org>
Acked-by: Nicolas Pitre <nico <at> linaro.org>
---
 arch/arm/include/asm/opcodes-virt.h |   29 +++++++++++++++++++++++++++++
 arch/arm/include/asm/opcodes.h      |    2 ++
 2 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/opcodes-virt.h

diff --git a/arch/arm/include/asm/opcodes-virt.h b/arch/arm/include/asm/opcodes-virt.h
new file mode 100644
index 0000000..b85665a
--- /dev/null
+++ b/arch/arm/include/asm/opcodes-virt.h
 <at>  <at>  -0,0 +1,29  <at>  <at> 
+/*
+ * opcodes-virt.h: Opcode definitions for the ARM virtualization extensions
+ * Copyright (C) 2012  Linaro Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
(Continue reading)


Gmane