xen/arm32: Introduce alternative runtime patching
PATCH v4 1/1 xen/arm32: Introduce alternative runtime patching
This patch is based on the implementation of ARM64, it introduces alternative runtime patching to ARM32. This allows to patch assembly instruction at runtime to either fix hardware bugs or optimize for certain hardware features on ARM32 platform.
Xen hypervisor is using ARM execution state only on ARM32 platform, Thumb is not used. So, the Thumb only branch instructions (CBZ, CBNZ, TBB and TBH) are not considered in alternatives.
The left ARM32 branch instructions are BX, BLX, BL and B. The instruction BX is taking a register in parameter, so we don't need to rewrite it. The instructions BLX, BL and B are using the similar encoding for the offset and will avoid specific case when extracting and updating the offset.
In this patch, we include alternative.h header file to livepatch.c directly for ARM32 compilation issues. When the alternative patching config is enabled, the livepatch.c will use the alternative functions. In this case, we should include the alternative header file to this file. But for ARM64, it does not include this header file directly. It includes this header file indirectly through:sched.h->domain.h->page.h->alternative.h.
But, unfortunately, the page.h of ARM32 doesn't include alternative.h, and we don't have the reason to include it to ARM32 page.h now. So we have to include the alternative.h directly in livepatch.c.
---v3->v4:
1. Use open-code to replace the macro __AARCH32_INSN_FUNCS
2. Add code comment to explain why we can use one check to catch all the branch instructions we should handle.
--- xen/arch/arm/Kconfig | 2 +- xen/arch/arm/arm32/Makefile | 1 + xen/arch/arm/arm32/insn.c | 91 ++++++++++++++++++++++++++++++++++++++++ xen/common/livepatch.c | 1 + xen/include/asm-arm/arm32/insn.h | 71 +++++++++++++++++++++++++++++++ xen/include/asm-arm/insn.h | 2 + 6 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/arm32/insn.c create mode 100644 xen/include/asm-arm/arm32/insn.h
xen/arch/arm/Kconfig +1 -1
@@ -12,11 +12,11 @@ config ARM_32 config ARM_64 def_bool y depends on 64BIT - select HAS_ALTERNATIVE select HAS_GICV3 config ARM def_bool y + select HAS_ALTERNATIVE select HAS_ARM_HDLCD select HAS_DEVICE_TREE select HAS_MEM_ACCESS
xen/arch/arm/arm32/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(EARLY_PRINTK) += debug.o obj-y += domctl.o obj-y += domain.o obj-y += entry.o +obj-y += insn.o obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-y += proc-v7.o proc-caxx.o obj-y += smpboot.o
xen/arch/arm/arm32/insn.c new file +91 -0
91 lines not on this page · raw message
xen/common/livepatch.c +1 -0
@@ -25,6 +25,7 @@#include <xen/livepatch.h> #include <xen/livepatch_payload.h> +#include <asm/alternative.h> #include <asm/event.h> /*
xen/include/asm-arm/arm32/insn.h new file +71 -0
71 lines not on this page · raw message
xen/include/asm-arm/insn.h +2 -0
@@ -5,6 +5,8 @@#if defined(CONFIG_ARM_64 )# include <asm/arm64/insn.h> +#elif defined(CONFIG_ARM_32 ) +# include <asm/arm32/insn.h> #else # error "unknown ARM variant"#endif
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Hi Wei,
Quoted 26 lines · Wei Chen
This patch is based on the implementation of ARM64, it introduces alternative runtime patching to ARM32. This allows to patch assembly instruction at runtime to either fix hardware bugs or optimize for certain hardware features on ARM32 platform.
Xen hypervisor is using ARM execution state only on ARM32 platform, Thumb is not used. So, the Thumb only branch instructions (CBZ, CBNZ, TBB and TBH) are not considered in alternatives.
The left ARM32 branch instructions are BX, BLX, BL and B. The instruction BX is taking a register in parameter, so we don't need to rewrite it. The instructions BLX, BL and B are using the similar encoding for the offset and will avoid specific case when extracting and updating the offset.
In this patch, we include
alternative.hheader file tolivepatch.cdirectly for ARM32 compilation issues. When the alternative patching config is enabled, thelivepatch.cwill use the alternative functions. In this case, we should include the alternative header file to this file. But for ARM64, it does not include this header file directly. It includes this header file indirectly through:sched.h->domain.h->page.h->alternative.h.
But, unfortunately, thepage.hof ARM32 doesn't includealternative.h, and we don't have the reason to include it to ARM32page.hnow. So we have to include thealternative.hdirectly inlivepatch.c.
Quoted 2 lines
Signed-off-by Wei Chen <[email protected]>Reviewed-by Konrad Rzeszutek Wilk <[email protected]>
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel