Second round of 64bit PowerPC little endian patches
Subsystems (5)
cover Second round of 64bit PowerPC little endian patches
This patchset fixes little endian issues found in various places including the alignment handler, PCI, and ptrace code.
It also adds little endian support for KVM guests and PowerNV.
Alistair Popple (4):
powerpc: Little endian fixes for platforms/powernv/opal.c
powerpc: Little endian fix for arch/powerpc/platforms/powernv/pci.c
powerpc: Little endian fix for
arch/powerpc/platforms/powernv/pci-p5ioc2.c
powerpc: Little endian sparse clean up for
arch/powerpc/platforms/powernv/pci-ioda.c
Anton Blanchard (22):
powerpc: Fix endian issues in VMX copy loops
powerpc: Book 3S MMU little endian support
powerpc: Fix offset of FPRs in VSX registers in little endian builds
powerpc: PTRACE_PEEKUSR/PTRACE_POKEUSER of FPR registers in little
endian builds
powerpc: Little endian builds double word swap VSX state during
context save/restore
powerpc: Add little endian support for word-at-a-time functions
powerpc: Set MSR_LE bit on little endian builds
powerpc: Reset MSR_LE on signal entry
powerpc: Remove open coded byte swap macro in alignment handler
powerpc: Remove hard coded FP offsets in alignment handler
powerpc: Alignment handler shouldn't access VSX registers with TS_FPR
powerpc: Add little endian support to alignment handler
powerpc: Handle VSX alignment faults in little endian mode
powerpc: Use generic checksum code in little endian
powerpc: Use generic memcpy code in little endian
powerpc: uname should return ppc64le/ppcle on little endian builds powerpc/powernv: More little endian issues in OPAL RTC driver powerpc/powernv: Fix some PCI sparse errors and one LE bug
KVM: PPC: Disable KVM on little endian builds powerpc/kvm/book3s_hv: Add little endian guest support
powerpc: Don't set HAVE_EFFICIENT_UNALIGNED_ACCESS on little endian
builds
powerpc: Work around little endian gcc bug
Benjamin Herrenschmidt (10):
powerpc: endian safe trampoline
powerpc/powernv: Fix endian issues in OPAL RTC driver powerpc/powernv: Fix endian issues in OPAL ICS backend powerpc/powernv: Make OPAL NVRAM device tree accesses endian safe powerpc/powernv: Fix endian issues in powernv PCI code powerpc/powernv: Fix endian issues in OPAL console and udbg backend powerpc/powernv: Fix OPAL entry and exit in little endian mode powerpc/powernv: Don't register exception handlers in little endian
mode
powerpc/hvsi: Fix endian issues in HVSI driver tty/hvc_opal: powerpc: Make OPAL HVC device tree accesses endian safe
Ian Munsie (3):
powerpc: Support endian agnostic MMIO
powerpc: Include the appropriate endianness header
powerpc: Add ability to build little endian kernels
arch/powerpc/Kconfig | 5 +- arch/powerpc/Makefile | 37 +++++- arch/powerpc/boot/Makefile | 3 +- arch/powerpc/include/asm/checksum.h | 5 + arch/powerpc/include/asm/hvsi.h | 16 +-- arch/powerpc/include/asm/io.h | 67 +++++++--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/mmu-hash64.h | 4 +- arch/powerpc/include/asm/opal.h | 34 +++--- arch/powerpc/include/asm/ppc-opcode.h | 3 + arch/powerpc/include/asm/ppc_asm.h | 52 +++++++- arch/powerpc/include/asm/processor.h | 12 +- arch/powerpc/include/asm/reg.h | 7 +- arch/powerpc/include/asm/string.h | 4 + arch/powerpc/include/asm/word-at-a-time.h | 71 +++++++++++ arch/powerpc/include/uapi/asm/byteorder.h | 4 + arch/powerpc/kernel/align.c | 162 ++++++++++++++++--------- arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kernel/entry_64.S | 36 +++--- arch/powerpc/kernel/head_64.S | 3 + arch/powerpc/kernel/ppc_ksyms.c | 4 + arch/powerpc/kernel/ptrace.c | 8 +- arch/powerpc/kernel/signal_32.c | 3 +- arch/powerpc/kernel/signal_64.c | 3 +- arch/powerpc/kernel/vdso32/vdso32.lds.S | 4 + arch/powerpc/kernel/vdso64/vdso64.lds.S | 4 + arch/powerpc/kvm/Kconfig | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 44 +++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 15 +-- arch/powerpc/lib/Makefile | 18 ++- arch/powerpc/lib/copyuser_power7.S | 54 +++++---- arch/powerpc/lib/memcpy_power7.S | 55 +++++---- arch/powerpc/mm/hash_native_64.c | 46 ++++--- arch/powerpc/mm/hash_utils_64.c | 38 +++--- arch/powerpc/platforms/powernv/opal-nvram.c | 4 +- arch/powerpc/platforms/powernv/opal-rtc.c | 12 +- arch/powerpc/platforms/powernv/opal-wrappers.S | 9 +- arch/powerpc/platforms/powernv/opal.c | 34 +++--- arch/powerpc/platforms/powernv/pci-ioda.c | 41 ++++--- arch/powerpc/platforms/powernv/pci-p5ioc2.c | 4 +- arch/powerpc/platforms/powernv/pci.c | 26 ++-- arch/powerpc/platforms/powernv/pci.h | 2 +- arch/powerpc/sysdev/xics/ics-opal.c | 17 +-- drivers/tty/hvc/hvc_opal.c | 4 +- drivers/tty/hvc/hvsi_lib.c | 25 ++-- 46 files changed, 685 insertions(+), 319 deletions(-)
Signature · 1 line
1.8.1.2
PATCH 1/39 powerpc: Fix endian issues in VMX copy loops
Fix the permute loops for little endian.
--- arch/powerpc/lib/copyuser_power7.S | 54 +++++++++++++++++++++---------------- arch/powerpc/lib/memcpy_power7.S | 55 ++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 46 deletions(-)
arch/powerpc/lib/copyuser_power7.S +31 -23
@@ -19,6 +19,14 @@ */ #include <asm/ppc_asm.h> +#ifdef __BIG_ENDIAN__ +#define LVS(VRT,RA,RB) lvsl VRT,RA,RB +#define VPERM(VRT,VRA,VRB,VRC) vperm VRT,VRA,VRB,VRC +#else +#define LVS(VRT,RA,RB) lvsr VRT,RA,RB +#define VPERM(VRT,VRA,VRB,VRC) vperm VRT,VRB,VRA,VRC +#endif + .macro err1 100: .section __ex_table,"a"
@@ -552,13 +560,13 @@ err3; stw r7,4(r3) li r10,32 li r11,48 - lvsl vr16,0,r4 /* Setup permute control vector */ + LVS(vr16,0,r4) /* Setup permute control vector */ err3; lvx vr0,0,r4 addi r4,r4,16 bf cr7*4+3,5f err3; lvx vr1,r0,r4 - vperm vr8,vr0,vr1,vr16 + VPERM(vr8,vr0,vr1,vr16) addi r4,r4,16 err3; stvx vr8,r0,r3 addi r3,r3,16
@@ -566,9 +574,9 @@ err3; stvx vr8,r0,r3 5: bf cr7*4+2,6f err3; lvx vr1,r0,r4 - vperm vr8,vr0,vr1,vr16 + VPERM(vr8,vr0,vr1,vr16) err3; lvx vr0,r4,r9 - vperm vr9,vr1,vr0,vr16 + VPERM(vr9,vr1,vr0,vr16) addi r4,r4,32 err3; stvx vr8,r0,r3 err3; stvx vr9,r3,r9
@@ -576,13 +584,13 @@ err3; stvx vr9,r3,r9 6: bf cr7*4+1,7f err3; lvx vr3,r0,r4 - vperm vr8,vr0,vr3,vr16 + VPERM(vr8,vr0,vr3,vr16) err3; lvx vr2,r4,r9 - vperm vr9,vr3,vr2,vr16 + VPERM(vr9,vr3,vr2,vr16) err3; lvx vr1,r4,r10 - vperm vr10,vr2,vr1,vr16 + VPERM(vr10,vr2,vr1,vr16) err3; lvx vr0,r4,r11 - vperm vr11,vr1,vr0,vr16 + VPERM(vr11,vr1,vr0,vr16) addi r4,r4,64 err3; stvx vr8,r0,r3 err3; stvx vr9,r3,r9
@@ -611,21 +619,21 @@ err3; stvx vr11,r3,r11 .align 5 8: err4; lvx vr7,r0,r4 - vperm vr8,vr0,vr7,vr16 + VPERM(vr8,vr0,vr7,vr16) err4; lvx vr6,r4,r9 - vperm vr9,vr7,vr6,vr16 + VPERM(vr9,vr7,vr6,vr16) err4; lvx vr5,r4,r10 - vperm vr10,vr6,vr5,vr16 + VPERM(vr10,vr6,vr5,vr16) err4; lvx vr4,r4,r11 - vperm vr11,vr5,vr4,vr16 + VPERM(vr11,vr5,vr4,vr16) err4; lvx vr3,r4,r12 - vperm vr12,vr4,vr3,vr16 + VPERM(vr12,vr4,vr3,vr16) err4; lvx vr2,r4,r14 - vperm vr13,vr3,vr2,vr16 + VPERM(vr13,vr3,vr2,vr16) err4; lvx vr1,r4,r15 - vperm vr14,vr2,vr1,vr16 + VPERM(vr14,vr2,vr1,vr16) err4; lvx vr0,r4,r16 - vperm vr15,vr1,vr0,vr16 + VPERM(vr15,vr1,vr0,vr16) addi r4,r4,128 err4; stvx vr8,r0,r3 err4; stvx vr9,r3,r9
@@ -649,13 +657,13 @@ err4; stvx vr15,r3,r16 bf cr7*4+1,9f err3; lvx vr3,r0,r4 - vperm vr8,vr0,vr3,vr16 + VPERM(vr8,vr0,vr3,vr16) err3; lvx vr2,r4,r9 - vperm vr9,vr3,vr2,vr16 + VPERM(vr9,vr3,vr2,vr16) err3; lvx vr1,r4,r10 - vperm vr10,vr2,vr1,vr16 + VPERM(vr10,vr2,vr1,vr16) err3; lvx vr0,r4,r11 - vperm vr11,vr1,vr0,vr16 + VPERM(vr11,vr1,vr0,vr16) addi r4,r4,64 err3; stvx vr8,r0,r3 err3; stvx vr9,r3,r9
@@ -665,9 +673,9 @@ err3; stvx vr11,r3,r11 9: bf cr7*4+2,10f err3; lvx vr1,r0,r4 - vperm vr8,vr0,vr1,vr16 + VPERM(vr8,vr0,vr1,vr16) err3; lvx vr0,r4,r9 - vperm vr9,vr1,vr0,vr16 + VPERM(vr9,vr1,vr0,vr16) addi r4,r4,32 err3; stvx vr8,r0,r3 err3; stvx vr9,r3,r9
@@ -675,7 +683,7 @@ err3; stvx vr9,r3,r9 10: bf cr7*4+3,11f err3; lvx vr1,r0,r4 - vperm vr8,vr0,vr1,vr16 + VPERM(vr8,vr0,vr1,vr16) addi r4,r4,16 err3; stvx vr8,r0,r3 addi r3,r3,16
arch/powerpc/lib/memcpy_power7.S +32 -23
123 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 2/39 powerpc: Book 3S MMU little endian support
In reply to Anton Blanchardv2: HPTE_LOCK_BIT was wrong in LE, spotted by Paul Mackerras.
--- arch/powerpc/include/asm/mmu-hash64.h | 4 +-- arch/powerpc/mm/hash_native_64.c | 46 ++++++++++++++++++++--------------- arch/powerpc/mm/hash_utils_64.c | 38 ++++++++++++++--------------- 3 files changed, 46 insertions(+), 42 deletions(-)
arch/powerpc/include/asm/mmu-hash64.h +2 -2
@@ -135,8 +135,8 @@ extern char initial_stab[];#ifndef __ASSEMBLY__struct hash_pte { -unsigned long v; -unsigned long r; +__be64 v; +__be64 r; };extern struct hash_pte *htab_address;
arch/powerpc/mm/hash_native_64.c +26 -20
152 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +18 -20
@@ -251,19 +251,18 @@ static int __init htab_dt_scan_seg_sizes(unsigned long node, void *data) {char *type =of_get_flat_dt_prop (node,"device_type" ,NULL ); -u32 *prop; +__be32 *prop;unsigned long size =0 ;/* We are scanning "cpu" nodes only */ if (type ==NULL ||strcmp (type,"cpu" ) !=0 )return 0 ; - prop = (u32 *)of_get_flat_dt_prop (node,"ibm,processor-segment-sizes" , - &size); + prop =of_get_flat_dt_prop (node,"ibm,processor-segment-sizes" , &size);if (prop ==NULL )return 0 ;for (; size >=4 ; size -=4 , ++prop) { -if (prop[0 ] ==40 ) { +if (be32_to_cpu (prop[0 ]) ==40 ) {DBG ("1T segment support detected\n" ); cur_cpu_spec->mmu_features |=MMU_FTR_1T_SEGMENT ;return 1 ;
@@ -307,23 +306,22 @@ static int __init htab_dt_scan_page_sizes(unsigned long node, void *data) {char *type =of_get_flat_dt_prop (node,"device_type" ,NULL ); -u32 *prop; +__be32 *prop;unsigned long size =0 ;/* We are scanning "cpu" nodes only */ if (type ==NULL ||strcmp (type,"cpu" ) !=0 )return 0 ; - prop = (u32 *)of_get_flat_dt_prop (node, -"ibm,segment-page-sizes" , &size); + prop =of_get_flat_dt_prop (node,"ibm,segment-page-sizes" , &size);if (prop !=NULL ) {pr_info ("Page sizes from device-tree:\n" ); size /=4 ; cur_cpu_spec->mmu_features &= ~(MMU_FTR_16M_PAGE );while (size >0 ) { -unsigned int base_shift = prop[0 ]; -unsigned int slbenc = prop[1 ]; -unsigned int lpnum = prop[2 ]; +unsigned int base_shift =be32_to_cpu (prop[0 ]); +unsigned int slbenc =be32_to_cpu (prop[1 ]); +unsigned int lpnum =be32_to_cpu (prop[2 ]);struct mmu_psize_def *def;int idx, base_idx;
@@ -356,8 +354,8 @@ static int __init htab_dt_scan_page_sizes(unsigned long node, def->tlbiel =0 ;while (size >0 && lpnum) { -unsigned int shift = prop[0 ]; -int penc = prop[1 ]; +unsigned int shift =be32_to_cpu (prop[0 ]); +int penc =be32_to_cpu (prop[1 ]); prop +=2 ; size -=2 ; lpnum--;
@@ -390,8 +388,8 @@ static int __init htab_dt_scan_hugepage_blocks(unsigned long node, const char *uname, int depth, void *data) { char *type = of_get_flat_dt_prop(node, "device_type", NULL); -unsigned long *addr_prop; -u32 *page_count_prop; +__be64 *addr_prop; +__be32 *page_count_prop;unsigned int expected_pages;long unsigned int phys_addr;long unsigned int block_size;
@@ -405,12 +403,12 @@ static int __init htab_dt_scan_hugepage_blocks(unsigned long node, page_count_prop =of_get_flat_dt_prop (node,"ibm,expected#pages" ,NULL );if (page_count_prop ==NULL )return 0 ; - expected_pages = (1 << page_count_prop[0 ]); + expected_pages = (1 <<be32_to_cpu (page_count_prop[0 ])); addr_prop =of_get_flat_dt_prop (node,"reg" ,NULL );if (addr_prop ==NULL )return 0 ; - phys_addr = addr_prop[0 ]; - block_size = addr_prop[1 ]; + phys_addr =be64_to_cpu (addr_prop[0 ]); + block_size =be64_to_cpu (addr_prop[1 ]);if (block_size != (16 *GB ))return 0 ; printk(KERN_INFO "Huge page(16GB) memory: "
@@ -534,16 +532,16 @@ static int __init htab_dt_scan_pftsize(unsigned long node, void *data) {char *type =of_get_flat_dt_prop (node,"device_type" ,NULL ); -u32 *prop; +__be32 *prop;/* We are scanning "cpu" nodes only */ if (type ==NULL ||strcmp (type,"cpu" ) !=0 )return 0 ; - prop = (u32 *)of_get_flat_dt_prop (node,"ibm,pft-size" ,NULL ); + prop =of_get_flat_dt_prop (node,"ibm,pft-size" ,NULL );if (prop !=NULL ) {/* pft_size[0] is the NUMA CEC cookie */ - ppc64_pft_size = prop[1 ]; + ppc64_pft_size =be32_to_cpu (prop[1 ]);return 1 ; }return 0 ;
Signature · 1 line
1.8.1.2
PATCH 3/39 powerpc: Fix offset of FPRs in VSX registers in little endian builds
In reply to Anton BlanchardThe FPRs overlap the high doublewords of the first 32 VSX registers. Fix TS_FPROFFSET and TS_VSRLOWOFFSET so we access the correct fields in little endian mode.
If VSX is disabled the FPRs are only one doubleword in length so TS_FPROFFSET needs adjusting in little endian.
--- arch/powerpc/include/asm/processor.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/processor.h +10 -2
@@ -14,8 +14,18 @@#ifdef CONFIG_VSX #define TS_FPRWIDTH 2 + +#ifdef __BIG_ENDIAN__ +#define TS_FPROFFSET 0 +#define TS_VSRLOWOFFSET 1 +#else +#define TS_FPROFFSET 1 +#define TS_VSRLOWOFFSET 0 +#endif +#else #define TS_FPRWIDTH 1 +#define TS_FPROFFSET 0#endif #ifdef CONFIG_PPC64
@@ -142,8 +152,6 @@ typedef struct {unsigned long seg; } mm_segment_t; -#define TS_FPROFFSET 0 -#define TS_VSRLOWOFFSET 1#define TS_FPR (i) fpr[i][TS_FPROFFSET]#define TS_TRANS_FPR (i) transact_fpr[i][TS_FPROFFSET]
Signature · 1 line
1.8.1.2
PATCH 4/39 powerpc: PTRACE_PEEKUSR/PTRACE_POKEUSER of FPR registers in little endian builds
In reply to Anton BlanchardFPRs overlap the high 64bits of the first 32 VSX registers. The ptrace FP read/write code assumes big endian ordering and grabs the lowest 64 bits.
Fix this by using the TS_FPR macro which does the right thing.
--- arch/powerpc/kernel/ptrace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/kernel/ptrace.c +4 -4
@@ -1554,8 +1554,8 @@ long arch_ptrace(struct task_struct *child, long request,flush_fp_to_thread (child);if (fpidx < (PT_FPSCR -PT_FPR0 )) - tmp = ((unsigned long *)child->thread.fpr) - [fpidx *TS_FPRWIDTH ]; +memcpy (&tmp, &child->thread.TS_FPR (fpidx), +sizeof (long ));else tmp = child->thread.fpscr.val; }
@@ -1587,8 +1587,8 @@ long arch_ptrace(struct task_struct *child, long request,flush_fp_to_thread (child);if (fpidx < (PT_FPSCR -PT_FPR0 )) - ((unsigned long *)child->thread.fpr) - [fpidx *TS_FPRWIDTH ] = data; +memcpy (&child->thread.TS_FPR (fpidx), &data, +sizeof (long ));else child->thread.fpscr.val = data; ret =0 ;
Signature · 1 line
1.8.1.2
PATCH 5/39 powerpc: Little endian builds double word swap VSX state during context save/restore
In reply to Anton BlanchardThe elements within VSX loads and stores are big endian ordered regardless of endianness. Our VSX context save/restore code uses lxvd2x and stxvd2x which is a 2x doubleword operation. This means the two doublewords will be swapped and we have to perform another swap to undo it.
We need to do this on save and restore.
--- arch/powerpc/include/asm/ppc-opcode.h | 3 +++ arch/powerpc/include/asm/ppc_asm.h | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/ppc-opcode.h +3 -0
@@ -181,6 +181,7 @@#define PPC_INST_TLBIVAX 0x7c000624#define PPC_INST_TLBSRX_DOT 0x7c0006a5#define PPC_INST_XXLOR 0xf0000510 +#define PPC_INST_XXSWAPD 0xf0000250#define PPC_INST_XVCPSGNDP 0xf0000780#define PPC_INST_TRECHKPT 0x7c0007dd#define PPC_INST_TRECLAIM 0x7c00075d
@@ -344,6 +345,8 @@ VSX_XX1((s), a, b))#define XXLOR (t, a, b) stringify_in_c(.long PPC_INST_XXLOR | \ VSX_XX3((t), a, b)) +#define XXSWAPD (t, a) stringify_in_c(.long PPC_INST_XXSWAPD | \ + VSX_XX3((t), a, a))#define XVCPSGNDP (t, a, b) stringify_in_c(.long (PPC_INST_XVCPSGNDP | \ VSX_XX3((t), (a), (b))))
arch/powerpc/include/asm/ppc_asm.h +17 -4
@@ -180,9 +180,20 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)#define REST_32VRS_TRANSACT (n,b,base) REST_16VRS_TRANSACT(n,b,base); \ REST_16VRS_TRANSACT(n+16,b,base) +#ifdef __BIG_ENDIAN__ +#define STXVD2X_ROT (n,b,base) STXVD2X(n,b,base) +#define LXVD2X_ROT (n,b,base) LXVD2X(n,b,base) +#else +#define STXVD2X_ROT (n,b,base) XXSWAPD(n,n); \ + STXVD2X(n,b,base); \ + XXSWAPD(n,n) + +#define LXVD2X_ROT (n,b,base) LXVD2X(n,b,base); \ + XXSWAPD(n,n) +#endif #define SAVE_VSR_TRANSACT (n,b,base) li b,THREAD_TRANSACT_VSR0+(16*(n)); \ - STXVD2X(n,R##base,R##b) + STXVD2X_ROT(n,R##base,R##b)#define SAVE_2VSRS_TRANSACT (n,b,base) SAVE_VSR_TRANSACT(n,b,base); \ SAVE_VSR_TRANSACT(n+1,b,base)#define SAVE_4VSRS_TRANSACT (n,b,base) SAVE_2VSRS_TRANSACT(n,b,base); \
@@ -195,7 +206,7 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) SAVE_16VSRS_TRANSACT(n+16,b,base)#define REST_VSR_TRANSACT (n,b,base) li b,THREAD_TRANSACT_VSR0+(16*(n)); \ - LXVD2X(n,R##base,R##b) + LXVD2X_ROT(n,R##base,R##b)#define REST_2VSRS_TRANSACT (n,b,base) REST_VSR_TRANSACT(n,b,base); \ REST_VSR_TRANSACT(n+1,b,base)#define REST_4VSRS_TRANSACT (n,b,base) REST_2VSRS_TRANSACT(n,b,base); \
@@ -208,13 +219,15 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)REST_16VSRS_TRANSACT (n+16 ,b,base) /* Save the lower 32 VSRs in the thread VSR region */ -#define SAVE_VSR (n,b,base) li b,THREAD_VSR0+(16*(n)); STXVD2X(n,R##base,R##b) +#define SAVE_VSR (n,b,base) li b,THREAD_VSR0+(16*(n)); \ + STXVD2X_ROT(n,R##base,R##b)#define SAVE_2VSRS (n,b,base) SAVE_VSR(n,b,base); SAVE_VSR(n+1,b,base)#define SAVE_4VSRS (n,b,base) SAVE_2VSRS(n,b,base); SAVE_2VSRS(n+2,b,base)#define SAVE_8VSRS (n,b,base) SAVE_4VSRS(n,b,base); SAVE_4VSRS(n+4,b,base)#define SAVE_16VSRS (n,b,base) SAVE_8VSRS(n,b,base); SAVE_8VSRS(n+8,b,base)#define SAVE_32VSRS (n,b,base) SAVE_16VSRS(n,b,base); SAVE_16VSRS(n+16,b,base) -#define REST_VSR (n,b,base) li b,THREAD_VSR0+(16*(n)); LXVD2X(n,R##base,R##b) +#define REST_VSR (n,b,base) li b,THREAD_VSR0+(16*(n)); \ + LXVD2X_ROT(n,R##base,R##b)#define REST_2VSRS (n,b,base) REST_VSR(n,b,base); REST_VSR(n+1,b,base)#define REST_4VSRS (n,b,base) REST_2VSRS(n,b,base); REST_2VSRS(n+2,b,base)#define REST_8VSRS (n,b,base) REST_4VSRS(n,b,base); REST_4VSRS(n+4,b,base)
Signature · 1 line
1.8.1.2
PATCH 6/39 powerpc: Support endian agnostic MMIO
In reply to Anton BlanchardFrom: Ian Munsie <[email protected]>
This patch maps the MMIO functions for 32bit PowerPC to their appropriate instructions depending on CPU endianness.
The macros used to create the corresponding inline functions are also renamed by this patch. Previously they had BE or LE in their names which was misleading - they had nothing to do with endianness, but actually created different instruction forms so their new names reflect the instruction form they are creating (D-Form and X-Form).
Little endian 64bit PowerPC is not supported, so the lack of mappings (and corresponding breakage) for that case is intentional to bring the attention of anyone doing a 64bit little endian port. 64bit big endian is unaffected.
[ Added 64 bit versions - Anton ]
--- arch/powerpc/include/asm/io.h | 67 +++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/io.h +49 -18
@@ -113,7 +113,7 @@ extern bool isa_io_special;/* gcc 4.0 and older doesn't have 'Z' constraint */ #if __GNUC__ <4 || (__GNUC__ ==4 && __GNUC_MINOR__ ==0 ) -#define DEF_MMIO_IN_LE (name, size, insn) \ +#define DEF_MMIO_IN_X (name, size, insn) \ static inline u##size name(const volatile u##size __iomem *addr) \ { \ u##size ret; \
@@ -122,7 +122,7 @@ static inline u##size name(const volatile u##size __iomem *addr) \return ret; \ } -#define DEF_MMIO_OUT_LE (name, size, insn) \ +#define DEF_MMIO_OUT_X (name, size, insn) \ static inline void name(volatile u##size __iomem *addr, u##size val) \ { \ __asm__ __volatile__("sync;"#insn" %1,0,%2" \
@@ -130,7 +130,7 @@ static inline void name(volatile u##size __iomem *addr, u##size val) \IO_SET_SYNC_FLAG (); \ }#else /* newer gcc */ -#define DEF_MMIO_IN_LE (name, size, insn) \ +#define DEF_MMIO_IN_X (name, size, insn) \ static inline u##size name(const volatile u##size __iomem *addr) \ { \ u##size ret; \
@@ -139,7 +139,7 @@ static inline u##size name(const volatile u##size __iomem *addr) \return ret; \ } -#define DEF_MMIO_OUT_LE (name, size, insn) \ +#define DEF_MMIO_OUT_X (name, size, insn) \ static inline void name(volatile u##size __iomem *addr, u##size val) \ { \ __asm__ __volatile__("sync;"#insn" %1,%y0" \
@@ -148,7 +148,7 @@ static inline void name(volatile u##size __iomem *addr, u##size val) \ }#endif -#define DEF_MMIO_IN_BE (name, size, insn) \ +#define DEF_MMIO_IN_D (name, size, insn) \ static inline u##size name(const volatile u##size __iomem *addr) \ { \ u##size ret; \
@@ -157,7 +157,7 @@ static inline u##size name(const volatile u##size __iomem *addr) \return ret; \ } -#define DEF_MMIO_OUT_BE (name, size, insn) \ +#define DEF_MMIO_OUT_D (name, size, insn) \ static inline void name(volatile u##size __iomem *addr, u##size val) \ { \ __asm__ __volatile__("sync;"#insn"%U0%X0 %1,%0" \
@@ -165,22 +165,37 @@ static inline void name(volatile u##size __iomem *addr, u##size val) \IO_SET_SYNC_FLAG (); \ } +DEF_MMIO_IN_D (in_8,8 , lbz); +DEF_MMIO_OUT_D (out_8,8 , stb); -DEF_MMIO_IN_BE (in_8,8 , lbz); -DEF_MMIO_IN_BE (in_be16,16 , lhz); -DEF_MMIO_IN_BE (in_be32,32 , lwz); -DEF_MMIO_IN_LE (in_le16,16 , lhbrx); -DEF_MMIO_IN_LE (in_le32,32 , lwbrx); +#ifdef __BIG_ENDIAN__ +DEF_MMIO_IN_D (in_be16,16 , lhz); +DEF_MMIO_IN_D (in_be32,32 , lwz); +DEF_MMIO_IN_X (in_le16,16 , lhbrx); +DEF_MMIO_IN_X (in_le32,32 , lwbrx); -DEF_MMIO_OUT_BE (out_8,8 , stb); -DEF_MMIO_OUT_BE (out_be16,16 , sth); -DEF_MMIO_OUT_BE (out_be32,32 , stw); -DEF_MMIO_OUT_LE (out_le16,16 , sthbrx); -DEF_MMIO_OUT_LE (out_le32,32 , stwbrx); +DEF_MMIO_OUT_D (out_be16,16 , sth); +DEF_MMIO_OUT_D (out_be32,32 , stw); +DEF_MMIO_OUT_X (out_le16,16 , sthbrx); +DEF_MMIO_OUT_X (out_le32,32 , stwbrx); +#else +DEF_MMIO_IN_X (in_be16,16 , lhbrx); +DEF_MMIO_IN_X (in_be32,32 , lwbrx); +DEF_MMIO_IN_D (in_le16,16 , lhz); +DEF_MMIO_IN_D (in_le32,32 , lwz); + +DEF_MMIO_OUT_X (out_be16,16 , sthbrx); +DEF_MMIO_OUT_X (out_be32,32 , stwbrx); +DEF_MMIO_OUT_D (out_le16,16 , sth); +DEF_MMIO_OUT_D (out_le32,32 , stw); + +#endif /* __BIG_ENDIAN */ #ifdef __powerpc64__ -DEF_MMIO_OUT_BE (out_be64,64 , std); -DEF_MMIO_IN_BE (in_be64,64 , ld); + +#ifdef __BIG_ENDIAN__ +DEF_MMIO_OUT_D (out_be64,64 , std); +DEF_MMIO_IN_D (in_be64,64 , ld);/* There is no asm instructions for 64 bits reverse loads and stores */ static inline u64 in_le64 (const volatile u64 __iomem *addr)
@@ -192,6 +207,22 @@ static inline void out_le64(volatile u64 __iomem *addr, u64 val) {out_be64 (addr,swab64 (val)); } +#else +DEF_MMIO_OUT_D (out_le64,64 , std); +DEF_MMIO_IN_D (in_le64,64 , ld); + +/* There is no asm instructions for 64 bits reverse loads and stores */ +static inline u64 in_be64 (const volatile u64 __iomem *addr) +{ +return swab64 (in_le64 (addr)); +} + +static inline void out_be64 (volatile u64 __iomem *addr,u64 val) +{ +out_le64 (addr,swab64 (val)); +} + +#endif #endif /* __powerpc64__ */ /*
Signature · 1 line
1.8.1.2
PATCH 7/39 powerpc: Add little endian support for word-at-a-time functions
In reply to Anton BlanchardThe powerpc word-at-a-time functions are big endian specific. Bring in the x86 version in order to support little endian builds.
--- arch/powerpc/include/asm/word-at-a-time.h | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
arch/powerpc/include/asm/word-at-a-time.h +71 -0
@@ -8,6 +8,8 @@#include <linux/kernel.h> #include <asm/asm-compat.h> +#ifdef __BIG_ENDIAN__ +struct word_at_a_time {const unsigned long high_bits, low_bits; };
@@ -38,4 +40,73 @@ static inline bool has_zero(unsigned long val, unsigned long *data, const structreturn (val + c->high_bits) & ~rhs; } +#else + +/* +* This is largely generic for little-endian machines, but the +* optimal byte mask counting is probably going to be something +* that is architecture-specific. If you have a reliably fast +* bit count instruction, that might be better than the multiply +* and shift, for example. +*/ +struct word_at_a_time { +const unsigned long one_bits, high_bits; +}; + +#define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) } + +#ifdef CONFIG_64BIT + +/* +* Jan Achrenius on G+: microoptimized version of +* the simpler "(mask & ONEBYTES) * ONEBYTES >> 56" +* that works for the bytemasks without having to +* mask them first. +*/ +static inline long count_masked_bytes (unsigned long mask) +{ +return mask*0x0001020304050608ul >>56 ; +} + +#else /* 32-bit case */ + +/* Carl Chatfield / Jan Achrenius G+ version for 32-bit */ +static inline long count_masked_bytes (long mask) +{ +/* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */ +long a = (0x0ff0001 +mask) >>23 ; +/* Fix the 1 for 00 case */ +return a & mask; +} + +#endif + +/* Return nonzero if it has a zero */ +static inline unsigned long has_zero (unsigned long a,unsigned long *bits,const struct word_at_a_time *c) +{ +unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits; + *bits = mask; +return mask; +} + +static inline unsigned long prep_zero_mask (unsigned long a,unsigned long bits,const struct word_at_a_time *c) +{ +return bits; +} + +static inline unsigned long create_zero_mask (unsigned long bits) +{ + bits = (bits -1 ) & ~bits; +return bits >>7 ; +} + +/* The mask we created is directly usable as a bytemask */ +#define zero_bytemask (mask) (mask) + +static inline unsigned long find_zero (unsigned long mask) +{ +return count_masked_bytes (mask); +} +#endif +#endif /* _ASM_WORD_AT_A_TIME_H */
Signature · 1 line
1.8.1.2
PATCH 8/39 powerpc: Set MSR_LE bit on little endian builds
In reply to Anton BlanchardWe need to set MSR_LE in kernel and userspace for little endian builds
--- arch/powerpc/include/asm/reg.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/reg.h +6 -1
@@ -115,7 +115,12 @@#define MSR_64BIT MSR_SF/* Server variant */ -#define MSR_ (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV) +#define __MSR (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV) +#ifdef __BIG_ENDIAN__ +#define MSR_ __MSR +#else +#define MSR_ (__MSR | MSR_LE) +#endif #define MSR_KERNEL (MSR_ | MSR_64BIT)#define MSR_USER32 (MSR_ | MSR_PR | MSR_EE)#define MSR_USER64 (MSR_USER32 | MSR_64BIT)
Signature · 1 line
1.8.1.2
PATCH 9/39 powerpc: Reset MSR_LE on signal entry
In reply to Anton BlanchardWe always take signals in big endian which is wrong. Signals should be taken in native endian.
--- arch/powerpc/kernel/signal_32.c | 3 ++- arch/powerpc/kernel/signal_64.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/kernel/signal_32.c +2 -1
@@ -1045,8 +1045,9 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka, regs->gpr[5 ] = (unsigned long ) &rt_sf->uc; regs->gpr[6 ] = (unsigned long ) rt_sf; regs->nip = (unsigned long ) ka->sa.sa_handler; -/* enter the signal handler in big-endian mode */ +/* enter the signal handler in native-endian mode */ regs->msr &= ~MSR_LE ; + regs->msr |= (MSR_KERNEL &MSR_LE );#ifdef CONFIG_PPC_TRANSACTIONAL_MEM /* Remove TM bits from thread's MSR. The MSR in the sigcontext * just indicates to userland that we were doing a transaction, but we
arch/powerpc/kernel/signal_64.c +2 -1
@@ -773,8 +773,9 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,/* Set up "regs" so we "return" to the signal handler. */ err |=get_user (regs->nip, &funct_desc_ptr->entry); -/* enter the signal handler in big-endian mode */ +/* enter the signal handler in native-endian mode */ regs->msr &= ~MSR_LE ; + regs->msr |= (MSR_KERNEL &MSR_LE ); regs->gpr[1 ] = newsp; err |=get_user (regs->gpr[2 ], &funct_desc_ptr->toc); regs->gpr[3 ] = signr;
Signature · 1 line
1.8.1.2
PATCH 10/39 powerpc: Include the appropriate endianness header
In reply to Anton BlanchardFrom: Ian Munsie <[email protected]>
This patch will have powerpc include the appropriate generic endianness header depending on what the compiler reports.
--- arch/powerpc/include/uapi/asm/byteorder.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/powerpc/include/uapi/asm/byteorder.h +4 -0
@@ -7,6 +7,10 @@* as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ +#ifdef __LITTLE_ENDIAN__ +#include <linux/byteorder/little_endian.h> +#else #include <linux/byteorder/big_endian.h> +#endif #endif /* _ASM_POWERPC_BYTEORDER_H */
Signature · 1 line
1.8.1.2
PATCH 11/39 powerpc: endian safe trampoline
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
Create a trampoline that works in either endian and flips to the expected endian. Use it for primary and secondary thread entry as well as RTAS and OF call return.
--- arch/powerpc/include/asm/ppc_asm.h | 31 ++++++++++++++++++++++++++++++- arch/powerpc/kernel/entry_64.S | 36 ++++++++++++++++++++---------------- arch/powerpc/kernel/head_64.S | 3 +++ 3 files changed, 53 insertions(+), 17 deletions(-)
arch/powerpc/include/asm/ppc_asm.h +30 -1
@@ -845,6 +845,35 @@ END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,946)#define N_SLINE 68#define N_SO 100 -#endif /* __ASSEMBLY__ */ +/* +* Create an endian fixup trampoline +* +* This starts with a "tdi 0,0,0x48" instruction which is +* essentially a "trap never", and thus akin to a nop. +* +* The opcode for this instruction read with the wrong endian +* however results in a b . + 8 +* +* So essentially we use that trick to execute the following +* trampoline in "reverse endian" if we are running with the +* MSR_LE bit set the "wrong" way for whatever endianness the +* kernel is built for. +*/ +#ifdef CONFIG_PPC_BOOK3E +#define FIXUP_ENDIAN +#else +#define FIXUP_ENDIAN \ + tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ + b $+36; /* Skip trampoline if endian is good */ \ + .long 0x05009f42; /* bcl 20,31,$+4 */ \ + .long 0xa602487d; /* mflr r10 */ \ + .long 0x1c004a39; /* addi r10,r10,28 */ \ + .long 0xa600607d; /* mfmsr r11 */ \ + .long 0x01006b69; /* xori r11,r11,1 */ \ + .long 0xa6035a7d; /* mtsrr0 r10 */ \ + .long 0xa6037b7d; /* mtsrr1 r11 */ \ + .long 0x2400004c /* rfid */ +#endif /* !CONFIG_PPC_BOOK3E */ +#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_PPC_ASM_H */
arch/powerpc/kernel/entry_64.S +20 -16
@@ -1017,7 +1017,7 @@ _GLOBAL(enter_rtas) li r9,1 rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG) - ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI + ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI|MSR_LE andc r6,r0,r9 sync /* disable interrupts so SRR0/1 */ mtmsrd r0 /* don't get trashed */
@@ -1032,6 +1032,8 @@ _GLOBAL(enter_rtas) b . /* prevent speculative execution */ _STATIC(rtas_return_loc) + FIXUP_ENDIAN + /* relocation is off at this point */ GET_PACA(r4) clrldi r4,r4,2 /* convert to realmode address */
@@ -1103,28 +1105,30 @@ _GLOBAL(enter_prom) std r10,_CCR(r1) std r11,_MSR(r1) - /* Get the PROM entrypoint */ - mtlr r4 + /* Put PROM address in SRR0 */ + mtsrr0 r4 + + /* Setup our trampoline return addr in LR */ + bcl 20,31,$+4 +0: mflr r4 + addi r4,r4,(1f - 0b) + mtlr r4 - /* Switch MSR to 32 bits mode + /* Prepare a 32-bit mode big endian MSR */ #ifdef CONFIG_PPC_BOOK3E rlwinm r11,r11,0,1,31 - mtmsr r11 + mtsrr1 r11 + rfi #else /* CONFIG_PPC_BOOK3E */ - mfmsr r11 - li r12,1 - rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG) - andc r11,r11,r12 - li r12,1 - rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG) - andc r11,r11,r12 - mtmsrd r11 + LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_ISF | MSR_LE) + andc r11,r11,r12 + mtsrr1 r11 + rfid #endif /* CONFIG_PPC_BOOK3E */ - isync - /* Enter PROM here... */ - blrl +1: /* Return from OF */ + FIXUP_ENDIAN /* Just make sure that r1 top 32 bits didn't get * corrupt by OF
arch/powerpc/kernel/head_64.S +3 -0
@@ -68,6 +68,7 @@ _stext: _GLOBAL(__start) /* NOP this out unconditionally */ BEGIN_FTR_SECTION + FIXUP_ENDIAN b .__start_initialization_multiplatform END_FTR_SECTION(0, 1)
@@ -115,6 +116,7 @@ __run_at_load: */ .globl __secondary_hold __secondary_hold: + FIXUP_ENDIAN #ifndef CONFIG_PPC_BOOK3E mfmsr r24 ori r24,r24,MSR_RI
@@ -205,6 +207,7 @@ _GLOBAL(generic_secondary_thread_init) * as SCOM before entry). */ _GLOBAL(generic_secondary_smp_init) + FIXUP_ENDIAN mr r24,r3 mr r25,r4
Signature · 1 line
1.8.1.2
Re: [PATCH 11/39] powerpc: endian safe trampoline
Nothing like some holiday powerpc early boot debugging. :-)
Quoted 8 lines · Anton Blanchard
From: Benjamin Herrenschmidt <[email protected]>
Create a trampoline that works in either endian and flips to the expected endian. Use it for primary and secondary thread entry as well as RTAS and OF call return.
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by Anton Blanchard <[email protected]>
Some users reported failure with their kernel config to build and run 3.13-rc5. pasemi_defconfig boots just fine, but it seems that ppc64_defconfig does not.
I've bisected it down to this particular patch. More below.
Quoted 28 lines
arch/powerpc/include/asm/ppc_asm.h +18
-1@@ -845,6 +845,35 @@ END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,946)#define N_SLINE 68#define N_SO 100 -#endif /* __ASSEMBLY__ */ +/* +* Create an endian fixup trampoline +* +* This starts with a "tdi 0,0,0x48" instruction which is +* essentially a "trap never", and thus akin to a nop. +* +* The opcode for this instruction read with the wrong endian +* however results in a b . + 8 +* +* So essentially we use that trick to execute the following +* trampoline in "reverse endian" if we are running with the +* MSR_LE bit set the "wrong" way for whatever endianness the +* kernel is built for. +*/ +#ifdef CONFIG_PPC_BOOK3E +#define FIXUP_ENDIAN +#else +#define FIXUP_ENDIAN \
arch/powerpc/include/asm/ppc_asm.h END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,946) · line 876
Quoted 10 lines
arch/powerpc/include/asm/ppc_asm.h +10
-0+ tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ + b $+36; /* Skip trampoline if endian is good */ \ + .long 0x05009f42; /* bcl 20,31,$+4 */ \ + .long 0xa602487d; /* mflr r10 */ \ + .long 0x1c004a39; /* addi r10,r10,28 */ \ + .long 0xa600607d; /* mfmsr r11 */ \ + .long 0x01006b69; /* xori r11,r11,1 */ \ + .long 0xa6035a7d; /* mtsrr0 r10 */ \ + .long 0xa6037b7d; /* mtsrr1 r11 */ \ + .long 0x2400004c /* rfid */
So, the combination of this sequence and its execution at __start seems to be what's causing problems for me. I've both commented out and nopped out the second instruction and the handcoded LE opcodes, and it makes no difference -- it seems to be the execution of the tdi that traps or causes some other problem. And yeah -- it definitely shouldn't since TO is 0. Likewise if I replace the tdi with nop and keep the rest it runs fine.
I'm a bit baffled that there's a difference based on what config is booted. I'm booting a raw vmlinux from a BE firmware. Initial code sequence is largely the same for both configs.
Unfortunately I no longer have a JTAG environment such that I can check the value of r0 at the time of tdi execution. Still, based on docs it shouldn't matter since there are no TO bits set. I don't see a rational reason to why the above should fail. And indeed, if I load a known-different value and set TO=4, I still see failures. Etc.
I also tried moving the FIXUP_ENDIAN call until after the branch to __start_initialization_multiplatform but before 64-bit enable and there it runs just fine.
So, I'm really quite baffled right now. Any ideas would be welcome, I'm sort of stumped. In particular since pasemi_defconfig boots fine.
-Olof
Re: [PATCH 11/39] powerpc: endian safe trampoline
Quoted 3 lines · Olof Johansson
So, I'm really quite baffled right now. Any ideas would be welcome, I'm sort of stumped. In particular since
pasemi_defconfigboots fine.
So you are coming in with "good" endian... what if you stick an isync in there just for fun ? I wonder if it prefetches the "bad" instructions and somewhat gets itself confused.
Also did you try sticking a b . around 0x700 see if that's where it's going and what condition gets set ?
Cheers,
Ben.
PATCH 12/39 powerpc: Remove open coded byte swap macro in alignment handler
In reply to Anton BlanchardUse swab64/32/16 instead of open coding it.
--- arch/powerpc/kernel/align.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
arch/powerpc/kernel/align.c +12 -24
@@ -54,8 +54,6 @@ struct aligninfo {/* DSISR bits reported for a DCBZ instruction: */ #define DCBZ 0x5f/* 8xx/82xx dcbz faults when cache not enabled */ -#define SWAP (a, b) (t = (a), (a) = (b), (b) = t) -/* * The PowerPC stores certain bits of the instruction that caused the * alignment exception in the DSISR register. This array maps those
@@ -458,7 +456,7 @@ static struct aligninfo spe_aligninfo[32] = {static int emulate_spe (struct pt_regs *regs,unsigned int reg,unsigned int instr) { -int t, ret; +int ret;union {u64 ll;u32 w[2 ];
@@ -581,24 +579,18 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,if (flags &SW ) {switch (flags &0xf0 ) {case E8 : -SWAP (data.v[0 ], data.v[7 ]); -SWAP (data.v[1 ], data.v[6 ]); -SWAP (data.v[2 ], data.v[5 ]); -SWAP (data.v[3 ], data.v[4 ]); + data.ll =swab64 (data.ll);break ;case E4 : - -SWAP (data.v[0 ], data.v[3 ]); -SWAP (data.v[1 ], data.v[2 ]); -SWAP (data.v[4 ], data.v[7 ]); -SWAP (data.v[5 ], data.v[6 ]); + data.w[0 ] =swab32 (data.w[0 ]); + data.w[1 ] =swab32 (data.w[1 ]);break ;/* Its half word endian */ default : -SWAP (data.v[0 ], data.v[1 ]); -SWAP (data.v[2 ], data.v[3 ]); -SWAP (data.v[4 ], data.v[5 ]); -SWAP (data.v[6 ], data.v[7 ]); + data.h[0 ] =swab16 (data.h[0 ]); + data.h[1 ] =swab16 (data.h[1 ]); + data.h[2 ] =swab16 (data.h[2 ]); + data.h[3 ] =swab16 (data.h[3 ]);break ; } }
@@ -710,7 +702,7 @@ int fix_alignment(struct pt_regs *regs)unsigned int dsisr;unsigned char __user *addr;unsigned long p, swiz; -int ret, t; +int ret;union {u64 ll;double dd;
@@ -915,17 +907,13 @@ int fix_alignment(struct pt_regs *regs)if (flags &SW ) {switch (nb) {case 8 : -SWAP (data.v[0 ], data.v[7 ]); -SWAP (data.v[1 ], data.v[6 ]); -SWAP (data.v[2 ], data.v[5 ]); -SWAP (data.v[3 ], data.v[4 ]); + data.ll =swab64 (data.ll);break ;case 4 : -SWAP (data.v[4 ], data.v[7 ]); -SWAP (data.v[5 ], data.v[6 ]); + data.x32.low32 =swab32 (data.x32.low32);break ;case 2 : -SWAP (data.v[6 ], data.v[7 ]); + data.x16.low16 =swab16 (data.x16.low16);break ; } }
Signature · 1 line
1.8.1.2
PATCH 13/39 powerpc: Remove hard coded FP offsets in alignment handler
In reply to Anton BlanchardThe alignment handler assumes big endian ordering when selecting the low word of a 64bit floating point value. Use the existing union which works in both little and big endian.
--- arch/powerpc/kernel/align.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/align.c +2 -2
@@ -895,7 +895,7 @@ int fix_alignment(struct pt_regs *regs)#ifdef CONFIG_PPC_FPU preempt_disable ();enable_kernel_fp (); -cvt_df (&data.dd, (float *)&data.v[4 ]); +cvt_df (&data.dd, (float *)&data.x32.low32);preempt_enable ();#else return 0 ;
@@ -935,7 +935,7 @@ int fix_alignment(struct pt_regs *regs)#ifdef CONFIG_PPC_FPU preempt_disable ();enable_kernel_fp (); -cvt_fd ((float *)&data.v[4 ], &data.dd); +cvt_fd ((float *)&data.x32.low32, &data.dd);preempt_enable ();#else return 0 ;
Signature · 1 line
1.8.1.2
PATCH 14/39 powerpc: Alignment handler shouldn't access VSX registers with TS_FPR
In reply to Anton BlanchardThe TS_FPR macro selects the FPR component of a VSX register (the high doubleword). emulate_vsx is using this macro to get the address of the associated VSX register. This happens to work on big endian, but fails on little endian.
Replace it with an explicit array access.
--- arch/powerpc/kernel/align.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/align.c +1 -1
@@ -650,7 +650,7 @@ static int emulate_vsx(unsigned char __user *addr, unsigned int reg,flush_vsx_to_thread (current);if (reg <32 ) - ptr = (char *) ¤t->thread.TS_FPR (reg); + ptr = (char *) ¤t->thread.fpr[reg][0 ];else ptr = (char *) ¤t->thread.vr[reg -32 ];
Signature · 1 line
1.8.1.2
PATCH 15/39 powerpc: Add little endian support to alignment handler
In reply to Anton BlanchardHandle most unaligned load and store faults in little endian mode. Strings, multiples and VSX are not supported.
--- arch/powerpc/kernel/align.c | 93 ++++++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 30 deletions(-)
arch/powerpc/kernel/align.c +63 -30
@@ -262,6 +262,7 @@ static int emulate_dcbz(struct pt_regs *regs, unsigned char __user *addr)#define SWIZ_PTR (p) ((unsigned char __user *)((p) ^ swiz)) +#ifdef __BIG_ENDIAN__ static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr, unsigned int reg, unsigned int nb, unsigned int flags, unsigned int instr,
@@ -390,6 +391,7 @@ static int emulate_fp_pair(unsigned char __user *addr, unsigned int reg,return -EFAULT ; return 1; /* exception handled and fixed up */ } +#endif #ifdef CONFIG_SPE
@@ -628,7 +630,7 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg, }#endif /* CONFIG_SPE */ -#ifdef CONFIG_VSX +#if defined(CONFIG_VSX ) && defined(__BIG_ENDIAN__)/* * Emulate VSX instructions... */
@@ -702,18 +704,28 @@ int fix_alignment(struct pt_regs *regs)unsigned int dsisr;unsigned char __user *addr;unsigned long p, swiz; -int ret; -union { +int ret, i; +union data {u64 ll;double dd;unsigned char v[8 ];struct { +#ifdef __LITTLE_ENDIAN__ +int low32; +unsigned hi32; +#else unsigned hi32;int low32; +#endif } x32;struct { +#ifdef __LITTLE_ENDIAN__ +short low16; +unsigned char hi48[6 ]; +#else unsigned char hi48[6 ];short low16; +#endif } x16; } data;
@@ -772,8 +784,9 @@ int fix_alignment(struct pt_regs *regs)/* Byteswap little endian loads and stores */ swiz =0 ; -if (regs->msr &MSR_LE ) { +if ((regs->msr &MSR_LE ) != (MSR_KERNEL &MSR_LE )) { flags ^=SW ; +#ifdef __BIG_ENDIAN__/* * So-called "PowerPC little endian" mode works by * swizzling addresses rather than by actually doing
@@ -786,11 +799,13 @@ int fix_alignment(struct pt_regs *regs)*/ if (cpu_has_feature (CPU_FTR_PPC_LE )) swiz =7 ; +#endif }/* DAR has the operand effective address */ addr = (unsigned char __user *)regs->dar; +#ifdef __BIG_ENDIAN__ #ifdef CONFIG_VSX if ((instruction & 0xfc00003e) == 0x7c000018) { unsigned int elsize;
@@ -810,7 +825,7 @@ int fix_alignment(struct pt_regs *regs) elsize =8 ; flags =0 ; -if (regs->msr &MSR_LE ) +if ((regs->msr &MSR_LE ) != (MSR_KERNEL &MSR_LE )) flags |=SW ;if (instruction &0x100 ) flags |=ST ;
@@ -825,6 +840,9 @@ int fix_alignment(struct pt_regs *regs)return emulate_vsx (addr, reg, areg, regs, flags, nb, elsize); }#endif +#else +return -EFAULT ; +#endif /* A size of 0 indicates an instruction we don't support, with * the exception of DCBZ which is handled as a special case here */
@@ -839,9 +857,13 @@ int fix_alignment(struct pt_regs *regs)* function */ if (flags &M ) { +#ifdef __BIG_ENDIAN__PPC_WARN_ALIGNMENT (multiple, regs);return emulate_multiple (regs, addr, reg, nb, flags, instr, swiz); +#else +return -EFAULT ; +#endif }/* Verify the address of the operand */
@@ -860,8 +882,12 @@ int fix_alignment(struct pt_regs *regs)/* Special case for 16-byte FP loads and stores */ if (nb ==16 ) { +#ifdef __BIG_ENDIAN__PPC_WARN_ALIGNMENT (fp_pair, regs);return emulate_fp_pair (addr, reg, flags); +#else +return -EFAULT ; +#endif }PPC_WARN_ALIGNMENT (unaligned, regs);
@@ -870,24 +896,28 @@ int fix_alignment(struct pt_regs *regs)* get it from register values */ if (!(flags &ST )) { - data.ll =0 ; - ret =0 ; - p = (unsigned long ) addr; +unsigned int start =0 ; +switch (nb) { -case 8 : - ret |=__get_user_inatomic (data.v[0 ],SWIZ_PTR (p++)); - ret |=__get_user_inatomic (data.v[1 ],SWIZ_PTR (p++)); - ret |=__get_user_inatomic (data.v[2 ],SWIZ_PTR (p++)); - ret |=__get_user_inatomic (data.v[3 ],SWIZ_PTR (p++));case 4 : - ret |=__get_user_inatomic (data.v[4 ],SWIZ_PTR (p++)); - ret |=__get_user_inatomic (data.v[5 ],SWIZ_PTR (p++)); + start = offsetof(union data, x32.low32); +break ;case 2 : - ret |=__get_user_inatomic (data.v[6 ],SWIZ_PTR (p++)); - ret |=__get_user_inatomic (data.v[7 ],SWIZ_PTR (p++)); -if (unlikely (ret)) -return -EFAULT ; + start = offsetof(union data, x16.low16); +break ; } + + data.ll =0 ; + ret =0 ; + p = (unsigned long )addr; + +for (i =0 ; i < nb; i++) + ret |=__get_user_inatomic (data.v[start + i], +SWIZ_PTR (p++)); + +if (unlikely (ret)) +return -EFAULT ; + }else if (flags &F ) { data.dd = current->thread.TS_FPR (reg);if (flags &S ) {
@@ -945,21 +975,24 @@ int fix_alignment(struct pt_regs *regs)/* Store result to memory or update registers */ if (flags &ST ) { - ret =0 ; - p = (unsigned long ) addr; +unsigned int start =0 ; +switch (nb) { -case 8 : - ret |=__put_user_inatomic (data.v[0 ],SWIZ_PTR (p++)); - ret |=__put_user_inatomic (data.v[1 ],SWIZ_PTR (p++)); - ret |=__put_user_inatomic (data.v[2 ],SWIZ_PTR (p++)); - ret |=__put_user_inatomic (data.v[3 ],SWIZ_PTR (p++));case 4 : - ret |=__put_user_inatomic (data.v[4 ],SWIZ_PTR (p++)); - ret |=__put_user_inatomic (data.v[5 ],SWIZ_PTR (p++)); + start = offsetof(union data, x32.low32); +break ;case 2 : - ret |=__put_user_inatomic (data.v[6 ],SWIZ_PTR (p++)); - ret |=__put_user_inatomic (data.v[7 ],SWIZ_PTR (p++)); + start = offsetof(union data, x16.low16); +break ; } + + ret =0 ; + p = (unsigned long )addr; + +for (i =0 ; i < nb; i++) + ret |=__put_user_inatomic (data.v[start + i], +SWIZ_PTR (p++)); +if (unlikely (ret))return -EFAULT ; }else if (flags &F )
Signature · 1 line
1.8.1.2
PATCH 16/39 powerpc: Handle VSX alignment faults in little endian mode
In reply to Anton BlanchardThings are complicated by the fact that VSX elements are big endian ordered even in little endian mode. 8 byte loads and stores also write to the top 8 bytes of the register.
--- arch/powerpc/kernel/align.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)
arch/powerpc/kernel/align.c +33 -8
@@ -630,7 +630,7 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg, }#endif /* CONFIG_SPE */ -#if defined(CONFIG_VSX ) && defined(__BIG_ENDIAN__) +#ifdef CONFIG_VSX /* * Emulate VSX instructions... */
@@ -658,8 +658,25 @@ static int emulate_vsx(unsigned char __user *addr, unsigned int reg, lptr = (unsigned long *) ptr; +#ifdef __LITTLE_ENDIAN__ +if (flags &SW ) { + elsize = length; + sw = length-1 ; + }else { +/* +* The elements are BE ordered, even in LE mode, so process +* them in reverse order. +*/ + addr += length - elsize; + +/* 8 byte memory accesses go in the top 8 bytes of the VR */ +if (length ==8 ) + ptr +=8 ; + } +#else if (flags &SW ) sw = elsize-1 ; +#endif for (j =0 ; j < length; j += elsize) {for (i =0 ; i < elsize; ++i) {
@@ -669,19 +686,31 @@ static int emulate_vsx(unsigned char __user *addr, unsigned int reg, ret |=__get_user (ptr[i^sw], addr + i); } ptr += elsize; +#ifdef __LITTLE_ENDIAN__ + addr -= elsize; +#else addr += elsize; +#endif } +#ifdef __BIG_ENDIAN__ +#define VSX_HI 0 +#define VSX_LO 1 +#else +#define VSX_HI 1 +#define VSX_LO 0 +#endif +if (!ret) {if (flags &U ) regs->gpr[areg] = regs->dar;/* Splat load copies the same data to top and bottom 8 bytes */ if (flags &SPLT ) - lptr[1 ] = lptr[0 ]; -/* For 8 byte loads, zero the top 8 bytes */ + lptr[VSX_LO ] = lptr[VSX_HI ]; +/* For 8 byte loads, zero the low 8 bytes */ else if (!(flags &ST ) && (8 == length)) - lptr[1 ] =0 ; + lptr[VSX_LO ] =0 ; }else return -EFAULT ;
@@ -805,7 +834,6 @@ int fix_alignment(struct pt_regs *regs)/* DAR has the operand effective address */ addr = (unsigned char __user *)regs->dar; -#ifdef __BIG_ENDIAN__#ifdef CONFIG_VSX if ((instruction &0xfc00003e ) ==0x7c000018 ) {unsigned int elsize;
@@ -840,9 +868,6 @@ int fix_alignment(struct pt_regs *regs) return emulate_vsx(addr, reg, areg, regs, flags, nb, elsize); }#endif -#else -return -EFAULT ; -#endif /* A size of 0 indicates an instruction we don't support, with * the exception of DCBZ which is handled as a special case here */
Signature · 1 line
1.8.1.2
PATCH 17/39 powerpc: Use generic checksum code in little endian
In reply to Anton BlanchardWe need to fix some endian issues in our checksum code. For now just enable the generic checksum routines for little endian builds.
--- arch/powerpc/Kconfig | 3 +++ arch/powerpc/include/asm/checksum.h | 5 +++++ arch/powerpc/kernel/ppc_ksyms.c | 2 ++ arch/powerpc/lib/Makefile | 9 +++++++-- 4 files changed, 17 insertions(+), 2 deletions(-)
arch/powerpc/Kconfig +3 -0
@@ -140,6 +140,9 @@ config PPC select OLD_SIGACTION if PPC32 select HAVE_DEBUG_STACKOVERFLOW +config GENERIC_CSUM + def_bool CPU_LITTLE_ENDIAN + config EARLY_PRINTK bool default y
arch/powerpc/include/asm/checksum.h +5 -0
@@ -14,6 +14,9 @@* which always checksum on 4 octet boundaries. ihl is the number * of 32-bit words and is always >= 5. */ +#ifdef CONFIG_GENERIC_CSUM +#include <asm-generic/checksum.h> +#else extern __sum16 ip_fast_csum (const void *iph,unsigned int ihl);/*
@@ -123,5 +126,7 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,return sum;#endif } + +#endif #endif /* __KERNEL__ */ #endif
arch/powerpc/kernel/ppc_ksyms.c +2 -0
@@ -79,10 +79,12 @@ EXPORT_SYMBOL(strlen);EXPORT_SYMBOL (strcmp);EXPORT_SYMBOL (strncmp); +#ifndef CONFIG_GENERIC_CSUM EXPORT_SYMBOL (csum_partial);EXPORT_SYMBOL (csum_partial_copy_generic);EXPORT_SYMBOL (ip_fast_csum);EXPORT_SYMBOL (csum_tcpudp_magic); +#endif EXPORT_SYMBOL (__copy_tofrom_user);EXPORT_SYMBOL (__clear_user);
arch/powerpc/lib/Makefile +7 -2
@@ -10,15 +10,20 @@ CFLAGS_REMOVE_code-patching.o = -pg CFLAGS_REMOVE_feature-fixups.o = -pg obj-y := string.o alloc.o \ - checksum_$(CONFIG_WORD_SIZE).o crtsavres.o + crtsavres.o obj-$(CONFIG_PPC32) += div64.o copy_32.o obj-$(CONFIG_HAS_IOMEM) += devres.o obj-$(CONFIG_PPC64) += copypage_64.o copyuser_64.o \ memcpy_64.o usercopy_64.o mem_64.o string.o \ - checksum_wrappers_64.o hweight_64.o \ + hweight_64.o \ copyuser_power7.o string_64.o copypage_power7.o \ memcpy_power7.o +ifeq ($(CONFIG_GENERIC_CSUM),) +obj-y += checksum_$(CONFIG_WORD_SIZE).o +obj-$(CONFIG_PPC64) += checksum_wrappers_64.o +endif + obj-$(CONFIG_PPC_EMULATE_SSTEP) += sstep.o ldstfp.o ifeq ($(CONFIG_PPC64),y)
Signature · 1 line
1.8.1.2
PATCH 18/39 powerpc: Use generic memcpy code in little endian
In reply to Anton BlanchardWe need to fix some endian issues in our memcpy code. For now just enable the generic memcpy routine for little endian builds.
--- arch/powerpc/include/asm/string.h | 4 ++++ arch/powerpc/kernel/ppc_ksyms.c | 2 ++ arch/powerpc/lib/Makefile | 9 ++++++--- 3 files changed, 12 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/string.h +4 -0
@@ -10,7 +10,9 @@#define __HAVE_ARCH_STRNCMP#define __HAVE_ARCH_STRCAT#define __HAVE_ARCH_MEMSET +#ifdef __BIG_ENDIAN__#define __HAVE_ARCH_MEMCPY +#endif #define __HAVE_ARCH_MEMMOVE#define __HAVE_ARCH_MEMCMP#define __HAVE_ARCH_MEMCHR
@@ -22,7 +24,9 @@ extern int strcmp(const char *,const char *);extern int strncmp (const char *,const char *,__kernel_size_t );extern char *strcat (char *,const char *);extern void *memset (void *,int ,__kernel_size_t ); +#ifdef __BIG_ENDIAN__extern void *memcpy (void *,const void *,__kernel_size_t ); +#endif extern void *memmove (void *,const void *,__kernel_size_t );extern int memcmp (const void *,const void *,__kernel_size_t );extern void *memchr (const void *,int ,__kernel_size_t );
arch/powerpc/kernel/ppc_ksyms.c +2 -0
@@ -148,7 +148,9 @@ EXPORT_SYMBOL(__ucmpdi2);#endif long long __bswapdi2 (long long );EXPORT_SYMBOL (__bswapdi2); +#ifdef __BIG_ENDIAN__EXPORT_SYMBOL (memcpy); +#endif EXPORT_SYMBOL (memset);EXPORT_SYMBOL (memmove);EXPORT_SYMBOL (memcmp);
arch/powerpc/lib/Makefile +6 -3
@@ -15,15 +15,18 @@ obj-$(CONFIG_PPC32) += div64.o copy_32.o obj-$(CONFIG_HAS_IOMEM) += devres.o obj-$(CONFIG_PPC64) += copypage_64.o copyuser_64.o \ - memcpy_64.o usercopy_64.o mem_64.o string.o \ + usercopy_64.o mem_64.o string.o \ hweight_64.o \ - copyuser_power7.o string_64.o copypage_power7.o \ - memcpy_power7.o + copyuser_power7.o string_64.o copypage_power7.o ifeq ($(CONFIG_GENERIC_CSUM),) obj-y += checksum_$(CONFIG_WORD_SIZE).o obj-$(CONFIG_PPC64) += checksum_wrappers_64.o endif +ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),) +obj-$(CONFIG_PPC64) += memcpy_power7.o memcpy_64.o +endif + obj-$(CONFIG_PPC_EMULATE_SSTEP) += sstep.o ldstfp.o ifeq ($(CONFIG_PPC64),y)
Signature · 1 line
1.8.1.2
PATCH 19/39 powerpc: uname should return ppc64le/ppcle on little endian builds
In reply to Anton BlanchardWe need to distinguish between big endian and little endian environments, so fix uname to return the right thing.
--- arch/powerpc/Makefile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/powerpc/Makefile +11 -2
@@ -36,17 +36,26 @@ KBUILD_DEFCONFIG := ppc64_defconfig endif ifeq ($(CONFIG_PPC64),y) -OLDARCH := ppc64 - new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi) ifeq ($(new_nm),y) NM := $(NM) --synthetic endif +endif +ifeq ($(CONFIG_PPC64),y) +ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) +OLDARCH := ppc64le +else +OLDARCH := ppc64 +endif +else +ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) +OLDARCH := ppcle else OLDARCH := ppc endif +endif # It seems there are times we use this Makefile without # including the config file, but this replicates the old behaviour
Signature · 1 line
1.8.1.2
PATCH 20/39 powerpc: Little endian fixes for platforms/powernv/opal.c
In reply to Anton BlanchardFrom: Alistair Popple <[email protected]>
--- arch/powerpc/platforms/powernv/opal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/platforms/powernv/opal.c +1 -1
@@ -372,7 +372,7 @@ static irqreturn_t opal_interrupt(int irq, void *data)static int __init opal_init (void ) {struct device_node *np, *consoles; -const u32 *irqs; +const __be32 *irqs;int rc, i, irqlen; opal_node =of_find_node_by_path ("/ibm,opal" );
Signature · 1 line
1.8.1.2
PATCH 21/39 powerpc: Little endian fix for arch/powerpc/platforms/powernv/pci.c
In reply to Anton BlanchardFrom: Alistair Popple <[email protected]>
--- arch/powerpc/platforms/powernv/pci.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
arch/powerpc/platforms/powernv/pci.c +5 -4
@@ -462,8 +462,8 @@ void pnv_pci_setup_iommu_table(struct iommu_table *tbl,static struct iommu_table *pnv_pci_setup_bml_iommu (struct pci_controller *hose) {struct iommu_table *tbl; -const __be64 *basep, *swinvp; -const __be32 *sizep; +const __be64 *basep; +const __be32 *sizep, *swinvp; basep =of_get_property (hose->dn,"linux,tce-base" ,NULL ); sizep =of_get_property (hose->dn,"linux,tce-size" ,NULL );
@@ -484,8 +484,9 @@ static struct iommu_table *pnv_pci_setup_bml_iommu(struct pci_controller *hose) swinvp =of_get_property (hose->dn,"linux,tce-sw-invalidate-info" ,NULL );if (swinvp) { - tbl->it_busno = swinvp[1 ]; - tbl->it_index = (unsigned long )ioremap (swinvp[0 ],8 ); + tbl->it_busno =of_read_ulong (&swinvp[1 ],2 ); + tbl->it_index = + (unsigned long )ioremap (of_read_number (swinvp,2 ),8 ); tbl->it_type =TCE_PCI_SWINV_CREATE |TCE_PCI_SWINV_FREE ; }return tbl;
Signature · 1 line
1.8.1.2
PATCH 22/39 powerpc: Little endian fix for arch/powerpc/platforms/powernv/pci-p5ioc2.c
In reply to Anton BlanchardFrom: Alistair Popple <[email protected]>
--- arch/powerpc/platforms/powernv/pci-p5ioc2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/pci-p5ioc2.c +2 -2
@@ -99,7 +99,7 @@ static void __init pnv_pci_init_p5ioc2_phb(struct device_node *np, u64 hub_id, void *tce_mem, u64 tce_size) {struct pnv_phb *phb; -const u64 *prop64; +const __be64 *prop64;u64 phb_id;int64_t rc;static int primary =1 ;
@@ -178,7 +178,7 @@ static void __init pnv_pci_init_p5ioc2_phb(struct device_node *np, u64 hub_id,void __init pnv_pci_init_p5ioc2_hub (struct device_node *np) {struct device_node *phbn; -const u64 *prop64; +const __be64 *prop64;u64 hub_id;void *tce_mem;uint64_t tce_per_phb;
Signature · 1 line
1.8.1.2
PATCH 23/39 powerpc: Little endian sparse clean up for arch/powerpc/platforms/powernv/pci-ioda.c
In reply to Anton BlanchardFrom: Alistair Popple <[email protected]>
--- arch/powerpc/platforms/powernv/pci-ioda.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda.c +2 -2
@@ -1106,7 +1106,7 @@ void __init pnv_pci_init_ioda_phb(struct device_node *np,struct pci_controller *hose;struct pnv_phb *phb;unsigned long size, m32map_off, iomap_off, pemap_off; -const u64 *prop64; +const __be64 *prop64;const u32 *prop32;int len;u64 phb_id;
@@ -1285,7 +1285,7 @@ void __init pnv_pci_init_ioda2_phb(struct device_node *np)void __init pnv_pci_init_ioda_hub (struct device_node *np) {struct device_node *phbn; -const u64 *prop64; +const __be64 *prop64;u64 hub_id;pr_info ("Probing IODA IO-Hub %s\n" , np->full_name);
Signature · 1 line
1.8.1.2
PATCH 24/39 powerpc/powernv: Fix endian issues in OPAL RTC driver
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/platforms/powernv/opal-rtc.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/powerpc/platforms/powernv/opal-rtc.c +7 -0
@@ -48,6 +48,8 @@ unsigned long __init opal_get_boot_time(void) }if (rc !=OPAL_SUCCESS )return 0 ; + y_m_d =be32_to_cpu (y_m_d); + h_m_s_ms =be64_to_cpu (h_m_s_ms);opal_to_tm (y_m_d, h_m_s_ms, &tm);return mktime (tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
@@ -68,6 +70,8 @@ void opal_get_rtc_time(struct rtc_time *tm) }if (rc !=OPAL_SUCCESS )return ; + y_m_d =be32_to_cpu (y_m_d); + h_m_s_ms =be64_to_cpu (h_m_s_ms);opal_to_tm (y_m_d, h_m_s_ms, tm); }
@@ -86,6 +90,9 @@ int opal_set_rtc_time(struct rtc_time *tm) h_m_s_ms |= ((u64 )bin2bcd (tm->tm_min)) <<48 ; h_m_s_ms |= ((u64 )bin2bcd (tm->tm_sec)) <<40 ; + y_m_d =cpu_to_be32 (y_m_d); + h_m_s_ms =cpu_to_be64 (h_m_s_ms); +while (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { rc =opal_rtc_write (y_m_d, h_m_s_ms);if (rc ==OPAL_BUSY_EVENT )
Signature · 1 line
1.8.1.2
PATCH 25/39 powerpc/powernv: Fix endian issues in OPAL ICS backend
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/sysdev/xics/ics-opal.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
arch/powerpc/sysdev/xics/ics-opal.c +9 -8
@@ -112,6 +112,7 @@ static int ics_opal_set_affinity(struct irq_data *d, bool force) {unsigned int hw_irq = (unsigned int )irqd_to_hwirq (d); +__be16 oserver;int16_t server;int8_t priority;int64_t rc;
@@ -120,13 +121,13 @@ static int ics_opal_set_affinity(struct irq_data *d,if (hw_irq ==XICS_IPI || hw_irq ==XICS_IRQ_SPURIOUS )return -1 ; - rc =opal_get_xive (hw_irq, &server, &priority); + rc =opal_get_xive (hw_irq, &oserver, &priority);if (rc !=OPAL_SUCCESS ) { -pr_err ("%s: opal_set_xive(irq=%d [hw 0x%x] server=%x)" -" error %lld\n" , - __func__, d->irq, hw_irq, server, rc); +pr_err ("%s: opal_get_xive(irq=%d [hw 0x%x]) error %lld\n" , + __func__, d->irq, hw_irq, rc);return -1 ; } + server =be16_to_cpu (oserver); wanted_server =xics_get_irq_server (d->irq, cpumask,1 );if (wanted_server <0 ) {
@@ -181,7 +182,7 @@ static int ics_opal_map(struct ics *ics, unsigned int virq) {unsigned int hw_irq = (unsigned int )virq_to_hw (virq);int64_t rc; -int16_t server; +__be16 server;int8_t priority;if (WARN_ON (hw_irq ==XICS_IPI || hw_irq ==XICS_IRQ_SPURIOUS ))
@@ -201,7 +202,7 @@ static int ics_opal_map(struct ics *ics, unsigned int virq)static void ics_opal_mask_unknown (struct ics *ics,unsigned long vec) {int64_t rc; -int16_t server; +__be16 server;int8_t priority;/* Check if HAL knows about this interrupt */
@@ -215,14 +216,14 @@ static void ics_opal_mask_unknown(struct ics *ics, unsigned long vec)static long ics_opal_get_server (struct ics *ics,unsigned long vec) {int64_t rc; -int16_t server; +__be16 server;int8_t priority;/* Check if HAL knows about this interrupt */ rc =opal_get_xive (vec, &server, &priority);if (rc !=OPAL_SUCCESS )return -1 ; -return ics_opal_unmangle_server (server); +return ics_opal_unmangle_server (be16_to_cpu (server)); }int __init ics_opal_init (void )
Signature · 1 line
1.8.1.2
PATCH 26/39 powerpc/powernv: Make OPAL NVRAM device tree accesses endian safe
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/platforms/powernv/opal-nvram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/opal-nvram.c +2 -2
@@ -65,7 +65,7 @@ static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)void __init opal_nvram_init (void ) {struct device_node *np; -const u32 *nbytes_p; +const __be32 *nbytes_p; np =of_find_compatible_node (NULL ,NULL ,"ibm,opal-nvram" );if (np ==NULL )
@@ -76,7 +76,7 @@ void __init opal_nvram_init(void)of_node_put (np);return ; } - nvram_size = *nbytes_p; + nvram_size =be32_to_cpup (nbytes_p);printk (KERN_INFO "OPAL nvram setup, %u bytes\n" , nvram_size);of_node_put (np);
Signature · 1 line
1.8.1.2
PATCH 27/39 powerpc/powernv: Fix endian issues in powernv PCI code
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/platforms/powernv/pci-ioda.c | 31 +++++++++++++++++-------------- arch/powerpc/platforms/powernv/pci.c | 27 +++++++++++++-------------- 2 files changed, 30 insertions(+), 28 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda.c +17 -14
@@ -457,7 +457,7 @@ static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)static void pnv_pci_ioda1_tce_invalidate (struct iommu_table *tbl,u64 *startp,u64 *endp) { -u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index; +__be64 __iomem *invalidate = (__be64 __iomem *)tbl->it_index;unsigned long start, end, inc; start =__pa (startp);
@@ -484,7 +484,7 @@ static void pnv_pci_ioda1_tce_invalidate(struct iommu_table *tbl,mb ();/* Ensure above stores are visible */ while (start <= end) { -__raw_writeq (start, invalidate); +__raw_writeq (cpu_to_be64 (start), invalidate); start += inc; }
@@ -499,7 +499,7 @@ static void pnv_pci_ioda2_tce_invalidate(struct pnv_ioda_pe *pe, u64 *startp, u64 *endp) {unsigned long start, end, inc; -u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index; +__be64 __iomem *invalidate = (__be64 __iomem *)tbl->it_index;/* We'll invalidate DMA address in PE scope */ start =0x2ul <<60 ;
@@ -515,7 +515,7 @@ static void pnv_pci_ioda2_tce_invalidate(struct pnv_ioda_pe *pe,mb ();while (start <= end) { -__raw_writeq (start, invalidate); +__raw_writeq (cpu_to_be64 (start), invalidate); start += inc; } }
@@ -786,8 +786,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,struct irq_data *idata;struct irq_chip *ichip;unsigned int xive_num = hwirq - phb->msi_base; -uint64_t addr64; -uint32_t addr32, data; +__be32 data;int rc;/* No PE assigned ? bail out ... no MSI for you ! */
@@ -811,6 +810,8 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev, }if (is_64) { +__be64 addr64; + rc =opal_get_msi_64 (phb->opal_id, pe->mve_number, xive_num,1 , &addr64, &data);if (rc) {
@@ -818,9 +819,11 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev, pci_name(dev), rc);return -EIO ; } - msg->address_hi = addr64 >>32 ; - msg->address_lo = addr64 &0xfffffffful ; + msg->address_hi =be64_to_cpu (addr64) >>32 ; + msg->address_lo =be64_to_cpu (addr64) &0xfffffffful ; }else { +__be32 addr32; + rc =opal_get_msi_32 (phb->opal_id, pe->mve_number, xive_num,1 , &addr32, &data);if (rc) {
@@ -829,9 +832,9 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,return -EIO ; } msg->address_hi =0 ; - msg->address_lo = addr32; + msg->address_lo =be32_to_cpu (addr32); } - msg->data = data; + msg->data =be32_to_cpu (data);/* * Change the IRQ chip for the MSI interrupts on PHB3.
@@ -1107,7 +1110,7 @@ void __init pnv_pci_init_ioda_phb(struct device_node *np,struct pnv_phb *phb;unsigned long size, m32map_off, iomap_off, pemap_off;const __be64 *prop64; -const u32 *prop32; +const __be32 *prop32;int len;u64 phb_id;void *aux;
@@ -1142,8 +1145,8 @@ void __init pnv_pci_init_ioda_phb(struct device_node *np,spin_lock_init (&phb->lock); prop32 =of_get_property (np,"bus-range" , &len);if (prop32 && len ==8 ) { - hose->first_busno = prop32[0 ]; - hose->last_busno = prop32[1 ]; + hose->first_busno =be32_to_cpu (prop32[0 ]); + hose->last_busno =be32_to_cpu (prop32[1 ]); }else {pr_warn (" Broken <bus-range> on %s\n" , np->full_name); hose->first_busno =0 ;
@@ -1175,7 +1178,7 @@ void __init pnv_pci_init_ioda_phb(struct device_node *np,if (!prop32) phb->ioda.total_pe =1 ;else - phb->ioda.total_pe = *prop32; + phb->ioda.total_pe =be32_to_cpup (prop32); phb->ioda.m32_size =resource_size (&hose->mem_resources[0 ]);/* FW Has already off top 64k of M32 space (MSI space) */
arch/powerpc/platforms/powernv/pci.c +13 -14
@@ -236,7 +236,7 @@ static void pnv_pci_config_check_eeh(struct pnv_phb *phb, {s64 rc;u8 fstate; -u16 pcierr; +__be16 pcierr;u32 pe_no;/*
@@ -283,16 +283,16 @@ int pnv_pci_cfg_read(struct device_node *dn,break ; }case 2 : { -u16 v16; +__be16 v16; rc =opal_pci_config_read_half_word (phb->opal_id, bdfn, where, &v16); - *val = (rc ==OPAL_SUCCESS ) ? v16 :0xffff ; + *val = (rc ==OPAL_SUCCESS ) ?be16_to_cpu (v16) :0xffff ;break ; }case 4 : { -u32 v32; +__be32 v32; rc =opal_pci_config_read_word (phb->opal_id, bdfn, where, &v32); - *val = (rc ==OPAL_SUCCESS ) ? v32 :0xffffffff ; + *val = (rc ==OPAL_SUCCESS ) ?be32_to_cpu (v32) :0xffffffff ;break ; }default :
@@ -404,7 +404,7 @@ static int pnv_tce_build(struct iommu_table *tbl, long index, long npages, struct dma_attrs *attrs) {u64 proto_tce; -u64 *tcep, *tces; +__be64 *tcep, *tces;u64 rpn; proto_tce =TCE_PCI_READ ;// Read allowed
@@ -416,7 +416,7 @@ static int pnv_tce_build(struct iommu_table *tbl, long index, long npages, rpn =__pa (uaddr) >>TCE_SHIFT ;while (npages--) - *(tcep++) = proto_tce | (rpn++ <<TCE_RPN_SHIFT ); + *(tcep++) =cpu_to_be64 (proto_tce | (rpn++ <<TCE_RPN_SHIFT ));/* Some implementations won't cache invalid TCEs and thus may not * need that flush. We'll probably turn it_type into a bit mask
@@ -430,12 +430,12 @@ static int pnv_tce_build(struct iommu_table *tbl, long index, long npages,static void pnv_tce_free (struct iommu_table *tbl,long index,long npages) { -u64 *tcep, *tces; +__be64 *tcep, *tces; tces = tcep = ((u64 *)tbl->it_base) + index - tbl->it_offset;while (npages--) - *(tcep++) =0 ; + *(tcep++) =cpu_to_be64 (0 );if (tbl->it_type &TCE_PCI_SWINV_FREE )pnv_pci_ioda_tce_invalidate (tbl, tces, tcep -1 );
@@ -462,8 +462,8 @@ void pnv_pci_setup_iommu_table(struct iommu_table *tbl,static struct iommu_table *pnv_pci_setup_bml_iommu (struct pci_controller *hose) {struct iommu_table *tbl; -const __be64 *basep; -const __be32 *sizep, *swinvp; +const __be64 *basep, *swinvp; +const __be32 *sizep; basep =of_get_property (hose->dn,"linux,tce-base" ,NULL ); sizep =of_get_property (hose->dn,"linux,tce-size" ,NULL );
@@ -484,9 +484,8 @@ static struct iommu_table *pnv_pci_setup_bml_iommu(struct pci_controller *hose) swinvp =of_get_property (hose->dn,"linux,tce-sw-invalidate-info" ,NULL );if (swinvp) { - tbl->it_busno =of_read_ulong (&swinvp[1 ],2 ); - tbl->it_index = - (unsigned long )ioremap (of_read_number (swinvp,2 ),8 ); + tbl->it_busno = swinvp[1 ]; + tbl->it_index = (unsigned long )ioremap (be64_to_cpup (swinvp),8 ); tbl->it_type =TCE_PCI_SWINV_CREATE |TCE_PCI_SWINV_FREE ; }return tbl;
Signature · 1 line
1.8.1.2
PATCH 28/39 powerpc/powernv: Fix endian issues in OPAL console and udbg backend
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/include/asm/opal.h | 8 ++++---- arch/powerpc/platforms/powernv/opal.c | 28 ++++++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/opal.h +4 -4
@@ -537,12 +537,12 @@ typedef struct oppanel_line { } oppanel_line_t;/* API functions */ -int64_t opal_console_write (int64_t term_number,int64_t *length, +int64_t opal_console_write (int64_t term_number,__be64 *length,const uint8_t *buffer); -int64_t opal_console_read (int64_t term_number,int64_t *length, +int64_t opal_console_read (int64_t term_number,__be64 *length,uint8_t *buffer);int64_t opal_console_write_buffer_space (int64_t term_number, -int64_t *length); +__be64 *length);int64_t opal_rtc_read (uint32_t *year_month_day,uint64_t *hour_minute_second_millisecond); int64_t opal_rtc_write(uint32_t year_month_day,
@@ -552,7 +552,7 @@ int64_t opal_cec_reboot(void);int64_t opal_read_nvram (uint64_t buffer,uint64_t size,uint64_t offset);int64_t opal_write_nvram (uint64_t buffer,uint64_t size,uint64_t offset);int64_t opal_handle_interrupt (uint64_t isn,uint64_t *outstanding_event_mask); -int64_t opal_poll_events (uint64_t *outstanding_event_mask); +int64_t opal_poll_events (__be64 *outstanding_event_mask);int64_t opal_pci_set_hub_tce_memory (uint64_t hub_id,uint64_t tce_mem_addr,uint64_t tce_mem_size); int64_t opal_pci_set_phb_tce_memory(uint64_t phb_id, uint64_t tce_mem_addr,
arch/powerpc/platforms/powernv/opal.c +16 -12
@@ -164,27 +164,28 @@ void opal_notifier_disable(void)int opal_get_chars (uint32_t vtermno,char *buf,int count) { -s64 len, rc; -u64 evt; +s64 rc; +__be64 evt, len;if (!opal.entry)return -ENODEV ;opal_poll_events (&evt); -if ((evt &OPAL_EVENT_CONSOLE_INPUT ) ==0 ) +if ((be64_to_cpu (evt) &OPAL_EVENT_CONSOLE_INPUT ) ==0 )return 0 ; - len = count; - rc =opal_console_read (vtermno, &len, buf); + len =cpu_to_be64 (count); + rc =opal_console_read (vtermno, &len, buf);if (rc ==OPAL_SUCCESS ) -return len; +return be64_to_cpu (len);return 0 ; }int opal_put_chars (uint32_t vtermno,const char *data,int total_len) {int written =0 ; +__be64 olen;s64 len, rc;unsigned long flags; -u64 evt; +__be64 evt;if (!opal.entry)return -ENODEV ;
@@ -199,13 +200,14 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)*/ spin_lock_irqsave (&opal_write_lock, flags);if (firmware_has_feature (FW_FEATURE_OPALv2)) { - rc =opal_console_write_buffer_space (vtermno, &len); + rc =opal_console_write_buffer_space (vtermno, &olen); + len =be64_to_cpu (olen);if (rc || len < total_len) {spin_unlock_irqrestore (&opal_write_lock, flags);/* Closed -> drop characters */ if (rc)return total_len; -opal_poll_events (&evt); +opal_poll_events (NULL );return -EAGAIN ; } }
@@ -216,8 +218,9 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) rc =OPAL_BUSY ;while (total_len >0 && (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT || rc ==OPAL_SUCCESS )) { - len = total_len; - rc =opal_console_write (vtermno, &len, data); + olen =cpu_to_be64 (total_len); + rc =opal_console_write (vtermno, &olen, data); + len =be64_to_cpu (olen);/* Closed or other error drop */ if (rc != OPAL_SUCCESS && rc != OPAL_BUSY &&
@@ -237,7 +240,8 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len)*/ do opal_poll_events (&evt); -while (rc ==OPAL_SUCCESS && (evt &OPAL_EVENT_CONSOLE_OUTPUT )); +while (rc ==OPAL_SUCCESS && + (be64_to_cpu (evt) &OPAL_EVENT_CONSOLE_OUTPUT )); }spin_unlock_irqrestore (&opal_write_lock, flags);return written;
Signature · 1 line
1.8.1.2
PATCH 29/39 powerpc/powernv: Fix OPAL entry and exit in little endian mode
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/platforms/powernv/opal-wrappers.S | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/opal-wrappers.S +8 -1
@@ -34,7 +34,7 @@ mtmsrd r12,1; \ LOAD_REG_ADDR(r0,.opal_return); \ mtlr r0; \ - li r0,MSR_DR|MSR_IR; \ + li r0,MSR_DR|MSR_IR|MSR_LE;\ andc r12,r12,r0; \ li r0,token; \ mtspr SPRN_HSRR1,r12; \
@@ -45,6 +45,13 @@ hrfid _STATIC(opal_return) + /* + * Fixup endian on OPAL return... we should be able to simplify + * this by instead converting the below trampoline to a set of + * bytes (always BE) since MSR:LE will end up fixed up as a side + * effect of the rfid. + */ + FIXUP_ENDIAN ld r2,PACATOC(r13); ld r4,8(r1); ld r5,16(r1);
Signature · 1 line
1.8.1.2
PATCH 30/39 powerpc/powernv: Don't register exception handlers in little endian mode
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
The powernv exception handlers are not ready to take exceptions in little endian mode, so disable them.
--- arch/powerpc/platforms/powernv/opal.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/platforms/powernv/opal.c +2 -0
@@ -77,6 +77,7 @@ int __init early_init_dt_scan_opal(unsigned long node,static int __init opal_register_exception_handlers (void ) { +#ifdef __BIG_ENDIAN__u64 glue;if (!(powerpc_firmware_features &FW_FEATURE_OPAL ))
@@ -94,6 +95,7 @@ static int __init opal_register_exception_handlers(void) 0, glue); glue +=128 ;opal_register_exception_handler (OPAL_SOFTPATCH_HANDLER ,0 , glue); +#endif return 0 ; }
Signature · 1 line
1.8.1.2
PATCH 31/39 powerpc/powernv: More little endian issues in OPAL RTC driver
In reply to Anton BlanchardSparse caught an issue where opal_set_rtc_time was incorrectly byteswapping. Also fix a number of sparse warnings.
--- arch/powerpc/include/asm/opal.h | 4 ++-- arch/powerpc/platforms/powernv/opal-rtc.c | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/opal.h +2 -2
@@ -543,8 +543,8 @@ int64_t opal_console_read(int64_t term_number, __be64 *length, uint8_t *buffer);int64_t opal_console_write_buffer_space (int64_t term_number,__be64 *length); -int64_t opal_rtc_read (uint32_t *year_month_day, -uint64_t *hour_minute_second_millisecond); +int64_t opal_rtc_read (__be32 *year_month_day, +__be64 *hour_minute_second_millisecond);int64_t opal_rtc_write (uint32_t year_month_day,uint64_t hour_minute_second_millisecond);int64_t opal_cec_power_down (uint64_t request);
arch/powerpc/platforms/powernv/opal-rtc.c +10 -9
@@ -37,10 +37,12 @@ unsigned long __init opal_get_boot_time(void)struct rtc_time tm;u32 y_m_d;u64 h_m_s_ms; +__be32 __y_m_d; +__be64 __h_m_s_ms;long rc =OPAL_BUSY ;while (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { - rc =opal_rtc_read (&y_m_d, &h_m_s_ms); + rc =opal_rtc_read (&__y_m_d, &__h_m_s_ms);if (rc ==OPAL_BUSY_EVENT )opal_poll_events (NULL );else
@@ -48,8 +50,8 @@ unsigned long __init opal_get_boot_time(void) }if (rc !=OPAL_SUCCESS )return 0 ; - y_m_d =be32_to_cpu (y_m_d); - h_m_s_ms =be64_to_cpu (h_m_s_ms); + y_m_d =be32_to_cpu (__y_m_d); + h_m_s_ms =be64_to_cpu (__h_m_s_ms);opal_to_tm (y_m_d, h_m_s_ms, &tm);return mktime (tm.tm_year +1900 , tm.tm_mon +1 , tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
@@ -60,9 +62,11 @@ void opal_get_rtc_time(struct rtc_time *tm)long rc =OPAL_BUSY ;u32 y_m_d;u64 h_m_s_ms; +__be32 __y_m_d; +__be64 __h_m_s_ms;while (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { - rc =opal_rtc_read (&y_m_d, &h_m_s_ms); + rc =opal_rtc_read (&__y_m_d, &__h_m_s_ms);if (rc ==OPAL_BUSY_EVENT )opal_poll_events (NULL );else
@@ -70,8 +74,8 @@ void opal_get_rtc_time(struct rtc_time *tm) }if (rc !=OPAL_SUCCESS )return ; - y_m_d =be32_to_cpu (y_m_d); - h_m_s_ms =be64_to_cpu (h_m_s_ms); + y_m_d =be32_to_cpu (__y_m_d); + h_m_s_ms =be64_to_cpu (__h_m_s_ms);opal_to_tm (y_m_d, h_m_s_ms, tm); }
@@ -90,9 +94,6 @@ int opal_set_rtc_time(struct rtc_time *tm) h_m_s_ms |= ((u64 )bin2bcd (tm->tm_min)) <<48 ; h_m_s_ms |= ((u64 )bin2bcd (tm->tm_sec)) <<40 ; - y_m_d =cpu_to_be32 (y_m_d); - h_m_s_ms =cpu_to_be64 (h_m_s_ms); -while (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { rc =opal_rtc_write (y_m_d, h_m_s_ms);if (rc ==OPAL_BUSY_EVENT )
Signature · 1 line
1.8.1.2
PATCH 32/39 powerpc/powernv: Fix some PCI sparse errors and one LE bug
In reply to Anton Blanchardpnv_pci_setup_bml_iommu was missing a byteswap of a device tree property.
--- arch/powerpc/include/asm/opal.h | 22 +++++++++++----------- arch/powerpc/platforms/powernv/opal.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 6 +++--- arch/powerpc/platforms/powernv/pci.c | 6 +++--- arch/powerpc/platforms/powernv/pci.h | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-)
arch/powerpc/include/asm/opal.h +11 -11
@@ -551,7 +551,7 @@ int64_t opal_cec_power_down(uint64_t request);int64_t opal_cec_reboot (void );int64_t opal_read_nvram (uint64_t buffer,uint64_t size,uint64_t offset);int64_t opal_write_nvram (uint64_t buffer,uint64_t size,uint64_t offset); -int64_t opal_handle_interrupt (uint64_t isn,uint64_t *outstanding_event_mask); +int64_t opal_handle_interrupt (uint64_t isn,__be64 *outstanding_event_mask);int64_t opal_poll_events (__be64 *outstanding_event_mask);int64_t opal_pci_set_hub_tce_memory (uint64_t hub_id,uint64_t tce_mem_addr,uint64_t tce_mem_size);
@@ -560,9 +560,9 @@ int64_t opal_pci_set_phb_tce_memory(uint64_t phb_id, uint64_t tce_mem_addr,int64_t opal_pci_config_read_byte (uint64_t phb_id,uint64_t bus_dev_func,uint64_t offset,uint8_t *data);int64_t opal_pci_config_read_half_word (uint64_t phb_id,uint64_t bus_dev_func, -uint64_t offset,uint16_t *data); +uint64_t offset,__be16 *data);int64_t opal_pci_config_read_word (uint64_t phb_id,uint64_t bus_dev_func, -uint64_t offset,uint32_t *data); +uint64_t offset,__be32 *data);int64_t opal_pci_config_write_byte (uint64_t phb_id,uint64_t bus_dev_func,uint64_t offset,uint8_t data); int64_t opal_pci_config_write_half_word(uint64_t phb_id, uint64_t bus_dev_func,
@@ -570,14 +570,14 @@ int64_t opal_pci_config_write_half_word(uint64_t phb_id, uint64_t bus_dev_func,int64_t opal_pci_config_write_word (uint64_t phb_id,uint64_t bus_dev_func,uint64_t offset,uint32_t data);int64_t opal_set_xive (uint32_t isn,uint16_t server,uint8_t priority); -int64_t opal_get_xive (uint32_t isn,uint16_t *server,uint8_t *priority); +int64_t opal_get_xive (uint32_t isn,__be16 *server,uint8_t *priority);int64_t opal_register_exception_handler (uint64_t opal_exception,uint64_t handler_address,uint64_t glue_cache_line);int64_t opal_pci_eeh_freeze_status (uint64_t phb_id,uint64_t pe_number,uint8_t *freeze_state, -uint16_t *pci_error_type, -uint64_t *phb_status); +__be16 *pci_error_type, +__be64 *phb_status);int64_t opal_pci_eeh_freeze_clear (uint64_t phb_id,uint64_t pe_number,uint64_t eeh_action_token);int64_t opal_pci_shpc (uint64_t phb_id,uint64_t shpc_action,uint8_t *state);
@@ -614,13 +614,13 @@ int64_t opal_pci_msi_eoi(uint64_t phb_id, uint32_t hw_irq);int64_t opal_pci_set_xive_pe (uint64_t phb_id,uint32_t pe_number,uint32_t xive_num);int64_t opal_get_xive_source (uint64_t phb_id,uint32_t xive_num, -int32_t *interrupt_source_number); +__be32 *interrupt_source_number);int64_t opal_get_msi_32 (uint64_t phb_id,uint32_t mve_number,uint32_t xive_num, -uint8_t msi_range,uint32_t *msi_address, -uint32_t *message_data); +uint8_t msi_range,__be32 *msi_address, +__be32 *message_data);int64_t opal_get_msi_64 (uint64_t phb_id,uint32_t mve_number,uint32_t xive_num,uint8_t msi_range, -uint64_t *msi_address,uint32_t *message_data); +__be64 *msi_address,__be32 *message_data);int64_t opal_start_cpu (uint64_t thread_number,uint64_t start_address);int64_t opal_query_cpu_status (uint64_t thread_number,uint8_t *thread_status);int64_t opal_write_oppanel (oppanel_line_t *lines,uint64_t num_lines);
@@ -642,7 +642,7 @@ int64_t opal_pci_fence_phb(uint64_t phb_id);int64_t opal_pci_reinit (uint64_t phb_id,uint8_t reinit_scope);int64_t opal_pci_mask_pe_error (uint64_t phb_id,uint16_t pe_number,uint8_t error_type,uint8_t mask_action);int64_t opal_set_slot_led_status (uint64_t phb_id,uint64_t slot_id,uint8_t led_type,uint8_t led_action); -int64_t opal_get_epow_status (uint64_t *status); +int64_t opal_get_epow_status (__be64 *status);int64_t opal_set_system_attention_led (uint8_t led_action);int64_t opal_pci_next_error (uint64_t phb_id,uint64_t *first_frozen_pe,uint16_t *pci_error_type,uint16_t *severity);
arch/powerpc/platforms/powernv/opal.c +1 -1
@@ -366,7 +366,7 @@ int opal_machine_check(struct pt_regs *regs)static irqreturn_t opal_interrupt (int irq,void *data) { -uint64_t events; +__be64 events;opal_handle_interrupt (virq_to_hw (irq), &events);
arch/powerpc/platforms/powernv/pci-ioda.c +3 -3
@@ -455,7 +455,7 @@ static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus) }static void pnv_pci_ioda1_tce_invalidate (struct iommu_table *tbl, -u64 *startp,u64 *endp) +__be64 *startp,__be64 *endp) {__be64 __iomem *invalidate = (__be64 __iomem *)tbl->it_index;unsigned long start, end, inc;
@@ -496,7 +496,7 @@ static void pnv_pci_ioda1_tce_invalidate(struct iommu_table *tbl,static void pnv_pci_ioda2_tce_invalidate (struct pnv_ioda_pe *pe,struct iommu_table *tbl, -u64 *startp,u64 *endp) +__be64 *startp,__be64 *endp) {unsigned long start, end, inc;__be64 __iomem *invalidate = (__be64 __iomem *)tbl->it_index;
@@ -521,7 +521,7 @@ static void pnv_pci_ioda2_tce_invalidate(struct pnv_ioda_pe *pe, }void pnv_pci_ioda_tce_invalidate (struct iommu_table *tbl, -u64 *startp,u64 *endp) +__be64 *startp,__be64 *endp) { struct pnv_ioda_pe *pe = container_of(tbl, struct pnv_ioda_pe, tce32_table);
arch/powerpc/platforms/powernv/pci.c +3 -3
@@ -412,7 +412,7 @@ static int pnv_tce_build(struct iommu_table *tbl, long index, long npages,if (direction !=DMA_TO_DEVICE ) proto_tce |=TCE_PCI_WRITE ; - tces = tcep = ((u64 *)tbl->it_base) + index - tbl->it_offset; + tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; rpn =__pa (uaddr) >>TCE_SHIFT ;while (npages--)
@@ -432,7 +432,7 @@ static void pnv_tce_free(struct iommu_table *tbl, long index, long npages) {__be64 *tcep, *tces; - tces = tcep = ((u64 *)tbl->it_base) + index - tbl->it_offset; + tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset;while (npages--) *(tcep++) =cpu_to_be64 (0 );
@@ -484,7 +484,7 @@ static struct iommu_table *pnv_pci_setup_bml_iommu(struct pci_controller *hose) swinvp =of_get_property (hose->dn,"linux,tce-sw-invalidate-info" ,NULL );if (swinvp) { - tbl->it_busno = swinvp[1 ]; + tbl->it_busno =be64_to_cpu (swinvp[1 ]); tbl->it_index = (unsigned long )ioremap (be64_to_cpup (swinvp),8 ); tbl->it_type =TCE_PCI_SWINV_CREATE |TCE_PCI_SWINV_FREE ; }
arch/powerpc/platforms/powernv/pci.h +1 -1
@@ -193,6 +193,6 @@ extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);extern void pnv_pci_init_ioda_hub (struct device_node *np);extern void pnv_pci_init_ioda2_phb (struct device_node *np);extern void pnv_pci_ioda_tce_invalidate (struct iommu_table *tbl, -u64 *startp,u64 *endp); +__be64 *startp,__be64 *endp);#endif /* __POWERNV_PCI_H */
Signature · 1 line
1.8.1.2
PATCH 33/39 powerpc/hvsi: Fix endian issues in HVSI driver
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/include/asm/hvsi.h | 16 ++++++++-------- drivers/tty/hvc/hvsi_lib.c | 25 ++++++++++++------------- 2 files changed, 20 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/hvsi.h +8 -8
@@ -25,7 +25,7 @@struct hvsi_header {uint8_t type;uint8_t len; -uint16_t seqno; +__be16 seqno; } __attribute__((packed));struct hvsi_data {
@@ -35,24 +35,24 @@ struct hvsi_data {struct hvsi_control {struct hvsi_header hdr; -uint16_t verb; +__be16 verb;/* optional depending on verb: */ -uint32_t word; -uint32_t mask; +__be32 word; +__be32 mask; } __attribute__((packed));struct hvsi_query {struct hvsi_header hdr; -uint16_t verb; +__be16 verb; } __attribute__((packed));struct hvsi_query_response {struct hvsi_header hdr; -uint16_t verb; -uint16_t query_seqno; +__be16 verb; +__be16 query_seqno;union {uint8_t version; -uint32_t mctrl_word; +__be32 mctrl_word; } u; } __attribute__((packed));
drivers/tty/hvc/hvsi_lib.c +12 -13
@@ -9,7 +9,7 @@static int hvsi_send_packet (struct hvsi_priv *pv,struct hvsi_header *packet) { - packet->seqno =atomic_inc_return (&pv->seqno); + packet->seqno =cpu_to_be16 (atomic_inc_return (&pv->seqno));/* Assumes that always succeeds, works in practice */ return pv->put_chars (pv->termno, (char *)packet, packet->len);
@@ -28,7 +28,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)/* Send version query */ q.hdr.type =VS_QUERY_PACKET_HEADER ; q.hdr.len =sizeof (struct hvsi_query ); - q.verb =VSV_SEND_VERSION_NUMBER ; + q.verb =cpu_to_be16 (VSV_SEND_VERSION_NUMBER );hvsi_send_packet (pv, &q.hdr); }
@@ -40,7 +40,7 @@ static int hvsi_send_close(struct hvsi_priv *pv) ctrl.hdr.type =VS_CONTROL_PACKET_HEADER ; ctrl.hdr.len =sizeof (struct hvsi_control ); - ctrl.verb =VSV_CLOSE_PROTOCOL ; + ctrl.verb =cpu_to_be16 (VSV_CLOSE_PROTOCOL );return hvsi_send_packet (pv, &ctrl.hdr); }
@@ -69,14 +69,14 @@ static void hvsi_got_control(struct hvsi_priv *pv) {struct hvsi_control *pkt = (struct hvsi_control *)pv->inbuf; -switch (pkt->verb) { +switch (be16_to_cpu (pkt->verb)) {case VSV_CLOSE_PROTOCOL :/* We restart the handshaking */ hvsi_start_handshake (pv);break ;case VSV_MODEM_CTL_UPDATE :/* Transition of carrier detect */ -hvsi_cd_change (pv, pkt->word &HVSI_TSCD ); +hvsi_cd_change (pv,be32_to_cpu (pkt->word) &HVSI_TSCD );break ; } }
@@ -87,7 +87,7 @@ static void hvsi_got_query(struct hvsi_priv *pv)struct hvsi_query_response r;/* We only handle version queries */ -if (pkt->verb !=VSV_SEND_VERSION_NUMBER ) +if (be16_to_cpu (pkt->verb) !=VSV_SEND_VERSION_NUMBER )return ; pr_devel("HVSI@%x: Got version query, sending response...\n",
@@ -96,7 +96,7 @@ static void hvsi_got_query(struct hvsi_priv *pv)/* Send version response */ r.hdr.type =VS_QUERY_RESPONSE_PACKET_HEADER ; r.hdr.len =sizeof (struct hvsi_query_response ); - r.verb =VSV_SEND_VERSION_NUMBER ; + r.verb =cpu_to_be16 (VSV_SEND_VERSION_NUMBER ); r.u.version =HVSI_VERSION ; r.query_seqno = pkt->hdr.seqno;hvsi_send_packet (pv, &r.hdr);
@@ -112,7 +112,7 @@ static void hvsi_got_response(struct hvsi_priv *pv)switch (r->verb) {case VSV_SEND_MODEM_CTL_STATUS : -hvsi_cd_change (pv, r->u.mctrl_word &HVSI_TSCD ); +hvsi_cd_change (pv,be32_to_cpu (r->u.mctrl_word) &HVSI_TSCD ); pv->mctrl_update =1 ;break ; }
@@ -265,8 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv) pv->mctrl_update =0 ; q.hdr.type =VS_QUERY_PACKET_HEADER ; q.hdr.len =sizeof (struct hvsi_query ); - q.hdr.seqno =atomic_inc_return (&pv->seqno); - q.verb =VSV_SEND_MODEM_CTL_STATUS ; + q.verb =cpu_to_be16 (VSV_SEND_MODEM_CTL_STATUS ); rc =hvsi_send_packet (pv, &q.hdr);if (rc <=0 ) {pr_devel ("HVSI@%x: Error %d...\n" , pv->termno, rc);
@@ -304,9 +303,9 @@ int hvsilib_write_mctrl(struct hvsi_priv *pv, int dtr) ctrl.hdr.type =VS_CONTROL_PACKET_HEADER , ctrl.hdr.len =sizeof (struct hvsi_control ); - ctrl.verb =VSV_SET_MODEM_CTL ; - ctrl.mask =HVSI_TSDTR ; - ctrl.word = dtr ?HVSI_TSDTR :0 ; + ctrl.verb =cpu_to_be16 (VSV_SET_MODEM_CTL ); + ctrl.mask =cpu_to_be32 (HVSI_TSDTR ); + ctrl.word =cpu_to_be32 (dtr ?HVSI_TSDTR :0 );return hvsi_send_packet (pv, &ctrl.hdr); }
Signature · 1 line
1.8.1.2
PATCH 34/39 tty/hvc_opal: powerpc: Make OPAL HVC device tree accesses endian safe
In reply to Anton BlanchardFrom: Benjamin Herrenschmidt <[email protected]>
--- drivers/tty/hvc/hvc_opal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/hvc/hvc_opal.c +2 -2
@@ -329,7 +329,7 @@ static void udbg_init_opal_common(void)void __init hvc_opal_init_early (void ) {struct device_node *stdout_node =NULL ; -const u32 *termno; +const __be32 *termno;const char *name =NULL ;const struct hv_ops *ops;u32 index;
@@ -371,7 +371,7 @@ void __init hvc_opal_init_early(void)if (!stdout_node)return ; termno =of_get_property (stdout_node,"reg" ,NULL ); - index = termno ? *termno :0 ; + index = termno ?be32_to_cpup (termno) :0 ;if (index >=MAX_NR_HVC_CONSOLES )return ; hvc_opal_privs[index] = &hvc_opal_boot_priv;
Signature · 1 line
1.8.1.2
PATCH 35/39 KVM: PPC: Disable KVM on little endian builds
In reply to Anton BlanchardThere are a number of KVM issues with little endian builds. We are working on fixing them, but in the meantime disable it.
--- arch/powerpc/kvm/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/kvm/Kconfig +1 -0
@@ -6,6 +6,7 @@ source "virt/kvm/Kconfig" menuconfig VIRTUALIZATION bool "Virtualization" + depends on !CPU_LITTLE_ENDIAN ---help--- Say Y here to get to see options for using your Linux host to run other operating systems inside virtual machines (guests).
Signature · 1 line
1.8.1.2
PATCH 36/39 powerpc/kvm/book3s_hv: Add little endian guest support
In reply to Anton BlanchardAdd support for the H_SET_MODE hcall so we can select the endianness of our exceptions.
We create a guest MSR from scratch when delivering exceptions in a few places and instead of extracing the LPCR[ILE] and inserting it into MSR_LE each time simply create a new variable intr_msr which contains the entire MSR to use.
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 44 +++++++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 15 ++++------- 5 files changed, 52 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -605,6 +605,7 @@ struct kvm_vcpu_arch {spinlock_t tbacct_lock;u64 busy_stolen;u64 busy_preempt; +unsigned long intr_msr;#endif };
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -490,6 +490,7 @@ int main(void) DEFINE(VCPU_DAR, offsetof(struct kvm_vcpu, arch.shregs.dar)); DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr)); DEFINE(VCPU_VPA_DIRTY, offsetof(struct kvm_vcpu, arch.vpa.dirty)); + DEFINE(VCPU_INTR_MSR, offsetof(struct kvm_vcpu, arch.intr_msr));#endif #ifdef CONFIG_PPC_BOOK3S DEFINE (VCPU_VCPUID , offsetof(struct kvm_vcpu , vcpu_id));
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -266,7 +266,7 @@ void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)static void kvmppc_mmu_book3s_64_hv_reset_msr (struct kvm_vcpu *vcpu) { -kvmppc_set_msr (vcpu,MSR_SF |MSR_ME ); +kvmppc_set_msr (vcpu, vcpu->arch.intr_msr); }/*
arch/powerpc/kvm/book3s_hv.c +44 -0
62 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +5 -10
@@ -521,8 +521,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) 12: mr r6,r10 mr r10,r0 mr r7,r11 - li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11,r11,63 + ld r11,VCPU_INTR_MSR(r4) b 5f 11: beq 5f mfspr r0,SPRN_DEC
@@ -758,8 +757,7 @@ do_ext_interrupt: mtspr SPRN_SRR0, r10 mtspr SPRN_SRR1, r11 li r10, BOOK3S_INTERRUPT_EXTERNAL - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11,VCPU_INTR_MSR(r9) 2: mr r4, r9 mtspr SPRN_LPCR, r8 b fast_guest_return
@@ -1300,8 +1298,7 @@ kvmppc_hdsi: mtspr SPRN_SRR0, r10 mtspr SPRN_SRR1, r11 li r10, BOOK3S_INTERRUPT_DATA_STORAGE - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11,VCPU_INTR_MSR(r9) fast_interrupt_c_return: 6: ld r7, VCPU_CTR(r9) lwz r8, VCPU_XER(r9)
@@ -1370,8 +1367,7 @@ kvmppc_hisi: 1: mtspr SPRN_SRR0, r10 mtspr SPRN_SRR1, r11 li r10, BOOK3S_INTERRUPT_INST_STORAGE - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11,VCPU_INTR_MSR(r9) b fast_interrupt_c_return 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */
@@ -1697,8 +1693,7 @@ machine_check_realmode: beq mc_cont /* If not, deliver a machine check. SRR0/1 are already set */ li r10, BOOK3S_INTERRUPT_MACHINE_CHECK - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11,VCPU_INTR_MSR(r9) b fast_interrupt_c_return secondary_too_late:
Signature · 1 line
1.8.1.2
PATCH 1/1 powerpc/kvmbook3s_hv: propagate H_SET_MODE to the host
Follow-up to Anton's H_SET_MODE patch, the host should be taken aware of guest endianess change.
The hcall H_SET_MODE is processed in kvm then in the host.
--- arch/powerpc/kvm/book3s_hv.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/powerpc/kvm/book3s_hv.c +8 -0
@@ -599,6 +599,14 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ),kvmppc_get_gpr (vcpu,6 ), kvmppc_get_gpr(vcpu, 7)); +/* +* If the hcall succeeded, we propagate it to the host. +* This way, it will be aware of the endianess's change too. +* The assumption is made that the hcall will succeed in the +* host. +*/ +if (ret ==H_SUCCESS ) +return RESUME_HOST ;break ;case H_XIRR :
Re: [PATCH] powerpc/kvmbook3s_hv: propagate H_SET_MODE to the host
Quoted 6 lines · On Wed, 25 Sep 2013 14:10:27 +0200 Laurent Dufour <[email protected]>…
Follow-up to Anton's
H_SET_MODEpatch, the host should be taken aware of guest endianess change.The hcall
H_SET_MODEis processed in kvm then in the host.Signed-off-by Laurent Dufour <[email protected]>
Quoted 9 lines
--- arch/powerpc/kvm/book3s_hv.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/powerpc/kvm/book3s_hv.c +0
-0
arch/powerpc/kvm/book3s_hv.c int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) · line 606
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +5
-0@@ -599,6 +599,14 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ),kvmppc_get_gpr (vcpu,6 ), kvmppc_get_gpr(vcpu, 7)); +/* +* If the hcall succeeded, we propagate it to the host. +* This way, it will be aware of the endianess's change too. +* The assumption is made that the hcall will succeed in the +* host.
Hmmm... Not sure the last sentence is appropriate from a kernel
perspective: it is up to the userland code to remain consistent with this endianess change.
Quoted 12 lines
arch/powerpc/kvm/book3s_hv.c +3
-0+*/ +if (ret ==H_SUCCESS ) +return RESUME_HOST ;break ;case H_XIRR :_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Signature · 7 lines
Gregory Kurz [email protected] [email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Re: [PATCH] powerpc/kvmbook3s_hv: propagate H_SET_MODE to the host
In reply to Laurent DufourQuoted 17 lines · Laurent Dufour
Follow-up to Anton's
H_SET_MODEpatch, the host should be taken aware of guest endianess change.The hcall
H_SET_MODEis processed in kvm then in the host.Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/powerpc/kvm/book3s_hv.c +0
-0@@ -599,6 +599,14 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6),
arch/powerpc/kvm/book3s_hv.c int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) · line 610
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +8
-0kvmppc_get_gpr(vcpu, 7)); +/* +* If the hcall succeeded, we propagate it to the host. +* This way, it will be aware of the endianess's change too. +* The assumption is made that the hcall will succeed in the +* host. +*/ +if (ret ==H_SUCCESS ) +return RESUME_HOST ;break ;
The problem with this is that H_SET_MODE isn't just used for setting endianness; it also does breakpoint setting (DAWR/X and CIABR), which might happen very frequently, so we don't want them being punted up to userspace.
Paul.
Re: [PATCH] powerpc/kvmbook3s_hv: propagate H_SET_MODE to the host
Quoted 34 lines · Paul Mackerras
Quoted 17 lines · Laurent Dufour
Follow-up to Anton's
H_SET_MODEpatch, the host should be taken aware of guest endianess change.The hcall
H_SET_MODEis processed in kvm then in the host.Signed-off-by Laurent Dufour <[email protected]>--- arch/powerpc/kvm/book3s_hv.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/powerpc/kvm/book3s_hv.c +0
-0@@ -599,6 +599,14 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ), kvmppc_get_gpr(vcpu, 6),arch/powerpc/kvm/book3s_hv.c int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) · line 610
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +8
-0kvmppc_get_gpr(vcpu, 7)); +/* +* If the hcall succeeded, we propagate it to the host. +* This way, it will be aware of the endianess's change too. +* The assumption is made that the hcall will succeed in the +* host. +*/ +if (ret ==H_SUCCESS ) +return RESUME_HOST ;break ;The problem with this is that
H_SET_MODEisn't just used for setting endianness; it also does breakpoint setting (DAWR/X and CIABR), which might happen very frequently, so we don't want them being punted up to userspace.
Quoted 1 line
Paul.
Hi Paul,
My mistake, the patch was based on a too old kernel missing yours and Michael's latest patches on H_SET_MODE handling.
I'll propose a new one asap.
Thanks,
Laurent.
PATCH v2 1/1 powerpc/kvm/book3s_hv: propagate H_SET_MODE_RESOURCE_LE to the host
In reply to Paul MackerrasFollow-up to Anton's H_SET_MODE patch, the host should be taken aware of guest endianess change.
The hcall H_SET_MODE/H_SET_MODE_RESOURCE_LE is processed in kvm and then propagated to the host.
v2: taking in account the Paul Mackerras's comment, using H_TOO_HARD to propagate only H_SET_MODE_RESOURCE_LE to the host.
--- arch/powerpc/kvm/book3s_hv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_hv.c +4 -2
@@ -523,14 +523,14 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags,kvm_for_each_vcpu (n, v, kvm) v->arch.intr_msr &= ~MSR_LE ;kick_all_cpus_sync (); -return H_SUCCESS ; +return H_TOO_HARD ;/* propagating to the host */ case 1 : kvm->arch.lpcr |=LPCR_ILE ;kvm_for_each_vcpu (n, v, kvm) v->arch.intr_msr |=MSR_LE ;kick_all_cpus_sync (); -return H_SUCCESS ; +return H_TOO_HARD ;/* propagating to the host */ default :return H_UNSUPPORTED_FLAG_START ;
@@ -599,6 +599,8 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ),kvmppc_get_gpr (vcpu,6 ), kvmppc_get_gpr(vcpu, 7)); +if (ret ==H_TOO_HARD ) +return RESUME_HOST ;break ;case H_XIRR :
Re: [PATCH V2] powerpc/kvm/book3s_hv: propagate H_SET_MODE_RESOURCE_LE to the host
Quoted 6 lines · On Fri, 27 Sep 2013 15:59:30 +0200 Laurent Dufour <[email protected]>…
Follow-up to Anton's
H_SET_MODEpatch, the host should be taken aware of guest endianess change.The hcall H_SET_MODE/H_SET_MODE_RESOURCE_LE is processed in kvm and then propagated to the host.
Even if it seems a bit odd to get H_SET_MODE handled both by kvm and qemu, it is a simple way to get the job done. Unless we expect tons of calls to H_SET_MODE_RESOURCE_LE to occur, I do not see a better way for the host code to know the guest endianess.
FYI, with this patch, Rusty's (Cc'ed) virtio endianess patchset for qemu works like a charm: my guest kernel calls h_set_mode once at boot time, qemu gets notified and keeps the information. Do we need more ?
Quoted 5 lines
v2: taking in account the Paul Mackerras's comment, using
H_TOO_HARDto propagate onlyH_SET_MODE_RESOURCE_LEto the host.Signed-off-by Laurent Dufour <[email protected]>---
Quoted 41 lines
arch/powerpc/kvm/book3s_hv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/arch/powerpc/kvm/book3s_hv.cindex 998cad3..be0af39 100644arch/powerpc/kvm/book3s_hv.c +1
-1@@ -523,14 +523,14 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, unsigned long mflags, kvm_for_each_vcpu(n, v, kvm) v->arch.intr_msr &= ~MSR_LE;kick_all_cpus_sync (); -return H_SUCCESS ; +return H_TOO_HARD ;/* propagating to the host */
arch/powerpc/kvm/book3s_hv.c +1
-1case 1 : kvm->arch.lpcr |=LPCR_ILE ;kvm_for_each_vcpu (n, v, kvm) v->arch.intr_msr |=MSR_LE ;kick_all_cpus_sync (); -return H_SUCCESS ; +return H_TOO_HARD ;/* propagating to the host */
arch/powerpc/kvm/book3s_hv.c +2
-0default :return H_UNSUPPORTED_FLAG_START ;@@ -599,6 +599,8 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)kvmppc_get_gpr (vcpu,5 ),kvmppc_get_gpr (vcpu,6 ), kvmppc_get_gpr(vcpu, 7)); +if (ret ==H_TOO_HARD ) +return RESUME_HOST ;break ;case H_XIRR :_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Signature · 7 lines
Gregory Kurz [email protected] [email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Re: [PATCH 36/39] powerpc/kvm/book3s_hv: Add little endian guest support
In reply to Anton BlanchardQuoted 70 lines · Anton Blanchard
Add support for the
H_SET_MODEhcall so we can select the endianness of our exceptions.We create a guest MSR from scratch when delivering exceptions in a few places and instead of extracing the LPCR[ILE] and inserting it into
MSR_LEeach time simply create a new variableintr_msrwhich contains the entire MSR to use.Signed-off-by Anton Blanchard<[email protected]>Cc Alexander Graf<[email protected]>--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 44 +++++++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 15 ++++------- 5 files changed, 52 insertions(+), 11 deletions(-)arch/powerpc/include/asm/kvm_host.h +1
-0@@ -605,6 +605,7 @@ struct kvm_vcpu_arch {spinlock_t tbacct_lock;u64 busy_stolen;u64 busy_preempt; +unsigned long intr_msr;#endif };arch/powerpc/kernel/asm-offsets.c +1
-0@@ -490,6 +490,7 @@ int main(void) DEFINE(VCPU_DAR, offsetof(struct kvm_vcpu, arch.shregs.dar)); DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr)); DEFINE(VCPU_VPA_DIRTY, offsetof(struct kvm_vcpu, arch.vpa.dirty)); + DEFINE(VCPU_INTR_MSR, offsetof(struct kvm_vcpu, arch.intr_msr));#endif #ifdef CONFIG_PPC_BOOK3S DEFINE (VCPU_VCPUID , offsetof(struct kvm_vcpu , vcpu_id));arch/powerpc/kvm/book3s_64_mmu_hv.c +1
-1@@ -266,7 +266,7 @@ void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)static void kvmppc_mmu_book3s_64_hv_reset_msr (struct kvm_vcpu *vcpu) { -kvmppc_set_msr (vcpu,MSR_SF |MSR_ME ); +kvmppc_set_msr (vcpu, vcpu->arch.intr_msr); }/* arch/powerpc/kvm/book3s_hv.c +7
-0@@ -503,6 +503,43 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, vcpu->arch.dtl.dirty = true; } +static int kvmppc_h_set_mode (struct kvm_vcpu *vcpu,unsigned long mflags, +unsigned long resource,unsigned long value1, +unsigned long value2) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_vcpu *v; +int n;
arch/powerpc/kvm/book3s_hv.c static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu, · line 522
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +10
-0+ +if (resource ==4 ) { +if (value1) +return H_P3 ; +if (value2) +return H_P4 ; + +switch (mflags) { +case 0 : + kvm->arch.lpcr&= ~LPCR_ILE ;
Can we live migrate this properly?
Alex
PATCH 37/39 powerpc: Add ability to build little endian kernels
In reply to Anton BlanchardFrom: Ian Munsie <[email protected]>
This patch allows the kbuild system to successfully compile a kernel for the little endian PowerPC64 architecture. A subsequent patch will add the CONFIG_CPU_LITTLE_ENDIAN kernel config option which must be set to build such a kernel.
If cross compiling, CROSS_COMPILE must point to a suitable toolchain (compiled for the powerpc64le-linux and powerpcle-linux targets).
--- arch/powerpc/Makefile | 24 +++++++++++++++++++++--- arch/powerpc/boot/Makefile | 3 ++- arch/powerpc/kernel/vdso32/vdso32.lds.S | 4 ++++ arch/powerpc/kernel/vdso64/vdso64.lds.S | 4 ++++ 4 files changed, 31 insertions(+), 4 deletions(-)
arch/powerpc/Makefile +21 -3
@@ -65,11 +65,29 @@ endif UTS_MACHINE := $(OLDARCH) +ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) +override CC += -mlittle-endian +override AS += -mlittle-endian +override LD += -EL +override CROSS32CC += -mlittle-endian +override CROSS32AS += -mlittle-endian +LDEMULATION := lppc +GNUTARGET := powerpcle +MULTIPLEWORD := -mno-multiple +else +override CC += -mbig-endian +override AS += -mbig-endian +override LD += -EB +LDEMULATION := ppc +GNUTARGET := powerpc +MULTIPLEWORD := -mmultiple +endif + ifeq ($(HAS_BIARCH),y) override AS += -a$(CONFIG_WORD_SIZE) -override LD += -m elf$(CONFIG_WORD_SIZE)ppc +override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION) override CC += -m$(CONFIG_WORD_SIZE) -override AR := GNUTARGET=elf$(CONFIG_WORD_SIZE)-powerpc $(AR) +override AR := GNUTARGET=elf$(CONFIG_WORD_SIZE)-$(GNUTARGET) $(AR) endif LDFLAGS_vmlinux-y := -Bstatic
@@ -95,7 +113,7 @@ endif CFLAGS-$(CONFIG_PPC64) := -mtraceback=no -mcall-aixdesc CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcmodel=medium,-mminimal-toc) CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mno-pointers-to-nested-functions) -CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 -mmultiple +CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 $(MULTIPLEWORD) ifeq ($(CONFIG_PPC_BOOK3S_64),y) CFLAGS-$(CONFIG_GENERIC_CPU) += $(call cc-option,-mtune=power7,-mtune=power4)
arch/powerpc/boot/Makefile +2 -1
@@ -22,7 +22,8 @@ all: $(obj)/zImage BOOTCFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -Os -msoft-float -pipe \ -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \ - -isystem $(shell $(CROSS32CC) -print-file-name=include) + -isystem $(shell $(CROSS32CC) -print-file-name=include) \ + -mbig-endian BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc ifdef CONFIG_DEBUG_INFO
arch/powerpc/kernel/vdso32/vdso32.lds.S +4 -0
@@ -4,7 +4,11 @@ */ #include <asm/vdso.h> +#ifdef __LITTLE_ENDIAN__ +OUTPUT_FORMAT("elf32-powerpcle", "elf32-powerpcle", "elf32-powerpcle") +#else OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc") +#endif OUTPUT_ARCH(powerpc:common) ENTRY(_start)
arch/powerpc/kernel/vdso64/vdso64.lds.S +4 -0
@@ -4,7 +4,11 @@ */ #include <asm/vdso.h> +#ifdef __LITTLE_ENDIAN__ +OUTPUT_FORMAT("elf64-powerpcle", "elf64-powerpcle", "elf64-powerpcle") +#else OUTPUT_FORMAT("elf64-powerpc", "elf64-powerpc", "elf64-powerpc") +#endif OUTPUT_ARCH(powerpc:common64) ENTRY(_start)
Signature · 1 line
1.8.1.2
PATCH 38/39 powerpc: Don't set HAVE_EFFICIENT_UNALIGNED_ACCESS on little endian builds
In reply to Anton BlanchardPOWER7 takes alignment exceptions on some unaligned addresses, so disable HAVE_EFFICIENT_UNALIGNED_ACCESS. This fixes an early boot issue in the printk code.
--- arch/powerpc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/Kconfig +1 -1
@@ -97,7 +97,7 @@ config PPC select VIRT_TO_BUS if !PPC64 select HAVE_IDE select HAVE_IOREMAP_PROT - select HAVE_EFFICIENT_UNALIGNED_ACCESS + select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_LITTLE_ENDIAN select HAVE_KPROBES select HAVE_ARCH_KGDB select HAVE_KRETPROBES
Signature · 1 line
1.8.1.2
PATCH 39/39 powerpc: Work around little endian gcc bug
In reply to Anton BlanchardTemporarily work around an ICE we are seeing while building in little endian mode:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57134
--- arch/powerpc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/Makefile +1 -1
@@ -66,7 +66,7 @@ endif UTS_MACHINE := $(OLDARCH) ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) -override CC += -mlittle-endian +override CC += -mlittle-endian -mno-strict-align override AS += -mlittle-endian override LD += -EL override CROSS32CC += -mlittle-endian
Signature · 1 line
1.8.1.2
[RFC] QEMU/KVM PowerPC: virtio and guest endianness
Hi,
There have been some work on the topic lately but no agreement has been reached yet. I want to consolidate the facts in a single thread of mail and re-start the discussion. Please find below a recap of what we have as of today:
From a virtio POV, guest endianness is reflected by the endianness of the interrupt vectors (ILE bit in the LPCR register). The guest kernel relies on the H_SET_MODE_RESOURCE_LE hcall to set this bit, early in the boot process.
Rusty sent a patchset on qemu-devel@ to provide the necessary bits to perform byteswap in the QEMU:
http://patchwork.ozlabs.org/patch/266451/
http://patchwork.ozlabs.org/patch/266452/
http://patchwork.ozlabs.org/patch/266450/
(plus other enablement patches for virtio drivers, not essential for the discussion).
In non-KVM mode, QEMU implements the H_SET_MODE_RESOURCE_LE and updates its internal value for LPCR when the guest requests it. Rusty's patchset works out-of-the-box in this mode: I could successfully setup and use a 9p share over virtio transport (broader virtio testing still to be done though).
When using KVM, the story is different : QEMU is not on this endianness change flow anymore, providing KVM has the following patch from Anton:
http://patchwork.ozlabs.org/patch/277079/
There are *at least* two approaches to bring back endianness knowledge to QEMU: polling (1) and propagation (2).
(1) QEMU must retrieve LPCR from the kernel using the following API:
http://patchwork.ozlabs.org/patch/273029/
(2) KVM can resume execution to the host and thus propagating H_SET_MODE_RESOURCE_LE to QEMU. Laurent came up with a patch on linuxppc-dev@ to do this:
http://patchwork.ozlabs.org/patch/278590/
I would say (1) is a standard and sane way of addressing the issue:
since the LPCR register value is held by KVM, it makes sense to introduce an API to get/set it. Then, it is up to QEMU to use this API.
We can dumbly do the polling in all the places where byteswapping
matters: it is clearly sub-optimized, especially since the LPCR_ILE bit doesn't change so often. Rusty suggested we can retrieve it at virtio device reset time and cache it, since an endianness change after the devices have started to be used is non-sensical.
I have searched for an appropriate place to add the polling and I must admit I did not find any... I am no QEMU expert but I suspect we would need some kind of arch specific hook to be called from the virtio code to do this... :-\ I hope I am wrong, please correct me if so.
On the other hand, (2) looks a bit hacky: KVM usually returns to the host when it cannot fully handle the h_call. Propagating may look like a useless path to follow from a KVM POV. From a QEMU POV, things are
different: propagation will trig the fallback code in QEMU, already working in non-KVM mode. Nothing more to be done.
I have a better feeling for (2) because:
- 2-liner patch in KVM
- no extra code change in QEMU
- already *partially* tested
Also, I understood Rusty is working on the next virtio specification which should address the endian issue: probably not worth to add too many temporary lines in the QEMU code...
Of course, I probably lack some essential knowledge that would be more favorable to (1)... so please comment and argue ! :)
Thanks.
--
Greg Kurz
Re: [RFC] QEMU/KVM PowerPC: virtio and guest endianness
CC'ing qemu-devel - please use qemu-ppc@ only as a tag, every mail needs to go to qemu-devel as well.
Quoted 56 lines · Greg Kurz
Hi,
There have been some work on the topic lately but no agreement has been reached yet. I want to consolidate the facts in a single thread of mail and re-start the discussion. Please find below a recap of what we have as of today:
From a virtio POV, guest endianness is reflected by the endianness of the interrupt vectors (ILE bit in the LPCR register). The guest kernel relies on the
H_SET_MODE_RESOURCE_LEhcall to set this bit, early in the boot process.Rusty sent a patchset on qemu-devel@ to provide the necessary bits to perform byteswap in the QEMU:
http://patchwork.ozlabs.org/patch/266451/
http://patchwork.ozlabs.org/patch/266452/
http://patchwork.ozlabs.org/patch/266450/
(plus other enablement patches for virtio drivers, not essential for the discussion).In non-KVM mode, QEMU implements the
H_SET_MODE_RESOURCE_LEand updates its internal value for LPCR when the guest requests it. Rusty's patchset works out-of-the-box in this mode: I could successfully setup and use a 9p share over virtio transport (broader virtio testing still to be done though).When using KVM, the story is different : QEMU is not on this endianness change flow anymore, providing KVM has the following patch from Anton:
http://patchwork.ozlabs.org/patch/277079/
There are *at least* two approaches to bring back endianness knowledge to QEMU: polling (1) and propagation (2).
(1) QEMU must retrieve LPCR from the kernel using the following API:
http://patchwork.ozlabs.org/patch/273029/
(2) KVM can resume execution to the host and thus propagating
H_SET_MODE_RESOURCE_LEto QEMU. Laurent came up with a patch on linuxppc-dev@ to do this:http://patchwork.ozlabs.org/patch/278590/
I would say (1) is a standard and sane way of addressing the issue:
since the LPCR register value is held by KVM, it makes sense to introduce an API to get/set it. Then, it is up to QEMU to use this API.We can dumbly do the polling in all the places where byteswapping
matters: it is clearly sub-optimized, especially since theLPCR_ILEbit doesn't change so often. Rusty suggested we can retrieve it at virtio device reset time and cache it, since an endianness change after the devices have started to be used is non-sensical.
Quoted 4 lines
I have searched for an appropriate place to add the polling and I must admit I did not find any... I am no QEMU expert but I suspect we would need some kind of arch specific hook to be called from the virtio code to do this... :-\ I hope I am wrong, please correct me if so.
Just put it into the normal register sync function and call cpu_synchronize_state() on virtio reset.
Quoted 5 lines
On the other hand, (2) looks a bit hacky: KVM usually returns to the host when it cannot fully handle the
h_call. Propagating may look like a useless path to follow from a KVM POV. From a QEMU POV, things are
different: propagation will trig the fallback code in QEMU, already working in non-KVM mode. Nothing more to be done.
We have to decide which scheme to follow. There are 2 way we can / should handle registers usually:
a) owned by QEMU
b) owned by KVM
If they're owned by QEMU, every hypercall needs to go into QEMU which then propagates that change through an ioctl back into KVM. If they're owned by KVM, QEMU needs to fetch them whenever it needs to
As a general rule of thumb path b is easier to hack up, path a is easier to maintain long term. Which is pretty much what you're seeing here.
Quoted 4 lines
I have a better feeling for (2) because:
- 2-liner patch in KVM
- no extra code change in QEMU
- already *partially* tested
I don't understand. QEMU would get triggered, then have to propagate things back into KVM. We definitely do _not_ want KVM to do magic, then tell QEMU to handle a hypercall again.
Quoted 3 lines
Also, I understood Rusty is working on the next virtio specification which should address the endian issue: probably not worth to add too many temporary lines in the QEMU code...
Does 3.13 support LE mode? Does 3.13 support the new and shiny virtio spec? There's a good chance we'd have to deal with guest kernels that can do LE, but not sane virtio.
Quoted 2 lines
Of course, I probably lack some essential knowledge that would be more favorable to (1)... so please comment and argue ! :)
I think a 100% QEMU implementation that just goes through all vcpus and does a simple SET_ONE_REG for LPCR to set ILE would be the best. Anton's patch isn't in Linus' tree yet, right? So all it takes is a partial revert of that one to not handle the actual hypercall in KVM. And some code in kvmppc_set_lpcr() to also set intr_msr (not changing it is a bug today already).
Alex
Re: [Qemu-ppc] [RFC] QEMU/KVM PowerPC: virtio and guest endianness
Quoted 3 lines · On Fri, 4 Oct 2013 13:43:38 +0200 Alexander Graf <[email protected]> wrote:
CC'ing qemu-devel - please use qemu-ppc@ only as a tag, every mail needs to go to qemu-devel as well.
Sure I will.
Quoted 11 lines · Greg Kurz
[...]
Quoted 5 lines
I have searched for an appropriate place to add the polling and I must admit I did not find any... I am no QEMU expert but I suspect we would need some kind of arch specific hook to be called from the virtio code to do this... :-\ I hope I am wrong, please correct me if so.
Just put it into the normal register sync function and call
cpu_synchronize_state()on virtio reset.
Thanks, I will look into that.
Quoted 7 lines
We have to decide which scheme to follow. There are 2 way we can / should handle registers usually:
a) owned by QEMU
b) owned by KVM
Quoted 8 lines
If they're owned by QEMU, every hypercall needs to go into QEMU which then propagates that change through an ioctl back into KVM. If they're owned by KVM, QEMU needs to fetch them whenever it needs to
As a general rule of thumb path b is easier to hack up, path a is easier to maintain long term. Which is pretty much what you're seeing here.
Agreed.
Quoted 9 lines
Quoted 4 lines
I have a better feeling for (2) because:
- 2-liner patch in KVM
- no extra code change in QEMU
- already *partially* testedI don't understand. QEMU would get triggered, then have to propagate things back into KVM. We definitely do _not_ want KVM to do magic, then tell QEMU to handle a hypercall again.
My idea was to have KVM and QEMU be like *co-owners* of the LPCR register... now I admit it was a bad idea ! :)
Quoted 8 lines
Quoted 3 lines
Also, I understood Rusty is working on the next virtio specification which should address the endian issue: probably not worth to add too many temporary lines in the QEMU code...
Does 3.13 support LE mode? Does 3.13 support the new and shiny virtio spec? There's a good chance we'd have to deal with guest kernels that can do LE, but not sane virtio.
I don't know any details about 3.13 but I guess you are right, it is unlikely the guests will have it.
Quoted 11 lines
Quoted 2 lines
Of course, I probably lack some essential knowledge that would be more favorable to (1)... so please comment and argue ! :)
I think a 100% QEMU implementation that just goes through all vcpus and does a simple
SET_ONE_REGfor LPCR to set ILE would be the best. Anton's patch isn't in Linus' tree yet, right? So all it takes is a partial revert of that one to not handle the actual hypercall in KVM. And some code inkvmppc_set_lpcr()to also setintr_msr(not changing it is a bug today already).
Quoted 3 lines
Alex
Thanks for your indications Alex.
Cheers.
--
Greg
Re: [RFC] QEMU/KVM PowerPC: virtio and guest endianness
In reply to Greg KurzQuoted 61 lines · Greg Kurz
Hi,
There have been some work on the topic lately but no agreement has been reached yet. I want to consolidate the facts in a single thread of mail and re-start the discussion. Please find below a recap of what we have as of today:
From a virtio POV, guest endianness is reflected by the endianness of the interrupt vectors (ILE bit in the LPCR register). The guest kernel relies on the
H_SET_MODE_RESOURCE_LEhcall to set this bit, early in the boot process.Rusty sent a patchset on qemu-devel@ to provide the necessary bits to perform byteswap in the QEMU:
http://patchwork.ozlabs.org/patch/266451/
http://patchwork.ozlabs.org/patch/266452/
http://patchwork.ozlabs.org/patch/266450/
(plus other enablement patches for virtio drivers, not essential for the discussion).In non-KVM mode, QEMU implements the
H_SET_MODE_RESOURCE_LEand updates its internal value for LPCR when the guest requests it. Rusty's patchset works out-of-the-box in this mode: I could successfully setup and use a 9p share over virtio transport (broader virtio testing still to be done though).When using KVM, the story is different : QEMU is not on this endianness change flow anymore, providing KVM has the following patch from Anton:
http://patchwork.ozlabs.org/patch/277079/
There are *at least* two approaches to bring back endianness knowledge to QEMU: polling (1) and propagation (2).
(1) QEMU must retrieve LPCR from the kernel using the following API:
http://patchwork.ozlabs.org/patch/273029/
(2) KVM can resume execution to the host and thus propagating
H_SET_MODE_RESOURCE_LEto QEMU. Laurent came up with a patch on linuxppc-dev@ to do this:http://patchwork.ozlabs.org/patch/278590/
I would say (1) is a standard and sane way of addressing the issue:
since the LPCR register value is held by KVM, it makes sense to introduce an API to get/set it. Then, it is up to QEMU to use this API.We can dumbly do the polling in all the places where byteswapping
matters: it is clearly sub-optimized, especially since theLPCR_ILEbit doesn't change so often. Rusty suggested we can retrieve it at virtio device reset time and cache it, since an endianness change after the devices have started to be used is non-sensical.I have searched for an appropriate place to add the polling and I must admit I did not find any... I am no QEMU expert but I suspect we would need some kind of arch specific hook to be called from the virtio code to do this... :-\ I hope I am wrong, please correct me if so.
Quoted 5 lines
On the other hand, (2) looks a bit hacky: KVM usually returns to the host when it cannot fully handle the
h_call. Propagating may look like a useless path to follow from a KVM POV. From a QEMU POV, things are
different: propagation will trig the fallback code in QEMU, already working in non-KVM mode. Nothing more to be done.
I don't mind particularly whether H_SET_MODE for the endianness setting gets handled in the kernel or in QEMU, but I don't think it should be handled in both. If you want QEMU to know about the endianness setting immediately, make the kernel version do nothing and get QEMU to handle it -- which if KVM is enabled will mean iterating over all vcpus and getting them all to send the new LPCR setting to the kernel via the SET_ONE_REG ioctl.
However, I want the setting of breakpoint registers (CIABR and DAWR/X) via H_SET_MODE to happen in the kernel, preferably in real mode, since that can happen on context switch and thus needs to be quick.
Regards,
Paul.
Re: [Qemu-ppc] [RFC] QEMU/KVM PowerPC: virtio and guest endianness
Quoted 76 lines · Paul Mackerras
Quoted 61 lines · Greg Kurz
Hi,
There have been some work on the topic lately but no agreement has been reached yet. I want to consolidate the facts in a single thread of mail and re-start the discussion. Please find below a recap of what we have as of today:
From a virtio POV, guest endianness is reflected by the endianness of the interrupt vectors (ILE bit in the LPCR register). The guest kernel relies on the
H_SET_MODE_RESOURCE_LEhcall to set this bit, early in the boot process.Rusty sent a patchset on qemu-devel@ to provide the necessary bits to perform byteswap in the QEMU:
http://patchwork.ozlabs.org/patch/266451/
http://patchwork.ozlabs.org/patch/266452/
http://patchwork.ozlabs.org/patch/266450/
(plus other enablement patches for virtio drivers, not essential for the discussion).In non-KVM mode, QEMU implements the
H_SET_MODE_RESOURCE_LEand updates its internal value for LPCR when the guest requests it. Rusty's patchset works out-of-the-box in this mode: I could successfully setup and use a 9p share over virtio transport (broader virtio testing still to be done though).When using KVM, the story is different : QEMU is not on this endianness change flow anymore, providing KVM has the following patch from Anton:
http://patchwork.ozlabs.org/patch/277079/
There are *at least* two approaches to bring back endianness knowledge to QEMU: polling (1) and propagation (2).
(1) QEMU must retrieve LPCR from the kernel using the following API:
http://patchwork.ozlabs.org/patch/273029/
(2) KVM can resume execution to the host and thus propagating
H_SET_MODE_RESOURCE_LEto QEMU. Laurent came up with a patch on linuxppc-dev@ to do this:http://patchwork.ozlabs.org/patch/278590/
I would say (1) is a standard and sane way of addressing the issue:
since the LPCR register value is held by KVM, it makes sense to introduce an API to get/set it. Then, it is up to QEMU to use this API.We can dumbly do the polling in all the places where byteswapping
matters: it is clearly sub-optimized, especially since theLPCR_ILEbit doesn't change so often. Rusty suggested we can retrieve it at virtio device reset time and cache it, since an endianness change after the devices have started to be used is non-sensical.I have searched for an appropriate place to add the polling and I must admit I did not find any... I am no QEMU expert but I suspect we would need some kind of arch specific hook to be called from the virtio code to do this... :-\ I hope I am wrong, please correct me if so.
Quoted 5 lines
On the other hand, (2) looks a bit hacky: KVM usually returns to the host when it cannot fully handle the
h_call. Propagating may look like a useless path to follow from a KVM POV. From a QEMU POV, things are
different: propagation will trig the fallback code in QEMU, already working in non-KVM mode. Nothing more to be done.I don't mind particularly whether
H_SET_MODEfor the endianness setting gets handled in the kernel or in QEMU, but I don't think it should be handled in both. If you want QEMU to know about the endianness setting immediately, make the kernel version do nothing and get QEMU to handle it -- which if KVM is enabled will mean iterating over all vcpus and getting them all to send the new LPCR setting to the kernel via theSET_ONE_REGioctl.
Quoted 3 lines
However, I want the setting of breakpoint registers (CIABR and DAWR/X) via
H_SET_MODEto happen in the kernel, preferably in real mode, since that can happen on context switch and thus needs to be quick.
I don't want to see a single hypercall be split across the QEMU/KVM barrier. So if there's a reasonable incentive to handle H_SET_MODE in KVM, we should handle all of it in KVM.
Alex
Re: [Qemu-ppc] [RFC] QEMU/KVM PowerPC: virtio and guest endianness
Answering to both Paul and Alex.
Quoted 11 lines · On Fri, 4 Oct 2013 13:54:25 +0200 Alexander Graf <[email protected]> wrote:
Quoted 9 lines · Paul Mackerras
I don't mind particularly whether
H_SET_MODEfor the endianness setting gets handled in the kernel or in QEMU, but I don't think it should be handled in both. If you want QEMU to know about the endianness setting immediately, make the kernel version do nothing and get QEMU to handle it -- which if KVM is enabled will mean iterating over all vcpus and getting them all to send the new LPCR setting to the kernel via theSET_ONE_REGioctl.
Quoted 5 lines
Quoted 4 lines
However, I want the setting of breakpoint registers (CIABR and DAWR/X) via
H_SET_MODEto happen in the kernel, preferably in real mode, since that can happen on context switch and thus needs to be quick.
Paul,
As far as virtio is concerned, QEMU only needs to know about the guest endiannes if a virtio device shows up. The virtio reset flow is a good candiadate for that.
Quoted 4 lines
I don't want to see a single hypercall be split across the QEMU/KVM barrier. So if there's a reasonable incentive to handle
H_SET_MODEin KVM, we should handle all of it in KVM.
Alex,
The appropriate solution would be then to let KVM implement the whole H_SET_MODE hcall and own LPCR. QEMU will poll it with cpu_synchronize_state(). It seems to preserve all the requirements.
Quoted 4 lines
Alex
--
Thanks for your guidance.
Cheers.
--
Greg
Re: [Qemu-ppc] [RFC] QEMU/KVM PowerPC: virtio and guest endianness
Quoted 33 lines · Greg Kurz
Answering to both Paul and Alex.
Quoted 11 lines · On Fri, 4 Oct 2013 13:54:25 +0200 Alexander Graf <[email protected]> wrote:
Quoted 9 lines · Paul Mackerras
I don't mind particularly whether
H_SET_MODEfor the endianness setting gets handled in the kernel or in QEMU, but I don't think it should be handled in both. If you want QEMU to know about the endianness setting immediately, make the kernel version do nothing and get QEMU to handle it -- which if KVM is enabled will mean iterating over all vcpus and getting them all to send the new LPCR setting to the kernel via theSET_ONE_REGioctl.Quoted 5 lines
Quoted 4 lines
However, I want the setting of breakpoint registers (CIABR and DAWR/X) via
H_SET_MODEto happen in the kernel, preferably in real mode, since that can happen on context switch and thus needs to be quick.Paul,
As far as virtio is concerned, QEMU only needs to know about the guest endiannes if a virtio device shows up. The virtio reset flow is a good candiadate for that.
Quoted 4 lines
I don't want to see a single hypercall be split across the QEMU/KVM barrier. So if there's a reasonable incentive to handle
H_SET_MODEin KVM, we should handle all of it in KVM.
Quoted 5 lines
Alex,
The appropriate solution would be then to let KVM implement the whole
H_SET_MODEhcall and own LPCR. QEMU will poll it withcpu_synchronize_state(). It seems to preserve all the requirements.
Yes. Since breakpoint registers are part of H_SET_MODE, we want to have it owned by KVM rather than QEMU. I still don't know what those PAPR people think they're doing, shoving completely unrelated things into the same hypercall though :).
Alex
cover virtio: guest endianness support
This patchset is a followup to Rusty's "virtio for endian curious guests" serie:
https://lists.nongnu.org/archive/html/qemu-devel/2013-08/msg01502.html
It brings guest endianness knowledge to the virtio drivers when running in KVM mode, on PowerPC.
The first patch is only here to have KVM_REG_PPC_LPCR defined. It is not needed unless you wish to build and do not already have KVM_REG_PPC_LPCR in linux-headers/asm-powerpc/kvm.h. The interesting code is in the second patch.
Cheers.
---
Greg Kurz (2):
linux-headers: POWER8 partial update
virtio: refresh registers at reset time
hw/virtio/virtio.c | 5 +++++ linux-headers/asm-powerpc/kvm.h | 3 +++ target-ppc/kvm.c | 4 ++++ 3 files changed, 12 insertions(+)
Signature · 1 line
Greg Kurz
PATCH 1/2 linux-headers: POWER8 partial update
Add definition for KVM_REG_PPC_LPCR, taken from:
https://github.com/agraf/linux-2.6/commit/1a87967d4c
--- linux-headers/asm-powerpc/kvm.h | 3 +++ 1 file changed, 3 insertions(+)
linux-headers/asm-powerpc/kvm.h +3 -0
@@ -499,6 +499,9 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_TLB3PS (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9a)#define KVM_REG_PPC_EPTCFG (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9b) +/* POWER8 registers */ +#define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5) +/* PPC64 eXternal Interrupt Controller Specification */ #define KVM_DEV_XICS_GRP_SOURCES 1/* 64-bit source attributes */
PATCH 2/2 virtio: refresh registers at reset time
In reply to Greg KurzWe need to support the guest endianness as soon as a virtio device shows up. Alex suggested this can achieved by calling cpu_synchronize_state().
To have it working on PowerPC, we need to add LPCR in the sync register functions.
--- hw/virtio/virtio.c | 5 +++++ target-ppc/kvm.c | 4 ++++ 2 files changed, 9 insertions(+)
hw/virtio/virtio.c +5 -0
@@ -19,6 +19,7 @@#include "qemu/atomic.h" #include "hw/virtio/virtio-bus.h" #include "hw/virtio/virtio-access.h" +#include "sysemu/kvm.h" /* * The alignment to use between consumer and producer parts of vring.
@@ -566,6 +567,10 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; } + +if (current_cpu) { +cpu_synchronize_state (current_cpu); + } }uint32_t virtio_config_readb (VirtIODevice *vdev,uint32_t addr)
target-ppc/kvm.c +4 -0
@@ -869,6 +869,8 @@ int kvm_arch_put_registers(CPUState *cs, int level) DPRINTF("Warning: Unable to set VPA information to KVM\n"); } } + +kvm_put_one_spr (cs,KVM_REG_PPC_LPCR ,SPR_LPCR );#endif /* TARGET_PPC64 */ }
@@ -1091,6 +1093,8 @@ int kvm_arch_get_registers(CPUState *cs) DPRINTF("Warning: Unable to get VPA information from KVM\n"); } } + +kvm_get_one_spr (cs,KVM_REG_PPC_LPCR ,SPR_LPCR );#endif }
Re: [Qemu-devel] [PATCH 2/2] virtio: refresh registers at reset time
Quoted 7 lines · Greg Kurz
We need to support the guest endianness as soon as a virtio device shows up. Alex suggested this can achieved by calling
cpu_synchronize_state().To have it working on PowerPC, we need to add LPCR in the sync register functions.
Signed-off-by Greg Kurz <[email protected]>
Excellent! Alex, if you take this, I'll be happy to rebase and re-test the virtio endianness patches on top.
Cheers,
Rusty.