Skip to content

Commit 835e206

Browse files
antonblanchardozbenh
authored andcommitted
powerpc: Add little endian support to alignment handler
Handle most unaligned load and store faults in little endian mode. Strings, multiples and VSX are not supported. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent a5841a4 commit 835e206

1 file changed

Lines changed: 63 additions & 30 deletions

File tree

‎arch/powerpc/kernel/align.c‎

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static int emulate_dcbz(struct pt_regs *regs, unsigned char __user *addr)
262262

263263
#define SWIZ_PTR(p) ((unsigned char __user *)((p) ^ swiz))
264264

265+
#ifdef __BIG_ENDIAN__
265266
static int emulate_multiple(struct pt_regs *regs, unsigned char __user *addr,
266267
unsigned int reg, unsigned int nb,
267268
unsigned int flags, unsigned int instr,
@@ -390,6 +391,7 @@ static int emulate_fp_pair(unsigned char __user *addr, unsigned int reg,
390391
return -EFAULT;
391392
return 1; /* exception handled and fixed up */
392393
}
394+
#endif
393395

394396
#ifdef CONFIG_SPE
395397

@@ -628,7 +630,7 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,
628630
}
629631
#endif /* CONFIG_SPE */
630632

631-
#ifdef CONFIG_VSX
633+
#if defined(CONFIG_VSX) && defined(__BIG_ENDIAN__)
632634
/*
633635
* Emulate VSX instructions...
634636
*/
@@ -702,18 +704,28 @@ int fix_alignment(struct pt_regs *regs)
702704
unsigned int dsisr;
703705
unsigned char __user *addr;
704706
unsigned long p, swiz;
705-
int ret;
706-
union {
707+
int ret, i;
708+
union data {
707709
u64 ll;
708710
double dd;
709711
unsigned char v[8];
710712
struct {
713+
#ifdef __LITTLE_ENDIAN__
714+
int low32;
715+
unsigned hi32;
716+
#else
711717
unsigned hi32;
712718
int low32;
719+
#endif
713720
} x32;
714721
struct {
722+
#ifdef __LITTLE_ENDIAN__
723+
short low16;
724+
unsigned char hi48[6];
725+
#else
715726
unsigned char hi48[6];
716727
short low16;
728+
#endif
717729
} x16;
718730
} data;
719731

@@ -772,8 +784,9 @@ int fix_alignment(struct pt_regs *regs)
772784

773785
/* Byteswap little endian loads and stores */
774786
swiz = 0;
775-
if (regs->msr & MSR_LE) {
787+
if ((regs->msr & MSR_LE) != (MSR_KERNEL & MSR_LE)) {
776788
flags ^= SW;
789+
#ifdef __BIG_ENDIAN__
777790
/*
778791
* So-called "PowerPC little endian" mode works by
779792
* swizzling addresses rather than by actually doing
@@ -786,11 +799,13 @@ int fix_alignment(struct pt_regs *regs)
786799
*/
787800
if (cpu_has_feature(CPU_FTR_PPC_LE))
788801
swiz = 7;
802+
#endif
789803
}
790804

791805
/* DAR has the operand effective address */
792806
addr = (unsigned char __user *)regs->dar;
793807

808+
#ifdef __BIG_ENDIAN__
794809
#ifdef CONFIG_VSX
795810
if ((instruction & 0xfc00003e) == 0x7c000018) {
796811
unsigned int elsize;
@@ -810,7 +825,7 @@ int fix_alignment(struct pt_regs *regs)
810825
elsize = 8;
811826

812827
flags = 0;
813-
if (regs->msr & MSR_LE)
828+
if ((regs->msr & MSR_LE) != (MSR_KERNEL & MSR_LE))
814829
flags |= SW;
815830
if (instruction & 0x100)
816831
flags |= ST;
@@ -824,6 +839,9 @@ int fix_alignment(struct pt_regs *regs)
824839
PPC_WARN_ALIGNMENT(vsx, regs);
825840
return emulate_vsx(addr, reg, areg, regs, flags, nb, elsize);
826841
}
842+
#endif
843+
#else
844+
return -EFAULT;
827845
#endif
828846
/* A size of 0 indicates an instruction we don't support, with
829847
* the exception of DCBZ which is handled as a special case here
@@ -839,9 +857,13 @@ int fix_alignment(struct pt_regs *regs)
839857
* function
840858
*/
841859
if (flags & M) {
860+
#ifdef __BIG_ENDIAN__
842861
PPC_WARN_ALIGNMENT(multiple, regs);
843862
return emulate_multiple(regs, addr, reg, nb,
844863
flags, instr, swiz);
864+
#else
865+
return -EFAULT;
866+
#endif
845867
}
846868

847869
/* Verify the address of the operand */
@@ -860,8 +882,12 @@ int fix_alignment(struct pt_regs *regs)
860882

861883
/* Special case for 16-byte FP loads and stores */
862884
if (nb == 16) {
885+
#ifdef __BIG_ENDIAN__
863886
PPC_WARN_ALIGNMENT(fp_pair, regs);
864887
return emulate_fp_pair(addr, reg, flags);
888+
#else
889+
return -EFAULT;
890+
#endif
865891
}
866892

867893
PPC_WARN_ALIGNMENT(unaligned, regs);
@@ -870,24 +896,28 @@ int fix_alignment(struct pt_regs *regs)
870896
* get it from register values
871897
*/
872898
if (!(flags & ST)) {
873-
data.ll = 0;
874-
ret = 0;
875-
p = (unsigned long) addr;
899+
unsigned int start = 0;
900+
876901
switch (nb) {
877-
case 8:
878-
ret |= __get_user_inatomic(data.v[0], SWIZ_PTR(p++));
879-
ret |= __get_user_inatomic(data.v[1], SWIZ_PTR(p++));
880-
ret |= __get_user_inatomic(data.v[2], SWIZ_PTR(p++));
881-
ret |= __get_user_inatomic(data.v[3], SWIZ_PTR(p++));
882902
case 4:
883-
ret |= __get_user_inatomic(data.v[4], SWIZ_PTR(p++));
884-
ret |= __get_user_inatomic(data.v[5], SWIZ_PTR(p++));
903+
start = offsetof(union data, x32.low32);
904+
break;
885905
case 2:
886-
ret |= __get_user_inatomic(data.v[6], SWIZ_PTR(p++));
887-
ret |= __get_user_inatomic(data.v[7], SWIZ_PTR(p++));
888-
if (unlikely(ret))
889-
return -EFAULT;
906+
start = offsetof(union data, x16.low16);
907+
break;
890908
}
909+
910+
data.ll = 0;
911+
ret = 0;
912+
p = (unsigned long)addr;
913+
914+
for (i = 0; i < nb; i++)
915+
ret |= __get_user_inatomic(data.v[start + i],
916+
SWIZ_PTR(p++));
917+
918+
if (unlikely(ret))
919+
return -EFAULT;
920+
891921
} else if (flags & F) {
892922
data.dd = current->thread.TS_FPR(reg);
893923
if (flags & S) {
@@ -945,21 +975,24 @@ int fix_alignment(struct pt_regs *regs)
945975

946976
/* Store result to memory or update registers */
947977
if (flags & ST) {
948-
ret = 0;
949-
p = (unsigned long) addr;
978+
unsigned int start = 0;
979+
950980
switch (nb) {
951-
case 8:
952-
ret |= __put_user_inatomic(data.v[0], SWIZ_PTR(p++));
953-
ret |= __put_user_inatomic(data.v[1], SWIZ_PTR(p++));
954-
ret |= __put_user_inatomic(data.v[2], SWIZ_PTR(p++));
955-
ret |= __put_user_inatomic(data.v[3], SWIZ_PTR(p++));
956981
case 4:
957-
ret |= __put_user_inatomic(data.v[4], SWIZ_PTR(p++));
958-
ret |= __put_user_inatomic(data.v[5], SWIZ_PTR(p++));
982+
start = offsetof(union data, x32.low32);
983+
break;
959984
case 2:
960-
ret |= __put_user_inatomic(data.v[6], SWIZ_PTR(p++));
961-
ret |= __put_user_inatomic(data.v[7], SWIZ_PTR(p++));
985+
start = offsetof(union data, x16.low16);
986+
break;
962987
}
988+
989+
ret = 0;
990+
p = (unsigned long)addr;
991+
992+
for (i = 0; i < nb; i++)
993+
ret |= __put_user_inatomic(data.v[start + i],
994+
SWIZ_PTR(p++));
995+
963996
if (unlikely(ret))
964997
return -EFAULT;
965998
} else if (flags & F)

0 commit comments

Comments
 (0)