diff options
author | David Sterba <dsterba@suse.com> | 2016-07-28 19:56:20 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-07-29 15:04:54 +0200 |
commit | af1812090bf957cdbc3d2e49e3a2d68b2108a07d (patch) | |
tree | da1b08f10df6b426e9bc9cd81009740d51b42390 /raid6.c | |
parent | 4e4c1e603970a47cc8088d23657a85f2602feef6 (diff) |
btrfs-progs: fix unaligned access in raid6 calculations
The raid6 code matches kernel implementation that also does the
unaligned access. So to keep the code close, add helpers for unaligned
native access and use them. The helpers are local as we don't plan to
use them elsewhere.
Reported-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'raid6.c')
-rw-r--r-- | raid6.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -11,6 +11,10 @@ * ----------------------------------------------------------------------- */ /* + * Added helpers for unaligned native int access + */ + +/* * raid6int1.c * * 1-way unrolled portable integer math RAID-6 instruction set @@ -33,11 +37,15 @@ # define NSIZE 8 # define NSHIFT 3 typedef uint64_t unative_t; +#define put_unaligned_native(val,p) put_unaligned_64((val),(p)) +#define get_unaligned_native(p) get_unaligned_64((p)) #else # define NBYTES(x) ((x) * 0x01010101U) # define NSIZE 4 # define NSHIFT 2 typedef uint32_t unative_t; +#define put_unaligned_native(val,p) put_unaligned_32((val),(p)) +#define get_unaligned_native(p) get_unaligned_32((p)) #endif /* @@ -84,9 +92,9 @@ void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs) q = dptr[z0+2]; /* RS syndrome */ for ( d = 0 ; d < bytes ; d += NSIZE*1 ) { - wq0 = wp0 = *(unative_t *)&dptr[z0][d+0*NSIZE]; + wq0 = wp0 = get_unaligned_native(&dptr[z0][d+0*NSIZE]); for ( z = z0-1 ; z >= 0 ; z-- ) { - wd0 = *(unative_t *)&dptr[z][d+0*NSIZE]; + wd0 = get_unaligned_native(&dptr[z][d+0*NSIZE]); wp0 ^= wd0; w20 = MASK(wq0); w10 = SHLBYTE(wq0); @@ -94,8 +102,8 @@ void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs) w10 ^= w20; wq0 = w10 ^ wd0; } - *(unative_t *)&p[d+NSIZE*0] = wp0; - *(unative_t *)&q[d+NSIZE*0] = wq0; + put_unaligned_native(wp0, &p[d+NSIZE*0]); + put_unaligned_native(wq0, &q[d+NSIZE*0]); } } |