KVM: PPC: Book3S PR: Fix build when PR KVM is built in

Submitted by Paul Mackerras on April 11, 2017, 11:27 p.m.

Details

Message ID 20170411232704.GB3055@fergus.ozlabs.ibm.com
State New
Headers show

Commit Message

Paul Mackerras April 11, 2017, 11:27 p.m.
Commit f8513214ac9d("KVM: PPC: Book3S: Add MMIO emulation for FP and
VSX instructions", 2017-02-21) added uses of kvm_cvt_fd() and
kvm_cvt_df() in arch/powerpc/kvm/powerpc.c, and therefore added
arch/powerpc/kvm/fpu.S to the list of sources to be included in the
main KVM module.  However, the PR KVM module also uses fpu.S and has
it in the list of sources for the PR KVM module.  When PR KVM is built
in (rather than being compiled as a module), this means we get two
copies of fpu.o, leading to errors like this:

arch/powerpc/kvm/fpu.o:(.opd+0x0): multiple definition of `fps_fres'
arch/powerpc/kvm/fpu.o:(.opd+0x0): first defined here
arch/powerpc/kvm/fpu.o: In function `fps_fres':
(.text+0x0): multiple definition of `.fps_fres'
arch/powerpc/kvm/fpu.o:(.text+0x0): first defined here
arch/powerpc/kvm/fpu.o:(.opd+0x18): multiple definition of
`fps_frsqrte'
arch/powerpc/kvm/fpu.o:(.opd+0x18): first defined here
arch/powerpc/kvm/fpu.o: In function `fps_frsqrte':
(.text+0x20): multiple definition of `.fps_frsqrte'
arch/powerpc/kvm/fpu.o:(.text+0x20): first defined here
... and so on ...

To fix the problem, this replaces the calls to kvm_cvt_fd() and
kvm_cvt_df() in powerpc.c with inline asm, meaning that we no longer
need to include fpu.S in the list of sources for the main KVM module.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
---
Note: this commit is against my kvm-ppc-next branch and the referenced
commit is only in that branch as of now.

 arch/powerpc/kvm/Makefile  | 1 -
 arch/powerpc/kvm/powerpc.c | 7 ++++---
 2 files changed, 4 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index 23dcb18..60115ff 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -17,7 +17,6 @@  CFLAGS_emulate.o  := -I.
 CFLAGS_emulate_loadstore.o  := -I.
 
 common-objs-y += powerpc.o emulate_loadstore.o
-common-objs-$(CONFIG_PPC_FPU) += fpu.o
 obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o
 obj-$(CONFIG_KVM_BOOK3S_HANDLER) += book3s_exports.o
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ea7d0b7..9f8ef98 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -37,7 +37,6 @@ 
 #include <asm/cputhreads.h>
 #include <asm/irqflags.h>
 #include <asm/iommu.h>
-#include <asm/kvm_fpu.h>
 #include <asm/switch_to.h>
 #include "timing.h"
 #include "irq.h"
@@ -910,7 +909,8 @@  static inline u64 sp_to_dp(u32 fprs)
 
 	preempt_disable();
 	enable_kernel_fp();
-	kvm_cvt_fd(&fprs, &fprd);
+	asm ("lfs%U1%X1 0,%1; stfd%U0%X0 0,%0" : "=m" (fprd) : "m" (fprs)
+	     : "fr0");
 	preempt_enable();
 	return fprd;
 }
@@ -921,7 +921,8 @@  static inline u32 dp_to_sp(u64 fprd)
 
 	preempt_disable();
 	enable_kernel_fp();
-	kvm_cvt_df(&fprd, &fprs);
+	asm ("lfd%U1%X1 0,%1; stfs%U0%X0 0,%0" : "=m" (fprs) : "m" (fprd)
+	     : "fr0");
 	preempt_enable();
 	return fprs;
 }