From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Graf Date: Thu, 29 Jul 2010 12:48:02 +0000 Subject: [PATCH 21/27] KVM: PPC: Introduce branch patching helper Message-Id: <1280407688-9815-22-git-send-email-agraf@suse.de> List-Id: References: <1280407688-9815-1-git-send-email-agraf@suse.de> In-Reply-To: <1280407688-9815-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: KVM list , linuxppc-dev , Liu Yu , Segher Boessenkool We will need to patch several instruction streams over to a different code path, so we need a way to patch a single instruction with a branch somewhere else. This patch adds a helper to facilitate this patching. Signed-off-by: Alexander Graf --- v2 -> v3: - add safety check for relocatable kernels --- arch/powerpc/kernel/kvm.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c index 926f93f..239a70d 100644 --- a/arch/powerpc/kernel/kvm.c +++ b/arch/powerpc/kernel/kvm.c @@ -107,6 +107,20 @@ static void kvm_patch_ins_nop(u32 *inst) kvm_patch_ins(inst, KVM_INST_NOP); } +static void kvm_patch_ins_b(u32 *inst, int addr) +{ +#ifdef CONFIG_RELOCATABLE + /* On relocatable kernels interrupts handlers and our code + can be in different regions, so we don't patch them */ + + extern u32 __end_interrupts; + if ((ulong)inst < (ulong)&__end_interrupts) + return; +#endif + + kvm_patch_ins(inst, KVM_INST_B | (addr & KVM_INST_B_MASK)); +} + static u32 *kvm_alloc(int len) { u32 *p; -- 1.6.0.2